Some checks failed
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
auto-fix lint issues & formatting / Generate eslint --fix patch (push) Has been cancelled
auto-fix lint issues & formatting / Apply patch (push) Has been cancelled
Skills Index Freshness Check / check-freshness (push) Has been cancelled
Skills Index Freshness Check / check-catalog-cors (push) Has been cancelled
Docs Search Monitor / probe (push) Has been cancelled
`pnpm run dist:bundled` stages its payload through scripts/bundles/stage.py, not the prepared desktop builder. Its automatic route compiled only the TUI and dashboard, so a payload stamped `bundled` shipped no Webapp and `hermes webapp` stopped at "This desktop app ships no Webapp renderer". Install the Desktop workspace in the frontend snapshot, compile the Webapp there and pass it to stage_native. The native staging child takes its products as flags and only knew --tui/--web, so it also learns --webapp; without that, handing it the Webapp exits 2 on an unrecognized argument. The regression test runs stage.main through the real stage_native argv into native.main and asserts the planted payload: red on the PR head (no dist-webapp), red with stage.py alone changed (argparse exit 2). Reported by @kvnloo on #154325, whose b294b532 changed stage.py the same way. Co-authored-by: Kevin Rajan <7121943+kvnloo@users.noreply.github.com>
92 lines
4.3 KiB
Python
92 lines
4.3 KiB
Python
"""Every desktop bundle that carries an agent payload plants the prebuilt Webapp beside the TUI and
|
|
the dashboard: the payload has no sources to build one from, so `hermes webapp` in the app serves it."""
|
|
from __future__ import annotations
|
|
|
|
import contextlib
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from scripts.bundles import desktop
|
|
|
|
|
|
def _compile(argv: list[str], **_kwargs) -> None:
|
|
"""Stands in for the product compilers: each writes its product, marked with its builder's name."""
|
|
script = Path(argv[1]).name
|
|
if script not in {"tui.mjs", "web.mjs", "webapp.mjs"}:
|
|
return
|
|
out = Path(argv[argv.index("--out") + 1])
|
|
if script == "tui.mjs":
|
|
(out / "dist").mkdir(parents=True)
|
|
(out / "dist/entry.js").write_text(script, encoding="utf-8")
|
|
(out / "package.json").write_text('{"type": "module"}', encoding="utf-8")
|
|
else:
|
|
out.mkdir(parents=True)
|
|
(out / "index.html").write_text(script, encoding="utf-8")
|
|
|
|
|
|
@pytest.mark.parametrize("variant", ["bundled", "store"])
|
|
def test_every_payload_bundle_plants_the_prebuilt_webapp(tmp_path, monkeypatch, variant):
|
|
from scripts.build.agent import plant_surfaces
|
|
from scripts.bundles import desktop_inputs, desktop_prepare, native
|
|
|
|
payload = tmp_path / "payload" / "hermes-agent"
|
|
request = SimpleNamespace(source=tmp_path / "checkout", target="host", channel_request=None,
|
|
release_epoch=None, version="1.2.3", commit="c" * 40, tag=None, workspaces=list)
|
|
prepared = SimpleNamespace(request=request, validate=lambda: None, node=Path("node"), icon_python=Path("python"),
|
|
packager=tmp_path / "packager", native=tmp_path / "native",
|
|
native_toolchain="fixture", payload=tmp_path / "payload.prepared.json")
|
|
|
|
def finish(prepared_payload, frontends):
|
|
assert prepared_payload == prepared.payload
|
|
plant_surfaces(payload, frontends)
|
|
return 0
|
|
|
|
monkeypatch.setattr(desktop, "run", _compile)
|
|
monkeypatch.setattr(desktop, "flavored_assets", lambda *_a: contextlib.nullcontext())
|
|
monkeypatch.setattr(native, "finish_native", finish)
|
|
monkeypatch.setattr(desktop_prepare, "require_source", lambda *_a: None)
|
|
monkeypatch.setattr(desktop_inputs, "validate_builder_identity", lambda *_a: None)
|
|
monkeypatch.setattr(desktop_inputs, "select_variant", lambda _prepared, chosen: chosen)
|
|
monkeypatch.setattr(desktop_inputs, "build_environment", lambda *_a: {})
|
|
monkeypatch.setattr(desktop_inputs, "packaging_environment", lambda *_a: {})
|
|
|
|
desktop._build_prepared(prepared, [], variant)
|
|
|
|
assert (payload / "apps/desktop/dist-webapp/index.html").read_text(encoding="utf-8") == "webapp.mjs"
|
|
assert (payload / "hermes_cli/web_dist/index.html").read_text(encoding="utf-8") == "web.mjs"
|
|
assert (payload / "hermes_cli/tui_dist/entry.js").read_text(encoding="utf-8") == "tui.mjs"
|
|
|
|
|
|
def test_source_bundle_staging_plants_the_prebuilt_webapp(tmp_path, monkeypatch):
|
|
"""`pnpm run dist:bundled` stages through scripts/bundles/stage.py, whose native child parses its own argv."""
|
|
from scripts.build.agent import plant_surfaces
|
|
from scripts.bundles import native, stage
|
|
|
|
payload = tmp_path / "out" / "hermes-agent"
|
|
|
|
def staged(args):
|
|
plant_surfaces(payload, args.frontends)
|
|
return 0
|
|
|
|
def run(argv, **kwargs):
|
|
if argv[0] == "/prepared/node":
|
|
return _compile(argv, **kwargs)
|
|
assert argv[1:4] == ["-B", "-m", "scripts.bundles.native"]
|
|
monkeypatch.setattr(sys, "argv", ["native", *argv[4:]])
|
|
return subprocess.CompletedProcess(argv, native.main())
|
|
|
|
monkeypatch.setattr(stage.shutil, "which", lambda _name: "/prepared/node")
|
|
monkeypatch.setattr("scripts.bundles.payload.snapshot", lambda _root, _ref, destination: destination.mkdir())
|
|
monkeypatch.setattr("scripts.build.icon_environment.prepare_icon_environment", lambda *_a: sys.executable)
|
|
monkeypatch.setattr(subprocess, "run", run)
|
|
monkeypatch.setattr(native, "_stage_native", staged)
|
|
|
|
assert stage.main(["--out", str(tmp_path / "out")]) == 0
|
|
|
|
assert (payload / "apps/desktop/dist-webapp/index.html").read_text(encoding="utf-8") == "webapp.mjs"
|
|
assert (payload / "hermes_cli/web_dist/index.html").read_text(encoding="utf-8") == "web.mjs"
|