Files
SubMiner/src/main/runtime/startup-config-main-deps.test.ts
sudacode a6d85def34 refactor(main): eliminate unsafe runtime cast escapes
Tighten main/runtime dependency contracts to remove non-test `as never` and `as unknown as` usage so type drift surfaces during compile/test checks instead of at runtime.
2026-02-22 13:59:08 -08:00

69 lines
2.4 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
createBuildCriticalConfigErrorMainDepsHandler,
createBuildReloadConfigMainDepsHandler,
} from './startup-config-main-deps';
test('reload config main deps builder maps callbacks and fail handlers', async () => {
const calls: string[] = [];
const deps = createBuildReloadConfigMainDepsHandler({
reloadConfigStrict: () => ({ ok: true, path: '/tmp/config.jsonc', warnings: [] }),
logInfo: (message) => calls.push(`info:${message}`),
logWarning: (message) => calls.push(`warn:${message}`),
showDesktopNotification: (title, options) => calls.push(`notify:${title}:${options.body}`),
startConfigHotReload: () => calls.push('start-hot-reload'),
refreshAnilistClientSecretState: async (options) => {
calls.push(`refresh:${options.force}`);
return true;
},
failHandlers: {
logError: (details) => calls.push(`error:${details}`),
showErrorBox: (title, details) => calls.push(`error-box:${title}:${details}`),
quit: () => calls.push('quit'),
},
})();
assert.deepEqual(deps.reloadConfigStrict(), {
ok: true,
path: '/tmp/config.jsonc',
warnings: [],
});
deps.logInfo('x');
deps.logWarning('y');
deps.showDesktopNotification('SubMiner', { body: 'warn' });
deps.startConfigHotReload();
await deps.refreshAnilistClientSecretState({ force: true });
deps.failHandlers.logError('bad');
deps.failHandlers.showErrorBox('Oops', 'Details');
deps.failHandlers.quit();
assert.deepEqual(calls, [
'info:x',
'warn:y',
'notify:SubMiner:warn',
'start-hot-reload',
'refresh:true',
'error:bad',
'error-box:Oops:Details',
'quit',
]);
});
test('critical config main deps builder maps config path and fail handlers', () => {
const calls: string[] = [];
const deps = createBuildCriticalConfigErrorMainDepsHandler({
getConfigPath: () => '/tmp/config.jsonc',
failHandlers: {
logError: (details) => calls.push(`error:${details}`),
showErrorBox: (title, details) => calls.push(`error-box:${title}:${details}`),
quit: () => calls.push('quit'),
},
})();
assert.equal(deps.getConfigPath(), '/tmp/config.jsonc');
deps.failHandlers.logError('bad');
deps.failHandlers.showErrorBox('Oops', 'Details');
deps.failHandlers.quit();
assert.deepEqual(calls, ['error:bad', 'error-box:Oops:Details', 'quit']);
});