|
1 | 1 | /** |
2 | 2 | * @vitest-environment node |
3 | 3 | * |
4 | | - * These pin transport policy against the vendored SDK rather than against a number |
5 | | - * typed from memory: if an `openai` bump moves `DEFAULT_TIMEOUT` or the retry default, |
6 | | - * this fails and the divergence is a decision rather than a surprise. |
| 4 | + * Pinned against the vendored SDKs rather than against numbers typed from memory: if an |
| 5 | + * SDK bump moves a default, these fail and the divergence becomes a decision instead of |
| 6 | + * a surprise. |
7 | 7 | */ |
| 8 | +import Cerebras from '@cerebras/cerebras_cloud_sdk' |
| 9 | +import Groq from 'groq-sdk' |
| 10 | +import OpenAI from 'openai' |
8 | 11 | import { describe, expect, it } from 'vitest' |
9 | 12 | import { |
10 | 13 | openAICompatTransport, |
11 | | - PROVIDER_DISCOVERY_TIMEOUT_MS, |
12 | 14 | PROVIDER_HEADERS_TIMEOUT_MS, |
13 | 15 | PROVIDER_MAX_RETRIES, |
14 | 16 | } from '@/providers/transport' |
15 | 17 |
|
16 | 18 | describe('provider transport policy', () => { |
17 | | - it('pins the headers budget to the vendored OpenAI client default', async () => { |
18 | | - const { default: OpenAI } = await import('openai') |
19 | | - expect(PROVIDER_HEADERS_TIMEOUT_MS).toBe( |
20 | | - (OpenAI as unknown as { DEFAULT_TIMEOUT: number }).DEFAULT_TIMEOUT |
21 | | - ) |
22 | | - expect(PROVIDER_HEADERS_TIMEOUT_MS).toBe(600_000) |
| 19 | + it('pins the headers budget to the vendored OpenAI client default', () => { |
| 20 | + expect(PROVIDER_HEADERS_TIMEOUT_MS).toBe(OpenAI.DEFAULT_TIMEOUT) |
23 | 21 | }) |
24 | 22 |
|
25 | 23 | /** |
26 | | - * Not lowered to 0 on purpose. A chat completion is non-idempotent and carries no |
27 | | - * idempotency key, and on the non-streaming path the response exists only once the |
28 | | - * generation is already billed — so a replay re-bills completed work. |
| 24 | + * Not lowered to 0 in favour of a hand-rolled loop: a chat completion is |
| 25 | + * non-idempotent and carries no idempotency key, and on the non-streaming path the |
| 26 | + * response exists only once the generation is already billed, so a replay re-bills |
| 27 | + * completed work. |
29 | 28 | */ |
30 | 29 | it('keeps the vendor retry default rather than hand-rolling one', () => { |
31 | | - expect(PROVIDER_MAX_RETRIES).toBe(2) |
| 30 | + expect(PROVIDER_MAX_RETRIES).toBe(OpenAI.DEFAULT_MAX_RETRIES ?? 2) |
32 | 31 | }) |
33 | 32 |
|
34 | | - it('stamps only constructor-safe options, since clients are memoised', () => { |
35 | | - expect(openAICompatTransport()).toEqual({ timeout: 600_000, maxRetries: 2 }) |
| 33 | + /** |
| 34 | + * The assertion that matters: object spread gets no excess-property checking, so a |
| 35 | + * renamed option in either SDK would become a silent no-op with a green typecheck. |
| 36 | + * These read the value back off a constructed client. |
| 37 | + */ |
| 38 | + it('actually reaches the Groq client, which defaults to 60s', () => { |
| 39 | + const client = new Groq({ apiKey: 'test', ...openAICompatTransport() }) |
| 40 | + expect(client.timeout).toBe(PROVIDER_HEADERS_TIMEOUT_MS) |
| 41 | + expect(client.maxRetries).toBe(PROVIDER_MAX_RETRIES) |
| 42 | + }) |
| 43 | + |
| 44 | + it('actually reaches the Cerebras client, which defaults to 60s', () => { |
| 45 | + const client = new Cerebras({ apiKey: 'test', ...openAICompatTransport() }) |
| 46 | + expect(client.timeout).toBe(PROVIDER_HEADERS_TIMEOUT_MS) |
| 47 | + expect(client.maxRetries).toBe(PROVIDER_MAX_RETRIES) |
| 48 | + }) |
| 49 | + |
| 50 | + it('actually reaches an OpenAI-compatible client', () => { |
| 51 | + const client = new OpenAI({ |
| 52 | + apiKey: 'test', |
| 53 | + baseURL: 'https://example.invalid', |
| 54 | + ...openAICompatTransport(), |
| 55 | + }) |
| 56 | + expect(client.timeout).toBe(PROVIDER_HEADERS_TIMEOUT_MS) |
| 57 | + expect(client.maxRetries).toBe(PROVIDER_MAX_RETRIES) |
36 | 58 | }) |
37 | 59 |
|
38 | | - /** A catalog probe must not inherit a generation-sized budget. */ |
39 | | - it('bounds discovery far below a generation', () => { |
40 | | - expect(PROVIDER_DISCOVERY_TIMEOUT_MS).toBeLessThan(PROVIDER_HEADERS_TIMEOUT_MS / 10) |
| 60 | + /** Stamping a `fetch` wrapper here would convert a header-only timer into a total |
| 61 | + * deadline that truncates live streams, so the shape is pinned too. */ |
| 62 | + it('stamps only constructor-safe options', () => { |
| 63 | + expect(Object.keys(openAICompatTransport()).sort()).toEqual(['maxRetries', 'timeout']) |
41 | 64 | }) |
42 | 65 | }) |
0 commit comments