"""Verify that the repository documentation is complete and self-contained.""" from pathlib import Path import re import sys from urllib.parse import unquote, urlsplit ROOT = Path(__file__).resolve().parent.parent REQUIRED_DOCS = ( "README.md", "docs/requirements.md", "docs/architecture.md", "docs/ai-providers.md", "docs/deployment.md", "docs/verification.md", ) LINK = re.compile(r"\]\(([^\s)]+)\)") def documentation_errors(): for relative_path in REQUIRED_DOCS: document = ROOT / relative_path if not document.is_file(): yield f"{relative_path}: required document is missing" continue contents = document.read_text(encoding="utf-8") if not contents.startswith("# "): yield f"{relative_path}: expected a top-level heading" for link in LINK.findall(contents): url = urlsplit(link) if url.scheme or url.netloc or not url.path: continue target = (document.parent / unquote(url.path)).resolve() if not target.is_relative_to(ROOT): yield f"{relative_path}: link leaves the repository ({link})" elif not target.exists(): yield f"{relative_path}: link target is missing ({link})" def main(): errors = list(documentation_errors()) if errors: for error in errors: print(error, file=sys.stderr) return 1 print(f"Verified {len(REQUIRED_DOCS)} project documents.") return 0 if __name__ == "__main__": sys.exit(main())