test: harden demo bootstrap validation

This commit is contained in:
d-robotics 2026-08-31 21:05:24 +08:00
parent dcdbcfcda3
commit fdeecb3b92
7 changed files with 43 additions and 7 deletions

View File

@ -38,6 +38,8 @@ Do not redesign accepted architecture unless the task explicitly asks for an arc
- Keep scope limited to the task.
- Do not opportunistically implement future tasks.
- Update relevant contracts/docs when behavior changes.
- Add useful code comments/docstrings and record file or behavior changes in the relevant docs/progress log.
- After validation, push and merge the task branch into `main` before starting the next Task ID.
## Before finishing

View File

@ -1,9 +1,10 @@
"""FastAPI application entry point."""
from ekp_core.config import Settings, get_settings
from fastapi import FastAPI
from pydantic import BaseModel
from ekp_core.config import Settings, get_settings
class HealthResponse(BaseModel):
"""Health endpoint response."""

View File

@ -10,3 +10,13 @@ Next: DEMO-002
The full V1 backlog is deferred until the Demo scope is complete. See
`docs/demo/DEMO_SCOPE.md` for the active task sequence.
## Task records
### DEMO-001
- Added the Python 3.12/uv toolchain, dependency lock, FastAPI application,
typed settings, health/OpenAPI endpoints, and runnable Make targets.
- Added deterministic unit, integration, and seed evaluation tests.
- Verified format, lint, strict type checking, tests, dependency lock, API
startup, health response, and versioned OpenAPI output.

View File

@ -33,6 +33,9 @@ line-length = 100
[tool.ruff.lint]
select = ["ASYNC", "B", "E4", "E7", "E9", "F", "I", "UP"]
[tool.ruff.lint.isort]
known-first-party = ["ekp_api", "ekp_core"]
[tool.mypy]
python_version = "3.12"
strict = true

18
tests/conftest.py Normal file
View File

@ -0,0 +1,18 @@
"""Shared pytest fixtures for deterministic test configuration."""
from pathlib import Path
import pytest
from ekp_core.config import Settings
@pytest.fixture
def isolated_settings_environment(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
) -> None:
"""Prevent developer environment variables or .env files from changing tests."""
monkeypatch.chdir(tmp_path)
for field_name in Settings.model_fields:
monkeypatch.delenv(field_name.upper(), raising=False)

View File

@ -1,11 +1,12 @@
"""API startup and health checks."""
from fastapi.testclient import TestClient
from ekp_api.main import create_app
from ekp_core.config import Settings
from fastapi.testclient import TestClient
def test_health_endpoint_uses_supplied_settings() -> None:
def test_health_endpoint_uses_supplied_settings(isolated_settings_environment: None) -> None:
settings = Settings(
app_env="test",
app_name="ekp-test",
@ -22,7 +23,7 @@ def test_health_endpoint_uses_supplied_settings() -> None:
}
def test_openapi_is_versioned() -> None:
def test_openapi_is_versioned(isolated_settings_environment: None) -> None:
settings = Settings(app_env="test")
with TestClient(create_app(settings)) as client:

View File

@ -1,11 +1,12 @@
"""Tests for typed application settings."""
import pytest
from ekp_core.config import Settings
from pydantic import ValidationError
from ekp_core.config import Settings
def test_settings_have_demo_defaults() -> None:
def test_settings_have_demo_defaults(isolated_settings_environment: None) -> None:
settings = Settings()
assert settings.app_env == "development"
@ -13,6 +14,6 @@ def test_settings_have_demo_defaults() -> None:
assert settings.api_port == 8000
def test_settings_reject_invalid_port() -> None:
def test_settings_reject_invalid_port(isolated_settings_environment: None) -> None:
with pytest.raises(ValidationError):
Settings(api_port=0)