fix(api): wrap pre-paginated list responses
Server CI/CD / docker-image (push) Failing after 28s
Server CI/CD / deploy-fallback-log (push) Successful in 1s

This commit is contained in:
2026-07-30 21:50:21 +08:00
parent ba947b616b
commit 1d88f8efbe
2 changed files with 71 additions and 21 deletions
+29 -1
View File
@@ -4,7 +4,7 @@ from pathlib import Path
from uuid import uuid4
import pytest
from fastapi import FastAPI
from fastapi import APIRouter, FastAPI, Query
from fastapi.routing import APIRoute
from fastapi.testclient import TestClient
@@ -254,3 +254,31 @@ def test_rest_runtime_consumes_injected_project_context(monkeypatch) -> None:
assert response.json()["items"] == [
{"scheme_name": "burst_case", "scheme_type": "burst_analysis"}
]
def test_rest_runtime_wraps_handler_paginated_list() -> None:
source_router = APIRouter()
@source_router.get("/records", response_model=list[int])
async def list_records(
skip: int = Query(0, ge=0),
limit: int = Query(2, ge=1, le=10),
) -> list[int]:
records = [10, 20, 30, 40]
return records[skip : skip + limit]
app = FastAPI(redirect_slashes=False)
app.include_router(build_rest_router(source_router.routes), prefix="/api/v1")
response = TestClient(app, raise_server_exceptions=False).get(
"/api/v1/records",
params={"skip": 1, "limit": 2},
)
assert response.status_code == 200
assert response.json() == {
"items": [20, 30],
"total": 3,
"limit": 2,
"offset": 1,
}