ESP-IDF CI / Host Tests (Unity) (push) Successful in 1m8s
CI / firmware-native (push) Successful in 2m57s
Rust Protection Tests / Cargo test (host) (push) Failing after 3m21s
ESP-IDF CI / ESP-IDF Build (v5.4) (push) Failing after 6m55s
ESP-IDF CI / Memory Budget Gate (push) Has been skipped
qa-cicd-environments / qa-kxkm-s3-build (push) Successful in 8m53s
qa-cicd-environments / qa-sim-host (push) Successful in 2m2s
qa-cicd-environments / qa-kxkm-s3-memory-budget (push) Successful in 11m17s
Context: the project archive (KXKM_Batterie_Parallelator-main) had no git history locally; a fresh repository is needed to host it on git.saillant.cc (electron/KXKM_Batterie_Parallelator). Approach: initialize a new repo on branch main, stage the archive content, and harden .gitignore before the first commit. Changes: - Import the full project tree: firmware/, firmware-idf/, firmware-rs/, iosApp/, kxkm-bmu-app/, kxkm-api/, hardware/, docs/, specs/, scripts/, models/, tests/ - Keep project dotfiles tracked despite the trailing '.*' ignore rule: .github/, .claude/, .superpowers/, .gitattributes, .markdownlint.json - Extend .gitignore: firmware/src/credentials.h (local secrets, template kept), kxkm-bmu-app/**/build/ (66 MB compiled iOS framework), .remember/ (session data) Impact: the project can now be maintained on the self-hosted Gitea forge with a clean, secret-free initial history.
73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
"""Unit tests for diagnostic API response format and validation."""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "services" / "soh-llm"))
|
|
|
|
|
|
class TestDiagnosticResponseFormat:
|
|
"""Verify API response schema matches spec."""
|
|
|
|
def test_diagnostic_response_fields(self):
|
|
from diagnostic_api import DiagnosticResponse
|
|
|
|
resp = DiagnosticResponse(
|
|
battery=3,
|
|
diagnostic="Batterie en bon état.",
|
|
severity="info",
|
|
generated_at=1743678000,
|
|
)
|
|
assert resp.battery == 3
|
|
assert resp.severity == "info"
|
|
assert resp.generated_at == 1743678000
|
|
|
|
def test_diagnostic_response_rejects_invalid_severity_type(self):
|
|
from diagnostic_api import DiagnosticResponse
|
|
|
|
# severity is a str field — Pydantic accepts any string
|
|
# Actual validation happens in extract_severity()
|
|
resp = DiagnosticResponse(
|
|
battery=0,
|
|
diagnostic="Test",
|
|
severity="unknown",
|
|
generated_at=0,
|
|
)
|
|
assert resp.severity == "unknown"
|
|
|
|
def test_fleet_response_fields(self):
|
|
from diagnostic_api import FleetDiagnosticResponse
|
|
|
|
resp = FleetDiagnosticResponse(
|
|
diagnostic="Flotte en bon état global.",
|
|
severity="info",
|
|
generated_at=1743678000,
|
|
num_batteries=16,
|
|
)
|
|
assert resp.num_batteries == 16
|
|
|
|
def test_health_response_fields(self):
|
|
from diagnostic_api import HealthResponse
|
|
|
|
resp = HealthResponse(
|
|
status="ok",
|
|
model_loaded=True,
|
|
cache_size=5,
|
|
uptime_s=120.5,
|
|
)
|
|
assert resp.model_loaded is True
|
|
|
|
|
|
class TestCacheLogic:
|
|
"""Verify cache behavior without loading actual model."""
|
|
|
|
def test_cache_miss_returns_404(self):
|
|
"""GET /api/diagnostic/{id} with empty cache should 404."""
|
|
from diagnostic_api import _cache
|
|
_cache.clear()
|
|
# Cache is empty, battery 99 not present
|
|
assert 99 not in _cache
|