






















@@ -0,0 +1,56 @@
1+import { beforeEach, describe, expect, it, vi } from "vitest";
2+3+const callGatewayMock = vi.fn(async () => ({ ok: true }));
4+vi.mock("../gateway/call.js", () => ({
5+callGateway: callGatewayMock,
6+}));
7+8+vi.mock("./progress.js", () => ({
9+withProgress: async (_options: unknown, action: () => Promise<unknown>) => await action(),
10+}));
11+12+const { callGatewayFromCliRuntime } = await import("./gateway-rpc.runtime.js");
13+14+describe("callGatewayFromCliRuntime", () => {
15+beforeEach(() => {
16+callGatewayMock.mockClear().mockResolvedValue({ ok: true });
17+});
18+19+it.each([
20+["cron status", "cron.status"],
21+["cron list", "cron.list"],
22+["cron add", "cron.add"],
23+["cron update", "cron.update"],
24+["cron remove", "cron.remove"],
25+["cron get", "cron.get"],
26+["cron runs", "cron.runs"],
27+["cron run", "cron.run"],
28+["logs", "logs.tail"],
29+["secrets reload", "secrets.reload"],
30+])("rejects malformed shared --timeout before gateway call for %s", async (_name, method) => {
31+await expect(callGatewayFromCliRuntime(method, { timeout: "10ms" })).rejects.toThrow(
32+'Invalid --timeout. Use a positive millisecond value, e.g. --timeout 30000. Received: "10ms".',
33+);
34+35+expect(callGatewayMock).not.toHaveBeenCalled();
36+});
37+38+it.each(["0", "-1", "1.5"])("rejects invalid shared --timeout value %j", async (timeout) => {
39+await expect(callGatewayFromCliRuntime("cron.status", { timeout })).rejects.toThrow(
40+`Received: "${timeout}"`,
41+);
42+43+expect(callGatewayMock).not.toHaveBeenCalled();
44+});
45+46+it("passes strict integer timeouts to the gateway call", async () => {
47+await callGatewayFromCliRuntime("cron.status", { timeout: "15000" });
48+49+expect(callGatewayMock).toHaveBeenCalledWith(
50+expect.objectContaining({
51+method: "cron.status",
52+timeoutMs: 15_000,
53+}),
54+);
55+});
56+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。