feat(api): health endpoints (#108) #114

Merged
timothy merged 4 commits from feat/108-health-api into main 2026-07-03 21:28:13 +02:00
Owner

Summary

Adds GET /api/health so the ChicoryTV SPA shell footer and Dashboard (#109) can show server health. Wraps the existing health-check subsystem (IHealthCheckService.PerformHealthChecks) — same source, filtering and cancellation semantics as the Blazor dashboard on /.

Endpoint

  • GET /api/health (route name GetHealthChecks, group general) → 200 [{title, status, detail, link?}], status ∈ pass|fail|warn|info; NotApplicable checks are filtered out; link is nullable (OpenAPI 3.1 ["null","string"]).

Notes

  • Started from the salvaged WIP commit; rebased onto main (post-#113). Fixed a real bug in the WIP: Option.Match returning null throws LanguageExt ResultIsNullException for every check without a link → MatchUnsafe.
  • Controller matches the #97/#105 parameterless-GET pattern (typed return, Name, [Tags], [EndpointSummary], [EndpointGroupName]).
  • HealthCheckResponseModel introduces file-scoped #nullable enable in ErsatzTV.Core/Api for the genuinely-nullable Link — first DTO there to need it.
  • Each request re-runs all ~14 checks (identical to Blazor per page load; only the warn/error summary is cached) — the SPA should not poll aggressively; noted on #108/#109.
  • OpenAPI regenerated via scripts/update-openapi.sh.

Review

Adversarial review verdict: APPROVE, no blockers/majors. Applied the one minor (unreachable NotApplicable→\"info\" mapper arm now throws instead of silently masking a missing filter). Tests: 278/278 pass (TZ=UTC).

fixes #108

🤖 Generated with Claude Code

## Summary Adds `GET /api/health` so the ChicoryTV SPA shell footer and Dashboard (#109) can show server health. Wraps the existing health-check subsystem (`IHealthCheckService.PerformHealthChecks`) — same source, filtering and cancellation semantics as the Blazor dashboard on `/`. ## Endpoint - `GET /api/health` (route name `GetHealthChecks`, group `general`) → `200 [{title, status, detail, link?}]`, `status` ∈ `pass|fail|warn|info`; `NotApplicable` checks are filtered out; `link` is nullable (OpenAPI 3.1 `["null","string"]`). ## Notes - Started from the salvaged WIP commit; rebased onto main (post-#113). Fixed a real bug in the WIP: `Option.Match` returning `null` throws LanguageExt `ResultIsNullException` for every check without a link → `MatchUnsafe`. - Controller matches the #97/#105 parameterless-GET pattern (typed return, `Name`, `[Tags]`, `[EndpointSummary]`, `[EndpointGroupName]`). - `HealthCheckResponseModel` introduces file-scoped `#nullable enable` in `ErsatzTV.Core/Api` for the genuinely-nullable `Link` — first DTO there to need it. - Each request re-runs all ~14 checks (identical to Blazor per page load; only the warn/error summary is cached) — the SPA should not poll aggressively; noted on #108/#109. - OpenAPI regenerated via `scripts/update-openapi.sh`. ## Review Adversarial review verdict: **APPROVE**, no blockers/majors. Applied the one minor (unreachable `NotApplicable→\"info\"` mapper arm now throws instead of silently masking a missing filter). Tests: 278/278 pass (`TZ=UTC`). fixes #108 🤖 Generated with [Claude Code](https://claude.com/claude-code)
timothy added 4 commits 2026-07-03 21:19:00 +02:00
Untrusted draft — no build/test had run yet. Review before building on it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fix the WIP health-check API slice to match established patterns:

- HealthController: add Name="GetHealthChecks" route name and move
  [EndpointGroupName("general")] to method level, matching
  FillerPresetController/FFmpegProfileController exactly (the
  precedent for parameterless 200-only GET actions).
- HealthCheckResponseModel: enable #nullable for the file and mark
  Link as string? since the mapper can emit null when
  HealthCheckResult.Link is None.
- Mapper: fix a real bug - LanguageExt's Option.Match throws
  ResultIsNullException.ResultIsNull if either branch returns null
  (by design, to catch accidental nulls). The WIP's
  `Link.Match(l => l.Link, () => null)` crashed on every health
  check without a Link. Switch to MatchUnsafe, the LanguageExt-
  sanctioned way to intentionally produce a nullable result from
  Option<T>.
- HealthControllerTests: add the idiomatic-route-assertion test
  (route template + Name) and empty-list case, matching
  FillerPresetControllerTests.

Verified: GetAllHealthCheckResultsForApiHandler already matches the
existing GetAllHealthCheckResultsHandler's cancellation handling
(both swallow TaskCanceledException/OperationCanceledException), so
no change was needed there. Confirmed no OpenApi contract test
enumerates all endpoints for error-response metadata (it's an
explicit TestCase allowlist), so the new GET needed no new entries.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
refactor(api): throw on unmapped health status instead of silent NotApplicable fallthrough (#108)
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 4m23s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 5m27s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
922bec4b24
Review finding: NotApplicable is filtered by the handler before mapping,
so a silent ->"info" arm would only mask a missing filter if the mapper
is ever reused unfiltered.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
timothy merged commit 335a8b8a77 into main 2026-07-03 21:28:13 +02:00
Sign in to join this conversation.