From 19465f36c5b57f3a5fe1a99750ae6a2362030e3b Mon Sep 17 00:00:00 2001 From: 86cloudyun-afk <86cloudyun@gmail.com> Date: Tue, 21 Apr 2026 20:50:32 +0800 Subject: [PATCH] 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 --- agent/copilot_acp_client.py | 2 +- tests/agent/test_copilot_acp_client.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/agent/copilot_acp_client.py b/agent/copilot_acp_client.py index 783f949567..02a5d00b10 100644 --- a/agent/copilot_acp_client.py +++ b/agent/copilot_acp_client.py @@ -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 diff --git a/tests/agent/test_copilot_acp_client.py b/tests/agent/test_copilot_acp_client.py index 52ad20a350..1805a43ce3 100644 --- a/tests/agent/test_copilot_acp_client.py +++ b/tests/agent/test_copilot_acp_client.py @@ -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"