#!/usr/bin/env python3
import collections,json,pathlib,sys
def check(ok,label):
    if not ok:raise AssertionError(label)
def verify(data):
    check(data['scope']=='fixed-five-row-readonly' and [r['version_key'] for r in data['runs']]==['73','74'],'two runtimes')
    for x in data['runs']:
        r=x['report'];check(x['exit_code']==0 and x['stderr_bytes']==0 and r['status']=='pass','clean success')
        check(r['sample_rows']==5 and r['wide_above_2pow53_samples']==0,'limited actual sample')
        check(r['assertions']==(82 if x['version_key']=='73' else 113),'frozen assertions')
        check(r['business_dml']==r['ddl']==r['http_increment']==0 and not r['cache_enabled'] and not r['global_p0_closed'],'safe limited boundary')
        check(r['metadata_rechecked_equal'] is True,'frozen metadata actual recheck')
        check(r['identity']['extra_decimal_defined'] is False and r['identity']['core_soft']==0 and len(r['identity']['mapped'])==3,'old actual maps')
        check(r['target']['schema_matches'] is True and r['target']['owned_established_loopback_5238_sockets']>=1,'actual target')
        check(r['candidate_sql_sha256']=='04e5f5a264c39e257cc8ebed4ea1c52cc3d807112ad7e21a3f69de8a18880fa5','reviewed five column SQL')
        check(r['truth_sql_sha256']=='69321f12e6a6523703bbc9300b9b95db0d856169e6c6afbaa62fbab55251d4b0','independent text SQL')
        c=collections.Counter(r['actual_sql_sha256']);check(c=={r['candidate_sql_sha256']:8,r['truth_sql_sha256']:1,'37c3f74b06c88f7dd5208fd8cf34e5b45a46e9779c3ea859ad646528622ddea5':1},'exact query count')
        h=r['hydrate'];check(h['status']==('not_supported_php73_typed_business_source' if x['version_key']=='73' else 'pass_actual_php74_model'),'no fake PHP73 ORM')
        check(h['assertions']==(0 if x['version_key']=='73' else 21),'actual hydrate count')
        if x['version_key']=='74':check(len(h['physical_sources'])==3 and h['private_schema_provider_reads']==1,'physical model source/provider')
    a,b=[x['report'] for x in data['runs']]
    check(all(a[k]==b[k] for k in ('raw_native_digest','text_truth_digest','restored_digest')),'same actual read sample')
    return {'status':'pass','php73_assertions':82,'php74_assertions':113,'actual_rows_per_version':5,'actual_wide_samples':0,'business_dml':0,'ddl':0,'http_increment':0,'global_p0_closed':False}
if __name__=='__main__':
    try:print(json.dumps(verify(json.loads(pathlib.Path(sys.argv[1]).read_text())),indent=2))
    except Exception as e:print(json.dumps({'status':'fail','class':type(e).__name__,'reason':str(e)}));raise SystemExit(1)
