The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): hand the admitted checkout back after flavored icon staging
ethernet80234bc38bceec46
diff --git a/scripts/bundles/desktop.py b/scripts/bundles/desktop.pyindex 64840ec6621..aebe46450d5 100644--- a/scripts/bundles/desktop.py+++ b/scripts/bundles/desktop.py@@ -7,6 +7,7 @@ import osimport shutilimport subprocessimport sys+from contextlib import contextmanagerfrom pathlib import PathROOT = Path(__file__).resolve().parents[2]@@ -23,6 +24,33 @@ def capture(argv: list[str], repo: Path, env: dict[str, str]) -> str:return subprocess.check_output(argv, cwd=repo, env=env, text=True, encoding="utf-8").strip()+@contextmanager+def flavored_assets(icons: Path, assets: Path):+ """Hold the flavored icon set at its workspace path for the packaging window.++ electron-builder resolves every piece of packaging artwork from the+ workspace — the app icon, the icon.ico extraResource, the MSIX logo set+ before-build stages into build/appx, and the exe identity stamp — so a+ flavored (canary/commit) build cannot package from the rendered product+ directory alone. Restore the admitted files once packaging ends: the source+ custody check refuses a dirty checkout, and a build that leaves its own+ render behind breaks every later build in that tree and `hermes update`.+ """+ admitted = {path.relative_to(assets): path.read_bytes()+ for path in assets.rglob("*") if path.is_file()}+ try:+ shutil.copytree(icons, assets, dirs_exist_ok=True)+ yield+ finally:+ for path in assets.rglob("*"):+ if path.is_file() and path.relative_to(assets) not in admitted:+ path.unlink()+ for relative, data in admitted.items():+ path = assets / relative+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_bytes(data)++def release_version(_repo: Path, tag: str) -> str:from scripts.termux.deb_version import channel_for_tag@@ -90,19 +118,22 @@ def _build_prepared(prepared, builder_args: list[str], variant: str | None) -> Nraise RuntimeError("prepared payload assembly failed")from scripts.bundles.desktop_prepare import require_sourcerequire_source(repo, request.commit)- shutil.copytree(icons / "apps/desktop/assets", desktop / "assets", dirs_exist_ok=True)- run([node, "scripts/write-build-stamp.mjs"], cwd=desktop, env=env)- run([node, "scripts/build/desktop.mjs", "--source", str(repo), "--icons", str(icons),- "--stamp", str(desktop / "build/install-stamp.json"), "--native-deps", str(prepared.native),- "--out", str(desktop / "dist")], cwd=repo, env=env)- version_args = []- if sys.platform == "win32" and request.channel_request is None and request.tag is not None:- script = "const m=require('./scripts/msix-shared.mjs');console.log(m.nativeQuad(process.argv[1], Number(process.env.HERMES_RELEASE_EPOCH)))"- quad = capture([node, "-e", script, request.tag], repo, env)- version_args = [f'-c.extraMetadata.shortVersion={quad}', f'-c.extraMetadata.shortVersionWindows={quad}']+ # The admitted checkout stays clean across the whole build: packaging reads+ # its artwork from the workspace, so the render lives there only while+ # electron-builder holds it, and the final check proves it was handed back.+ with flavored_assets(icons / "apps/desktop/assets", desktop / "assets"):+ run([node, "scripts/write-build-stamp.mjs"], cwd=desktop, env=env)+ run([node, "scripts/build/desktop.mjs", "--source", str(repo), "--icons", str(icons),+ "--stamp", str(desktop / "build/install-stamp.json"), "--native-deps", str(prepared.native),+ "--out", str(desktop / "dist")], cwd=repo, env=env)+ version_args = []+ if sys.platform == "win32" and request.channel_request is None and request.tag is not None:+ script = "const m=require('./scripts/msix-shared.mjs');console.log(m.nativeQuad(process.argv[1], Number(process.env.HERMES_RELEASE_EPOCH)))"+ quad = capture([node, "-e", script, request.tag], repo, env)+ version_args = [f'-c.extraMetadata.shortVersion={quad}', f'-c.extraMetadata.shortVersionWindows={quad}']+ run([node, "scripts/run-electron-builder.mjs", *package_args, *version_args, *builder_args], cwd=desktop,+ env=packaging_environment(env, os.environ, request.target))require_source(repo, request.commit)- run([node, "scripts/run-electron-builder.mjs", *package_args, *version_args, *builder_args], cwd=desktop,- env=packaging_environment(env, os.environ, request.target))def main() -> None:diff --git a/tests/scripts/test_desktop_preparation.py b/tests/scripts/test_desktop_preparation.pyindex 270b28255b7..07d3350d595 100644--- a/tests/scripts/test_desktop_preparation.py+++ b/tests/scripts/test_desktop_preparation.py@@ -232,3 +232,44 @@ def test_checkout_lock_excludes_a_second_build_process(tmp_path):released = subprocess.run(command, capture_output=True, text=True, timeout=30)assert released.returncode == 0, released.stderrassert released.stdout.strip() == "acquired"+++def test_flavored_icon_staging_hands_the_admitted_checkout_back(tmp_path):+ from scripts.bundles.desktop import flavored_assets+ from scripts.bundles.desktop_prepare import require_source++ source, commit = _project(tmp_path)+ assets = source / "apps/desktop/assets"+ (assets / "appx").mkdir(parents=True)+ (assets / "icon.png").write_bytes(b"admitted icon")+ (assets / "appx/Square150x150Logo.png").write_bytes(b"admitted tile")+ subprocess.run(["git", "add", "."], cwd=source, check=True)+ subprocess.run(["git", "-c", "user.name=Fixture", "-c", "[email protected]",+ "commit", "-m", "icons"], cwd=source, check=True, capture_output=True)+ commit = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=source, text=True).strip()++ rendered = tmp_path / "products/icons"+ (rendered / "appx").mkdir(parents=True)+ (rendered / "icon.png").write_bytes(b"canary icon")+ (rendered / "icon-mac.png").write_bytes(b"canary dock icon")+ (rendered / "appx/Square150x150Logo.png").write_bytes(b"canary tile")++ # Packaging reads artwork from the workspace path, so the render is live+ # there — and the custody check rightly refuses the checkout in that window.+ with flavored_assets(rendered, assets):+ assert (assets / "icon.png").read_bytes() == b"canary icon"+ assert (assets / "icon-mac.png").read_bytes() == b"canary dock icon"+ with pytest.raises(ValueError, match="clean source checkout"):+ require_source(source, commit)++ # A finished or failed package leaves the admitted files back in place, with+ # render-only additions removed; a dirty tree breaks the next build.+ assert (assets / "icon.png").read_bytes() == b"admitted icon"+ assert (assets / "appx/Square150x150Logo.png").read_bytes() == b"admitted tile"+ assert not (assets / "icon-mac.png").exists()+ require_source(source, commit)++ with pytest.raises(RuntimeError, match="packaging failed"):+ with flavored_assets(rendered, assets):+ raise RuntimeError("packaging failed")+ require_source(source, commit)