"""Exercise a real compiler failure without modifying the project manual.""" from pathlib import Path import shutil import subprocess import sys import tempfile import unittest ROOT = Path(__file__).resolve().parents[2] @unittest.skipUnless(shutil.which('latexmk'), 'Requires the pinned TeX image') class CompilerFailureTests(unittest.TestCase): def test_failed_compile_removes_stale_publish_targets(self): with tempfile.TemporaryDirectory() as temp: root = Path(temp) for name in ('documentation/ci/build_manual.py', 'ci/final_project.py'): target = root / name target.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(ROOT / name, target) (root / 'documentation/main.tex').write_text( '\\documentclass{article}\n\\newcommand{\\DocumentVersion}{1.0}\n' '\\begin{document}\n\\UndefinedFinalProjectCommand\n\\end{document}\n') def git(*args): return subprocess.check_output(['git', '-C', str(root), *args], stderr=subprocess.DEVNULL, text=True).strip() git('init'); git('add', '.') git('-c', 'user.name=Fixture', '-c', 'user.email=fixture@localhost', 'commit', '-m', 'Isolated compiler failure fixture') build = root / 'documentation/build' build.mkdir() for name in ('main.pdf', 'build-manifest.json'): (build / name).write_text('stale output') result = subprocess.run([sys.executable, str(root/'documentation/ci/build_manual.py'), '--sha', git('rev-parse', 'HEAD'), '--run-number', '1', '--run-id', '1'], capture_output=True, text=True, timeout=60) self.assertNotEqual(result.returncode, 0) self.assertIn('LaTeX compilation failed', result.stderr) self.assertTrue((build/'main.log').is_file()) self.assertFalse((build/'main.pdf').exists()) self.assertFalse((build/'build-manifest.json').exists())