mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-10 04:46:07 -08:00
* refactor(main): build overlay geometry and pointer interaction in the overlay assembly Inject Electron's screen (and the stats-window promotion) into the overlay geometry and visible-overlay interaction runtimes so they load under bun test, then construct both in createOverlayAssembly together with the overlay visibility composer and the mpv subtitle suppression handlers. Replace the three regex tests that pinned the moved Linux input and shape code with behaviour tests on the runtimes. * refactor(main): move the autoplay-ready gate into the playback assembly The autoplay-ready gate, its post-warm subtitle prime, the current-media tokenization gate and managed local subtitle selection all read playback state, and playback signals through the gate, so createPlaybackAssembly now builds them. The overlay reaches the gate through a getter. Replace the last four regex guards with behaviour tests: the gate holds the release until the visible overlay has measured the line and ignores untokenized lines during warmup (playback), cached autoplay priming never paints raw first and the sidebar media path is tagged only after prefetch loads (priming runtime), and dashboard mining overrides the Hachidori Anki server only when the proxy is on (stats server runtime). main-wiring.test.ts is now empty and removed. * refactor(main): move the plugin host, panel and windows into a plugins assembly * refactor(main): move session action dispatch and renderer mpv commands into an assembly createSessionActionsAssembly owns the session action dispatcher, the secondary-subtitle mode cycle, queueing the clipboard's video, and the mpv commands the overlay renderer sends. The runtime option cycle both paths used is now one function. * refactor(main): move Whisper subtitle generation into an assembly * refactor(main): resolve subtitle annotation options in a runtime module The runtime-option-over-config resolution that the texthooker page and the MeCab startup decision share moves out of main.ts into createAnnotationOptions. * test(main): cover a non-boolean runtime annotation option value * docs: describe the plugins, session actions and subtitle generation assemblies Update ownership for overlay geometry and pointer interaction, the autoplay-ready gate, and annotation options; point the overlay priming entry points at their new modules; the main-wiring regex debt is gone. * build: export MpvClientEvents so declaration emit can name the plugins assembly's return type
107 lines
4.0 KiB
TypeScript
107 lines
4.0 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { DEFAULT_CONFIG } from '../../config/definitions';
|
|
import type { ResolvedConfig } from '../../types';
|
|
import { createAppState } from '../state';
|
|
import { createSessionActionsAssembly, type SessionActionsAssemblyDeps } from './session-actions';
|
|
|
|
function lazy(name: string) {
|
|
return (): never => {
|
|
throw new Error(`${name} called unexpectedly`);
|
|
};
|
|
}
|
|
|
|
/** Builds deps whose every function throws unless a test overrides it. */
|
|
function makeDeps(overrides: Partial<SessionActionsAssemblyDeps> = {}): SessionActionsAssemblyDeps {
|
|
const thrower = <T extends object>(name: string): T =>
|
|
new Proxy({}, { get: (_target, key: string) => lazy(`${name}.${key}`) }) as T;
|
|
return {
|
|
appState: createAppState({ mpvSocketPath: '/tmp/subminer-session.sock', texthookerPort: 0 }),
|
|
getConfig: lazy('getConfig'),
|
|
logger: thrower('logger'),
|
|
overlayManager: thrower('overlayManager'),
|
|
getOverlayNotifications: lazy('getOverlayNotifications'),
|
|
stats: thrower('stats'),
|
|
mining: thrower('mining'),
|
|
overlayModals: thrower('overlayModals'),
|
|
youtube: thrower('youtube'),
|
|
plugins: { host: thrower('plugins.host') },
|
|
toggleVisibleOverlay: lazy('toggleVisibleOverlay'),
|
|
triggerSubsyncFromConfig: lazy('triggerSubsyncFromConfig'),
|
|
readClipboardText: lazy('readClipboardText'),
|
|
showMpvOsd: lazy('showMpvOsd'),
|
|
sendRendererMpvCommand: lazy('sendRendererMpvCommand'),
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function configWithSubtitleSelection(enabled: boolean): ResolvedConfig {
|
|
return {
|
|
...DEFAULT_CONFIG,
|
|
subtitleSelection: { ...DEFAULT_CONFIG.subtitleSelection, enabled },
|
|
};
|
|
}
|
|
|
|
test('createSessionActionsAssembly does not call its deps while constructing', () => {
|
|
const sessionActions = createSessionActionsAssembly(makeDeps());
|
|
assert.equal(typeof sessionActions.dispatchSessionAction, 'function');
|
|
});
|
|
|
|
test('the subtitle selection action opens its modal only when subtitle selection is enabled', async () => {
|
|
let enabled = false;
|
|
const opened: string[] = [];
|
|
const sessionActions = createSessionActionsAssembly(
|
|
makeDeps({
|
|
getConfig: () => configWithSubtitleSelection(enabled),
|
|
overlayModals: {
|
|
openOverlayHostedModalWithOsd: (_open: unknown, unavailableMessage: string) => {
|
|
opened.push(unavailableMessage);
|
|
},
|
|
} as unknown as SessionActionsAssemblyDeps['overlayModals'],
|
|
}),
|
|
);
|
|
|
|
await sessionActions.dispatchSessionAction({ actionId: 'openSubtitleSelection' });
|
|
assert.deepEqual(opened, []);
|
|
|
|
enabled = true;
|
|
await sessionActions.dispatchSessionAction({ actionId: 'openSubtitleSelection' });
|
|
assert.deepEqual(opened, ['Subtitle selection overlay unavailable.']);
|
|
});
|
|
|
|
test('an unregistered plugin action warns and tells the user it is unavailable', async () => {
|
|
const warnings: string[] = [];
|
|
const feedback: string[] = [];
|
|
const sessionActions = createSessionActionsAssembly(
|
|
makeDeps({
|
|
logger: { warn: (message: string) => warnings.push(message) },
|
|
getOverlayNotifications: () =>
|
|
({
|
|
showConfiguredPlaybackFeedback: (text: string) => feedback.push(text),
|
|
}) as unknown as ReturnType<SessionActionsAssemblyDeps['getOverlayNotifications']>,
|
|
plugins: { host: { runAction: async () => false } },
|
|
}),
|
|
);
|
|
|
|
await sessionActions.dispatchSessionAction({
|
|
actionId: 'runPluginAction',
|
|
payload: { pluginActionId: 'example.missing' },
|
|
});
|
|
|
|
assert.deepEqual(warnings, ['Plugin action is not registered: example.missing']);
|
|
assert.deepEqual(feedback, ['Plugin action not available: example.missing']);
|
|
});
|
|
|
|
test('renderer mpv commands cycle runtime options only once the options manager exists', () => {
|
|
const sessionActions = createSessionActionsAssembly(makeDeps());
|
|
|
|
assert.equal(sessionActions.mpvCommandDeps.hasRuntimeOptionsManager(), false);
|
|
assert.deepEqual(
|
|
sessionActions.mpvCommandDeps.cycleRuntimeOption('subtitle.annotation.jlpt', 1),
|
|
{
|
|
ok: false,
|
|
error: 'Runtime options manager unavailable',
|
|
},
|
|
);
|
|
});
|