From 130965636dec025eaa35b94c6e811fb572e369c1 Mon Sep 17 00:00:00 2001 From: Mariusz Banach Date: Wed, 18 Feb 2026 01:18:58 +0100 Subject: [PATCH] MAESTRO: align tests API response with selector --- ...cKit-web-header-analyzer-Phase-04-Test-Selection.md | 2 +- backend/app/routers/tests.py | 9 +++++---- backend/app/schemas/tests.py | 9 +++++++++ backend/tests/api/test_tests_router.py | 10 +++++++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Auto Run Docs/SpecKit-web-header-analyzer-Phase-04-Test-Selection.md b/Auto Run Docs/SpecKit-web-header-analyzer-Phase-04-Test-Selection.md index 9381ad3..6f61dc9 100644 --- a/Auto Run Docs/SpecKit-web-header-analyzer-Phase-04-Test-Selection.md +++ b/Auto Run Docs/SpecKit-web-header-analyzer-Phase-04-Test-Selection.md @@ -31,7 +31,7 @@ This phase implements the test selection panel and analysis configuration contro - [x] `pytest backend/tests/api/test_tests_router.py` passes - [x] `GET /api/tests` returns all 106+ tests with id, name, and category - [x] All vitest tests pass: `npx vitest run src/__tests__/TestSelector.test.tsx src/__tests__/AnalysisControls.test.tsx` -- [ ] Test selector renders all 106+ tests with checkboxes +- [x] Test selector renders all 106+ tests with checkboxes - [ ] Select All / Deselect All buttons work correctly - [ ] Search/filter narrows visible tests by name - [ ] DNS resolution toggle defaults to off diff --git a/backend/app/routers/tests.py b/backend/app/routers/tests.py index c84e3fa..233e68c 100644 --- a/backend/app/routers/tests.py +++ b/backend/app/routers/tests.py @@ -3,13 +3,14 @@ from __future__ import annotations from fastapi import APIRouter from app.engine.scanner_registry import ScannerRegistry -from app.schemas.tests import TestResponse +from app.schemas.tests import TestListResponse, TestResponse router = APIRouter(prefix="/api", tags=["tests"]) -@router.get("/tests", response_model=list[TestResponse]) -def list_tests() -> list[TestResponse]: +@router.get("/tests", response_model=TestListResponse) +def list_tests() -> TestListResponse: registry = ScannerRegistry() tests = registry.list_tests() - return [TestResponse.model_validate(test.model_dump()) for test in tests] + response_tests = [TestResponse.model_validate(test.model_dump()) for test in tests] + return TestListResponse(tests=response_tests, total_count=len(response_tests)) diff --git a/backend/app/schemas/tests.py b/backend/app/schemas/tests.py index cb29e69..d1d2003 100644 --- a/backend/app/schemas/tests.py +++ b/backend/app/schemas/tests.py @@ -1,7 +1,16 @@ from __future__ import annotations +from pydantic import BaseModel, ConfigDict, Field + from app.engine.models import Test class TestResponse(Test): pass + + +class TestListResponse(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + tests: list[TestResponse] + total_count: int = Field(alias="totalCount") diff --git a/backend/tests/api/test_tests_router.py b/backend/tests/api/test_tests_router.py index dfa1291..275ded2 100644 --- a/backend/tests/api/test_tests_router.py +++ b/backend/tests/api/test_tests_router.py @@ -22,9 +22,13 @@ async def test_get_tests_returns_all_registered_tests() -> None: assert response.status_code == 200 payload = response.json() - assert isinstance(payload, list) - assert len(payload) == len(expected_lookup) + assert isinstance(payload, dict) + assert payload["totalCount"] == len(expected_lookup) - response_lookup = {item["id"]: item["name"] for item in payload} + tests_payload = payload["tests"] + assert isinstance(tests_payload, list) + assert len(tests_payload) == len(expected_lookup) + + response_lookup = {item["id"]: item["name"] for item in tests_payload} assert len(response_lookup) == len(expected_lookup) assert response_lookup == expected_lookup