|
1 | | -import { describe, expect, it } from "vitest"; |
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
2 | 2 | import { withEnvAsync } from "../test-utils/env.js"; |
3 | 3 | import { withFetchPreconnect } from "../test-utils/fetch-mock.js"; |
4 | 4 | import { scanOpenRouterModels } from "./model-scan.js"; |
5 | 5 | |
| 6 | +const MAX_TIMER_TIMEOUT_MS = 2_147_000_000; |
| 7 | + |
6 | 8 | function createFetchFixture(payload: unknown): typeof fetch { |
7 | 9 | return withFetchPreconnect( |
8 | 10 | async () => |
@@ -14,6 +16,10 @@ function createFetchFixture(payload: unknown): typeof fetch {
|
14 | 16 | } |
15 | 17 | |
16 | 18 | describe("scanOpenRouterModels", () => { |
| 19 | +afterEach(() => { |
| 20 | +vi.restoreAllMocks(); |
| 21 | +}); |
| 22 | + |
17 | 23 | it("lists free models without probing", async () => { |
18 | 24 | const fetchImpl = createFetchFixture({ |
19 | 25 | data: [ |
@@ -102,6 +108,22 @@ describe("scanOpenRouterModels", () => {
|
102 | 108 | ).rejects.toThrow(/catalog aborted/); |
103 | 109 | }); |
104 | 110 | |
| 111 | +it("caps oversized scan timeouts before scheduling catalog aborts", async () => { |
| 112 | +const timeoutSpy = vi |
| 113 | +.spyOn(globalThis, "setTimeout") |
| 114 | +.mockReturnValue(1 as unknown as ReturnType<typeof setTimeout>); |
| 115 | +vi.spyOn(globalThis, "clearTimeout").mockImplementation(() => undefined); |
| 116 | +const fetchImpl = createFetchFixture({ data: [] }); |
| 117 | + |
| 118 | +await scanOpenRouterModels({ |
| 119 | + fetchImpl, |
| 120 | +probe: false, |
| 121 | +timeoutMs: MAX_TIMER_TIMEOUT_MS + 1_000_000, |
| 122 | +}); |
| 123 | + |
| 124 | +expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS); |
| 125 | +}); |
| 126 | + |
105 | 127 | it("does not match provider filters across provider id variants", async () => { |
106 | 128 | const fetchImpl = createFetchFixture({ |
107 | 129 | data: [ |
|