Skip to content

test: opt-in mutation testing on numeric hotspots - #58

Merged
mrebbert merged 1 commit into
mainfrom
test/mutmut-hotspots
Oct 16, 2026
Merged

mrebbert merged 1 commit into
mainfrom
test/mutmut-hotspots

Conversation

@mrebbert

Copy link
Copy Markdown
Owner

Summary

Fünfte und letzte Welle der HA-Adoptions. Zweiter Oracle neben der Hypothesis-Property-Suite: mutmut auf den Modulen, bei denen eine stille Zahl-Verschiebung sonst durchrutscht.

Zweck

Property-Tests prüfen Shape (bleibt `raw` intakt, kommt `from_dict` mit random Subsets klar). Mutation-Tests prüfen Logik: Was passiert, wenn mutmut

  • `+` → `-`
  • `>` → `>=`
  • `a - b` → `a + b`
  • einen Konstanten um 1 verschiebt

in den eigentlichen Rechen-Pfaden macht? Jede überlebende Mutation ist eine Lücke in den Assertions.

Scope

Zwei Hotspot-Module:

  • `onekommafive/models/analytics.py` — §14a-Modul-3-Savings, VAT, Heartbeat-Price-Windows, alle numerischen Transforms.
  • `onekommafive/models/prices.py` — `MarketPrices`-Formeln (`_price`, `_ts_field`, Grid-Kosten).

Rest des SDK ist I/O-Glue und Auth — mehr Rauschen als Signal, Laufzeit würde über 20 min klettern.

Was hinzukommt

  • `test-mutation`-Extra in `pyproject.toml` mit `mutmut>=3,<4` (4.x hat Config-Keys erneut umbenannt).
  • `[tool.mutmut]`-Config mit `source_paths`, `also_copy=["onekommafive"]` (sonst crashed pytest auf Import), `pytest_add_cli_args_test_selection=["tests/"]`, `runner="pytest -x -p no:cacheprovider --no-cov"`.
  • `.github/workflows/mutation.yml` als opt-in-Workflow (Push auf main zu den Hotspot-Dateien + manual dispatch), 60 min Timeout, Ergebnis als Artifact + Job-Summary.

Was nicht drin ist

Noch kein harter Baseline-Gate (`.mutmut-baseline` + score-gate-Script, wie HA es hat). Der erste Lauf etabliert die Survivor-Population. Follow-up-PR kann bei Interesse eine Regressions-Schutz-Schranke einziehen.

Keine Secrets

Keine `secrets.*`-Referenz, kein Live-API-Traffic. Alles läuft gegen `aioresponses`-gemockte HTTP.

Test plan

  • YAML-Syntax validiert
  • `uv run pytest --cov --cov-fail-under=95` → 529 passed, 34 skipped, 96.14 %
  • `uv run --with 'mutmut>=3,<4' mutmut --version` → 3.8.0 lädt sauber
  • Erster CI-Lauf nach Merge: via `workflow_dispatch` auslösen, erwartete Laufzeit 10–20 min. Ergebnisliste erst nach dem Lauf sinnvoll zu lesen

🤖 Generated with Claude Code

https://claude.ai/code/session_01RgkYaQACLxezeceA1hrXQs

Hypothesis property tests prove shape robustness. This adds the
other axis: mutmut on the modules where a `+` → `-` or `>` → `>=`
flip would silently return wrong numbers.

- test-mutation extra in pyproject.toml with mutmut 3.x (4.x
  changed config keys again, pinned deliberately).
- [tool.mutmut] targeting analytics.py (§14a Modul-3 savings math,
  VAT, Heartbeat-price windows) and prices.py (MarketPrices numeric
  conversions). I/O glue and auth are intentionally excluded —
  more noise than signal there.
- .github/workflows/mutation.yml opt-in: runs on main pushes that
  touch the hotspot modules or pyproject.toml, plus workflow_dispatch.
  Not a required check for PRs. Results land as an artifact and in
  the job summary.

No baseline-gate yet. The first run establishes the survivor
population; a follow-up PR can bake it into a .mutmut-baseline file
with a score-gate script if we want hard regression protection.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RgkYaQACLxezeceA1hrXQs
@mrebbert
mrebbert force-pushed the test/mutmut-hotspots branch from 5689f67 to 44b2bd6 Compare October 16, 2026 06:17
@mrebbert
mrebbert merged commit 7a7787d into main Oct 16, 2026
9 checks passed
@mrebbert
mrebbert deleted the test/mutmut-hotspots branch October 16, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant