fix(01): CR-01 bind review digest to selected receipt bytes

This commit is contained in:
UnixNight committed 2026-11-13 17:00:47 -05:00
1 parent 5915128570
commit 5569bc2b8b
2 files changed
+25 -3

No files matched your search

+21
View File
@@ -156,6 +156,27 @@ class AcceptanceTests(unittest.TestCase):
self.review['receipt_ids'] = ['different'] self.review['receipt_ids'] = ['different']
self.assertTrue(self.audit()['errors']) self.assertTrue(self.audit()['errors'])
def test_review_digest_binds_selected_filename_without_sidecar(self):
checkpoint = self.root / 'checkpoint'
(checkpoint / 'protocol').mkdir(parents=True)
(checkpoint / 'manifest.json').write_bytes(receipts.canonical_bytes(
dict(self.manifest, packages={})))
(checkpoint / 'protocol/scenarios.json').write_bytes(receipts.canonical_bytes(self.protocol))
selected = self.record_root / 'selected.json'
selected.write_bytes(receipts.canonical_bytes(self.record))
sibling = self.record_root / 'receipt.json'
sibling.write_text('{"unrelated": true}')
(self.root / 'current.json').write_bytes(receipts.canonical_bytes(
{'receipts': [selected.relative_to(self.root).as_posix()]}))
for reviewed, expected_pending in ((sibling, True), (None, True), (selected, False)):
review = dict(self.review, receipt_sha256={} if reviewed is None else {
self.record['receipt_id']: receipts.identify_file(reviewed)['sha256']})
(self.root / 'human-review.json').write_bytes(receipts.canonical_bytes(review))
with mock.patch.object(self.api(), 'ready'), mock.patch.object(self.api(), '_bind'):
report = self.api().audit(checkpoint, self.root)
self.assertEqual(bool(report['human_needed']), expected_pending)
self.assertEqual(report['matrix']['accepted'], 1)
def test_actual_failed_linux_receipt_import_and_review_remains_open(self): def test_actual_failed_linux_receipt_import_and_review_remains_open(self):
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'
if not source.exists(): if not source.exists():
+4 -3
View File
@@ -130,16 +130,17 @@ def audit(checkpoint, results):
paths = read_json(selection).get('receipts', []) if selection.exists() else [] paths = read_json(selection).get('receipts', []) if selection.exists() else []
if not isinstance(paths, list) or len(paths) > 120 or len(set(paths)) != len(paths): if not isinstance(paths, list) or len(paths) > 120 or len(set(paths)) != len(paths):
raise ValueError('Current receipt selection must be a bounded unique array') raise ValueError('Current receipt selection must be a bounded unique array')
records = [] records, selected = [], []
for name in paths: for name in paths:
path = contained_path(results, name) path = contained_path(results, name)
records.append((read_receipt(path), path.parent)) records.append((read_receipt(path), path.parent))
selected.append(path)
review_path = results / 'human-review.json' review_path = results / 'human-review.json'
review = read_json(review_path) if review_path.exists() else {} review = read_json(review_path) if review_path.exists() else {}
# Bind review to actual receipt bytes, not just reusable labels. # Bind review to actual receipt bytes, not just reusable labels.
for receipt, directory in records: for (receipt, _), path in zip(records, selected):
expected = review.get('receipt_sha256', {}).get(receipt['receipt_id']) expected = review.get('receipt_sha256', {}).get(receipt['receipt_id'])
if expected != identify_file(directory / 'receipt.json')['sha256']: if expected != identify_file(path)['sha256']:
review = dict(review, checks={}) review = dict(review, checks={})
break break
return audit_records(read_json(root / 'protocol/scenarios.json'), manifest, records, review) return audit_records(read_json(root / 'protocol/scenarios.json'), manifest, records, review)