mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: extract config warning log formatter
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
"docs:build": "vitepress build docs",
|
||||
"docs:preview": "vitepress preview docs --host 0.0.0.0 --port 4173 --strictPort",
|
||||
"test:config": "pnpm run build && node --test dist/config/config.test.js",
|
||||
"test:core": "pnpm run build && node --test dist/cli/args.test.js dist/cli/help.test.js dist/core/services/cli-command-service.test.js dist/core/services/numeric-shortcut-session-service.test.js dist/core/services/secondary-subtitle-service.test.js dist/core/services/mpv-render-metrics-service.test.js dist/core/services/mpv-runtime-service.test.js dist/core/services/runtime-options-runtime-service.test.js dist/core/services/overlay-modal-restore-service.test.js dist/core/services/runtime-config-service.test.js dist/core/services/overlay-bridge-runtime-service.test.js dist/core/services/overlay-visibility-facade-service.test.js dist/core/services/overlay-broadcast-runtime-service.test.js dist/core/services/app-ready-runtime-service.test.js dist/core/services/app-shutdown-runtime-service.test.js dist/core/services/mpv-client-deps-runtime-service.test.js dist/core/services/app-lifecycle-deps-runtime-service.test.js dist/core/services/runtime-options-manager-runtime-service.test.js",
|
||||
"test:core": "pnpm run build && node --test dist/cli/args.test.js dist/cli/help.test.js dist/core/services/cli-command-service.test.js dist/core/services/numeric-shortcut-session-service.test.js dist/core/services/secondary-subtitle-service.test.js dist/core/services/mpv-render-metrics-service.test.js dist/core/services/mpv-runtime-service.test.js dist/core/services/runtime-options-runtime-service.test.js dist/core/services/overlay-modal-restore-service.test.js dist/core/services/runtime-config-service.test.js dist/core/services/overlay-bridge-runtime-service.test.js dist/core/services/overlay-visibility-facade-service.test.js dist/core/services/overlay-broadcast-runtime-service.test.js dist/core/services/app-ready-runtime-service.test.js dist/core/services/app-shutdown-runtime-service.test.js dist/core/services/mpv-client-deps-runtime-service.test.js dist/core/services/app-lifecycle-deps-runtime-service.test.js dist/core/services/runtime-options-manager-runtime-service.test.js dist/core/services/config-warning-runtime-service.test.js",
|
||||
"test:subtitle": "pnpm run build && node --test dist/subtitle/stages.test.js dist/subtitle/pipeline.test.js",
|
||||
"generate:config-example": "pnpm run build && node dist/generate-config-example.js",
|
||||
"start": "pnpm run build && electron . --start",
|
||||
|
||||
34
src/core/services/config-warning-runtime-service.test.ts
Normal file
34
src/core/services/config-warning-runtime-service.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
formatConfigWarningRuntimeService,
|
||||
logConfigWarningRuntimeService,
|
||||
} from "./config-warning-runtime-service";
|
||||
|
||||
test("formatConfigWarningRuntimeService formats warning line", () => {
|
||||
const message = formatConfigWarningRuntimeService({
|
||||
path: "ankiConnect.enabled",
|
||||
value: "oops",
|
||||
fallback: true,
|
||||
message: "invalid type",
|
||||
});
|
||||
assert.equal(
|
||||
message,
|
||||
'[config] ankiConnect.enabled: invalid type value="oops" fallback=true',
|
||||
);
|
||||
});
|
||||
|
||||
test("logConfigWarningRuntimeService delegates to logger", () => {
|
||||
const logs: string[] = [];
|
||||
logConfigWarningRuntimeService(
|
||||
{
|
||||
path: "x.y",
|
||||
value: 1,
|
||||
fallback: 2,
|
||||
message: "bad",
|
||||
},
|
||||
(line) => logs.push(line),
|
||||
);
|
||||
assert.equal(logs.length, 1);
|
||||
assert.match(logs[0], /^\[config\] x\.y: bad /);
|
||||
});
|
||||
14
src/core/services/config-warning-runtime-service.ts
Normal file
14
src/core/services/config-warning-runtime-service.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { ConfigValidationWarning } from "../../types";
|
||||
|
||||
export function formatConfigWarningRuntimeService(
|
||||
warning: ConfigValidationWarning,
|
||||
): string {
|
||||
return `[config] ${warning.path}: ${warning.message} value=${JSON.stringify(warning.value)} fallback=${JSON.stringify(warning.fallback)}`;
|
||||
}
|
||||
|
||||
export function logConfigWarningRuntimeService(
|
||||
warning: ConfigValidationWarning,
|
||||
log: (message: string) => void,
|
||||
): void {
|
||||
log(formatConfigWarningRuntimeService(warning));
|
||||
}
|
||||
@@ -206,6 +206,7 @@ import { runAppShutdownRuntimeService } from "./core/services/app-shutdown-runti
|
||||
import { createMpvIpcClientDepsRuntimeService } from "./core/services/mpv-client-deps-runtime-service";
|
||||
import { createAppLifecycleDepsRuntimeService } from "./core/services/app-lifecycle-deps-runtime-service";
|
||||
import { createRuntimeOptionsManagerRuntimeService } from "./core/services/runtime-options-manager-runtime-service";
|
||||
import { logConfigWarningRuntimeService } from "./core/services/config-warning-runtime-service";
|
||||
import {
|
||||
runSubsyncManualFromIpcRuntimeService,
|
||||
triggerSubsyncFromConfigRuntimeService,
|
||||
@@ -533,9 +534,7 @@ if (initialArgs.generateConfig && !shouldStartApp(initialArgs)) {
|
||||
getResolvedConfig: () => getResolvedConfig(),
|
||||
getConfigWarnings: () => configService.getWarnings(),
|
||||
logConfigWarning: (warning) => {
|
||||
console.warn(
|
||||
`[config] ${warning.path}: ${warning.message} value=${JSON.stringify(warning.value)} fallback=${JSON.stringify(warning.fallback)}`,
|
||||
);
|
||||
logConfigWarningRuntimeService(warning, (line) => console.warn(line));
|
||||
},
|
||||
initRuntimeOptionsManager: () => {
|
||||
runtimeOptionsManager = createRuntimeOptionsManagerRuntimeService({
|
||||
|
||||
Reference in New Issue
Block a user