From 80a94f65962821159cb26142598411dd71949ed2 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 12 Apr 2026 05:00:28 +0100 Subject: [PATCH] test(doctor): share legacy config step harness --- .../doctor/shared/config-flow-steps.test.ts | 103 +++++++++--------- 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/src/commands/doctor/shared/config-flow-steps.test.ts b/src/commands/doctor/shared/config-flow-steps.test.ts index 2c65c108045..413982109d4 100644 --- a/src/commands/doctor/shared/config-flow-steps.test.ts +++ b/src/commands/doctor/shared/config-flow-steps.test.ts @@ -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);