The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bundle): preserve staging guards and verify real uv sync
ethernet8643f933845f
diff --git a/.github/workflows/pm-bundle.yml b/.github/workflows/pm-bundle.ymlindex 87bdf850687..5f0bf75b571 100644--- a/.github/workflows/pm-bundle.yml+++ b/.github/workflows/pm-bundle.yml@@ -21,6 +21,7 @@ on:pull_request:paths:- 'pm/**'+ - 'scripts/bundles/**'- 'uv.lock'- 'pyproject.toml'- '.github/workflows/pm-bundle.yml'diff --git a/apps/desktop/scripts/before-build.mjs b/apps/desktop/scripts/before-build.mjsindex 93a3b09c2e6..633620f2940 100644--- a/apps/desktop/scripts/before-build.mjs+++ b/apps/desktop/scripts/before-build.mjs@@ -108,9 +108,8 @@ ${aliases}`}/**- * One uap5:Extension block per payload CLI launcher, each naming its own- * Executable (the distlib-minted launcher exes under bin/) and the alias- * that exe serves. Exported pure for tests.+ * One uap5:Extension carries the aliases declared by the payload.+ * Exported pure for tests.* @param {string[]} launchers exe stems under bin/*/export function appExecutionAliasExtensions(launchers) {diff --git a/apps/desktop/scripts/test-desktop.mjs b/apps/desktop/scripts/test-desktop.mjsindex 319dac70df4..1dd496df15d 100644--- a/apps/desktop/scripts/test-desktop.mjs+++ b/apps/desktop/scripts/test-desktop.mjs@@ -439,7 +439,7 @@ function validateBundle() {die(`Missing packaged app binary: ${APP.binary}`)}- // The payload may be the real pm bundle (staged by build-bundled-desktop /+ // The payload may be the real pm bundle (staged by scripts/bundles/desktop.py /// `hermes pm bundle --out build/agent-payload`) or the external stub// (plain `npm run pack` in the PR/JS lane — the app fetches the runtime at// first launch via the stage protocol). Validate the payload only when adiff --git a/scripts/bundles/desktop.py b/scripts/bundles/desktop.pyindex 4f0e5e3aa94..fe3e07db5e2 100644--- a/scripts/bundles/desktop.py+++ b/scripts/bundles/desktop.py@@ -5,6 +5,7 @@ import argparseimport hashlibimport jsonimport os+import reimport shutilimport subprocessimport sys@@ -64,6 +65,9 @@ def build(repo: Path, tag: str, variant: str, builder_args: list[str]) -> None:node = shutil.which("node")if not node or not shutil.which("uv"):raise FileNotFoundError("Node and uv are required")+ banner = capture(["uv", "--version"], repo)+ if not re.search(r"[a-z0-9_]+-[a-z0-9]+-[a-z][a-z0-9-]*", banner):+ raise ValueError(f"uv must report its build triple (official uv 0.12+): {banner}")npm = npm_command(node)env = {**os.environ, "CI": "true", "PYTHONUTF8": "1", "GITHUB_SHA": commit,"HERMES_DESKTOP_VARIANT": variant, "HERMES_PAYLOAD_TAG": tag}diff --git a/scripts/bundles/mint_launchers.py b/scripts/bundles/mint_launchers.pyindex fce0768a1a4..8ce7a96ac81 100644--- a/scripts/bundles/mint_launchers.py+++ b/scripts/bundles/mint_launchers.py@@ -14,8 +14,7 @@ works with NO extra dependency. A top-level distlib install is preferredwhen present. (Self-contained .\_pth interpreters were REJECTED as analternative approach: they break uv venv materialization.)-Layout facts arrive via env (build-bundled-desktop forbids whitespace in-win32 argv, so argv is not an option):+Layout facts arrive via environment from scripts/bundles/payload.py:HERMES_MINT_BIN_DIR absolute output dir (agent-payload/bin)HERMES_MINT_SPECS JSON list of {"name": exe stem, "module": dotteddiff --git a/scripts/bundles/payload.py b/scripts/bundles/payload.pyindex 90bc65cfb16..23ea0400db5 100644--- a/scripts/bundles/payload.py+++ b/scripts/bundles/payload.py@@ -130,12 +130,12 @@ def posix_launcher(name: str, entry: str, *, python: str, repo: str, site: str,if bionic:extra = '''PREFIX="${PREFIX:-/data/data/com.termux/files/usr}"export PREFIX-export LD_LIBRARY_PATH="$root/tools/python$PREFIX/lib:$root/tools/node$PREFIX/lib:$root/tools/ffmpeg$PREFIX/lib:$root/runtime-libs/lib:$PREFIX/lib"+export LD_LIBRARY_PATH="$root/tools/python/data/data/com.termux/files/usr/lib:$root/tools/node/data/data/com.termux/files/usr/lib:$root/tools/ffmpeg/data/data/com.termux/files/usr/lib:$root/runtime-libs/lib:$PREFIX/lib"export HERMES_PYTHON_SRC_ROOT="$REPO"export HERMES_PYTHON="$PYTHON"-export HERMES_NODE="$root/tools/node$PREFIX/bin/node"+export HERMES_NODE="$root/tools/node/data/data/com.termux/files/usr/bin/node"export HERMES_RUNTIME_DIR="$root/tools"-export PATH="$root/tools/npm/bin:$root/tools/node$PREFIX/bin:$root/tools/ffmpeg$PREFIX/bin:$root/tools/ripgrep:$PATH"+export PATH="$root/tools/npm/bin:$root/tools/node/data/data/com.termux/files/usr/bin:$root/tools/ffmpeg/data/data/com.termux/files/usr/bin:$root/tools/ripgrep:$PATH"'''code = f"import sys; sys.argv[0]={name!r}; from {module} import {func}; sys.exit({func}())"return f'''{header}@@ -178,6 +178,8 @@ def stage_launchers(root: Path, manifest: dict, *, run=subprocess.run) -> list[sminor = python_fact["version"].split("+")[0].rsplit(".", 1)[0]site = f'{manifest["venv"]}/' + ("Lib/site-packages" if windows else f"lib/python{minor}/site-packages")bindir = root / "bin"+ if bindir.exists():+ shutil.rmtree(bindir)bindir.mkdir(parents=True, exist_ok=True)relative_python = python.relative_to(root).as_posix()for name, entry in entries.items():diff --git a/tests/scripts/test_bundle_native.py b/tests/scripts/test_bundle_native.pyindex 9dc035967a5..e4168d30b60 100644--- a/tests/scripts/test_bundle_native.py+++ b/tests/scripts/test_bundle_native.py@@ -3,6 +3,7 @@ from __future__ import annotationsimport jsonimport os+import shutilimport subprocessimport sysfrom pathlib import Path@@ -14,7 +15,11 @@ from scripts.bundles import nativedef test_bundle_stages_git_tree_and_runs_native_children_before_manifest(tmp_path, monkeypatch):repo = tmp_path / "repo"repo.mkdir()- (repo / "pyproject.toml").write_text('[project]\nname="fixture"\nversion="1.0.0"\n')+ (repo / "pyproject.toml").write_text('[project]\nname="fixture"\nversion="1.0.0"\nrequires-python=">=3.11"\n[tool.uv]\npackage=false\n', encoding="utf-8")+ uv = shutil.which("uv")+ assert uv, "native bundle test requires uv"+ env = {**os.environ, "UV_OFFLINE": "1", "UV_PYTHON_DOWNLOADS": "never", "UV_CACHE_DIR": str(tmp_path / "cache")}+ subprocess.run([uv, "lock", "--python", sys.executable], cwd=repo, env=env, check=True, capture_output=True)subprocess.run(["git", "init", str(repo)], check=True, capture_output=True)subprocess.run(["git", "add", "."], cwd=repo, check=True)subprocess.run(["git", "-c", "user.name=Fixture", "-c", "[email protected]", "commit", "-m", "fixture"], cwd=repo, check=True, capture_output=True)@@ -25,7 +30,7 @@ def test_bundle_stages_git_tree_and_runs_native_children_before_manifest(tmp_patmonkeypatch.setattr(native, "_store", lambda: SimpleNamespace(root=output / "tools", entry=lambda _: Path(sys.executable).parent))monkeypatch.setattr(native, "_facts", lambda: SimpleNamespace(get=lambda _: {"entry": "python"}, entries_in_use=lambda: []))monkeypatch.setattr(native, "get_package", lambda _: SimpleNamespace(binary=lambda *args: Path(sys.executable)))- monkeypatch.setattr(native, "pm_uv", lambda: (sys.executable, dict(os.environ)))+ monkeypatch.setattr(native, "pm_uv", lambda: (uv, dict(env)))monkeypatch.setattr(native, "_arch_guard", lambda store: [])monkeypatch.setattr("scripts.bundles.payload.relativize_links", lambda root: 0)monkeypatch.setattr("pm.features.installed_extras", lambda *args: [])@@ -36,9 +41,7 @@ def test_bundle_stages_git_tree_and_runs_native_children_before_manifest(tmp_patdef child(argv, *, cwd, env):calls.append(argv[1])assert not (output / "manifest.json").exists()- # Execute a real child and a real venv, without network or tool-store writes.- command = [sys.executable, "-m", "venv", "--without-pip", str(output / "venv")] if argv[1] == "venv" else [sys.executable, "-c", "print('sync fixture complete')"]- return real_run(command, cwd=cwd, env=env)+ return real_run(argv, cwd=cwd, env=env)monkeypatch.setattr(native, "_run_live", child)monkeypatch.setenv("HERMES_RUNTIME_DIR", str(tmp_path / "original"))diff --git a/tests/scripts/test_bundle_payload.py b/tests/scripts/test_bundle_payload.pyindex 52084b9c980..a2342a7f943 100644--- a/tests/scripts/test_bundle_payload.py+++ b/tests/scripts/test_bundle_payload.py@@ -9,7 +9,7 @@ import sysimport pytest-from scripts.bundles.payload import plant_surfaces, posix_launcher, project_entries, relativize_links, snapshot, write_manifest+from scripts.bundles.payload import plant_surfaces, posix_launcher, project_entries, relativize_links, snapshot, write_manifest, stage_launchersfrom scripts.bundles.desktop import release_version@@ -54,6 +54,41 @@ def test_surfaces_require_complete_outputs_and_replace_stale_files(tmp_path):plant_surfaces(repo, source)+def test_launcher_stage_reads_declared_entries_and_drops_stale_names(tmp_path, monkeypatch):+ from pathlib import Path+ from types import SimpleNamespace+ from pm.lock import Facts+ from pm.store import current_target++ root = tmp_path / "payload"+ repo, tools = root / "app", root / "tools"+ repo.mkdir(parents=True)+ tools.mkdir()+ interpreter = tools / "python/python.exe"+ interpreter.parent.mkdir()+ interpreter.write_bytes(b"fixture interpreter")+ (repo / "pyproject.toml").write_text('[project.scripts]\ncustom="entry:run"\n', encoding="utf-8")+ Facts(tools / "facts.json").record("python", "3.11.16", "python", {}, tools)+ manifest = write_manifest(root, target=current_target(), repo="app")+ (root / "bin").mkdir()+ (root / "bin/removed-entry").write_text("old")+ monkeypatch.setattr("pm.registry.get_package", lambda _: SimpleNamespace(binary=lambda *args: interpreter))+ calls = []++ def mint(argv, *, env, check):+ calls.append(json.loads(env["HERMES_MINT_SPECS"]))+ compile(Path(env["HERMES_MINT_WRAPPER"]).read_text(), "wrapper", "exec")+ (root / "bin/custom.exe").write_bytes(b"mint fixture")++ assert stage_launchers(root, manifest, run=mint) == ["custom"]+ assert not (root / "bin/removed-entry").exists()+ if current_target().startswith("win32"):+ assert calls == [[{"name": "custom", "module": "entry", "func": "run"}]]+ else:+ assert (root / "bin/custom").is_file()+ assert json.loads((root / "manifest.json").read_text())["launchers"] == ["custom"]++@pytest.mark.platforms("posix")def test_relocation_preserves_sibling_and_framework_links(tmp_path):root = tmp_path / "payload"