




















1+import { beforeEach, describe, expect, it, vi } from "vitest";
2+import { MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js";
3+import {
4+createPluginCliGatewayNodesRuntime,
5+resolvePluginCliNodeInvokeGatewayTimeoutMs,
6+} from "./cli-gateway-nodes-runtime.js";
7+8+const callGatewayMock = vi.fn();
9+10+vi.mock("../gateway/call.js", () => ({
11+callGateway: (opts: unknown) => callGatewayMock(opts),
12+}));
13+14+describe("createPluginCliGatewayNodesRuntime", () => {
15+beforeEach(() => {
16+callGatewayMock.mockReset();
17+callGatewayMock.mockResolvedValue({});
18+});
19+20+it("caps oversized node invoke gateway timeouts", async () => {
21+const nodes = createPluginCliGatewayNodesRuntime();
22+23+await nodes.invoke({
24+nodeId: "node-1",
25+command: "system.run",
26+timeoutMs: Number.MAX_SAFE_INTEGER,
27+});
28+29+expect(callGatewayMock).toHaveBeenCalledWith(
30+expect.objectContaining({
31+method: "node.invoke",
32+timeoutMs: MAX_TIMER_TIMEOUT_MS,
33+params: expect.objectContaining({
34+timeoutMs: Number.MAX_SAFE_INTEGER,
35+}),
36+}),
37+);
38+});
39+});
40+41+describe("resolvePluginCliNodeInvokeGatewayTimeoutMs", () => {
42+it("preserves absent and non-positive timeout behavior", () => {
43+expect(resolvePluginCliNodeInvokeGatewayTimeoutMs(undefined)).toBeUndefined();
44+expect(resolvePluginCliNodeInvokeGatewayTimeoutMs(0)).toBeUndefined();
45+expect(resolvePluginCliNodeInvokeGatewayTimeoutMs(-1)).toBeUndefined();
46+});
47+48+it("adds gateway grace for normal positive timeouts", () => {
49+expect(resolvePluginCliNodeInvokeGatewayTimeoutMs(10_000)).toBe(15_000);
50+});
51+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。