mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-21 23:05:46 +00:00
ddead24678
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.
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
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);
|
|
});
|
|
});
|