import difflib import hashlib import json from pathlib import Path import re import resource import subprocess import sys import time started = time.monotonic() cpu_started = time.process_time() children_started = resource.getrusage(resource.RUSAGE_CHILDREN) bundle = json.loads(Path(sys.argv[1]).read_text()) destination = Path(sys.argv[2]) destination.mkdir(parents=True, exist_ok=True) docs = bundle['docs'] sha = lambda text: hashlib.sha256(text.encode()).hexdigest() assert all(sha(text) == bundle['sha256'][name] for name, text in docs.items()) def ledger(text): block = re.search(r'', '\n'.join(text.splitlines()[:60])) assert block fields = dict(re.findall(r'^([a-z]+):\s*(.*)$', block[1], re.M)) fields['todo'] = [{'id': x.strip(), 'retired': False} for x in fields.get('todo', 'none').split(',') if x.strip() and x.strip() != 'none'] return fields def index(text): section = text.split('## 2. Every question, by id', 1)[1].split('## 3.', 1)[0] result = {} for line in section.splitlines(): if not line.startswith('| `Q-'): continue cells = [x.strip() for x in re.split(r'(? \{[\s\S]*?\n \};', docs['research/qc/questions.js'])[0] node_source = "const path=require('node:path'), fs=require('node:fs');const records=JSON.parse(fs.readFileSync(0,'utf8'));const byId=new Map();\n" node_source += "for(const r of records){if(!byId.has(r.block.id))byId.set(r.block.id,[]);byId.get(r.block.id).push(r);}\n" node_source += expression + "\nprocess.stdout.write(JSON.stringify([...byId.keys()].sort().map(summarise)));\n" def generated(snapshot): records = [{'file': p, 'block': ledger(snapshot[p])} for p in owners] process = subprocess.run(['node', '-e', node_source], input=json.dumps(records), text=True, capture_output=True, check=True) return {r['id']: {'status': r['status'], 'verdict': r['verdict']} for r in json.loads(process.stdout)} def mismatches(actual, expected): return sorted(identifier for identifier in selected if any(actual[identifier][key] != expected[identifier][key] for key in ['status', 'verdict'])) assert mismatches(generated(docs), before) == [] prereg_path = 'research/history/staging/perfold-window-prereg.md' producer_path = 'research/attack-perfold-02-blindwindow.js' seam_path = 'research/oeis-seam-submission.md' # Re-score the recorded integers against the independently read sealed bands. # This does not run the sieve or refit the predictive model. sealed = {} for line in docs[prereg_path].splitlines(): match = re.match(r'^\s*(\d+)\s+.*?\[(\d+),\s*(\d+)\]\s+\[(\d+),\s*(\d+)\]', line) if match: sealed[int(match[1])] = tuple(map(int, match.groups()[1:])) recorded = {} for line in docs[producer_path].splitlines(): match = re.match(r'^//\s+(\d+)\s+[\d.]+\s+\[(\d+),\s*(\d+)\]\s+\[(\d+),\s*(\d+)\]\s+(\d+)\s+(yes|NO)\s+(yes|NO)', line) if match: p = int(match[1]) bands = tuple(map(int, match.groups()[1:5])) value = int(match[6]) assert bands == sealed[p] in90, in9973 = bands[0] <= value <= bands[1], bands[2] <= value <= bands[3] assert in90 == (match[7] == 'yes') and in9973 == (match[8] == 'yes') recorded[p] = {'value': value, 'in90': in90, 'in9973': in9973} assert len(recorded) == len(sealed) == 37 and set(recorded) == set(sealed) inside90 = sum(r['in90'] for r in recorded.values()) outside9973 = sum(not r['in9973'] for r in recorded.values()) assert (inside90, outside9973) == (33, 0) assert inside90 >= 28 and outside9973 <= 1 missed = sorted(p for p, r in recorded.items() if not r['in90']) assert missed == [107, 113, 137, 257] assert 'A367739' in docs[seam_path].split('**CROSSREFS**')[1].split('**KEYWORD**')[0] assert 'a(21)..a(30)' in docs[seam_path] and 'not a URL' in docs[seam_path] targets = { 'Q-perfold-window': prereg_path, 'Q-oeis-seam-submission': seam_path, } verdicts = { 'Q-perfold-window': 'The preregistered blind window [6.6e10, 6.6e10+2e9) is scored HIT: 33 of 37 folds inside the sealed 90% bands (needed >= 28), 0 outside the 99.73% bands (allowed <= 1), with an independent re-sieve/re-score in redteam-0820-empirical.md section T1.b. The producer is attack-perfold-02-blindwindow.js Stage D; perfold-error-model.md sections 0 and 5 records the outcome. This is finite blind validation of a MEASURED error model, not a derivation, aggregate-law upgrade or twin-prime result.', 'Q-oeis-seam-submission': 'Status DRAFT. The source records twenty DATA terms plus ten further verified terms available for the submitter. CROSSREFS now includes A367739 and A384545, so the old missing-neighbour objection is resolved. Before submission still identifies the LINKS entry as a path rather than a public URL, with the publication moratorium unresolved. No new OEIS absence search or submission is claimed.', } revised = dict(docs) for identifier, path in targets.items(): original = docs[path] assert original.count('verdict:') == 1 changed = re.sub(r'^verdict:.*$', 'verdict: ' + verdicts[identifier], original, count=1, flags=re.M) if identifier == 'Q-perfold-window': assert ledger(original)['status'] == 'OPEN' changed = re.sub(r'^status: OPEN$', 'status: ANSWERED', changed, count=1, flags=re.M) assert original.split('-->', 1)[1] == changed.split('-->', 1)[1] revised[path] = changed expected = generated(revised) lines = [] changes = 0 for line in registry.splitlines(keepends=True): identifier = next((i for i in targets if '`' + i + '`' in line), None) if identifier and line.startswith('| `Q-'): cells = [c.strip() for c in re.split(r'(?