diff --git a/tests/test_fidelity_acceptance.py b/tests/test_fidelity_acceptance.py index 2fd7b7a..36422f4 100644 --- a/tests/test_fidelity_acceptance.py +++ b/tests/test_fidelity_acceptance.py @@ -283,6 +283,22 @@ class AcceptanceTests(unittest.TestCase): with self.assertRaises(ValueError): self.api().ready(root) + def test_ready_rejects_sealed_viewer_missing_history_projection(self): + root, manifest = self.prepared() + viewer = root / 'review/review.json' + data = receipts.read_json(viewer) + del data['ledger']['capabilities'][0]['history'] + viewer.write_bytes(receipts.canonical_bytes(data)) + manifest['files'] = [dict(entry, **receipts.identify_file(viewer)) + if entry['path'] == 'review/review.json' else entry for entry in manifest['files']] + (root / 'manifest.json').write_bytes(receipts.canonical_bytes(manifest)) + seal = receipts.read_json(root / 'READY.json') + seal['manifest'] = dict(path='manifest.json', **receipts.identify_file(root / 'manifest.json')) + (root / 'READY.json').write_bytes(receipts.canonical_bytes(seal)) + with mock.patch.object(self.api(), '_package', side_effect=lambda _, rid, __: manifest['packages'][rid]): + with self.assertRaisesRegex(ValueError, 'viewer ledger projection'): + self.api().ready(root) + def test_audit_explicit_selection_reads_actual_failed_linux_hashes(self): root, manifest = self.prepared() source = ROOT / 'artifacts/fidelity/linux-current-receipts/linux-01-06-matrix-preflight-linux' diff --git a/tests/test_fidelity_checkpoint.py b/tests/test_fidelity_checkpoint.py index 62085a1..5d4c4e2 100644 --- a/tests/test_fidelity_checkpoint.py +++ b/tests/test_fidelity_checkpoint.py @@ -85,6 +85,37 @@ class FidelityCheckpoint(unittest.TestCase): self.assertEqual(manifest['packages'][rid]['resources']['assets']['tree_sha256'], receipts.identify_tree(package / 'assets')['tree_sha256']) + def test_preparation_preserves_current_and_superseded_records_through_renderer(self): + self.prepare() + model = self.output / 'review/review.json' + row = next(row for row in receipts.read_json(model)['ledger']['capabilities'] + if row['id'] == 'startup-order') + self.assertEqual(len(row['current']), 2) + self.assertEqual(len(row['history']), 2) + script = ''' + import {readFileSync} from 'node:fs'; + const api = await import(process.argv[1]); + const model = JSON.parse(readFileSync(process.argv[2])); + class Element { + constructor(text='') { this.textContent=text; this.children=[]; } + append(...items) { this.children.push(...items); } + replaceChildren(...items) { this.children=items; } + get text() { return this.textContent + this.children.map(x=>x.text??String(x)).join(' '); } + } + const doc={createElement:()=>new Element()}; + const container=new Element(); container.ownerDocument=doc; + api.renderCapabilities(container, model.ledger); + process.stdout.write(container.text); + ''' + # Render the actual assembled model with its bundled renderer, using only + # a DOM double. This proves fields reach the UI, not browser playback. + rendered = subprocess.run(['node', '--input-type=module', '-e', script, + (self.output / 'review/viewer.mjs').as_uri(), str(model)], + capture_output=True, text=True, timeout=15) + self.assertEqual(rendered.returncode, 0, rendered.stderr) + for record in row['current'] + row['history']: + self.assertIn(record['id'], rendered.stdout) + def test_original_change_rejected_before_output(self): (self.original / 'Jimmy Neutron.exe').write_bytes(b'changed') with self.assertRaises(ValueError): self.prepare() diff --git a/tools/recon/fidelity_acceptance.py b/tools/recon/fidelity_acceptance.py index 60c893d..6802b90 100644 --- a/tools/recon/fidelity_acceptance.py +++ b/tools/recon/fidelity_acceptance.py @@ -26,7 +26,7 @@ def ready(checkpoint): raise ValueError('Synthetic checkpoint is tooling-only, not final materials') names = {entry['path'] for entry in manifest['files']} required = set(MATERIALS) | {'protocol/scenarios.json', 'protocol/capabilities.json', - 'protocol/agenda.json', 'protocol/settings-template.json', + 'protocol/agenda.json', 'protocol/settings-template.json', 'protocol/capability-ledger.json', 'protocol/annotation-template.json', 'review/index.html', 'review/viewer.mjs', 'review/review.json'} if required - names: @@ -50,6 +50,11 @@ def ready(checkpoint): # Exported ledger links are already normalized by the exporter. Recheck # every active link against the sealed actual materials at final handoff. ledger = read_json(root / 'review/review.json')['ledger'] + expected_ledger = read_json(root / 'protocol/capability-ledger.json') + for field in ('current', 'history'): + if [(row['id'], row.get(field)) for row in ledger['capabilities']] != [ + (row['id'], row[field]) for row in expected_ledger['capabilities']]: + raise ValueError('Malformed viewer ledger projection: ' + field) for capability in ledger['capabilities']: for link in capability.get('source_links', []): if link.get('href'): diff --git a/tools/recon/fidelity_checkpoint.py b/tools/recon/fidelity_checkpoint.py index d079f6f..d91faa0 100644 --- a/tools/recon/fidelity_checkpoint.py +++ b/tools/recon/fidelity_checkpoint.py @@ -19,6 +19,7 @@ from fidelity_receipts import (canonical_bytes, contained_path, identify_file, utc_now, validate_receipt, validate_scenario_contract, verify_inventory, _id, _write_json) from fidelity_review import export_review +from fidelity_ledger import export_ledger PROJECT = Path(__file__).resolve().parents[2] RIDS = ('linux-x64', 'win-x64') @@ -164,7 +165,9 @@ def prepare_checkpoint(original, original_manifest, packages, output, tooling=Fa _copy_file(original_manifest, temporary / 'protocol/original-manifest.json') for name in ('scenarios.json', 'capabilities.json'): _copy_file(PROJECT / 'docs/evidence' / name, temporary / 'protocol' / name) - export_review(None, None, temporary / 'review', PROJECT / 'docs/evidence/capabilities.json') + ledger = temporary / 'protocol/capability-ledger.json' + _write_json(ledger, export_ledger(read_json(PROJECT / 'docs/evidence/capabilities.json'), PROJECT)) + export_review(None, None, temporary / 'review', ledger) for name in MUTABLE: (temporary / name).mkdir() # All 80 Windows obligations are prepared; Linux's remaining40 use the same protocol.