#!/usr/bin/env python3
"""Run each authorized scenario serially, preserving its raw PNG frames and logs."""
import json,subprocess,sys
from pathlib import Path
scripts=Path('/tmp/lead-28684-r1/evidence-capture-2')
root=scripts/'2026-11-02T22-50-00Z'
side=sys.argv[1]
for scenario in sys.argv[2:]:
 log=root/f'{side}-{scenario}.log'
 with log.open('w') as out:
  p=subprocess.run(['node',str(scripts/'capture-driver.mjs'),side,scenario,'10'],stdout=out,stderr=subprocess.STDOUT)
 if p.returncode:print(log.read_text()[-8000:],flush=True);sys.exit(p.returncode)
 result=json.loads(log.read_text().splitlines()[-1]);run=Path(result['run'])
 print(result,flush=True)
 with (run/'encoding.log').open('w') as out:
  p=subprocess.run(['python3',str(scripts/'encode-verify.py'),str(run)],stdout=out,stderr=subprocess.STDOUT)
 print((run/'encoding.log').read_text(),flush=True)
 if p.returncode:sys.exit(p.returncode)
