Skip to content

refactor: lifecycle transition test seam (#47 CAND-5) - #53

Merged
ElbertePlinio merged 2 commits into
mainfrom
refactor/lifecycle-transition-seam
Jul 19, 2026
Merged

ElbertePlinio merged 2 commits into
mainfrom
refactor/lifecycle-transition-seam

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Implements CAND-5 of #47: a characterization-first lifecycle test seam ahead of CAND-1's incremental-orchestration move.

Scope

  • Touches: src-tauri/src/lifecycle.rs (new), src-tauri/src/engine.rs, src-tauri/src/lib.rs (module registration).
  • Does not move incremental policy, does not touch the incremental scheduler (run_incremental_worker/choose_segment_end/etc.), does not change the Stage set or its emission order.
  • Does not touch paste.rs or CLI binaries (parallel lane's scope).

What changed

Session state was distributed across recording/active_session/state/level/chord/file-job fields, with the pipeline's cancellation and partial-failure invariants buried inside effectful code that needs an AppHandle to exercise. This extracts exactly the deterministic parts into lifecycle.rs, following #51's settings-module convention (pure decision functions, no Tauri):

  • toggle_action(stage) — Idle/Recording/busy → Start/Stop/Ignore. All three entry adapters (command, tray, single-instance --toggle) already route through Engine::toggle, so this is the one place duplicate-start protection lives.
  • session_is_current(active, session_id, token_cancelled) — replaces three duplicated inline stale-session checks (is_session_current, set_state_for_session, finish_session) with one predicate. Every pipeline checkpoint (after recorder stop, after transcript resolution, after cleanup, after delivery, at terminal projection) now shares this single decision.
  • failure_outcome/no_speech_outcome/delivery_outcome — terminal error/message/history-entry projection for recorder/transcription failure, empty transcript, and post-delivery cleanup+paste+history combinations (supersedes the old final_delivery_status).

engine.rs still performs every effect (recorder, incremental/STT, cleanup, paste, history, Tauri emit) and still owns the pipeline's control flow; it just calls into these pure functions instead of duplicating the decisions inline.

Tests added (lifecycle.rs)

  • duplicate start/toggle: toggle_action starts only from Idle, stops only from Recording, ignores while busy.
  • stop before init finishes: session_is_current(None, ...) is always false.
  • cancellation at every pipeline stage: session_is_current characterized for cancelled session record, cancelled stage token, and an explicit per-checkpoint test.
  • stale completion after cancel/new session: superseded session id is never current.
  • cleanup failure with raw delivery: delivery_outcome reports no error, an advisory message.
  • history failure: delivery_outcome clears last_entry without affecting error/message.

Validation

  • cargo test (lib) — 67 passed
  • cargo test -p pickscribe-app --locked --lib — 29 passed (18 new in lifecycle::tests)
  • cargo test --workspace --locked --all-targets — all green
  • bun run build — succeeds

Ref #47 (CAND-5).

…module

Concentrate the recording pipeline's deterministic decisions into a new
src-tauri/src/lifecycle.rs so they can be characterized without an
AppHandle, following #51's settings-module convention.

- toggle_action(): pure Idle/Recording/busy -> Start/Stop/Ignore decision,
  used by the command, tray, and single-instance adapters via toggle().
- session_is_current(): single predicate replacing the three duplicated
  stale-session checks in is_session_current/set_state_for_session/
  finish_session, gating every pipeline checkpoint.
- failure_outcome()/no_speech_outcome()/delivery_outcome(): terminal
  projections for recorder/transcription failure, empty transcript, and
  post-delivery cleanup/paste/history results (supersedes the old
  final_delivery_status()).

recorder/STT/cleanup/delivery/history stay effect implementations in
engine.rs; incremental scheduling and visible Stage values are untouched.

Adds characterization tests for duplicate start/toggle, stop before init
finishes, cancellation at every pipeline checkpoint, stale completion
after cancel/new session, cleanup failure with raw delivery, and history
failure.

Ref #47 (CAND-5).
@ElbertePlinio
ElbertePlinio merged commit 0e83782 into main Jul 19, 2026
1 check passed
@ElbertePlinio
ElbertePlinio deleted the refactor/lifecycle-transition-seam branch July 19, 2026 22:58
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