fix(copilot-acp): honor line=1 pagination for read_text_file

Apply fs/read_text_file pagination when line is 1 so first-page requests return the requested slice instead of the whole file.

Fixes #13451
This commit is contained in:
86cloudyun-afk 2026-04-21 20:50:32 +08:00
parent c6974043ef
commit 19465f36c5
2 changed files with 20 additions and 1 deletions

View file

@ -560,7 +560,7 @@ class CopilotACPClient:
content = path.read_text() if path.exists() else ""
line = params.get("line")
limit = params.get("limit")
if isinstance(line, int) and line > 1:
if isinstance(line, int) and line >= 1:
lines = content.splitlines(keepends=True)
start = line - 1
end = start + limit if isinstance(limit, int) and limit > 0 else None

View file

@ -94,6 +94,25 @@ class CopilotACPClientSafetyTests(unittest.TestCase):
self.assertNotIn("abc123def456", content)
self.assertIn("OPENAI_API_KEY=", content)
def test_read_text_file_honors_first_page_pagination(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
root = Path(tmpdir)
text_file = root / "sample.txt"
text_file.write_text("one\ntwo\nthree\n")
response = self._dispatch(
{
"jsonrpc": "2.0",
"id": 33,
"method": "fs/read_text_file",
"params": {"path": str(text_file), "line": 1, "limit": 1},
},
cwd=str(root),
)
content = ((response.get("result") or {}).get("content") or "")
self.assertEqual(content, "one\n")
def test_write_text_file_reuses_write_denylist(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
home = Path(tmpdir) / "home"