The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Merge branch 'ethie/pm-test-audit' into ethie/pm-clean
ethernetf8bdc960333f
diff --cc tests/scripts/test_bundle_native.pyindex 4de7d9ff46e,2aa8bcc3568..7b29ce912b9--- a/tests/scripts/test_bundle_native.py+++ b/tests/scripts/test_bundle_native.py@@@ -20,67 -20,84 +20,122 @@@ from scripts.bundles import nativdef test_bundle_stages_git_tree_and_runs_native_children_before_manifest(tmp_path, monkeypatch):++ import importlibimport inspectfrom hermes_cli.runtime_paths import site_packages- from pm.lock import Facts, Lockfile- from pm.store import Store++ from pm.lock import Facts++ from pm.registry import get_package++ from pm.store import tree_digest+ from tests.pm._fixtures import _wheelmonkeypatch.setattr(Path, "home", lambda: tmp_path / "home")++ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "home"))output = tmp_path / "payload"- target_python = output / "tools/cached-python" / ("python.exe" if os.name == "nt" else "bin/python3")- target_python.parent.mkdir(parents=True)+ canonical = tmp_path / "canonical"- from pm.lock import Facts- from pm.registry import get_package- from pm.store import tree_digest+ lock, target = native._lockfile(), native.current_target()+ python_package = get_package("python")+ python_entry = python_package.store_entry(lock.version("python"), target)+ source_python = python_package.binary(canonical / python_entry, target)+ target_python = output / "tools" / source_python.relative_to(canonical)+ source_python.parent.mkdir(parents=True)# PM seals a payload-owned base interpreter, not an external venv launcher.# The POSIX host supplies its stdlib; Windows needs it beside the executable.if os.name == "nt":- shutil.copytree(Path(sys.base_prefix), target_python.parent, dirs_exist_ok=True)+ shutil.copytree(Path(sys.base_prefix), source_python.parent, dirs_exist_ok=True)else:- shutil.copy2(Path(getattr(sys, "_base_executable")).resolve(), target_python)+ shutil.copy2(Path(getattr(sys, "_base_executable")).resolve(), source_python)repo = tmp_path / "repo"repo.mkdir()- pm_project = Path(__file__).resolve().parents[2] / "pm"- (repo / "pm").mkdir()- for name in ("pyproject.toml", "uv.lock", "lock.json"):- shutil.copy2(pm_project / name, repo / "pm" / name)- (repo / "pyproject.toml").write_text('[project]\nname="fixture"\nversion="1.0.0"\nrequires-python=">=3.11"\n[project.scripts]\nprobe="entry:main"\n[project.optional-dependencies]\npayloadtest=[]\n[tool.uv]\npackage=false\n', encoding="utf-8")+ source = Path(__file__).resolve().parents[2]+ shutil.copytree(source / "pm", repo / "pm", ignore=shutil.ignore_patterns("__pycache__"))+ (repo / "hermes_cli").mkdir()+ for name in ("__init__.py", "runtime_paths.py", "runtime_state.py"):+ shutil.copy2(source / "hermes_cli" / name, repo / "hermes_cli" / name)+ shutil.copy2(source / "hermes_constants.py", repo / "hermes_constants.py")+ wheels = repo / "wheels"+ wheels.mkdir()+ witness = tmp_path / "inventory-python.json"+ wheel = _wheel(wheels, "bundle_probe")+ import zipfile+ with zipfile.ZipFile(wheel, "a") as archive:+ archive.writestr("bundle_probe/witness/__init__.py", "import json,pathlib,sys\n"- f"pathlib.Path({str(witness)!r}).write_text(json.dumps(sys.executable))\n")++ f"pathlib.Path({str(witness)!r}).write_text(json.dumps(sys.executable), encoding='utf-8')\n")+ archive.writestr("bundle_probe/witness/present.py", "")+ (repo / "pyproject.toml").write_text(+ '[project]\nname="fixture"\nversion="1.0.0"\nrequires-python=">=3.11"\n'+ '[project.scripts]\nprobe="entry:main"\n[project.optional-dependencies]\npayloadtest=["bundle-probe==1.0"]\n'+ '[tool.uv]\npackage=false\nno-index=true\nfind-links=["wheels"]\n', encoding="utf-8")+ selected = {"agent-browser", "chromium", "uv", "python"}+ stale = {"chromium-headless-shell", "retired-tool"}+ user_store = tmp_path / "user-tools"+ for store in (output / "tools", user_store):+ store.mkdir(parents=True, exist_ok=True)+ facts = Facts(store / "facts.json")+ for name in selected | stale:+ entry = store / f"cached-{name}"+ entry.mkdir(exist_ok=True)+ (entry / "payload").write_text(name, encoding="utf-8")+ facts.record(name, f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}", entry.name, {}, store)+ (store / "orphaned-version").mkdir()+ (store / ".partials").mkdir()+ user_before = {path.relative_to(user_store): path.read_bytes() if path.is_file() else None for path in user_store.rglob("*")}- selection = Lockfile(tmp_path / "selection.json")- for name in ("agent-browser", "uv"):- selection.set_pin(name, "fixture", {})- selection.save()++from scripts.build.inputs import RESOURCE_ENVfor name in RESOURCE_ENV:(repo / name).mkdir()(repo / name / "asset").write_text("required", encoding="utf-8")- (repo / "entry.py").write_text("def main(): return 0\n", encoding="utf-8")+ (repo / "entry.py").write_text("import bundle_probe\ndef main(): print(bundle_probe.__version__); return 7\n", encoding="utf-8")uv = shutil.which("uv")assert uv, "native bundle test requires uv"+ uv_package = get_package("uv")+ uv_entry = canonical / uv_package.store_entry(lock.version("uv"), target)+ uv_entry.mkdir(parents=True)+ shutil.copy2(uv, uv_package.binary(uv_entry, target))++ # Browser payloads are inert: this test exercises their real dependency++ # closure, admission and pruning, not browser execution or downloads.++ for name in ("agent-browser", "chromium"):++ package = get_package(name)++ entry = canonical / package.store_entry(lock.version(name), target)++ binary = (entry / ("chrome.exe" if os.name == "nt" else "chrome")++ if name == "chromium" else package.binary(entry, target))++ binary.parent.mkdir(parents=True)++ binary.write_text("inert browser fixture", encoding="utf-8")++ if name == "chromium":++ (entry / "INSTALLATION_COMPLETE").touch()+ facts = Facts(canonical / "facts.json")- for name in ("python", "uv"):++ for name in selected:+ package = get_package(name)+ entry = canonical / package.store_entry(lock.version(name), target)++ (entry / "payload").write_text(name, encoding="utf-8")+ facts.record(name, lock.version(name), entry.name, package.env(entry, target), canonical,+ target=target, artifacts=[row["sha256"] for row in lock.artifacts(name, target)],+ digest=tree_digest(entry))- canonical_before = {name: tree_digest(canonical / facts.get(name)["entry"]) for name in ("python", "uv")}++ canonical_before = {name: tree_digest(canonical / facts.get(name)["entry"]) for name in selected}++ canonical_facts = (canonical / "facts.json").read_bytes()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)monkeypatch.setattr("pm.paths.repo_root", lambda: repo)- monkeypatch.setattr(native, "_bundle_package_names", lambda: ["uv"])- monkeypatch.setattr("pm.prepare_tools", lambda names, **kwargs: kwargs["out"])+ (repo / "untracked").write_text("must not ship", encoding="utf-8")- monkeypatch.setattr(native, "_lockfile", lambda: selection)- monkeypatch.setattr(native, "_install_names", lambda names: 0) # prepared artifacts, real facts/prune- monkeypatch.setattr(native, "_store", lambda: Store(output / "tools"))- monkeypatch.setattr(native, "_facts", lambda: Facts(output / "tools/facts.json"))++ monkeypatch.setattr(native, "_bundle_package_names", lambda: ["agent-browser", "uv"])++ monkeypatch.setattr(importlib.import_module("pm.ensure"), "_prepare_artifacts",++ lambda *args, **kwargs: pytest.fail("prepared tools reached acquisition"))monkeypatch.setattr("pm.client.is_runtime", lambda: True)monkeypatch.setattr("pm._uv._toolchain", lambda **kwargs: (Path(uv), Path(sys.executable)))-- monkeypatch.setattr("pm.extras.ANCHORS", {"payloadtest": "bundle_probe.present"})+ monkeypatch.setattr("pm.extras.ANCHORS", {"payloadtest": "bundle_probe.witness.present"})import pm++ real_stage = pm.stage_manager_runtime++++ def stage(**kwargs):++ assert kwargs["cache"] == tmp_path / "cache"++ assert kwargs["python"] == target_python++ assert kwargs["project"] == output / "hermes-agent/pm"++ return real_stage(**kwargs)++++ monkeypatch.setattr(pm, "stage_manager_runtime", stage)real_build = pm.build_environmentinstall_timeout = inspect.signature(real_build).parameters["timeout"].defaultcalls = []@@@ -90,10 -106,10 +144,14 @@@def build(**kwargs):assert "uv" not in kwargsassert kwargs["sealed"] is True++ assert kwargs["python"] == target_python++ assert kwargs["source"] == output / "hermes-agent"assert kwargs.get("timeout", install_timeout) > install_timeoutcalls.append(kwargs)assert not (output / "manifest.json").exists()-- marker = json.loads((output / "pm-runtime/pm-runtime.json").read_text())++ marker_path = output / "pm-runtime/pm-runtime.json"++ assert marker_path.is_file(), "PM must be staged before the application environment"++ marker = json.loads(marker_path.read_text())assert (output / "pm-runtime" / marker["python"]).resolve() == target_pythonassert (output / "pm-runtime" / marker["sitePackages"]).is_dir()result = real_build(**kwargs)@@@ -103,120 -119,70 +161,148 @@@return resultmonkeypatch.setattr(pm, "build_environment", build)- monkeypatch.setenv("HERMES_RUNTIME_DIR", str(tmp_path / "original"))+ monkeypatch.setenv("HERMES_RUNTIME_DIR", str(user_store))monkeypatch.setenv("UV_CACHE_DIR", str(tmp_path / "cache"))- assert native._stage_native(SimpleNamespace(out=str(output), ref="HEAD")) == 0+ prepared = native.prepare_native(out=output, ref="HEAD", source=repo, cache=tmp_path / "cache", tools=canonical, env=env)- assert {name: tree_digest(canonical / facts.get(name)["entry"]) for name in ("python", "uv")} == canonical_before++ assert {name: tree_digest(canonical / facts.get(name)["entry"]) for name in selected} == canonical_before++ assert (canonical / "facts.json").read_bytes() == canonical_facts+ assert not target_python.samefile(source_python)+ assert prepared == output.with_name(output.name + ".prepared.json")+ assert not prepared.is_relative_to(output)+ assert prepared.is_file()+ assert not (output / "manifest.json").exists()+ from scripts.bundles.native_prepared import load_prepared, preparation_lock+ with preparation_lock(output):+ with pytest.raises(ValueError, match="already in use"):+ native.finish_native(prepared, {})+ assert prepared.is_file()+ # Dependencies are already installed. Reject changed bytes rather than+ # healing them, including a substituted directory with identical bytes.+ inventory = json.loads(prepared.read_text())+ revision = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=repo, text=True).strip()+ assert inventory["revision"] == revision+ assert inventory["inputs"]["ref"] == "HEAD"+ changed_inputs = json.loads(prepared.read_text())+ changed_inputs["inputs"]["project"] = str(repo / "pyproject.toml")+ prepared.write_text(json.dumps(changed_inputs), encoding="utf-8")+ with pytest.raises(ValueError, match="run preparation again"):+ load_prepared(prepared)+ prepared.write_text(json.dumps(inventory), encoding="utf-8")+ for relative in ("hermes-agent/entry.py", "hermes-agent/uv.lock",+ "venv/pyvenv.cfg", "pm-runtime/pm-runtime.json",+ "enabled-features.json"):+ changed = output / relative+ original = changed.read_bytes()+ changed.write_bytes(original + b"\nchanged")+ with pytest.raises(ValueError, match="run preparation again"):+ load_prepared(prepared)+ changed.write_bytes(original)+ moved = output / "hermes-agent"+ outside = tmp_path / "substituted-source"+ moved.rename(outside)+ moved.symlink_to(outside, target_is_directory=True)+ with pytest.raises(ValueError, match="run preparation again"):+ load_prepared(prepared)+ moved.unlink()+ outside.rename(moved)+ # A source entry linked outside the payload must never be admitted, even+ # when its link text itself is freshly covered by the stored digest.+ linked = moved / "escape"+ linked.symlink_to(witness)+ from scripts.bundles.native_prepared import _source_digest+ inventory["digests"]["hermes-agent"] = _source_digest(moved)+ prepared.write_text(json.dumps(inventory), encoding="utf-8")+ with pytest.raises(ValueError, match="run preparation again"):+ load_prepared(prepared)+ linked.unlink()+ inventory["digests"]["hermes-agent"] = _source_digest(moved)+ prepared.write_text(json.dumps(inventory), encoding="utf-8")+ frontend = tmp_path / "web-product"+ frontend.mkdir()+ (frontend / "index.html").write_text("built web", encoding="utf-8")+ with monkeypatch.context() as strict:+ def forbidden(*args, **kwargs):+ pytest.fail("strict finish entered dependency acquisition or a child process")+ strict.setattr(pm, "build_environment", forbidden)+ strict.setattr(pm, "stage_manager_runtime", forbidden)++ strict.setattr(pm, "prepare_tools", forbidden)++ strict.setattr(pm, "stage_tools", forbidden)+ strict.setattr(subprocess, "run", forbidden)+ assert native.finish_native(prepared, {"web": frontend}) == 0+ (output / "hermes-agent/install-stamp.json").write_text('{"variant":"bundled"}', encoding="utf-8")+ (output / "manifest.json").write_text('{"variant":"bundled"}', encoding="utf-8")+ launcher = output / ("bin/probe.exe" if os.name == "nt" else "bin/probe")+ launcher.rename(launcher.with_name("renamed-launcher"))+ (frontend / "index.html").write_text("store web", encoding="utf-8")+ assert native.finish_native(prepared, {"web": frontend}) == 0+ assert (output / "hermes-agent/hermes_cli/web_dist/index.html").read_text() == "store web"+ assert calls[0]["all_extras"] is Trueassert calls[0]["cache"] == tmp_path / "cache"assert (output / "hermes-agent/pyproject.toml").is_file()+ assert not (output / "hermes-agent/untracked").exists()+ assert not (output / "hermes-agent/.git").exists()+ facts = Facts(output / "tools/facts.json")+ for name in stale:+ assert facts.get(name) is None+ assert not (output / "tools" / f"cached-{name}").exists()+ for name in selected:- assert facts.get(name)["entry"] == f"cached-{name}"- assert (output / "tools" / f"cached-{name}" / "payload").read_text(encoding="utf-8-sig") == name++ entry = get_package(name).store_entry(lock.version(name), target)++ assert facts.get(name)["entry"] == entry++ assert facts.get(name)["version"] == lock.version(name)++ assert facts.get(name)["target"] == target++ assert facts.get(name)["artifacts"] == [row["sha256"] for row in lock.artifacts(name, target)]++ assert (output / "tools" / entry / "payload").read_text(encoding="utf-8-sig") == name++ assert not (output / "tools" / f"cached-{name}").exists()+ assert not (output / "tools/orphaned-version").exists()+ assert (output / "tools/.partials").is_dir()+ assert user_before == {path.relative_to(user_store): path.read_bytes() if path.is_file() else None for path in user_store.rglob("*")}+manifest = json.loads((output / "manifest.json").read_text())assert manifest["repo"] == "hermes-agent"command = "bin/probe.exe" if os.name == "nt" else "bin/probe"assert manifest["runtime"]["commands"] == {"probe": command}feature_file = output / "enabled-features.json"- assert json.loads(feature_file.read_text(encoding="utf-8"))["extras"] == ["payloadtest"]- assert Path(json.loads(witness.read_text(encoding="utf-8"))) == target_python- assert os.environ["HERMES_RUNTIME_DIR"] == str(tmp_path / "original")+ assert os.environ["HERMES_RUNTIME_DIR"] == str(user_store)+ moved = tmp_path / "installed elsewhere"+ output.rename(moved)+ try:+ run = subprocess.run([str(moved / command)], cwd=tmp_path, capture_output=True, text=True, timeout=30)+ assert run.returncode == 7, run.stderr+ assert run.stdout.strip() == "1.0"+ from pm import runtime as runtime_api, paths+ with monkeypatch.context() as patch:+ patch.setattr(paths, "repo_root", lambda: moved / "hermes-agent")+ run = subprocess.run(runtime_api.runtime_command(moved / "hermes-agent/pm/launch.py", ["status"]),+ cwd=tmp_path, env=runtime_api.runtime_environment(), capture_output=True, text=True, timeout=30)+ assert run.returncode == 0, run.stderr+ assert "no pm sync receipt" in run.stdout+ finally:+ moved.rename(output)+ assert json.loads(feature_file.read_text(encoding="utf-8"))["extras"] == ["payloadtest"]+ assert Path(json.loads(witness.read_text(encoding="utf-8-sig"))) == target_pythonbefore = feature_file.read_bytes()fail_inventory = True-- assert native._stage_native(SimpleNamespace(out=str(output), ref="HEAD")) == 1++ args = SimpleNamespace(out=str(output), ref="HEAD", source=repo, cache=tmp_path / "cache", tools=canonical)++ assert native._stage_native(args) == 1assert not (output / "manifest.json").exists()assert feature_file.read_bytes() == before- assert os.environ["HERMES_RUNTIME_DIR"] == str(tmp_path / "original")+ assert os.environ["HERMES_RUNTIME_DIR"] == str(user_store)from pm.package import InstallErrordef fail_build(**kwargs):raise InstallError("venv", "injected failure")monkeypatch.setattr(pm, "build_environment", fail_build)-- assert native._stage_native(SimpleNamespace(out=str(output), ref="HEAD")) == 1++ assert native._stage_native(args) == 1assert not (output / "manifest.json").exists()- assert os.environ["HERMES_RUNTIME_DIR"] == str(tmp_path / "original")+ assert os.environ["HERMES_RUNTIME_DIR"] == str(user_store)- import pytest(repo / "pm/lock.json").write_text("{}", encoding="utf-8")subprocess.run(["git", "add", "pm/lock.json"], cwd=repo, check=True)subprocess.run(["git", "-c", "user.name=Fixture", "-c", "[email protected]", "commit", "-m", "different pins"], cwd=repo, check=True, capture_output=True)- monkeypatch.setattr(native, "_install_names", lambda names: pytest.fail("mismatched pins reached provisioning"))+ monkeypatch.setattr("pm.prepare_tools", lambda names, **kwargs: pytest.fail("mismatched pins reached provisioning"))with pytest.raises(ValueError, match="PM lock differs"):-- native._stage_native(SimpleNamespace(out=str(output), ref="HEAD"))++ native._stage_native(args)@pytest.mark.parametrize("pointer, shard", [("revision.http", ""), ("revision.rev", "build-settings")])@@@ -418,79 -325,53 +445,68 @@@ def test_native_dispatch_isolates_proceassert not list(out.glob(".build-*"))+def test_native_preparation_refuses_symlinked_output_before_writing(tmp_path, monkeypatch):+ monkeypatch.setattr("pm.prepare_tools", lambda *args, **kwargs: pytest.fail("unsafe output reached acquisition"))+ output = tmp_path / "payload"+ output.mkdir()+ outside = tmp_path / "outside"+ outside.mkdir()+ (outside / "keep").write_text("untouched", encoding="utf-8")+ (output / "hermes-agent").symlink_to(outside, target_is_directory=True)+ with pytest.raises(ValueError, match="symlink|escaped"):+ native.prepare_native(out=output, ref="HEAD", source=Path(__file__).resolve().parents[2],+ cache=tmp_path / "cache")+ assert (outside / "keep").read_text() == "untouched"- assert not (output / "native-prepared.json").exists()-++ assert not output.with_name(output.name + ".prepared.json").exists()+- def test_native_dispatch_keeps_cache_across_failed_children(tmp_path, monkeypatch):- monkeypatch.setattr("scripts.build.windows_deps.prepare_windows_environment", lambda **kwargs: dict(kwargs["env"]))- out = tmp_path / "payload"- cache = tmp_path / "persistent-cache"- monkeypatch.setenv("UV_CACHE_DIR", str(tmp_path / "ambient-cache"))- original = dict(os.environ)- run = subprocess.run- attempts = []-- def child(command, *, cwd, env):- assert command[command.index("-m") + 1] == "scripts.bundles.native"- assert Path(env["UV_CACHE_DIR"]) == cache- attempts.append(Path(env["HOME"]))- # Run a real child using the actual dispatch environment. Its cache- # write must survive the failing process and temporary-HOME cleanup.- return run([sys.executable, "-c",- "import os,sys; from pathlib import Path; "- "p=Path(os.environ['UV_CACHE_DIR']); p.mkdir(exist_ok=True); "- "f=p/'reused'; f.write_text(f.read_text()+'x' if f.exists() else 'x'); sys.exit(17)"],- cwd=cwd, env=env)-- monkeypatch.setattr(native.subprocess, "run", child)- for _ in range(2):- assert native.stage_native(SimpleNamespace(out=out, ref="HEAD", cache=cache)) == 17- assert (cache / "reused").read_text() == "xx"- assert all(not home.exists() for home in attempts)- assert not (tmp_path / "ambient-cache").exists()- assert dict(os.environ) == original++ @pytest.mark.parametrize("cache_source,explicit_compilers,status", [+ ("explicit", True, 17), ("ambient", False, 0), ("default", False, 17),+ ])+ def test_native_dispatch_child_environment(tmp_path, monkeypatch, cache_source, explicit_compilers, status):+ from pm.packages import uv_cache_dir- @pytest.mark.parametrize("explicit", [False, True])- def test_native_dispatch_preserves_compiler_homes_inside_isolated_home(tmp_path, monkeypatch, explicit):- host_home = tmp_path / "host"- monkeypatch.setattr(Path, "home", lambda: host_home)+ monkeypatch.setattr(Path, "home", lambda: tmp_path / "host")monkeypatch.setattr("scripts.build.windows_deps.prepare_windows_environment", lambda **kwargs: dict(kwargs["env"]))- homes = {}+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "user"))+ monkeypatch.delenv("UV_CACHE_DIR", raising=False)+ ambient = tmp_path / "ambient"+ if cache_source != "default":+ monkeypatch.setenv("UV_CACHE_DIR", str(ambient))+ cache = {"explicit": tmp_path / "explicit", "ambient": ambient, "default": uv_cache_dir()}[cache_source]+ compilers = {}for key, name in (("CARGO_HOME", ".cargo"), ("RUSTUP_HOME", ".rustup")):- directory = (tmp_path / "custom" if explicit else host_home) / name- directory.mkdir(parents=True)- (directory / "fixture-state").write_text(key, encoding="utf-8")- homes[key] = str(directory)- if explicit:- monkeypatch.setenv(key, str(directory))- else:- monkeypatch.delenv(key, raising=False)- before = dict(os.environ)- run = subprocess.run+ home = tmp_path / ("custom" if explicit_compilers else "host") / name+ home.mkdir(parents=True)+ (home / "fixture-state").write_text(key, encoding="utf-8")+ compilers[key] = str(home)+ monkeypatch.delenv(key, raising=False)+ if explicit_compilers:+ monkeypatch.setenv(key, str(home))+ before, run, homes = dict(os.environ), subprocess.run, []+ observed = tmp_path / "child.json"def child(command, *, cwd, env):- assert env["HOME"] != str(host_home)- assert env["USERPROFILE"] == env["HOME"]- assert {key: env.get(key) for key in homes} == homes+ assert command[command.index("-m") + 1] == "scripts.bundles.native"return run([sys.executable, "-c",- "import os; from pathlib import Path; "- "assert all((Path(os.environ[k]) / 'fixture-state').read_text() == k "- "for k in ('CARGO_HOME', 'RUSTUP_HOME'))"],- cwd=cwd, env=env, check=True)+ "import os,json,sys; from pathlib import Path; "+ "Path(sys.argv[1]).write_text(json.dumps(dict(os.environ))); "+ "assert all((Path(os.environ[k])/'fixture-state').read_text() == k for k in ('CARGO_HOME','RUSTUP_HOME')); "+ "p=Path(os.environ['UV_CACHE_DIR']); p.mkdir(parents=True,exist_ok=True); "+ "f=p/'reused'; f.write_text(f.read_text()+'x' if f.exists() else 'x'); sys.exit(int(sys.argv[2]))",+ str(observed), str(status)], cwd=cwd, env=env)monkeypatch.setattr(native.subprocess, "run", child)- assert native.stage_native(SimpleNamespace(out=tmp_path / "out", ref="HEAD")) == 0+ out = tmp_path / "payload"+ for _ in range(2):+ assert native.stage_native(SimpleNamespace(out=out, ref="HEAD", cache=cache if cache_source == "explicit" else None)) == status+ env = json.loads(observed.read_text(encoding="utf-8-sig"))+ homes.append(Path(env["HOME"]))+ assert env["HOME"] == env["USERPROFILE"] != str(tmp_path / "host")+ assert {key: env[key] for key in compilers} == compilers+ assert Path(env["UV_CACHE_DIR"]) == cache+ assert Path(env["HERMES_RUNTIME_DIR"]) == out / "tools"+ assert Path(env["HERMES_HOME"]) == homes[-1] / ".hermes"+ assert (cache / "reused").read_text(encoding="utf-8-sig") == "xx"+ assert all(not home.exists() for home in homes)assert dict(os.environ) == before