"""Re-audit immutable r03 logs; retain original marker-collector rejection.""" from pathlib import Path import hashlib import importlib.util import json import re import shutil ROOT = Path(__file__).resolve().parents[4] BASE = ROOT / 'artifacts/original-completion-2026-10-02' INPUT = BASE / 'full-regression-r03' OUTPUT = BASE / 'full-regression-r03-review-r01' def sha(p): return hashlib.sha256(p.read_bytes()).hexdigest() def read(p): return json.loads(p.read_text()) def write(p, value): with p.open('x') as f: f.write(json.dumps(value, ensure_ascii=False, indent=2) + '\n') def require(ok, label): if not ok: raise ValueError(label) def module(path, name): spec = importlib.util.spec_from_file_location(name, path) result = importlib.util.module_from_spec(spec) spec.loader.exec_module(result) return result def completion(test, text, previous): # Only the two rejected schemas change. All other retained exact markers # and every engine/exit/source/raw-byte gate remain in force. if test == 'tests/performance/test_snapshot_ownership.gd': matches = re.findall(r'^Snapshot ownership: (\d+) checks, 0 failures\n', text, re.M) require(len(matches) == 1, 'Unique ownership completion') return int(matches[0]), f'Snapshot ownership: {matches[0]} checks, 0 failures\n' if test == 'tests/ui/test_supply_auto_purchase_ui.gd': matches = re.findall(r'^SUPPLY_AUTO_PURCHASE_UI checks=(\d+) failures=0\n', text, re.M) require(len(matches) == 1, 'Unique auto UI completion') return int(matches[0]), f'SUPPLY_AUTO_PURCHASE_UI checks={matches[0]} failures=0\n' require(previous['passed'] and text.count(previous['completion_marker']) == 1, 'Retained exact marker') return previous['actual_checks'], previous['completion_marker'] def main(): require(not OUTPUT.exists(), 'Fresh output only') original = read(INPUT / 'verification.json') require(not original['passed'] and original['runner_exit_code'] == 0 and original['changed_paths'] == [], 'Expected collector-only rejection') changed = ['tests/performance/test_snapshot_ownership.gd', 'tests/ui/test_supply_auto_purchase_ui.gd'] require(original['failed_tests'] == changed, 'Only expected marker rejections') pins = read(INPUT / 'source-start.json') require(pins == read(INPUT / 'source-end.json') and sha(INPUT / 'source-start.json') == sha(INPUT / 'source-end.json') == original['source_map_sha256'], 'Stable full input bytes') require(original['wrapper_unchanged'] and sha(INPUT / 'wrapper-input.py') == original['wrapper_sha256'] == original['wrapper_sha256_after'], 'Execution wrapper unchanged') require(sha(INPUT / 'suites/all-tests.json') == original['all_results_sha256'], 'Raw runner result SHA') wrapper = module(INPUT / 'wrapper-input.py', 'execution_wrapper') wrapper.ROOT = ROOT require(wrapper.source_map() == pins, 'Current production equals execution source') roster = read(INPUT / 'expected-tests.json') rows = read(INPUT / 'suites/all-tests.json') require(roster == [r['test'] for r in rows] == [r['test'] for r in original['rows']] and len(set(roster)) == len(roster), 'Unique ordered actual roster') adapter_path = BASE / 'windows-current-release-adapter-prep-r01/windows_adapter.py' independent = module(adapter_path, 'independent_completion') independent.SPECIAL_MARKERS['tests/ui/test_supply_auto_purchase_ui.gd'] = r'SUPPLY_AUTO_PURCHASE_UI checks=(\d+) failures=0' reviewed = [] for raw, old in zip(rows, original['rows']): test = raw['test'] require(raw['exit_code'] == 0 and raw['failed'] is False and old['source_sha256'] == pins[test], 'Actual pass and test source') log = INPUT / 'suites' / raw['log'] require(raw['log'] == old['log'] and Path(raw['log']).name == raw['log'] and sha(log) == old['log_sha256'], 'Exact ordinary raw log') text = log.read_text() require('Godot Engine v4.7.2' in text and not re.search(r'(?m)^\s*(?:SCRIPT ERROR|ERROR|Parse Error):', text), 'Clean engine completion') count, marker = completion(test, text, old) other_count, other_marker = independent.completion(test, text) require((count, marker.rstrip('\n')) == (other_count, other_marker) and count > 0, 'Independent parser agreement') reviewed.append(dict(old, actual_checks=count, completion_marker=marker, passed=True)) # The ownership source is unchanged and enumerates every runtime section # in both the new-game and populated captures. Added auto_purchase_plans # accounts for two additional checks, with no weakened assertion. old_map = read(BASE / 'full-regression-r02/source-end.json') ownership = 'tests/performance/test_snapshot_ownership.gd' require(old_map[ownership] == pins[ownership], 'Ownership test source unchanged') ownership_text = (ROOT / ownership).read_text() require('for section: Variant in expected[&"systems"][&"runtime"]:' in ownership_text and 'verify_detached(runtime, "new game")' in ownership_text and 'verify_detached(runtime, "populated game")' in ownership_text, 'Dynamic section count, two captures') require('SUPPLY_AUTO_PURCHASE_UI checks=%d failures=%d' in (ROOT / changed[1]).read_text(), 'UI literal summary source') negatives = [] for test, good in [(changed[0], 'Snapshot ownership: 91 checks, 0 failures\n'), (changed[1], 'SUPPLY_AUTO_PURCHASE_UI checks=28 failures=0\n')]: for name, value in [('duplicate', good + good), ('failure', good.replace('0 failures', '1 failures').replace('failures=0', 'failures=1')), ('missing', '')]: try: completion(test, value, {}) except ValueError: negatives.append({'test': test, 'case': name, 'rejected': True}) else: raise ValueError('Negative marker accepted') before = {str(p.relative_to(INPUT)): sha(p) for p in INPUT.rglob('*') if p.is_file()} shutil.copytree(INPUT, OUTPUT) (OUTPUT / 'verification.json').rename(OUTPUT / 'original-collector-verification.json') shutil.copyfile(Path(__file__), OUTPUT / 'review-input.py') report = dict(original, passed=True, checks=sum(r['actual_checks'] for r in reviewed), failed_tests=[], rows=reviewed, wrapper_copy_path=str(OUTPUT / 'wrapper-input.py')) report['reaudit'] = {'scope': 'immutable actual r03 logs; engine not rerun', 'original_collector_passed': False, 'original_collector_verification_sha256': sha(INPUT / 'verification.json'), 'original_execution_directory': str(INPUT), 'review_sha256': sha(Path(__file__)), 'independent_parser_source_sha256': sha(adapter_path), 'narrow_marker_schema_corrections': changed, 'negative_controls': negatives, 'no_engine_execution': True, 'source_test_assertions_changed': False, 'original_full_acceptance': False, 'windows_acceptance': False} write(OUTPUT / 'verification.json', report) require(before == {str(p.relative_to(INPUT)): sha(p) for p in INPUT.rglob('*') if p.is_file()} and wrapper.source_map() == pins, 'Original evidence and production unchanged') write(OUTPUT / 'review-integrity.json', {'original_files_unchanged': True, 'original_files': before, 'actual_suites':len(reviewed), 'actual_checks':report['checks'], 'source_changes': [], 'negative_controls_rejected': len(negatives), 'execution_wrapper_unchanged':True,'game_complete':False}) print(json.dumps({k: report[k] for k in ['passed','suites','checks','failed_tests','changed_paths']}, ensure_ascii=False)) if __name__ == '__main__': main()