Skip to main content

## Module switch

Source
Expand description

Profile switch orchestration, as a plan rather than a procedure.

Switching profiles tears down and rebuilds nearly everything the app holds: the player and its queue, the sync queue drain, the session poller, the lockscreen metadata, the repository handle. The ordering of that teardown is a correctness invariant, not an implementation detail — a straggler that reports after the active user has flipped attributes one account’s viewing to another, which is silent, plausible-looking, and unrecoverable.

So the ordering lives here as a pure function returning a list of steps, and the command layer executes them. That is the only way this gets tested: an end-to-end switch needs two real accounts on a real server, which CI does not have and never will. The plan needs nothing.

Two hazards worth remembering while executing a plan, both already paid for elsewhere in this codebase (see CLAUDE.md): never call a blocking API from a player event callback, and never hold a lock across a `match` scrutinee. A teardown reaches every one of those paths at once, from a new direction.

TRACES: UR-082 | DR-270

## Enums§

SwitchStep
  One executable step of a switch.

## Functions§

plan
  Build the ordered plan for moving from `from` to `to`.