feat(01-06): preserve full Linux obligation matrix and capture history
This commit is contained in:
1 parent
e17cfbebe3
commit
0172916ffd
4 files changed
+300
-11
No files matched your search
+147
-11
@@ -7,6 +7,7 @@ X11/Pulse are the implemented external recorder sources; unsupported sources
|
||||
produce precise failed receipts rather than dummy fallback recordings.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
@@ -22,7 +23,8 @@ import time
|
||||
from fidelity_checkpoint import _package
|
||||
from fidelity_receipts import (MAX_JSON_BYTES, _id, _write_json, canonical_bytes,
|
||||
contained_path, identify_file, import_receipt, read_json, separated_roots,
|
||||
utc_now, validate_receipt, validate_scenario_contract)
|
||||
utc_now, validate_receipt, validate_scenario_contract, required_events,
|
||||
_scenario_observation, read_receipt)
|
||||
|
||||
PROJECT = Path(__file__).resolve().parents[2]
|
||||
MAX_SECONDS = 3600
|
||||
@@ -176,7 +178,8 @@ def run_capture(package, output, session_id, case_id, scope, settings, seconds=1
|
||||
'input_method': settings['input_method'], 'settings': settings,
|
||||
'invocation': {'argv': game, 'cwd': str(package)}, 'recorder_argv': recorder,
|
||||
'clocks': {'monotonic_start': start, 'monotonic_end': start,
|
||||
'wall_start': wall_start, 'wall_end': wall_start},
|
||||
'wall_start': wall_start, 'wall_end': wall_start,
|
||||
'clock_id': session_id + '-monotonic'},
|
||||
'status': 'failed' if not report['ready'] else 'incomplete',
|
||||
'missing': list(report['blockers']), 'processes': {}}
|
||||
_write_json(output / 'started.json', state)
|
||||
@@ -239,7 +242,9 @@ def collect(run, probe=command_probe, annotations=None):
|
||||
missing.append('Post-capture package identity failed: ' + str(error))
|
||||
media = run / 'raw.mkv'
|
||||
duration = None
|
||||
if media.exists() and media.stat().st_size:
|
||||
if media.exists() and media.stat().st_size > MAX_MEDIA:
|
||||
missing.append('Raw media exceeds 8 GiB capture bound; preserved locally but excluded from import')
|
||||
elif media.exists() and media.stat().st_size:
|
||||
media_probe = probe(['ffprobe', '-v', 'error', '-show_streams', '-show_format',
|
||||
'-of', 'json', str(media)], timeout=20)
|
||||
_write_json(run / 'media-probe.json', media_probe)
|
||||
@@ -268,16 +273,47 @@ def collect(run, probe=command_probe, annotations=None):
|
||||
identity[key] = {'path': 'identity/' + name, **identify_file(identity_dir / name)}
|
||||
identity['resources'] = {'path': 'identity/resources.json', **identify_file(identity_dir / 'resources.json')}
|
||||
identity['launcher'] = {'path': 'identity/collector.py', **identify_file(identity_dir / 'collector.py')}
|
||||
note = read_json(annotations) if annotations else {}
|
||||
# Explicit local annotations bind actual files; no imported commands execute.
|
||||
extra_roles = note.get('artifact_roles', {})
|
||||
if not isinstance(extra_roles, dict) or any(role != 'prerequisite' for role in extra_roles.values()):
|
||||
raise ValueError('Only explicit prerequisite artifact roles can supplement capture roles')
|
||||
for name in extra_roles: identify_file(contained_path(run, name))
|
||||
for key, name in note.get('identity_files', {}).items():
|
||||
if key not in ('copy_pre', 'retained_copy', 'copy_post'):
|
||||
raise ValueError('Unsupported annotated copy identity')
|
||||
identity[key] = {'path': name, **identify_file(contained_path(run, name))}
|
||||
artifacts = []
|
||||
for path in sorted(run.rglob('*')):
|
||||
count = 0
|
||||
for path in run.rglob('*'):
|
||||
count += 1
|
||||
if count > 10000: raise ValueError('Capture exceeds 10000-entry bound')
|
||||
if path.is_symlink(): raise ValueError('Symlink in capture output')
|
||||
if not path.is_file() or path.is_relative_to(identity_dir): continue
|
||||
bound = MAX_MEDIA if path.suffix == '.mkv' else MAX_LOG
|
||||
if path.stat().st_size > bound:
|
||||
missing.append('Artifact exceeds import bound: ' + path.relative_to(run).as_posix())
|
||||
continue
|
||||
name = path.relative_to(run).as_posix()
|
||||
role = 'video' if name == 'raw.mkv' else 'input_events' if name.startswith('observer/') else 'diagnostic'
|
||||
role = extra_roles.get(name, role)
|
||||
item = {'path': name, 'role': role, **identify_file(path)}
|
||||
if state['tooling_only']: item['synthetic'] = True
|
||||
if name == 'raw.mkv' and duration is not None: item['duration_seconds'] = duration
|
||||
if role == 'prerequisite' and duration is not None:
|
||||
if item['sha256'] == identify_file(media)['sha256']:
|
||||
item['duration_seconds'] = duration
|
||||
else:
|
||||
inspection = probe(['ffprobe', '-v', 'error', '-show_format', '-of', 'json', str(path)], timeout=20)
|
||||
try:
|
||||
seconds = float(json.loads(inspection['stdout'])['format']['duration'])
|
||||
if inspection['exit_code'] != 0 or inspection['error'] or not math.isfinite(seconds) or seconds <= 0:
|
||||
raise ValueError('Invalid prerequisite media duration')
|
||||
item['duration_seconds'] = seconds
|
||||
except (ValueError, KeyError, TypeError) as error:
|
||||
raise ValueError('Cannot identify prerequisite recording duration') from error
|
||||
artifacts.append(item)
|
||||
artifacts.sort(key=lambda item: item['path'])
|
||||
# The same hashed MKV contains both streams; audio role uses a distinct
|
||||
# byte-identical local alias to satisfy the shared validator's unique paths.
|
||||
if duration is not None:
|
||||
@@ -285,16 +321,13 @@ def collect(run, probe=command_probe, annotations=None):
|
||||
artifacts.append({'path': 'raw-audio.mkv', 'role': 'audio',
|
||||
'duration_seconds': duration, **identify_file(run / 'raw-audio.mkv'),
|
||||
**({'synthetic': True} if state['tooling_only'] else {})})
|
||||
events = []
|
||||
if annotations:
|
||||
note = read_json(annotations)
|
||||
events = note.get('events', [])
|
||||
# Annotations carry observed markers, never review/acceptance promotion.
|
||||
events = note.get('events', [])
|
||||
kind = 'synthetic' if state['tooling_only'] else 'native_port' if state['input_method'] == 'physical' else 'port_fixture'
|
||||
status = state['status']
|
||||
if status == 'captured' and missing: status = 'failed'
|
||||
receipt = {'schema_version': 1, 'receipt_id': state['session_id'] + '-linux',
|
||||
'session_id': state['session_id'], 'case_id': state['case_id'], 'scope': state['scope'],
|
||||
'obligation_id': state['scope'],
|
||||
'evidence_kind': kind, 'historical': False, 'status': status,
|
||||
'platform': {'os': 'linux', 'execution': 'native' if kind == 'native_port' else kind},
|
||||
'invocation': state['invocation'], 'clocks': state['clocks'], 'identity': identity,
|
||||
@@ -306,6 +339,7 @@ def collect(run, probe=command_probe, annotations=None):
|
||||
'ordinary_input': False, 'human_reviewed': False},
|
||||
'capture_methods': state['settings'], 'clock_id': state['clock_id'],
|
||||
'launch_id': state['launch_id'],
|
||||
'continuity': note.get('continuity', {}),
|
||||
'acceptance': {'state': 'open', 'remaining': [
|
||||
'Actual moving-content/crop/clock/physical-input/audibility review',
|
||||
'Observed scenario markers and lifetime/route continuity validation',
|
||||
@@ -315,6 +349,84 @@ def collect(run, probe=command_probe, annotations=None):
|
||||
return receipt
|
||||
|
||||
|
||||
def matrix(protocol, records=(), previous=None, dependency=None):
|
||||
"""Forty Linux obligations with validated append-only attempt history.
|
||||
|
||||
Previous attempts are re-read and hash-checked, never trusted as acceptance.
|
||||
Distinct failed/incomplete retries require distinct process/session IDs.
|
||||
A shared environment failure is a dependency, not forty fabricated runs.
|
||||
"""
|
||||
validate_scenario_contract(protocol)
|
||||
cells = {c['id']: c for c in protocol['cells']}
|
||||
slots = {(c['id'], o): [] for c in protocol['cells'] for o in c['obligations']}
|
||||
history = []
|
||||
if previous:
|
||||
if previous.get('schema_version') != 1 or previous.get('side') != 'port-linux-native':
|
||||
raise ValueError('Unrecognized previous Linux matrix')
|
||||
for cell in previous['cells']:
|
||||
for obligation in cell['obligations']:
|
||||
for attempt in obligation['attempts']:
|
||||
path = Path(attempt['receipt_path'])
|
||||
if identify_file(path)['sha256'] != attempt['receipt_sha256']:
|
||||
raise ValueError('Historical receipt bytes changed')
|
||||
history.append((read_receipt(path), path.parent))
|
||||
seen, sessions = {}, {}
|
||||
for receipt, root in [*history, *records]:
|
||||
root = Path(root).resolve(strict=True)
|
||||
validated = validate_receipt(receipt, root)
|
||||
key = (receipt['case_id'], receipt.get('obligation_id', receipt['scope']))
|
||||
if key not in slots: raise ValueError('Unknown Linux matrix slot')
|
||||
if receipt['platform']['os'] != 'linux': raise ValueError('Linux matrix requires Linux observations')
|
||||
digest = hashlib.sha256(canonical_bytes(receipt)).hexdigest()
|
||||
record_id, session_id = receipt['receipt_id'], receipt['session_id']
|
||||
if record_id in seen:
|
||||
if seen[record_id] != digest: raise ValueError('Conflicting immutable receipt ID')
|
||||
continue
|
||||
if session_id in sessions:
|
||||
raise ValueError('A new matrix attempt must use a new launch/session ID')
|
||||
sessions[session_id] = record_id; seen[record_id] = digest
|
||||
reasons = list(validated['missing_evidence'])
|
||||
try:
|
||||
_scenario_observation(protocol, cells[key[0]], receipt)
|
||||
except (ValueError, KeyError, StopIteration) as error:
|
||||
reasons.append('Scenario continuity: ' + str(error))
|
||||
if receipt['evidence_kind'] != 'native_port':
|
||||
reasons.append('Linux native gameplay requires actual native evidence')
|
||||
path = root / 'receipt.json'
|
||||
if read_receipt(path) != receipt: raise ValueError('Matrix input differs from saved receipt')
|
||||
slots[key].append({'receipt_id': record_id, 'session_id': session_id,
|
||||
'receipt_path': str(path), 'receipt_sha256': identify_file(path)['sha256'],
|
||||
'status': receipt['status'], 'evidence_kind': receipt['evidence_kind'],
|
||||
'accepted': validated['accepted'] and not reasons, 'remaining': list(dict.fromkeys(reasons))})
|
||||
result_cells, accepted = [], 0
|
||||
for cell in protocol['cells']:
|
||||
result = {k: cell[k] for k in ('id', 'lifetime', 'dialogue', 'input')}
|
||||
result['procedures'] = {
|
||||
'lifetime': protocol['lifetime_procedures'][cell['lifetime']],
|
||||
'dialogue': protocol['dialogue_procedures'][cell['dialogue']],
|
||||
'input': protocol['input_procedures'][cell['input']]}
|
||||
result['obligations'] = []
|
||||
for obligation_id in cell['obligations']:
|
||||
attempts = slots[(cell['id'], obligation_id)]
|
||||
done = any(a['accepted'] for a in attempts)
|
||||
accepted += int(done)
|
||||
dependencies = [] if done else list((dependency or {}).get('reasons', []))
|
||||
if not done:
|
||||
dependencies += ['Actual Linux ' + cell['id'] + '/' + obligation_id + ' recording and physical/audible review']
|
||||
dependencies += [reason for a in attempts for reason in a['remaining']]
|
||||
result['obligations'].append({'id': obligation_id, 'state': 'accepted' if done else 'open',
|
||||
'attempts': attempts, 'dependencies': list(dict.fromkeys(dependencies)),
|
||||
'dependency_receipt_id': (dependency or {}).get('receipt_id'),
|
||||
'required_events': required_events(protocol, cell, obligation_id),
|
||||
'route': protocol['obligations'][obligation_id].get('route'),
|
||||
'procedure': protocol['obligations'][obligation_id]})
|
||||
result_cells.append(result)
|
||||
return {'schema_version': 1, 'side': 'port-linux-native', 'required': 40,
|
||||
'accepted': accepted, 'complete': accepted == 40, 'cells': result_cells,
|
||||
'environment_dependency': dependency,
|
||||
'acceptance': {'state': 'open', 'remaining': ['Final combined original/native acceptance audit']}}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
sub = parser.add_subparsers(dest='action', required=True)
|
||||
@@ -332,17 +444,41 @@ def main():
|
||||
command.add_argument('--run', type=Path, required=True)
|
||||
command.add_argument('--annotations', type=Path)
|
||||
command.add_argument('--import-to', type=Path)
|
||||
command = sub.add_parser('matrix')
|
||||
command.add_argument('--receipt', type=Path, action='append', default=[])
|
||||
command.add_argument('--previous', type=Path)
|
||||
command.add_argument('--dependency-run', type=Path)
|
||||
command.add_argument('--output', type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
if args.action == 'preflight':
|
||||
result = preflight(args.package, read_json(args.settings))
|
||||
elif args.action == 'run':
|
||||
result = run_capture(args.package, args.output, args.session_id, args.case_id,
|
||||
args.scope, read_json(args.settings), args.seconds)
|
||||
else:
|
||||
elif args.action == 'collect':
|
||||
result = collect(args.run, annotations=args.annotations)
|
||||
if args.import_to: import_receipt(args.run / 'receipt.json', args.run, args.import_to)
|
||||
else:
|
||||
dependency = None
|
||||
if args.dependency_run:
|
||||
path = args.dependency_run / 'receipt.json'
|
||||
receipt = read_receipt(path)
|
||||
validate_receipt(receipt, path.parent)
|
||||
pre = read_json(args.dependency_run / 'preflight.json')
|
||||
if pre['ready'] or not pre['blockers'] or receipt['status'] != 'failed':
|
||||
raise ValueError('Environment dependency requires an actual failed-preflight receipt')
|
||||
dependency = {'receipt_id': receipt['receipt_id'], 'receipt_path': str(path.resolve()),
|
||||
'receipt_sha256': identify_file(path)['sha256'], 'reasons': pre['blockers']}
|
||||
result = matrix(read_json(PROJECT / 'docs/evidence/scenarios.json'),
|
||||
[(read_receipt(p), p.parent) for p in args.receipt],
|
||||
read_json(args.previous) if args.previous else None, dependency)
|
||||
separated_roots(PROJECT.parent / 'Original', args.output)
|
||||
if any(p.is_symlink() for p in (args.output.absolute(), *args.output.absolute().parents)):
|
||||
raise ValueError('Matrix output cannot use symlink aliases')
|
||||
args.output.parent.mkdir(parents=True, exist_ok=True)
|
||||
_write_json(args.output, result)
|
||||
print(canonical_bytes(result).decode(), end='')
|
||||
return 0 if result.get('ready', result.get('status') == 'captured') else 1
|
||||
return 0 if args.action == 'matrix' or result.get('ready', result.get('status') == 'captured') else 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in new issue
Block a user