mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:01:36 +00:00
CLI/Config: keep explicitly unset keys removed
This commit is contained in:
@@ -9,11 +9,14 @@ import type { ConfigFileSnapshot, OpenClawConfig } from "../config/types.js";
|
||||
*/
|
||||
|
||||
const mockReadConfigFileSnapshot = vi.fn<() => Promise<ConfigFileSnapshot>>();
|
||||
const mockWriteConfigFile = vi.fn<(cfg: OpenClawConfig) => Promise<void>>(async () => {});
|
||||
const mockWriteConfigFile = vi.fn<
|
||||
(cfg: OpenClawConfig, options?: { unsetPaths?: string[][] }) => Promise<void>
|
||||
>(async () => {});
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
readConfigFileSnapshot: () => mockReadConfigFileSnapshot(),
|
||||
writeConfigFile: (cfg: OpenClawConfig) => mockWriteConfigFile(cfg),
|
||||
writeConfigFile: (cfg: OpenClawConfig, options?: { unsetPaths?: string[][] }) =>
|
||||
mockWriteConfigFile(cfg, options),
|
||||
}));
|
||||
|
||||
const mockLog = vi.fn();
|
||||
@@ -216,6 +219,9 @@ describe("config cli", () => {
|
||||
expect(written.gateway).toEqual(resolved.gateway);
|
||||
expect(written.tools?.profile).toBe("coding");
|
||||
expect(written.logging).toEqual(resolved.logging);
|
||||
expect(mockWriteConfigFile.mock.calls[0]?.[1]).toEqual({
|
||||
unsetPaths: [["tools", "alsoAllow"]],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -272,7 +272,7 @@ export async function runConfigUnset(opts: { path: string; runtime?: RuntimeEnv
|
||||
runtime.exit(1);
|
||||
return;
|
||||
}
|
||||
await writeConfigFile(next);
|
||||
await writeConfigFile(next, { unsetPaths: [parsedPath] });
|
||||
runtime.log(info(`Removed ${opts.path}. Restart the gateway to apply.`));
|
||||
} catch (err) {
|
||||
runtime.error(danger(String(err)));
|
||||
|
||||
Reference in New Issue
Block a user