mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
Move OSD log appends off sync fs calls to reduce main-process blocking under frequent OSD activity. Add buffered flush wiring into quit cleanup so pending log lines are drained best-effort during shutdown.
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
createBuildAppendToMpvLogMainDepsHandler,
|
|
createBuildShowMpvOsdMainDepsHandler,
|
|
} from './mpv-osd-log-main-deps';
|
|
|
|
test('append to mpv log main deps map filesystem functions and log path', async () => {
|
|
const calls: string[] = [];
|
|
const deps = createBuildAppendToMpvLogMainDepsHandler({
|
|
logPath: '/tmp/mpv.log',
|
|
dirname: (targetPath) => {
|
|
calls.push(`dirname:${targetPath}`);
|
|
return '/tmp';
|
|
},
|
|
mkdir: async (targetPath) => {
|
|
calls.push(`mkdir:${targetPath}`);
|
|
},
|
|
appendFile: async (_targetPath, data) => {
|
|
calls.push(`append:${data}`);
|
|
},
|
|
now: () => new Date('2026-02-20T00:00:00.000Z'),
|
|
})();
|
|
|
|
assert.equal(deps.logPath, '/tmp/mpv.log');
|
|
assert.equal(deps.dirname('/tmp/mpv.log'), '/tmp');
|
|
await deps.mkdir('/tmp', { recursive: true });
|
|
await deps.appendFile('/tmp/mpv.log', 'line', { encoding: 'utf8' });
|
|
assert.equal(deps.now().toISOString(), '2026-02-20T00:00:00.000Z');
|
|
assert.deepEqual(calls, ['dirname:/tmp/mpv.log', 'mkdir:/tmp', 'append:line']);
|
|
});
|
|
|
|
test('show mpv osd main deps map runtime delegates and logging callback', () => {
|
|
const calls: string[] = [];
|
|
const client = { id: 'mpv' };
|
|
const deps = createBuildShowMpvOsdMainDepsHandler({
|
|
appendToMpvLog: (message) => calls.push(`append:${message}`),
|
|
showMpvOsdRuntime: (_mpvClient, text, fallbackLog) => {
|
|
calls.push(`show:${text}`);
|
|
fallbackLog('fallback');
|
|
},
|
|
getMpvClient: () => client,
|
|
logInfo: (line) => calls.push(`info:${line}`),
|
|
})();
|
|
|
|
assert.deepEqual(deps.getMpvClient(), client);
|
|
deps.appendToMpvLog('hello');
|
|
deps.showMpvOsdRuntime(deps.getMpvClient(), 'subtitle', (line) => deps.logInfo(line));
|
|
assert.deepEqual(calls, ['append:hello', 'show:subtitle', 'info:fallback']);
|
|
});
|