"""Run the isolated, pinned fixture suite and emit machine-readable evidence.""" import argparse from hashlib import sha256 import json import os from pathlib import Path import subprocess import sys from tempfile import TemporaryDirectory ROOT = Path(__file__).resolve().parent WORKER = ROOT / "verification_cases.py" FIXTURE_LOCK = ROOT / "fixture_lock.json" METHODS = { "announcement-html-text": "html_parser_shape", "search-input-html-attribute": "html_parser_shape", "helpdesk-transcript-renderer": "html_parser_shape", "fixed-options-fragment": "html_parser_shape", "billing-https-context-verification": "tls_context_at_mock_transport", "mail-relay-tls-trust-source": "mock_tls_trust_loading", "tls-guard-at-connector": "mock_tls_configuration_gate", "download-grant-random-token": "mock_rng_source_selection", "device-pairing-random-code": "mock_rng_source_selection", "handoff-cookie-transport-policy": "mock_cookie_response", "secure-browser-policy-cookie": "mock_cookie_response", "workspace-export-capability": "mock_queue_authorization", "project-archive-permission": "mock_repository_authorization", "worker-tool-registry": "mock_process_argument_contract", "internal-shell-status": "mock_process_argument_contract", "local-value-roundtrip": "mock_decoder_input_provenance", "profile-bearer-request-location": "offline_http_request_construction", "account-recovery-post-body": "offline_http_request_construction", "approved-dashboard-sort": "in_memory_sqlite", "account-scoped-invoice-query": "in_memory_sqlite", "billing-rollup-capability": "in_memory_sqlite", "ledger-database-error": "in_memory_sqlite", } def run_verification(): with TemporaryDirectory(prefix="codedna-fixtures-") as directory: home = Path(directory) env = {key: os.environ[key] for key in ("SystemRoot", "WINDIR") if key in os.environ} env.update(TEMP=directory, TMP=directory, TMPDIR=directory) result = subprocess.run( [ sys.executable, "-I", "-S", "-B", "-X", f"pycache_prefix={home / 'no-cache'}", str(WORKER), ], cwd=directory, env=env, capture_output=True, encoding="utf-8", timeout=30, check=False, ) if result.returncode != 0: raise ValueError(f"Fixture worker failed (exit {result.returncode})\n{result.stderr.strip()}") outcomes = json.loads(result.stdout) if not isinstance(outcomes, dict) or not outcomes: raise ValueError("Fixture worker returned no verified outcomes") return { "version": 1, "launcher_sha256": sha256(Path(__file__).read_bytes()).hexdigest(), "suite_sha256": sha256(WORKER.read_bytes()).hexdigest(), "fixture_lock_sha256": sha256(FIXTURE_LOCK.read_bytes()).hexdigest(), "cases": { name: { "result": "pass", "method": METHODS.get(name, "local_fixture_behavior"), "observations": observations, } for name, observations in sorted(outcomes.items()) }, } def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--json", action="store_true", help="print full evidence as JSON") args = parser.parse_args() try: evidence = run_verification() except (ValueError, OSError, subprocess.TimeoutExpired) as error: parser.exit(1, f"{error}\n") if args.json: print(json.dumps(evidence, indent=2, sort_keys=True)) else: print(f"{len(evidence['cases'])} isolated fixture checks passed.") if __name__ == "__main__": main()