← back to Ticket System
data/codex-yoloforever/cycle-20260908T1221Z.HzXvuQ/parent-root-fixture-check.py
29 lines
from pathlib import Path
import hashlib,json,subprocess,tempfile,os
BASE=Path(__file__).resolve().parent
patch=(BASE/'ops-root-only-snapshot-exclusions.patch').read_text()
snippet='\n'.join(line[1:] for line in patch.splitlines() if line.startswith('+') and not line.startswith('+++'))+'\n'
paths=json.loads((BASE/'ops-proposal-identities.json').read_text())['paths']
scratch=Path(tempfile.mkdtemp(prefix='parent-root-fixtures-',dir='/private/tmp'))
checks=[]
for root, present in [(True,True),(False,True),(True,False),(False,False)]:
case=('root' if root else 'nested')+('-present' if present else '-absent'); repo=scratch/case;repo.mkdir()
subprocess.run(['git','init','-q',str(repo)],check=True)
keep=['source.txt','rentv-slideshow/renders/other.mp4']
allfiles=keep+(paths if present else [])
for rel in allfiles:
f=repo/rel;f.parent.mkdir(parents=True,exist_ok=True);f.write_text(rel+'\n')
subprocess.run(['git','-C',str(repo),'add','source.txt'],check=True)
real_index=repo/'.git/index';before=hashlib.sha256(real_index.read_bytes()).hexdigest()
trial_index=scratch/(case+'.index')
env={**os.environ,'repo':str(repo),'PROJECTS_DIR':str(repo) if root else str(scratch/'other-root'),'tmpidx':str(trial_index)}
result=subprocess.run(['/bin/bash','-c','set -uo pipefail\n'+snippet],env=env,text=True,capture_output=True)
assert result.returncode==0,(case,result.stderr)
out=subprocess.check_output(['git','-C',str(repo),'ls-files','-z'],env={**os.environ,'GIT_INDEX_FILE':str(trial_index)})
actual=sorted(x.decode() for x in out.split(b'\0') if x);expected=sorted(keep if root else allfiles)
assert actual==expected,(case,actual,expected)
after=hashlib.sha256(real_index.read_bytes()).hexdigest();assert after==before
checks.append({'case':case,'exit':result.returncode,'expected':expected,'actual':actual,'real_index_unchanged':True,'verdict':'PASS'})
record={'intent':'Run actual corrected proposed staging snippet on installed Bash3 with nounset','patch_sha256':hashlib.sha256(patch.encode()).hexdigest(),'scratch':str(scratch),'retained':True,'source_script_run':False,'source_mutations':False,'checks':checks,'verdict':'PASS'}
(BASE/'parent-root-fixture-proof.json').write_text(json.dumps(record,indent=2)+'\n');print(json.dumps(record))