fix(01): WR-01 preserve validated capability history in checkpoint viewer

This commit is contained in:
UnixNight committed 2026-11-13 17:07:44 -05:00
1 parent 6e5ee0bd25
commit 548c97aa58
4 files changed
+57 -2

No files matched your search

+16
View File
@@ -283,6 +283,22 @@ class AcceptanceTests(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
self.api().ready(root) 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): def test_audit_explicit_selection_reads_actual_failed_linux_hashes(self):
root, manifest = self.prepared() root, manifest = self.prepared()
source = ROOT / 'artifacts/fidelity/linux-current-receipts/linux-01-06-matrix-preflight-linux' source = ROOT / 'artifacts/fidelity/linux-current-receipts/linux-01-06-matrix-preflight-linux'
+31
View File
@@ -85,6 +85,37 @@ class FidelityCheckpoint(unittest.TestCase):
self.assertEqual(manifest['packages'][rid]['resources']['assets']['tree_sha256'], self.assertEqual(manifest['packages'][rid]['resources']['assets']['tree_sha256'],
receipts.identify_tree(package / '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): def test_original_change_rejected_before_output(self):
(self.original / 'Jimmy Neutron.exe').write_bytes(b'changed') (self.original / 'Jimmy Neutron.exe').write_bytes(b'changed')
with self.assertRaises(ValueError): self.prepare() with self.assertRaises(ValueError): self.prepare()
+6 -1
View File
@@ -26,7 +26,7 @@ def ready(checkpoint):
raise ValueError('Synthetic checkpoint is tooling-only, not final materials') raise ValueError('Synthetic checkpoint is tooling-only, not final materials')
names = {entry['path'] for entry in manifest['files']} names = {entry['path'] for entry in manifest['files']}
required = set(MATERIALS) | {'protocol/scenarios.json', 'protocol/capabilities.json', 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', 'protocol/annotation-template.json', 'review/index.html', 'review/viewer.mjs',
'review/review.json'} 'review/review.json'}
if required - names: if required - names:
@@ -50,6 +50,11 @@ def ready(checkpoint):
# Exported ledger links are already normalized by the exporter. Recheck # Exported ledger links are already normalized by the exporter. Recheck
# every active link against the sealed actual materials at final handoff. # every active link against the sealed actual materials at final handoff.
ledger = read_json(root / 'review/review.json')['ledger'] 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 capability in ledger['capabilities']:
for link in capability.get('source_links', []): for link in capability.get('source_links', []):
if link.get('href'): if link.get('href'):
+4 -1
View File
@@ -19,6 +19,7 @@ from fidelity_receipts import (canonical_bytes, contained_path, identify_file,
utc_now, validate_receipt, validate_scenario_contract, verify_inventory, utc_now, validate_receipt, validate_scenario_contract, verify_inventory,
_id, _write_json) _id, _write_json)
from fidelity_review import export_review from fidelity_review import export_review
from fidelity_ledger import export_ledger
PROJECT = Path(__file__).resolve().parents[2] PROJECT = Path(__file__).resolve().parents[2]
RIDS = ('linux-x64', 'win-x64') 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') _copy_file(original_manifest, temporary / 'protocol/original-manifest.json')
for name in ('scenarios.json', 'capabilities.json'): for name in ('scenarios.json', 'capabilities.json'):
_copy_file(PROJECT / 'docs/evidence' / name, temporary / 'protocol' / name) _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: for name in MUTABLE:
(temporary / name).mkdir() (temporary / name).mkdir()
# All 80 Windows obligations are prepared; Linux's remaining40 use the same protocol. # All 80 Windows obligations are prepared; Linux's remaining40 use the same protocol.