- Add targeted unit tests in tests/unit/services/test_booking_service.py asserting strict boundaries (< vs <=), encroaching buffer intervals, and 48.0h cutoff comparisons - Add naive/aware UTC normalization tests in tests/unit/services/test_timestamps.py - Add calendar prefix state tests and mock/failure sync tests in tests/unit/services/test_calendar.py - Achieve 100% mutmut kill score (253/253 mutants killed, 0 surviving) - Document test taxonomy and mutmut workflow in tests/README.md - Add ADR 0006 documenting mutation testing quality audit gate Refs: #6
2.4 KiB
2.4 KiB
ADR 0006: Mutation Testing & Boundary Hardening for Core Business Logic
Status
Accepted (2026-10-19)
Context
Standard line and branch coverage metrics only verify that code was executed during a test run; they do not verify that the test assertions are strict enough to detect subtle defects.
In armonia-api, two domain invariants carry direct business risks if mutated:
- Mandatory Post-Session Buffer Overlap Math:
- An off-by-one operator error (
<vs\le) or sign change (duration - bufferinstead ofduration + buffer) could either allow double-booking a slot during Jasmin's decompression window or falsely reject a legitimate back-to-back appointment.
- An off-by-one operator error (
- 48-Hour Payment Follow-Up Cutoff:
- A boundary condition mutation (
<vs\le) onhours_until <= thresholdcould exclude consultantes scheduled at the exact threshold boundary, preventing Jasmin's assistant from sending timely WhatsApp follow-ups and allowing ghosted reservations to block inventory.
- A boundary condition mutation (
Decision
- Decouple Pure Domain Logic into
app/services/:- Business arithmetic (buffer collision detection, 48-hour follow-up evaluation, and folio generation) is decoupled from FastAPI route handlers into
app/services/bookings.pyandapp/services/timestamps.py.
- Business arithmetic (buffer collision detection, 48-hour follow-up evaluation, and folio generation) is decoupled from FastAPI route handlers into
- Adopt
mutmutas Quality Audit Gate:- Mutation testing is configured in
pyproject.toml([tool.mutmut]), targetingapp/services/. - The test selection for mutation workers is restricted to isolated unit tests (
pytest_add_cli_args_test_selection = ["tests/unit/services/"]) to avoid SQLite database lock contention (SQLITE_BUSY) during parallel test execution. - All surviving mutants on boundary arithmetic (
<,\le,+,-, and threshold fallbacks) must be eliminated prior to merging PRs alteringapp/services/.
- Mutation testing is configured in
Consequences
Positive
- Guaranteed Boundary Invariants: 100% kill rate achieved on domain functions (
check_slot_collision,evaluate_payment_followup,calculate_hours_until,parse_iso_datetime,compute_calendar_prefix). - Zero Tautological Tests: Unit tests assert exact boundary values (
48.0h,48.01h, adjacent buffer ends) rather than loose status checks. - Fast Execution: Pure unit tests execute in under 0.1 seconds, enabling
mutmutto evaluate 250+ mutants in seconds.
Negative / Trade-offs
- Developers modifying domain logic in
app/services/must runmutmutalongside standardpytestto prevent mutation leaks.