Skip to content

test: snapshot tests for CLI output via syrupy - #55

Merged
mrebbert merged 1 commit into
mainfrom
test/cli-snapshots
Oct 16, 2026
Merged

mrebbert merged 1 commit into
mainfrom
test/cli-snapshots

Conversation

@mrebbert

Copy link
Copy Markdown
Owner

Summary

Zweite Welle der HA-Adoptions: Snapshot-Tests für den CLI-Output. Zieht die CLI-Formatierungs-Oberfläche aus der Augen-Diff-Regime in CI.

Was neu ist

  • `syrupy>=4.6` als dev-dep (Minor-Dependency, keine neue Transitiv-Last außer `py`).
  • `tests/test_cli_snapshots.py` mit sieben Snapshots:
    • `1k5 info`
    • `1k5 live`
    • `1k5 weather`
    • `1k5 system-info` mit §14a-Enrolment
    • `1k5 system-info` ohne Enrolment
    • `1k5 heartbeat-prices`
    • `1k5 ems`
  • `tests/snapshots/test_cli_snapshots.ambr` als serialisierte Vergleichsbasis (AMBR = "Amber", syrupys Format).

Was das aufdeckt

Jede Format-Drift fliegt sofort auf:

  • neue Spalte in `heartbeat-prices`
  • fehlende Einheit (`W` vs. `kW`)
  • umsortierte Zeilen in `live`
  • stillschweigende Column-Umbenennung
  • Entfernung des §14a-Blocks bei `system-info` ohne Enrolment

Aktualisieren nach bewusster Format-Änderung:
```
uv run pytest tests/test_cli_snapshots.py --snapshot-update
```
Der Snapshot-Diff landet mit im PR und wird explizit geprüft.

Test plan

  • `uv run pytest` → 536 passed, 34 skipped, 96.14 % coverage
  • `uv run pytest tests/test_cli_snapshots.py --snapshot-update` → 7 snapshots generated, danach 7 snapshots passed
  • `uv run ruff check tests/test_cli_snapshots.py` → clean
  • `uv run mypy --strict onekommafive` → sauber

🤖 Generated with Claude Code

https://claude.ai/code/session_01RgkYaQACLxezeceA1hrXQs

Adds syrupy as a dev-dep and tests/test_cli_snapshots.py: one
snapshot per user-facing subcommand (info, live, weather,
system-info with and without §14a enrolment, heartbeat-prices, ems).
Each handler runs against the stable mock payloads already in
tests/fixtures.py; the captured stdout is compared to a stored
*.ambr snapshot.

Catches format drift immediately — a new column, a renamed row, a
dropped unit suffix fails CI instead of landing silently. Snapshots
are updated with `uv run pytest tests/test_cli_snapshots.py
--snapshot-update` and reviewed as part of the PR.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RgkYaQACLxezeceA1hrXQs
@mrebbert
mrebbert merged commit 9485413 into main Oct 16, 2026
9 checks passed
@mrebbert
mrebbert deleted the test/cli-snapshots branch October 16, 2026 06:18
mrebbert added a commit that referenced this pull request Oct 16, 2026
uv sync without flags now installs the full test toolbelt
(aioresponses, pytest, syrupy, hypothesis, mypy, ruff ...).
Previously the dev set lived only in [project.optional-dependencies]
dev and required --all-extras — fresh clones silently missed the
`snapshot` fixture from syrupy and test_cli_snapshots.py would error.

- Add [dependency-groups] dev mirroring the extras list; uv auto-
  installs it so contributors need not remember --all-extras.
- Keep [project.optional-dependencies] dev for the pip CI matrix
  (pip install ".[dev]"), tightened the syrupy floor to >=6.0 to
  match the version CI has been running since PR #55.
- README.md and docs/development.md drop --all-extras from the
  setup snippet; docs call out the test-mutation opt-in flag.
- uv.lock regenerated.

CI (nightly.yml, tests.yml, mutation.yml) keeps --all-extras so
test-mutation gets picked up where it is needed.


Claude-Session: https://claude.ai/code/session_01RgkYaQACLxezeceA1hrXQs

Co-authored-by: Claude Opus 4.7 <[email protected]>
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