From e3dcb89f63f7ab157bac5758692d0419ceeae480 Mon Sep 17 00:00:00 2001 From: T0mSIlver Date: Sat, 27 Jun 2026 00:44:46 +0000 Subject: [PATCH] fix(read): truncate long lines at 500 chars as documented read.md states 'Any lines longer than 500 characters will be truncated to 500 characters with ...' but MAX_LINE_LENGTH was 2000, so lines up to 2000 chars passed through untruncated. Set MAX_LINE_LENGTH to 500 to match the documented contract (MAX_LINE, the 2000-line file cap, is correct and unchanged), and add a test covering the truncation length. --- src/fastcontext/agent/tool/read.py | 2 +- tests/test_read_truncation.py | 32 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/test_read_truncation.py diff --git a/src/fastcontext/agent/tool/read.py b/src/fastcontext/agent/tool/read.py index a0caa76..6683a6e 100644 --- a/src/fastcontext/agent/tool/read.py +++ b/src/fastcontext/agent/tool/read.py @@ -6,7 +6,7 @@ from .tool import Tool MAX_LINE = 2000 -MAX_LINE_LENGTH = 2000 +MAX_LINE_LENGTH = 500 class ReadTool(Tool): diff --git a/tests/test_read_truncation.py b/tests/test_read_truncation.py new file mode 100644 index 0000000..12e1621 --- /dev/null +++ b/tests/test_read_truncation.py @@ -0,0 +1,32 @@ +import asyncio +import json +import tempfile +from pathlib import Path + +from fastcontext.agent.tool.read import ReadTool + + +def test_read_truncates_long_lines_at_500(): + """read.md promises lines longer than 500 chars are truncated to 500 with + '...'. Verify the runtime honors that length.""" + read = ReadTool() + with tempfile.TemporaryDirectory() as cwd: + p = Path(cwd) / "long.txt" + p.write_text("a" * 600 + "\n" + "short\n", encoding="utf-8") + + out = asyncio.run(read.call(json.dumps({"path": str(p)}), cwd=cwd)) + + # Exactly 500 chars of the long line survive, with a "..." marker. + assert "a" * 500 in out + assert "a" * 501 not in out + assert "..." in out + # Short lines are passed through untouched. + assert "short" in out + + +def test_read_doc_matches_truncation_length(): + """The documented truncation length must match the implementation.""" + from fastcontext.agent.tool.read import MAX_LINE_LENGTH + + assert MAX_LINE_LENGTH == 500 + assert "500 characters" in ReadTool().description