diff --git a/agent/copilot_acp_client.py b/agent/copilot_acp_client.py index 94d40d2d9..105d3460a 100644 --- a/agent/copilot_acp_client.py +++ b/agent/copilot_acp_client.py @@ -602,7 +602,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 63c87fdab..995b32e80 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"