CLI: route gateway status through daemon status

This commit is contained in:
Vincent Koc
2026-03-15 21:11:39 -07:00
parent 7e8f5ca71b
commit cb4a298961
2 changed files with 64 additions and 28 deletions

View File

@@ -5,7 +5,7 @@ const runConfigGetMock = vi.hoisted(() => vi.fn(async () => {}));
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 runDaemonStatusMock = vi.hoisted(() => vi.fn(async () => {}));
const statusJsonCommandMock = vi.hoisted(() => vi.fn(async () => {}));
vi.mock("../config-cli.js", () => ({
@@ -18,8 +18,8 @@ vi.mock("../../commands/models.js", () => ({
modelsStatusCommand: modelsStatusCommandMock,
}));
vi.mock("../../commands/gateway-status.js", () => ({
gatewayStatusCommand: gatewayStatusCommandMock,
vi.mock("../daemon-cli/status.js", () => ({
runDaemonStatus: runDaemonStatusMock,
}));
vi.mock("../../commands/status-json.js", () => ({
@@ -77,14 +77,24 @@ describe("program routes", () => {
["gateway", "status"],
["node", "openclaw", "gateway", "status", "--timeout"],
);
await expectRunFalse(["gateway", "status"], ["node", "openclaw", "gateway", "status", "--ssh"]);
});
it("returns false for gateway status route when probe-only flags are present", async () => {
await expectRunFalse(
["gateway", "status"],
["node", "openclaw", "gateway", "status", "--ssh-identity"],
["node", "openclaw", "gateway", "status", "--ssh", "user@host"],
);
await expectRunFalse(
["gateway", "status"],
["node", "openclaw", "gateway", "status", "--ssh-identity", "~/.ssh/id_test"],
);
await expectRunFalse(
["gateway", "status"],
["node", "openclaw", "gateway", "status", "--ssh-auto"],
);
});
it("passes parsed gateway status flags through", async () => {
it("passes parsed gateway status flags through to daemon status", async () => {
const route = expectRoute(["gateway", "status"]);
await expect(
route?.run([
@@ -102,27 +112,43 @@ describe("program routes", () => {
"def",
"--timeout",
"5000",
"--ssh",
"user@host",
"--ssh-identity",
"~/.ssh/id_test",
"--ssh-auto",
"--deep",
"--require-rpc",
"--json",
]),
).resolves.toBe(true);
expect(gatewayStatusCommandMock).toHaveBeenCalledWith(
{
expect(runDaemonStatusMock).toHaveBeenCalledWith({
rpc: {
url: "ws://127.0.0.1:18789",
token: "abc",
password: "def",
timeout: "5000",
json: true,
ssh: "user@host",
sshIdentity: "~/.ssh/id_test",
sshAuto: true,
},
expect.any(Object),
probe: true,
requireRpc: true,
deep: true,
json: true,
});
});
it("passes --no-probe through to daemon status", async () => {
const route = expectRoute(["gateway", "status"]);
await expect(route?.run(["node", "openclaw", "gateway", "status", "--no-probe"])).resolves.toBe(
true,
);
expect(runDaemonStatusMock).toHaveBeenCalledWith({
rpc: {
url: undefined,
token: undefined,
password: undefined,
timeout: undefined,
},
probe: false,
requireRpc: false,
deep: false,
json: false,
});
});
it("returns false when status timeout flag value is missing", async () => {

View File

@@ -81,26 +81,36 @@ const routeGatewayStatus: RouteSpec = {
if (ssh === null) {
return false;
}
if (ssh !== undefined) {
return false;
}
const sshIdentity = getFlagValue(argv, "--ssh-identity");
if (sshIdentity === null) {
return false;
}
const sshAuto = hasFlag(argv, "--ssh-auto");
if (sshIdentity !== undefined) {
return false;
}
if (hasFlag(argv, "--ssh-auto")) {
return false;
}
const deep = hasFlag(argv, "--deep");
const json = hasFlag(argv, "--json");
const { gatewayStatusCommand } = await import("../../commands/gateway-status.js");
await gatewayStatusCommand(
{
const requireRpc = hasFlag(argv, "--require-rpc");
const probe = !hasFlag(argv, "--no-probe");
const { runDaemonStatus } = await import("../daemon-cli/status.js");
await runDaemonStatus({
rpc: {
url: url ?? undefined,
token: token ?? undefined,
password: password ?? undefined,
timeout: timeout ?? undefined,
json,
ssh: ssh ?? undefined,
sshIdentity: sshIdentity ?? undefined,
sshAuto,
},
defaultRuntime,
);
probe,
requireRpc,
deep,
json,
});
return true;
},
};