#!/usr/bin/env python3
from pathlib import Path
import json,hashlib,subprocess,sys,datetime
ROOT=Path('/data/video-pipeline/HaTramAudio/project/018-Hon-Uoc-Khong-Duoc-Phep-Yeu');PROVIDER=ROOT/'image/provider';rev=json.loads((ROOT/'work/artwork/left-panel-revision-0002.json').read_text())
def sha(p):
 h=hashlib.sha256()
 with p.open('rb') as f:
  for b in iter(lambda:f.read(8*1024*1024),b''):h.update(b)
 return h.hexdigest()
lock=json.loads((ROOT/'.ownership-lock.json').read_text());assert (lock['project_id'],lock['run_id'],lock['owner'],lock['status'])==(ROOT.name,'run-20260721T040505Z-cd9f944a','zoro','main_session_pipeline')
assert sha(PROVIDER/'intro-poster-provider.png')=='96c15ad4556c1492807b1fecb1d089da524c525ac10abd6662f6879e9c51c7e5';assert sha(PROVIDER/'right-panel-provider.png')=='e3be2f0ce1428f5b3dd408298d91d12b53bd7962e9dd1003b42e37d4bb1ac074';assert sha(PROVIDER/'left-panel-provider-v1-rejected.png')=='78f84ae8b9206d0f242ebdd5f4c3a2681ba9a450e03b606b949d6633a2efa08b'
out=Path(rev['output_path']);assert not out.exists();script=Path.home()/'.hermes/skills/content-creation/tao-anh/scripts/generate_image.py';subprocess.run([sys.executable,str(script),'--prompt',rev['prompt'],'--output',str(out),'--n','1','--size','auto','--quality','auto','--background','auto','--detail','high','--format','png','--model','cx/gpt-5.5-image','--timeout','600'],check=True);assert out.read_bytes()[:8]==b'\x89PNG\r\n\x1a\n';receipt={'schema_version':1,'project_id':ROOT.name,'run_id':'run-20260721T040505Z-cd9f944a','status':'generated_waiting_qa','revision':2,'target_artifact':'left_panel','request_count':1,'provider':'cx/gpt-5.5-image','typography':'provider_only','output_path':str(out),'output_sha256':sha(out),'output_bytes':out.stat().st_size,'reused_artifacts':rev['reuse_passed'],'completed_at':datetime.datetime.now(datetime.timezone.utc).isoformat().replace('+00:00','Z')};(ROOT/'log/artwork-provider-revision-0002.json').write_text(json.dumps(receipt,ensure_ascii=False,indent=2)+'\n');print(json.dumps(receipt))
