import ast,json,os,re,subprocess
from pathlib import Path
os.umask(0o077)
R=Path(__file__).parent;repo=Path('/workspace/contextra-analytics-runtime-lifecycle-refactor')
paths=['app/metadata_storage.py','tests/test_redis_connection_logging.py',
 'docs/profiles/ltb1021/topics/runtime-lifecycle/README.ko.md',
 'docs/profiles/ltb1021/topics/runtime-lifecycle/runs/20260911T171135+0900-run-metadata-auth-image-rollback.md']
def git(*args):return subprocess.check_output(['git','-C',str(repo),*args],text=True).strip()
assert git('rev-parse','HEAD')=='c94d77ef5affe621b5c2861b3e7e7273190d06da'
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()
 if path.endswith('.py'):ast.parse(text)
 else:
  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 path in R.iterdir():
 if path.is_file():os.chmod(path,0o600)
args=['/root/.local/bin/codex-git-closeout','prepare','--repository',str(repo),
 '--output',str(R/'git-manifest.json'),'--job-id','ltb1021-metadata-auth-20260911',
 '--profile','ltb1021','--session-alias','work-session',
 '--title','fix(redis): 접속 로그 비밀정보 제거와 적용 실패 복원 기록',
 '--message','Why=인증 접속 URL의 비밀번호가 로그에 출력되지 않도록 기존 Redis client를 최소 교정한다.',
 '--message','What=성공 URL/실패 예외 원문을 제거하고 fake client 회귀를 추가했다. 실제 ACL 적용·Analytics 기동 실패·복원과 재개점을 Owner에 기록했다.',
 '--message','Impact=source/test와 Owner4개 변경. 새 image는 보존하며 Runtime은 이전 actual 구성으로 복원했다. Stream Start/Stop과 Metadata 시각 검증은 미실행이다.',
 '--message','Verify=source/image 각3 tests PASS, build24초 PASS. Redis 인증/healthcheck 통과 뒤 Analytics exit1, rollback 후 healthy/stopped·정책·모델·비대상 불변 확인. 상세 실패 로그 미확보 한계를 기록했다.',
 '--message','Rollback=로그 교정 commit은 되돌릴 수 있다. 실제 env/Redis/image/포트/방화벽 변경은 이미 복원했고 private 실패 staging은 미적용으로 보존한다.',
 '--verify','source/image each3 tests PASS; build PASS; rollback/readiness/stopped PASS; exact4 syntax/docs/diff PASS; startup cause unresolved',
 '--expires-in-seconds','604800']
for path in paths:args+=['--path',path]
subprocess.run(args,check=True)
