Skip to content

R2: one source of truth for state classification#46

Merged
adyz merged 1 commit into
masterfrom
r2-clasificare-stari
Jul 4, 2026
Merged

R2: one source of truth for state classification#46
adyz merged 1 commit into
masterfrom
r2-clasificare-stari

Conversation

@adyz

@adyz adyz commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Second phase of the post-review refactor plan (plan.md, R2). Zero behavior change — untouched e2e suite 37/37 green, clean typecheck, 62/62 unit (61 old + 1 new), identical build.

The "which states count as loading / error / audible" classification was hand-spelled in four places across main.ts and mediaSession.ts, and the review showed they had already drifted once (commit a667b7f had to edit them when the error-sound semantics changed).

What changed

  • New predicates next to STATE_FX in radioMachine.ts, re-exported through radioCore:
    • isLoadingLike (loading|retrying), isErrorLike (error|recovering), isFeedbackAudible (their union), playbackStateFor (what the OS lock screen should report).
  • mediaSession.ts: the 'pause' action handler, reassertPlaybackState, and updateMediaSession (including the playbackState and position-clear expressions) now all derive from the predicates.
  • main.ts: the player 'pause' listener keeps its exact current set (isLoadingLike(s) || s === 'recovering', deliberately without 'error') — the pre-existing drift is now explicit and commented instead of hidden in a fourth hand-typed list. Whether it's intent or a bug gets decided in R3/R5.
  • New unit test locks the full 7-state classification table, so adding/renaming a machine state forces a conscious decision here instead of a silent fall-through.

Adding a new RadioState now hits: the exhaustive STATE_FX record (compile error), the predicates one line away, and the classification test.

🤖 Generated with Claude Code

From the post-review refactor plan (plan.md, R2). Zero behavior change,
proven by the untouched e2e suite (37/37).

The "which states count as loading / error / audible" classification was
hand-spelled in four places across main.ts and mediaSession.ts and had
already drifted once. It now lives next to STATE_FX in radioMachine.ts:

- isLoadingLike (loading|retrying), isErrorLike (error|recovering),
  isFeedbackAudible (their union), playbackStateFor (what the OS lock
  screen should report) — re-exported through radioCore like the rest of
  the shared surface.
- mediaSession.ts: the 'pause' action handler, reassertPlaybackState and
  updateMediaSession (incl. the playbackState and position-clear
  expressions) all derive from the predicates now.
- main.ts: the player 'pause' listener keeps its EXACT current set
  (isLoadingLike + recovering, deliberately without 'error') — the
  pre-existing drift is now explicit and commented; whether it is intent
  or a bug gets decided in R3/R5, not silently.
- New unit test locks the full 7-state classification table.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
radio Ready Ready Preview, Comment Jul 4, 2026 5:26am

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

CI Summary

Check Status Result
Typecheck PASS tsc --noEmit clean
Unit tests PASS 62/62 passed; Coverage: Lines 99.71%, Branches 92.04%, Functions 97.14%, Statements 99.71%
Build PASS Build completed
Playwright browser PASS Chromium installed
E2E tests PASS 37/37 passed

@adyz adyz merged commit 3224eb1 into master Jul 4, 2026
3 checks passed
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