refactor(files): remove redundant edit and snapshot state
This commit is contained in:
1 parent
721cc4e23f
commit
51884a244e
6 files changed
+47
-61
No files matched your search
@@ -141,11 +141,11 @@ def test_apply_patch_edits_add_to_existing_crlf_file_without_final_newline(tmp_p
|
||||
assert target.read_bytes() == b"alpha\r\nbravo\r\ncharlie\r\n"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("existing", [False, True], ids=["new-file", "existing-crlf"])
|
||||
def test_apply_patch_replaces_text_from_an_earlier_edit_in_the_batch(tmp_path, existing):
|
||||
@pytest.mark.parametrize("original", [None, b"", b"alpha\r\nbravo"], ids=["new", "empty", "crlf"])
|
||||
def test_apply_patch_replaces_text_from_an_earlier_edit_in_the_batch(tmp_path, original):
|
||||
target = tmp_path / "notes.txt"
|
||||
if existing:
|
||||
target.write_bytes(b"alpha\r\nbravo")
|
||||
if original is not None:
|
||||
target.write_bytes(original)
|
||||
tool = ApplyPatchTool(workspace=tmp_path)
|
||||
|
||||
result = asyncio.run(tool.execute(edits=[
|
||||
@@ -155,8 +155,8 @@ def test_apply_patch_replaces_text_from_an_earlier_edit_in_the_batch(tmp_path, e
|
||||
|
||||
assert result.startswith("Patch applied:\n")
|
||||
assert result.count("notes.txt") == 1
|
||||
assert f"{'update' if existing else 'add'} notes.txt" in result
|
||||
assert target.read_bytes() == (b"alpha\r\nbravo\r\ndelta\r\n" if existing else b"delta\n")
|
||||
assert f"{'add' if original is None else 'update'} notes.txt" in result
|
||||
assert target.read_bytes() == (b"alpha\r\nbravo\r\ndelta\r\n" if original else b"delta\n")
|
||||
|
||||
|
||||
def test_apply_patch_rejects_delete_action(tmp_path):
|
||||
|
||||
@@ -256,7 +256,6 @@ def test_binary_file_is_reported_but_not_counted(tmp_path: Path) -> None:
|
||||
params={"path": "data.bin", "old_text": "before", "new_text": "after"},
|
||||
)
|
||||
[tracker] = trackers
|
||||
assert not tracker.before.countable
|
||||
target.write_bytes(b"\x00\x01after")
|
||||
event = build_file_edit_end_event(tracker)
|
||||
assert event["binary"] is True
|
||||
@@ -264,9 +263,15 @@ def test_binary_file_is_reported_but_not_counted(tmp_path: Path) -> None:
|
||||
assert "diff" not in event
|
||||
|
||||
|
||||
def test_binary_before_file_is_reported_but_not_counted(tmp_path: Path) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"before", [b"\x00\x01before", b"text\n" * 20], ids=["binary", "oversized"],
|
||||
)
|
||||
def test_unavailable_before_is_reported_but_not_counted(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, before: bytes,
|
||||
) -> None:
|
||||
monkeypatch.setattr("nanobot.utils.file_edit_events._MAX_SNAPSHOT_BYTES", 64)
|
||||
target = tmp_path / "data.bin"
|
||||
target.write_bytes(b"\x00\x01before")
|
||||
target.write_bytes(before)
|
||||
trackers = prepare_file_edit_trackers(
|
||||
call_id="call-bin",
|
||||
tool_name="write_file",
|
||||
|
||||
Reference in new issue
Block a user