The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a ZIP archive that does not name its commit is refused before the swap
Teknium4cf84b0c83cc
diff --git a/hermes_cli/update_cmd_zip.py b/hermes_cli/update_cmd_zip.pyindex 1fcc24cce99..f50d44ad8ac 100644--- a/hermes_cli/update_cmd_zip.py+++ b/hermes_cli/update_cmd_zip.py@@ -528,7 +528,7 @@ def _journaled_stage_and_swap(extracted: str, entries: list[str], root: Path, tadef _download_and_swap_zip(branch: str, zip_url: str, target_sha: str | None = None) -> Optional[str]:"""Download the source ZIP for *branch* and two-phase swap it into the checkout; return the commit it- installed (``target_sha``, else the archive's own, else None).+ installed: the archive's own, which must equal ``target_sha`` when one is pinned.``sys.exit(1)`` on any failure; the install ends fully updated or fully rolled back.Two-phase: stage every entry (dirs AND top-level files) beside its target, then swap all in withsame-filesystem renames, rolling back on failure — one-at-a-time replacement left a mixed, unbootable@@ -542,11 +542,15 @@ def _download_and_swap_zip(branch: str, zip_url: str, target_sha: str | None = Ntry:zip_path = os.path.join(tmp_dir, f"hermes-agent-{branch}.zip")urlretrieve(zip_url, zip_path)- # An unpinned branch ZIP still names its commit; without it the restart debt is armed for ''- # and can never be proven discharged.- target_sha = target_sha or _archive_commit(zip_path)print("→ Extracting...")_extract_zip_safely(zip_path, tmp_dir)+ # The installed identity comes from the downloaded bytes (``git archive``'s comment), pinned or+ # not: without it the restart debt is armed for '' and can never be proven discharged (S4).+ archived = _archive_commit(zip_path)+ if archived is None or (target_sha and archived != target_sha):+ raise ValueError(f"the archive names commit {archived or 'none'}, not "+ f"{target_sha or 'a full commit SHA'}; refusing to install unidentified bytes")+ target_sha = archivedextracted = _extracted_root(tmp_dir, branch)entries = [i for i in os.listdir(extracted) if i not in _ZIP_PRESERVED_TOP_LEVEL]project_root = str(_m().PROJECT_ROOT)diff --git a/tests/hermes_cli/test_update_zip_completion.py b/tests/hermes_cli/test_update_zip_completion.pyindex 42fe31b6deb..ab940ec910f 100644--- a/tests/hermes_cli/test_update_zip_completion.py+++ b/tests/hermes_cli/test_update_zip_completion.py@@ -58,6 +58,7 @@ def zip_update(tmp_path, monkeypatch, isolated_source_completion):for name in ("new-entry/data", "tools/code.py", "apps/desktop/source.js","venv/keep", "node_modules/keep", ".env"):out.writestr("hermes-agent-main/" + name, "new")+ out.comment = b"8192da90e0afb20010a1c2f5da83db305d05ac5a" # git archive's commit identity# Only redirect transport: extraction, staging, dirty recheck and swap run.monkeypatch.setattr("urllib.request.urlretrieve", lambda url, dst: urlretrieve(archive.as_uri(), dst))monkeypatch.setattr(main, "PROJECT_ROOT", root)@@ -461,3 +462,29 @@ def test_unpinned_zip_update_owes_the_restart_for_the_archive_commit(tmp_path, massert (root / "payload.txt").read_text(encoding="utf-8-sig") == "new"assert armed == [sha]assert [request["expected_sha"] for request in completed] == [sha]++[email protected](("comment", "pinned"), [+ (b"", None), (b"main", None), (b"a" * 40, "c" * 40), (b"", "c" * 40)])+def test_a_zip_that_does_not_name_its_commit_is_refused_before_the_swap(tmp_path, monkeypatch, comment, pinned):+ """S4: the installed identity must come from the downloaded bytes (``git archive``'s ZIP comment).+ No comment, a malformed one, or one naming another commit than the pinned target: no live rename,+ no obligation armed, never an empty durable SHA."""+ from hermes_cli import update_cmd_commit++ root = tmp_path / "checkout"+ root.mkdir()+ (root / "payload.txt").write_text("old", encoding="utf-8")+ archive = tmp_path / "source.zip"+ with zipfile.ZipFile(archive, "w") as out:+ out.writestr("hermes-agent-main/payload.txt", "new")+ out.comment = comment+ monkeypatch.setattr("urllib.request.urlretrieve", lambda url, dst: urlretrieve(archive.as_uri(), dst))+ monkeypatch.setattr(main, "PROJECT_ROOT", root)+ armed = []+ monkeypatch.setattr(update_cmd_commit, "arm_commit_obligations", lambda _root, expected: armed.append(expected))+ with pytest.raises(SystemExit) as error:+ update_cmd_zip._download_and_swap_zip("main", "local fixture", pinned)+ assert error.value.code == 1+ assert (root / "payload.txt").read_text(encoding="utf-8") == "old"+ assert armed == []diff --git a/tests/hermes_cli/test_update_zip_symlink_reject.py b/tests/hermes_cli/test_update_zip_symlink_reject.pyindex 91a2a669f30..b6e9d021869 100644--- a/tests/hermes_cli/test_update_zip_symlink_reject.py+++ b/tests/hermes_cli/test_update_zip_symlink_reject.py@@ -31,6 +31,7 @@ def _build_normal_zip(zip_path: str) -> None:"""Write a regular ZIP with a normal file member (no symlink)."""with zipfile.ZipFile(zip_path, "w") as zf:zf.writestr("hermes-agent-main/README.md", "ok\n")+ zf.comment = b"8192da90e0afb20010a1c2f5da83db305d05ac5a" # git archive's commit identitydef test_update_via_zip_rejects_symlink_member(tmp_path, monkeypatch):