mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:00:42 +00:00
CLI: route gateway status through daemon status
This commit is contained in:
@@ -5,7 +5,7 @@ const runConfigGetMock = vi.hoisted(() => vi.fn(async () => {}));
|
|||||||
const runConfigUnsetMock = vi.hoisted(() => vi.fn(async () => {}));
|
const runConfigUnsetMock = vi.hoisted(() => vi.fn(async () => {}));
|
||||||
const modelsListCommandMock = vi.hoisted(() => vi.fn(async () => {}));
|
const modelsListCommandMock = vi.hoisted(() => vi.fn(async () => {}));
|
||||||
const modelsStatusCommandMock = 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 () => {}));
|
const statusJsonCommandMock = vi.hoisted(() => vi.fn(async () => {}));
|
||||||
|
|
||||||
vi.mock("../config-cli.js", () => ({
|
vi.mock("../config-cli.js", () => ({
|
||||||
@@ -18,8 +18,8 @@ vi.mock("../../commands/models.js", () => ({
|
|||||||
modelsStatusCommand: modelsStatusCommandMock,
|
modelsStatusCommand: modelsStatusCommandMock,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../../commands/gateway-status.js", () => ({
|
vi.mock("../daemon-cli/status.js", () => ({
|
||||||
gatewayStatusCommand: gatewayStatusCommandMock,
|
runDaemonStatus: runDaemonStatusMock,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../../commands/status-json.js", () => ({
|
vi.mock("../../commands/status-json.js", () => ({
|
||||||
@@ -77,14 +77,24 @@ describe("program routes", () => {
|
|||||||
["gateway", "status"],
|
["gateway", "status"],
|
||||||
["node", "openclaw", "gateway", "status", "--timeout"],
|
["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(
|
await expectRunFalse(
|
||||||
["gateway", "status"],
|
["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"]);
|
const route = expectRoute(["gateway", "status"]);
|
||||||
await expect(
|
await expect(
|
||||||
route?.run([
|
route?.run([
|
||||||
@@ -102,27 +112,43 @@ describe("program routes", () => {
|
|||||||
"def",
|
"def",
|
||||||
"--timeout",
|
"--timeout",
|
||||||
"5000",
|
"5000",
|
||||||
"--ssh",
|
"--deep",
|
||||||
"user@host",
|
"--require-rpc",
|
||||||
"--ssh-identity",
|
|
||||||
"~/.ssh/id_test",
|
|
||||||
"--ssh-auto",
|
|
||||||
"--json",
|
"--json",
|
||||||
]),
|
]),
|
||||||
).resolves.toBe(true);
|
).resolves.toBe(true);
|
||||||
expect(gatewayStatusCommandMock).toHaveBeenCalledWith(
|
expect(runDaemonStatusMock).toHaveBeenCalledWith({
|
||||||
{
|
rpc: {
|
||||||
url: "ws://127.0.0.1:18789",
|
url: "ws://127.0.0.1:18789",
|
||||||
token: "abc",
|
token: "abc",
|
||||||
password: "def",
|
password: "def",
|
||||||
timeout: "5000",
|
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 () => {
|
it("returns false when status timeout flag value is missing", async () => {
|
||||||
|
|||||||
@@ -81,26 +81,36 @@ const routeGatewayStatus: RouteSpec = {
|
|||||||
if (ssh === null) {
|
if (ssh === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (ssh !== undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const sshIdentity = getFlagValue(argv, "--ssh-identity");
|
const sshIdentity = getFlagValue(argv, "--ssh-identity");
|
||||||
if (sshIdentity === null) {
|
if (sshIdentity === null) {
|
||||||
return false;
|
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 json = hasFlag(argv, "--json");
|
||||||
const { gatewayStatusCommand } = await import("../../commands/gateway-status.js");
|
const requireRpc = hasFlag(argv, "--require-rpc");
|
||||||
await gatewayStatusCommand(
|
const probe = !hasFlag(argv, "--no-probe");
|
||||||
{
|
const { runDaemonStatus } = await import("../daemon-cli/status.js");
|
||||||
|
await runDaemonStatus({
|
||||||
|
rpc: {
|
||||||
url: url ?? undefined,
|
url: url ?? undefined,
|
||||||
token: token ?? undefined,
|
token: token ?? undefined,
|
||||||
password: password ?? undefined,
|
password: password ?? undefined,
|
||||||
timeout: timeout ?? undefined,
|
timeout: timeout ?? undefined,
|
||||||
json,
|
|
||||||
ssh: ssh ?? undefined,
|
|
||||||
sshIdentity: sshIdentity ?? undefined,
|
|
||||||
sshAuto,
|
|
||||||
},
|
},
|
||||||
defaultRuntime,
|
probe,
|
||||||
);
|
requireRpc,
|
||||||
|
deep,
|
||||||
|
json,
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user