The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
chore(scratch): BOM-tolerant reads in the scratch prune and its tests
Teknium0c4350993e01
diff --git a/hermes_constants_scratch.py b/hermes_constants_scratch.pyindex 20a6bb51d93..3991b8d38ea 100644--- a/hermes_constants_scratch.py+++ b/hermes_constants_scratch.py@@ -299,7 +299,7 @@ def _linked_worktree_repos(entry: Path) -> set[str]:for child in it:if child.name == ".git" and child.is_file(follow_symlinks=False):try:- line = Path(child.path).read_text(encoding="utf-8", errors="replace").strip()+ line = Path(child.path).read_text(encoding="utf-8-sig", errors="replace").strip()except OSError:continueif line.startswith("gitdir:"):diff --git a/tests/test_scratch_dir.py b/tests/test_scratch_dir.pyindex 952cea6a219..aa8ade9a663 100644--- a/tests/test_scratch_dir.py+++ b/tests/test_scratch_dir.py@@ -422,7 +422,7 @@ def test_write_during_size_walk_is_rescued(tmp_path: Path) -> None:with patch("hermes_constants_scratch._tree_bytes", write_during_size_walk):assert prune_scratch_dir(scratch) == 0- assert payload.read_text(encoding="utf-8") == "FRESH", "write during size walk was destroyed"+ assert payload.read_text(encoding="utf-8-sig") == "FRESH", "write during size walk was destroyed"log = (tmp_path / "logs" / "scratch-prune.log").read_text(encoding="utf-8-sig")assert f"rescued {str(entry)!r} " in log, log@@ -484,7 +484,7 @@ def test_midprune_nested_overwrite_is_rescued_by_descending_recheck(tmp_path: Pawith patch("hermes_constants_scratch.reap_processes_rooted_in", overwrite_during_reap):assert prune_scratch_dir(scratch) == 0 # rescued — not counted as removed- assert payload.read_text(encoding="utf-8") == "FRESH OVERWRITE, DEEP\n", (+ assert payload.read_text(encoding="utf-8-sig") == "FRESH OVERWRITE, DEEP\n", ("deep mid-prune overwrite was destroyed")assert entry.exists()@@ -556,7 +556,7 @@ def test_postremoval_unreadable_entry_is_not_counted_as_removed(tmp_path: Path)patch("hermes_constants_scratch.shutil.rmtree", rmtree_leaves_residue), \patch("hermes_constants_scratch.os.lstat", lstat):assert prune_scratch_dir(scratch) == 0 # unknown, not removed- assert entry.exists() and payload.read_text(encoding="utf-8") == "still here"+ assert entry.exists() and payload.read_text(encoding="utf-8-sig") == "still here"log = log_file.read_text(encoding="utf-8-sig")assert f"removed {str(entry)!r} (" not in log, logassert "could not confirm removal" in log, log@@ -585,7 +585,7 @@ def test_prune_keeps_entry_a_registered_hermes_process_works_in_but_reaps_orphancwd=str(orphan_dir))def _lane_done():registry.poll(lane.id)- return lane.exited and pidfile.exists() and pidfile.read_text().strip()+ return lane.exited and pidfile.exists() and pidfile.read_text(encoding="utf-8-sig").strip()orphan = int(wait_until(_lane_done, timeout=15, what="lane shell exits after forking its orphan"))ancient = time.time() - 30 * 3600for path in (owned_dir, orphan_dir):