]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - reports/slice-22u/reproduce.py
examples: explore project work through native Topic Maps (slice 22U)
[topic-maps.git] / reports / slice-22u / reproduce.py
1 #!/usr/bin/env python3
2 """Execute the existing offline collector; audit 22U without original reclassification."""
3 import argparse,datetime,hashlib,importlib.util,json,re,sys
4 from pathlib import Path
5 from urllib.parse import urlparse,unquote
6 sys.dont_write_bytecode=True
7 ROOT=Path(__file__).resolve().parents[2]
8 D=ROOT/'reports/slice-22u';PRIOR=ROOT/'reports/slice-22t/after'
9 BASE='b9517b977fca2105422892a14b4cf9fe9790bbba'
10 ALLOWED={'topic-maps.asd','scripts/fresh-sbcl.lisp'}
11 def read(p):return json.loads(p.read_text())
12 def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
13 def save(p,x):p.write_text(json.dumps(x,ensure_ascii=False,indent=2)+'\n')
14 def audit(out):
15 initial=read(D/'initial-state.json');assert initial['baseCommit']==BASE and initial['initialIndexAndWorktreeClean']
16 protected={p:h for p,h in initial['trackedFileSHA256'].items() if p not in ALLOWED}
17 assert protected=={p:sha(ROOT/p) for p in protected}
18 runs=read(out/'runs.json');assert len(runs['runs'])==119
19 assert runs['executionSourcesSHA256']=={p:sha(ROOT/p) for p in runs['executionSourcesSHA256']}
20 assert runs['rawReportSHA256']=={p:sha(out/p) for p in runs['rawReportSHA256']}
21 for r in runs['runs']:
22 assert r['exitCode']==r['expectedExitCode'] and r['freshProcess']
23 assert r['network']==r['repositoryWrites']==r['hyperdocWrites']=='denied'
24 assert sha(out/(r['label']+'.log'))==r['logSHA256']
25 faults=[]
26 for r in runs['runs']:
27 if '-control-' not in r['label']:continue
28 name=r['label']+'.json';assert (out/name).read_bytes()==(PRIOR/name).read_bytes()
29 assert r['exitCode']==1;faults.append({'label':r['label'],'reportByteIdenticalTo22T':True,'expectedExitCode':1})
30 assert len(faults)==113
31 for name in ['xtm.json','after-diagnostics.json','ctm.validation.json','ctm.cxtm.json','ctm.encoding.json']:
32 assert (out/name).read_bytes()==(PRIOR/name).read_bytes(),name
33 assert len(read(out/'after-diagnostics.json'))==124
34 newrel='retained/core.json.project-work.json';retained=[]
35 for p in (PRIOR/'retained').rglob('*'):
36 if not p.is_file():continue
37 rel=p.relative_to(PRIOR);assert p.read_bytes()==(out/rel).read_bytes(),str(rel)
38 retained.append({'report':str(rel),'SHA256':sha(p)})
39 assert {str(p.relative_to(out)) for p in (out/'retained').rglob('*') if p.is_file()}=={r['report'] for r in retained}|{newrel}
40 prep,oldprep=read(out/'source-preparation.json'),read(PRIOR/'source-preparation.json')
41 assert prep['sources']==oldprep['sources'] and prep['patches']==oldprep['patches']
42 project=read(out/newrel);obs=project['observation'];checks=project['checks']
43 assert len(checks)==len(set(checks))==27 and all(c.startswith('project-work:') for c in checks)
44 assert project['productionChanges'] is False and project['originalRegistrationsAdded']==0
45 isolated=read(D/'isolated.json')['observation']
46 assert all(obs[k]==v for k,v in isolated.items())
47 assert obs['source']==(ROOT/'examples/project-work.ctm').read_text()
48 assert obs['nativeReferencesCurrent'] and obs['sourceUnchanged'] and obs['reparsedOriginalMatchesBefore']
49 before,after=bytes.fromhex(obs['beforeCXTMHex']),bytes.fromhex(obs['afterCXTMHex'])
50 assert len(before)==obs['beforeBytes'] and len(after)==obs['afterBytes'] and before!=after
51 assert next(i for i,(a,b) in enumerate(zip(before,after)) if a!=b)==obs['firstDifferentByteZeroBased']
52 facts=obs['historicalFactsFromNativeItems'];historical=read(PRIOR/'execution.json')
53 assert facts['commitHash']==BASE and facts['sliceStatus']=='abgeschlossen'
54 assert facts['questionStatus']=='offene normative Frage'
55 assert facts['evidenceSummary']==f"{historical['equivalenceReaderPairs']} Reader-Paare, {historical['equivalenceContrasts']} Kontraste, {historical['equivalenceChecks']} Checks."
56 assert historical['acceptancePassed']
57 sources=[]
58 for key in ['questionSource','sliceSource','evidenceDocument']:
59 u=urlparse(facts[key]);assert u.scheme=='file' and not u.netloc and not u.fragment
60 p=Path(unquote(u.path));assert p.is_relative_to(ROOT) and str(p.relative_to(ROOT)) in protected
61 assert sha(p)==protected[str(p.relative_to(ROOT))]
62 sources.append({'nativeFact':key,'IRI':facts[key],'repositorySource':str(p.relative_to(ROOT)),'SHA256':sha(p)})
63 disposition=(ROOT/'docs/slice-22o-qualified-xtm-corpus-disposition.md').read_text()
64 assert 'Offene normative Frage' in disposition and '**Registrierter Status bleibt NOT-RUN.**' in disposition
65 assert facts['disposition']=='NOT-RUN beibehalten; keine normative Zyklussemantik festgelegt.'
66 reg=(out/'regression.log').read_text();previous=read(PRIOR/'execution.json')
67 core=read(ROOT/'reports/slice-22d/baseline/execution.json')['retainedChecks'];assert sum(core.values())==12100
68 for marker,count in dict(core,**previous['stageChecks'],**{'PROJECT-WORK':27}).items():
69 assert int(re.search(r'(?m)^'+marker+r'-PASS: (\d+)',reg).group(1))==count,marker
70 assert 'CTM-XTM-EQUIVALENCE-PASS: 728 checks; 34 actual reader pairs; 4 contrasts; 0 capability gaps.' in reg
71 assert 'Ran 2 tests' in reg and 'NFC-ORACLE-PASS: 16294' in reg
72 assert 'CXML-SUMMARY 146 PASS 0 FAIL' in (out/'xml.log').read_text()
73 assert protected=={p:sha(ROOT/p) for p in protected}
74 (out/'project-before.cxtm').write_bytes(before);(out/'project-after.cxtm').write_bytes(after)
75 (out/'project-before-native.sexp').write_text(obs['beforeNativeView']+'\n')
76 (out/'project-after-native.sexp').write_text(obs['afterNativeView']+'\n')
77 (out/'project-repl.txt').write_text(obs['transcript'])
78 save(out/'failure-controls-audit.json',faults);save(out/'retained-reports.json',retained)
79 save(out/'source-grounding.json',{'historicalFactsReadFromActualNativeItems':facts,'verifiedSources':sources,'historicalExecutionAccepted':True,'newNormativeDecision':False,'canonicalDifferenceZeroBased':obs['firstDifferentByteZeroBased']})
80 save(out/'diagnostic-changes.json',{'observations':124,'changed':0,'registrationsAdded':0,'retargetings':[]})
81 save(out/'integrity.json',{'protectedBaseFilesSHA256':protected,'protectedBaseFileCount':len(protected),'pinnedCorpusFilesVerified':sum(p.startswith('vendor/cxtm/') for p in protected),'historicalReportFilesVerified':sum(p.startswith('reports/') for p in protected),'allProductionSourcesUnchanged':True,'allowedTrackedChanges':sorted(ALLOWED)})
82 save(out/'execution.json',{'kind':'slice-22u-native-project-work-example-not-corpus-registration','baseCommit':BASE,'runtime':'SBCL 2.5.4','startedAtUTC':runs['startedAtUTC'],'finishedAtUTC':runs['finishedAtUTC'],'auditedAtUTC':datetime.datetime.now(datetime.timezone.utc).isoformat(),'runs':runs['runs'],'runCount':119,'faultControls':113,'projectWorkChecks':27,'exampleSourceSHA256':sha(ROOT/'examples/project-work.ctm'),'exampleLispSHA256':sha(ROOT/'examples/project-work.lisp'),'retainedCoreChecks':12100,'standaloneXTMChecks':4327,'equivalenceChecks':728,'equivalencePairs':34,'equivalenceContrasts':4,'xmlQualificationChecks':146,'pythonTests':2,'nfcComparisons':16294,'stageChecks':previous['stageChecks'],'statusesBefore':previous['statusesAfter'],'statusesAfter':previous['statusesAfter'],'all124OriginalDiagnosesUnchanged':True,'originalRegistrationsAdded':0,'retargetings':0,'newProductionAPIs':0,'allRetainedReportsByteIdentical':True,'retainedReportCount':len(retained),'acceptancePassed':True})
83 print(json.dumps({'acceptancePassed':True,'exampleChecks':27,'nativeTopics':obs['TopicCountBeforeAndAfter'],'nativeAssociations':obs['associationCountBeforeAndAfter'],'beforeBytes':len(before),'afterBytes':len(after),'faultControls':113,'statuses':previous['statusesAfter']}),flush=True)
84 def main():
85 ap=argparse.ArgumentParser(description=__doc__);ap.add_argument('--output',type=Path,required=True);ap.add_argument('--audit-only',action='store_true');a=ap.parse_args();out=a.output.resolve();assert not out.is_relative_to(ROOT)
86 if not a.audit_only:
87 spec=importlib.util.spec_from_file_location('retained_collector',D/'collect.py');m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m);m.collect(out)
88 audit(out)
89 if __name__=='__main__':main()