mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-26 21:48:38 +00:00
fix(config-cli): correct misleading --json flag description (#21332)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: b6c8d1edfa
Co-authored-by: adhitShet <131381638+adhitShet@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
@@ -135,6 +135,51 @@ describe("config cli", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("config set parsing flags", () => {
|
||||
it("falls back to raw string when parsing fails and strict mode is off", async () => {
|
||||
const resolved: OpenClawConfig = { gateway: { port: 18789 } };
|
||||
setSnapshot(resolved, resolved);
|
||||
|
||||
await runConfigCommand(["config", "set", "gateway.auth.mode", "{bad"]);
|
||||
|
||||
expect(mockWriteConfigFile).toHaveBeenCalledTimes(1);
|
||||
const written = mockWriteConfigFile.mock.calls[0]?.[0];
|
||||
expect(written.gateway?.auth).toEqual({ mode: "{bad" });
|
||||
});
|
||||
|
||||
it("throws when strict parsing is enabled via --strict-json", async () => {
|
||||
await expect(
|
||||
runConfigCommand(["config", "set", "gateway.auth.mode", "{bad", "--strict-json"]),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
|
||||
expect(mockWriteConfigFile).not.toHaveBeenCalled();
|
||||
expect(mockReadConfigFileSnapshot).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps --json as a strict parsing alias", async () => {
|
||||
await expect(
|
||||
runConfigCommand(["config", "set", "gateway.auth.mode", "{bad", "--json"]),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
|
||||
expect(mockWriteConfigFile).not.toHaveBeenCalled();
|
||||
expect(mockReadConfigFileSnapshot).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("shows --strict-json and keeps --json as a legacy alias in help", async () => {
|
||||
const { registerConfigCli } = await import("./config-cli.js");
|
||||
const program = new Command();
|
||||
registerConfigCli(program);
|
||||
|
||||
const configCommand = program.commands.find((command) => command.name() === "config");
|
||||
const setCommand = configCommand?.commands.find((command) => command.name() === "set");
|
||||
const helpText = setCommand?.helpInformation() ?? "";
|
||||
|
||||
expect(helpText).toContain("--strict-json");
|
||||
expect(helpText).toContain("--json");
|
||||
expect(helpText).toContain("Legacy alias for --strict-json");
|
||||
});
|
||||
});
|
||||
|
||||
describe("config unset - issue #6070", () => {
|
||||
it("preserves existing config keys when unsetting a value", async () => {
|
||||
const resolved: OpenClawConfig = {
|
||||
|
||||
Reference in New Issue
Block a user