The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): the ZIP pre-commit gate holds a newer-Python target to the conflict-marker check
Teknium3d4283e465e6
diff --git a/hermes_cli/update_cmd_zip.py b/hermes_cli/update_cmd_zip.pyindex d87f0a23e78..15580b3dcca 100644--- a/hermes_cli/update_cmd_zip.py+++ b/hermes_cli/update_cmd_zip.py@@ -448,15 +448,20 @@ def _journaled_stage_and_swap(extracted: str, entries: list[str], root: Path, taprint(" Files appeared in the checkout while the update was downloading; committing the swap would delete them.")print(_STASH_HINT)_m().sys.exit(1)- # Pre-commit gate: a target whose startup modules do not compile is refused untouched- # (unless it requires a Python this interpreter is not: its syntax is not ours to judge).+ # Pre-commit gate: a target whose startup modules do not compile is refused untouched. A+ # target that requires a Python this interpreter is not may use syntax this compile() cannot+ # judge; it is still held to ``conflict_marker``, which is broken under every Python.pyproject = Path(extracted, "pyproject.toml")newer_python = pyproject.is_file() and _commit.requires_other_python(pyproject.read_bytes())- for rel in () if newer_python else _UPDATE_CRITICAL_FILES:+ for rel in _UPDATE_CRITICAL_FILES:path = os.path.join(extracted, *rel.split("/"))if os.path.isfile(path):with open(path, "rb") as handle:- compile(handle.read(), rel, "exec", dont_inherit=True)+ source = handle.read()+ if not newer_python:+ compile(source, rel, "exec", dont_inherit=True)+ elif reason := _commit.conflict_marker(source):+ raise SyntaxError(f"{rel}: {reason}")# The commit point: tail + fleet restart owed before the first live rename._commit.arm_commit_obligations(root, target_sha or "")write_zip_swap_journal(root, "swapping", journal_entries)diff --git a/tests/hermes_cli/test_update_zip_two_phase.py b/tests/hermes_cli/test_update_zip_two_phase.pyindex d67df7a268c..b6085960013 100644--- a/tests/hermes_cli/test_update_zip_two_phase.py+++ b/tests/hermes_cli/test_update_zip_two_phase.py@@ -617,3 +617,28 @@ def test_a_backup_copy_killed_before_its_rename_is_cleared_by_the_recovery(tmp_passert not (live / ZIP_SWAP_JOURNAL).exists()assert sorted(p.name for p in live.iterdir() if not p.name.endswith(".lock")) == ["a.py"]assert (live / "a.py").read_text(encoding="utf-8") == "old\n"++[email protected]("requires", [">=3.8", ">=3.99"])+def test_the_zip_gate_never_admits_a_conflict_marker_even_for_a_newer_python(tmp_path, monkeypatch, requires):+ """A release whose requires-python excludes this interpreter skipped the ZIP pre-commit gate+ entirely, so a startup module with a merge-conflict marker (broken under EVERY Python) was+ swapped in (review C5). Its syntax may be a newer Python's, the marker never is."""+ from hermes_cli import update_cmd_commit++ armed = []+ monkeypatch.setattr(update_cmd_commit, "arm_commit_obligations", lambda *a, **k: armed.append(a))+ live, extracted = tmp_path / "live", tmp_path / "extracted"+ (live / "hermes_cli").mkdir(parents=True)+ (live / "hermes_cli" / "main.py").write_text("OLD = 1\n", encoding="utf-8")+ (extracted / "hermes_cli").mkdir(parents=True)+ (extracted / "hermes_cli" / "main.py").write_text(+ "<<<<<<< HEAD\nA = 1\n=======\nA = 2\n>>>>>>> branch\n", encoding="utf-8")+ (extracted / "pyproject.toml").write_text(+ f'[project]\nname = "x"\nrequires-python = "{requires}"\n', encoding="utf-8")++ with pytest.raises(SyntaxError):+ update_cmd_zip._journaled_stage_and_swap(str(extracted), ["hermes_cli", "pyproject.toml"], live, None)++ assert not armed # refused before the commit point+ assert (live / "hermes_cli" / "main.py").read_text(encoding="utf-8") == "OLD = 1\n"