Skip to content

Commit b09e689

Browse files
committed
test: 前端路由用例不再依赖本地 web/dist(CI 上产物不存在)
CI 在干净检出上跑:web/dist 是 gitignored 的,原用例断言 200 会拿到 503。 改为 monkeypatch _frontend_dist 指向临时 dist,断言 SPA index.html 被服务, 并已在把 web/dist 移走的条件下本地复现验证。
1 parent ba9a393 commit b09e689

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎tests/test_hardening.py‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,22 @@ def test_unknown_api_path_returns_json_404(client):
401401
assert response.json()["error"]["code"] == "invalid_request"
402402

403403

404-
def test_frontend_routes_still_served(client):
405-
assert client.get("/credentials").status_code == 200
404+
def test_frontend_routes_are_not_treated_as_api_404(client, tmp_path, monkeypatch):
405+
"""前端路由(非 /api、/v1)不进 API 404 分支,走 SPA 兜底。
406+
407+
dist 产物是 gitignored 的(CI 上不存在),因此这里把 dist 指到临时目录,
408+
同时断言「服务了 index.html」而不是「依赖本地构建产物」。
409+
"""
410+
from src import main
411+
412+
dist = tmp_path / "dist"
413+
dist.mkdir()
414+
(dist / "index.html").write_text("<html>spa</html>", encoding="utf-8")
415+
monkeypatch.setattr(main, "_frontend_dist", lambda: dist)
416+
417+
response = client.get("/credentials")
418+
assert response.status_code == 200
419+
assert "spa" in response.text
406420

407421

408422
def test_api_not_found_helper_shape():

0 commit comments

Comments
 (0)