import csv,hashlib,json
from compare import ROOT,verify
from sql_audit import audit
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
r=verify();s=audit();(ROOT/'comparison.json').write_text(json.dumps(r,ensure_ascii=False,indent=2)+'\n');(ROOT/'sql-audit.json').write_text(json.dumps(s,indent=2)+'\n')
with (ROOT/'interface-ledger.csv').open('w',newline='') as f:
 w=csv.writer(f);w.writerow(['repo','method','path','status','business_evidence','limits'])
 for module in ('store','terminal'):
  for path in ('Home/data','statistics.Data/data','statistics.Data/survey','order.Export/list'):w.writerow(['ai_api','GET','/'+module+'/'+path,'dual_business_partial','real own nonempty count/ranking/export record, full physical source and recursive DTO, SQL and scope audit','synthetic zero money only; no active User ranking/nonzero transaction/payment/fulfillment/actual export/download/performance'])
fixes={'app/'+m+'/service/statistics/data/GoodsRanking.php':sha(ROOT/(m+'GoodsRankingTextCandidate.php')) for m in ('store','terminal')}
m={'status':'COMPLETE_SEALED_ROOT_REVIEW','interfaces':8,'HTTP':{'B':10,'C':12,'total':22},'native_assertions':88,'original_C_SQL_reds':2,'intermediate_C_SUM_type_red_responses':2,'intermediate_C_SUM_type_red_leaves':4,'full_original_DTO_passes':18,'complete_BC_positive_pairs':8,'B_original_body_unchanged':2,'business_fix_files':fixes,'SQL_evidence_layer':'framework Db::listen debug interpolation; compiler0PDO0SQL structure; independent PDO original physical effect and readonly literal diagnostics separately','SQL':s,'raw_remote_each_lane':'/tmp/cdx-ai-dashboard-export-read8-20261011/private/evidence','raw_ignored_local':str(ROOT/'private-evidence'),'raw':{lane:{p.name:{'sha256':sha(p),'bytes':p.stat().st_size} for p in sorted((ROOT/'private-evidence'/lane).glob('*')) if p.is_file()} for lane in ('B','C')},'cleanup':{lane:json.loads((ROOT/f'resource-cleanup-{lane}.json').read_text()) for lane in ('B','C')},'open_limits':['general wide-P0 and aggregate backend range','nonempty active UserExpendRanking','nonzero business sale/recharge totals','real payment/fulfillment/timer','real export/file/download','Order.getListAll','representative performance/pressure'],'files':{p.name:sha(p) for p in sorted(ROOT.iterdir()) if p.is_file() and p.name not in ('manifest.json','MANIFEST.sha256')}}
(ROOT/'manifest.json').write_text(json.dumps(m,ensure_ascii=False,indent=2)+'\n');(ROOT/'MANIFEST.sha256').write_text(''.join(f'{sha(p)}  {p.name}\n' for p in sorted(ROOT.iterdir()) if p.is_file() and p.name!='MANIFEST.sha256'));print(json.dumps({'interfaces':8,'HTTP':22,'native_assertions':88,'full_BC_pairs':8,'sealed_artifacts':len(m['files'])+1}))
