"""Offline archive/source/lifetime evidence checks. Screenshots require independent human review.""" from pathlib import Path,PurePosixPath from decimal import Decimal import argparse,hashlib,json,re,zipfile def pin(data):return {'bytes':len(data),'sha256':hashlib.sha256(data).hexdigest()} def main(): parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('directory',type=Path);args=parser.parse_args();root=args.directory.resolve() manifest=json.loads((root/'manifest.json').read_text(encoding='utf-8'));raw=(root/'native-evidence.zip').read_bytes();assert pin(raw)==manifest['archive'],'Archive pin mismatch' with zipfile.ZipFile(root/'native-evidence.zip') as archive: names=archive.namelist();assert len(names)==len(set(names)) and set(names)==set(manifest['members']),'Archive member inventory mismatch' for name in names: p=PurePosixPath(name);assert not p.is_absolute() and '..' not in p.parts and '\\' not in name and ((archive.getinfo(name).external_attr>>16)&0o170000)!=0o120000,'Unsafe member' files={name:archive.read(name) for name in names} for name,data in files.items():assert pin(data)==manifest['members'][name],name assert not any(PurePosixPath(n).suffix.lower() in ('.exe','.dll') for n in files),'Binary bytes unexpectedly included' assert (root/'verify.py').read_bytes()==files['helpers/native-evidence-verify.py'],'External verifier differs from archived exact helper' def js(name):return json.loads(files[name].decode('utf-8-sig')) fixture=js('fixtures/fixture-manifest.json') for name,expected in fixture['files'].items():assert pin(files['fixtures/'+name])==expected,'Fixture pin mismatch' phase_names={'baseline':'baseline.arcadia','messages':'expected-messages.arcadia','messages-and-lanes':'expected-messages-and-lanes.arcadia'} number=rb'[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?' fields=[(rb'(occurrence @alpha_report; \}; send_y )('+number+rb')(;)',Decimal(184)),(rb'(occurrence @gamma_report; \}; send_y )('+number+rb')(;)',Decimal(384)),(rb'(lifeline @intake_lane; x )('+number+rb')(;)',Decimal(172)),(rb'(lifeline @review_lane; x )('+number+rb')(;)',Decimal(432))] def check_source(actual,phase): expected=files['fixtures/'+phase_names[phase]] if phase=='baseline':assert actual==expected,'Baseline source differs';return def section(data): a=b' diagram trial_a ';b=b' diagram trial_b ';assert data.count(a)==data.count(b)==1 start=data.index(a);end=data.index(b);assert start0,'No native capture observations retained') reports.append({'run':run['name'],'reviewer_accepted':run['accepted'],'checks_pass':not problems,'problems':problems,'capture_records':captures}) if run['accepted']:assert not problems,json.dumps(reports[-1],indent=2) old=js('preflight/fixture-preflight-1/result.json') # Retained as history, never promoted to a pass. current=js('preflight/fixture-preflight-2/result.json');assert current['status'].startswith('PASS') and current['cliUnchanged'] is True cp='preflight/fixture-preflight-2/';cr=js(cp+'evidence/result.json');proof=js(cp+'evidence/source-proof.json') assert current['receipt']==proof['result']==pin(files[cp+'evidence/result.json']) and current['proof']==pin(files[cp+'evidence/source-proof.json']) cli=[a for a in cr['artifacts'] if a['cargo']['target']['name']=='arcadia' and not a['cargo']['profile']['test']];assert len(cli)==1 and cli[0]['readback']==current['cli']==manifest['excluded_binary_bytes'][cp+'bin/arcadia.exe'] assert {check['fixture'] for check in current['checks']}==set(fixture['files']) and len(current['checks'])==3,'All three fixture preflights required' assert cr['exitCode']==0 and cr['inputsUnchanged'] is True and current['source']==cr['head']==proof['commit'],'Current CLI closed source binding' for check in current['checks']: name=check['fixture'];assert check['exitCode']==0 and check['json_report'] and check['fixtureUnchanged'] assert pin(files[cp+name+'.stdout.json'])==check['stdout'] and pin(files[cp+name+'.stderr.log'])==check['stderr'] assert pin(files[cp+'fixtures/'+name])==fixture['files'][name] report=js(cp+name+'.stdout.json');assert isinstance(report,dict) and report['operation']=='check' and report['exit_code']==0 and report['written'] is False and not any(d['severity']=='error' for d in report['diagnostics']),'Raw CLI report must independently confirm valid read-only check' print(json.dumps({'status':'PASS offline archive, source and receipt consistency checks','runs':reports,'old_preflight_retained':True,'limitations':['Human visual/interaction claims not inferred from screenshots.','Omitted executable/DLL bytes cannot be rehashed offline.','Build input map/source proof consistency checked; Git blobs not independently available offline.','Failed attempts retained with accepted=false are reported, not silently asserted passing.']},indent=2)) if __name__=='__main__': main()