Guard file handles and streamline scoped search

This commit is contained in:
Xubin Ren committed 2026-11-14 22:09:21 +08:00
1 parent 51884a244e
commit 5c7ff5b796
6 files changed
+137 -78

No files matched your search

+6 -7
View File
@@ -1,11 +1,11 @@
from __future__ import annotations
import asyncio
from pathlib import Path
import pytest
from nanobot.agent.tools.apply_patch import ApplyPatchTool
from nanobot.execution.files import WritableFile
def test_apply_patch_edits_replace(tmp_path):
@@ -472,18 +472,17 @@ def test_apply_patch_edits_rolls_back_when_later_write_fails(tmp_path, monkeypat
second_original = b"before\r\nsecond tail"
second.write_bytes(second_original)
tool = ApplyPatchTool(workspace=tmp_path)
write_text = Path.write_text
write = WritableFile.write
failed = False
def _fail_second_write(path, *args, **kwargs):
def _fail_second_write(target, *args, **kwargs):
nonlocal failed
written = write_text(path, *args, **kwargs)
if path == second and not failed:
write(target, *args, **kwargs)
if target.path == second.resolve() and not failed:
failed = True
raise OSError("injected second write failure")
return written
monkeypatch.setattr(Path, "write_text", _fail_second_write)
monkeypatch.setattr(WritableFile, "write", _fail_second_write)
result = asyncio.run(
tool.execute(