import csv
import hashlib
import json
from pathlib import Path

P=Path(__file__).resolve().parent
main=P.parents[3]/'zhctproject'/'ai_api'
files=[]
for directory in ['app','cores','config','extend','route','vendor']:
    files.extend(p for p in (main/directory).rglob('*') if p.is_file() and not p.name.startswith('._'))
files.extend(main/p for p in ['composer.json','version.json'])
out={str(p.relative_to(main)):hashlib.sha256(p.read_bytes()).hexdigest() for p in sorted(files)}
(P/'source-frozen-sha.json').write_text(json.dumps({'scope':'Current main develop_dameng including Root 0550 Rope service; no slice source changes','files':out},indent=2)+'\n')
cases=json.loads((P/'case-proposal.json').read_text())
paths={r['path'] for r in cases['cases']}
ledger=P.parents[2]/'work/2026-09-28-smart-canteen-dm8-poc/http-cron-coverage-matrix.csv'
rows=[r for r in csv.DictReader(ledger.open()) if r['repo']=='ai_api' and r['route_or_command'] in paths]
assert len(rows)==11 and all(r['mysql_http_or_command']=='not-tested' for r in rows)
(P/'ledger-original.json').write_text(json.dumps(rows,ensure_ascii=False,indent=2)+'\n')
print(json.dumps({'frozen_source_files':len(out),'unmeasured_methods':len(rows),'HTTP':0,'DML':0,'DDL':0}))
