























@@ -2,7 +2,7 @@ import fs from "node:fs";
22import os from "node:os";
33import path from "node:path";
44import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
5-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5+import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
66import type { OpenClawConfig } from "../config/config.js";
77import { loggingState } from "../logging/state.js";
88import type { RuntimeEnv } from "../runtime.js";
@@ -219,15 +219,20 @@ vi.mock("./agent.js", () => {
219219});
220220221221let originalForceConsoleToStderr = false;
222+let zeroTimeoutGatewayRequestMs: number | undefined;
222223223-beforeEach(() => {
224+function resetAgentCliCommandMocksForTest() {
224225vi.clearAllMocks();
225226agentViaGatewayTesting.resetLazyImportsForTests();
226227agentViaGatewayTesting.setGatewayAbortRetryDelaysMsForTests([0, 0, 0, 0]);
227228loadAgentSessionModuleMock.mockImplementation(async () => await import("./agent/session.js"));
228229agentViaGatewayTesting.setAgentSessionModuleLoaderForTests(loadAgentSessionModuleMock);
229230originalForceConsoleToStderr = loggingState.forceConsoleToStderr;
230231loggingState.forceConsoleToStderr = false;
232+}
233+234+beforeEach(() => {
235+resetAgentCliCommandMocksForTest();
231236});
232237233238afterEach(() => {
@@ -236,16 +241,27 @@ afterEach(() => {
236241});
237242238243describe("agentCliCommand", () => {
239-it("uses a timer-safe max gateway timeout when --timeout is 0", async () => {
240-await withTempStore(async () => {
241-mockGatewaySuccessReply();
244+beforeAll(async () => {
245+const restoreForceConsoleToStderr = loggingState.forceConsoleToStderr;
246+resetAgentCliCommandMocksForTest();
247+try {
248+await withTempStore(async () => {
249+mockGatewaySuccessReply();
242250243-await agentCliCommand({ message: "hi", to: "+1555", timeout: "0" }, runtime);
251+ await agentCliCommand({ message: "hi", to: "+1555", timeout: "0" }, runtime);
244252245-expect(callGateway).toHaveBeenCalledTimes(1);
246-const request = requireFirstCallArg(callGateway, "gateway") as { timeoutMs?: number };
247-expect(request.timeoutMs).toBe(2_147_000_000);
248-});
253+expect(callGateway).toHaveBeenCalledTimes(1);
254+const request = requireFirstCallArg(callGateway, "gateway") as { timeoutMs?: number };
255+zeroTimeoutGatewayRequestMs = request.timeoutMs;
256+});
257+} finally {
258+agentViaGatewayTesting.setGatewayAbortRetryDelaysMsForTests();
259+loggingState.forceConsoleToStderr = restoreForceConsoleToStderr;
260+}
261+});
262+263+it("uses a timer-safe max gateway timeout when --timeout is 0", () => {
264+expect(zeroTimeoutGatewayRequestMs).toBe(2_147_000_000);
249265});
250266251267it("clamps oversized gateway timeout seconds", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。