mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
cb1a110afb
Relocate the playback/queue/transport/audio-output engine out of the type-first
store/ + utils/playback/ + utils/audio/ dirs into a cohesive src/features/playback/,
structure-preserving:
store/<x> -> features/playback/store/<x>
store/audioListenerSetup/<x> -> features/playback/store/audioListenerSetup/<x>
utils/playback/<x> -> features/playback/utils/playback/<x>
utils/audio/<x> -> features/playback/utils/audio/<x>
184 files moved (107 source + 77 tests), 365 consumers rewritten. Pure move — no
behavior change, no state-split (the playerStore state-split stays a separate M5
question). Enabled by this session's decouple seams (artist/offline/orbit/auth →
core registries), so the engine carries no inbound core->feature inversion: store/
now holds only the 50 cross-cutting global stores (auth family, the seams, library
index, UI/settings stores).
KEPT OUT of the move (would re-create global->engine edges): the 3 pure config
helpers utils/audio/{loudnessPreAnalysisSlider,hiResCrossfadeResample} +
utils/playback/autodjOverlapCap (authStore + settings UI read them — they stay in
utils/). Ambiguous view-state stores (eqStore, queueToolbarStore,
playerBarLayoutStore) stay global (no engine imports).
Consumers use DEEP paths (@/features/playback/...), no barrel — matches the lib/
approach and avoids barrel-mock-collapse across the 140 usePlayerStore consumers.
Two tolerated type-only core->feature edges remain (localPlaybackStore->QueueItemRef,
localPlaybackMigration->HotCacheEntry, both erased).
tsc 0, lint 0, full suite 319/2353 green, iron-rule clean (no runtime store->feature
import). Behavior-touching only via the prerequisite bridge seam (already QA-flagged);
the move itself is pure.
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
const { authState, invokeMock } = vi.hoisted(() => ({
|
|
authState: { loggingMode: 'off' as 'off' | 'debug' | string },
|
|
invokeMock: vi.fn(async (_cmd: string, _args?: Record<string, unknown>) => undefined),
|
|
}));
|
|
|
|
vi.mock('@tauri-apps/api/core', () => ({ invoke: invokeMock }));
|
|
vi.mock('@/store/authStore', () => ({ useAuthStore: { getState: () => authState } }));
|
|
|
|
import { emitNormalizationDebug } from '@/features/playback/store/normalizationDebug';
|
|
|
|
beforeEach(() => {
|
|
authState.loggingMode = 'off';
|
|
invokeMock.mockClear();
|
|
invokeMock.mockResolvedValue(undefined);
|
|
});
|
|
|
|
describe('emitNormalizationDebug', () => {
|
|
it('is a no-op when logging mode is not debug', () => {
|
|
emitNormalizationDebug('refresh:start', { trackId: 't1' });
|
|
expect(invokeMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('forwards a JSON payload to frontend_debug_log in debug mode', () => {
|
|
authState.loggingMode = 'debug';
|
|
emitNormalizationDebug('refresh:start', { trackId: 't1' });
|
|
expect(invokeMock).toHaveBeenCalledTimes(1);
|
|
const [cmd, args] = invokeMock.mock.calls[0];
|
|
expect(cmd).toBe('frontend_debug_log');
|
|
expect(args).toMatchObject({
|
|
scope: 'normalization',
|
|
message: JSON.stringify({ step: 'refresh:start', details: { trackId: 't1' } }),
|
|
});
|
|
});
|
|
|
|
it('serializes calls without details too', () => {
|
|
authState.loggingMode = 'debug';
|
|
emitNormalizationDebug('plain-step');
|
|
const args = invokeMock.mock.calls[0][1] as { message: string };
|
|
expect(JSON.parse(args.message)).toEqual({ step: 'plain-step' });
|
|
});
|
|
|
|
it('swallows invoke rejections (best-effort instrumentation)', async () => {
|
|
authState.loggingMode = 'debug';
|
|
invokeMock.mockRejectedValueOnce(new Error('rust busy'));
|
|
expect(() => emitNormalizationDebug('refresh:start')).not.toThrow();
|
|
// Give the rejected promise a tick to settle without throwing.
|
|
await Promise.resolve();
|
|
});
|
|
});
|