"""Exercise maintenance failure guards without changing authored project files.""" from pathlib import Path import importlib.util, sys, json, contextlib, io sys.dont_write_bytecode=True root=next(p for p in Path(__file__).resolve().parents if (p/'AGENTS.md').is_file()) spec=importlib.util.spec_from_file_location('diagram_index',root/'documents/update-diagram-index.py') module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module) task=root/'work/diagram-audit-2026-11-24/index-check';task.mkdir(exist_ok=True) results=[] def call(*args): sys.argv=['update-diagram-index.py',*args] with contextlib.redirect_stdout(io.StringIO()):module.main() def expect(name, phrase, action): try:action() except ValueError as exc: assert phrase in str(exc),(name,str(exc)) results.append(dict(check=name,result='PASS',diagnostic=str(exc))) else:raise AssertionError(name+' did not fail') original_sources=module.sources def duplicate_sources(): yield from original_sources() yield root/'documents/latex/tkrSoftwareArchitecture.tex', r'\begin{figure}\caption{Duplicate}\label{Figure:AlphaDeployment}\end{figure}' module.sources=duplicate_sources expect('Duplicate active figure label','Duplicate active figure labels',module.inventory) def missing_sources(): yield root/'documents/latex/tkrSoftwareArchitecture.tex', r'\begin{figure}\input{missing-audit-example.tex}\caption{Missing}\label{Figure:Missing}\end{figure}' module.sources=missing_sources expect('Missing editable input','Missing figure asset',module.inventory) module.sources=original_sources original_manifest=module.MANIFEST manifest=json.loads(original_manifest.read_text());manifest['figures'].pop('Figure:AlphaDeployment') test_manifest=task/'manifest.json';test_manifest.write_text(json.dumps(manifest)) module.MANIFEST=test_manifest call('--build-directory',str(task),'--record-sources') expect('Unclassified active figure','Classify new figures',lambda:call('--build-directory',str(task))) module.MANIFEST=original_manifest call('--build-directory',str(task),'--record-sources') snapshot=task/'diagram-source-hashes.json';data=json.loads(snapshot.read_text());data[next(iter(data))]='0'*64;snapshot.write_text(json.dumps(data)) expect('Source edits after build snapshot','Sources changed since the build snapshot',lambda:call('--build-directory',str(task))) (Path(__file__).parent/'index-checks.json').write_text(json.dumps(results,indent=2)+'\n') print('PASS 4 diagram-index maintenance guards; no authored source mutation')