from pathlib import Path import hashlib,json,re def run(load,check): root=Path(__file__).resolve().parent.parent plan=json.loads((root/'AUDIT_PLAN.json').read_text()) texts={name:(root/'sources'/name).read_text() for name in plan['source_documents']} excerpts=[] for spec in plan['citation_spans']: lines=texts[spec['source']].splitlines();a=spec['start_line'];b=spec['end_line'] assert 1<=a<=b<=len(lines) text='\n'.join(lines[a-1:b]);excerpts.append({**spec,'text':text,'excerpt_sha256':hashlib.sha256(text.encode()).hexdigest()}) check('twenty citation spans fromthree authorized documents',len(excerpts)==20 and {e['source'] for e in excerpts}==set(plan['source_documents'])) search=[] for name,text in texts.items(): lines=text.splitlines() groups={key:[{'line':i+1,'text':line} for i,line in enumerate(lines) if re.search(pattern,line,re.I)] for key,pattern in plan['whole_document_search_patterns'].items()} exact={q:[i+1 for i,line in enumerate(lines) if q.lower() in line.lower()] for q in ['2832','5890','5290','LXX_OFF','600']} search.append({'source':name,'total_lines':len(lines),'candidate_lines':groups,'literal_occurrences':exact,'interpretation':'Search results identify review candidates; absence is not an automated proof about source meaning.'}) f18=texts['File_18.md'];axis=texts['AXIS_REPORT.md'];f09=texts['File_09.md'] check('File18explicitstateidentityguard','A shared date-label, number, span, or tradition does not create identity' in f18) check('File18companionstatesqualified','not six independently attested source states' in f18) check('File09explicitcumulativeShemguard','Do not substitute a regular Shem birth or death state unless a dependency opens it.' in f09) check('File09explicitreplacementdependency','unless the active section states the conversion and dependency.' in f09) check('AXISgeneralcomparisonformulaheld','D_W(b,d)=W-b-d' in axis) check('AXISkeepspriorselectedstatesdistinct','They must not be written as an unconverted equality.' in axis) sp=[] for line in f18.splitlines(): m=re.fullmatch(r'\| G([123]) \| (\d+)/(\d+) \| (\d+)/(\d+) \| (\d+)/(\d+) \| (\d+)/(\d+) \|',line.strip()) if not m:continue g,*v=map(int,m.groups()) if v[4] not in [2991,2993,2995]:continue for k,rail in enumerate(['primary','companion']):sp.append({'gear':g,'rail':rail,'native_Shem_birth':v[4+k],'native_Shem_death':v[6+k],'Terah60_Shem_birth':v[4+k]+60,'Terah60_Shem_death':v[6+k]+60,'native_frame':'minimum215','Cainan':'OFF'}) check('sixSPstatecontrolledpairsparsed',len(sp)==6 and sorted({r['gear'] for r in sp})==[1,2,3]) check('SPqualifiedlifespansremain600',all(r['native_Shem_birth']-r['native_Shem_death']==r['Terah60_Shem_birth']-r['Terah60_Shem_death']==600 for r in sp)) pairs=load('C302_DATA.json')['complete_segments'];lxx=[p for p in pairs if p['profile']=='LXX_OFF'];sphits=[p for p in lxx if p['upper']['regular']['tradition']=='SP'] check('allfiveSPcoversegmentsbindtableand60state',len(sphits)==5 and all(any(r['gear']==p['upper']['regular']['gear'] and r['rail']==p['upper']['regular']['rail'] and r['Terah60_Shem_birth']==p['upper']['regular']['center'] and r['Terah60_Shem_death']==p['lower']['regular']['center'] for r in sp) for p in sphits)) check('MTnormalNoahanchorbindstableplus215','| Noah | 2843 | 1893 | 950 | 500 |' in f18 and 2843+215==3058) check('fixedcrossbridgeoffsetunchanged',12696-8464-(1406-6)==2832) check('retainedpairsbothendpointsrespectfixedoffset',all(p['upper']['cumulative']['BC']-p['upper']['regular']['center']==p['lower']['cumulative']['BC']-p['lower']['regular']['center']==2832 for p in pairs)) fam=load('C310_DATA.json')['families'];families={f['tradition']:f for f in fam} check('retainedminimumcontextcoveridentity',families['MT']['indices']==[0,2] and families['SP']['indices']==[3,4,5,6,7] and families['LXX']['indices']==[3,5,7]) check('retainedscopekeepsmissingindex1',load('C310_DATA.json')['missing_annual_index']==[1]) return {'audit_type':'Bounded source-rule audit; qualitative selection judgment is in the report and reviewer notes.','criteria':plan['criteria'],'excerpts':excerpts,'whole_document_candidate_search':search,'direct_SP_ingredient_reconstruction':sp,'retained_C310_families':fam,'retained_comparison_offset':2832,'new_endpoint_census_performed':False,'prescriptive_rule_search_scope':plan['absence_claim_limit'],'automated_checks_do_not_prove_textual_absence':True}