import json
from pathlib import Path
p=Path(__file__).parent
read=lambda f:json.loads((p/f).read_text())
b,c=[read(f'result-{lane}.json') for lane in 'BC']
for r in (b,c):
    assert r['error'] is None and len(r['cases'])==44 and len(r['owned'])==4
    assert r['cleanup']=={'all_tokens_absent':True,'natural_templates_unchanged':True,'payment_bindings_unchanged':True,'templates_intentionally_retained':4,'stores_intentionally_retained':2,'tripwire_calls':0,'queue_or_user_stub_calls':0}
    assert len({(x['method'],x['path']) for x in r['cases']})==12
    assert all(x.get('complete_source_projection_equal',True) for x in r['cases'])
for x,y in zip(b['cases'],c['cases']):
    assert (x['scenario'],x['method'],x['path'],x['status'])==(y['scenario'],y['method'],y['path'],y['status'])
    assert x['wire_shape']==y['wire_shape']
for lane in 'BC':
    extra=read(f'extra-{lane}.json')
    assert extra['error'] is None and len(extra['cases'])==6 and extra['all_tokens_absent'] and extra['tripwire_calls']==0
    audit=read(f'audit-{lane}.json')
    assert audit['all_passed'] and audit['independent_new_connection'] and audit['business_writes']==0
    assert len(audit['retained_inventory'])==4 and audit['owned_template_binding_references']==0
    cleanup=read('cleanup.json')[lane]
    assert cleanup['worker_stopped'] and cleanup['port_not_listening'] and cleanup['tokens_absent']
    assert cleanup['private_cache_files_remaining']==cleanup['private_runtime_files_remaining']==0
    assert cleanup['templates_retained']==4 and cleanup['stores_retained']==2
w=read('wire-comparison.json')
assert w['passed'] and w['scenario_pairs']==50 and all(x['complete_wire_equal_with_source_owned_id_time_mapping'] for x in w['results'])
print('PASS: 12 distinct actual-method/path entries; 50 HTTP cases each engine; complete source and mapped wire; natural/payment unchanged; four templates/two stores retained each; token/runtime/worker reclaimed')
