mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 01:19:31 +08:00
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.
40 lines
1.3 KiB
Python
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()
|