Status: route JSON through lean command

This commit is contained in:
Vincent Koc
2026-03-15 20:56:44 -07:00
parent 1f50fed3b2
commit ca2f046668
3 changed files with 130 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ const runConfigUnsetMock = vi.hoisted(() => vi.fn(async () => {}));
const modelsListCommandMock = vi.hoisted(() => vi.fn(async () => {}));
const modelsStatusCommandMock = vi.hoisted(() => vi.fn(async () => {}));
const gatewayStatusCommandMock = vi.hoisted(() => vi.fn(async () => {}));
const statusJsonCommandMock = vi.hoisted(() => vi.fn(async () => {}));
vi.mock("../config-cli.js", () => ({
runConfigGet: runConfigGetMock,
@@ -21,6 +22,10 @@ vi.mock("../../commands/gateway-status.js", () => ({
gatewayStatusCommand: gatewayStatusCommandMock,
}));
vi.mock("../../commands/status-json.js", () => ({
statusJsonCommand: statusJsonCommandMock,
}));
describe("program routes", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -124,6 +129,26 @@ describe("program routes", () => {
await expectRunFalse(["status"], ["node", "openclaw", "status", "--timeout"]);
});
it("routes status --json through the lean JSON command", async () => {
const route = expectRoute(["status"]);
await expect(
route?.run([
"node",
"openclaw",
"status",
"--json",
"--deep",
"--usage",
"--timeout",
"5000",
]),
).resolves.toBe(true);
expect(statusJsonCommandMock).toHaveBeenCalledWith(
{ deep: true, all: false, usage: true, timeoutMs: 5000 },
expect.any(Object),
);
});
it("returns false for sessions route when --store value is missing", async () => {
await expectRunFalse(["sessions"], ["node", "openclaw", "sessions", "--store"]);
});

View File

@@ -47,6 +47,11 @@ const routeStatus: RouteSpec = {
if (timeoutMs === null) {
return false;
}
if (json) {
const { statusJsonCommand } = await import("../../commands/status-json.js");
await statusJsonCommand({ deep, all, usage, timeoutMs }, defaultRuntime);
return true;
}
const { statusCommand } = await import("../../commands/status.js");
await statusCommand({ json, deep, all, usage, timeoutMs, verbose }, defaultRuntime);
return true;