Skip to content

Commit 902c599

Browse files
authored
fix: tighten LocalSnapshot restorable checks (#2975)
1 parent 5515283 commit 902c599

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/agents/sandbox/snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def restore(self, *, dependencies: Dependencies | None = None) -> io.IOBas
121121

122122
async def restorable(self, *, dependencies: Dependencies | None = None) -> bool:
123123
_ = dependencies
124-
return self._path().exists()
124+
return self._path().is_file()
125125

126126
def _path(self) -> Path:
127127
return self.base_path / self._filename()

tests/sandbox/test_snapshot.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ def test_snapshot_exclude_unset_preserves_type_discriminator() -> None:
158158
}
159159

160160

161+
@pytest.mark.asyncio
162+
async def test_local_snapshot_restorable_requires_file(tmp_path: Path) -> None:
163+
snapshot = LocalSnapshot(id="local-snapshot", base_path=tmp_path)
164+
snapshot_path = tmp_path / "local-snapshot.tar"
165+
166+
assert await snapshot.restorable() is False
167+
168+
snapshot_path.mkdir()
169+
170+
assert await snapshot.restorable() is False
171+
172+
snapshot_path.rmdir()
173+
snapshot_path.write_bytes(b"workspace")
174+
175+
assert await snapshot.restorable() is True
176+
177+
161178
def test_snapshot_parse_uses_registered_custom_snapshot_type() -> None:
162179
parsed = SnapshotBase.parse({"type": "test-noop", "id": "registered"})
163180

0 commit comments

Comments
 (0)