fix: block invalid config startup
Co-authored-by: Muhammed Mukhthar CM <mukhtharcm@gmail.com>
This commit is contained in:
37
src/commands/doctor-config-flow.test.ts
Normal file
37
src/commands/doctor-config-flow.test.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { withTempHome } from "../../test/helpers/temp-home.js";
|
||||
import { loadAndMaybeMigrateDoctorConfig } from "./doctor-config-flow.js";
|
||||
|
||||
describe("doctor config flow", () => {
|
||||
it("preserves invalid config for doctor repairs", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const configDir = path.join(home, ".clawdbot");
|
||||
await fs.mkdir(configDir, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(configDir, "clawdbot.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
gateway: { auth: { mode: "token", token: 123 } },
|
||||
agents: { list: [{ id: "pi" }] },
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const result = await loadAndMaybeMigrateDoctorConfig({
|
||||
options: { nonInteractive: true },
|
||||
confirm: async () => false,
|
||||
});
|
||||
|
||||
expect((result.cfg as Record<string, unknown>).gateway).toEqual({
|
||||
auth: { mode: "token", token: 123 },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -46,9 +46,9 @@ export async function loadAndMaybeMigrateDoctorConfig(params: {
|
||||
confirm: (p: { message: string; initialValue: boolean }) => Promise<boolean>;
|
||||
}) {
|
||||
const snapshot = await readConfigFileSnapshot();
|
||||
let cfg: ClawdbotConfig = snapshot.valid ? snapshot.config : {};
|
||||
let cfg: ClawdbotConfig = snapshot.config ?? {};
|
||||
if (snapshot.exists && !snapshot.valid && snapshot.legacyIssues.length === 0) {
|
||||
note("Config invalid; doctor will run with defaults.", "Config");
|
||||
note("Config invalid; doctor will run with best-effort config.", "Config");
|
||||
}
|
||||
|
||||
if (snapshot.legacyIssues.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user