Files
DeepTutor/tests/api/test_docs_surface_export.py
AleFlyX f8c982a181 test: fail when the committed surface artifact drifts from the app
docs/tests/docs_surface.json is generated from the live CLI and FastAPI app,
then committed so the dependency-light doc tests can read it. Nothing
regenerates it on its own, so without a gate it silently becomes a description
of an older application.

This is the failure this repository already has elsewhere: web/contracts/README.md
documents a `--check` drift gate for the frontend contracts, but no workflow
runs it, so web/contracts/schema/openapi.json can disagree with the backend
while CI stays green. Do not repeat that here.

The gate runs the real entry point (`scripts/export_docs_surface.py --check`)
in a subprocess, so it exercises what a developer runs, and surfaces stdout and
stderr with the regenerate command when it fails. It lives in tests/api/
because that directory's tests run in the python-tests job, which has the full
dependency set installed. A second test pins determinism: two renders of the
same live app must be byte-identical.
2026-11-26 21:35:16 +08:00

40 lines
1.3 KiB
Python

"""Freshness gate for the committed docs surface artifact.
``docs/tests/docs_surface.json`` is generated from the real Typer CLI and
FastAPI app by ``scripts/export_docs_surface.py``, then committed so the
dependency-light doc contract tests can read it. Nothing regenerates it on its
own, so without this gate the artifact could silently drift from the code it
claims to describe.
"""
from __future__ import annotations
from pathlib import Path
import subprocess
import sys
from scripts.export_docs_surface import render_surface
ROOT = Path(__file__).resolve().parents[2]
def test_committed_docs_surface_matches_the_live_app() -> None:
result = subprocess.run(
[sys.executable, "scripts/export_docs_surface.py", "--check"],
cwd=ROOT,
capture_output=True,
text=True,
timeout=600,
)
assert result.returncode == 0, (
"docs/tests/docs_surface.json no longer matches the live CLI/API surface. "
"Regenerate it with `python scripts/export_docs_surface.py` and commit the "
f"result.\n--- stdout ---\n{result.stdout}\n--- stderr ---\n{result.stderr}"
)
def test_render_surface_is_deterministic() -> None:
"""Two renders of the same live app must be byte-identical."""
assert render_surface() == render_surface()