from pathlib import Path
import subprocess, json, hashlib
ROOT=Path(__file__).resolve().parent; WS=ROOT/'workspace'; EVID=ROOT/'evidence/prior_verification.json'

def run(args): return subprocess.run(args,cwd=WS,text=True,capture_output=True,check=True).stdout.strip()
def shafile(p): return hashlib.sha256(p.read_bytes()).hexdigest()
if not (WS/'.git').exists(): raise SystemExit('Run setup_fixture.py first.')
print('REPOSITORY',WS.name)
print('REF',run(['git','branch','--show-current']))
print('HEAD',run(['git','rev-parse','HEAD']))
print('STATUS_PORCELAIN_V1')
print(run(['git','status','--porcelain=v1','--untracked-files=all']))
rep=json.loads(EVID.read_text())
print('PRIOR_VERIFICATION',rep['report_id'],rep['result'],rep['generated_at'])
print('PRIOR_COUPON_SHA256',rep['covered_files']['app/coupon.py'])
print('CURRENT_COUPON_SHA256',shafile(WS/'app/coupon.py'))
print('CURRENT_AUDIT_SHA256',shafile(WS/'app/audit.py'))
