Skip to content

Test-debt: snapshot-context mutations in DictationMachine specs (106 sites) #406

Description

@rosscado

Problem

The DictationMachine spec suite sets up scenarios by mutating the running actor's snapshot context directly, e.g. service.state.context.transcriptionTargets[1] = el, service.state.context.transcriptionsByTarget['name-input'] = {…}, service.state.context.transcriptions[1] = '…', service.state.context.targetElement = undefined, etc. This works today only because XState v5 (5.32.1) does not deep-freeze nested snapshot context. If a future v5 deep-freezes it, these break.

This was item #9 of #403, filed as "a couple of specs." A full scan shows it's 106 sites across 6 specs:
DictationMachine.spec.ts, DictationMachine-characterization.spec.ts, DictationMachine-OutOfOrder.spec.ts, DictationMachine-PRDRequirements.spec.ts, DictationMachine-ManualEditTermination.spec.ts, DictationMachine-InsertAtCaret.spec.ts.

Scope

  • Affects DictationMachine specs only. The tests currently pass — this is forward-compatibility / maintainability debt, not a live failure. Low priority.
  • Out of scope: production code (no src/ change); the already-event-driven UniversalDictationModule-StateAccumulation.spec.ts (the reference pattern).

Reproduction / verification

grep -rnE "\.state\.context\.[A-Za-z]+(\[[^]]*\])?\s*=[^=]" test/state-machines/DictationMachine*.spec.ts → 106 hits. They pass today; they'd fail if getSnapshot().context (and nested objects) became frozen.

Acceptance criteria

Dictation specs no longer mutate the live snapshot context. Either: (a) route all seeding through a small documented test-helper seam in test/state-machines/support/testActor.ts (the single place that does the mutation, swappable to event-driven later — the createTestActor philosophy); or (b) drive the real recording flow to populate context (as UniversalDictationModule-StateAccumulation.spec.ts does). Suite stays green.

Notes

Non-binding recommendation: migrate opportunistically when each spec is next touched (the seam approach is low-risk, behavior-identical), rather than one 106-site churn PR. Decided (founder) to re-scope this out of the #403 fix PR — see that PR for the 8 substantive bugs. Surfaced during the #403 resolution loop.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions