mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:20:43 +00:00
fix: keep legacy config repair in doctor
This commit is contained in:
@@ -3,6 +3,7 @@ import { ensureConfigReady, __test__ } from "./config-guard.js";
|
||||
|
||||
const loadAndMaybeMigrateDoctorConfigMock = vi.hoisted(() => vi.fn());
|
||||
const readConfigFileSnapshotMock = vi.hoisted(() => vi.fn());
|
||||
const setRuntimeConfigSnapshotMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("../../commands/doctor-config-preflight.js", () => ({
|
||||
runDoctorConfigPreflight: loadAndMaybeMigrateDoctorConfigMock,
|
||||
@@ -10,6 +11,7 @@ vi.mock("../../commands/doctor-config-preflight.js", () => ({
|
||||
|
||||
vi.mock("../../config/config.js", () => ({
|
||||
readConfigFileSnapshot: readConfigFileSnapshotMock,
|
||||
setRuntimeConfigSnapshot: setRuntimeConfigSnapshotMock,
|
||||
}));
|
||||
|
||||
function makeSnapshot() {
|
||||
@@ -105,6 +107,23 @@ describe("ensureConfigReady", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("pins a valid preflight snapshot for command code reuse", async () => {
|
||||
const snapshot = {
|
||||
...makeSnapshot(),
|
||||
config: { runtime: true },
|
||||
runtimeConfig: { runtime: true, materialized: true },
|
||||
sourceConfig: { source: true },
|
||||
};
|
||||
readConfigFileSnapshotMock.mockResolvedValue(snapshot);
|
||||
|
||||
await runEnsureConfigReady(["status"]);
|
||||
|
||||
expect(setRuntimeConfigSnapshotMock).toHaveBeenCalledWith(
|
||||
snapshot.runtimeConfig,
|
||||
snapshot.sourceConfig,
|
||||
);
|
||||
});
|
||||
|
||||
it("exits for invalid config on non-allowlisted commands", async () => {
|
||||
setInvalidSnapshot();
|
||||
const runtime = await runEnsureConfigReady(["message"]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { readConfigFileSnapshot } from "../../config/config.js";
|
||||
import { readConfigFileSnapshot, setRuntimeConfigSnapshot } from "../../config/config.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import { shouldMigrateStateFromPath } from "../argv.js";
|
||||
|
||||
@@ -93,6 +93,9 @@ export async function ensureConfigReady(params: {
|
||||
snapshot.legacyIssues.length > 0 ? formatConfigIssueLines(snapshot.legacyIssues, "-") : [];
|
||||
|
||||
const invalid = snapshot.exists && !snapshot.valid;
|
||||
if (!invalid) {
|
||||
setRuntimeConfigSnapshot(snapshot.runtimeConfig ?? snapshot.config, snapshot.sourceConfig);
|
||||
}
|
||||
if (!invalid) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user