The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): gitignored user files also block the ZIP overlay
joaomarcose64db7698290
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 1b2633d0ba7..329aab645ac 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -1603,7 +1603,10 @@ def _zip_overlay_block_reason(result = subprocess.run(# -uall: a user-level ``status.showUntrackedFiles = no`` git config# would otherwise hide untracked files and silently blind this guard.- git_cmd + ["status", "--porcelain", "--untracked-files=all"],+ # --ignored=all: gitignored files are still USER DATA the ZIP overlay+ # would permanently delete (logs, local venvs, scratch files) — a+ # .gitignore entry must not blind the guard either (#87392).+ git_cmd + ["status", "--porcelain", "--untracked-files=all", "--ignored=all"],cwd=root,capture_output=True,text=True,@@ -1615,6 +1618,11 @@ def _zip_overlay_block_reason(suffix = f" ({detail[0]})" if detail else ""return f"could not check the working tree{suffix}"lines = [line for line in (result.stdout or "").splitlines() if line.strip()]+ # --ignored=all reports the ZIP path's own preserved entries (venv,+ # node_modules are gitignored on every normal install). The swap never+ # touches those top-level entries, so they must not turn into a false+ # dirty-tree refusal. Everything else — including ignored files — blocks.+ lines = [line for line in lines if not _is_zip_preserved_entry_status_line(line)]if ignore_staging_artifacts:lines = [line for line in lines if not _is_zip_staging_artifact_status_line(line)@@ -1625,6 +1633,22 @@ def _zip_overlay_block_reason(_ZIP_STAGING_ARTIFACT_SUFFIXES = (".hermes-update-staging", ".hermes-update-old")+# Keep in sync with the `preserve` set in _update_via_zip's swap loop.+_ZIP_PRESERVED_TOP_LEVEL = {"venv", "node_modules", ".git", ".env"}+++def _is_zip_preserved_entry_status_line(line: str) -> bool:+ """True when every path on a porcelain status line sits under a top-level+ entry the ZIP swap preserves (rename lines carry two paths)."""+ payload = line[3:] if len(line) >= 3 else line+ paths = payload.split(" -> ")+ for path in paths:+ top_level = (+ path.strip().strip('"').replace("\\", "/").rstrip("/").split("/", 1)[0]+ )+ if top_level not in _ZIP_PRESERVED_TOP_LEVEL:+ return False+ return Truedef _is_zip_staging_artifact_status_line(line: str) -> bool:diff --git a/tests/hermes_cli/test_update_zip_fallback_guards.py b/tests/hermes_cli/test_update_zip_fallback_guards.pyindex 8b6bc426f7e..595c66a2fae 100644--- a/tests/hermes_cli/test_update_zip_fallback_guards.py+++ b/tests/hermes_cli/test_update_zip_fallback_guards.py@@ -247,3 +247,44 @@ def test_recheck_still_blocks_user_files_amid_staging_artifacts(tmp_path, monkeytmp_path, ignore_staging_artifacts=True)assert reason is not None+++def test_zip_overlay_blocked_on_ignored_user_file(tmp_path, monkeypatch):+ """#87392 follow-up: a gitignored file outside the preserved entries is+ still user data the overlay would delete — it must block."""+ (tmp_path / ".git").mkdir()+ monkeypatch.setattr(+ update_cmd.subprocess, "run", _porcelain_run("!! scratch/notes.local\n")+ )+ reason = update_cmd._zip_overlay_block_reason(tmp_path)+ assert reason is not None+ assert "uncommitted" in reason or "untracked" in reason+++def test_zip_overlay_requests_ignored_files_from_git(tmp_path, monkeypatch):+ """The status invocation itself must carry --ignored=all."""+ seen = {}++ def capture_run(cmd, **kwargs):+ joined = " ".join(str(c) for c in cmd)+ if "status" in joined and "--porcelain" in joined:+ seen["cmd"] = cmd+ return subprocess.CompletedProcess(cmd, 0, stdout="", stderr="")+ return subprocess.CompletedProcess(cmd, 0, stdout="", stderr="")++ (tmp_path / ".git").mkdir()+ monkeypatch.setattr(update_cmd.subprocess, "run", capture_run)+ update_cmd._zip_overlay_block_reason(tmp_path)+ assert "--ignored=all" in [str(c) for c in seen["cmd"]]+++def test_zip_overlay_allows_ignored_preserved_entries(tmp_path, monkeypatch):+ """venv/node_modules are gitignored on every normal install and the swap+ preserves them — --ignored=all must not turn them into a false refusal."""+ (tmp_path / ".git").mkdir()+ monkeypatch.setattr(+ update_cmd.subprocess,+ "run",+ _porcelain_run("!! venv/\n!! node_modules/\n!! .env\n"),+ )+ assert update_cmd._zip_overlay_block_reason(tmp_path) is None