Skip to content

test: named failure-path suite - #56

Merged
mrebbert merged 1 commit into
mainfrom
test/failure-paths
Oct 16, 2026
Merged

mrebbert merged 1 commit into
mainfrom
test/failure-paths

Conversation

@mrebbert

Copy link
Copy Markdown
Owner

Summary

Dritte Welle der HA-Adoptions: Benannte Failure-Path-Suite als dokumentiertes Resilience-Vertrag.

Einzelne Test-Module (test_client.py, test_system.py, …) prüfen heute ihren Happy-Path plus ein paar Negativ-Tests. Diese Datei bündelt die degraded-mode-Garantien, die der SDK Aufrufern macht, als lesbare, zusammenhängende Suite:

Was drin ist

  • `TestErrorHierarchy` — `AuthenticationError` und `RequestError` erben beide von `ApiError`; ein einziger `except ApiError`-Block fängt alles. `ApiError.message` entspricht `str(err)`.
  • `TestTokenRefreshFallback` — `get_token` fällt auf frischen `_login` zurück, wenn `_refresh_token` `AuthenticationError` wirft.
  • `TestRequestFailurePaths` — `_request` wirft `RequestError` mit dem caller-eigenen `error_label` bei 401, 403, 500 und bei `expected_status`-Mismatch; ein nicht-JSON-Body auf 200 surfaced direkt `JSONDecodeError` (Contract-Violation, kein Protocol-Fehler).
  • `TestResourceErrorLabels` — Resource-Methoden propagieren den `RequestError` mit methoden-spezifischem Label (geprüft gegen `System.get_live_overview`).

Warum sinnvoll

Jeder Testklassen-Name dokumentiert die Invariante. Ein brechender Test bedeutet: Vertrag hat sich verschoben, nicht nur Bug. Das ergänzt die Property-Suite (Shape-Robustheit) um die „degraded contract"-Dimension.

Test plan

  • `uv run pytest tests/test_failure_paths.py` → 11 passed
  • `uv run pytest --cov --cov-fail-under=95` → 540 passed, 34 skipped, 96.14 %
  • `uv run ruff check tests/test_failure_paths.py` → clean
  • `uv run mypy --strict onekommafive` → sauber

🤖 Generated with Claude Code

https://claude.ai/code/session_01RgkYaQACLxezeceA1hrXQs

Introduces tests/test_failure_paths.py bundling the degraded-mode
guarantees the SDK makes to callers into one documenting module:

- TestErrorHierarchy: AuthenticationError and RequestError both
  inherit from ApiError, so `except ApiError` catches every error
  the SDK raises; ApiError carries .message plus str() alias.
- TestTokenRefreshFallback: get_token falls back to a fresh login
  when _refresh_token raises AuthenticationError.
- TestRequestFailurePaths: _request raises RequestError with the
  caller-supplied error_label on 401, 403, 500 and on an
  expected_status mismatch; a non-JSON body on a success response
  surfaces the raw JSONDecodeError (contract violation, not protocol
  failure).
- TestResourceErrorLabels: resource methods wrap the underlying
  RequestError with a method-specific label (verified against
  System.get_live_overview).

Each class name documents the invariant; a failing test marks a
contract change, not just a bug.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RgkYaQACLxezeceA1hrXQs
@mrebbert
mrebbert merged commit ac70061 into main Oct 16, 2026
8 checks passed
@mrebbert
mrebbert deleted the test/failure-paths branch October 16, 2026 06:16
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