feat(gateway): X-API-Deprecated header for legacy /api/* paths (Stage 1 PR5)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1445043649
2026-06-28 19:37:36 +08:00
parent 9d6decd91b
commit 3f0d5c8c96
3 changed files with 81 additions and 0 deletions
@@ -0,0 +1,46 @@
"""Deprecation header tests (Stage 1 PR5)."""
from __future__ import annotations
from starlette.testclient import TestClient
def _make_app():
from fastapi import FastAPI
from app.gateway.deprecation_middleware import ApiDeprecationMiddleware
app = FastAPI()
app.add_middleware(ApiDeprecationMiddleware)
@app.get("/api/threads")
async def legacy():
return {"ok": True}
@app.get("/api/v1/threads")
async def versioned():
return {"ok": True}
@app.get("/api/langgraph/info")
async def lg():
return {"ok": True}
return app
def test_legacy_path_gets_deprecation_header():
client = TestClient(_make_app())
r = client.get("/api/threads")
assert r.headers.get("X-API-Deprecated") == "2027-01-01"
def test_versioned_path_no_header():
client = TestClient(_make_app())
r = client.get("/api/v1/threads")
assert "X-API-Deprecated" not in r.headers
def test_langgraph_path_no_header():
client = TestClient(_make_app())
r = client.get("/api/langgraph/info")
assert "X-API-Deprecated" not in r.headers