mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-01 04:11:03 +00:00
fix(cli): route logs to stderr in --json mode to keep stdout clean
This commit is contained in:
committed by
Peter Steinberger
parent
b863e1c315
commit
ebb4cc0128
@@ -5,6 +5,7 @@ const setVerboseMock = vi.fn();
|
||||
const emitCliBannerMock = vi.fn();
|
||||
const ensureConfigReadyMock = vi.fn(async () => {});
|
||||
const ensurePluginRegistryLoadedMock = vi.fn();
|
||||
const routeLogsToStderrMock = vi.fn();
|
||||
|
||||
const runtimeMock = {
|
||||
log: vi.fn(),
|
||||
@@ -24,6 +25,10 @@ vi.mock("../banner.js", () => ({
|
||||
emitCliBanner: emitCliBannerMock,
|
||||
}));
|
||||
|
||||
vi.mock("../../logging/console.js", () => ({
|
||||
routeLogsToStderr: routeLogsToStderrMock,
|
||||
}));
|
||||
|
||||
vi.mock("../cli-name.js", () => ({
|
||||
resolveCliName: () => "openclaw",
|
||||
}));
|
||||
@@ -270,6 +275,35 @@ describe("registerPreActionHooks", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("routes logs to stderr in --json mode so stdout stays clean", async () => {
|
||||
await runPreAction({
|
||||
parseArgv: ["agents"],
|
||||
processArgv: ["node", "openclaw", "agents", "--json"],
|
||||
});
|
||||
|
||||
expect(routeLogsToStderrMock).toHaveBeenCalledOnce();
|
||||
|
||||
vi.clearAllMocks();
|
||||
|
||||
// config set --json is parse-only (not JSON output mode), should not route
|
||||
await runPreAction({
|
||||
parseArgv: ["config", "set", "gateway.auth.mode", "local", "--json"],
|
||||
processArgv: ["node", "openclaw", "config", "set", "gateway.auth.mode", "local", "--json"],
|
||||
});
|
||||
|
||||
expect(routeLogsToStderrMock).not.toHaveBeenCalled();
|
||||
|
||||
vi.clearAllMocks();
|
||||
|
||||
// non-json command should not route
|
||||
await runPreAction({
|
||||
parseArgv: ["agents"],
|
||||
processArgv: ["node", "openclaw", "agents"],
|
||||
});
|
||||
|
||||
expect(routeLogsToStderrMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("bypasses config guard for config validate", async () => {
|
||||
await runPreAction({
|
||||
parseArgv: ["config", "validate"],
|
||||
|
||||
Reference in New Issue
Block a user