mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-20 16:46:07 -08:00
Merge remote-tracking branch 'origin/main' into add-hachidori-backend
# Conflicts: # launcher/main.test.ts # src/cli/help.test.ts # src/core/services/__tests__/stats-server.test.ts # src/core/services/cli-command.test.ts # src/core/services/tokenizer/yomitan-parser-runtime.test.ts # src/main/overlay-runtime.test.ts # src/main/runtime/character-dictionary-auto-sync.test.ts # src/main/runtime/cli-command-context-deps.test.ts # src/main/runtime/cli-command-context-factory.test.ts # src/main/runtime/cli-command-context-main-deps.test.ts # src/main/runtime/composers/cli-startup-composer.test.ts # src/main/runtime/stats-server-runtime.test.ts # src/main/runtime/tray-main-actions.test.ts # src/main/runtime/tray-main-deps.test.ts # src/main/runtime/tray-runtime-handlers.test.ts # src/main/runtime/tray-runtime.test.ts # src/main/runtime/yomitan-anki-server-sync.test.ts # src/preload.ts # src/renderer/handlers/mouse.test.ts # src/renderer/yomitan-popup.test.ts
This commit is contained in:
417 files changed
+19477
-60921
No files matched your search
@@ -2,62 +2,41 @@ import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createBuildCliCommandContextMainDepsHandler } from './cli-command-context-main-deps';
|
||||
|
||||
test('cli command context main deps builder maps state and callbacks', async () => {
|
||||
const calls: string[] = [];
|
||||
const appState = {
|
||||
mpvSocketPath: '/tmp/mpv.sock',
|
||||
mpvClient: null,
|
||||
texthookerPort: 5174,
|
||||
overlayRuntimeInitialized: false,
|
||||
};
|
||||
type MainDeps = Parameters<typeof createBuildCliCommandContextMainDepsHandler>[0];
|
||||
|
||||
const build = createBuildCliCommandContextMainDepsHandler({
|
||||
appState,
|
||||
onMpvSocketPathChanged: (next, previous) => calls.push(`socket:${previous}->${next}`),
|
||||
function buildContextDeps(overrides: Partial<MainDeps> = {}) {
|
||||
const noop = () => {};
|
||||
const noopAsync = async () => {};
|
||||
return createBuildCliCommandContextMainDepsHandler({
|
||||
appState: {
|
||||
mpvSocketPath: '/tmp/mpv.sock',
|
||||
mpvClient: null,
|
||||
texthookerPort: 5174,
|
||||
overlayRuntimeInitialized: false,
|
||||
},
|
||||
texthookerService: { isRunning: () => false, start: () => null },
|
||||
getResolvedConfig: () => ({
|
||||
texthooker: { openBrowser: true },
|
||||
annotationWebsocket: { enabled: true, port: 6678 },
|
||||
}),
|
||||
getResolvedConfig: () => ({}),
|
||||
defaultWebsocketPort: 6677,
|
||||
defaultAnnotationWebsocketPort: 6678,
|
||||
hasMpvWebsocketPlugin: () => false,
|
||||
openExternal: async (url) => {
|
||||
calls.push(`open:${url}`);
|
||||
},
|
||||
logBrowserOpenError: (url) => calls.push(`open-error:${url}`),
|
||||
showMpvOsd: (text) => calls.push(`osd:${text}`),
|
||||
|
||||
initializeOverlayRuntime: () => calls.push('init-overlay'),
|
||||
toggleVisibleOverlay: () => calls.push('toggle-visible'),
|
||||
togglePrimarySubtitleBar: () => calls.push('toggle-primary-subtitle'),
|
||||
openFirstRunSetupWindow: (force?: boolean) =>
|
||||
calls.push(`open-setup:${force === true ? 'force' : 'default'}`),
|
||||
setVisibleOverlayVisible: (visible) => calls.push(`set-visible:${visible}`),
|
||||
|
||||
copyCurrentSubtitle: () => calls.push('copy-sub'),
|
||||
startPendingMultiCopy: (timeoutMs) => calls.push(`multi:${timeoutMs}`),
|
||||
mineSentenceCard: async () => {
|
||||
calls.push('mine');
|
||||
},
|
||||
startPendingMineSentenceMultiple: (timeoutMs) => calls.push(`mine-multi:${timeoutMs}`),
|
||||
updateLastCardFromClipboard: async () => {
|
||||
calls.push('update-last-card');
|
||||
},
|
||||
refreshKnownWordCache: async () => {
|
||||
calls.push('refresh-known');
|
||||
},
|
||||
triggerFieldGrouping: async () => {
|
||||
calls.push('field-grouping');
|
||||
},
|
||||
triggerSubsyncFromConfig: async () => {
|
||||
calls.push('subsync');
|
||||
},
|
||||
markLastCardAsAudioCard: async () => {
|
||||
calls.push('mark-audio');
|
||||
},
|
||||
dispatchSessionAction: async () => {},
|
||||
|
||||
openExternal: noopAsync,
|
||||
logBrowserOpenError: noop,
|
||||
showMpvOsd: noop,
|
||||
initializeOverlayRuntime: noop,
|
||||
toggleVisibleOverlay: noop,
|
||||
togglePrimarySubtitleBar: noop,
|
||||
openFirstRunSetupWindow: noop,
|
||||
setVisibleOverlayVisible: noop,
|
||||
copyCurrentSubtitle: noop,
|
||||
startPendingMultiCopy: noop,
|
||||
mineSentenceCard: noopAsync,
|
||||
startPendingMineSentenceMultiple: noop,
|
||||
updateLastCardFromClipboard: noopAsync,
|
||||
refreshKnownWordCache: noopAsync,
|
||||
triggerFieldGrouping: noopAsync,
|
||||
triggerSubsyncFromConfig: noopAsync,
|
||||
markLastCardAsAudioCard: noopAsync,
|
||||
dispatchSessionAction: noopAsync,
|
||||
getAnilistStatus: () => ({
|
||||
tokenStatus: 'resolved',
|
||||
tokenSource: 'literal',
|
||||
@@ -70,11 +49,11 @@ test('cli command context main deps builder maps state and callbacks', async ()
|
||||
queueLastAttemptAt: null,
|
||||
queueLastError: null,
|
||||
}),
|
||||
clearAnilistToken: () => calls.push('clear-token'),
|
||||
openAnilistSetupWindow: () => calls.push('open-anilist-setup'),
|
||||
openJellyfinSetupWindow: () => calls.push('open-jellyfin-setup'),
|
||||
clearAnilistToken: noop,
|
||||
openAnilistSetupWindow: noop,
|
||||
openJellyfinSetupWindow: noop,
|
||||
getAnilistQueueStatus: () => ({
|
||||
pending: 1,
|
||||
pending: 0,
|
||||
ready: 0,
|
||||
deadLetter: 0,
|
||||
lastAttemptAt: null,
|
||||
@@ -88,73 +67,90 @@ test('cli command context main deps builder maps state and callbacks', async ()
|
||||
mediaTitle: 'Test',
|
||||
entryCount: 10,
|
||||
}),
|
||||
runStatsCommand: async () => {
|
||||
calls.push('run-stats');
|
||||
},
|
||||
runJellyfinCommand: async () => {
|
||||
calls.push('run-jellyfin');
|
||||
},
|
||||
runUpdateCommand: async () => {
|
||||
calls.push('run-update');
|
||||
},
|
||||
runEnsureLinuxRuntimePluginAssetsCommand: async () => {
|
||||
calls.push('run-ensure-linux-runtime-plugin-assets');
|
||||
},
|
||||
runYoutubePlaybackFlow: async () => {
|
||||
calls.push('run-youtube-playback');
|
||||
},
|
||||
openHachidoriSettings: () => {},
|
||||
openYomitanSettings: () => calls.push('open-yomitan'),
|
||||
openConfigSettingsWindow: () => calls.push('open-config-settings'),
|
||||
openSyncUiWindow: () => {},
|
||||
openYoutubeBrowserWindow: () => {},
|
||||
cycleSecondarySubMode: () => calls.push('cycle-secondary'),
|
||||
openRuntimeOptionsPalette: () => calls.push('open-runtime-options'),
|
||||
printHelp: () => calls.push('help'),
|
||||
stopApp: () => calls.push('stop-app'),
|
||||
runStatsCommand: noopAsync,
|
||||
runJellyfinCommand: noopAsync,
|
||||
runUpdateCommand: noopAsync,
|
||||
runEnsureLinuxRuntimePluginAssetsCommand: noopAsync,
|
||||
runYoutubePlaybackFlow: noopAsync,
|
||||
openHachidoriSettings: noop,
|
||||
openYomitanSettings: noop,
|
||||
openConfigSettingsWindow: noop,
|
||||
openSyncUiWindow: noop,
|
||||
openYoutubeBrowserWindow: noop,
|
||||
cycleSecondarySubMode: noop,
|
||||
openRuntimeOptionsPalette: noop,
|
||||
printHelp: noop,
|
||||
stopApp: noop,
|
||||
hasMainWindow: () => true,
|
||||
getMultiCopyTimeoutMs: () => 5000,
|
||||
schedule: (fn) => {
|
||||
fn();
|
||||
return setTimeout(() => {}, 0);
|
||||
},
|
||||
logInfo: (message) => calls.push(`info:${message}`),
|
||||
logDebug: (message) => calls.push(`debug:${message}`),
|
||||
logWarn: (message) => calls.push(`warn:${message}`),
|
||||
logError: (message) => calls.push(`error:${message}`),
|
||||
schedule: (fn) => setTimeout(fn, 0),
|
||||
logInfo: noop,
|
||||
logDebug: noop,
|
||||
logWarn: noop,
|
||||
logError: noop,
|
||||
...overrides,
|
||||
})();
|
||||
}
|
||||
|
||||
test('cli command context setSocketPath notifies only when the socket path changes', () => {
|
||||
const changes: string[] = [];
|
||||
const appState = {
|
||||
mpvSocketPath: '/tmp/mpv.sock',
|
||||
mpvClient: null,
|
||||
texthookerPort: 5174,
|
||||
overlayRuntimeInitialized: false,
|
||||
};
|
||||
const deps = buildContextDeps({
|
||||
appState,
|
||||
onMpvSocketPathChanged: (next, previous) => changes.push(`${previous}->${next}`),
|
||||
});
|
||||
|
||||
const deps = build();
|
||||
assert.equal(deps.getSocketPath(), '/tmp/mpv.sock');
|
||||
deps.setSocketPath('/tmp/next.sock');
|
||||
deps.setSocketPath('/tmp/next.sock');
|
||||
|
||||
assert.equal(appState.mpvSocketPath, '/tmp/next.sock');
|
||||
assert.deepEqual(calls, ['socket:/tmp/mpv.sock->/tmp/next.sock']);
|
||||
deps.setSocketPath('/tmp/next.sock');
|
||||
assert.deepEqual(calls, ['socket:/tmp/mpv.sock->/tmp/next.sock']);
|
||||
calls.length = 0;
|
||||
assert.equal(deps.getTexthookerPort(), 5174);
|
||||
deps.setTexthookerPort(5175);
|
||||
assert.equal(appState.texthookerPort, 5175);
|
||||
assert.equal(deps.getTexthookerWebsocketUrl(), 'ws://127.0.0.1:6678');
|
||||
assert.equal(deps.shouldOpenBrowser(), true);
|
||||
deps.showOsd('hello');
|
||||
deps.initializeOverlay();
|
||||
deps.openFirstRunSetup(true);
|
||||
deps.setVisibleOverlay(true);
|
||||
deps.openConfigSettingsWindow();
|
||||
deps.printHelp();
|
||||
await deps.runUpdateCommand({ update: true } as never, 'initial');
|
||||
|
||||
assert.deepEqual(calls, [
|
||||
'osd:hello',
|
||||
'init-overlay',
|
||||
'open-setup:force',
|
||||
'set-visible:true',
|
||||
'open-config-settings',
|
||||
'help',
|
||||
'run-update',
|
||||
]);
|
||||
|
||||
const retry = await deps.retryAnilistQueueNow();
|
||||
assert.deepEqual(retry, { ok: true, message: 'ok' });
|
||||
assert.equal(deps.getSocketPath(), '/tmp/next.sock');
|
||||
assert.deepEqual(changes, ['/tmp/mpv.sock->/tmp/next.sock']);
|
||||
});
|
||||
|
||||
for (const c of [
|
||||
{ openBrowser: undefined, expected: true },
|
||||
{ openBrowser: true, expected: true },
|
||||
{ openBrowser: false, expected: false },
|
||||
]) {
|
||||
test(`cli command context shouldOpenBrowser is ${c.expected} when texthooker.openBrowser is ${c.openBrowser}`, () => {
|
||||
const deps = buildContextDeps({
|
||||
getResolvedConfig: () => ({ texthooker: { openBrowser: c.openBrowser } }),
|
||||
});
|
||||
assert.equal(deps.shouldOpenBrowser(), c.expected);
|
||||
});
|
||||
}
|
||||
|
||||
for (const c of [
|
||||
{
|
||||
name: 'uses the annotation websocket port when annotations are enabled',
|
||||
config: { annotationWebsocket: { enabled: true } },
|
||||
hasPlugin: true,
|
||||
expected: 'ws://127.0.0.1:6678',
|
||||
},
|
||||
{
|
||||
name: 'falls back to the default websocket port without the mpv plugin',
|
||||
config: { annotationWebsocket: { enabled: false } },
|
||||
hasPlugin: false,
|
||||
expected: 'ws://127.0.0.1:6677',
|
||||
},
|
||||
{
|
||||
name: 'returns no websocket url when the mpv plugin owns the websocket',
|
||||
config: { annotationWebsocket: { enabled: false } },
|
||||
hasPlugin: true,
|
||||
expected: undefined,
|
||||
},
|
||||
]) {
|
||||
test(`cli command context texthooker websocket url ${c.name}`, () => {
|
||||
const deps = buildContextDeps({
|
||||
getResolvedConfig: () => c.config,
|
||||
hasMpvWebsocketPlugin: () => c.hasPlugin,
|
||||
});
|
||||
assert.equal(deps.getTexthookerWebsocketUrl(), c.expected);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user