refactor(player): E.11 — extract two playback-coordination helpers (#574)

Two small file-private helpers move into dedicated modules under
src/store/:

- `waveformRefreshGen.ts` — the per-track generation counter that
  guards against applying a stale waveform read after the cache was
  invalidated. Exposes `bumpWaveformRefreshGen` (existing) +
  `getWaveformRefreshGen` (new accessor that replaces the two direct
  reads at `refreshWaveformForTrack`).
- `hotCacheTouch.ts` — `touchHotCacheOnPlayback` with its empty-id
  guards, called from every `audio_play` entry point.

Both file-private; no caller-side changes outside playerStore's own
imports. 8 focused tests pin the generation-increment + isolation
contract and the touch helper's empty-id guards.

playerStore 3302 → 3291 LOC.
This commit is contained in:
Frank Stellmacher
2026-05-12 14:14:50 +02:00
committed by GitHub
parent 86b13dd4d0
commit ddead24678
5 changed files with 129 additions and 18 deletions
+44
View File
@@ -0,0 +1,44 @@
import { afterEach, describe, expect, it } from 'vitest';
import {
_resetWaveformRefreshGenForTest,
bumpWaveformRefreshGen,
getWaveformRefreshGen,
} from './waveformRefreshGen';
afterEach(() => {
_resetWaveformRefreshGenForTest();
});
describe('waveformRefreshGen', () => {
it('returns 0 for an unknown track', () => {
expect(getWaveformRefreshGen('missing')).toBe(0);
});
it('increments the per-track generation on each bump', () => {
bumpWaveformRefreshGen('t1');
expect(getWaveformRefreshGen('t1')).toBe(1);
bumpWaveformRefreshGen('t1');
expect(getWaveformRefreshGen('t1')).toBe(2);
});
it('keeps tracks independent', () => {
bumpWaveformRefreshGen('a');
bumpWaveformRefreshGen('a');
bumpWaveformRefreshGen('b');
expect(getWaveformRefreshGen('a')).toBe(2);
expect(getWaveformRefreshGen('b')).toBe(1);
});
it('is a no-op for an empty trackId', () => {
bumpWaveformRefreshGen('');
expect(getWaveformRefreshGen('')).toBe(0);
});
it('captures the stale-result guard pattern: a snapshot is invalidated by a later bump', () => {
bumpWaveformRefreshGen('t1');
const snapshot = getWaveformRefreshGen('t1');
expect(snapshot).toBe(1);
bumpWaveformRefreshGen('t1');
expect(getWaveformRefreshGen('t1')).not.toBe(snapshot);
});
});