42 lines
2.0 KiB
Python
42 lines
2.0 KiB
Python
"""Require every manifest-bound evidence payload to survive the Git index."""
|
|
from pathlib import Path
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = Path('C:/ar-text-9e8r6t')
|
|
SETS = ['text-find-selection-20260913', 'text-workspace-initial-20260913', 'text-workspace-native2-20260913', 'text-workspace-native3-20260913']
|
|
expected = {}
|
|
sets = []
|
|
for label in SETS:
|
|
base = 'harness/experiments/' + label
|
|
manifest_path = ROOT / base / 'manifest.json'
|
|
raw = manifest_path.read_bytes()
|
|
manifest = json.loads(raw)
|
|
rows = manifest['files']
|
|
sets.append({'path': base, 'payloads': len(rows), 'manifestSha256': hashlib.sha256(raw).hexdigest()})
|
|
expected[base + '/manifest.json'] = {'bytes': len(raw), 'sha256': hashlib.sha256(raw).hexdigest()}
|
|
for row in rows:
|
|
name = base + '/' + row['path']
|
|
assert name not in expected
|
|
expected[name] = row
|
|
names = sorted(expected)
|
|
raw = subprocess.check_output(['git', 'cat-file', '--batch'], input=''.join(':' + name + '\n' for name in names).encode(), cwd=ROOT)
|
|
offset = 0
|
|
for name in names:
|
|
end = raw.index(b'\n', offset)
|
|
header = raw[offset:end].split()
|
|
assert len(header) == 3 and header[1] == b'blob', ('Missing staged payload', name, header)
|
|
size = int(header[2])
|
|
blob = raw[end + 1:end + 1 + size]
|
|
offset = end + size + 2
|
|
assert size == expected[name]['bytes'] and hashlib.sha256(blob).hexdigest() == expected[name]['sha256'], ('Staged archive payload differs', name)
|
|
assert blob == (ROOT / name).read_bytes(), ('Working archive differs', name)
|
|
assert offset == len(raw)
|
|
receipt = {'scope': 'All four experiment manifests and every referenced payload equal staged Git blobs and working originals, including ignored raw logs explicitly staged.', 'files': len(names), 'archives': sets, 'gitTree': subprocess.check_output(['git', 'write-tree'], cwd=ROOT).decode().strip()}
|
|
with Path(sys.argv[1]).open('x', encoding='utf-8', newline='\n') as out:
|
|
json.dump(receipt, out, indent=2)
|
|
out.write('\n')
|
|
print(json.dumps(receipt))
|