test(core): expand mpv/subsync/tokenizer and cli coverage

This commit is contained in:
kyasuda
2026-02-10 13:13:47 -08:00
committed by sudacode
parent f868fdbbb3
commit 35cad19839
6 changed files with 749 additions and 1 deletions

View File

@@ -179,3 +179,112 @@ test("handleCliCommandService reports async mine errors to OSD", async () => {
assert.ok(calls.some((value) => value.startsWith("error:mineSentenceCard failed:")));
assert.ok(osd.some((value) => value.includes("Mine sentence failed: boom")));
});
test("handleCliCommandService applies socket path and connects on start", () => {
const { deps, calls } = createDeps();
handleCliCommandService(
makeArgs({ start: true, socketPath: "/tmp/custom.sock" }),
"initial",
deps,
);
assert.ok(calls.includes("setMpvSocketPath:/tmp/custom.sock"));
assert.ok(calls.includes("setMpvClientSocketPath:/tmp/custom.sock"));
assert.ok(calls.includes("connectMpvClient"));
});
test("handleCliCommandService warns when texthooker port override used while running", () => {
const { deps, calls } = createDeps({
isTexthookerRunning: () => true,
});
handleCliCommandService(
makeArgs({ texthookerPort: 9999, texthooker: true }),
"initial",
deps,
);
assert.ok(
calls.includes(
"warn:Ignoring --port override because the texthooker server is already running.",
),
);
assert.equal(calls.some((value) => value === "setTexthookerPort:9999"), false);
});
test("handleCliCommandService prints help and stops app when no window exists", () => {
const { deps, calls } = createDeps({
hasMainWindow: () => false,
});
handleCliCommandService(makeArgs({ help: true }), "initial", deps);
assert.ok(calls.includes("printHelp"));
assert.ok(calls.includes("stopApp"));
});
test("handleCliCommandService reports async trigger-subsync errors to OSD", async () => {
const { deps, calls, osd } = createDeps({
triggerSubsyncFromConfig: async () => {
throw new Error("subsync boom");
},
});
handleCliCommandService(makeArgs({ triggerSubsync: true }), "initial", deps);
await new Promise((resolve) => setImmediate(resolve));
assert.ok(
calls.some((value) => value.startsWith("error:triggerSubsyncFromConfig failed:")),
);
assert.ok(osd.some((value) => value.includes("Subsync failed: subsync boom")));
});
test("handleCliCommandService stops app for --stop command", () => {
const { deps, calls } = createDeps();
handleCliCommandService(makeArgs({ stop: true }), "initial", deps);
assert.ok(calls.includes("log:Stopping SubMiner..."));
assert.ok(calls.includes("stopApp"));
});
test("handleCliCommandService still runs non-start actions on second-instance", () => {
const { deps, calls } = createDeps();
handleCliCommandService(
makeArgs({ start: true, toggleVisibleOverlay: true }),
"second-instance",
deps,
);
assert.ok(calls.includes("toggleVisibleOverlay"));
assert.equal(calls.some((value) => value === "connectMpvClient"), false);
});
test("handleCliCommandService handles visibility and utility command dispatches", () => {
const cases: Array<{
args: Partial<CliArgs>;
expected: string;
}> = [
{ args: { toggleInvisibleOverlay: true }, expected: "toggleInvisibleOverlay" },
{ args: { settings: true }, expected: "openYomitanSettingsDelayed:1000" },
{ args: { showVisibleOverlay: true }, expected: "setVisibleOverlayVisible:true" },
{ args: { hideVisibleOverlay: true }, expected: "setVisibleOverlayVisible:false" },
{ args: { showInvisibleOverlay: true }, expected: "setInvisibleOverlayVisible:true" },
{ args: { hideInvisibleOverlay: true }, expected: "setInvisibleOverlayVisible:false" },
{ args: { copySubtitle: true }, expected: "copyCurrentSubtitle" },
{ args: { copySubtitleMultiple: true }, expected: "startPendingMultiCopy:2500" },
{
args: { mineSentenceMultiple: true },
expected: "startPendingMineSentenceMultiple:2500",
},
{ args: { toggleSecondarySub: true }, expected: "cycleSecondarySubMode" },
{ args: { openRuntimeOptions: true }, expected: "openRuntimeOptionsPalette" },
];
for (const entry of cases) {
const { deps, calls } = createDeps();
handleCliCommandService(makeArgs(entry.args), "initial", deps);
assert.ok(
calls.includes(entry.expected),
`expected call missing for args ${JSON.stringify(entry.args)}: ${entry.expected}`,
);
}
});