"""实现不能跑出契约之外(API1):后端暴露的每个接口,openapi.yaml 里都要有同样的路径和方法。 骨架阶段契约里的接口还没全部实现;没实现的列在 api-design §10 的进度里,这里不要求。 """ from __future__ import annotations from pathlib import Path import yaml CONTRACT = Path(__file__).resolve().parents[2] / "docs" / "architecture" / "openapi.yaml" PREFIX = "/api/v1" def test_implemented_endpoints_are_in_contract() -> None: from bid_doctor.app import create_app contract = yaml.safe_load(CONTRACT.read_text(encoding="utf-8"))["paths"] generated = create_app().openapi()["paths"] missing = [] for path, ops in generated.items(): rel = path.removeprefix(PREFIX) for method in ops: if method not in contract.get(rel, {}): missing.append(f"{method.upper()} {rel}") assert not missing, f"这些接口不在 openapi.yaml 里:{missing}"