Files
ARCADIA-Studio/harness/experiments/analysis-source-s0-s1-windows-20260913/evidence/.local/admit-analysis-source-gate.py
T

76 lines
4.4 KiB
Python

"""Admit the exact fifteen authored S0/S1 tests and their actual executions."""
from pathlib import Path
import hashlib
import json
import re
import subprocess
import sys
base = Path(__file__).resolve().parent.parent
root = base / '.local/analysis-core-worktree-20260911'
folder = base / '.local/analysis-source-gates-20260913'
groups = {
'language::analysis_source::tests::': '''budgets_aggregate_across_fragments_and_latch_numeric_exhaustion
byte_token_frame_logical_and_list_boundaries_have_nearby_successes
every_expression_shape_and_exact_constructor_arity_is_represented
flat_binary_depth_and_malformed_constructor_retain_bounded_completed_children
mixed_precedence_and_grouping_have_independent_expected_child_topology
partial_wide_and_deep_input_cleanup_does_not_poison_a_fresh_parse
public_source_headers_and_existing_numeric_token_controls_are_unchanged
raw_numeric_lexing_preserves_exact_atoms_and_operator_boundaries
repeated_call_argument_occurrences_have_distinct_original_spans
significant_ratio_and_quantity_trivia_preserve_original_spans
unary_literals_precedence_and_comparison_children_keep_distinct_trees'''.splitlines(),
'persistence::source_save_tests::': '''equal_project_from_generated_legacy_source_still_rejects_migration
generated_source_admission_checks_final_newline_under_the_effective_byte_limit
malformed_generated_source_rejects_before_any_filesystem_staging
parseable_source_omitting_a_definition_cannot_replace_the_whole_project'''.splitlines()}
name = sys.argv[1]
assert re.fullmatch(r'[a-zA-Z0-9-]+', name)
path = folder / (name + '.result.json')
record = json.loads(path.read_bytes())
assert record['exit'] == 0 and not record['changed_inputs'] and record['head_after'] == record['source']
assert subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root).decode().strip() == record['source']
inputs_path = folder / record['inputs']
inputs = json.loads(inputs_path.read_bytes())
assert inputs['source'] == record['source']
for item in inputs['inputs']:
raw = (root / item['path']).read_bytes()
assert len(raw) == item['bytes'] and hashlib.sha256(raw).hexdigest() == item['sha256']
assert len(record['artifacts']) == 1
artifact = record['artifacts'][0]
raw = Path(artifact['path']).read_bytes()
assert len(raw) == artifact['bytes'] and hashlib.sha256(raw).hexdigest() == artifact['sha256']
log_path = folder / (name + '.log')
log = log_path.read_text(encoding='utf-8', errors='strict')
if record['command'][-1] == '--list':
names = record['listing_members']
assert len(names) == len(set(names)) == record['listing_count'] == 114
assert re.findall(r'^(\d+) tests, (\d+) benchmarks\s*$', log, re.M) == [('114', '0')]
for prefix, leaves in groups.items():
assert {n for n in names if n.startswith(prefix)} == {prefix + n for n in leaves}
mode, admitted_names = 'list', names
else:
listing_name, selector = sys.argv[2:4]
listing_path = folder / (listing_name + '.result.json')
listing = json.loads(listing_path.read_bytes())
admission = json.loads((folder / (listing_name + '.admission.json')).read_bytes())
assert admission['result_sha256'] == hashlib.sha256(listing_path.read_bytes()).hexdigest()
assert admission['source'] == listing['source'] == record['source']
assert admission['artifact'] == artifact and admission['mode'] == 'list'
assert selector in record['command']
admitted_names = [n for n in listing['listing_members'] if selector in n]
actual = re.findall(r'^test ([^\r\n]+) \.\.\. ok\s*$', log, re.M)
assert admitted_names and len(actual) == len(set(actual)) and set(actual) == set(admitted_names)
assert re.search(rf'test result: ok\. {len(actual)} passed; 0 failed; 0 ignored;', log)
mode = 'focused'
receipt = {'source': record['source'], 'mode': mode, 'artifact': artifact,
'result_sha256': hashlib.sha256(path.read_bytes()).hexdigest(),
'log_sha256': hashlib.sha256(log_path.read_bytes()).hexdigest(),
'inputs_sha256': hashlib.sha256(inputs_path.read_bytes()).hexdigest(),
'verified_inputs': len(inputs['inputs']), 'names': admitted_names,
'admission_helper_sha256': hashlib.sha256(Path(__file__).read_bytes()).hexdigest()}
with (folder / (name + '.admission.json')).open('x', encoding='utf-8', newline='\n') as stream:
stream.write(json.dumps(receipt, indent=2) + '\n')
print(json.dumps({'name': name, 'source': record['source'], 'mode': mode, 'members': len(admitted_names)}))