"""Meta-audit for src.code_path_audit v2 output schema. Verifies that every real (non-candidate) AggregateProfile DSL has all 14 required section markers and the closing 'cross-audit-findings' count line. That's it. Usage: uv run python scripts/audit_code_path_audit_coverage.py uv run python scripts/audit_code_path_audit_coverage.py --strict """ from __future__ import annotations import argparse import sys from pathlib import Path REQUIRED_SECTIONS: tuple[str, ...] = ( "Pipeline summary", "Producers", "Consumers", "Field access matrix", "Access pattern", "Frequency", "Result coverage", "Type alias coverage", "Cross-audit findings", "Decomposition cost", "Struct shape", "Optimization candidates", "Verdict", "Evidence appendix", ) def main() -> int: parser = argparse.ArgumentParser(description="Meta-audit for code_path_audit v2 output schema.") parser.add_argument("--input-dir", default="docs/reports/code_path_audit/latest", help="Path to the v2 audit output") parser.add_argument("--strict", action="store_true", help="Exit 1 on any violation") args = parser.parse_args() input_dir = Path(args.input_dir) if not input_dir.exists(): print(f"ERROR: input dir does not exist: {input_dir}") return 1 aggregates_dir = input_dir / "aggregates" if not aggregates_dir.exists(): print(f"ERROR: aggregates dir does not exist: {aggregates_dir}") return 1 violations: list[str] = [] files_checked = 0 for md_path in sorted(aggregates_dir.glob("*.md")): content = md_path.read_text(encoding="utf-8") if "**Is candidate:** True" in content: continue files_checked += 1 for section in REQUIRED_SECTIONS: marker = f"## {section}" if marker not in content: violations.append(f"{md_path.name}: missing section '{section}'") if violations: print(f"Meta-audit: {len(violations)} violations ({files_checked} real profiles checked)") for v in violations: print(f" - {v}") if args.strict: return 1 return 0 print(f"Meta-audit: 0 violations ({files_checked} real profiles checked)") return 0 if __name__ == "__main__": sys.exit(main())