Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.
Rust ai-agentsai-gatewayclaude-codecodexcoding-agentcost-optimizationdeepseekllm-gatewayllm-routerlocal-firstmodel-routingrusttask-routingtauri
fix(pilot): snapshot CPA manifest contents for build reuse (#184)
aias00239909238a5c
diff --git a/docs/code-map/testing.md b/docs/code-map/testing.mdindex 15eff29c..5c903cd2 100644--- a/docs/code-map/testing.md+++ b/docs/code-map/testing.md@@ -16,6 +16,13 @@ and its [native executor](../../scripts/windows-dev-host.py), reached throughthe project owns artifact admission, exact-case execution and revision-bound evidence.Its four temporary-directory native artifact ACL/recovery cases can execute withoutreplacing an existing installation; installed-product cases still require a fresh profile.+Reusable Desktop Pilot build admission belongs to+[pilot-builds.py](../../scripts/pilot-builds.py); its+[lifecycle regressions](../../scripts/test-pilot-builds.py) cover manifest-content+identity, frozen snapshots and checks before reuse/start using fake build/launch tools.+The separate `--real-consumer` case is required by the affected CI selection and+checks the production Rust build-script and embedding declaration; local default+checks never compile or execute those temporary Rust programs.[Orphaned data preparation](../../scripts/windows-dev-profile.py) preserves completebackups after explicit user authorization; it does not establish a product scenario.[Native Desktop session actions](../../scripts/windows-desktop-session.py) admitdiff --git a/docs/github-actions-validation.md b/docs/github-actions-validation.mdindex fac46dfe..977e5d06 100644--- a/docs/github-actions-validation.md+++ b/docs/github-actions-validation.md@@ -64,6 +64,19 @@ Rust runners and depend on the frontend result without rebuilding it there. The`backend` status is a small aggregate job, so the public branch-protection contract remainsstable while individual shard jobs can run concurrently.+Pilot manifest inputs, reusable-build tooling and selection-rule changes select+`python3 scripts/test-pilot-builds.py --real-consumer` in Actions; full CI plans+select it as well. This uses the existing selected-tooling executor for tooling-only+PRs, or the affected/full backend gates when Rust product checks are also selected.+Failure blocks the aggregate `backend` result. The explicit entry requires exactly+one executed, unskipped case and a real compiler. Its four bounded subprocess phases+retain exit codes and stdout/stderr under `artifacts/ci/pilot-manifest-consumer/`,+included in the existing CI artifact upload even on failure. The default local+`test-pilot-builds.py` invocation runs fixture-only regressions and never executes+these temporary Rust programs, regardless of compiler availability. The CI case+proves build-script/embedding consumption of the frozen snapshot, not native Desktop,+CPA, provider or installation acceptance.+Changes to `gateway-core.yml`, `ci-run.py`, or `ci-shards.py` force a full plan on the pullrequest because those files define the hosted backend execution contract. Changes only totheir tests or documentation keep the ordinary tooling-only selection.diff --git a/docs/test-selection.md b/docs/test-selection.mdindex 5d6abd68..79177877 100644--- a/docs/test-selection.md+++ b/docs/test-selection.md@@ -37,6 +37,7 @@ semantics, explicit focused/final run associations and the required agent feedba| Hosted backend workflow and execution adapters (`gateway-core.yml`, `ci-run.py`, `ci-shards.py`) | Full hosted matrix, because these files decide what backend validation actually runs; their unit tests alone do not prove the real Actions entry path. || `scripts/test-plan.py`, `scripts/test-test-plan.py`, hosted adapter tests, and the operator skill `.agents/skills/hiroute-integrate/SKILL.md` | Selection and shard-coverage regression tests; no Rust or frontend build when the execution adapters themselves are unchanged. || HOME validation routing and local/SSH Rust runner tooling | Routing, runner and Pilot launcher Python regressions; no Rust/frontend build unless the change also affects product code. |+| Pilot CPA manifest producer/consumer, reusable-build tests or selection rules | Default local Pilot checks use fake build/launch tools. In Actions (`GITHUB_ACTIONS=true`), affected paths and full plans additionally select the explicit `test-pilot-builds.py --real-consumer` command; its single real Rust case is required and cannot pass by skipping or selecting nothing. No full Desktop acceptance is added. || Bounded manual local GC wrapper | Wrapper and shared local-runner Python regressions; deletion policy remains in the runner. No Rust/frontend build. || Bounded Gateway runtime/protocol tests, routing fixtures, Responses request helper | Package Clippy, explicit target/consumer tests and coverage gates; runtime test changes also select the protocol matrix, and the Responses helper retains the coverage gate and indirect smoke consumer. Gateway runtime includes the known `serde_json/preserve_order` combination from #94. || Real Worker test entries and native-context fixtures | Bounded package compilation plus separate required `product_checks`; ignored native cases are never counted as ordinary Cargo success. Shared native-context fixtures select both Codex/Claude and Qoder consumers. |diff --git a/docs/validation-routing.md b/docs/validation-routing.mdindex 7ef35b87..83f1f750 100644--- a/docs/validation-routing.md+++ b/docs/validation-routing.md@@ -634,6 +634,38 @@ contents and all three executable identities/digests. Same-owner acquire isidempotent; different owners share binaries with independent leases and sessions.An invalid existing bundle is retained and reported, not silently rebuilt.+The recipe binds the effective Desktop CPA manifest's exact content digest. The+checked-in default is read from the exact candidate blob; an explicit+`HIROUTE_CPA_MANIFEST` is read on the execution host, resolving relative paths from+the execution repository's `apps/desktop/src-tauri` directory. Ingestion captures+and validates the bytes once, then hashes that buffer. Equal bytes reuse the same+build even at different paths or through default versus explicit selection, when+all other inputs match. The original path is not retained in recipes, lease state+or status output.++Compilation consumes a private build-owned snapshot of the captured bytes. Reuse+and each Pilot start check that snapshot along with the existing frontend and+executable attestations. Changing or deleting the ingestion source afterwards does+not invalidate an acquired build or lease. A fresh acquisition reads the current+input: changed bytes select another identity, and a missing, unreadable, symbolic-link,+non-regular or invalid-JSON input fails before the managed build starts. JSON must be+a UTF-8 object without non-finite constants (`NaN` or `Infinity`); Python does not+duplicate the native manifest schema. Hardlinked regular source files are admitted+by their captured contents.++`python3 scripts/test-pilot-builds.py` runs the default local fixture suite. It+checks snapshot bytes/permissions, build-environment wiring, source changes,+rejection paths and lease/cleanup ownership with fake build and launch tools, even+when `rustc` is installed. It does not establish native product acceptance.+The explicit `python3 scripts/test-pilot-builds.py --real-consumer` entry belongs+to required CI validation, selected through `test-plan.py` for affected manifest+producer/consumer/tooling paths and full CI plans. It must execute exactly one+case with a real compiler; a missing compiler, skipped case, empty selection or+failure is nonzero. Each subprocess phase retains exit, stdout and stderr in+`artifacts/ci/pilot-manifest-consumer/` before temporary fixture cleanup. The case+checks the production `build.rs` and embedding declaration after the original+source is removed; it does not launch Desktop, CPA or a provider.+Use `pilot-build start --lease LEASE --case CASE` to launch each scenario withthe existing isolated Pilot launcher. It returns the session and socket for`pilot-cli`. All scenarios for that lease use the same build. These manageddiff --git a/issue-spec/specs/product-smoke-verification/spec.md b/issue-spec/specs/product-smoke-verification/spec.mdindex 96631ad6..c0c40097 100644--- a/issue-spec/specs/product-smoke-verification/spec.md+++ b/issue-spec/specs/product-smoke-verification/spec.md@@ -79,6 +79,19 @@ current source/build/artifact proof rather than lower trust checks. Real processlistener/protocol and independent outcome evidence are required; static goldens/fixture self-report/model success text are not actual user content or effects.+Reusable native Desktop build identity MUST bind the exact CPA manifest bytes+captured and validated at acquisition, resolving the default from the exact+candidate or an explicit package-relative source. Compilation MUST consume a private+build-owned snapshot of that same captured buffer. Equal bytes MUST permit reuse+across source paths and default/explicit selection when all other build inputs+match. Original source paths MUST NOT be retained in recipes, lease state or public+evidence. Reuse and startup MUST verify the snapshot and existing artifact+attestations; later source modification or deletion MUST NOT invalidate an acquired+build or lease. A fresh acquisition MUST inspect its current input and reject+missing, unreadable, symbolic-link, special-file or invalid UTF-8 JSON object input,+including non-finite JSON constants, before starting the managed build. A hardlinked+regular source is admissible by its captured contents.+A missing essential publish/call step or substituted canned body MUST fail therelevant oracle. Evidence-generation integrity is verified before/after launch;large artifact verification time is runner overhead, not consumed from product-step@@ -101,6 +114,16 @@ environment. Missing, changed or conflicting selected evidence MUST fail admissi- **AND** a missing, corrupt, escaping or conflicting selected receipt remains afailure even when another valid receipt has the same executable digest.+#### Scenario: A changed CPA source selects a new build without invalidating an old lease++- **WHEN** an explicit CPA manifest is selected for a reusable Desktop Pilot build and its bytes later change at the same path+- **THEN** a fresh acquisition has a different build identity, while the old lease remains usable with its verified frozen snapshot even if the source is subsequently deleted.++#### Scenario: Equivalent CPA sources reuse the same frozen build++- **WHEN** different paths or default/explicit selections resolve to equal manifest bytes and all other build inputs match+- **THEN** acquisition reuses the same verified build without retaining the original source path.+### Requirement: Validation tracks have independent evidence limits| Track | Can establish | Cannot substitute for |@@ -169,6 +192,8 @@ complete validation when dependent targets were not admitted.- [Product control journey](../../../tools/product-e2e/tests/control_shell.rs),[oracle](../../../tools/product-e2e/tests/product_oracle.rs), and[controlled Gateway runtime](../../../tools/e2e-harness/tests/p0_gateway_runtime.rs).+- [Desktop Pilot reusable build owner](../../../scripts/pilot-builds.py) and+ [lifecycle regressions](../../../scripts/test-pilot-builds.py).- [Evidence/fixture map](../../../docs/code-map/testing.md) and[validation selection](../../../docs/test-selection.md).- [Smoke preparation](../../../tools/product-e2e/src/smoke/preparation.rs),diff --git a/scripts/pilot-builds.py b/scripts/pilot-builds.pyindex b8cad105..d75a0fde 100644--- a/scripts/pilot-builds.py+++ b/scripts/pilot-builds.py@@ -12,6 +12,7 @@ import platformimport reimport shutilimport signal+import statimport subprocessimport sysimport time@@ -35,6 +36,7 @@ COMMAND = ["cargo", "build", "--locked", "-p", "hiroute-desktop", "-p", "hiroute"--bin", "hiroute-desktop", "--bin", "hirouted", "--bin", "hiroute"]DRIVERS = ("pilot-builds.py", "local-rust.py", "remote-rust.py", "desktop-pilot.py", "validation-report.py")VERDICTS = ("green", "red", "expected_red", "not_executed")+DEFAULT_CPA_MANIFEST = Path("apps/desktop/src-tauri/development-cpa-artifacts.v1.json")def digest(value):@@ -56,7 +58,74 @@ def tree_digest(root):return digest(entries)-def build_recipe(repo, sha, jobs):+def validate_cpa_manifest(contents):+ def reject_constant(value):+ raise ValueError("Non-finite JSON constant: " + value)++ try:+ value = json.loads(contents.decode("utf-8"), parse_constant=reject_constant)+ except (UnicodeDecodeError, ValueError):+ raise ValueError("CPA manifest must be a UTF-8 JSON object") from None+ if not isinstance(value, dict):+ raise ValueError("CPA manifest must be a UTF-8 JSON object")+++def read_cpa_manifest(path):+ """Read one stable regular file without following a final-component link."""+ path = Path(path)+ try:+ before = path.lstat()+ if path.is_symlink() or not stat.S_ISREG(before.st_mode):+ raise ValueError("CPA manifest must be a real regular file")+ descriptor = os.open(path, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK)+ with os.fdopen(descriptor, "rb") as source:+ opened = os.fstat(source.fileno())+ if not stat.S_ISREG(opened.st_mode) or (opened.st_dev, opened.st_ino) != (before.st_dev, before.st_ino):+ raise ValueError("CPA manifest changed while opening")+ contents = source.read()+ after = os.fstat(source.fileno())+ final = path.lstat()+ except OSError:+ raise ValueError("CPA manifest is missing or unreadable") from None+ identity = lambda item: (item.st_dev, item.st_ino, item.st_mode, item.st_size,+ item.st_mtime_ns, item.st_ctime_ns)+ if path.is_symlink() or not stat.S_ISREG(final.st_mode) or not (+ identity(before) == identity(opened) == identity(after) == identity(final)):+ raise ValueError("CPA manifest changed while reading")+ validate_cpa_manifest(contents)+ return contents+++def candidate_cpa_manifest(repo, sha):+ relative = DEFAULT_CPA_MANIFEST.as_posix()+ try:+ entry = subprocess.check_output(+ ["git", "-C", str(repo), "ls-tree", sha, "--", relative], text=True, timeout=30).strip()+ fields = entry.split(None, 3)+ if len(fields) != 4 or fields[:2] not in (["100644", "blob"], ["100755", "blob"]):+ raise ValueError+ contents = subprocess.check_output(+ ["git", "-C", str(repo), "show", sha + ":" + relative], timeout=30)+ except (OSError, ValueError, subprocess.SubprocessError):+ raise ValueError("Candidate default CPA manifest is missing or not a regular file") from None+ validate_cpa_manifest(contents)+ return contents+++def select_cpa_manifest(repo, sha):+ selected = os.environ.get("HIROUTE_CPA_MANIFEST")+ if selected is None:+ return candidate_cpa_manifest(repo, sha)+ try:+ supplied = Path(selected)+ path = supplied if supplied.is_absolute() else repo / DEFAULT_CPA_MANIFEST.parent / supplied+ path = Path(os.path.abspath(path))+ except (OSError, TypeError, ValueError):+ raise ValueError("HIROUTE_CPA_MANIFEST does not identify a valid CPA manifest") from None+ return read_cpa_manifest(path)+++def build_recipe(repo, sha, jobs, cpa_manifest=None):# These are the only inherited knobs supported by this fixed build profile.# Values may contain private paths/flags; persist their digest, not plaintext.knobs = {k: v for k, v in os.environ.items() if@@ -77,9 +146,12 @@ def build_recipe(repo, sha, jobs):if sys.platform == "darwin":versions["sdk"] = subprocess.check_output(["xcrun", "--show-sdk-version"], text=True, timeout=30).strip()versions["sdk_path"] = subprocess.check_output(["xcrun", "--show-sdk-path"], text=True, timeout=30).strip()+ if cpa_manifest is None:+ cpa_manifest = select_cpa_manifest(repo, sha)return dict(sha=sha, origin=local.git(repo, "remote", "get-url", "origin"), command=COMMAND,profile="debug", jobs=jobs, toolchain=toolchain, tools=versions,platform=[sys.platform, platform.machine(), platform.release()], environment=digest(knobs),+ cpa_manifest={"sha256": hashlib.sha256(cpa_manifest).hexdigest()},drivers={name: pilot.file_sha256(Path(__file__).with_name(name)) for name in DRIVERS})@@ -127,9 +199,16 @@ class Builds:raise ValueError("Lease/build identity mismatch")return row- def prepare(self, timeout):+ def prepare(self, timeout, manifest):def frontend(checkout, env, row, descriptors):run = self.store.record_path(row["id"]).parent+ # Cargo consumes these verified bytes even if the borrowed source changes+ # while npm/Cargo run. Only the build-owned snapshot survives ingestion.+ snapshot = run / "cpa-manifest.json"+ with snapshot.open("xb") as output:+ os.chmod(snapshot, 0o600)+ output.write(manifest)+ env["HIROUTE_CPA_MANIFEST"] = str(snapshot)log = run / "frontend.log"env["PYTHONDONTWRITEBYTECODE"] = "1"for argv in (["npm", "--prefix", "apps/desktop", "ci"],@@ -169,6 +248,9 @@ class Builds:def verify(self, row, recipe):if row["pilot_reuse"]["recipe"] != recipe or row["command"] != COMMAND:raise ValueError("Build inputs differ")+ snapshot = self.store.record_path(row["id"]).parent / "cpa-manifest.json"+ if hashlib.sha256(read_cpa_manifest(snapshot)).hexdigest() != recipe["cpa_manifest"]["sha256"]:+ raise ValueError("Compiled CPA manifest snapshot changed")self.store.verify(row)build = pilot.verify_managed_pilot_build(row["id"], str(Path(row["checkout"]) / "target/debug/hiroute-desktop"), row["sha"])if build["artifacts"] != row["pilot_reuse"]["artifacts"]:@@ -193,7 +275,8 @@ class Builds:local.git(repo, "merge-base", "--is-ancestor", args.sha, ref)finally:local.git(repo, "update-ref", "-d", ref)- recipe = build_recipe(repo, args.sha, args.jobs)+ manifest = select_cpa_manifest(repo, args.sha)+ recipe = build_recipe(repo, args.sha, args.jobs, manifest)key = digest(recipe)with self.locked(key):index = self.index(key)@@ -207,7 +290,7 @@ class Builds:else:run_args = types.SimpleNamespace(repo=str(repo), ref=args.ref, sha=args.sha, source="origin",jobs=args.jobs, command=COMMAND, keep=True, cargo_only=False, timeout=args.timeout)- row = local.run(self.store, run_args, prepare=self.prepare(args.timeout),+ row = local.run(self.store, run_args, prepare=self.prepare(args.timeout, manifest),on_record=lambda record: local.remote.save(index, {"run": record["id"], "key": key}))if row.get("process_exit") != 0 or row.get("error") or row.get("scenario") != "unassessed":raise ValueError("Pilot build failed/unknown; retained run " + row["id"])diff --git a/scripts/test-pilot-builds.py b/scripts/test-pilot-builds.pyindex ec32b703..850efd75 100644--- a/scripts/test-pilot-builds.py+++ b/scripts/test-pilot-builds.py@@ -1,5 +1,5 @@#!/usr/bin/env python3-"""Real Git/worktree/file lifecycle with fake build tools, NOT product E2E."""+"""Fixture-only local checks; --real-consumer selects the required bounded Rust CI case."""import importlib.utilimport jsonimport os@@ -16,6 +16,30 @@ sys.dont_write_bytecode = Truespec = importlib.util.spec_from_file_location("builds", Path(__file__).with_name("pilot-builds.py"))m = importlib.util.module_from_spec(spec)spec.loader.exec_module(m)+REAL_RUSTC = shutil.which('rustc')+REAL_PATH = os.environ.get('PATH', '')+CONSUMER_EVIDENCE = Path(__file__).resolve().parents[1] / 'artifacts/ci/pilot-manifest-consumer'+++def consumer_step(phase, argv, cwd, env, timeout):+ """Keep each real-consumer subprocess result outside the disposable fixture."""+ report = {'phase': phase, 'returncode': None}+ try:+ completed = subprocess.run(argv, cwd=cwd, env=env, capture_output=True, timeout=timeout)+ report.update(returncode=completed.returncode, stdout=completed.stdout, stderr=completed.stderr)+ except (OSError, subprocess.TimeoutExpired) as error:+ report.update(error=str(error), stdout=getattr(error, 'stdout', None), stderr=getattr(error, 'stderr', None))+ for key in ('stdout', 'stderr'):+ value = report.get(key) or b''+ report[key] = value.decode('utf-8', errors='replace') if isinstance(value, bytes) else value+ CONSUMER_EVIDENCE.mkdir(parents=True, exist_ok=True)+ evidence = CONSUMER_EVIDENCE / (phase + '.json')+ evidence.write_text(json.dumps(report, indent=2) + '\n')+ if report['returncode'] != 0:+ message = 'Real consumer phase %s failed; diagnostics: %s' % (phase, evidence)+ print(message, file=sys.stderr)+ raise RuntimeError(message)+ return completed.stdoutclass Lifecycle(unittest.TestCase):@@ -32,6 +56,9 @@ class Lifecycle(unittest.TestCase):(self.repo / 'rust-toolchain.toml').write_text('[toolchain]\nchannel = "fixture"\n')(self.repo / 'scripts').mkdir()(self.repo / 'scripts/desktop-pilot.py').write_text('import json,sys\nprint(json.dumps({"build":{"frontendDist":sys.argv[-1]}}))\n')+ native = self.repo / 'apps/desktop/src-tauri'+ native.mkdir(parents=True)+ (native / 'development-cpa-artifacts.v1.json').write_text('{"fixture":"default"}\n')m.local.git(self.repo, 'add', '.')m.local.git(self.repo, 'commit', '-qm', 'fixture')m.local.git(self.repo, 'remote', 'add', 'origin', str(self.repo))@@ -48,6 +75,10 @@ if name=='cargo' and 'metadata' in sys.argv:print(json.dumps({'target_directory':str(root/'target')}));sys.exit(0)if name=='cargo':p=root/'target/debug';p.mkdir(parents=True)+ manifest=os.environ.get('HIROUTE_CPA_MANIFEST')+ manifest=pathlib.Path(manifest) if manifest is not None else root/'apps/desktop/src-tauri/development-cpa-artifacts.v1.json'+ if not manifest.is_absolute(): manifest=root/'apps/desktop/src-tauri'/manifest+ (p/'compiled-cpa.json').write_bytes(manifest.read_bytes())for name in ('hiroute-desktop','hirouted','hiroute'):(p/name).write_text('#!/bin/sh\\nexit 0\\n');(p/name).chmod(0o700)gen=root/'apps/desktop/src-tauri/gen';gen.mkdir(parents=True);(gen/'schema').write_text('generated')@@ -65,6 +96,7 @@ print('fixture build completed')env = patch.dict(os.environ, {'PATH': str(self.bin) + os.pathsep + os.environ['PATH']})env.start()self.addCleanup(env.stop)+ os.environ.pop('HIROUTE_CPA_MANIFEST', None)stats = patch.object(m.local.remote, 'stats', return_value={'cache_hits': 0})stats.start()self.addCleanup(stats.stop)@@ -128,6 +160,212 @@ print('fixture build completed')second = self.acquire('task-two')self.assertNotEqual(first['build_run'], second['build_run'])+ def test_equal_cpa_manifest_contents_share_a_build_across_paths(self):+ first_manifest = self.root / 'private-first-cpa.json'+ same_content_manifest = self.root / 'private-same-cpa.json'+ second_manifest = self.root / 'private-second-cpa.json'+ first_manifest.write_text('{"fixture":"first"}\n')+ same_content_manifest.write_text('{"fixture":"first"}\n')+ second_manifest.write_text('{"fixture":"second"}\n')+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(first_manifest)}):+ first = self.acquire()+ reused = self.acquire()+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(same_content_manifest)}):+ same_content = self.acquire('task-two')+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(second_manifest)}):+ second = self.acquire('task-three')+ self.assertTrue(reused['reused'])+ self.assertEqual(first['build_run'], reused['build_run'])+ self.assertTrue(same_content['reused'])+ self.assertEqual(first['build_run'], same_content['build_run'])+ self.assertNotEqual(first['build_run'], second['build_run'])+ self.start(first)++ def test_changing_explicit_cpa_manifest_in_place_invalidates_reuse(self):+ manifest = self.root / 'private-cpa.json'+ manifest.write_text('{"fixture":"before"}\n')+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(manifest)}):+ first = self.acquire()+ manifest.write_text('{"fixture":"after"}\n')+ second = self.acquire('task-two')+ self.assertNotEqual(first['build_run'], second['build_run'])+ self.start(first)++ def test_missing_or_invalid_cpa_manifest_fails_before_build(self):+ missing = self.root / 'missing-cpa.json'+ directory = self.root / 'cpa-directory'+ directory.mkdir()+ invalid = []+ for index, contents in enumerate((b'not json\n', b'[]', b'\xff',+ b'{"size":NaN}', b'{"size":Infinity}', b'{"size":-Infinity}')):+ path = self.root / ('invalid-cpa-%s.json' % index)+ path.write_bytes(contents)+ invalid.append(path)+ fifo = self.root / 'cpa-fifo'+ os.mkfifo(fifo)+ link = self.root / 'cpa-link.json'+ link.symlink_to(self.repo / 'apps/desktop/src-tauri/development-cpa-artifacts.v1.json')+ for manifest in (missing, directory, *invalid, fifo, link):+ with self.subTest(manifest=manifest), \+ patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(manifest)}), \+ patch.object(m.local, 'run') as build, \+ self.assertRaisesRegex(ValueError, 'CPA manifest'):+ self.acquire()+ build.assert_not_called()++ def test_source_changes_do_not_invalidate_an_acquired_build_or_publish_its_path(self):+ manifest = self.root / 'private-cpa.json'+ manifest.write_text('{"fixture":"stable"}\n')+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(manifest)}):+ result = self.acquire()+ row = self.store.load(result['build_run'])+ for public in (result, row, self.manager.locate(result['lease'])):+ self.assertNotIn(str(manifest), json.dumps(public, sort_keys=True))+ snapshot = self.store.record_path(result['build_run']).parent / 'cpa-manifest.json'+ self.assertEqual(snapshot.stat().st_mode & 0o777, 0o600)+ self.assertFalse((self.manager.root / 'manifests').exists())+ manifest.write_text('{"fixture":"changed"}\n')+ self.start(result)+ self.assertEqual(snapshot.read_bytes(), b'{"fixture":"stable"}\n')++ def test_default_cpa_manifest_comes_from_candidate_and_reuses_equal_explicit_bytes(self):+ manifest = self.repo / 'apps/desktop/src-tauri/development-cpa-artifacts.v1.json'+ original = manifest.read_bytes()+ manifest.write_text('{"fixture":"dirty execution checkout"}\n')+ result = self.acquire()+ self.assertEqual((Path(result['checkout']) / 'target/debug/compiled-cpa.json').read_bytes(), original)+ manifest.write_bytes(original)+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(manifest)}):+ explicit = self.acquire('task-two')+ self.assertTrue(explicit['reused'])+ self.assertEqual(result['build_run'], explicit['build_run'])++ def test_relative_cpa_manifest_uses_desktop_package_directory(self):+ manifest = self.repo / 'apps/desktop/src-tauri/relative-cpa.json'+ manifest.write_text('{"fixture":"relative"}\n')+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': 'relative-cpa.json'}):+ result = self.acquire()+ reused = self.acquire('task-two')+ self.assertTrue(reused['reused'])+ self.assertEqual((Path(result['checkout']) / 'target/debug/compiled-cpa.json').read_bytes(), manifest.read_bytes())+ self.start(result)++ def test_deleted_source_rejects_fresh_acquisition_but_old_lease_still_starts(self):+ manifest = self.root / 'private-cpa.json'+ manifest.write_text('{"fixture":"stable"}\n')+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(manifest)}):+ result = self.acquire()+ manifest.unlink()+ with patch.object(m.local, 'run') as build, self.assertRaisesRegex(ValueError, 'CPA manifest'):+ self.acquire('task-two')+ build.assert_not_called()+ self.start(result)++ def test_native_build_consumes_captured_snapshot_when_source_changes_during_compilation(self):+ manifest = self.root / 'private-cpa.json'+ original = b'{"fixture":"verified"}\n'+ manifest.write_bytes(original)+ start_command = m.local.remote.start_locked_command+ snapshot_paths = []++ def changed_source(argv, checkout, env, output, handles):+ if argv != m.COMMAND:+ return start_command(argv, checkout, env, output, handles)+ manifest.write_text('{"fixture":"changed during compilation"}\n')+ source = Path(env['HIROUTE_CPA_MANIFEST'])+ snapshot_paths.append(source)+ return start_command(argv, checkout, env, output, handles)++ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(manifest)}), \+ patch.object(m.local.remote, 'start_locked_command', side_effect=changed_source):+ result = self.acquire()+ self.assertEqual((Path(result['checkout']) / 'target/debug/compiled-cpa.json').read_bytes(), original)+ self.assertEqual(len(snapshot_paths), 1)+ self.assertNotEqual(snapshot_paths[0], manifest)+ self.assertEqual(snapshot_paths[0].stat().st_mode & 0o777, 0o600)+ self.start(result)++ def test_original_cpa_manifest_is_read_only_once_before_build_preparation(self):+ manifest = self.root / 'private-cpa.json'+ original = b'{"fixture":"captured"}\n'+ manifest.write_bytes(original)+ run = m.local.run++ def change_before_prepare(*args, **kwargs):+ manifest.write_text('{"fixture":"new input"}\n')+ return run(*args, **kwargs)++ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(manifest)}), \+ patch.object(m, 'read_cpa_manifest', wraps=m.read_cpa_manifest) as read, \+ patch.object(m.local, 'run', side_effect=change_before_prepare):+ result = self.acquire()+ source_reads = [call for call in read.call_args_list if Path(call.args[0]) == manifest]+ self.assertEqual(len(source_reads), 1)+ self.assertEqual((Path(result['checkout']) / 'target/debug/compiled-cpa.json').read_bytes(), original)++ def test_hardlinked_regular_manifests_are_ingested_by_content(self):+ manifest = self.root / 'private-cpa.json'+ manifest.write_text('{"fixture":"hardlinked"}\n')+ alias = self.root / 'other-cpa.json'+ os.link(manifest, alias)+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(manifest)}):+ first = self.acquire()+ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(alias)}):+ second = self.acquire('task-two')+ self.assertTrue(second['reused'])+ self.assertEqual(first['build_run'], second['build_run'])++ def test_altered_cpa_snapshot_rejects_reuse_and_start(self):+ result = self.acquire()+ snapshot = self.store.record_path(result['build_run']).parent / 'cpa-manifest.json'+ snapshot.write_text('{"fixture":"altered snapshot"}\n')+ with self.assertRaisesRegex(ValueError, 'CPA manifest snapshot'):+ self.acquire('task-two')+ with patch.object(m.pilot, 'start') as launch, self.assertRaisesRegex(ValueError, 'CPA manifest snapshot'):+ self.manager.start(types.SimpleNamespace(lease=result['lease'], case='model', timeout=1,+ data_root=None, process_home=None))+ launch.assert_not_called()++ def real_consumer(self):+ if not REAL_RUSTC:+ raise RuntimeError('The required real-consumer case needs rustc; it cannot be skipped')+ native = Path(__file__).resolve().parents[1] / 'apps/desktop/src-tauri'+ manifest = self.root / 'private-cpa.json'+ original = b'{"fixture":"captured by real consumer"}\n'+ manifest.write_bytes(original)+ output = self.root / 'consumer-out'+ output.mkdir()+ build_script = self.root / 'build-script'+ consumer = self.root / 'manifest-consumer'+ source = self.root / 'consumer.rs'+ # Reuse the production include_str! declaration, not another manifest reader.+ declaration = next(line for line in (native / 'src/development_cpa.rs').read_text().splitlines()+ if line.startswith('const MANIFEST_JSON:'))+ source.write_text(declaration + '\nfn main() { print!("{}", MANIFEST_JSON); }\n')+ start_command = m.local.remote.start_locked_command+ observed = []++ def compile_snapshot(argv, checkout, env, log, handles):+ if argv == m.COMMAND:+ manifest.unlink() # The consumer must no longer need the ingestion source.+ consumer_env = dict(env, PATH=REAL_PATH, OUT_DIR=str(output), PROFILE='debug')+ consumer_step('build-script-compile',+ [REAL_RUSTC, '--edition=2024', str(native / 'build.rs'), '-o', str(build_script)],+ native, consumer_env, 60)+ consumer_step('build-script-execute', [str(build_script)], native, consumer_env, 10)+ consumer_step('embedding-compile',+ [REAL_RUSTC, '--edition=2024', str(source), '-o', str(consumer)],+ native, consumer_env, 60)+ observed.append(consumer_step('embedding-execute', [str(consumer)], native, consumer_env, 10))+ return start_command(argv, checkout, env, log, handles)++ with patch.dict(os.environ, {'HIROUTE_CPA_MANIFEST': str(manifest)}), \+ patch.object(m.local.remote, 'start_locked_command', side_effect=compile_snapshot):+ result = self.acquire()+ self.assertEqual(observed, [original])+ self.assertEqual((output / 'cpa-artifacts.json').read_bytes(), original)+ self.start(result)+def test_failed_build_is_retained_without_creating_duplicate_on_retry(self):cargo = self.bin / 'cargo'source = cargo.read_text()@@ -269,5 +507,57 @@ print('fixture build completed')self.acquire('task-two')+class ConsumerRouting(unittest.TestCase):+ def test_default_discovery_does_not_select_the_real_consumer(self):+ self.assertNotIn('test_production_build_script_and_embedded_constant_consume_the_captured_snapshot',+ unittest.defaultTestLoader.getTestCaseNames(Lifecycle))+ self.assertNotIn('real_consumer', unittest.defaultTestLoader.getTestCaseNames(Lifecycle))++ def test_required_consumer_fails_for_zero_skipped_or_failed_cases(self):+ for count, skipped, successful in ((0, [], True), (2, [], True),+ (1, [('case', 'skip')], True), (1, [], False), (1, [], True)):+ result = types.SimpleNamespace(testsRun=count, skipped=skipped, wasSuccessful=lambda: successful)+ with self.subTest(count=count, skipped=skipped, successful=successful), \+ patch.object(unittest.TextTestRunner, 'run', return_value=result):+ self.assertEqual(run_real_consumer(), 0 if count == 1 and not skipped and successful else 1)++ def test_missing_real_compiler_is_an_error_not_a_skip(self):+ with patch.dict(Lifecycle.real_consumer.__globals__, {'REAL_RUSTC': None}):+ with self.assertRaisesRegex(RuntimeError, 'needs rustc'):+ Lifecycle('real_consumer').real_consumer()++ def test_failed_subprocess_diagnostics_survive_fixture_cleanup(self):+ outcomes = (+ (subprocess.CompletedProcess(['synthetic-consumer'], -9, b'partial output', b'synthetic rejection'),+ -9, 'partial output', 'synthetic rejection'),+ (subprocess.TimeoutExpired(['synthetic-consumer'], 10, output=b'partial output', stderr=b'timed out'),+ None, 'partial output', 'timed out'),+ (OSError('synthetic launch failure'), None, '', ''),+ )+ for outcome, returncode, stdout, stderr in outcomes:+ with self.subTest(outcome=outcome), tempfile.TemporaryDirectory() as root:+ evidence = Path(root) / 'evidence'+ with tempfile.TemporaryDirectory(dir=root) as fixture:+ with patch.dict(consumer_step.__globals__, {'CONSUMER_EVIDENCE': evidence}), \+ patch.object(subprocess, 'run', side_effect=[outcome]) as run, \+ self.assertRaisesRegex(RuntimeError, 'build-script-execute'):+ consumer_step('build-script-execute', ['synthetic-consumer'], fixture, {}, 10)+ run.assert_called_once()+ report = json.loads((evidence / 'build-script-execute.json').read_text())+ self.assertEqual(report['phase'], 'build-script-execute')+ self.assertEqual(report['returncode'], returncode)+ self.assertEqual(report['stdout'], stdout)+ self.assertEqual(report['stderr'], stderr)+ if isinstance(outcome, Exception):+ self.assertEqual(report['error'], str(outcome))+++def run_real_consumer():+ result = unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite([Lifecycle('real_consumer')]))+ return 0 if result.wasSuccessful() and result.testsRun == 1 and not result.skipped else 1++if __name__ == '__main__':+ if sys.argv[1:] == ['--real-consumer']:+ sys.exit(run_real_consumer())unittest.main()diff --git a/scripts/test-plan.py b/scripts/test-plan.pyindex f73368ab..0995df0b 100644--- a/scripts/test-plan.py+++ b/scripts/test-plan.py@@ -35,6 +35,11 @@ DIAGNOSTIC_CONTRACTS = ("crates/diagnostics/src/identity.rs", "crates/diagnostics/src/error.rs",)SELECTION_TOOLING = {"scripts/test-plan.py", "scripts/test-test-plan.py"}+PILOT_CONSUMER_INPUTS = SELECTION_TOOLING | {+ "scripts/pilot-builds.py", "scripts/test-pilot-builds.py",+ "apps/desktop/src-tauri/build.rs", "apps/desktop/src-tauri/src/development_cpa.rs",+ "apps/desktop/src-tauri/development-cpa-artifacts.v1.json",+}LOCAL_GC_TOOLING = {"scripts/local-rust-gc.py", "scripts/test-local-rust-gc.py"}WORKER_FIXTURE_TOOLING = {"scripts/test-agent-product-support.py","scripts/test-native-context-product.py",@@ -560,6 +565,10 @@ def select(paths, full=False):commands.extend([["python3", "scripts/" + name] for name in("test-validation.py", "test-console-assets.py", "test-windows-dev.py", "test-validation-report.py", "test-local-rust.py", "test-remote-rust.py", "test-validation-schedule.py","test-ci-run.py", "test-ci-shards.py", "test-desktop-pilot.py", "test-pilot-builds.py")])+ # Local script checks stay fixture-only. Actions runs this exact required case+ # through the existing tooling/affected/full gate executor, never a skipped test.+ if os.environ.get("GITHUB_ACTIONS") == "true" and (full or PILOT_CONSUMER_INPUTS.intersection(paths)):+ commands.append(["python3", "scripts/test-pilot-builds.py", "--real-consumer"])if full or validation_tooling or local_gc_tooling:if ["python3", "scripts/test-local-rust.py"] not in commands:commands.append(["python3", "scripts/test-local-rust.py"])diff --git a/scripts/test-test-plan.py b/scripts/test-test-plan.pyindex 627342a6..cf3bc4f1 100644--- a/scripts/test-test-plan.py+++ b/scripts/test-test-plan.py@@ -330,6 +330,26 @@ class SelectionTests(unittest.TestCase):self.assertTrue(mixed['rust'])self.assertIn('daemon', mixed['groups'])+ def test_real_pilot_manifest_consumer_is_selected_only_for_applicable_ci_plans(self):+ command = ['python3', 'scripts/test-pilot-builds.py', '--real-consumer']+ inputs = ('scripts/pilot-builds.py', 'scripts/test-pilot-builds.py',+ 'scripts/test-plan.py', 'scripts/test-test-plan.py',+ 'apps/desktop/src-tauri/build.rs',+ 'apps/desktop/src-tauri/src/development_cpa.rs',+ 'apps/desktop/src-tauri/development-cpa-artifacts.v1.json')+ with mock.patch.dict(plan.os.environ, {'GITHUB_ACTIONS': 'false'}):+ for path in inputs:+ self.assertNotIn(command, plan.select([path])['commands'])+ self.assertNotIn(command, plan.select([], full=True)['commands'])+ with mock.patch.dict(plan.os.environ, {'GITHUB_ACTIONS': 'true'}):+ for path in inputs:+ with self.subTest(path=path):+ self.assertIn(command, plan.select([path])['commands'])+ self.assertIn(command, plan.select([], full=True)['commands'])+ for path in ('docs/validation-routing.md', 'scripts/windows-dev.py'):+ self.assertNotIn(command, plan.select([path])['commands'])++def test_windows_development_runner_does_not_select_product_or_hosted_matrix(self):result = plan.select(['scripts/windows-dev.py', 'scripts/windows-dev-host.py','scripts/test-windows-dev.py', 'scripts/windows-desktop-session.py',