from ops import *
import datetime,re
job='20260926-contextra-provider-runtime-r01'
assert cmd(['git','-C',str(REPO),'rev-parse','HEAD']).strip()=='be680fcef5704a7bab642a151f98713287429b68'
assert not cmd(['git','-C',str(REPO),'diff','--cached','--name-only']).strip()
paths=sorted(set(cmd(['git','-C',str(REPO),'diff','--name-only']).splitlines()+cmd(['git','-C',str(REPO),'ls-files','--others','--exclude-standard']).splitlines()))
assert len(paths)==14
cmd(['git','-C',str(REPO),'diff','--check'])
for p in paths:
    if not p.endswith('.md'):continue
    for target in re.findall(r'\]\(([^)]+)\)',(REPO/p).read_text()):
        if '://' not in target and not target.startswith('#'):assert ((REPO/p).parent/target.split('#')[0]).exists(),target
image=json.loads((HERE/'image-9d6aedaed5.json').read_text())
for p,h in image['hashes'].items():assert hashlib.sha256((REPO/p).read_bytes()).hexdigest()==h
final=json.loads((HERE/'final-state.json').read_text())
assert final['wss'] and final['stopped']==36 and not final['active'] and not final['config_delta']
for phase in ('two-reader','three','mixed'):
    d=json.loads((HERE/(phase+'-result.json')).read_text())
    assert d['result']=='PASS'
    assert all(r['last_cleanup']['completed'] and r['last_cleanup']['child_reaped'] and not r['last_cleanup']['forced'] for r in d['after_stop'])
artifacts=json.loads((HERE/'artifact-evidence-final.json').read_text())
assert len(artifacts)==15 and all(r['state']=='READY' and r['http']==200 and r['delivery']=='SENT' for r in artifacts)
save('verification.json',dict(python='3.12',cpu_batches=[31,22,1,1],overlap=True,
    fixture_redis='isolated Unix socket; container stopped',phases=['two-reader10s','three10s','mixed30.02s'],
    all_normal_cleanup=True,final=final,files=paths,portfolio='MEDIUM user Web acceptance and multi-composite capacity pending'))
receipt=dict(schema_version='ltb1021.codex_hub.report_receipt.v1',receipt_id=job,
 timestamp=datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=9))).isoformat(),
 session_alias='work-session',task='복합 채널 provider process 운영 연결과 개별 Metadata 전송',
 results=['단일 provider 기존 경로와 복합 provider별 child/Decode, 채널 공통 감독/Redis writer 연결',
 '세 Metadata 필드와 provider별 순서/대기 슬롯, provider-local capture 및 기존 공통 Artifact 제한 유지',
 '2/3-provider 및 Medium10 혼합30초 정상 회수, 자연 FIGHT15건 READY/HTTP200'],
 verify=['Python3.12 표적31/22/1/1 PASS(중복 있음), Redis fencing/개별 Frame, CAS/no-op/저장실패/Stop 보호',
 '최종36stopped/WSS연결/4모델READY/Artifact HTTP On, 설정 semantic diff0, Compose image 외 비대상 보존'],
 commits=[],remaining=['혼합Medium 수락47.84FPS 공유부하 저하','실제 브라우저 수용과 FIRE 자연 Event 신규 경로 미확인','다수 복합 채널/장시간 안정성 미검증'])
save('report-receipt.json',receipt)
print(cmd(['codex-report-receipt','--profile','ltb1021','--session-alias','work-session','--receipt',str(HERE/'report-receipt.json')]))
out=Path('/tmp/codex/ltb1021/git-closeout')/job;out.mkdir(mode=0o700)
mf=out/'manifest.json'
args=['codex-git-closeout','prepare','--repository',str(REPO),'--output',str(mf),'--job-id',job,
 '--profile','ltb1021','--session-alias','work-session',
 '--title','feat(runtime): 복합 provider process와 개별 Metadata 운영 연결',
 '--message','Why=복합 채널 내부 대기를 줄이는 process 분리 비교 결과를 실제 Metadata/Event/Artifact 운영 경로로 연결하기로 승인했다.',
 '--message','What=채널 감독자와 fenced writer를 유지하며 provider별 child/Decode와 bounded IPC를 연결했다. 세 Metadata 필드, provider별 sequence/대기 슬롯, capture provenance와 표적 회귀를 추가했다.',
 '--message','Impact=단일 provider는 기존 경로, 복합은 provider process 기본이다. 일반 frame 저장/Active Learning/event_gated 조합은 명시 거부한다. 외부 Event/Artifact 스키마와 공통 상한, 모델/instance/batch/FPS/100ms는 보존한다.',
 '--message','Verify=Python3.12 표적31/22/1/1 PASS(중복), Redis와2/3-provider, Medium10 혼합30초 및 정상 회수. FIGHT15건 READY/HTTP200. 최종36stopped/WSS/4모델READY. Medium 공유부하 저하와 실제 Web/FIRE 자연 Event 수용은 후속이다.',
 '--message','Rollback=이전 image/config와 계측/helper/evidence를 보존한다. 명시 승인 뒤 Stop/reap 및 이전 image/config 검토로 복귀한다. 기존 single-decode flag만으로 전체 계약은 원복되지 않는다.',
 '--verify','Python3.12 targeted31/22/1/1 PASS with overlapping cases; isolated Redis fencing/provider messages; diff/link checks',
 '--verify','GPU 2/3-provider, mixed30.02s, normal Stop/reap, FIGHT15 READY HTTP200;36stopped/WSS/model readiness',
 '--expires-in-seconds','86400']
for p in paths:args+=['--path',p]
print(cmd(args))
batch=out/'batch.json'
print(cmd(['codex-git-closeout','batch-prepare','--output',str(batch),'--batch-id',job,'--profile','ltb1021','--session-alias','work-session','--expected-group-count','1','--repository-label','contextra-analytics','--manifest',str(mf),'--expect-plan-hash',json.loads(mf.read_text())['plan_hash'],'--expires-in-seconds','86400']))
h=json.loads(batch.read_text())['plan_hash']
print(cmd(['codex-git-closeout','batch-plan','--batch-manifest',str(batch),'--expect-batch-plan-hash',h]))
print(cmd(['codex-git-closeout','batch-present','--batch-manifest',str(batch),'--expect-batch-plan-hash',h]))
