refactor: extract config warning log formatter

This commit is contained in:
2026-02-10 00:44:29 -08:00
parent db327c4ea8
commit 2f34119a67
4 changed files with 51 additions and 4 deletions

View 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 /);
});

View 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));
}