"""Chapter 16: confirm that a manifest command field is rejected. Run from the repository root: uv run python content/examples/math/tool-chapters/ch16_invalid_manifest.py """ import json import subprocess import sys from pathlib import Path root = Path(__file__).resolve().parents[3] source = root / "experiments" / "relativity" / "math01.case.json" temp = root / ".ci" / "math01-invalid-command.json" temp.parent.mkdir(parents=True, exist_ok=True) data = json.loads(source.read_text(encoding="utf-8")) data["claims"][0]["checks"][0]["check"]["command"] = ["echo", "hi"] temp.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8") try: result = subprocess.run( [sys.executable, "-m", "math_engine", "case", "validate", str(temp)], cwd=root, text=True, capture_output=True, ) print(result.stdout, end="") print(result.stderr, end="") expected = "Extra inputs are not permitted" in result.stderr print("rejected unknown command field:", result.returncode != 0 and expected) sys.exit(0 if result.returncode != 0 and expected else 1) finally: temp.unlink(missing_ok=True)