fix: validate gateway call timeouts · openclaw/openclaw@f407e4e
steipete
·
2026-05-27
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -393,6 +393,14 @@ describe("gateway-cli coverage", () => {
|
393 | 393 | expect(runtimeErrors.join("\n")).toContain("Gateway call failed:"); |
394 | 394 | }); |
395 | 395 | |
| 396 | +it("validates gateway call timeout before opening a transport", async () => { |
| 397 | +callGateway.mockClear(); |
| 398 | +await expectGatewayExit(["gateway", "call", "health", "--timeout", "nope", "--json"]); |
| 399 | + |
| 400 | +expect(callGateway).not.toHaveBeenCalled(); |
| 401 | +expect(runtimeErrors.join("\n")).toContain("Invalid --timeout"); |
| 402 | +}); |
| 403 | + |
396 | 404 | it("validates gateway ports and handles force/start errors", async () => { |
397 | 405 | // Invalid port |
398 | 406 | await expectGatewayExit(["gateway", "--port", "0", "--token", "test-token"]); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@ import type { Command } from "commander";
|
2 | 2 | import type { OpenClawConfig } from "../../config/types.openclaw.js"; |
3 | 3 | import { callGateway } from "../../gateway/call.js"; |
4 | 4 | import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../../gateway/protocol/client-info.js"; |
| 5 | +import { parseTimeoutMsWithFallback } from "../parse-timeout.js"; |
5 | 6 | import { withProgress } from "../progress.js"; |
6 | 7 | |
7 | 8 | export type GatewayRpcOpts = { |
@@ -14,6 +15,8 @@ export type GatewayRpcOpts = {
|
14 | 15 | json?: boolean; |
15 | 16 | }; |
16 | 17 | |
| 18 | +const DEFAULT_GATEWAY_RPC_TIMEOUT_MS = 10_000; |
| 19 | + |
17 | 20 | export const gatewayCallOpts = (cmd: Command) => |
18 | 21 | cmd |
19 | 22 | .option("--url <url>", "Gateway WebSocket URL (defaults to gateway.remote.url when configured)") |
@@ -39,7 +42,7 @@ export const callGatewayCli = async (method: string, opts: GatewayRpcOpts, param
|
39 | 42 | method, |
40 | 43 | params, |
41 | 44 | expectFinal: Boolean(opts.expectFinal), |
42 | | -timeoutMs: Number(opts.timeout ?? 10_000), |
| 45 | +timeoutMs: parseTimeoutMsWithFallback(opts.timeout, DEFAULT_GATEWAY_RPC_TIMEOUT_MS), |
43 | 46 | clientName: GATEWAY_CLIENT_NAMES.CLI, |
44 | 47 | mode: GATEWAY_CLIENT_MODES.CLI, |
45 | 48 | }), |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。