fix(01): CR-02 bind original evidence to pristine inventory members

This commit is contained in:
UnixNight committed 2026-11-13 17:01:42 -05:00
1 parent 5569bc2b8b
commit bda35e5bf5
3 files changed
+75 -11

No files matched your search

+2 -2
View File
@@ -87,8 +87,8 @@ SHA-256, size and header. No path or command from returned metadata is executed.
| Windows native source/resources | Same actual `fidelity-build.json` file; retain its source commit/dirty/diff fields. Resources are proven by exact full seal equality |
| Linux native source | Raw `identity/BUILD-INFO.txt`, with commit/dirty/diff taken from the matching exact package seal |
| Linux native resources | Raw `identity/resources.json`, exactly equal to manifest package resources |
| Original executable | Actual selected executable from the generated run (`Neutron.exe` or the recorded selected variant); identify its bytes and compare to that exact pristine member, retaining any mismatch as open |
| Original package/resources | Save `identify_tree(original-pristine)` and actual generated-copy pre/post inventories as separate hashed JSON; preserve all raw original content identities |
| Original executable | Actual selected executable from the generated run (`Neutron.exe` or the recorded selected variant); retain its exact pristine relative path in `identity.executable.original_member` and compare size/header/hash to that member, retaining any mismatch as open |
| Original package/resources | Both identify hashed `identify_tree(original-pristine)` inventories whose complete file records and recomputed digest equal the checkpoint baseline. Generated-copy pre/post inventories remain separate; preserve all raw original content identities |
| Original pre/post | Save complete actual `identify_tree(original-pristine)` before/after return validation; require files and tree digest equal to the baseline and manifest original_pre. These describe authoritative/pristine preservation, separately from writable copy changes |
| Original copy pre/post/retained | Raw `copy-pre.json`, `copy-post.json`, `retained-copy.json`; preserve exact actual bytes/hashes and bind continuity to those hashes |
| Original source/launcher | Save manifest `tool_source` as `collector-source.json` and identify the actual bundled Windows collector; source commit/dirty/diff describes collector tooling, never recovered original source code |
+52 -3
View File
@@ -1,5 +1,6 @@
"""Acceptance metadata doubles are synthetic tests, never runtime proof."""
import copy
import hashlib
import importlib
import json
from pathlib import Path
@@ -37,7 +38,13 @@ class AcceptanceTests(unittest.TestCase):
self.package['build'] = {'source': {k: identity['source'][k]
for k in ('commit', 'dirty', 'diff_sha256')}}
# Bind real hashed metadata files in the test instead of accepting labels.
for key, data in [('original_pre', {'tree_sha256': 'c' * 64}),
self.original_files = [dict(path='Neutron.exe', **receipts.identify_file(self.record_root / 'setup.txt'))]
self.original_inventory = {'files': self.original_files,
'tree_sha256': hashlib.sha256(receipts.canonical_bytes(self.original_files)).hexdigest()}
for key, data in [('original_pre', self.original_inventory),
('original_post', self.original_inventory),
('original-package', self.original_inventory),
('original-resources', self.original_inventory),
('package', {'source': self.package['build']['source']}),
('resources', self.package['resources'])]:
path = self.record_root / (key + '.json')
@@ -46,7 +53,7 @@ class AcceptanceTests(unittest.TestCase):
self.package['seal'] = identity['package']
self.manifest = {'tooling_only': False, 'packages': {
'linux-x64': self.package, 'win-x64': self.package},
'original_pre': {'tree_sha256': 'c' * 64}}
'original_pre': {'tree_sha256': self.original_inventory['tree_sha256'], 'count': 1}}
self.review = {'schema_version': 1,
'checks': {key: {'observed': True, 'reviewer': 'metadata test',
'notes': 'Synthetic unit assertion only'} for key in
@@ -61,7 +68,16 @@ class AcceptanceTests(unittest.TestCase):
def audit(self, records=None, review=None):
return self.api().audit_records(self.protocol, self.manifest,
[(self.record, self.record_root)] if records is None else records,
self.review if review is None else review)
self.review if review is None else review, self.original_inventory)
def original_record(self):
value = copy.deepcopy(self.record)
value['evidence_kind'] = 'original_dxwnd'
value['platform'].update(os='windows', execution='dxwnd')
value['identity']['executable']['original_member'] = 'Neutron.exe'
for key in ('package', 'resources'):
value['identity'][key] = value['identity']['original-' + key]
return value
def test_empty_matrix_never_passes(self):
report = self.audit([])
@@ -80,6 +96,8 @@ class AcceptanceTests(unittest.TestCase):
('original_dxwnd', 'windows')]:
value, root = self.fixture.receipt(cell['id'], obligation, kind, os_name)
value['identity'] = copy.deepcopy(self.record['identity'])
if kind == 'original_dxwnd':
value['identity'] = self.original_record()['identity']
for path in self.record_root.iterdir():
if path.is_file() and root != self.record_root:
(root / path.name).write_bytes(path.read_bytes())
@@ -88,6 +106,36 @@ class AcceptanceTests(unittest.TestCase):
review['receipt_ids'] = [r['receipt_id'] for r, _ in records]
self.assertEqual(self.audit(records, review)['acceptance'], 'passed')
def test_original_executable_must_match_named_pristine_member(self):
value = self.original_record()
self.assertEqual(self.audit([(value, self.record_root)])['matrix']['accepted'], 1)
wrong = self.record_root / 'wrong.exe'
wrong.write_bytes(b'synthetic wrong original executable')
value['identity']['executable'] = dict(receipts.identify_file(wrong), path=wrong.name,
original_member='Neutron.exe')
self.assertEqual(self.audit([(value, self.record_root)])['matrix']['accepted'], 0)
value = self.original_record()
value['identity']['executable']['original_member'] = 'unselected.exe'
self.assertEqual(self.audit([(value, self.record_root)])['matrix']['accepted'], 0)
def test_original_inventories_require_actual_files_and_digest(self):
for key in ('original_pre', 'original_post', 'package', 'resources'):
with self.subTest(key=key):
value = self.original_record()
path = self.record_root / ('altered-' + key + '.json')
forged = copy.deepcopy(self.original_inventory)
forged['files'][0]['sha256'] = 'f' * 64
path.write_bytes(receipts.canonical_bytes(forged))
value['identity'][key] = dict(receipts.identify_file(path), path=path.name)
self.assertEqual(self.audit([(value, self.record_root)])['matrix']['accepted'], 0)
def test_generated_copy_changes_are_separate_from_original_preservation(self):
value = self.original_record()
path = self.record_root / 'changed-copy.json'
path.write_bytes(receipts.canonical_bytes({'files': [], 'generated_change': True}))
value['identity']['copy_post'] = dict(receipts.identify_file(path), path=path.name)
self.assertEqual(self.audit([(value, self.record_root)])['matrix']['accepted'], 1)
def test_aborted_case_stays_open(self):
self.record['status'] = 'aborted'
self.record['acceptance'] = {'state': 'open', 'remaining': ['aborted']}
@@ -162,6 +210,7 @@ class AcceptanceTests(unittest.TestCase):
(checkpoint / 'manifest.json').write_bytes(receipts.canonical_bytes(
dict(self.manifest, packages={})))
(checkpoint / 'protocol/scenarios.json').write_bytes(receipts.canonical_bytes(self.protocol))
(checkpoint / 'protocol/original-manifest.json').write_bytes(receipts.canonical_bytes(self.original_inventory))
selected = self.record_root / 'selected.json'
selected.write_bytes(receipts.canonical_bytes(self.record))
sibling = self.record_root / 'receipt.json'
+21 -6
View File
@@ -5,6 +5,7 @@ Human findings are declarations bound to exact receipts, never inferred from
successful tools. --allow-open is structural inspection, not acceptance.
"""
import argparse
import hashlib
from pathlib import Path
import sys
@@ -59,7 +60,7 @@ def ready(checkpoint):
'meaning': 'Identified offline materials only; all execution/review remains separate'}
def _bind(receipt, root, manifest):
def _bind(receipt, root, manifest, original_inventory=None):
identity = receipt['identity']
if receipt['evidence_kind'] == 'native_port':
rid = {'linux': 'linux-x64', 'windows': 'win-x64'}[receipt['platform']['os']]
@@ -79,12 +80,25 @@ def _bind(receipt, root, manifest):
if resources != expected['resources'] and identity['resources']['sha256'] != expected['seal']['sha256']:
raise ValueError('Wrong current resources')
elif receipt['evidence_kind'] == 'original_dxwnd':
before = read_json(contained_path(root, identity['original_pre']['path']))
if before.get('tree_sha256') != manifest['original_pre']['tree_sha256']:
files = (original_inventory or {}).get('files')
if not isinstance(files, list) or not files:
raise ValueError('Missing authoritative original file inventory')
digest = hashlib.sha256(canonical_bytes(files)).hexdigest()
if (digest != manifest['original_pre']['tree_sha256'] or
len(files) != manifest['original_pre']['count']):
raise ValueError('Wrong authoritative original inventory')
for key in ('original_pre', 'original_post', 'package', 'resources'):
inventory = read_json(contained_path(root, identity[key]['path']))
if inventory.get('files') != files or inventory.get('tree_sha256') != digest:
raise ValueError('Wrong authoritative original inventory: ' + key)
executable = identity['executable']
member = executable.get('original_member')
expected = next((item for item in files if item['path'] == member), None)
if not expected or any(executable.get(k) != expected[k] for k in ('sha256', 'size', 'header')):
raise ValueError('Wrong selected original executable member identity')
def audit_records(protocol, manifest, records, review):
def audit_records(protocol, manifest, records, review, original_inventory=None):
errors, usable, seen = [], [], set()
if manifest.get('tooling_only'):
errors.append('Synthetic checkpoint cannot qualify as runtime evidence')
@@ -98,7 +112,7 @@ def audit_records(protocol, manifest, records, review):
if receipt.get('superseded_by') or receipt.get('historical'):
raise ValueError('Superseded/historical receipt is not current applicability')
if valid['accepted']:
_bind(receipt, root, manifest)
_bind(receipt, root, manifest, original_inventory)
usable.append((receipt, root))
except (KeyError, TypeError, ValueError, OSError) as error:
errors.append(label + ': ' + str(error))
@@ -143,7 +157,8 @@ def audit(checkpoint, results):
if expected != identify_file(path)['sha256']:
review = dict(review, checks={})
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,
read_json(root / 'protocol/original-manifest.json'))
def main(argv=None):