from pathlib import Path import tempfile, shutil, subprocess, json p=Path(__file__).resolve().parent with tempfile.TemporaryDirectory() as t: r=Path(t);dest=r/'research/history/staging';dest.mkdir(parents=True) shutil.copy(p/'owners/history/staging/recon-0830-smooth-aps.md',dest/'recon-0830-smooth-aps.md') shutil.copy(p/'QUESTIONS.md',r/'research/QUESTIONS.md') subprocess.run(['patch','-p1','--batch','-i',str(p/'row24.patch')],cwd=r,check=True,capture_output=True) assert (dest/'recon-0830-smooth-aps.md').read_bytes()==(p/'recon-0830-smooth-aps.revised.md').read_bytes() assert (r/'research/QUESTIONS.md').read_bytes()==(p/'QUESTIONS.revised.md').read_bytes() for n in ['compare.js','qc-questions.js','selection.json']:shutil.copy(p/n,r/n) data=json.loads((p/'owner-inputs.json').read_text());data['history/staging/recon-0830-smooth-aps.md']=(p/'recon-0830-smooth-aps.revised.md').read_text() (r/'owner-inputs.json').write_text(json.dumps(data)) shutil.copy(p/'QUESTIONS.revised.md',r/'QUESTIONS.md') subprocess.run(['node',str(r/'compare.js')],check=True,capture_output=True) print('PASS: patch applies exactly; revised owner regenerates both revised row-24 occurrences; only pre-existing row-15 drift remains')