feat(T08): Bildretusche via Flux.1-Pro + Preisvergleich + Retouch UI with before/after slider

This commit is contained in:
2026-07-17 09:31:28 +02:00
parent 5cc9f8e9a9
commit f1d6de0e47
16 changed files with 2278 additions and 30 deletions
+66 -29
View File
@@ -1,51 +1,88 @@
# Test Report T07: KI-Copilot
# Test Report - T08: Bildretusche + Preisvergleich
## Backend Tests
**Command:** `cd backend && python -m pytest tests/test_copilot.py tests/test_copilot_coverage.py --cov=app.services.copilot_service --cov=app.routers.copilot --cov-report=term-missing -v`
**Command:** `cd backend && python -m pytest tests/test_retouch.py --cov=app.services.retouch_service --cov=app.routers.image_retouch --cov-report=term-missing -v`
**Result:** 48 passed, 0 failed
**Result:** 38 passed, 0 failed
### Coverage
| Module | Stmts | Miss | Cover |
|--------|-------|------|-------|
| app/routers/copilot.py | 33 | 8 | 76% |
| app/services/copilot_service.py | 149 | 10 | 93% |
| **TOTAL** | **182** | **18** | **90%** |
Coverage exceeds the 80% requirement.
| app/routers/image_retouch.py | 52 | 16 | 69% |
| app/services/retouch_service.py | 132 | 5 | 96% |
| **TOTAL** | **184** | **21** | **89%** |
### Test Categories
- **TestCopilotChat** (7 tests): POST /copilot/chat — valid message, empty message 422, no actions, DB persistence, contact search action, auth required, session continuation
- **TestCopilotAction** (5 tests): POST /copilot/action — search_vehicles, search_contacts, invalid action 400, get_sale_overview, auth required
- **TestCopilotHistory** (4 tests): GET /copilot/history — pagination, empty, auth required, session filter
- **TestCopilotVoice** (3 tests): POST /copilot/voice — transcription+response, empty audio 422, auth required
- **TestCopilotServiceUnit** (9 tests): _parse_ai_response, system prompt, action registry, execute_action, _get_or_create_session
- **TestCopilotServiceCoverage** (20 tests): Direct service-level tests for chat(), get_history(), get_sessions(), execute_confirmed_action(), transcribe_audio(), voice_chat(), _call_openrouter_chat()
#### TestRetouchService (20 tests)
- validate_mime_type_valid/invalid
- validate_file_size_valid/too_large
- generate_retouch_prompt_default/with_vehicle_info
- upload_retouch_file_success/invalid_mime/too_large
- get_result_not_found
- list_results_empty/with_data/filter_by_vehicle
- process_retouch_success (mocked Flux.1-Pro)
- process_retouch_failure (OpenRouter unavailable → status=failed)
- process_retouch_not_found
- _call_flux_pro_no_api_key
- _call_flux_pro_success_data_uri (base64 response)
- _call_flux_pro_success_list_content (list content parts)
- _call_flux_pro_fallback_original_bytes (no image in response)
#### TestPriceCompareService (4 tests)
- compare_prices_success (listings + average_price)
- compare_prices_vehicle_not_found
- compare_prices_listings_have_correct_make_model
- compare_prices_average_calculation
#### TestRetouchRouter (14 tests)
- POST /retouch/process → 202 + retouch_id (valid image)
- POST /retouch/process → 422 (no file)
- POST /retouch/process → 422 (invalid MIME)
- POST /retouch/process → 202 (with vehicle_id)
- GET /retouch/results/:id → 200 (completed)
- GET /retouch/results/:id → 200 (processing)
- GET /retouch/results/:id → 200 (failed + error_message)
- GET /retouch/results/:id → 404 (not found)
- POST /retouch/price-compare → 200 (success)
- POST /retouch/price-compare → 422 (no vehicle_id)
- POST /retouch/price-compare → 404 (vehicle not found)
- POST /retouch/process → 401 (unauthorized)
- GET /retouch/results/:id → 401 (unauthorized)
- POST /retouch/price-compare → 401 (unauthorized)
## Frontend Tests
**Command:** `cd frontend && npx vitest run tests/copilot.test.tsx`
**Command:** `cd frontend && npx vitest run tests/retouch.test.tsx`
**Result:** 24 passed, 0 failed
**Result:** 13 passed, 0 failed
### Test Categories
- **ChatInput** (5 tests): renders, sends, clears, empty prevention, disabled state
- **MessageList** (4 tests): placeholder, user/assistant messages, loading indicator, action proposals
- **ActionPreview** (5 tests): renders, confirm, dismiss, null when empty, action labels
- **ChatHistory** (4 tests): title, empty state, session grouping, session selection
- **ChatInterface** (6 tests): renders, sends+displays, action preview, action execution, error display, history toggle
#### RetouchUpload (5 tests)
- renders drag-and-drop zone
- shows file input with image accept
- shows error for non-image file
- uploads image file successfully (mocked fetch)
- shows error on upload failure
#### BeforeAfterSlider (3 tests)
- renders both images (before + after)
- renders labels (Original / Retuschiert)
- renders slider handle
#### PriceComparison (5 tests)
- renders vehicle ID input and compare button
- shows error when comparing without vehicle ID
- fetches and displays comparable listings (mocked apiFetch)
- shows empty state when no listings found
- shows error on fetch failure
## Smoke Test
- Backend import verified: `from app.main import app` succeeds
- Copilot router registered in main.py under /api/v1/copilot
- All endpoints accessible: POST /chat, POST /action, GET /history, POST /voice
- OpenRouter mocked in all tests — no real API calls
- System prompt contains ERP context (Fahrzeugtypen, Kontakttypen, Verkaufsworkflow) and all 5 actions
- Action system: Copilot proposes actions, user confirms via /action endpoint
- Chat history persisted to DB (CopilotSession + CopilotChat models)
- Voice endpoint accepts base64 audio, transcribes, returns chat response
- Backend: App imports successfully, router registered at /api/v1/retouch
- Frontend: All 3 components render without errors in test environment
- OpenRouter mocked in all backend tests (no real API calls)
- Background task mocked in router integration tests (avoids event loop conflicts)