import json,os,re,subprocess
from pathlib import Path
os.umask(0o077)
R=Path(__file__).parent;repo=Path('/workspace/contextra-analytics-runtime-lifecycle-refactor')
paths=['docs/profiles/ltb1021/topics/runtime-lifecycle/README.ko.md',
       'docs/profiles/ltb1021/topics/runtime-lifecycle/runs/20260911T173053+0900-run-startup-lifespan-diagnostic.md']
def git(*args):return subprocess.check_output(['git','-C',str(repo),*args],text=True).strip()
assert git('rev-parse','HEAD')=='57605e940c31bcd19cc1d3759ee8faaa859b32d6'
assert not git('diff','--cached','--name-only')
assert set(git('diff','--name-only').splitlines())|set(git('ls-files','--others','--exclude-standard').splitlines())==set(paths)
for path in paths:
 text=(repo/path).read_text();assert not re.search(r'192\.168\.\d+\.\d+',text)
 for target in re.findall(r'\]\(([^)]+)\)',text):
  if '://' not in target and not target.startswith('#'):assert ((repo/path).parent/target.split('#')[0]).exists()
subprocess.run(['git','-C',str(repo),'diff','--check'],check=True)
for p in R.iterdir():
 if p.is_file():os.chmod(p,0o600)
args=['/root/.local/bin/codex-git-closeout','prepare','--repository',str(repo),
 '--output',str(R/'git-manifest.json'),'--job-id','ltb1021-startup-diagnostic-20260911',
 '--profile','ltb1021','--session-alias','work-session',
 '--title','docs(runtime): FastAPI startup 중복 경계와 복원 결과 기록',
 '--message','Why=보존 image의 기동 실패를 실제 로그로 확인해 반복 배포 이전에 최소 교정 경계를 정한다.',
 '--message','What=기동1회·Stream0에서 로그와 exit1을 확보하고 설치 FastAPI의 parent event/child lifespan 중복 초기화 경계를 대조했다.',
 '--message','Impact=Owner 문서2개만 변경했다. source/build 변경0이며 Redis/Analytics는 이전 actual 구성으로 복원했다.',
 '--message','Verify=app69개/snapshot/설정 정합 PASS, 로그 수집 self-test PASS, FastAPI startup 실패 근거 확보, 복원 후 healthy/stopped·정책·모델·비대상 보존.',
 '--message','Rollback=진단 Runtime 설정은 복원 완료. 문서 pointer를 이전 상태로 돌릴 수 있고 다음은 앱 단일 lifespan 및 호출 횟수 회귀다.',
 '--verify','static source/config PASS; startup1 stream0; failure logs captured; restore healthy/stopped PASS; exact2 docs validation PASS',
 '--expires-in-seconds','604800']
for p in paths:args+=['--path',p]
subprocess.run(args,check=True)
