test(doctor): share legacy config step harness

This commit is contained in:
Vincent Koc
2026-04-12 05:00:28 +01:00
parent 9801ce7333
commit 80a94f6596

View File

@@ -3,32 +3,39 @@ import type { OpenClawConfig } from "../../../config/config.js";
import type { DoctorConfigPreflightResult } from "../../doctor-config-preflight.js";
import { applyLegacyCompatibilityStep, applyUnknownConfigKeyStep } from "./config-flow-steps.js";
function createLegacyStepResult(
snapshot: DoctorConfigPreflightResult["snapshot"],
doctorFixCommand = "openclaw doctor --fix",
) {
return applyLegacyCompatibilityStep({
snapshot,
state: {
cfg: {},
candidate: {},
pendingChanges: false,
fixHints: [],
},
shouldRepair: false,
doctorFixCommand,
});
}
describe("doctor config flow steps", () => {
it("collects legacy compatibility issue lines and preview fix hints", () => {
const result = applyLegacyCompatibilityStep({
snapshot: {
exists: true,
parsed: { heartbeat: { enabled: true } },
legacyIssues: [{ path: "heartbeat", message: "use agents.defaults.heartbeat" }],
path: "/tmp/config.json",
valid: true,
issues: [],
raw: "{}",
resolved: {},
sourceConfig: {},
config: {},
runtimeConfig: {},
warnings: [],
} satisfies DoctorConfigPreflightResult["snapshot"],
state: {
cfg: {},
candidate: {},
pendingChanges: false,
fixHints: [],
},
shouldRepair: false,
doctorFixCommand: "openclaw doctor --fix",
});
const result = createLegacyStepResult({
exists: true,
parsed: { heartbeat: { enabled: true } },
legacyIssues: [{ path: "heartbeat", message: "use agents.defaults.heartbeat" }],
path: "/tmp/config.json",
valid: true,
issues: [],
raw: "{}",
resolved: {},
sourceConfig: {},
config: {},
runtimeConfig: {},
warnings: [],
} satisfies DoctorConfigPreflightResult["snapshot"]);
expect(result.issueLines).toEqual([expect.stringContaining("- heartbeat:")]);
expect(result.changeLines).not.toEqual([]);
@@ -39,35 +46,25 @@ describe("doctor config flow steps", () => {
});
it("keeps pending repair state for legacy issues even when the snapshot is already normalized", () => {
const result = applyLegacyCompatibilityStep({
snapshot: {
exists: true,
parsed: { talk: { voiceId: "voice-1", modelId: "eleven_v3" } },
legacyIssues: [
{
path: "talk",
message: "talk.voiceId/talk.voiceAliases/talk.modelId/talk.outputFormat/talk.apiKey",
},
],
path: "/tmp/config.json",
valid: true,
issues: [],
raw: "{}",
resolved: {},
sourceConfig: {},
config: {},
runtimeConfig: {},
warnings: [],
} satisfies DoctorConfigPreflightResult["snapshot"],
state: {
cfg: {},
candidate: {},
pendingChanges: false,
fixHints: [],
},
shouldRepair: false,
doctorFixCommand: "openclaw doctor --fix",
});
const result = createLegacyStepResult({
exists: true,
parsed: { talk: { voiceId: "voice-1", modelId: "eleven_v3" } },
legacyIssues: [
{
path: "talk",
message: "talk.voiceId/talk.voiceAliases/talk.modelId/talk.outputFormat/talk.apiKey",
},
],
path: "/tmp/config.json",
valid: true,
issues: [],
raw: "{}",
resolved: {},
sourceConfig: {},
config: {},
runtimeConfig: {},
warnings: [],
} satisfies DoctorConfigPreflightResult["snapshot"]);
expect(result.changeLines).toEqual([]);
expect(result.state.pendingChanges).toBe(true);