feat(01-01): enforce eight-cell scenario and native evidence completeness

This commit is contained in:
UnixNight committed 2026-11-12 19:10:15 -05:00
1 parent cc4a5a3e92
commit 32a72654e8
5 files changed
+430 -22

No files matched your search

+99
View File
@@ -0,0 +1,99 @@
{
"schema_version": 1,
"protocol_id": "phase01-baseline-v1",
"description": "Procedures and obligations only. No runtime acceptance is asserted by this document.",
"decisions": ["D-01", "D-02", "D-03", "D-04", "D-15"],
"required_sides": [
{"id": "original-windows-dxwnd", "evidence_kind": "original_dxwnd", "os": "windows"},
{"id": "port-linux-native", "evidence_kind": "native_port", "os": "linux"},
{"id": "port-windows-native", "evidence_kind": "native_port", "os": "windows"}
],
"cells": [
{"id": "fresh-natural-edge", "lifetime": "fresh", "dialogue": "natural", "input": "edge", "obligations": ["continuous", "dialogue-return", "bank-left", "bank-right", "landing-idle"]},
{"id": "fresh-natural-ordinary", "lifetime": "fresh", "dialogue": "natural", "input": "ordinary", "obligations": ["continuous", "dialogue-return", "bank-left", "bank-right", "landing-idle"]},
{"id": "fresh-skipped-edge", "lifetime": "fresh", "dialogue": "skipped", "input": "edge", "obligations": ["continuous", "dialogue-return", "bank-left", "bank-right", "landing-idle"]},
{"id": "fresh-skipped-ordinary", "lifetime": "fresh", "dialogue": "skipped", "input": "ordinary", "obligations": ["continuous", "dialogue-return", "bank-left", "bank-right", "landing-idle"]},
{"id": "retained-natural-edge", "lifetime": "retained", "dialogue": "natural", "input": "edge", "obligations": ["continuous", "dialogue-return", "bank-left", "bank-right", "landing-idle"]},
{"id": "retained-natural-ordinary", "lifetime": "retained", "dialogue": "natural", "input": "ordinary", "obligations": ["continuous", "dialogue-return", "bank-left", "bank-right", "landing-idle"]},
{"id": "retained-skipped-edge", "lifetime": "retained", "dialogue": "skipped", "input": "edge", "obligations": ["continuous", "dialogue-return", "bank-left", "bank-right", "landing-idle"]},
{"id": "retained-skipped-ordinary", "lifetime": "retained", "dialogue": "skipped", "input": "ordinary", "obligations": ["continuous", "dialogue-return", "bank-left", "bank-right", "landing-idle"]}
],
"lifetime_procedures": {
"fresh": {
"setup": "Allocate an independently verified generated copy and new launch/session ID for each run. Record copy_pre identity. For the port, identify the actual package and its existing startup path; do not reset gameplay state to fit the procedure.",
"actions": "Record startup and ordinary New Game/TSK lab entry visibly. A direct fresh-scene fixture is a separate observation, not a replacement for New Game.",
"end_condition": "The requested continuous or focused procedure ends in this independently identified launch. Never reuse a fresh-session ID for another required run."
},
"retained": {
"setup": "Begin recording in one verified generated copy/launch. Visibly establish lab departure to VR04 and return as prerequisite setup before the retained test. Hash the prerequisite recording and retained copy state; preserve the original copy_pre identity.",
"actions": "Keep departure_session_id and return_session_id equal to the same session_id/lifetime_id. Record prerequisite_departure and prerequisite_return markers on the hashed prerequisite_artifact before the tested interval. Bind copy_pre_sha256 and retained_copy_sha256 to actual identified records. Continue the required scenario without terminating, restaging, loading unrelated state or resetting clocks.",
"end_condition": "Evidence includes prerequisite setup, retained copy identity and the actual departure/return in the same process lifetime. A second fresh launch cannot count as retained."
}
},
"dialogue_procedures": {
"natural": "Approach Carl through normal play, let dialogue and its return complete naturally, then observe the first resumed input and neutral idle. Do not press skip.",
"skipped": "Approach Carl through normal play, visibly perform the supported skip input, record the observed skip and dialogue completion boundary, then observe resumed input and neutral idle. Record the actual chosen key; do not infer original sampling."
},
"input_procedures": {
"ordinary": "Use normal physical play inputs. Release movement at dialogue/control return, observe the first neutral input, perform separately visible left and right banked jumps, land and remain idle. Record actual input description and audible/visual output.",
"edge": "Deliberately hold movement through the dialogue boundary, observe resumed held input, then release and record first neutral input. Perform left and right banked jumps, land and remain idle. Hold a declared direction through RETURN and record cleanup/resumption. Preserve legitimate landing bank."
},
"dialogue_events": {"natural": ["dialogue_end"], "skipped": ["dialogue_skip", "dialogue_end"]},
"input_events": {"ordinary": [], "edge": ["resumed_held_input", "held_dialogue", "held_return"]},
"obligations": {
"continuous": {
"route": ["lab", "VR04", "lab", "outside"],
"setup": "Apply the cell's lifetime, dialogue and input procedures. Start one uninterrupted video/audio recording before startup/control or retained prerequisite setup. Identify package, copy, launcher and platform.",
"actions": "In the lab, complete Carl dialogue according to policy, observe resumed/neutral input, perform left/right banked jumps, land and idle. Depart normally to VR04, use its existing supported gadget, invoke ordinary RETURN, observe gadget cleanup and lab return, then take the ordinary lab exit to outside. Keep one process lifetime and one continuous video for the route. No debug warp, scene snapshots or injected smoke input substitutes.",
"end_condition": "Jimmy visibly arrives outside after lab -> VR04 -> lab in the same run; audio/input events and cleanup are reviewable, with missing/failed transitions reported honestly.",
"required_events": ["startup", "control", "dialogue_start", "dialogue_end", "first_neutral_input", "jump_left", "bank_left", "landing_left", "jump_right", "bank_right", "landing", "idle", "lab_departure", "vr04_entry", "vr04_use", "return_cleanup", "lab_return", "lab_exit", "outside_arrival"],
"required_artifact_roles": ["video", "audio", "input_events", "prerequisite"]
},
"dialogue-return": {
"setup": "Apply the cell's visible lifetime prerequisite, then approach Carl with the chosen natural/skipped and ordinary/held-input policy. Record setup before the focused clip.",
"actions": "Observe dialogue activation, actual natural completion or skip, first resumed held input when applicable, release to first neutral input and sustained idle. Record method/uncertainty at each observed boundary.",
"end_condition": "Control has resumed and neutral idle is visibly recorded, without inserting any leveling reset.",
"required_events": ["dialogue_start", "dialogue_end", "first_neutral_input", "idle"],
"required_artifact_roles": ["video", "audio", "input_events", "prerequisite"]
},
"bank-left": {
"setup": "Apply the cell lifetime and record the supported normal standing/moving setup. Preserve the actual selected camera/control state.",
"actions": "Use ordinary physical jump and Left/A to visibly bank left, release as prescribed, land and observe the resulting pose. Record exact physical keys and actual elapsed/media markers.",
"end_condition": "The left bank and landing are both visible; orientation is observed rather than forced upright.",
"required_events": ["jump_left", "bank_left", "landing"],
"required_artifact_roles": ["video", "audio", "input_events", "prerequisite"]
},
"bank-right": {
"setup": "Apply the same cell lifetime independently and record the supported normal standing/moving setup.",
"actions": "Use ordinary physical jump and Right/D to visibly bank right, release as prescribed, land and observe the resulting pose. Do not mirror or relabel the left recording.",
"end_condition": "The right bank and landing are independently visible and audible.",
"required_events": ["jump_right", "bank_right", "landing"],
"required_artifact_roles": ["video", "audio", "input_events", "prerequisite"]
},
"landing-idle": {
"setup": "Apply the cell lifetime. Record a real jump/landing setup with support visible; retain the actual body and camera state.",
"actions": "Observe landing, release movement and record sustained idle at actual speed. Keep any legitimate landing bank and record discrepancies rather than tuning them away.",
"end_condition": "Landing and a reviewable idle interval are captured; no universal duration/angle/pixel/audio tolerance is inferred.",
"required_events": ["landing", "idle"],
"required_artifact_roles": ["video", "audio", "input_events", "prerequisite"]
}
},
"event_contract": {
"fields": ["name", "artifact", "media_seconds", "elapsed_seconds", "method", "uncertainty_seconds"],
"original_method": ["manual", "procedural"],
"simulation_ticks": "separate_port_only",
"clocks": "Finite monotonic elapsed seconds from one identified clock_id; actual media seconds on hashed raw recordings. Preserve clock offsets and uncertainty. Do not reset or normalize clocks at scene transitions.",
"continuity": "Continuous route events reference one video artifact in chronological order. Independent scene snapshots cannot satisfy this obligation.",
"derivatives": "Preserve raw recordings; each preview/still links its hashed source, actual tool/version/command and any crop/timing changes. Never silently retime.",
"tolerances": "No blanket timing, pixel, angle or audio threshold; later system-specific acceptance needs authoritative evidence."
},
"protected_observations": {
"tsk_retained_order": "Preserve implemented menu/background Jimmy-before-level-input successful TSK entry; docs/gameplay/main-menu-player-lifetime.md.",
"fresh_direct_scene_order": "Fresh direct-scene order remains a distinct observation; do not apply retained-story classification universally.",
"legitimate_landing_bank": "Observe and preserve legitimate landing bank; never substitute an unsupported leveling reset."
},
"acceptance": {
"structural_readiness": "--allow-open checks the complete protocol while reporting every missing case/obligation. It is not native/reference acceptance.",
"complete": "--require-complete requires all 8 cells x 5 obligations x 3 independently identified original/native sides, hashed artifacts, chronological markers, lifetime continuity and actual human audiovisual review. Failed/skipped/aborted/missing captures remain open. D-13 availability, launcher exit zero, fixtures, component probes, Wine and cross-publish do not fill any slot."
}
}
+33 -3
View File
@@ -93,9 +93,13 @@ class FidelityScenarios(unittest.TestCase):
identity[key] = dict(api.identify_file(d / 'setup.txt'), path='setup.txt')
identity['source'].update(commit='a' * 40, dirty=False, diff_sha256='b' * 64)
required = api.required_events(p, c, obligation)
events = [dict(name=name, artifact='video.txt', media_seconds=index,
elapsed_seconds=index, method='manual', uncertainty_seconds=.1)
events = [dict(name=name, artifact='video.txt', media_seconds=index + 2,
elapsed_seconds=index + 2, method='manual', uncertainty_seconds=.1)
for index, name in enumerate(required)]
if c['lifetime'] == 'retained':
events = [dict(name=name, artifact='setup.txt', media_seconds=index,
elapsed_seconds=index, method='manual', uncertainty_seconds=.1)
for index, name in enumerate(('prerequisite_departure', 'prerequisite_return'))] + events
value = {'schema_version': 1, 'receipt_id': d.name, 'session_id': d.name,
'case_id': cell, 'obligation_id': obligation, 'evidence_kind': kind,
'status': 'reviewed', 'historical': False, 'scope': obligation,
@@ -112,7 +116,8 @@ class FidelityScenarios(unittest.TestCase):
'wrapper_settings': {'description': 'unit fixture only'},
'continuity': {'lifetime_id': d.name, 'departure_session_id': d.name,
'return_session_id': d.name, 'prerequisite_artifact': 'setup.txt',
'copy_pre_sha256': 'a' * 64, 'retained_copy_sha256': 'b' * 64}}
'copy_pre_sha256': identity['copy_pre']['sha256'],
'retained_copy_sha256': identity['copy_post']['sha256']}}
return value, d
def test_identified_metadata_cell_can_cover_one_obligation(self):
@@ -195,6 +200,31 @@ class FidelityScenarios(unittest.TestCase):
self.assertEqual(p['event_contract']['simulation_ticks'], 'separate_port_only')
self.assertEqual(p['event_contract']['original_method'], ['manual', 'procedural'])
def test_all_120_metadata_slots_are_counted_independently(self):
p = self.protocol()
records = [self.receipt(c['id'], o, side['evidence_kind'], side['os'])
for c in p['cells'] for o in c['obligations'] for side in p['required_sides']]
result = api.audit_scenarios(p, records)
self.assertEqual(result['invalid'], [])
self.assertEqual(result['accepted'], 120)
self.assertTrue(result['complete'])
def test_duplicate_slot_cannot_replace_another_case(self):
value, root = self.receipt()
result = api.audit_scenarios(self.protocol(), [(value, root), (value, root)])
self.assertEqual(result['accepted'], 0)
self.assertTrue(result['invalid'])
def test_retained_prerequisite_must_have_observed_departure_and_return(self):
value, root = self.receipt()
value['events'] = [e for e in value['events'] if e['name'] != 'prerequisite_departure']
self.assertEqual(api.audit_scenarios(self.protocol(), [(value, root)])['accepted'], 0)
def test_retained_copy_hash_must_bind_identified_bytes(self):
value, root = self.receipt()
value['continuity']['retained_copy_sha256'] = 'f' * 64
self.assertEqual(api.audit_scenarios(self.protocol(), [(value, root)])['accepted'], 0)
if __name__ == '__main__':
unittest.main()
+31 -7
View File
@@ -8,6 +8,7 @@ import subprocess
import sys
import tempfile
import unittest
import wave
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
@@ -50,11 +51,13 @@ class FidelitySessions(unittest.TestCase):
api = self.api()
bundle = self.base / 'synthetic-pair'
bundle.mkdir(exist_ok=True)
for name in ('original.txt', 'port.txt'):
(bundle / name).write_text('explicitly synthetic paired media fixture')
for name in ('original.wav', 'port.wav'):
with wave.open(str(bundle / name), 'wb') as audio:
audio.setparams((1, 2, 8000, 0, 'NONE', 'not compressed'))
audio.writeframes(b'\0\0' * 800)
artifacts = [dict(api.identify_file(bundle / name), role=role, path=name,
synthetic=True) for name, role in
[('original.txt', 'original_video'), ('port.txt', 'port_video')]]
[('original.wav', 'original_audio'), ('port.wav', 'port_audio')]]
value = {'schema_version': 1, 'receipt_id': receipt_id,
'session_id': 'test-session', 'case_id': 'test-only',
'evidence_kind': 'synthetic', 'status': 'captured',
@@ -189,7 +192,7 @@ class FidelitySessions(unittest.TestCase):
def test_tampered_artifact_rejected(self):
bundle, _, value = self.fixture_receipt()
(bundle / 'original.txt').write_text('tampered')
(bundle / 'original.wav').write_text('tampered')
with self.assertRaises(ValueError): self.api().validate_receipt(value, bundle)
def test_duplicate_import_identical_only(self):
@@ -233,8 +236,8 @@ class FidelitySessions(unittest.TestCase):
def test_relative_artifact_symlink_escape_rejected(self):
bundle, _, value = self.fixture_receipt()
(bundle / 'original.txt').unlink()
(bundle / 'original.txt').symlink_to(self.manifest)
(bundle / 'original.wav').unlink()
(bundle / 'original.wav').symlink_to(self.manifest)
with self.assertRaises(ValueError): self.api().validate_receipt(value, bundle)
def test_bad_schema_and_oversized_json_rejected_by_cli(self):
@@ -254,13 +257,34 @@ class FidelitySessions(unittest.TestCase):
self.assertIn('Historical Wine/component', result['recorded_scope'])
self.assertTrue(any('resources absent' in s for s in result['missing_evidence']))
def test_import_rejects_case_aliased_directory_components(self):
bundle, _, value = self.fixture_receipt()
(bundle / 'Media').mkdir()
(bundle / 'media').mkdir()
(bundle / 'Media/a.wav').write_bytes(b'a')
(bundle / 'media/b.wav').write_bytes(b'b')
value['artifacts'] = [dict(self.api().identify_file(bundle / path), path=path,
role='test', synthetic=True)
for path in ('Media/a.wav', 'media/b.wav')]
with self.assertRaises(ValueError): self.api().validate_receipt(value, bundle)
def test_imported_receipt_metadata_tampering_fails_cli(self):
bundle, path, _ = self.fixture_receipt()
out = self.base / 'test-index'
result = self.api().import_receipt(path, bundle, out)
stored = Path(result['path'])
value = json.loads(stored.read_text())
value['limitations'].append('changed metadata')
stored.write_text(json.dumps(value))
self.assertNotEqual(self.cli('validate', stored, '--root', stored.parent).returncode, 0)
def test_cli_hostile_output_and_tampering_exit_nonzero(self):
result = self.cli('stage', '--source', self.original, '--manifest', self.manifest,
'--output', self.original / 'illegal', '--session-id', 'new')
self.assertNotEqual(result.returncode, 0)
self.assertFalse((self.original / 'illegal').exists())
bundle, path, _ = self.fixture_receipt()
(bundle / 'port.txt').write_text('changed')
(bundle / 'port.wav').write_text('changed')
self.assertNotEqual(self.cli('import', path, '--root', bundle,
'--output', self.base / 'test-index').returncode, 0)
path.write_bytes(b' ' * (4 * 1024 * 1024 + 1))
+26 -5
View File
@@ -13,7 +13,8 @@ from pathlib import Path
import sys
from fidelity_receipts import (identify_tree, identify_report, import_receipt,
read_json, stage_original, validate_receipt)
read_json, read_receipt, stage_original, validate_receipt,
audit_receipt_tree, canonical_bytes, MAX_JSON_BYTES)
def main(argv=None):
@@ -32,8 +33,10 @@ def main(argv=None):
imp.add_argument('--root', type=Path, required=True)
imp.add_argument('--output', type=Path, required=True)
validate = sub.add_parser('validate')
validate.add_argument('receipt', type=Path)
validate.add_argument('--root', type=Path, required=True)
validate.add_argument('receipt', type=Path, nargs='?')
validate.add_argument('--root', type=Path)
validate.add_argument('--scenarios', type=Path)
validate.add_argument('--receipts', type=Path)
mode = validate.add_mutually_exclusive_group()
mode.add_argument('--allow-open', action='store_true')
mode.add_argument('--require-complete', action='store_true')
@@ -48,13 +51,31 @@ def main(argv=None):
elif args.command == 'import':
result = import_receipt(args.receipt, args.root, args.output)
else:
result = validate_receipt(read_json(args.receipt), args.root)
if args.scenarios:
if args.receipt or args.root or not args.receipts:
raise ValueError('Scenario validation requires --scenarios PATH --receipts ROOT')
result = audit_receipt_tree(read_json(args.scenarios), args.receipts)
print('Structural readiness: READY; acceptance: ' + ('COMPLETE' if result['complete'] else 'OPEN'))
print('Accepted obligations: {accepted}/{required}'.format(**result))
print('Missing case IDs: ' + ', '.join(result['missing_case_ids']))
for key in ('missing_obligations', 'open_receipts', 'invalid'):
for item in result[key]:
print(key + ': ' + item)
if result['invalid']:
return 2
return 1 if args.require_complete and not result['complete'] else 0
if args.receipt is None or args.root is None or args.receipts:
raise ValueError('Receipt validation requires RECEIPT --root ROOT')
result = validate_receipt(read_receipt(args.receipt), args.root)
print('Receipt {receipt_id}: {evidence_kind}, status={status}'.format(**result))
print('Acceptance: ' + ('ACCEPTED' if result['accepted'] else 'OPEN'))
for missing in result['missing_evidence']:
print('Missing/open: ' + str(missing))
return 1 if args.require_complete and not result['accepted'] else 0
print(json.dumps(result, indent=2, allow_nan=False))
data = canonical_bytes(result)
if len(data) > MAX_JSON_BYTES:
raise ValueError('Result JSON exceeds 4 MiB limit')
print(data.decode(), end='')
return 0
except (ValueError, OSError, KeyError, TypeError) as error:
print('Invalid fidelity evidence: ' + str(error), file=sys.stderr)
+241 -7
View File
@@ -19,6 +19,7 @@ Local cooperative writers are serialized; concurrent hostile filesystem mutation
is outside this offline workflow (revalidate after collection/before review).
"""
import hashlib
import itertools
import json
import math
import ntpath
@@ -94,7 +95,7 @@ def relative_name(value):
raise ValueError('Reference must be a bounded relative POSIX path')
parts = value.split('/')
if ('\\' in value or ':' in value or value.startswith('/') or
any(c in value for c in '\x00\r\n') or
any(ord(c) < 32 or c in '<>"|?*' for c in value) or
any(p in ('', '.', '..') or p.endswith((' ', '.')) for p in parts)):
raise ValueError('Unsafe relative reference: ' + value)
for part in parts:
@@ -133,7 +134,7 @@ def identify_tree(root):
root = Path(root).resolve(strict=True)
if not root.is_dir():
raise ValueError('Tree root must be a directory')
files, aliases = [], set()
files, aliases, json_size = [], set(), 0
for directory, dirs, names in os.walk(root, followlinks=False):
for name in sorted(dirs + names):
path = Path(directory) / name
@@ -148,7 +149,11 @@ def identify_tree(root):
if path.is_symlink():
raise ValueError('Symlink tree member: ' + relative)
if path.is_file():
files.append({'path': relative, **identify_file(path)})
item = {'path': relative, **identify_file(path)}
json_size += len(canonical_bytes(item))
if json_size > MAX_JSON_BYTES:
raise ValueError('Tree identity exceeds JSON size bound')
files.append(item)
elif not path.is_dir():
raise ValueError('Non-regular tree member: ' + relative)
files.sort(key=lambda item: item['path'])
@@ -278,7 +283,12 @@ def _checked_artifact(item, root):
def _finite(value):
return isinstance(value, (int, float)) and not isinstance(value, bool) and math.isfinite(value)
if not isinstance(value, (int, float)) or isinstance(value, bool):
return False
try:
return math.isfinite(value)
except OverflowError:
return False
def validate_receipt(receipt, root):
@@ -309,12 +319,17 @@ def validate_receipt(receipt, root):
for key in ('artifacts', 'derivatives', 'events', 'limitations', 'missing_evidence'):
if not isinstance(receipt.get(key), list) or len(receipt[key]) > 10000:
raise ValueError('Missing or unbounded list: ' + key)
for key in ('limitations', 'missing_evidence'):
if not all(isinstance(item, str) for item in receipt[key]):
raise ValueError('Text list required: ' + key)
invocation = receipt.get('invocation')
if (not isinstance(invocation, dict) or not isinstance(invocation.get('argv'), list)
or not all(isinstance(a, str) for a in invocation['argv'])
or not isinstance(invocation.get('cwd'), str)):
raise ValueError('Invocation requires inert argv array and recorded cwd')
clocks = receipt.get('clocks', {})
if not isinstance(clocks, dict):
raise ValueError('Clocks must be an object')
start, end = clocks.get('monotonic_start'), clocks.get('monotonic_end')
if not _finite(start) or not _finite(end) or start < 0 or end < start:
raise ValueError('Invalid/reset monotonic clocks')
@@ -334,10 +349,12 @@ def validate_receipt(receipt, root):
aliases.add(key)
artifacts[item['path']] = item
for derivative in receipt['derivatives']:
if (derivative.get('path') not in artifacts or derivative.get('source') not in artifacts
if (not isinstance(derivative, dict) or derivative.get('path') not in artifacts or derivative.get('source') not in artifacts
or not derivative.get('tool') or not isinstance(derivative.get('argv'), list)):
raise ValueError('Derivative requires hashed source/output and tool/argv provenance')
for event in receipt['events']:
if not isinstance(event, dict):
raise ValueError('Event must be an object')
artifact = artifacts.get(event.get('artifact'))
if not artifact or not event.get('name') or not event.get('method'):
raise ValueError('Observed event requires media reference/name/method')
@@ -360,9 +377,18 @@ def validate_receipt(receipt, root):
for item in identity.values():
if isinstance(item, dict) and 'path' in item:
_checked_artifact(item, root)
reference_aliases = {}
for name in _receipt_paths(receipt):
parts = relative_name(name).parts
for length in range(1, len(parts) + 1):
prefix = '/'.join(parts[:length])
previous = reference_aliases.setdefault(prefix.casefold(), prefix)
if previous != prefix:
raise ValueError('Case-colliding artifact/identity path components')
acceptance = receipt.get('acceptance')
if (not isinstance(acceptance, dict) or acceptance.get('state') not in ('open', 'accepted')
or not isinstance(acceptance.get('remaining'), list)):
or not isinstance(acceptance.get('remaining'), list)
or not all(isinstance(item, str) for item in acceptance['remaining'])):
raise ValueError('Explicit acceptance state/remaining required')
synthetic = (kind == 'synthetic' or receipt.get('scope') == 'tooling-test' or
any(item.get('synthetic') for item in artifacts.values()))
@@ -387,6 +413,8 @@ def validate_receipt(receipt, root):
if role not in roles:
missing.append('Missing evidence artifact: ' + role)
review = receipt.get('review', {})
if not isinstance(review, dict):
raise ValueError('Review must be an object')
if not all(review.get(k) is True for k in ('visible', 'audible', 'ordinary_input', 'human_reviewed')):
missing.append('Actual visible/audible/ordinary-input human review remains open')
if not platform.get('version'):
@@ -421,9 +449,12 @@ def import_receipt(path, root, output):
raise ValueError('Receipt input must be contained in bundle')
receipt = read_json(path)
validate_receipt(receipt, root)
raw = path.read_bytes() # bounded by read_json above; re-check below against races
with path.open('rb') as stream:
raw = stream.read(MAX_JSON_BYTES + 1)
if len(raw) > MAX_JSON_BYTES:
raise ValueError('Receipt exceeds size limit')
if json.loads(raw) != receipt:
raise ValueError('Receipt changed during import')
receipt_id = _id(receipt['receipt_id'])
if receipt['evidence_kind'] == 'synthetic' and 'test' not in output.name.casefold():
raise ValueError('Synthetic receipt requires a separate test output namespace')
@@ -517,3 +548,206 @@ def identify_report(package, report=None, executable=None, resources=None, launc
result['collector_source'] = source_identity(project)
result['missing_evidence'].append('No new runtime execution or current applicability established')
return result
OBLIGATION_IDS = ['continuous', 'dialogue-return', 'bank-left', 'bank-right', 'landing-idle']
SIDE_KEYS = [('original_dxwnd', 'windows'), ('native_port', 'linux'), ('native_port', 'windows')]
BASE_EVENTS = {
'continuous': ['startup', 'control', 'dialogue_start', 'dialogue_end', 'first_neutral_input',
'jump_left', 'bank_left', 'landing_left', 'jump_right', 'bank_right', 'landing',
'idle', 'lab_departure', 'vr04_entry', 'vr04_use', 'return_cleanup', 'lab_return',
'lab_exit', 'outside_arrival'],
'dialogue-return': ['dialogue_start', 'dialogue_end', 'first_neutral_input', 'idle'],
'bank-left': ['jump_left', 'bank_left', 'landing'],
'bank-right': ['jump_right', 'bank_right', 'landing'],
'landing-idle': ['landing', 'idle']}
def validate_scenario_contract(protocol):
if protocol.get('schema_version') != 1:
raise ValueError('Unsupported scenario schema')
cells = protocol.get('cells', [])
expected = sorted('-'.join(parts) for parts in itertools.product(
('fresh', 'retained'), ('natural', 'skipped'), ('ordinary', 'edge')))
if [c.get('id') for c in cells] != expected:
raise ValueError('Required eight uniquely identified, ordered matrix cells are missing/duplicated')
for cell in cells:
if (cell['id'] != '-'.join(cell.get(k, '') for k in ('lifetime', 'dialogue', 'input'))
or cell.get('obligations') != OBLIGATION_IDS):
raise ValueError('Matrix dimensions/obligations do not match stable case ID')
sides = protocol.get('required_sides', [])
if [(s.get('evidence_kind'), s.get('os')) for s in sides] != SIDE_KEYS:
raise ValueError('Original-DxWnd and both native-port sides are separately required')
if len({s.get('id') for s in sides}) != 3:
raise ValueError('Side IDs must be unique')
for key in OBLIGATION_IDS:
obligation = protocol.get('obligations', {}).get(key, {})
if obligation.get('required_events') != BASE_EVENTS[key]:
raise ValueError('Required chronological event protocol missing: ' + key)
if obligation.get('required_artifact_roles') != ['video', 'audio', 'input_events', 'prerequisite']:
raise ValueError('Required artifact obligations missing: ' + key)
if not all(isinstance(obligation.get(k), str) and obligation[k].strip()
for k in ('setup', 'actions', 'end_condition')):
raise ValueError('Executable procedure missing: ' + key)
if protocol['obligations']['continuous'].get('route') != ['lab', 'VR04', 'lab', 'outside']:
raise ValueError('Continuous journey must be lab -> VR04 -> lab -> outside')
if protocol.get('dialogue_events') != {'natural': ['dialogue_end'], 'skipped': ['dialogue_skip', 'dialogue_end']}:
raise ValueError('Natural/skipped dialogue require separate observed boundaries')
if protocol.get('input_events') != {'ordinary': [], 'edge': ['resumed_held_input', 'held_dialogue', 'held_return']}:
raise ValueError('Held input through dialogue/return is required for edge runs')
if set(protocol.get('protected_observations', {})) != {
'tsk_retained_order', 'fresh_direct_scene_order', 'legitimate_landing_bank'}:
raise ValueError('Protected movement observations are missing')
event = protocol.get('event_contract', {})
if (event.get('original_method') != ['manual', 'procedural'] or
event.get('simulation_ticks') != 'separate_port_only'):
raise ValueError('Original annotation and port clock categories must remain distinct')
return {'valid': True, 'cells': 8, 'required': 120}
def required_events(protocol, cell, obligation_id):
events = list(protocol['obligations'][obligation_id]['required_events'])
if 'dialogue_end' in events and cell['dialogue'] == 'skipped':
events.insert(events.index('dialogue_end'), 'dialogue_skip')
if cell['input'] == 'edge':
if 'dialogue_start' in events:
events.insert(events.index('dialogue_start') + 1, 'held_dialogue')
events.insert(events.index('first_neutral_input'), 'resumed_held_input')
if 'return_cleanup' in events:
events.insert(events.index('return_cleanup'), 'held_return')
return events
def _scenario_observation(protocol, cell, receipt):
obligation = receipt['obligation_id']
if receipt.get('scope') != obligation:
raise ValueError('Receipt scope must match its explicit obligation')
events = receipt['events']
required = required_events(protocol, cell, obligation)
# Select in recorded order; repeated names are legitimate only when the
# requested boundaries can still be found without reordering observations.
selected, cursor = [], 0
for name in required:
while cursor < len(events) and events[cursor]['name'] != name:
cursor += 1
if cursor >= len(events):
raise ValueError('Missing/out-of-order event: ' + name)
selected.append(events[cursor])
cursor += 1
elapsed = [e['elapsed_seconds'] for e in events]
if elapsed != sorted(elapsed):
raise ValueError('Event timestamps reset within session')
media_paths = {e['artifact'] for e in selected}
if len(media_paths) != 1:
raise ValueError('continuous/focused observations cannot be disconnected snapshots')
times = [e['media_seconds'] for e in selected]
if times != sorted(times) or times[-1] <= times[0]:
raise ValueError('Media timestamps reset or contain no observed interval')
video = next(a for a in receipt['artifacts'] if a['path'] == selected[0]['artifact'])
if video.get('role') != 'video':
raise ValueError('continuous/focused markers require actual video artifact')
roles = {a.get('role') for a in receipt['artifacts']}
if not set(protocol['obligations'][obligation]['required_artifact_roles']).issubset(roles):
raise ValueError('Missing required scenario artifacts')
continuity = receipt.get('continuity', {})
if (not receipt['clocks'].get('clock_id') or
continuity.get('lifetime_id') != receipt['session_id']):
raise ValueError('One explicit monotonic clock and lifetime identity required')
if continuity.get('prerequisite_artifact') not in {
a['path'] for a in receipt['artifacts'] if a.get('role') == 'prerequisite'}:
raise ValueError('Visible identified prerequisite setup required')
if not re.fullmatch('[0-9a-f]{64}', continuity.get('copy_pre_sha256', '')):
raise ValueError('Missing pristine copy/package session identity')
if cell['lifetime'] == 'retained':
if (continuity.get('departure_session_id') != receipt['session_id'] or
continuity.get('return_session_id') != receipt['session_id'] or
not re.fullmatch('[0-9a-f]{64}', continuity.get('retained_copy_sha256', ''))):
raise ValueError('Retained departure/return/copy must preserve the same session')
identified = {item.get('sha256') for item in receipt['identity'].values() if isinstance(item, dict)}
if (continuity['copy_pre_sha256'] not in identified or
continuity['retained_copy_sha256'] not in identified):
raise ValueError('Retained copy state must bind actual hashed identity records')
prerequisite = [e for e in events if e['artifact'] == continuity['prerequisite_artifact']]
names = [e['name'] for e in prerequisite]
if ('prerequisite_departure' not in names or 'prerequisite_return' not in names or
names.index('prerequisite_departure') >= names.index('prerequisite_return') or
any(e['elapsed_seconds'] >= selected[0]['elapsed_seconds'] for e in prerequisite)):
raise ValueError('Retained setup requires observed prerequisite departure/return before test')
def audit_scenarios(protocol, records):
"""records is [(receipt_dict, contained_artifact_root), ...]. No writes.
A complete result describes declared/reviewed receipt coverage, not automatic
audiovisual truth or a universal fidelity tolerance. Real capture/review and
current applicability remain the responsibility of the acceptance owner.
"""
validate_scenario_contract(protocol)
cells = {c['id']: c for c in protocol['cells']}
required = {(c, o, kind, os_name) for c in cells for o in OBLIGATION_IDS
for kind, os_name in SIDE_KEYS}
filled, seen, invalid, open_receipts, fresh_sessions = set(), set(), [], [], {}
for receipt, root in records:
label = str(receipt.get('receipt_id', '<missing>'))
try:
result = validate_receipt(receipt, root)
case, obligation = receipt['case_id'], receipt.get('obligation_id')
key = (case, obligation, receipt['evidence_kind'], receipt['platform']['os'])
if key not in required:
raise ValueError('Evidence is not a required original/native matrix slot')
if key in seen:
filled.discard(key)
raise ValueError('Duplicate/conflicting matrix slot; explicitly select applicability first')
seen.add(key)
if not result['accepted']:
open_receipts.append(label + ': ' + '; '.join(result['missing_evidence']))
continue
_scenario_observation(protocol, cells[case], receipt)
if cells[case]['lifetime'] == 'fresh':
session_key = (receipt['evidence_kind'], receipt['platform']['os'], receipt['session_id'])
if session_key in fresh_sessions:
filled.discard(fresh_sessions[session_key])
raise ValueError('fresh runs require independently staged launch/session IDs')
fresh_sessions[session_key] = key
filled.add(key)
except (ValueError, KeyError, TypeError) as error:
invalid.append(label + ': ' + str(error))
gaps = required - filled
side_ids = {(s['evidence_kind'], s['os']): s['id'] for s in protocol['required_sides']}
return {'schema_version': 1, 'structurally_ready': True,
'complete': not gaps and not invalid, 'required': len(required), 'accepted': len(filled),
'missing_case_ids': sorted({g[0] for g in gaps}),
'missing_obligations': sorted('/'.join((c, o, side_ids[(k, os_name)]))
for c, o, k, os_name in gaps),
'open_receipts': open_receipts, 'invalid': invalid}
def audit_receipt_tree(protocol, root):
root = Path(root)
records = []
if root.exists():
# Reuse tree walker safety/bounds without hashing every video a second
# time. Validate each referenced artifact once via validate_receipt.
count = 0
for directory, dirs, files in os.walk(root, followlinks=False):
for name in dirs + files:
count += 1
if count > MAX_FILES or (Path(directory) / name).is_symlink():
raise ValueError('Receipt index unbounded or contains symlinks')
if 'receipt.json' in files:
path = Path(directory) / 'receipt.json'
records.append((read_receipt(path), path.parent))
return audit_scenarios(protocol, records)
def read_receipt(path):
"""Verify the import sidecar when present; raw collector bundles may lack it."""
path = Path(path)
receipt = read_json(path)
sidecar = path.with_name('receipt.sha256')
if sidecar.exists():
if sidecar.is_symlink() or sidecar.stat().st_size > 128:
raise ValueError('Invalid receipt hash sidecar')
if sidecar.read_text().strip() != identify_file(path)['sha256']:
raise ValueError('Receipt byte identity mismatch')
return receipt