Skip to content

The agent that grows with you

fix: bind baseline reads to the task local path

teknium1602e76a88b36
diff --git a/tests/tools/test_file_read_guards.py b/tests/tools/test_file_read_guards.py
index 9331759f613..4b03076dab1 100644
--- a/tests/tools/test_file_read_guards.py
+++ b/tests/tools/test_file_read_guards.py
@@ -49,7 +49,7 @@ class _FakeReadResult:
def _make_fake_ops(content="hello\n", total_lines=1, file_size=6):
- fake = MagicMock()
+ fake = MagicMock(env=None)
fake.read_file = lambda path, offset=1, limit=500: _FakeReadResult(
content=content, total_lines=total_lines, file_size=file_size,
)
@@ -445,7 +445,7 @@ class TestFileDedup(unittest.TestCase):
@patch("tools.file_tools._get_file_ops")
def test_write_rejects_internal_read_status_text(self, mock_ops):
"""write_file must not persist internal read_file status text."""
- fake = MagicMock()
+ fake = MagicMock(env=None)
fake.write_file = MagicMock()
mock_ops.return_value = fake
@@ -806,7 +806,7 @@ class TestWriteInvalidatesDedup(unittest.TestCase):
read would previously cause the second read to return a stale dedup
stub because the mtime comparison saw no change.
"""
- fake = MagicMock()
+ fake = MagicMock(env=None)
fake.read_file = lambda path, offset=1, limit=500: _FakeReadResult(
content="original content\n", total_lines=1, file_size=18,
)
@@ -835,7 +835,7 @@ class TestWriteInvalidatesDedup(unittest.TestCase):
@patch("tools.file_tools._get_file_ops")
def test_write_invalidates_all_offsets(self, mock_ops):
"""A write invalidates dedup entries for ALL offset/limit combos."""
- fake = MagicMock()
+ fake = MagicMock(env=None)
fake.read_file = lambda path, offset=1, limit=500: _FakeReadResult(
content="line1\nline2\nline3\n", total_lines=3, file_size=20,
)
diff --git a/tests/tools/test_file_staleness.py b/tests/tools/test_file_staleness.py
index cb580aee62c..ce3495e4640 100644
--- a/tests/tools/test_file_staleness.py
+++ b/tests/tools/test_file_staleness.py
@@ -57,7 +57,7 @@ class _FakePatchResult:
def _make_fake_ops(read_content="hello\n", file_size=6):
- fake = MagicMock()
+ fake = MagicMock(env=None)
fake.read_file = lambda path, offset=1, limit=500: _FakeReadResult(
content=read_content, total_lines=1, file_size=file_size,
)
diff --git a/tools/file_tools.py b/tools/file_tools.py
index 174a23d0259..9985643121f 100644
--- a/tools/file_tools.py
+++ b/tools/file_tools.py
@@ -675,7 +675,7 @@ def read_file_tool(path: str, offset: int = 1, limit: int = DEFAULT_READ_LIMIT,
and version_before == cached_version and content_served_in_generation):
return _dedup_stub_or_block(task_data, dedup_key, path)
- result = file_ops.read_file(path, offset, limit)
+ result = file_ops.read_file(resolved_str if _file_ops_uses_host_paths(file_ops) else path, offset, limit)
result_dict = result.to_dict()
# Failed reads cannot establish whole-file knowledge.
diff --git a/tools/file_tools_read_tracking.py b/tools/file_tools_read_tracking.py
index 10475c6a7ac..80dcdb1418d 100644
--- a/tools/file_tools_read_tracking.py
+++ b/tools/file_tools_read_tracking.py
@@ -255,7 +255,7 @@ def _file_version(resolved: str) -> tuple | None:
try:
if not stat.S_ISREG(os.stat(resolved).st_mode):
return None
- fd = os.open(resolved, os.O_RDONLY | getattr(os, "O_NONBLOCK", 0))
+ fd = os.open(resolved, os.O_RDONLY | getattr(os, "O_NONBLOCK", 0) | getattr(os, "O_BINARY", 0))
with os.fdopen(fd, "rb") as stream:
before = os.fstat(stream.fileno())
if not stat.S_ISREG(before.st_mode):