test: close coverage gaps and add frontend test infrastructure

Backend (516 tests, 94% coverage):
- Add azure_openai endpoint/deployment validation tests (config.py -> 100%)
- Add _total_conversations and _avg_turns direct tests (queries.py -> 100%)
- Add transformer edge cases: list content, string checkpoint, invalid JSON,
  malformed message graceful skip (transformer.py -> 93%)
- Add safety combined status_code+error_message interaction tests
- Fix ambiguous 200/422 assertion to strict 422
- Add E2E pagination shape assertions (total, page, per_page, row count)
- Fix ReplayPool mock to respect LIMIT/OFFSET params

Frontend (23 tests, vitest + happy-dom + @testing-library/react):
- Add vitest infrastructure with happy-dom environment
- Add api.ts tests: success, HTTP error, success=false, URL encoding
- Add DashboardPage tests: loading, data, error, empty states
- Add ReplayListPage tests: loading, empty, data, error, status badge classes
- Add ReplayPage tests: loading, steps, empty, error states
This commit is contained in:
Yaojia Wang
2026-04-06 13:32:10 +02:00
parent 036e12349d
commit 19fc9f3289
15 changed files with 1270 additions and 7 deletions

View File

@@ -158,6 +158,42 @@ class TestInterruptStatsQuery:
assert result.expired == 0
class TestTotalConversations:
@pytest.mark.asyncio
async def test_returns_count(self) -> None:
from app.analytics.queries import _total_conversations
pool = _make_pool_with_fetchone({"total": 42})
result = await _total_conversations(pool, range_days=7)
assert result == 42
@pytest.mark.asyncio
async def test_zero_state_returns_zero(self) -> None:
from app.analytics.queries import _total_conversations
pool = _make_pool_with_fetchone(None)
result = await _total_conversations(pool, range_days=7)
assert result == 0
class TestAvgTurns:
@pytest.mark.asyncio
async def test_returns_float(self) -> None:
from app.analytics.queries import _avg_turns
pool = _make_pool_with_fetchone({"avg_turns": 3.5})
result = await _avg_turns(pool, range_days=7)
assert result == 3.5
@pytest.mark.asyncio
async def test_zero_state_returns_zero(self) -> None:
from app.analytics.queries import _avg_turns
pool = _make_pool_with_fetchone(None)
result = await _avg_turns(pool, range_days=7)
assert result == 0.0
class TestGetAnalytics:
@pytest.mark.asyncio
async def test_returns_analytics_result(self) -> None: