mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-26 00:55:16 -07:00
536d99251e
- Derive device identity from OS hostname; remove legacy configurable client/device fields - Prevent discovery playback from reloading active item, misreporting pause state, and duplicate overlay restores - Restart stale tray discovery sessions without re-login when server drops SubMiner cast target - Sync tray discovery checkbox state on Linux after CLI/startup/remote-session changes - Stop Discord presence falling back to stream URLs; prime title before tokenized stream loads - Fix picker library discovery when log level is above info - Fix config.example.jsonc trailing commas and array formatting
314 lines
9.9 KiB
TypeScript
314 lines
9.9 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { createAutoplayReadyGate } from './autoplay-ready-gate';
|
|
|
|
test('autoplay ready gate suppresses duplicate media signals for the same media', async () => {
|
|
const commands: Array<Array<string | boolean>> = [];
|
|
const scheduled: Array<() => void> = [];
|
|
|
|
const gate = createAutoplayReadyGate({
|
|
isAppOwnedFlowInFlight: () => false,
|
|
getCurrentMediaPath: () => '/media/video.mkv',
|
|
getCurrentVideoPath: () => null,
|
|
getPlaybackPaused: () => true,
|
|
getMpvClient: () =>
|
|
({
|
|
connected: true,
|
|
requestProperty: async () => true,
|
|
send: ({ command }: { command: Array<string | boolean> }) => {
|
|
commands.push(command);
|
|
},
|
|
}) as never,
|
|
signalPluginAutoplayReady: () => {
|
|
commands.push(['script-message', 'subminer-autoplay-ready']);
|
|
},
|
|
schedule: (callback) => {
|
|
scheduled.push(callback);
|
|
return 1 as never;
|
|
},
|
|
logDebug: () => {},
|
|
});
|
|
|
|
gate.maybeSignalPluginAutoplayReady({ text: '字幕', tokens: null });
|
|
gate.maybeSignalPluginAutoplayReady({ text: '字幕', tokens: null });
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
const firstScheduled = scheduled.shift();
|
|
firstScheduled?.();
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
assert.deepEqual(
|
|
commands.filter((command) => command[0] === 'script-message'),
|
|
[['script-message', 'subminer-autoplay-ready']],
|
|
);
|
|
assert.ok(
|
|
commands.some(
|
|
(command) => command[0] === 'set_property' && command[1] === 'pause' && command[2] === false,
|
|
),
|
|
);
|
|
});
|
|
|
|
test('autoplay ready gate retry loop does not re-signal plugin readiness', async () => {
|
|
const commands: Array<Array<string | boolean>> = [];
|
|
const scheduled: Array<() => void> = [];
|
|
|
|
const gate = createAutoplayReadyGate({
|
|
isAppOwnedFlowInFlight: () => false,
|
|
getCurrentMediaPath: () => '/media/video.mkv',
|
|
getCurrentVideoPath: () => null,
|
|
getPlaybackPaused: () => true,
|
|
getMpvClient: () =>
|
|
({
|
|
connected: true,
|
|
requestProperty: async () => true,
|
|
send: ({ command }: { command: Array<string | boolean> }) => {
|
|
commands.push(command);
|
|
},
|
|
}) as never,
|
|
signalPluginAutoplayReady: () => {
|
|
commands.push(['script-message', 'subminer-autoplay-ready']);
|
|
},
|
|
schedule: (callback) => {
|
|
scheduled.push(callback);
|
|
return 1 as never;
|
|
},
|
|
logDebug: () => {},
|
|
});
|
|
|
|
gate.maybeSignalPluginAutoplayReady({ text: '字幕', tokens: null }, { forceWhilePaused: true });
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
for (const callback of scheduled.splice(0, 3)) {
|
|
callback();
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
}
|
|
|
|
assert.deepEqual(
|
|
commands.filter((command) => command[0] === 'script-message'),
|
|
[['script-message', 'subminer-autoplay-ready']],
|
|
);
|
|
assert.equal(
|
|
commands.filter(
|
|
(command) => command[0] === 'set_property' && command[1] === 'pause' && command[2] === false,
|
|
).length > 0,
|
|
true,
|
|
);
|
|
});
|
|
|
|
test('autoplay ready gate does not unpause again after a later manual pause on the same media', async () => {
|
|
const commands: Array<Array<string | boolean>> = [];
|
|
let playbackPaused = true;
|
|
|
|
const gate = createAutoplayReadyGate({
|
|
isAppOwnedFlowInFlight: () => false,
|
|
getCurrentMediaPath: () => '/media/video.mkv',
|
|
getCurrentVideoPath: () => null,
|
|
getPlaybackPaused: () => playbackPaused,
|
|
getMpvClient: () =>
|
|
({
|
|
connected: true,
|
|
requestProperty: async () => playbackPaused,
|
|
send: ({ command }: { command: Array<string | boolean> }) => {
|
|
commands.push(command);
|
|
if (command[0] === 'set_property' && command[1] === 'pause' && command[2] === false) {
|
|
playbackPaused = false;
|
|
}
|
|
},
|
|
}) as never,
|
|
signalPluginAutoplayReady: () => {
|
|
commands.push(['script-message', 'subminer-autoplay-ready']);
|
|
},
|
|
schedule: (callback) => {
|
|
queueMicrotask(callback);
|
|
return 1 as never;
|
|
},
|
|
logDebug: () => {},
|
|
});
|
|
|
|
gate.maybeSignalPluginAutoplayReady({ text: '字幕', tokens: null }, { forceWhilePaused: true });
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
playbackPaused = true;
|
|
gate.maybeSignalPluginAutoplayReady(
|
|
{ text: '字幕その2', tokens: null },
|
|
{ forceWhilePaused: true },
|
|
);
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
assert.equal(
|
|
commands.filter(
|
|
(command) => command[0] === 'set_property' && command[1] === 'pause' && command[2] === false,
|
|
).length,
|
|
1,
|
|
);
|
|
});
|
|
|
|
test('autoplay ready gate cancels release retries after playback is paused again', async () => {
|
|
const commands: Array<Array<string | boolean>> = [];
|
|
const scheduled: Array<() => void> = [];
|
|
let playbackPaused = true;
|
|
|
|
const gate = createAutoplayReadyGate({
|
|
isAppOwnedFlowInFlight: () => false,
|
|
getCurrentMediaPath: () => '/media/video.mkv',
|
|
getCurrentVideoPath: () => null,
|
|
getPlaybackPaused: () => playbackPaused,
|
|
getMpvClient: () =>
|
|
({
|
|
connected: true,
|
|
requestProperty: async () => playbackPaused,
|
|
send: ({ command }: { command: Array<string | boolean> }) => {
|
|
commands.push(command);
|
|
if (command[0] === 'set_property' && command[1] === 'pause' && command[2] === false) {
|
|
playbackPaused = false;
|
|
}
|
|
},
|
|
}) as never,
|
|
signalPluginAutoplayReady: () => {
|
|
commands.push(['script-message', 'subminer-autoplay-ready']);
|
|
},
|
|
schedule: (callback) => {
|
|
scheduled.push(callback);
|
|
return 1 as never;
|
|
},
|
|
logDebug: () => {},
|
|
});
|
|
|
|
gate.maybeSignalPluginAutoplayReady({ text: '字幕', tokens: null }, { forceWhilePaused: true });
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
playbackPaused = true;
|
|
const retry = scheduled.shift();
|
|
retry?.();
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
assert.equal(
|
|
commands.filter(
|
|
(command) => command[0] === 'set_property' && command[1] === 'pause' && command[2] === false,
|
|
).length,
|
|
1,
|
|
);
|
|
});
|
|
|
|
test('autoplay ready gate suppresses release after manual current-media dismissal', async () => {
|
|
const commands: Array<Array<string | boolean>> = [];
|
|
|
|
const gate = createAutoplayReadyGate({
|
|
isAppOwnedFlowInFlight: () => false,
|
|
getCurrentMediaPath: () => '/media/video.mkv',
|
|
getCurrentVideoPath: () => null,
|
|
getPlaybackPaused: () => true,
|
|
getMpvClient: () =>
|
|
({
|
|
connected: true,
|
|
requestProperty: async () => true,
|
|
send: ({ command }: { command: Array<string | boolean> }) => {
|
|
commands.push(command);
|
|
},
|
|
}) as never,
|
|
signalPluginAutoplayReady: () => {
|
|
commands.push(['script-message', 'subminer-autoplay-ready']);
|
|
},
|
|
schedule: (callback) => {
|
|
queueMicrotask(callback);
|
|
return 1 as never;
|
|
},
|
|
logDebug: () => {},
|
|
});
|
|
|
|
gate.markCurrentMediaAutoplayReady();
|
|
gate.maybeSignalPluginAutoplayReady({ text: '字幕', tokens: null }, { forceWhilePaused: true });
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
assert.deepEqual(commands, []);
|
|
});
|
|
|
|
test('autoplay ready gate defers plugin readiness until the signal target is ready', async () => {
|
|
const commands: Array<Array<string | boolean>> = [];
|
|
let targetReady = false;
|
|
|
|
const gate = createAutoplayReadyGate({
|
|
isAppOwnedFlowInFlight: () => false,
|
|
getCurrentMediaPath: () => '/media/video.mkv',
|
|
getCurrentVideoPath: () => null,
|
|
getPlaybackPaused: () => true,
|
|
getMpvClient: () =>
|
|
({
|
|
connected: true,
|
|
requestProperty: async () => true,
|
|
send: ({ command }: { command: Array<string | boolean> }) => {
|
|
commands.push(command);
|
|
},
|
|
}) as never,
|
|
signalPluginAutoplayReady: () => {
|
|
commands.push(['script-message', 'subminer-autoplay-ready']);
|
|
},
|
|
isSignalTargetReady: () => targetReady,
|
|
schedule: (callback) => {
|
|
queueMicrotask(callback);
|
|
return 1 as never;
|
|
},
|
|
logDebug: () => {},
|
|
});
|
|
|
|
gate.maybeSignalPluginAutoplayReady({ text: '字幕', tokens: null }, { forceWhilePaused: true });
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
assert.deepEqual(commands, []);
|
|
|
|
targetReady = true;
|
|
gate.flushPendingAutoplayReadySignal();
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
assert.deepEqual(
|
|
commands.filter((command) => command[0] === 'script-message'),
|
|
[['script-message', 'subminer-autoplay-ready']],
|
|
);
|
|
assert.equal(
|
|
commands.some(
|
|
(command) => command[0] === 'set_property' && command[1] === 'pause' && command[2] === false,
|
|
),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test('autoplay ready gate drops deferred readiness after media changes before flush', async () => {
|
|
const commands: Array<Array<string | boolean>> = [];
|
|
let targetReady = false;
|
|
let currentMediaPath = '/media/video-1.mkv';
|
|
|
|
const gate = createAutoplayReadyGate({
|
|
isAppOwnedFlowInFlight: () => false,
|
|
getCurrentMediaPath: () => currentMediaPath,
|
|
getCurrentVideoPath: () => null,
|
|
getPlaybackPaused: () => true,
|
|
getMpvClient: () =>
|
|
({
|
|
connected: true,
|
|
requestProperty: async () => true,
|
|
send: ({ command }: { command: Array<string | boolean> }) => {
|
|
commands.push(command);
|
|
},
|
|
}) as never,
|
|
signalPluginAutoplayReady: () => {
|
|
commands.push(['script-message', 'subminer-autoplay-ready']);
|
|
},
|
|
isSignalTargetReady: () => targetReady,
|
|
schedule: (callback) => {
|
|
queueMicrotask(callback);
|
|
return 1 as never;
|
|
},
|
|
logDebug: () => {},
|
|
});
|
|
|
|
gate.maybeSignalPluginAutoplayReady({ text: '字幕', tokens: null }, { forceWhilePaused: true });
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
currentMediaPath = '/media/video-2.mkv';
|
|
targetReady = true;
|
|
gate.flushPendingAutoplayReadySignal();
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
|
|
assert.deepEqual(commands, []);
|
|
});
|