import json,os,subprocess,hashlib
from pathlib import Path
from datetime import datetime
from zoneinfo import ZoneInfo
ROOT=Path(__file__).resolve().parent;REPO=Path('/workspace/contextra-analytics-runtime-lifecycle-refactor');os.umask(0o077)
temp=Path('/tmp/codex/ltb1021/git-closeout/20261101-r5-notification-deploy');temp.mkdir(parents=True,exist_ok=True)
paths=['docs/deployment/SCENARIO_DEMO_COMPATIBILITY.ko.md','docs/integration/FIGHT_R5_WEB_CONFIG.ko.md','docs/profiles/ltb1021/topics/runtime-lifecycle/README.ko.md','docs/profiles/ltb1021/topics/runtime-lifecycle/run/20261101T152102+0900-run-icerti-r5-notification-deployment.md']
receipt=dict(schema_version='ltb1021.codex_hub.report_receipt.v1',receipt_id='20261101-r5-notification-deploy',timestamp=datetime.now(ZoneInfo('Asia/Seoul')).isoformat(),session_alias='work-session',task='아이서티 R5 재무장·재알림 실제 배포 및 camera24 사용자 확인',results=['현장 baseline의5파일 source-only image68823dd031b2 적용,Gateway 복구.','사용자 실행 확인 뒤75초750관측 새Event6건,10.299~14.432초 간격.모두READY/SENT200.','사용자가 새알람·썸네일·클립 모두 정상 확인.배포 유지.',str(ROOT)],verify=['현장 파생image7단위검사 통과,5파일지문 및4모델READY.','camera24 0.25/0.10/cooldown10 보존.사용자 또는 외부camera6/16 score변경은 보존.','git diff --check;운영 무승인 Start0,Web변경0.'],commits=[],remaining=['실제 PostgreSQL 동시성2검사·장시간 안정성·정오탐 일반화 미검증.','camera6 비교와 쓰러짐 개선은 별도 요청 대기.'])
(temp/'receipt.json').write_text(json.dumps(receipt,ensure_ascii=False));(temp/'receipt.json').chmod(0o600)
p=subprocess.run(['codex-report-receipt','--profile','ltb1021','--session-alias','work-session','--receipt',str(temp/'receipt.json')],capture_output=True,text=True);assert p.returncode==0,p.stderr
args=['codex-git-closeout','prepare','--repository',str(REPO),'--output',str(temp/'manifest.json'),'--job-id','20261101-r5-notification-deploy','--profile','ltb1021','--session-alias','work-session']
for path in paths:args+=['--path',path]
args+=['--title','ops(fight): 아이서티 재알림 배포와 camera24 실알람 확인 기록','--message','Why=R5 최초Event 장기잠금 개선을 현장에 반영하고 실제 사용자 연계를 확인한다.','--message','What=최소5파일 source-only 배포 및 Gateway 복구,75초6Event와 사용자 미디어 확인을 기록한다.','--message','Impact=아이서티 전체R5 소스 반영;Web·모델·Tracker·camera6 비교는 변경하지 않는다.','--message','Verify=격리7검사·소스지문·4모델READY·Event6건 READY/SENT200·사용자 정상확인·diff check.','--message','Rollback=기록된 이전image54ce2980ed2b와transaction을 별도 승인/CAS 확인 후 사용하며 현재 사용자 설정은 보존한다.','--verify','source5파일·파생image7검사·readiness PASS','--verify','75초750관측6Event READY/SENT HTTP200 및 사용자 브라우저 정상','--verify','git diff --check PASS']
m=json.loads(subprocess.check_output(args,text=True))
b=json.loads(subprocess.check_output(['codex-git-closeout','batch-prepare','--output',str(temp/'batch.json'),'--batch-id','20261101-r5-notification-deploy','--profile','ltb1021','--session-alias','work-session','--expected-group-count','1','--repository-label','Contextra','--manifest',str(temp/'manifest.json'),'--expect-plan-hash',m['plan_hash']],text=True))
print(subprocess.check_output(['codex-git-closeout','batch-present','--batch-manifest',str(temp/'batch.json'),'--expect-batch-plan-hash',b['plan_hash']],text=True))
print('REPORT_RECEIPT_PASS')
