#!/usr/bin/env python3
import json,math
from pathlib import Path
from compare import exact
def compare_cli(b,c):
    for x in (b,c):
        assert x['actual_HTTP_requests_total']==12 and x['named_assertions_total']==72 and x['captured_wire_requests']==6
        assert len(x['actual_runs'])==2 and len(x['wire'])==6 and len({w['scenario'] for w in x['wire']})==6
        for r in x['actual_runs']:
            assert r['stats']['requests']['total']==6 and r['stats']['assertions']['total']==36
            assert r['stats']['assertions']['failed']==0 and r['stats']['steps']['passed']==6 and not r['failures']
        d=x['independent_original_database']
        assert d['actual_DML']==0 and d['actual_SQL_SELECT']>0 and d['tokens_cache_reclaimed'] is True
        assert d['independent_fresh_exact_six_full_original_rows_unchanged'] is True and d['natural_two_full_sha_unchanged'] is True
        for w in x['wire']:
            assert w['method']=='GET' and w['http_status']==200 and w['body']['status']==200
            assert type(w['elapsed_ms']) in (int,float) and math.isfinite(w['elapsed_ms']) and w['elapsed_ms']>0
            assert len(w['named_assertions'])==6 and w['CLI_all_assertions_passed'] is True
    bm={w['scenario']:w for w in b['wire']};cm={w['scenario']:w for w in c['wire']};exact(set(bm),set(cm))
    for s in bm:exact({k:v for k,v in bm[s].items() if k!='elapsed_ms'},{k:v for k,v in cm[s].items() if k!='elapsed_ms'},s)
    return {'native_cli_runs_each_engine':2,'actual_cli_requests_each_engine':12,'named_assertions_each_engine':72,'captured_full_wire_pairs':6,'strict_business_wire_differences':0,'independent_original_DML_each_engine':0,'not_new_unique_API_count':True,'timing_excluded_only_after_positive_finite_validation':True}
if __name__=='__main__':
    p=Path(__file__).parent;print(json.dumps(compare_cli(json.loads((p/'apifox-cli-evidence-B.json').read_text()),json.loads((p/'apifox-cli-evidence-C.json').read_text())),indent=2))
