2026-09-10 05:42:18 -04:00
|
|
|
"""Tagless packaging enters the real builder with an exact source identity."""
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import json
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
import shutil
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from scripts.bundles import desktop
|
|
|
|
|
|
|
|
|
|
from tests.ci.test_desktop_release_tag_admission import _BASH, _child_env, _git, _seed_repo
|
|
|
|
|
|
|
|
|
|
|
2026-09-11 20:15:44 -04:00
|
|
|
@pytest.mark.parametrize("variant", ["bundled", "light"])
|
2026-09-10 05:42:18 -04:00
|
|
|
def test_desktop_build_reaches_the_managed_payload_with_commit_ref(tmp_path, monkeypatch, variant):
|
|
|
|
|
_, repo = _seed_repo(tmp_path)
|
|
|
|
|
sha = _git("rev-parse", "HEAD", cwd=repo)
|
|
|
|
|
(repo / "pyproject.toml").write_text('[project]\nname="x"\nversion="9.9.9"\n', encoding='utf-8')
|
|
|
|
|
monkeypatch.setenv("HERMES_PAYLOAD_TAG", "v9.9.9")
|
|
|
|
|
monkeypatch.setenv("GITHUB_SHA", "b" * 40)
|
|
|
|
|
monkeypatch.setenv("BUILD_NUMBER", "123")
|
2026-09-11 15:59:08 -04:00
|
|
|
defaults = {"HERMES_GUEST_ONBOARDING": "1", "HERMES_DATA_DIR_SUFFIX": "magic-test", "HERMES_HOME": None}
|
2026-09-11 11:45:00 -04:00
|
|
|
monkeypatch.setenv("HERMES_BUNDLE_ENV_JSON", json.dumps(defaults))
|
2026-09-11 18:14:43 -04:00
|
|
|
monkeypatch.setattr(desktop.shutil, "which", lambda name: None if name == "uv" else name)
|
2026-09-10 05:42:18 -04:00
|
|
|
monkeypatch.setattr(desktop, "npm_command", lambda node: [node, "npm-cli.js"])
|
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
|
|
|
monkeypatch.setattr("scripts.build.windows_deps.prepare_windows_environment", lambda **kwargs: dict(kwargs["env"]))
|
2026-09-10 05:42:18 -04:00
|
|
|
from pm.store import current_target
|
|
|
|
|
target_arch = current_target().split("-")[1]
|
|
|
|
|
def capture(argv, cwd):
|
|
|
|
|
if argv[0] == "git":
|
|
|
|
|
return _git(*argv[1:], cwd=cwd)
|
|
|
|
|
if "process.arch" in argv:
|
|
|
|
|
return target_arch
|
|
|
|
|
return "26.7.0"
|
|
|
|
|
monkeypatch.setattr(desktop, "capture", capture)
|
|
|
|
|
(repo / "package-lock.json").write_text("{}", encoding="utf-8")
|
|
|
|
|
(repo / "node_modules").mkdir()
|
|
|
|
|
(repo / 'apps/desktop').mkdir(parents=True)
|
|
|
|
|
(repo / 'ui-tui/dist').mkdir(parents=True)
|
|
|
|
|
(repo / 'ui-tui/dist/entry.js').write_text('source fixture', encoding='utf-8')
|
|
|
|
|
(repo / 'hermes_cli/web_dist').mkdir(parents=True)
|
|
|
|
|
(repo / 'hermes_cli/web_dist/index.html').write_text('source fixture', encoding='utf-8')
|
|
|
|
|
calls = []
|
|
|
|
|
def run(argv, *, cwd, env):
|
|
|
|
|
assert cwd.resolve().is_relative_to(repo.resolve())
|
|
|
|
|
calls.append((argv, cwd, env.copy()))
|
|
|
|
|
assert env.get("HERMES_PAYLOAD_TAG", "") == ""
|
|
|
|
|
assert env["HERMES_BUILD_COMMIT"] == sha
|
|
|
|
|
assert env["GITHUB_SHA"] == sha
|
2026-09-11 18:14:43 -04:00
|
|
|
assert env["HERMES_PYTHON"] == sys.executable
|
2026-09-10 05:42:18 -04:00
|
|
|
assert env["HERMES_PAYLOAD_VERSION"] == "0.1.2"
|
2026-09-11 11:45:00 -04:00
|
|
|
assert json.loads(env["HERMES_BUNDLE_ENV_JSON"]) == defaults
|
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
|
|
|
if "scripts.bundles.stage" in argv:
|
|
|
|
|
assert argv[argv.index("--ref") + 1] == sha
|
|
|
|
|
assert "--tui" in argv and "--web" in argv
|
2026-09-10 05:42:18 -04:00
|
|
|
payload = repo / 'apps/desktop/build/agent-payload'
|
|
|
|
|
(payload / 'hermes-agent').mkdir(parents=True)
|
|
|
|
|
(payload / 'manifest.json').write_text(json.dumps({'repo': 'hermes-agent', 'target': current_target()}), encoding='utf-8')
|
|
|
|
|
monkeypatch.setattr(desktop, "run", run)
|
|
|
|
|
desktop.build(repo, None, variant, ['--publish=never'], commit_build=sha)
|
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 any('scripts.bundles.stage' in argv for argv, _, _ in calls) == (variant != 'light')
|
2026-09-10 05:42:18 -04:00
|
|
|
argv, cwd, env = calls[-1]
|
|
|
|
|
assert argv[:5] == ['node', 'npm-cli.js', 'run', 'builder', '--']
|
|
|
|
|
assert '-c.extraMetadata.version=0.1.2' in argv
|
|
|
|
|
assert argv[-1] == '--publish=never'
|
|
|
|
|
assert cwd == repo / 'apps/desktop'
|
|
|
|
|
assert env['HERMES_DESKTOP_VARIANT'] == variant
|
|
|
|
|
if os.name == 'nt':
|
|
|
|
|
assert 'BUILD_NUMBER' not in env
|
|
|
|
|
before = len(calls)
|
|
|
|
|
for tag, commit in [('v0.1.2', sha), (None, 'b' * 40), (None, 'short')]:
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
|
desktop.build(repo, tag, variant, [], commit_build=commit)
|
|
|
|
|
assert len(calls) == before
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-09-11 20:15:44 -04:00
|
|
|
@pytest.mark.parametrize("tag,commit", [(None, "a" * 40), ("v1.2.3-canary.20260911120000", None)])
|
|
|
|
|
def test_store_build_rejects_nonstable_before_reading_or_preparing_repo(tmp_path, tag, commit):
|
|
|
|
|
absent = tmp_path / "must-not-be-created"
|
|
|
|
|
with pytest.raises(ValueError, match="Store.*stable"):
|
|
|
|
|
desktop.build(absent, tag, "store", [], commit_build=commit)
|
|
|
|
|
assert not absent.exists()
|
|
|
|
|
|
|
|
|
|
|
2026-09-10 05:42:18 -04:00
|
|
|
def test_termux_commit_args_reach_prerequisite_checks_without_mutation(tmp_path):
|
|
|
|
|
repo = Path(__file__).resolve().parents[2]
|
|
|
|
|
out = tmp_path / "must-not-be-written"
|
|
|
|
|
helper = tmp_path / "bin"
|
|
|
|
|
helper.mkdir()
|
|
|
|
|
# Empty prerequisite commands are not build substitutes: stop at the first
|
|
|
|
|
# actual prerequisite check, before any payload or output is created.
|
|
|
|
|
env = _child_env(PATH=str(helper), HERMES_PAYLOAD_TAG="")
|
|
|
|
|
scripts = [repo / "scripts/termux/termux_build.sh", repo / "scripts/termux/build_deb.sh"]
|
|
|
|
|
for script in scripts:
|
|
|
|
|
args = ["--repo", str(repo), "--commit", "a" * 40, "--out", str(out)]
|
|
|
|
|
if script.name == "build_deb.sh":
|
|
|
|
|
args += ["--payload", str(tmp_path / "absent")]
|
|
|
|
|
result = subprocess.run([_BASH, str(script), *args], env=env, cwd=tmp_path,
|
|
|
|
|
capture_output=True, text=True, timeout=30)
|
|
|
|
|
assert result.returncode == 1, result.stdout + result.stderr
|
|
|
|
|
assert "usage:" not in result.stderr
|
|
|
|
|
assert not out.exists()
|