@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
3 | 3 | import os from "node:os"; |
4 | 4 | import path from "node:path"; |
5 | 5 | import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; |
| 6 | +import { MAX_SAFE_TIMEOUT_DELAY_MS } from "../../../gateway-client/src/timeouts.js"; |
6 | 7 | |
7 | 8 | const spawnMock = vi.hoisted(() => vi.fn()); |
8 | 9 | |
@@ -64,6 +65,7 @@ beforeEach(async () => {
|
64 | 65 | }); |
65 | 66 | |
66 | 67 | afterEach(() => { |
| 68 | +vi.useRealTimers(); |
67 | 69 | process.env.PATH = originalPath; |
68 | 70 | process.env.PATHEXT = originalPathExt; |
69 | 71 | spawnMock.mockReset(); |
@@ -199,6 +201,22 @@ describe("checkQmdBinaryAvailability", () => {
|
199 | 201 | checkQmdBinaryAvailability({ command: "qmd", env: process.env, cwd: tempDir }), |
200 | 202 | ).resolves.toEqual({ available: false, reason: "binary", error: "spawn qmd ENOENT" }); |
201 | 203 | }); |
| 204 | + |
| 205 | +it("caps oversized availability probe timeouts before scheduling", async () => { |
| 206 | +vi.useFakeTimers(); |
| 207 | +const child = createMockChild(); |
| 208 | +const timeoutSpy = vi.spyOn(globalThis, "setTimeout"); |
| 209 | +spawnMock.mockReturnValueOnce(child); |
| 210 | + |
| 211 | +void checkQmdBinaryAvailability({ |
| 212 | +command: "qmd", |
| 213 | +env: process.env, |
| 214 | +cwd: tempDir, |
| 215 | +timeoutMs: Number.MAX_SAFE_INTEGER, |
| 216 | +}); |
| 217 | + |
| 218 | +expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_SAFE_TIMEOUT_DELAY_MS); |
| 219 | +}); |
202 | 220 | }); |
203 | 221 | |
204 | 222 | describe("runCliCommand", () => { |
@@ -304,4 +322,22 @@ describe("runCliCommand", () => {
|
304 | 322 | }), |
305 | 323 | ).rejects.toThrow(/🙂/); |
306 | 324 | }); |
| 325 | + |
| 326 | +it("caps oversized command timeouts before scheduling", async () => { |
| 327 | +vi.useFakeTimers(); |
| 328 | +const child = createMockChild(); |
| 329 | +const timeoutSpy = vi.spyOn(globalThis, "setTimeout"); |
| 330 | +spawnMock.mockReturnValueOnce(child); |
| 331 | + |
| 332 | +void runCliCommand({ |
| 333 | +commandSummary: "qmd query test", |
| 334 | +spawnInvocation: { command: "qmd", argv: ["query", "test", "--json"] }, |
| 335 | +env: process.env, |
| 336 | +cwd: tempDir, |
| 337 | +maxOutputChars: 10_000, |
| 338 | +timeoutMs: Number.MAX_SAFE_INTEGER, |
| 339 | +}).catch(() => undefined); |
| 340 | + |
| 341 | +expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_SAFE_TIMEOUT_DELAY_MS); |
| 342 | +}); |
307 | 343 | }); |