4.9 KiB
id, title, status, assignee, created_date, updated_date, labels, dependencies, priority
| id | title | status | assignee | created_date | updated_date | labels | dependencies | priority | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TASK-79 | Introduce explicit runtime state transitions and reducers in main | Done |
|
2026-02-18 11:43 | 2026-02-22 00:10 |
|
|
medium |
Description
Main runtime state is currently mutable from many callsites. This task introduces explicit state-transition functions (reducer-like actions) for critical state domains to improve traceability and reduce accidental cross-feature coupling.
Suggestions
- Start with high-risk domains: overlay visibility, MPV connection/session, AniList/Jellyfin runtime status.
- Use action-style transition helpers (
setMediaPath,setOverlayVisibility,setAnilistState) instead of direct field mutation. - Keep transition helpers side-effect free; invoke effects in orchestration layer.
Action Steps
- Inventory direct mutation hotspots in
src/main.tsand runtime modules. - Define state transition API in
src/main/state.tsfor priority domains. - Migrate callsites incrementally to transition helpers.
- Add unit tests for transition behavior and invariant enforcement.
- Add lightweight debug tracing for transition events in debug mode.
- Document state ownership and mutation rules in architecture docs.
Acceptance Criteria
- #1 Critical runtime state domains mutate through explicit transition helpers
- #2 State invariants are test-covered
- #3 Direct ad-hoc mutation in migrated domains is removed
- #4 Ownership/mutation rules documented
Implementation Plan
Implementation plan (writing-plans):
- Add pure reducer-style transition helpers in
src/main/state.tsfor critical AniList domains: client-secret state, retry queue metadata, media-guess runtime state, and tracking in-flight flag. Add focused tests insrc/main/state.test.ts. - Rewire
src/main.tsto use transition helpers instead of direct mutation for migrated domains in runtime deps wiring (buildAnilistStateRuntimeMainDepsHandler, media-guess state deps, retry-update deps, post-watch in-flight setter). - Add/extend invariant tests in
src/main/runtime/anilist-state.test.tsandsrc/main/runtime/anilist-media-state.test.ts(metadata preservation, idempotent reset, scoped-field resets). - Document ownership/mutation rules in
docs/architecture.mdunder composition guidance and run verification gates (bun run build,bun run test:core:src). - Record evidence and AC/DoD progress in TASK-79 notes.
Parallelization: run code-wiring slice and tests/docs slice in parallel subagents where safe, then reconcile and run final gates in the main session.
Detailed step-by-step plan saved at docs/plans/2026-02-21-task-79-runtime-state-reducers.md.
Implementation Notes
2026-02-21: Started implementation pass via writing-plans/executing-plans workflow. Scoping to explicit transition helpers/reducers for critical AniList runtime state domains in src/main.ts/src/main/state.ts, plus invariant tests and architecture ownership rules docs.
Implemented explicit AniList runtime transition helpers/reducers in src/main/state.ts and rewired migrated src/main.ts mutation paths through them (client-secret state, retry queue metadata, media-guess runtime state, in-flight flag).
Added focused reducer tests in src/main/state.test.ts plus invariants coverage updates in src/main/runtime/anilist-state.test.ts and src/main/runtime/anilist-media-state.test.ts.
Documented runtime ownership/mutation rules for migrated domains in docs/architecture.md under Composition Pattern.
Validation evidence: bun test src/main/state.test.ts src/main/runtime/anilist-state.test.ts src/main/runtime/anilist-media-state.test.ts (12 pass), bun run build (pass), bun run test:core:src (219 pass, 6 skip, 0 fail).
Final Summary
Introduced explicit reducer-style runtime transitions for critical AniList state in the main process by adding pure transition helpers in src/main/state.ts and routing migrated writes in src/main.ts through those helpers. Removed ad-hoc direct mutation in migrated domains (client-secret state, retry queue metadata, media-guess runtime state, in-flight flag), added focused and invariant tests, and documented ownership/mutation rules in architecture docs. Validation passed with focused state suites, full build, and core source test lane.
Definition of Done
- #1 Core tests pass after migration
- #2 No behavior regressions in startup/IPC/overlay flows