Skip to content

The agent that grows with you

fix(update): ZIP fallback keeps every nested Desktop/web build output

andrexibiza610f37d775b2
diff --git a/hermes_cli/update_cmd_zip.py b/hermes_cli/update_cmd_zip.py
index 5a981cc0e24..d23e5302813 100644
--- a/hermes_cli/update_cmd_zip.py
+++ b/hermes_cli/update_cmd_zip.py
@@ -24,6 +24,15 @@ _ZIP_STAGING_ARTIFACT_SUFFIXES = ".hermes-update-staging", ".hermes-update-old"
# Single source of truth for entries the ZIP swap preserves — used by the dirty-tree filter and the swap loop.
_ZIP_PRESERVED_TOP_LEVEL = {"venv", ".venv", "node_modules", ".git", ".env"}
+# Gitignored build outputs the source ZIP never ships, nested under top-level entries the swap replaces
+# (so `_ZIP_PRESERVED_TOP_LEVEL` cannot shield them): the packaged Desktop app, its renderer bundle and
+# its own node_modules (electron itself), and the dashboard assets. The dirty-tree guard admits them and
+# `_stage_entries` grafts the live copies into the staged tree so the swap keeps them (#90495).
+_ZIP_PRESERVED_NESTED = {
+ "apps": ("desktop/release", "desktop/dist", "desktop/node_modules"),
+ "hermes_cli": ("web_dist",),
+}
+
_STASH_HINT = " Stash or commit your changes, then rerun `hermes update`."
@@ -157,7 +166,10 @@ def _status_top_level(path: str) -> str:
def _is_zip_preserved_entry_status_line(line: str) -> bool:
- """True when every path on a porcelain status line sits under a preserved top-level entry.
+ """True when every path on a porcelain status line sits under a preserved top-level entry, or the
+ line is a gitignored (``!!``) build output the swap keeps (`_ZIP_PRESERVED_NESTED`) or regenerates
+ (``__pycache__``) — every real install has both, and blocking on them made the ZIP fallback refuse
+ all of them. Tracked edits, renames and other untracked/ignored user files still block.
The ``" -> "`` split applies ONLY to R/C codes: porcelain v1 doesn't quote plain names with spaces, so
``venv -> node_modules`` on a ``!!``/``??`` line is ONE path and splitting would fail-open. Requiring
@@ -165,7 +177,14 @@ def _is_zip_preserved_entry_status_line(line: str) -> bool:
"""
status, payload = (line[:2], line[3:]) if len(line) >= 3 else ("", line)
paths = payload.split(" -> ") if any(code in "RC" for code in status) else [payload]
- return all(_status_top_level(path) in _ZIP_PRESERVED_TOP_LEVEL for path in paths)
+ if all(_status_top_level(path) in _ZIP_PRESERVED_TOP_LEVEL for path in paths):
+ return True
+ if status != "!!":
+ return False
+ path = payload.strip().strip('"').replace("\\", "/").rstrip("/")
+ top, _, nested = path.partition("/")
+ return path.rsplit("/", 1)[-1] == "__pycache__" or any(
+ nested == keep or nested.startswith(f"{keep}/") for keep in _ZIP_PRESERVED_NESTED.get(top, ()))
def _is_zip_staging_artifact_status_line(line: str) -> bool:
@@ -242,6 +261,28 @@ def _require_staging_space(extracted: str, entries: list[str], project_root: str
)
+def _link_or_copy_artifact(source: str, destination: str) -> None:
+ """Hardlink where the filesystem allows (apps/desktop/node_modules is hundreds of MB, and a link stays
+ valid after the swap unlinks the old tree; on Windows a link also succeeds on a locked Hermes.exe
+ where copy2 raises); byte copy otherwise."""
+ try:
+ os.link(source, destination)
+ except OSError:
+ shutil.copy2(source, destination)
+
+
+def _graft_nested_artifacts(item: str, live: str, staging: str) -> None:
+ """Clone the live build outputs under *item* into its staged copy so the swap keeps them.
+ A path the ZIP ships wins over the live copy; a never-built install has nothing to graft."""
+ for nested in _ZIP_PRESERVED_NESTED.get(item, ()):
+ source = os.path.join(live, *nested.split("/"))
+ destination = os.path.join(staging, *nested.split("/"))
+ if os.path.lexists(destination) or not os.path.isdir(source):
+ continue
+ os.makedirs(os.path.dirname(destination), exist_ok=True)
+ shutil.copytree(source, destination, symlinks=True, copy_function=_link_or_copy_artifact)
+
+
def _stage_entries(extracted: str, entries: list[str], project_root: str) -> list[tuple[str, str]]:
"""Phase 1 for every entry; on failure nothing is live yet, so drop partial staging copies so a retry
starts from the same free space."""
@@ -250,17 +291,10 @@ def _stage_entries(extracted: str, entries: list[str], project_root: str) -> lis
for item in entries:
dst = os.path.join(project_root, item)
staged.append((_stage_replacement(os.path.join(extracted, item), dst), dst))
- # The source ZIP lacks apps/desktop/release/ (the BUILT desktop app); swapping `apps` without
- # it deletes the build and breaks the shortcut. Graft the live release dir in BEFORE the swap.
- # #70337/#87331: the GitHub source ZIP contains only source — apps/desktop/release/ (the BUILT
- # desktop app, win-unpacked/ Hermes.exe) exists only in the LIVE tree. Graft the live release
- # dir into the staged copy BEFORE the swap so the commit preserves it atomically.
- if item == "apps":
- live_release = os.path.join(dst, "desktop", "release")
- staged_release = os.path.join(staged[-1][0], "desktop", "release")
- if os.path.isdir(live_release) and not os.path.exists(staged_release):
- os.makedirs(os.path.dirname(staged_release), exist_ok=True)
- shutil.copytree(live_release, staged_release)
+ # The source ZIP carries only source; the built outputs (#70337/#87331 release/, then
+ # dist/, apps/desktop/node_modules and web_dist — #90495) exist only in the LIVE tree. Graft
+ # them into the staged copy BEFORE the swap so the commit preserves them atomically.
+ _graft_nested_artifacts(item, dst, staged[-1][0])
except Exception:
_discard_staged(staged)
raise
diff --git a/tests/hermes_cli/test_update_zip_release_preserve.py b/tests/hermes_cli/test_update_zip_release_preserve.py
index 61478821a7b..4cc8e8c2c27 100644
--- a/tests/hermes_cli/test_update_zip_release_preserve.py
+++ b/tests/hermes_cli/test_update_zip_release_preserve.py
@@ -1,8 +1,11 @@
-"""#70337/#87331: the ZIP swap must preserve apps/desktop/release/.
+"""#70337/#87331/#90495: the ZIP swap must preserve the gitignored build outputs.
The GitHub source ZIP carries only source; the BUILT desktop app
-(release/win-unpacked/Hermes.exe) exists only in the live tree. Swapping
-`apps` without grafting the live release dir deletes the desktop build.
+(release/win-unpacked/Hermes.exe), its renderer bundle (dist/), its own
+node_modules and the dashboard assets (hermes_cli/web_dist/) exist only in
+the live tree. Swapping `apps` / `hermes_cli` without grafting them deletes
+them — and the dirty-tree guard must admit their ``!!`` status lines, or the
+fallback refuses every install that has them.
"""
from __future__ import annotations
@@ -54,3 +57,51 @@ def test_staged_apps_swap_preserves_live_release_dir(tmp_path, monkeypatch):
)
exe = root / "apps" / "desktop" / "release" / "win-unpacked" / "Hermes.exe"
assert exe.exists() and exe.read_bytes() == b"MZbuilt"
+
+
+def test_zip_swap_keeps_every_nested_build_output_and_the_guard_admits_them(tmp_path):
+ from hermes_cli.update_cmd_zip import (
+ _commit_staged_replacements,
+ _is_zip_preserved_entry_status_line,
+ _stage_entries,
+ )
+
+ root = tmp_path / "install"
+ outputs = {
+ "apps/desktop/release/win-unpacked/Hermes.exe": b"MZbuilt",
+ "apps/desktop/node_modules/electron/index.js": b"electron",
+ "apps/desktop/dist/index.html": b"live renderer",
+ "hermes_cli/web_dist/index.html": b"<dashboard>",
+ }
+ for rel, data in outputs.items():
+ (root / rel).parent.mkdir(parents=True)
+ (root / rel).write_bytes(data)
+ (root / "hermes_cli" / "__pycache__").mkdir()
+ (root / "hermes_cli" / "x.py").write_text("old")
+
+ # Extracted ZIP: new source, none of the outputs — except dist/, which a future archive may ship.
+ extracted = tmp_path / "extracted"
+ (extracted / "apps" / "desktop" / "dist").mkdir(parents=True)
+ (extracted / "apps" / "desktop" / "dist" / "index.html").write_bytes(b"shipped renderer")
+ (extracted / "hermes_cli").mkdir()
+ (extracted / "hermes_cli" / "x.py").write_text("new")
+
+ _commit_staged_replacements(_stage_entries(str(extracted), ["apps", "hermes_cli"], str(root)))
+
+ assert (root / "hermes_cli" / "x.py").read_text() == "new"
+ for rel, data in outputs.items():
+ if rel.startswith("apps/desktop/dist/"):
+ continue
+ assert (root / rel).read_bytes() == data, rel
+ # What the ZIP ships wins over the live copy; the graft never clobbers it.
+ assert (root / "apps" / "desktop" / "dist" / "index.html").read_bytes() == b"shipped renderer"
+ assert not (root / "hermes_cli" / "__pycache__").exists() # regenerable, dropped with the old tree
+
+ # The dirty-tree guard sees these outputs as ``!!`` lines; they must not refuse the swap.
+ for line in ("!! apps/desktop/release/", "!! apps/desktop/dist/", "!! apps/desktop/node_modules/",
+ "!! hermes_cli/web_dist/", "!! hermes_cli/__pycache__/", "!! __pycache__/"):
+ assert _is_zip_preserved_entry_status_line(line), line
+ # ...while other gitignored data, untracked files and renames into those dirs still block.
+ for line in ("!! apps/desktop/notes.local", "?? apps/desktop/release/", "!! hermes_cli/web_dist_backup/",
+ "R src/x -> apps/desktop/release/x"):
+ assert not _is_zip_preserved_entry_status_line(line), line