2026-09-06 22:21:06 -04:00
|
|
|
"""The native bundle pipeline publishes only after a real staged sync succeeds."""
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-09-13 11:04:03 -04:00
|
|
|
import hashlib
|
2026-09-06 22:21:06 -04:00
|
|
|
import json
|
|
|
|
|
import os
|
2026-09-06 22:38:58 -04:00
|
|
|
import shutil
|
2026-09-06 22:21:06 -04:00
|
|
|
import subprocess
|
|
|
|
|
import sys
|
2026-09-08 01:47:57 -04:00
|
|
|
import tarfile
|
|
|
|
|
import threading
|
|
|
|
|
from functools import partial
|
|
|
|
|
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
2026-09-06 22:21:06 -04:00
|
|
|
from pathlib import Path
|
|
|
|
|
from types import SimpleNamespace
|
|
|
|
|
|
2026-09-12 02:05:48 -04:00
|
|
|
import pytest
|
|
|
|
|
|
2026-09-06 22:21:06 -04:00
|
|
|
from scripts.bundles import native
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_bundle_stages_git_tree_and_runs_native_children_before_manifest(tmp_path, monkeypatch):
|
2026-09-13 18:03:57 -04:00
|
|
|
import importlib
|
2026-09-12 13:20:02 -04:00
|
|
|
import inspect
|
|
|
|
|
|
2026-09-18 20:02:36 -04:00
|
|
|
from pm.environments import site_packages
|
2026-09-13 18:03:57 -04:00
|
|
|
from pm.lock import Facts
|
|
|
|
|
from pm.registry import get_package
|
|
|
|
|
from pm.store import tree_digest
|
2026-09-21 14:49:05 -04:00
|
|
|
from tests.pm._fixtures import _wheel, stage_host_python
|
2026-09-09 21:47:54 -04:00
|
|
|
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path / "home")
|
2026-09-13 18:03:57 -04:00
|
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "home"))
|
fix(pm): isolate bootstrap dependencies and unify YAML on ruamel
Activation reaches plugin discovery before the application dependencies
exist. Give PM its own locked Python project and runtime so it can install
or repair the application without importing that dependency tree.
Keep PM outside the application workspace. A shared uv workspace resolves
the application graph and cannot provide this isolation. Route mutations
through an isolated worker and preserve transaction callbacks, cancellation,
custom package registrations, and correlated receipts.
Use the same runtime builder for source installs and packaged payloads.
Keep offline wheelhouse support in that builder. Nix builds the independent
PM lock as a separate derivation. Refuse lazy-disabled bootstrap before
installing tools or dependencies.
Move first-party YAML readers and writers to ruamel. Keep the application
lock's transitive PyYAML requirements for third-party packages.
Verification:
- Focused canonical Python suite: 177 passed, 1 host-gated skip.
- Electron backend probes: 12 passed. Electron typecheck passed.
- Both uv locks, scoped lint, Bash syntax, and whitespace checks passed.
- Cold activation, corrupt-app repair, offline staging, and relocation ran.
- Built and exercised the Nix PM runtime and standalone YAML merge script.
Six broader caller test files retain the same 24 failing test IDs as an
archive of HEAD. The existing real-home guard blocks those tests before
they can exercise the affected paths. No full-suite pass is claimed.
Native Windows signing and full Bionic package execution remain unverified.
2026-09-11 12:23:51 -04:00
|
|
|
output = tmp_path / "payload"
|
2026-09-13 14:28:31 -04:00
|
|
|
canonical = tmp_path / "canonical"
|
|
|
|
|
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)
|
2026-09-21 14:49:05 -04:00
|
|
|
assert source_python is not None
|
2026-09-13 14:28:31 -04:00
|
|
|
target_python = output / "tools" / source_python.relative_to(canonical)
|
|
|
|
|
source_python.parent.mkdir(parents=True)
|
2026-09-21 14:49:05 -04:00
|
|
|
# Keep a real payload-owned interpreter and stdlib. The Linux fixture
|
|
|
|
|
# excludes unused SDK libraries and duplicate executable aliases, which
|
|
|
|
|
# otherwise dominate each of the repeated admission digests below.
|
|
|
|
|
if sys.platform == "linux":
|
|
|
|
|
stage_host_python(source_python)
|
|
|
|
|
elif os.name == "nt":
|
2026-09-13 14:28:31 -04:00
|
|
|
shutil.copytree(Path(sys.base_prefix), source_python.parent, dirs_exist_ok=True)
|
fix(pm): isolate bootstrap dependencies and unify YAML on ruamel
Activation reaches plugin discovery before the application dependencies
exist. Give PM its own locked Python project and runtime so it can install
or repair the application without importing that dependency tree.
Keep PM outside the application workspace. A shared uv workspace resolves
the application graph and cannot provide this isolation. Route mutations
through an isolated worker and preserve transaction callbacks, cancellation,
custom package registrations, and correlated receipts.
Use the same runtime builder for source installs and packaged payloads.
Keep offline wheelhouse support in that builder. Nix builds the independent
PM lock as a separate derivation. Refuse lazy-disabled bootstrap before
installing tools or dependencies.
Move first-party YAML readers and writers to ruamel. Keep the application
lock's transitive PyYAML requirements for third-party packages.
Verification:
- Focused canonical Python suite: 177 passed, 1 host-gated skip.
- Electron backend probes: 12 passed. Electron typecheck passed.
- Both uv locks, scoped lint, Bash syntax, and whitespace checks passed.
- Cold activation, corrupt-app repair, offline staging, and relocation ran.
- Built and exercised the Nix PM runtime and standalone YAML merge script.
Six broader caller test files retain the same 24 failing test IDs as an
archive of HEAD. The existing real-home guard blocks those tests before
they can exercise the affected paths. No full-suite pass is claimed.
Native Windows signing and full Bionic package execution remain unverified.
2026-09-11 12:23:51 -04:00
|
|
|
else:
|
2026-10-08 17:22:54 +02:00
|
|
|
shutil.copytree(Path(sys._base_executable).resolve().parents[1],
|
perf(bundles): bake payload bytecode; ship only what the sealed runtime reads
First launch of a bundled payload paid a cold-compile stall: the launcher
redirects bytecode writes to a user-level cache (signature-breaking on
macOS, read-only mount on AppImage/MSIX), so every import compiled from
source. Now staging bakes the cache into the payload:
- compileall with the payload's OWN staged 3.14 interpreter, unchecked-
hash pycs: repack mtimes cannot invalidate them, a stale source can
never trigger a rewrite, and read-only pycs mean the macOS signature
never observes a change. Dirs stay writable — in-place rebuilds
rmtree the tree; asserted coverage plus unchecked-hash means no
cache-miss write can target them.
- coverage is the perf contract: the bake FAILS if any parseable module
lacks a pyc (empirically 0 unparseable files ship, so compileall is
strict). Probe suite: py_compile/cache_from_source, PEP 552 flags,
multi-root read, stale-source no-rewrite, read-only cache-dir import.
- launcher: the baked marker makes configure() leave sys.pycache_prefix
UNSET — the prefix relocates reads too and would hide the baked pycs.
Payload modules read their source-adjacent cache (Python's default
multi-root lookup); plugin/user modules keep caching beside their own
sources under HERMES_HOME. Unmarked payloads keep the old redirect.
- snapshot(): the sealed payload ships without tests/website/evals/
.github/nix/docker/tests-js (~69MB, 46% of tracked bytes) and without
apps/ui-tui/web/scripts — CI prebuilds those products, and
is_bundled_payload routes sealed updates to the channel updater, so
the rebuild graph never runs in a bundle (linux_desktop_entry degrades
to the themed icon). Frontend product staging keeps the full tree.
- test_bundle_native now stages the FULL relocatable toolchain (a bare
interpreter ELF falls back to its compile-time /install prefix and
cannot create a venv), and runs on the real 3.14 for the first time
this campaign — the whole battery had been running 3.12 against the
3.14-pinned lock.
2026-09-14 19:26:04 -04:00
|
|
|
source_python.parents[1], dirs_exist_ok=True)
|
2026-09-06 22:21:06 -04:00
|
|
|
repo = tmp_path / "repo"
|
|
|
|
|
repo.mkdir()
|
2026-09-13 14:47:54 -04:00
|
|
|
source = Path(__file__).resolve().parents[2]
|
|
|
|
|
shutil.copytree(source / "pm", repo / "pm", ignore=shutil.ignore_patterns("__pycache__"))
|
|
|
|
|
(repo / "hermes_cli").mkdir()
|
2026-09-18 20:02:36 -04:00
|
|
|
for name in ("__init__.py", "runtime_state.py"):
|
2026-09-13 14:47:54 -04:00
|
|
|
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"
|
2026-09-13 18:03:57 -04:00
|
|
|
f"pathlib.Path({str(witness)!r}).write_text(json.dumps(sys.executable), encoding='utf-8')\n")
|
2026-09-13 14:47:54 -04:00
|
|
|
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")
|
2026-10-22 08:34:14 -07:00
|
|
|
selected = {"chromium", "uv", "python"}
|
|
|
|
|
# agent-browser: a retired package a pre-upgrade store still records.
|
|
|
|
|
stale = {"agent-browser", "chromium-headless-shell", "retired-tool"}
|
2026-09-13 14:47:54 -04:00
|
|
|
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("*")}
|
2026-09-13 18:03:57 -04:00
|
|
|
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
from scripts.build.inputs import RESOURCE_ENV
|
|
|
|
|
for name in RESOURCE_ENV:
|
|
|
|
|
(repo / name).mkdir()
|
|
|
|
|
(repo / name / "asset").write_text("required", encoding="utf-8")
|
2026-09-13 14:47:54 -04:00
|
|
|
(repo / "entry.py").write_text("import bundle_probe\ndef main(): print(bundle_probe.__version__); return 7\n", encoding="utf-8")
|
2026-09-06 22:38:58 -04:00
|
|
|
uv = shutil.which("uv")
|
|
|
|
|
assert uv, "native bundle test requires uv"
|
2026-09-13 14:28:31 -04:00
|
|
|
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))
|
2026-09-13 18:03:57 -04:00
|
|
|
# Browser payloads are inert: this test exercises their real dependency
|
|
|
|
|
# closure, admission and pruning, not browser execution or downloads.
|
2026-10-22 08:34:14 -07:00
|
|
|
chromium = get_package("chromium")
|
|
|
|
|
entry = canonical / chromium.store_entry(lock.version("chromium"), target)
|
|
|
|
|
binary = entry / ("chrome.exe" if os.name == "nt" else "chrome")
|
|
|
|
|
binary.parent.mkdir(parents=True)
|
|
|
|
|
binary.write_text("inert browser fixture", encoding="utf-8")
|
|
|
|
|
(entry / "INSTALLATION_COMPLETE").touch()
|
2026-09-13 14:28:31 -04:00
|
|
|
facts = Facts(canonical / "facts.json")
|
2026-09-13 18:03:57 -04:00
|
|
|
for name in selected:
|
2026-09-13 14:28:31 -04:00
|
|
|
package = get_package(name)
|
|
|
|
|
entry = canonical / package.store_entry(lock.version(name), target)
|
2026-09-13 18:03:57 -04:00
|
|
|
(entry / "payload").write_text(name, encoding="utf-8")
|
2026-09-13 14:28:31 -04:00
|
|
|
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))
|
2026-09-13 18:03:57 -04:00
|
|
|
canonical_before = {name: tree_digest(canonical / facts.get(name)["entry"]) for name in selected}
|
|
|
|
|
canonical_facts = (canonical / "facts.json").read_bytes()
|
refactor: make install-stamp.json the single runtime version identity
Runtime identity resolved through hermes_cli.__version__ (a static 0.0.0
on source installs, rewritten by release stamping) leaked v0.0.0 into
About, /api/health, User-Agents, and plugin compat, and source updates
showed "couldn't reach update server" because identity and channel
authority disagreed with the checkout.
Now: get_version_info() resolves install stamp -> live git -> unknown,
never pyproject metadata, never a package constant. Source checkouts
derive identity from their reachable release tag; the completion tail of
every successful install/update/historical takeover atomically rewrites
install-stamp.json with that identity; a stale source stamp whose commit
no longer matches HEAD defers to live git. ACP/TUI use derived_version
for display and base_version for protocol fields; all ~44 runtime
__version__ consumers migrated; hermes_cli.__version__ and generated
_version.py are gone; release stamping only touches the native manifests
external builders consume (nix/tauri/cargo) and passes release identity
straight into write_install_stamp.py; pyproject.toml stays inert 0.0.0.
Desktop no longer synthesizes a competing install-stamp.json: the
checkout owns its stamp, and desktop-bootstrap classification keys on
the bootstrap-complete marker. verify-bootstrap-version-stamp.py now
cross-checks the checkout's stamp (baseVersion + commit == HEAD).
Validation: 31-file focused suite green (version identity, stamping,
adoption, providers, gateway, acp/tui runtime identity, api server via
extras env, release graph); desktop tsc + 25 vitest green; real-repo
probe: base=unknown derived=git.0635606.dirty source=git on this
checkout; clean-env imports resolve entirely from this tree; windows
footgun + compat-pointer scans clean.
2026-09-23 11:41:01 -04:00
|
|
|
env = {**os.environ, "UV_OFFLINE": "1", "UV_PYTHON_DOWNLOADS": "never",
|
|
|
|
|
"UV_CACHE_DIR": str(tmp_path / "cache"), "HERMES_PAYLOAD_VERSION": "9.9.9"}
|
2026-09-06 22:38:58 -04:00
|
|
|
subprocess.run([uv, "lock", "--python", sys.executable], cwd=repo, env=env, check=True, capture_output=True)
|
2026-09-06 22:21:06 -04:00
|
|
|
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", "user.email=fixture@example.test", "commit", "-m", "fixture"], cwd=repo, check=True, capture_output=True)
|
|
|
|
|
monkeypatch.setattr("pm.paths.repo_root", lambda: repo)
|
2026-09-13 14:47:54 -04:00
|
|
|
(repo / "untracked").write_text("must not ship", encoding="utf-8")
|
2026-10-22 08:34:14 -07:00
|
|
|
monkeypatch.setattr(native, "_bundle_package_names", lambda: ["chromium", "uv"])
|
2026-09-18 23:27:05 -04:00
|
|
|
monkeypatch.setattr(importlib.import_module("pm.install"), "_prepare_artifacts",
|
2026-09-13 18:03:57 -04:00
|
|
|
lambda *args, **kwargs: pytest.fail("prepared tools reached acquisition"))
|
2026-09-11 18:14:43 -04:00
|
|
|
monkeypatch.setattr("pm.client.is_runtime", lambda: True)
|
|
|
|
|
monkeypatch.setattr("pm._uv._toolchain", lambda **kwargs: (Path(uv), Path(sys.executable)))
|
2026-09-13 14:47:54 -04:00
|
|
|
monkeypatch.setattr("pm.extras.ANCHORS", {"payloadtest": "bundle_probe.witness.present"})
|
2026-09-11 18:14:43 -04:00
|
|
|
import pm
|
2026-09-13 18:03:57 -04:00
|
|
|
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)
|
2026-09-11 18:14:43 -04:00
|
|
|
real_build = pm.build_environment
|
2026-09-12 13:20:02 -04:00
|
|
|
install_timeout = inspect.signature(real_build).parameters["timeout"].default
|
2026-09-06 22:21:06 -04:00
|
|
|
calls = []
|
2026-09-09 21:47:54 -04:00
|
|
|
fail_inventory = False
|
2026-09-06 22:21:06 -04:00
|
|
|
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
def build(**kwargs):
|
2026-09-11 18:14:43 -04:00
|
|
|
assert "uv" not in kwargs
|
|
|
|
|
assert kwargs["sealed"] is True
|
2026-09-13 18:03:57 -04:00
|
|
|
assert kwargs["python"] == target_python
|
|
|
|
|
assert kwargs["source"] == output / "hermes-agent"
|
2026-09-12 13:20:02 -04:00
|
|
|
assert kwargs.get("timeout", install_timeout) > install_timeout
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
calls.append(kwargs)
|
2026-09-06 22:21:06 -04:00
|
|
|
assert not (output / "manifest.json").exists()
|
2026-09-13 18:03:57 -04:00
|
|
|
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())
|
fix(pm): isolate bootstrap dependencies and unify YAML on ruamel
Activation reaches plugin discovery before the application dependencies
exist. Give PM its own locked Python project and runtime so it can install
or repair the application without importing that dependency tree.
Keep PM outside the application workspace. A shared uv workspace resolves
the application graph and cannot provide this isolation. Route mutations
through an isolated worker and preserve transaction callbacks, cancellation,
custom package registrations, and correlated receipts.
Use the same runtime builder for source installs and packaged payloads.
Keep offline wheelhouse support in that builder. Nix builds the independent
PM lock as a separate derivation. Refuse lazy-disabled bootstrap before
installing tools or dependencies.
Move first-party YAML readers and writers to ruamel. Keep the application
lock's transitive PyYAML requirements for third-party packages.
Verification:
- Focused canonical Python suite: 177 passed, 1 host-gated skip.
- Electron backend probes: 12 passed. Electron typecheck passed.
- Both uv locks, scoped lint, Bash syntax, and whitespace checks passed.
- Cold activation, corrupt-app repair, offline staging, and relocation ran.
- Built and exercised the Nix PM runtime and standalone YAML merge script.
Six broader caller test files retain the same 24 failing test IDs as an
archive of HEAD. The existing real-home guard blocks those tests before
they can exercise the affected paths. No full-suite pass is claimed.
Native Windows signing and full Bionic package execution remain unverified.
2026-09-11 12:23:51 -04:00
|
|
|
assert (output / "pm-runtime" / marker["python"]).resolve() == target_python
|
|
|
|
|
assert (output / "pm-runtime" / marker["sitePackages"]).is_dir()
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
result = real_build(**kwargs)
|
|
|
|
|
site = site_packages(output / "venv")
|
|
|
|
|
if fail_inventory:
|
|
|
|
|
shutil.rmtree(site)
|
2026-09-09 21:47:54 -04:00
|
|
|
return result
|
2026-09-06 22:21:06 -04:00
|
|
|
|
2026-09-11 18:14:43 -04:00
|
|
|
monkeypatch.setattr(pm, "build_environment", build)
|
2026-09-13 14:47:54 -04:00
|
|
|
monkeypatch.setenv("HERMES_RUNTIME_DIR", str(user_store))
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
monkeypatch.setenv("UV_CACHE_DIR", str(tmp_path / "cache"))
|
2026-09-13 14:28:31 -04:00
|
|
|
prepared = native.prepare_native(out=output, ref="HEAD", source=repo, cache=tmp_path / "cache", tools=canonical, env=env)
|
2026-09-13 18:03:57 -04:00
|
|
|
assert {name: tree_digest(canonical / facts.get(name)["entry"]) for name in selected} == canonical_before
|
|
|
|
|
assert (canonical / "facts.json").read_bytes() == canonical_facts
|
2026-09-13 14:28:31 -04:00
|
|
|
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)
|
2026-09-13 18:03:57 -04:00
|
|
|
strict.setattr(pm, "prepare_tools", forbidden)
|
|
|
|
|
strict.setattr(pm, "stage_tools", forbidden)
|
2026-09-13 14:28:31 -04:00
|
|
|
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"
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
assert calls[0]["all_extras"] is True
|
merge: unify shared product builders, caches, and Windows prerequisites
Merge ethie/shared-product-builders with the CI dependency cache and native Windows setup work. Preserve UTF-8 diagnostics in the shared Python environment runner. Pass a persistent cache through isolated native staging and PM-runtime construction. Reuse one Windows prerequisite installer from source setup, native adapters, and CI, preserving Rust homes across HOME isolation.
Verified 85 targeted Python tests (5 host skips), 18 JavaScript tests, workflow validation, and scoped lint/typecheck. On native Windows ARM64, five prerequisite contracts passed and the actual shared provider reused OpenSSL, compiled its header with MSVC, and retained Rust under isolated HOME. Full signed distribution builds and live Actions cache transfer remain CI verification.
2026-09-11 13:45:05 -04:00
|
|
|
assert calls[0]["cache"] == tmp_path / "cache"
|
2026-09-06 22:21:06 -04:00
|
|
|
assert (output / "hermes-agent/pyproject.toml").is_file()
|
refactor: make install-stamp.json the single runtime version identity
Runtime identity resolved through hermes_cli.__version__ (a static 0.0.0
on source installs, rewritten by release stamping) leaked v0.0.0 into
About, /api/health, User-Agents, and plugin compat, and source updates
showed "couldn't reach update server" because identity and channel
authority disagreed with the checkout.
Now: get_version_info() resolves install stamp -> live git -> unknown,
never pyproject metadata, never a package constant. Source checkouts
derive identity from their reachable release tag; the completion tail of
every successful install/update/historical takeover atomically rewrites
install-stamp.json with that identity; a stale source stamp whose commit
no longer matches HEAD defers to live git. ACP/TUI use derived_version
for display and base_version for protocol fields; all ~44 runtime
__version__ consumers migrated; hermes_cli.__version__ and generated
_version.py are gone; release stamping only touches the native manifests
external builders consume (nix/tauri/cargo) and passes release identity
straight into write_install_stamp.py; pyproject.toml stays inert 0.0.0.
Desktop no longer synthesizes a competing install-stamp.json: the
checkout owns its stamp, and desktop-bootstrap classification keys on
the bootstrap-complete marker. verify-bootstrap-version-stamp.py now
cross-checks the checkout's stamp (baseVersion + commit == HEAD).
Validation: 31-file focused suite green (version identity, stamping,
adoption, providers, gateway, acp/tui runtime identity, api server via
extras env, release graph); desktop tsc + 25 vitest green; real-repo
probe: base=unknown derived=git.0635606.dirty source=git on this
checkout; clean-env imports resolve entirely from this tree; windows
footgun + compat-pointer scans clean.
2026-09-23 11:41:01 -04:00
|
|
|
assert 'version="1.0.0"' in (output / "hermes-agent/pyproject.toml").read_text()
|
|
|
|
|
assert not (output / "hermes-agent/hermes_cli/_version.py").exists()
|
2026-09-13 14:47:54 -04:00
|
|
|
assert not (output / "hermes-agent/untracked").exists()
|
|
|
|
|
assert not (output / "hermes-agent/.git").exists()
|
|
|
|
|
facts = Facts(output / "tools/facts.json")
|
2026-10-01 22:42:51 +08:00
|
|
|
venv_fact = facts.get("venv")
|
|
|
|
|
assert venv_fact is not None
|
2026-10-07 07:04:52 +05:30
|
|
|
assert venv_fact["extras"] == json.loads((output / "enabled-features.json").read_text())["extras"]
|
2026-10-01 22:42:51 +08:00
|
|
|
assert "environment" not in venv_fact
|
2026-10-02 02:39:24 +08:00
|
|
|
from pm.install import venv_is_current
|
|
|
|
|
with monkeypatch.context() as patch:
|
2026-10-07 07:04:52 +05:30
|
|
|
# The desktop app points the bundled backend's store at the payload's tools dir.
|
|
|
|
|
patch.setenv("HERMES_RUNTIME_DIR", str(output / "tools"))
|
2026-10-02 02:39:24 +08:00
|
|
|
patch.setattr("pm.paths.repo_root", lambda: output / "hermes-agent")
|
|
|
|
|
assert venv_is_current(project_root=output / "hermes-agent")
|
2026-09-13 14:47:54 -04:00
|
|
|
for name in stale:
|
|
|
|
|
assert facts.get(name) is None
|
|
|
|
|
assert not (output / "tools" / f"cached-{name}").exists()
|
|
|
|
|
for name in selected:
|
2026-09-13 18:03:57 -04:00
|
|
|
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()
|
2026-09-13 14:47:54 -04:00
|
|
|
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("*")}
|
|
|
|
|
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
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}
|
2026-09-09 21:47:54 -04:00
|
|
|
feature_file = output / "enabled-features.json"
|
2026-09-13 14:47:54 -04:00
|
|
|
assert os.environ["HERMES_RUNTIME_DIR"] == str(user_store)
|
2026-09-09 21:47:54 -04:00
|
|
|
|
2026-09-13 14:47:54 -04:00
|
|
|
moved = tmp_path / "installed elsewhere"
|
|
|
|
|
output.rename(moved)
|
|
|
|
|
try:
|
2026-10-09 01:25:59 +02:00
|
|
|
run = subprocess.run([str(moved / command)], cwd=tmp_path, capture_output=True, text=True, timeout=30, check=False)
|
2026-09-13 14:47:54 -04:00
|
|
|
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"]),
|
2026-10-09 01:25:59 +02:00
|
|
|
cwd=tmp_path, env=runtime_api.runtime_environment(), capture_output=True, text=True, timeout=30, check=False)
|
2026-09-13 14:47:54 -04:00
|
|
|
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_python
|
2026-09-09 21:47:54 -04:00
|
|
|
before = feature_file.read_bytes()
|
|
|
|
|
fail_inventory = True
|
2026-09-13 18:03:57 -04:00
|
|
|
args = SimpleNamespace(out=str(output), ref="HEAD", source=repo, cache=tmp_path / "cache", tools=canonical)
|
|
|
|
|
assert native._stage_native(args) == 1
|
2026-09-09 21:47:54 -04:00
|
|
|
assert not (output / "manifest.json").exists()
|
|
|
|
|
assert feature_file.read_bytes() == before
|
2026-09-13 14:47:54 -04:00
|
|
|
assert os.environ["HERMES_RUNTIME_DIR"] == str(user_store)
|
2026-09-06 22:21:06 -04:00
|
|
|
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
from pm.package import InstallError
|
|
|
|
|
def fail_build(**kwargs):
|
|
|
|
|
raise InstallError("venv", "injected failure")
|
2026-09-11 18:14:43 -04:00
|
|
|
monkeypatch.setattr(pm, "build_environment", fail_build)
|
2026-09-13 18:03:57 -04:00
|
|
|
assert native._stage_native(args) == 1
|
2026-09-06 22:21:06 -04:00
|
|
|
assert not (output / "manifest.json").exists()
|
2026-09-13 14:47:54 -04:00
|
|
|
assert os.environ["HERMES_RUNTIME_DIR"] == str(user_store)
|
2026-09-08 01:47:57 -04:00
|
|
|
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
(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", "user.email=f@example.test", "commit", "-m", "different pins"], cwd=repo, check=True, capture_output=True)
|
2026-09-13 14:28:31 -04:00
|
|
|
monkeypatch.setattr("pm.prepare_tools", lambda names, **kwargs: pytest.fail("mismatched pins reached provisioning"))
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
with pytest.raises(ValueError, match="PM lock differs"):
|
2026-09-13 18:03:57 -04:00
|
|
|
native._stage_native(args)
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
|
2026-09-08 01:47:57 -04:00
|
|
|
|
2026-09-14 21:45:49 -04:00
|
|
|
def test_staged_cache_prunes_entries_the_lock_cannot_resolve(tmp_path, monkeypatch):
|
|
|
|
|
"""Ship gate: a rolled CI cache snapshot carries wheels for superseded pins;
|
|
|
|
|
the staged payload cache must contain exactly what the shipped lock resolves."""
|
|
|
|
|
lock = tmp_path / "repo"
|
|
|
|
|
lock.mkdir()
|
|
|
|
|
(lock / "uv.lock").write_text(
|
|
|
|
|
"[[package]]\n"
|
|
|
|
|
'name = "keep-me"\n'
|
|
|
|
|
'version = "1.0.0"\n'
|
|
|
|
|
'source = { registry = "https://pypi.org/simple" }\n'
|
|
|
|
|
"\n"
|
|
|
|
|
"[[package]]\n"
|
|
|
|
|
'name = "also-keep"\n'
|
|
|
|
|
'version = "2.0.0"\n'
|
|
|
|
|
'source = { registry = "https://pypi.org/simple" }\n',
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
cache = tmp_path / "cache"
|
|
|
|
|
buckets = {
|
|
|
|
|
"keep-me": ("keep_me-1.0.0.dist-info", True),
|
|
|
|
|
"also-keep": ("also_keep-2.0.0.dist-info", True),
|
|
|
|
|
"superseded-pin": ("superseded_pin-0.9.9.dist-info", False),
|
|
|
|
|
"old-dependency": ("old_dependency-3.2.1.dist-info", False),
|
|
|
|
|
}
|
|
|
|
|
for bucket, (dist_info, _keep) in buckets.items():
|
|
|
|
|
path = cache / "archive-v0" / bucket / dist_info
|
|
|
|
|
path.parent.mkdir(parents=True)
|
|
|
|
|
path.write_text("", encoding="utf-8")
|
|
|
|
|
# an unversioned bucket (no dist-info) must survive — it is not identifiable
|
|
|
|
|
unknown = cache / "archive-v0" / "unknownbucket"
|
|
|
|
|
unknown.mkdir(parents=True)
|
|
|
|
|
(unknown / "data.bin").write_bytes(b"x")
|
|
|
|
|
pruned = native.prune_uv_cache_to_lock(cache, lock)
|
|
|
|
|
assert pruned == 2
|
|
|
|
|
assert (cache / "archive-v0" / "keep-me").is_dir()
|
|
|
|
|
assert (cache / "archive-v0" / "also-keep").is_dir()
|
|
|
|
|
assert not (cache / "archive-v0" / "superseded-pin").exists()
|
|
|
|
|
assert not (cache / "archive-v0" / "old-dependency").exists()
|
|
|
|
|
assert (unknown / "data.bin").exists()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_staged_cache_prunes_wheel_index_entries_outside_the_lock(tmp_path):
|
|
|
|
|
lock = tmp_path / "repo"
|
|
|
|
|
lock.mkdir()
|
|
|
|
|
(lock / "uv.lock").write_text(
|
|
|
|
|
"[[package]]\n"
|
|
|
|
|
'name = "keep-me"\n'
|
|
|
|
|
'version = "1.0.0"\n'
|
|
|
|
|
'source = { registry = "https://pypi.org/simple" }\n',
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
cache = tmp_path / "cache"
|
|
|
|
|
for entry in ("keep-me", "superseded-pin"):
|
|
|
|
|
path = cache / "wheels-v6" / "pypi" / entry
|
|
|
|
|
path.mkdir(parents=True)
|
|
|
|
|
(path / "metadata.msgpack").write_bytes(b"")
|
|
|
|
|
sdist = cache / "sdists-v9" / "pypi" / "old-sdist-only"
|
|
|
|
|
sdist.mkdir(parents=True)
|
|
|
|
|
(sdist / "metadata.msgpack").write_bytes(b"")
|
|
|
|
|
native.prune_uv_cache_to_lock(cache, lock)
|
|
|
|
|
assert (cache / "wheels-v6" / "pypi" / "keep-me").is_dir()
|
|
|
|
|
assert not (cache / "wheels-v6" / "pypi" / "superseded-pin").exists()
|
|
|
|
|
assert not (cache / "sdists-v9" / "pypi" / "old-sdist-only").exists()
|
|
|
|
|
|
|
|
|
|
|
2026-11-02 22:52:10 +00:00
|
|
|
def test_staged_cache_keeps_a_dotted_dist_the_lock_resolves(tmp_path):
|
|
|
|
|
"""``ruamel.yaml`` and ``jaraco.classes`` keep the dot in their dist-info names, while
|
|
|
|
|
uv.lock lists them as ``ruamel-yaml``; the prune must compare normalized names or it
|
|
|
|
|
deletes the archive the shipped venv was installed from."""
|
|
|
|
|
lock = tmp_path / "repo"
|
|
|
|
|
lock.mkdir()
|
|
|
|
|
(lock / "uv.lock").write_text(
|
|
|
|
|
"[[package]]\n"
|
|
|
|
|
'name = "ruamel-yaml"\n'
|
|
|
|
|
'version = "0.18.16"\n'
|
|
|
|
|
'source = { registry = "https://pypi.org/simple" }\n',
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
cache = tmp_path / "cache"
|
|
|
|
|
bucket = cache / "archive-v0" / "bucket"
|
|
|
|
|
(bucket / "ruamel.yaml-0.18.16.dist-info").mkdir(parents=True)
|
|
|
|
|
index = cache / "wheels-v6" / "pypi" / "ruamel-yaml"
|
|
|
|
|
index.mkdir(parents=True)
|
|
|
|
|
|
|
|
|
|
assert native.prune_uv_cache_to_lock(cache, lock) == 0
|
|
|
|
|
assert bucket.is_dir()
|
|
|
|
|
assert index.is_dir()
|
|
|
|
|
|
|
|
|
|
|
fix(pm): drop uv cache links the prune left without a target
Staging now ships uv's wheel links as links, but the prune removes wheel
entries only under wheels-v*/pypi and sdists-v*/pypi. URL, git and
named-index wheels sit a hash directory deeper, so when the lock drops
one of them the prune deletes its archive-v0 bucket and leaves the link
pointing at nothing. publish_prepared's link check then rejects the
payload. Before links were kept, staging copied such an entry as a
self-contained directory, so the same prune left nothing dangling.
uv.lock has three such sources today (kittentts by URL, misaki and
psutil from git). With the pinned uv 0.13.5, a wheel installed from a
direct URL and then dropped from the lock reproduces it: stage, prune,
then the link check fails on wheels-v7/url/<hash>/gone-dep/<version>.
Finish the prune by removing links with no target in the wheel and
sdist families. The sweep does not depend on the layout. It also
repairs CI's rolling cache, which the setup-pm post-job runs through the
same prune.
Reported in review by @unsupportedpastels, whose regression test this
extends with a link the lock still resolves.
2026-11-03 01:15:57 +00:00
|
|
|
@pytest.mark.platforms("posix")
|
|
|
|
|
def test_prune_drops_a_url_wheel_link_whose_archive_it_pruned(tmp_path):
|
|
|
|
|
"""A URL, git or named-index wheel sits a hash directory deeper than ``pypi``. Once the
|
|
|
|
|
prune deletes its bucket, the link must go too: a payload that ships a link with no target
|
|
|
|
|
fails ``publish_prepared``. A link the lock still resolves stays."""
|
|
|
|
|
lock = tmp_path / "repo"
|
|
|
|
|
lock.mkdir()
|
|
|
|
|
(lock / "uv.lock").write_text('[[package]]\nname = "keep-me"\nversion = "1.0"\n', encoding="utf-8")
|
|
|
|
|
cache = tmp_path / "cache"
|
|
|
|
|
(cache / "archive-v0" / "gone" / "gone_dep-1.0.dist-info").mkdir(parents=True)
|
|
|
|
|
(cache / "archive-v0" / "kept" / "keep_me-1.0.dist-info").mkdir(parents=True)
|
|
|
|
|
url = cache / "wheels-v7" / "url" / "d87c3d39b3c6ef8c"
|
|
|
|
|
(url / "gone-dep").mkdir(parents=True)
|
|
|
|
|
(url / "keep-me").mkdir()
|
|
|
|
|
os.symlink("../../../../archive-v0/gone", url / "gone-dep" / "1.0-py3-none-any")
|
|
|
|
|
os.symlink("../../../../archive-v0/kept", url / "keep-me" / "1.0-py3-none-any")
|
|
|
|
|
|
|
|
|
|
native.prune_uv_cache_to_lock(cache, lock)
|
|
|
|
|
|
|
|
|
|
assert not (url / "gone-dep" / "1.0-py3-none-any").is_symlink(), "a dangling wheel link survived the prune"
|
|
|
|
|
assert (url / "keep-me" / "1.0-py3-none-any").resolve() == (cache / "archive-v0" / "kept").resolve()
|
|
|
|
|
|
|
|
|
|
|
2026-09-13 11:04:03 -04:00
|
|
|
@pytest.mark.parametrize("pointer, shard", [("revision.http", ""), ("revision.rev", "build-settings")])
|
|
|
|
|
def test_staged_cache_skips_build_inputs_before_copying(tmp_path, monkeypatch, pointer, shard):
|
|
|
|
|
cache = tmp_path / "cache"
|
|
|
|
|
revision = Path("sdists-v9/index/package/revision")
|
|
|
|
|
wheels = revision / shard
|
|
|
|
|
waste = {
|
|
|
|
|
revision / "src/target/release/build.exe": b"build output",
|
|
|
|
|
}
|
|
|
|
|
kept = {
|
|
|
|
|
wheels / "metadata.msgpack": b"wheel metadata",
|
2026-09-14 21:01:50 -04:00
|
|
|
wheels / "cache_proof-1.0-py3-none-any.whl": b"built wheel ZIP ships for offline rebuilds",
|
2026-09-13 11:04:03 -04:00
|
|
|
revision.parent / pointer: b"revision pointer",
|
|
|
|
|
wheels / "cache_proof-1.0-py3-none-any/src/template.whl": b"package data",
|
|
|
|
|
Path("archive-v0/entry/cache_proof/src/__init__.py"): b"archive data",
|
|
|
|
|
Path("other-bucket/src/keep.whl"): b"unrelated data",
|
|
|
|
|
}
|
|
|
|
|
for relative, data in {**waste, **kept}.items():
|
|
|
|
|
path = cache / relative
|
|
|
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
path.write_bytes(data)
|
|
|
|
|
copyfile = shutil.copyfile
|
|
|
|
|
|
|
|
|
|
def record_copy(source, destination, **kwargs):
|
|
|
|
|
assert Path(source).relative_to(cache) not in waste, "build inputs must never be copied"
|
|
|
|
|
return copyfile(source, destination, **kwargs)
|
|
|
|
|
|
|
|
|
|
shipped = tmp_path / "payload/uv-cache"
|
|
|
|
|
with monkeypatch.context() as patch:
|
|
|
|
|
patch.setattr(shutil, "copyfile", record_copy)
|
|
|
|
|
native.stage_uv_cache(cache, shipped)
|
|
|
|
|
assert all(not (shipped / relative).exists() for relative in waste)
|
|
|
|
|
assert all((shipped / relative).read_bytes() == data for relative, data in kept.items())
|
|
|
|
|
assert all((cache / relative).read_bytes() == data for relative, data in {**waste, **kept}.items())
|
|
|
|
|
|
|
|
|
|
|
2026-11-02 22:52:11 +00:00
|
|
|
@pytest.mark.platforms("posix")
|
|
|
|
|
def test_staged_cache_keeps_wheel_entries_as_links(tmp_path):
|
|
|
|
|
"""uv stores each cached wheel as a relative link into ``archive-v0/``. Following it
|
|
|
|
|
shipped every unpacked wheel twice and handed the seed a directory where uv renames
|
|
|
|
|
its own link (#141891); the payload must carry the link itself."""
|
|
|
|
|
cache = tmp_path / "cache"
|
|
|
|
|
bucket = cache / "archive-v0" / "bucket"
|
|
|
|
|
(bucket / "pkg").mkdir(parents=True)
|
|
|
|
|
(bucket / "pkg" / "__init__.py").write_text("shipped = True\n", encoding="utf-8")
|
|
|
|
|
wheel = cache / "wheels-v6" / "pypi" / "pkg"
|
|
|
|
|
wheel.mkdir(parents=True)
|
|
|
|
|
os.symlink("../../../archive-v0/bucket", wheel / "1.0-py3-none-any")
|
|
|
|
|
|
|
|
|
|
shipped = tmp_path / "payload" / "uv-cache"
|
|
|
|
|
native.stage_uv_cache(cache, shipped)
|
|
|
|
|
|
|
|
|
|
link = shipped / "wheels-v6" / "pypi" / "pkg" / "1.0-py3-none-any"
|
|
|
|
|
assert link.is_symlink(), "staging followed the wheel link and copied the archive again"
|
|
|
|
|
assert os.readlink(link) == "../../../archive-v0/bucket"
|
|
|
|
|
assert (link / "pkg" / "__init__.py").read_text(encoding="utf-8") == "shipped = True\n"
|
|
|
|
|
|
|
|
|
|
|
2026-09-14 21:01:50 -04:00
|
|
|
SELF_BUILD_BACKEND = '''import os, zipfile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
|
|
|
|
|
name = "cache_proof-1.0.0-py3-none-any.whl"
|
|
|
|
|
path = os.path.join(wheel_directory, name)
|
|
|
|
|
with zipfile.ZipFile(path, "w") as zf:
|
|
|
|
|
zf.writestr("cache_proof/__init__.py", "VALUE = 'installed from cached wheel'\\n")
|
|
|
|
|
info = "cache_proof-1.0.0.dist-info/"
|
|
|
|
|
zf.writestr(info + "METADATA", "Metadata-Version: 2.1\\nName: cache-proof\\nVersion: 1.0.0\\n")
|
|
|
|
|
zf.writestr(
|
|
|
|
|
info + "WHEEL",
|
|
|
|
|
"Wheel-Version: 1.0\\nGenerator: selfbuild\\nRoot-Is-Purelib: true\\nTag: py3-none-any\\n",
|
|
|
|
|
)
|
|
|
|
|
zf.writestr(info + "RECORD", "")
|
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_sdist(sdist_directory, config_settings=None):
|
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_requires_for_build_wheel(config_settings=None):
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_requires_for_build_sdist(config_settings=None):
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
|
|
|
|
|
path = os.path.join(metadata_directory, "cache_proof-1.0.0.dist-info")
|
|
|
|
|
os.mkdir(path)
|
|
|
|
|
with open(os.path.join(path, "METADATA"), "w") as handle:
|
|
|
|
|
handle.write("Metadata-Version: 2.1\\nName: cache-proof\\nVersion: 1.0.0\\n")
|
|
|
|
|
return "cache_proof-1.0.0.dist-info"
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_staged_cache_ships_full_wheel_set_and_rebuilds_offline(tmp_path):
|
2026-09-13 11:04:03 -04:00
|
|
|
from tests.pm._fixtures import _wheel
|
|
|
|
|
|
2026-09-08 01:47:57 -04:00
|
|
|
uv = shutil.which("uv")
|
|
|
|
|
assert uv, "native bundle test requires uv"
|
|
|
|
|
package = tmp_path / "package"
|
|
|
|
|
package.mkdir()
|
2026-09-14 21:01:50 -04:00
|
|
|
# Self-contained PEP 517 backend (stdlib only, requires=[]): the offline
|
|
|
|
|
# rebuild below must not depend on build tools absent from the fixture.
|
2026-09-08 01:47:57 -04:00
|
|
|
(package / "pyproject.toml").write_text(
|
2026-09-14 21:01:50 -04:00
|
|
|
'[build-system]\nrequires=[]\nbuild-backend="selfbuild"\nbackend-path=["."]\n',
|
2026-09-08 01:47:57 -04:00
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
2026-09-14 21:01:50 -04:00
|
|
|
(package / "selfbuild.py").write_text(SELF_BUILD_BACKEND, encoding="utf-8")
|
2026-09-08 01:47:57 -04:00
|
|
|
(package / "cache_proof.py").write_text("VALUE = 'installed from cached wheel'\n", encoding="utf-8")
|
|
|
|
|
dist = tmp_path / "dist"
|
|
|
|
|
dist.mkdir()
|
|
|
|
|
archive = dist / "cache_proof-1.0.0.tar.gz"
|
|
|
|
|
with tarfile.open(archive, "w:gz") as source:
|
|
|
|
|
source.add(package, arcname="cache_proof-1.0.0")
|
2026-09-13 11:04:03 -04:00
|
|
|
wheel = _wheel(dist, "wheel_proof")
|
|
|
|
|
for name, artifact in (("cache-proof", archive), ("wheel-proof", wheel)):
|
|
|
|
|
index = dist / "simple" / name
|
|
|
|
|
index.mkdir(parents=True)
|
|
|
|
|
digest = hashlib.sha256(artifact.read_bytes()).hexdigest()
|
|
|
|
|
(index / "index.html").write_text(
|
|
|
|
|
f'<a href="../../{artifact.name}#sha256={digest}">{artifact.name}</a>', encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
project = tmp_path / "project"
|
|
|
|
|
project.mkdir()
|
|
|
|
|
(project / "pyproject.toml").write_text(
|
|
|
|
|
'[project]\nname="offline-proof"\nversion="1.0"\nrequires-python=">=3.11"\n'
|
|
|
|
|
'dependencies=["cache-proof==1.0.0", "wheel-proof==1.0"]\n[tool.uv]\npackage=false\n',
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
2026-09-08 01:47:57 -04:00
|
|
|
cache = tmp_path / "build-cache"
|
|
|
|
|
env = {**os.environ, "UV_CACHE_DIR": str(cache), "UV_NO_CONFIG": "1", "UV_PYTHON_DOWNLOADS": "never"}
|
|
|
|
|
server = ThreadingHTTPServer(("127.0.0.1", 0), partial(SimpleHTTPRequestHandler, directory=str(dist)))
|
|
|
|
|
thread = threading.Thread(target=server.serve_forever, daemon=True)
|
|
|
|
|
thread.start()
|
2026-09-13 11:04:03 -04:00
|
|
|
index_url = f"http://127.0.0.1:{server.server_port}/simple"
|
2026-09-08 01:47:57 -04:00
|
|
|
try:
|
2026-09-14 21:01:50 -04:00
|
|
|
warm = subprocess.run(
|
2026-09-08 01:47:57 -04:00
|
|
|
[uv, "pip", "install", "--python", sys.executable, "--target", str(tmp_path / "first"),
|
2026-09-14 21:01:50 -04:00
|
|
|
"--no-deps", "--index-url", index_url,
|
2026-09-13 11:04:03 -04:00
|
|
|
"cache-proof==1.0.0", "wheel-proof==1.0"],
|
2026-09-14 21:01:50 -04:00
|
|
|
env=env, cwd=tmp_path, capture_output=True, text=True, timeout=60,
|
2026-10-09 01:25:59 +02:00
|
|
|
check=False,
|
2026-09-08 01:47:57 -04:00
|
|
|
)
|
2026-09-14 21:01:50 -04:00
|
|
|
assert warm.returncode == 0, warm.stderr + warm.stdout
|
2026-09-13 11:04:03 -04:00
|
|
|
locked = subprocess.run(
|
2026-09-14 21:01:50 -04:00
|
|
|
[uv, "lock", "--python", sys.executable, "--index-url", index_url],
|
2026-09-13 11:04:03 -04:00
|
|
|
env=env, cwd=project, capture_output=True, text=True, timeout=60,
|
2026-10-09 01:25:59 +02:00
|
|
|
check=False,
|
2026-09-13 11:04:03 -04:00
|
|
|
)
|
|
|
|
|
assert locked.returncode == 0, locked.stderr
|
|
|
|
|
warmed = subprocess.run(
|
|
|
|
|
[uv, "sync", "--python", sys.executable, "--frozen", "--index-url", index_url],
|
|
|
|
|
env=env, cwd=project, capture_output=True, text=True, timeout=60,
|
2026-10-09 01:25:59 +02:00
|
|
|
check=False,
|
2026-09-13 11:04:03 -04:00
|
|
|
)
|
|
|
|
|
assert warmed.returncode == 0, warmed.stderr
|
feat(bundles): slim the shipped uv cache to self-built wheels only
The desktop payloads shipped the builder's full uv cache (2.0GB mac,
1.1GB win-x64, 800MB win-arm64) so a mutable-venv rebuild could run
offline. But the bundle contract never needed offline rebuilds — it
needs rebuilds that never invoke a compiler: packages with no
downloadable wheel (sdist-only or platform gaps) would otherwise
demand Xcode CLT/MSVC/Rust on the user's machine.
prune_uv_cache_to_built keeps only what the builder compiled itself,
detected from the cache's own records (sdists-v9 entries, cached
wheels not listed in uv.lock, archive-v0 buckets by dist-info) and
drops the ~245 packages whose wheels PyPI re-serves in seconds.
Validated live on a clean host per target:
- macos arm64 (iris, no uv): 2.0GB -> 3MB; sync online, 0 builds,
pilk/psutil/alibabacloud-tea installed from the slim
- win11 arm64 (promise, no uv/MSVC): 800MB -> 48MB; sync online,
0 dependency builds, all 12 CI-built packages (cryptography,
httptools, brotlicffi, dependency-injector, ruamel-yaml-clib,
obstore, davey, firecrawl-anydoc, pilk, psutil, alibabacloud set)
import clean. The kept set matched the CI build log's Built list
exactly (12/12, no false positives).
Index-dir detection is name-agnostic (pypi/ vs custom --index-url
hashed dir), proven by the rewritten bundle test: sdist-only survives
the slim, downloadable wheels are dropped, the build machine's cache
is untouched, and an online rebuild compiles nothing.
2026-09-14 15:23:31 -04:00
|
|
|
|
|
|
|
|
built_zips = list(cache.rglob("*.whl"))
|
|
|
|
|
assert built_zips, "the actual uv build must create the redundant ZIP"
|
|
|
|
|
sources = [path for bucket in cache.glob("sdists-v*") for path in bucket.rglob("src") if path.is_dir()]
|
|
|
|
|
assert sources, "the actual uv build must leave its source tree in the cache"
|
|
|
|
|
shipped = tmp_path / "payload/uv-cache"
|
|
|
|
|
native.stage_uv_cache(cache, shipped)
|
|
|
|
|
assert all(not (shipped / path.relative_to(cache)).exists() for path in sources)
|
|
|
|
|
assert all(path.exists() for path in [*built_zips, *sources]), "the build machine's cache must not change"
|
2026-09-14 21:01:50 -04:00
|
|
|
# The full cache ships every wheel the build resolved, downloadable
|
|
|
|
|
# or built: a per-install venv rebuild must not depend on network
|
|
|
|
|
# reachability for any package the payload already shipped.
|
|
|
|
|
assert any(shipped.rglob("wheel_proof*")), "downloadable wheels ship in the full cache"
|
2026-11-02 22:52:11 +00:00
|
|
|
# uv's wheel entries are links into archive-v0/ (POSIX); each ships as the same link.
|
|
|
|
|
for link in (path for path in cache.rglob("*") if path.is_symlink()):
|
|
|
|
|
copy = shipped / link.relative_to(cache)
|
|
|
|
|
assert copy.is_symlink() and os.readlink(copy) == os.readlink(link), copy
|
|
|
|
|
# The payload prunes its cache to the lock after staging; the rebuild below reads that.
|
|
|
|
|
native.prune_uv_cache_to_lock(shipped, project)
|
2026-09-14 21:01:50 -04:00
|
|
|
|
|
|
|
|
# A fresh mutable venv rebuilds OFFLINE from the shipped cache alone.
|
feat(bundles): slim the shipped uv cache to self-built wheels only
The desktop payloads shipped the builder's full uv cache (2.0GB mac,
1.1GB win-x64, 800MB win-arm64) so a mutable-venv rebuild could run
offline. But the bundle contract never needed offline rebuilds — it
needs rebuilds that never invoke a compiler: packages with no
downloadable wheel (sdist-only or platform gaps) would otherwise
demand Xcode CLT/MSVC/Rust on the user's machine.
prune_uv_cache_to_built keeps only what the builder compiled itself,
detected from the cache's own records (sdists-v9 entries, cached
wheels not listed in uv.lock, archive-v0 buckets by dist-info) and
drops the ~245 packages whose wheels PyPI re-serves in seconds.
Validated live on a clean host per target:
- macos arm64 (iris, no uv): 2.0GB -> 3MB; sync online, 0 builds,
pilk/psutil/alibabacloud-tea installed from the slim
- win11 arm64 (promise, no uv/MSVC): 800MB -> 48MB; sync online,
0 dependency builds, all 12 CI-built packages (cryptography,
httptools, brotlicffi, dependency-injector, ruamel-yaml-clib,
obstore, davey, firecrawl-anydoc, pilk, psutil, alibabacloud set)
import clean. The kept set matched the CI build log's Built list
exactly (12/12, no false positives).
Index-dir detection is name-agnostic (pypi/ vs custom --index-url
hashed dir), proven by the rewritten bundle test: sdist-only survives
the slim, downloadable wheels are dropped, the build machine's cache
is untouched, and an online rebuild compiles nothing.
2026-09-14 15:23:31 -04:00
|
|
|
shutil.rmtree(cache, ignore_errors=True)
|
|
|
|
|
shutil.rmtree(tmp_path / "first", ignore_errors=True)
|
|
|
|
|
shutil.rmtree(project / ".venv", ignore_errors=True)
|
|
|
|
|
result = subprocess.run(
|
2026-09-14 21:01:50 -04:00
|
|
|
[uv, "sync", "--python", sys.executable, "--frozen", "--offline"],
|
feat(bundles): slim the shipped uv cache to self-built wheels only
The desktop payloads shipped the builder's full uv cache (2.0GB mac,
1.1GB win-x64, 800MB win-arm64) so a mutable-venv rebuild could run
offline. But the bundle contract never needed offline rebuilds — it
needs rebuilds that never invoke a compiler: packages with no
downloadable wheel (sdist-only or platform gaps) would otherwise
demand Xcode CLT/MSVC/Rust on the user's machine.
prune_uv_cache_to_built keeps only what the builder compiled itself,
detected from the cache's own records (sdists-v9 entries, cached
wheels not listed in uv.lock, archive-v0 buckets by dist-info) and
drops the ~245 packages whose wheels PyPI re-serves in seconds.
Validated live on a clean host per target:
- macos arm64 (iris, no uv): 2.0GB -> 3MB; sync online, 0 builds,
pilk/psutil/alibabacloud-tea installed from the slim
- win11 arm64 (promise, no uv/MSVC): 800MB -> 48MB; sync online,
0 dependency builds, all 12 CI-built packages (cryptography,
httptools, brotlicffi, dependency-injector, ruamel-yaml-clib,
obstore, davey, firecrawl-anydoc, pilk, psutil, alibabacloud set)
import clean. The kept set matched the CI build log's Built list
exactly (12/12, no false positives).
Index-dir detection is name-agnostic (pypi/ vs custom --index-url
hashed dir), proven by the rewritten bundle test: sdist-only survives
the slim, downloadable wheels are dropped, the build machine's cache
is untouched, and an online rebuild compiles nothing.
2026-09-14 15:23:31 -04:00
|
|
|
env={**env, "UV_CACHE_DIR": str(shipped)}, cwd=project,
|
|
|
|
|
capture_output=True, text=True, timeout=60,
|
2026-10-09 01:25:59 +02:00
|
|
|
check=False,
|
feat(bundles): slim the shipped uv cache to self-built wheels only
The desktop payloads shipped the builder's full uv cache (2.0GB mac,
1.1GB win-x64, 800MB win-arm64) so a mutable-venv rebuild could run
offline. But the bundle contract never needed offline rebuilds — it
needs rebuilds that never invoke a compiler: packages with no
downloadable wheel (sdist-only or platform gaps) would otherwise
demand Xcode CLT/MSVC/Rust on the user's machine.
prune_uv_cache_to_built keeps only what the builder compiled itself,
detected from the cache's own records (sdists-v9 entries, cached
wheels not listed in uv.lock, archive-v0 buckets by dist-info) and
drops the ~245 packages whose wheels PyPI re-serves in seconds.
Validated live on a clean host per target:
- macos arm64 (iris, no uv): 2.0GB -> 3MB; sync online, 0 builds,
pilk/psutil/alibabacloud-tea installed from the slim
- win11 arm64 (promise, no uv/MSVC): 800MB -> 48MB; sync online,
0 dependency builds, all 12 CI-built packages (cryptography,
httptools, brotlicffi, dependency-injector, ruamel-yaml-clib,
obstore, davey, firecrawl-anydoc, pilk, psutil, alibabacloud set)
import clean. The kept set matched the CI build log's Built list
exactly (12/12, no false positives).
Index-dir detection is name-agnostic (pypi/ vs custom --index-url
hashed dir), proven by the rewritten bundle test: sdist-only survives
the slim, downloadable wheels are dropped, the build machine's cache
is untouched, and an online rebuild compiles nothing.
2026-09-14 15:23:31 -04:00
|
|
|
)
|
|
|
|
|
assert result.returncode == 0, result.stderr
|
|
|
|
|
assert "Building" not in result.stderr and "Built" not in result.stdout, result.stderr + result.stdout
|
2026-09-08 01:47:57 -04:00
|
|
|
finally:
|
|
|
|
|
server.shutdown()
|
|
|
|
|
server.server_close()
|
|
|
|
|
thread.join(timeout=5)
|
2026-09-13 11:04:03 -04:00
|
|
|
python = project / ".venv" / ("Scripts/python.exe" if os.name == "nt" else "bin/python")
|
2026-09-08 01:47:57 -04:00
|
|
|
probe = subprocess.run(
|
2026-09-13 11:04:03 -04:00
|
|
|
[str(python), "-I", "-c",
|
|
|
|
|
"import cache_proof, wheel_proof; print(cache_proof.VALUE); print(wheel_proof.__version__)"],
|
|
|
|
|
cwd=tmp_path, env=env, capture_output=True, text=True, check=True, timeout=30,
|
2026-09-08 01:47:57 -04:00
|
|
|
)
|
2026-09-13 11:04:03 -04:00
|
|
|
assert probe.stdout.splitlines() == ["installed from cached wheel", "1.0"]
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_native_dispatch_isolates_process_state_on_real_child_failure(tmp_path, monkeypatch):
|
merge: unify shared product builders, caches, and Windows prerequisites
Merge ethie/shared-product-builders with the CI dependency cache and native Windows setup work. Preserve UTF-8 diagnostics in the shared Python environment runner. Pass a persistent cache through isolated native staging and PM-runtime construction. Reuse one Windows prerequisite installer from source setup, native adapters, and CI, preserving Rust homes across HOME isolation.
Verified 85 targeted Python tests (5 host skips), 18 JavaScript tests, workflow validation, and scoped lint/typecheck. On native Windows ARM64, five prerequisite contracts passed and the actual shared provider reused OpenSSL, compiled its header with MSVC, and retained Rust under isolated HOME. Full signed distribution builds and live Actions cache transfer remain CI verification.
2026-09-11 13:45:05 -04:00
|
|
|
# Compiler provisioning has its own native test; this probe must stop
|
|
|
|
|
# at the invalid revision without installing tools on a developer host.
|
fix(pm): prepare the Windows ARM64 compiler environment for every source dependency build
cryptography ships no win_arm64 wheel, so every Windows ARM64 venv sync
compiles it from the sdist and needs MSVC, Clang, Rust and static OpenSSL.
Only setup-hermes.ps1 (and so activate.ps1) prepared that environment,
between a `pm install --tools-only` and the real sync. install.ps1,
`hermes update` and repair ran the same sync without it and failed in
openssl-sys.
PM owns the sync, so PM prepares it. pm/native_build.py holds the adapter
(moved from scripts/build/windows_deps.py) plus source_build_environment(),
which prepares only on win32-arm64 when the synced project carries the
provider script. A payload has prebuilt dependencies and needs no compiler.
VenvPackage.apply and build_environment pass the result to uv children
only. It carries the bridged pip index settings, which managed_environment
applies only to the ambient environment. The state root stays the store
parent, so existing vcpkg/OpenSSL builds are reused.
setup-hermes.ps1 collapses to one `pm install`: the tools-only split existed
only for this preparation, and pm install already puts its tools on PATH
before the venv sync (pm/cli.py activate check).
Not yet verified live on Windows ARM64.
2026-09-23 16:07:47 -04:00
|
|
|
monkeypatch.setattr("pm.native_build.prepare_windows_environment", lambda **kwargs: dict(kwargs["env"]))
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "user-home"))
|
|
|
|
|
monkeypatch.setenv("HERMES_RUNTIME_DIR", str(tmp_path / "user-tools"))
|
|
|
|
|
before = dict(os.environ)
|
|
|
|
|
out = tmp_path / "output"
|
2026-09-12 13:11:36 -04:00
|
|
|
assert native.stage_native(SimpleNamespace(out=str(out), ref="missing-build-test-ref", cache=tmp_path / "cache")) != 0
|
refactor(build): share product recipes across distributions
Build TUI, web, desktop UI and runnable agent products from explicit
prepared inputs. Keep dependency preparation separate from distribution
packaging, with PM and native builds sharing uv environment construction.
Docker copies compiled frontend products instead of build dependencies.
Nix retains uv2nix environments and consumes shared assembly through store
references. Native desktop and Termux use the same launcher and frontend
contracts. Preserve the independent PM runtime and source imports from
arbitrary working directories.
Keep failed frontend builds from replacing the previous product, reject
source/output overlap, and bound dependency-process output draining.
Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its
missing package declaration on the base revision too.
Verified focused Python and JavaScript suites, Docker build/runtime checks,
Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY,
and real full-Chromium interaction. Native signed installers, Android device
installation and the full repository suite remain CI verification.
2026-09-11 13:16:55 -04:00
|
|
|
assert dict(os.environ) == before
|
|
|
|
|
assert not (tmp_path / "user-home").exists()
|
|
|
|
|
assert not (tmp_path / "user-tools").exists()
|
|
|
|
|
assert not (out / "manifest.json").exists()
|
|
|
|
|
assert not list(out.glob(".build-*"))
|
merge: unify shared product builders, caches, and Windows prerequisites
Merge ethie/shared-product-builders with the CI dependency cache and native Windows setup work. Preserve UTF-8 diagnostics in the shared Python environment runner. Pass a persistent cache through isolated native staging and PM-runtime construction. Reuse one Windows prerequisite installer from source setup, native adapters, and CI, preserving Rust homes across HOME isolation.
Verified 85 targeted Python tests (5 host skips), 18 JavaScript tests, workflow validation, and scoped lint/typecheck. On native Windows ARM64, five prerequisite contracts passed and the actual shared provider reused OpenSSL, compiled its header with MSVC, and retained Rust under isolated HOME. Full signed distribution builds and live Actions cache transfer remain CI verification.
2026-09-11 13:45:05 -04:00
|
|
|
|
|
|
|
|
|
2026-09-13 14:28:31 -04:00
|
|
|
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"
|
2026-09-13 18:03:57 -04:00
|
|
|
assert not output.with_name(output.name + ".prepared.json").exists()
|
2026-09-13 14:28:31 -04:00
|
|
|
|
2026-09-12 02:05:48 -04:00
|
|
|
|
2026-09-13 14:47:54 -04:00
|
|
|
@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
|
2026-09-12 02:05:48 -04:00
|
|
|
|
2026-09-13 14:47:54 -04:00
|
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path / "host")
|
fix(pm): prepare the Windows ARM64 compiler environment for every source dependency build
cryptography ships no win_arm64 wheel, so every Windows ARM64 venv sync
compiles it from the sdist and needs MSVC, Clang, Rust and static OpenSSL.
Only setup-hermes.ps1 (and so activate.ps1) prepared that environment,
between a `pm install --tools-only` and the real sync. install.ps1,
`hermes update` and repair ran the same sync without it and failed in
openssl-sys.
PM owns the sync, so PM prepares it. pm/native_build.py holds the adapter
(moved from scripts/build/windows_deps.py) plus source_build_environment(),
which prepares only on win32-arm64 when the synced project carries the
provider script. A payload has prebuilt dependencies and needs no compiler.
VenvPackage.apply and build_environment pass the result to uv children
only. It carries the bridged pip index settings, which managed_environment
applies only to the ambient environment. The state root stays the store
parent, so existing vcpkg/OpenSSL builds are reused.
setup-hermes.ps1 collapses to one `pm install`: the tools-only split existed
only for this preparation, and pm install already puts its tools on PATH
before the venv sync (pm/cli.py activate check).
Not yet verified live on Windows ARM64.
2026-09-23 16:07:47 -04:00
|
|
|
monkeypatch.setattr("pm.native_build.prepare_windows_environment", lambda **kwargs: dict(kwargs["env"]))
|
2026-09-13 14:47:54 -04:00
|
|
|
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 = {}
|
2026-09-12 02:05:48 -04:00
|
|
|
for key, name in (("CARGO_HOME", ".cargo"), ("RUSTUP_HOME", ".rustup")):
|
2026-09-13 14:47:54 -04:00
|
|
|
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"
|
2026-09-12 02:05:48 -04:00
|
|
|
|
2026-10-09 20:46:55 +02:00
|
|
|
def child(command, *, cwd, env, check):
|
2026-09-13 14:47:54 -04:00
|
|
|
assert command[command.index("-m") + 1] == "scripts.bundles.native"
|
2026-09-12 02:05:48 -04:00
|
|
|
return run([sys.executable, "-c",
|
2026-09-13 14:47:54 -04:00
|
|
|
"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]))",
|
2026-10-09 20:46:55 +02:00
|
|
|
str(observed), str(status)], cwd=cwd, env=env, check=check)
|
2026-09-12 02:05:48 -04:00
|
|
|
|
|
|
|
|
monkeypatch.setattr(native.subprocess, "run", child)
|
2026-09-13 14:47:54 -04:00
|
|
|
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)
|
2026-09-12 02:05:48 -04:00
|
|
|
assert dict(os.environ) == before
|