--- .local\scunion\.local\peer-union-e34-evidence-proposal-20260923\verify.py +++ .local\scunion\.local\peer-union-e34-evidence-proposal-v2-20260923\verify.py @@ -22,6 +22,32 @@ 'source_cli-628cfee23782acb5.exe': ('oa-cli', 'a40ae4b7af2ff749d5c206bc15be4b74c89e635c2e6f8c3c610f0b692147f573'), 'arcadia_studio-c5b42126ba36cd38.exe': ('oa-desktop', '4ee353b9bf1940258a27fad41b904b2638783c1a8c7f9498c118c5ba62df71e9'), } +HISTORICAL_LOG_SHA256 = '2a043b7f8dd2ba952f0a2f967a10936d0dc805913d8743375a714c4bde4a0c2e' +HISTORICAL_FAILED = { + 'app::behavior_removal_tests::mounted_scenario_use_delete_keeps_definition_and_second_use_and_rejects_owner_replay', + 'behavior::scenario::workspace::details_tests::details_opens_current_saved_view_properties_after_following_diagram_picker', + 'behavior::scenario::workspace::details_tests::saved_details_opens_real_editable_inspector_and_returns_to_same_view', +} +# Review policy is independent of the manifest and mutable receipt summaries. +# Basenames identify sections within the already checked literal workspace inventory. +EXPECTED_IGNORED = ( + ('r6_data-f7978707542e0007.exe', 'inheritance_chain_validation_scaling_probe', + 'explicit inheritance scaling probe; run with --ignored --nocapture'), + ('arcadia_studio-c5b42126ba36cd38.exe', 'app::source_rename::timing_tests::accepted_release1_prepare_commit_sync_and_confirm_timing', + 'manual Windows dev/debug rename latency trial; run alone with --ignored --nocapture --test-threads=1'), + ('arcadia_studio-c5b42126ba36cd38.exe', 'app::source_rename::timing_tests::layout_timing_tests::accepted_release1_constructor_vs_reuse_through_next_highlight', + 'manual Windows dev/debug editor replacement + layout/highlight trial; run alone with --ignored --nocapture --test-threads=1'), + ('arcadia_studio-c5b42126ba36cd38.exe', 'app::source_symbols::tests::source_symbols_100_modules_1000_definitions_10000_uses', + 'manual 100-module latency/process-memory trial; run alone with --ignored --nocapture --test-threads=1'), + ('arcadia_studio-c5b42126ba36cd38.exe', 'behavior::scenario::spacing::controller::timing_tests::saved_spacing_capture_prepare_20_lanes_1000_messages_3_views', + 'Diagnostic timing only; run alone with --exact --ignored --nocapture after correctness gates; no latency acceptance threshold'), + ('arcadia_studio-c5b42126ba36cd38.exe', 'source_annotations::anchor_tests::final_multi_glyph_cluster_anchor_uses_logical_trailing_advance_edge', + 'manual supported-font cluster and bidi witnesses'), + ('arcadia_studio-c5b42126ba36cd38.exe', 'source_annotations::anchor_tests::mixed_direction_omitted_separator_has_one_logical_predecessor_anchor', + 'manual supported-font cluster and bidi witnesses'), + ('arcadia_studio-c5b42126ba36cd38.exe', 'source_annotations::performance_tests::annotation_projection_cost_distributions', + 'manual diagnostic projection distributions; no fixed machine threshold'), +) PREFIXES = ('Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', '.cargo', 'build', 'crates', 'assets', 'docs', 'examples', 'harness/fixtures', 'scripts', 'vendor', 'harness/experiments/edge-attachments-20260922/native-fixture.arcadia', @@ -129,6 +155,7 @@ assert data[supplement_root + supplement['inputs']] == input_raw and supplement['inputs_sha256'] == sha(input_raw) assert supplement['binding_unchanged'] and supplement['before'] == supplement['after'] before = supplement['before'] + assert before == read(supplement_root + 'before.json') assert before['head'] == SOURCE and not before['tracked_status'] and not before['changed_inputs'] assert before['baseline_sha256'] == supplement['baseline_sha256'] and before['inputs_sha256'] == sha(input_raw) assert before['environment']['ARCADIA_CODEC_LIFECYCLE_PHASE'] is None and before['environment']['RUST_MIN_STACK'] is None @@ -136,6 +163,7 @@ assert len(supplement['inventories']) == 3 for item in supplement['inventories']: key = norm(item['path']) + assert item == read(supplement_root + ntpath.splitext(ntpath.basename(key))[0] + '.result.json') package, expected_hash = REBUILT[ntpath.basename(key)] assert item['exit'] == 0 and item['command'] == [item['path'], '--list'] assert norm(item['cwd']).endswith('\\crates\\' + package) @@ -162,6 +190,7 @@ passed += counts[0] assert passed == 2005 and len(ignored) == 8 assert ignored == manifest['ignored'] + assert tuple((ntpath.basename(i['section']), i['name'], i['reason']) for i in ignored) == EXPECTED_IGNORED desktop = next(a for a in listing['artifacts'] if ntpath.basename(a['path']).startswith('arcadia_studio-')) desktop_names = listed[norm(desktop['path'])]['listing_members'] @@ -193,6 +222,7 @@ assert raw == input_raw and native['scope'] == 'native' and native['mode'] == 'build' assert native['command'] == ['cargo', 'build', '--locked', '--offline', '-p', 'oa-desktop', '-p', 'oa-core', '--bin', 'arcadia-studio', '--example', 'attachment_snapshot', '--example', 'state_bend_routing_snapshot'] assert 'Finished `dev` profile' in text and native['duration_monotonic_ns'] > 0 + assert not re.search(r'^\s*error(?:\[|:)', text, re.M) for recorded in (listing, full, strict, native): assert recorded['environment']['CARGO_BUILD_JOBS'] == '1' assert recorded['environment']['CARGO_INCREMENTAL'] == '0' @@ -204,8 +234,21 @@ failed_prefix = 'supplement/combined-rebuilt-inventory-e34-1/' failure = read(failed_prefix + 'arcadia-dc4fafbbc0215f88.result.json') + failure_before = read(failed_prefix + 'before.json') + assert failure_before['head'] == SOURCE and not failure_before['tracked_status'] and not failure_before['changed_inputs'] + assert failure_before['baseline_sha256'] == supplement['baseline_sha256'] + assert data[failed_prefix + 'inputs.json'] == input_raw + assert failure_before['inputs_sha256'] == sha(input_raw) + assert failure_before['environment']['ARCADIA_CODEC_LIFECYCLE_PHASE'] is None + assert failure_before['environment']['RUST_MIN_STACK'] is None assert sha(data[failed_prefix + 'launcher.py']) == SUPPLEMENT assert failure['exit'] == 3221225781 and failure['command'] == [failure['path'], '--list'] + failure_key = norm(failure['path']) + assert ntpath.basename(failure_key) == 'arcadia-dc4fafbbc0215f88.exe' + assert failure['baseline_artifact'] == old_artifacts[failure_key] + successful_retry = next(i for i in supplement['inventories'] if norm(i['path']) == failure_key) + assert failure['cwd'] == successful_retry['cwd'] + assert failure['artifact_before'] == successful_retry['artifact_before'] assert failure['artifact_before'] == failure['artifact_after'] assert failure['artifact_before']['sha256'] == REBUILT['arcadia-dc4fafbbc0215f88.exe'][1] assert data[failed_prefix + failure['log']] == b'' and failure['log_sha256'] == sha(b'') @@ -247,12 +290,16 @@ historical_launcher = '0b14e2e80e4c02ecd31f6dfa5fdfaf1594a6bc3ac319530eca1a3c81505a478e' old_list, old_text, old_inputs = gate('combined-desktop-list-1', historical_launcher, historical_source) old_run, old_run_text, old_run_inputs = gate('combined-desktop-diagnostic-1', historical_launcher, historical_source, 101) + assert sha(data['gates/combined-desktop-diagnostic-1.log']) == HISTORICAL_LOG_SHA256 old_command = ['cargo', 'test', '--locked', '--offline', '-p', 'oa-desktop', '--bin', 'arcadia-studio', '--'] assert old_list['command'] == old_command + ['--list'] and old_run['command'] == old_command + ['--test-threads=1'] assert old_inputs == old_run_inputs and old_list['artifacts'] == old_run['artifacts'] historical_names = parse(old_text)['listing_members'] assert len(historical_names) == 1347 - outcomes(parse(old_run_text), historical_names, [1337, 3, 7]) + historical_parsed = parse(old_run_text) + historical_ignored = outcomes(historical_parsed, historical_names, [1337, 3, 7]) + assert {n for n, status, _ in historical_parsed['outcomes'] if status == 'FAILED'} == HISTORICAL_FAILED + assert tuple((i['name'], i['reason']) for i in historical_ignored) == tuple((n, reason) for section, n, reason in EXPECTED_IGNORED if section == 'arcadia_studio-c5b42126ba36cd38.exe') def git(*args, input=None): return subprocess.run(['git', *args], cwd=repo, input=input, capture_output=True, check=True).stdout --- .local\scunion\.local\peer-union-e34-evidence-proposal-20260923\manifest.json +++ .local\scunion\.local\peer-union-e34-evidence-proposal-v2-20260923\manifest.json @@ -6,8 +6,8 @@ "sha256": "08c9a6e72e74e3368a1b167b358bf76923db3986d53457d5ead707926d6b3b5b" }, "verifier": { - "bytes": 19786, - "sha256": "e41cc00a78f70e98344e2afaf96c06d15de0899cdaae12cecfe7a48229c1b02a" + "bytes": 24051, + "sha256": "2e2186141957d9490fecd8ada6956aa1419510602735007b287b36235ae477a8" }, "payloads": { "context/admit-scenario-union-gate.py": { --- .local\scunion\.local\peer-union-e34-evidence-proposal-20260923\README.md +++ .local\scunion\.local\peer-union-e34-evidence-proposal-v2-20260923\README.md @@ -1,9 +1,19 @@ -# Frozen e34 Windows gate evidence — proposed package +# Frozen e34 Windows gate evidence — proposed package v2 Source `e34ba27e26ede3ab55f276acc250d92b2e0c3204`, Git tree `29f769926e2e907f0b40c3b33ec36658ee6601b7`. This package is prepared for parent review; -its portable verifier has not yet been executed. Nothing here claims native or +its revised portable verifier has not yet been executed. Nothing here claims native or release acceptance. The evidence archive contains records and source bindings, without executable binary duplication. + +V2 addresses static review findings: independently fixed historical raw-log and +failed/ignored identities, an independent eight-test ignore policy, aggregate/leaf +and before-snapshot consistency for supplementary listings (including source and +baseline bindings for the retained failed attempt), and native compiler-error +refusal. The original proposal remains byte-exact. The archive and all 72 payloads +are unchanged; its archived original packaging script is historical evidence. +Only the verifier pin and this README change in the proposal. The separate v2 +producer and semantic-control driver are review helpers, not archived execution +dependencies. Neither the revised verifier nor the controls have been run. Recorded gates are a literal workspace inventory (2,013 names / 60 executables / three doctest sections), two direct repaired test groups (six + one passed), strict --- .local\scunion\.local\package-e34-evidence.py +++ .local\scunion\.local\package-e34-evidence-v2.py @@ -1,129 +1,68 @@ -"""Prepare a new proposal package only; do not execute its verifier or publish anything.""" +"""Create the reviewed v2 proposal without executing a verifier or archived code.""" from pathlib import Path import hashlib import json import shutil -import subprocess -import zipfile -ROOT = Path(__file__).resolve().parent.parent -LOCAL = ROOT / '.local' -RAW = LOCAL / 'scenario-union-gates-20260923' -OUT = LOCAL / 'peer-union-e34-evidence-proposal-20260923' -SOURCE = 'e34ba27e26ede3ab55f276acc250d92b2e0c3204' -TREE = '29f769926e2e907f0b40c3b33ec36658ee6601b7' -NAMES = ('combined-workspace-list-e34-1', 'combined-details-e34-direct-1', - 'combined-removal-e34-direct-1', 'combined-strict-e34-1', 'combined-native-e34-1', - 'combined-workspace-full-e34-1', 'combined-desktop-list-1', 'combined-desktop-diagnostic-1') +LOCAL = Path(__file__).resolve().parent +ORIGINAL = LOCAL / 'peer-union-e34-evidence-proposal-20260923' +OUT = LOCAL / 'peer-union-e34-evidence-proposal-v2-20260923' +ORIGINAL_PINS = { + '.gitattributes': (71, 'e4206e7142a4c884e433fb83f68548d8cbb6945955cb1d378a01f012da4123eb'), + 'evidence.zip': (1073739, '08c9a6e72e74e3368a1b167b358bf76923db3986d53457d5ead707926d6b3b5b'), + 'manifest.json': (17383, '9fc171e23543bff10452b2352844486165097a45533de7485bcbe3a542b2a9a4'), + 'README.md': (5158, '6ea11241d7e1c2e0f5bc74fd243be4adfe1723cde247f226e0d0f30a9aa1cfcd'), + 'verify.py': (19786, 'e41cc00a78f70e98344e2afaf96c06d15de0899cdaae12cecfe7a48229c1b02a'), +} + def pin(raw): return {'bytes': len(raw), 'sha256': hashlib.sha256(raw).hexdigest()} + +def check_original(): + assert {p.name for p in ORIGINAL.iterdir()} == set(ORIGINAL_PINS) + for name, (size, digest) in ORIGINAL_PINS.items(): + assert pin((ORIGINAL / name).read_bytes()) == {'bytes': size, 'sha256': digest}, name + + def main(): + check_original() OUT.mkdir() - payloads = {} - for name in NAMES: - record = json.loads((RAW / (name + '.result.json')).read_bytes()) - for path in sorted(RAW.glob(name + '.*')): - assert path.is_file() and path.suffix in ('.json', '.log') - payloads['gates/' + path.name] = path.read_bytes() - launcher = record['launcher_sha256'] + '.py' - payloads['launchers/' + launcher] = (RAW / 'launchers' / launcher).read_bytes() - for name in ('combined-rebuilt-inventory-e34-1', 'combined-rebuilt-inventory-e34-2'): - for path in sorted((RAW / name).rglob('*')): - if path.is_file(): - payloads['supplement/' + name + '/' + path.relative_to(RAW / name).as_posix()] = path.read_bytes() - transition = LOCAL / 'transition-oracle-builds-20260923/combined-transition-e34-1' - for path in sorted(transition.rglob('*')): - if path.is_file() and path.suffix != '.exe': - payloads['transition/' + path.relative_to(transition).as_posix()] = path.read_bytes() - for name in ('admit-scenario-union-gate.py', 'admit-workspace-union-gate.py', - 'admit-workspace-rebuilt-inventory.py', 'record-rebuilt-executable-listings.py', - 'e34-workspace-gate-order-20260923.md', 'scenario-union-desktop-diagnostic-status-20260923.md'): - payloads['context/' + name] = (LOCAL / name).read_bytes() - payloads['context/package-e34-evidence.py'] = Path(__file__).read_bytes() - source_commit = subprocess.check_output(['git', 'cat-file', 'commit', SOURCE], cwd=ROOT) - payloads['source/commit.txt'] = source_commit - predecessor = subprocess.check_output(['git', 'rev-parse', '2e7c399'], cwd=ROOT).decode().strip() - predecessor_record = {'commit': predecessor, 'path': 'harness/experiments/peer-union-windows-20260923', - 'scope': 'Published 13-receipt predecessor through f82 strict; not the later full desktop diagnostic.'} - payloads['history/predecessor.json'] = (json.dumps(predecessor_record, indent=2) + '\n').encode() - report = json.loads((RAW / 'combined-workspace-full-e34-1.workspace-rebuilt-admission.json').read_bytes()) - ignored = [{'section': s['key'], **i} for s in report['sections'] for i in s['ignored']] - limitations = [ - 'Archive verification rechecks recorded evidence and Git blobs; it does not rerun gates or reconstruct executable bytes.', - 'No executable binaries or DLLs are included; build artifacts remain identified by their original receipt hashes.', - 'Native workflow trials are not closed here. No native usability, public source8, or release acceptance is claimed.', - 'Eight named tests were ignored, not executed or passed. The unwired Scenario label experiment is outside the actual inventory.', - 'The full gate launch explicitly rejected lifecycle-phase and stack overrides, but the fb receipt omits those two environment fields; launch preconditions are transcript evidence, not a captured receipt snapshot. Direct focus and supplementary listings capture both null.', - 'Host UTC clock jumps occurred. The main fb recorder lacks a monotonic duration; no total elapsed-time claim is derived from UTC subtraction.', - 'First supplementary listing failed with 0xC0000135 after the toolchain environment was omitted; raw failure is retained. An unchanged-helper retry with the toolchain environment succeeded.', - 'Historical f82 desktop results remain a failure: 1337 passed, 3 failed, 7 ignored. The repaired e34 source is a distinct subject.' - ] - for name in payloads: - assert not name.lower().endswith(('.exe', '.dll', '.pdb')) - with zipfile.ZipFile(OUT / 'evidence.zip', 'x', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as archive: - for name, raw in sorted(payloads.items()): - archive.writestr(name, raw) - shutil.copyfile(LOCAL / 'verify-e34-evidence.py', OUT / 'verify.py') - manifest = {'source': SOURCE, 'tree': TREE, 'archive': pin((OUT / 'evidence.zip').read_bytes()), - 'verifier': pin((OUT / 'verify.py').read_bytes()), - 'payloads': {name: pin(raw) for name, raw in sorted(payloads.items())}, - 'gates': list(NAMES), 'ignored': ignored, 'historical_predecessor': predecessor_record, - 'limitations': limitations, 'status': 'PROPOSED_PACKAGE_NOT_YET_VERIFIED'} + # Preserve every raw evidence payload and the original ZIP bytes exactly. + for name in ('evidence.zip', '.gitattributes'): + shutil.copyfile(ORIGINAL / name, OUT / name) + shutil.copyfile(LOCAL / 'verify-e34-evidence-v2.py', OUT / 'verify.py') + manifest = json.loads((ORIGINAL / 'manifest.json').read_bytes()) + manifest['verifier'] = pin((OUT / 'verify.py').read_bytes()) (OUT / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n', encoding='utf-8', newline='\n') - ignored_lines = '\n'.join('- `' + i['name'] + '` — ' + i['reason'] for i in ignored) - readme = f'''# Frozen e34 Windows gate evidence — proposed package + readme = (ORIGINAL / 'README.md').read_text(encoding='utf-8') + readme = readme.replace('# Frozen e34 Windows gate evidence — proposed package', + '# Frozen e34 Windows gate evidence — proposed package v2', 1) + readme = readme.replace('its portable verifier has not yet been executed.', + 'its revised portable verifier has not yet been executed.', 1) + review = ''' +V2 addresses static review findings: independently fixed historical raw-log and +failed/ignored identities, an independent eight-test ignore policy, aggregate/leaf +and before-snapshot consistency for supplementary listings (including source and +baseline bindings for the retained failed attempt), and native compiler-error +refusal. The original proposal remains byte-exact. The archive and all 72 payloads +are unchanged; its archived original packaging script is historical evidence. +Only the verifier pin and this README change in the proposal. The separate v2 +producer and semantic-control driver are review helpers, not archived execution +dependencies. Neither the revised verifier nor the controls have been run. +''' + anchor = 'without executable binary duplication.\n' + assert readme.count(anchor) == 1 + readme = readme.replace(anchor, anchor + review, 1) + (OUT / 'README.md').write_text(readme, encoding='utf-8', newline='\n') + check_original() + assert (OUT / 'evidence.zip').read_bytes() == (ORIGINAL / 'evidence.zip').read_bytes() + print(json.dumps({'folder': str(OUT), 'archive': manifest['archive'], 'verifier': manifest['verifier'], + 'original_unchanged': True, 'verified': False}, indent=2)) -Source `{SOURCE}`, Git tree `{TREE}`. This package is prepared for parent review; -its portable verifier has not yet been executed. Nothing here claims native or -release acceptance. The evidence archive contains records and source bindings, -without executable binary duplication. - -Recorded gates are a literal workspace inventory (2,013 names / 60 executables / -three doctest sections), two direct repaired test groups (six + one passed), strict -workspace/all-target Clippy, one combined GUI/two-example build, the separate -transition-oracle build, and one unfiltered literal workspace test invocation -(2,005 passed, zero failed, eight ignored). All e34 gates bind 760 committed inputs. -The external transition build additionally binds three prepared files and the -preparation receipt; its original preparation subject f82 is distinguished from -the actual e34 build subject. - -The full invocation rebuilt three executable hashes. Fresh direct listings bind -their actual 0 / 12 / 1,347 members. Admission uses 57 original artifact hashes plus -those exact three replacements; neither original listings nor raw receipts were -rewritten. Both the initial failed direct-list attempt and successful retry are -included. All immutable launchers are evidence only; the verifier parses logs -itself and never imports or executes archived code. It uses only read-only Git -commands against the supplied repository to validate exact committed input bytes. - -Historical `combined-desktop-diagnostic-1` at f82 is retained with its own original -listing, raw log, input manifest and launcher: 1,337 passed, three failed, seven -ignored. Those failures motivated the distinct e34 test-fixture repairs; no f82 -outcome is relabeled as e34. The older published 13-gate checkpoint is linked at -`{predecessor}:harness/experiments/peer-union-windows-20260923`. - -After parent review, verify from any host with Python and Git, using a repository -containing the e34 and f82 commits: - -```text -python verify.py --repo /path/to/ARCADIA-Studio -``` - -The verifier compares commands, source/tree/blob pins, actual per-executable -membership, outcomes, all recorded artifact identities, prepared external inputs, -and raw hashes. It does not run Cargo, tests, GUI tools, or archived helpers. - -Ignored tests (not passed): - -{ignored_lines} - -Evidence limits: - -''' + '\n'.join('- ' + item for item in limitations) + '\n' - (OUT / 'README.md').write_text(readme, encoding='utf-8', newline='\n') - (OUT / '.gitattributes').write_text('evidence.zip -text\nmanifest.json -text\nverify.py -text\nREADME.md -text\n', encoding='utf-8', newline='\n') - print(json.dumps({'folder': str(OUT), 'payloads': len(payloads), 'archive': manifest['archive'], 'verifier': manifest['verifier'], 'verified': False}, indent=2)) if __name__ == '__main__': + if not __debug__: + raise SystemExit('Optimized Python is not supported') main() --- /dev/null +++ .local\scunion\.local\e34-evidence-v2-controls.py @@ -0,0 +1,249 @@ +"""Opt-in semantic controls for the reviewed v2 verifier; never execute archived code. + +Creates a NEW control directory, retains every case, and runs only copied verify.py +with read-only Git access. Ordinary archive/payload/reference hashes are repaired. +Do not run until the parent has reviewed this driver and the successor verifier. +""" +from pathlib import Path +import argparse +import copy +import hashlib +import json +import ntpath +import re +import shutil +import subprocess +import sys +import zipfile + +LOCAL = Path(__file__).resolve().parent +PACKAGE = LOCAL / 'peer-union-e34-evidence-proposal-v2-20260923' +FULL = 'gates/combined-workspace-full-e34-1' +OLD = 'gates/combined-desktop-diagnostic-1' +SUPPLEMENT = 'supplement/combined-rebuilt-inventory-e34-2/' + + +def sha(raw): + return hashlib.sha256(raw).hexdigest() + + +def pin(raw): + return {'bytes': len(raw), 'sha256': sha(raw)} + + +def read(data, name): + return json.loads(data[name]) + + +def write(data, name, value): + data[name] = (json.dumps(value, indent=2) + '\n').encode() + + +def parse(text): + return {'listing_members': re.findall(r'^([^\r\n]+): test\r?$', text, re.M), + 'outcomes': [list(t) for t in re.findall(r'^test ([^\r\n]+) \.\.\. (ok|FAILED|ignored)(?:, ([^\r\n]*))?\r?$', text, re.M)], + 'summaries': [list(t) for t in re.findall(r'^test result: (ok|FAILED)\. (\d+) passed; (\d+) failed; (\d+) ignored; (\d+) measured; (\d+) filtered out;', text, re.M)], + 'listing_totals': [list(t) for t in re.findall(r'^(\d+) tests?, (\d+) benchmarks?\r?$', text, re.M)], + 'text_sha256': sha(text.encode())} + + +def refresh_full(data, manifest, update_policy=False): + text = data[FULL + '.log'].decode() + headers = list(re.finditer(r'^\s+(?:Running (?P[^\r\n]+) \((?P[^\r\n]+\.exe)\)|Doc-tests (?P[^\r\n]+))\r?$', text, re.M)) + sections = [] + for index, match in enumerate(headers): + body = text[match.end():headers[index + 1].start() if index + 1 < len(headers) else len(text)] + sections.append({'key': ntpath.normpath(match['exe']) if match['exe'] else 'doctest:' + match['doc'], + 'kind': match['kind'] or 'doctest', **parse(body)}) + result = read(data, FULL + '.result.json') + result['workspace_sections'] = sections + write(data, FULL + '.result.json', result) + if update_policy: + manifest['ignored'] = [{'section': section['key'], 'name': n, 'reason': reason} + for section in sections for n, status, reason in section['outcomes'] if status == 'ignored'] + + +def replace_once(raw, old, new): + assert raw.count(old) == 1, old + return raw.replace(old, new, 1) + + +def repair_references(original, data): + """Repair ordinary payload-digest references transitively, preserving other bytes. + + This deliberately does not repair policy constants or consistency statements: + aggregate/leaf contradictions and mutated outcome identities must remain visible. + """ + history = {name: {sha(raw)} for name, raw in original.items()} + for _ in range(16): + replacements = {} + for name, raw in data.items(): + current = pin(raw) + for old_hash in history[name]: + if old_hash != current['sha256']: + assert old_hash not in replacements or replacements[old_hash] == current + replacements[old_hash] = current + history[name].add(current['sha256']) + + def repaired(value): + if isinstance(value, dict): + out = {k: repaired(v) for k, v in value.items()} + if value.get('sha256') in replacements and 'bytes' in value: + out['bytes'] = replacements[value['sha256']]['bytes'] + return out + if isinstance(value, list): + return [repaired(v) for v in value] + if isinstance(value, str) and value in replacements: + return replacements[value]['sha256'] + return value + + changed = False + for name in data: + if not name.endswith('.json'): + continue + before = read(data, name) + after = repaired(before) + if after != before: + write(data, name, after) + changed = True + if not changed: + return + raise AssertionError('Digest repair did not converge') + + +def mutate(kind, data, manifest): + if kind == 'historical_failed_identity': + raw = data[OLD + '.log'] + rows = parse(raw.decode())['outcomes'] + bad = next(n for n, status, _ in rows if status == 'FAILED') + good = next(n for n, status, _ in rows if status == 'ok') + raw = replace_once(raw, f'test {bad} ... FAILED'.encode(), f'test {bad} ... ok'.encode()) + data[OLD + '.log'] = replace_once(raw, f'test {good} ... ok'.encode(), f'test {good} ... FAILED'.encode()) + elif kind == 'historical_panic_details': + raw = data[OLD + '.log'] + line = next(line for line in raw.splitlines(keepends=True) if b'panicked at' in line) + data[OLD + '.log'] = replace_once(raw, line, b'') + elif kind in ('ignored_identity', 'ignored_reason'): + raw = data[FULL + '.log'] + r = read(data, FULL + '.result.json') + section = next(s for s in r['workspace_sections'] if any(status == 'ignored' for _, status, _ in s['outcomes'])) + bad, _, reason = next(row for row in section['outcomes'] if row[1] == 'ignored') + if kind == 'ignored_identity': + good = next(n for n, status, _ in section['outcomes'] if status == 'ok') + raw = replace_once(raw, f'test {bad} ... ignored, {reason}'.encode(), f'test {bad} ... ok'.encode()) + raw = replace_once(raw, f'test {good} ... ok'.encode(), f'test {good} ... ignored, {reason}'.encode()) + else: + raw = replace_once(raw, f'test {bad} ... ignored, {reason}'.encode(), f'test {bad} ... ignored, changed control reason'.encode()) + data[FULL + '.log'] = raw + refresh_full(data, manifest, update_policy=True) + elif kind == 'supplement_leaf_exit': + name = SUPPLEMENT + 'arcadia-dc4fafbbc0215f88.result.json' + value = read(data, name) + value['exit'] = 101 + write(data, name, value) + elif kind == 'supplement_before': + name = SUPPLEMENT + 'before.json' + value = read(data, name) + value['environment']['RUST_LOG'] = 'control-change' + write(data, name, value) + elif kind == 'rebuilt_artifact_rollback': + value = read(data, FULL + '.result.json') + listing = read(data, 'gates/combined-workspace-list-e34-1.result.json') + old = next(a for a in listing['artifacts'] if ntpath.basename(a['path']) == 'arcadia-dc4fafbbc0215f88.exe') + current = next(a for a in value['artifacts'] if a['path'] == old['path']) + assert current['sha256'] != old['sha256'] + current.update(old) + write(data, FULL + '.result.json', value) + elif kind in ('outcome_membership', 'duplicate_outcome'): + raw = data[FULL + '.log'] + result = read(data, FULL + '.result.json') + section = next(s for s in result['workspace_sections'] if sum(status == 'ok' for _, status, _ in s['outcomes']) >= 2) + first, second = [n for n, status, _ in section['outcomes'] if status == 'ok'][:2] + replacement = 'control::not_in_inventory' if kind == 'outcome_membership' else second + data[FULL + '.log'] = replace_once(raw, f'test {first} ... ok'.encode(), f'test {replacement} ... ok'.encode()) + refresh_full(data, manifest) + elif kind == 'filtered_command': + value = read(data, FULL + '.result.json') + value['command'].insert(value['command'].index('--'), 'control_filter') + value['filter'] = 'control_filter' + write(data, FULL + '.result.json', value) + elif kind == 'source_input_digest': + changed = 0 + for name in list(data): + if not name.endswith('.json'): + continue + value = read(data, name) + if (isinstance(value, dict) and value.get('source') == manifest['source'] + and isinstance(value.get('inputs'), list) and len(value['inputs']) == 760): + value['inputs'][0]['sha256'] = '0' * 64 + write(data, name, value) + changed += 1 + assert changed >= 8 + elif kind == 'native_error': + name = 'gates/combined-native-e34-1.log' + data[name] += b'error: injected semantic control compiler failure\n' + else: + raise AssertionError(kind) + + +CASES = ( + 'historical_failed_identity', 'historical_panic_details', 'ignored_identity', + 'ignored_reason', 'supplement_leaf_exit', 'supplement_before', + 'rebuilt_artifact_rollback', 'outcome_membership', 'duplicate_outcome', + 'filtered_command', 'source_input_digest', 'native_error', +) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--repo', type=Path, required=True) + parser.add_argument('--out', type=Path, required=True, help='New directory; existing paths are rejected') + args = parser.parse_args() + assert not args.out.exists() + manifest = json.loads((PACKAGE / 'manifest.json').read_bytes()) + assert pin((PACKAGE / 'verify.py').read_bytes()) == manifest['verifier'] + assert pin((PACKAGE / 'evidence.zip').read_bytes()) == manifest['archive'] + with zipfile.ZipFile(PACKAGE / 'evidence.zip') as archive: + assert len(archive.namelist()) == len(set(archive.namelist())) + original = {n: archive.read(n) for n in archive.namelist()} + assert {n: pin(raw) for n, raw in original.items()} == manifest['payloads'] + args.out.mkdir(parents=True) + results = [] + for kind in ('positive', *CASES): + case = args.out / kind + shutil.copytree(PACKAGE, case) + if kind != 'positive': + data = original.copy() + changed_manifest = copy.deepcopy(manifest) + mutate(kind, data, changed_manifest) + repair_references(original, data) + assert data != original + with zipfile.ZipFile(case / 'evidence.zip', 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as archive: + for name, raw in sorted(data.items()): + archive.writestr(name, raw) + changed_manifest['payloads'] = {n: pin(raw) for n, raw in sorted(data.items())} + changed_manifest['archive'] = pin((case / 'evidence.zip').read_bytes()) + (case / 'manifest.json').write_text(json.dumps(changed_manifest, indent=2) + '\n', encoding='utf-8', newline='\n') + # The only executable under test is reviewed top-level verify.py, never ZIP contents. + command = [sys.executable, str((case / 'verify.py').resolve()), '--repo', str(args.repo.resolve())] + run = subprocess.run(command, capture_output=True) + (case / 'stdout.txt').write_bytes(run.stdout) + (case / 'stderr.txt').write_bytes(run.stderr) + if kind == 'positive': + accepted = run.returncode == 0 and json.loads(run.stdout)['status'] == 'RECORDED_E34_GATES_VERIFIED' + else: + accepted = run.returncode != 0 and b'AssertionError' in run.stderr + results.append({'case': kind, 'expected': 'accept' if kind == 'positive' else 'reject', + 'exit': run.returncode, 'control_passed': accepted, 'command': command}) + print(json.dumps(results[-1]), flush=True) + report = {'verifier': manifest['verifier'], 'archive': manifest['archive'], + 'results': results, 'passed': all(r['control_passed'] for r in results), + 'archived_code_executed': False} + (args.out / 'report.json').write_text(json.dumps(report, indent=2) + '\n', encoding='utf-8', newline='\n') + return 0 if report['passed'] else 1 + + +if __name__ == '__main__': + if not __debug__: + raise SystemExit('Optimized Python is not supported') + sys.exit(main())