"""Render the /docs page locally and open it in the default browser. Goes through the real handler code path (vendored Redoc bundle + fonts inlined, breakout guards applied, spec spliced), so the preview is byte-identical to what the Lambda serves, minus the token gate. No AWS credentials or network needed; without a request context the spec keeps its committed fallback server URL. Run from the repo root: `npm run docs:preview` (or `.venv/bin/python scripts/preview_docs.py`). """ import sys import tempfile import webbrowser from pathlib import Path REPO_ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(REPO_ROOT)) from tests.support import load_lambda_module # noqa: E402 def main() -> None: handler = load_lambda_module("api", "handler") html = handler._render_docs_html({}) out = Path(tempfile.gettempdir()) / "procurement-docs-preview.html" out.write_text(html, encoding="utf-8") print(f"wrote {out} ({len(html)} bytes)") webbrowser.open(out.as_uri()) if __name__ == "__main__": main()