fix(typecheck): correct fetch mock type casts in test files (#1592)

* fix(typecheck): correct fetch mock type casts in test files

Test files were casting mock functions to 'typeof fetch' but the mock
signatures didn't match the full fetch type (missing init parameter,
wrong return type, etc.), causing TS2352 errors.

Changes:
- Use double-cast pattern: 'as unknown as typeof fetch' or 'as unknown as FetchType'
- Remove unused @ts-expect-error directive in providerDiscovery.test.ts
- Applied consistently across 6 test files

Files modified:
- src/utils/providerDiscovery.test.ts (11 errors fixed)
- src/services/api/openaiShim.test.ts (9 errors fixed)
- src/tools/firecrawl/client.test.ts (5 errors fixed)
- src/utils/apiPreconnect.test.ts (4 errors fixed)
- src/services/api/codexOAuth.test.ts (2 errors fixed)
- src/services/api/fetchWithProxyRetry.test.ts (1 error fixed)

Testing:
- bun test [all 6 files]: 154/154 pass
- bun run smoke: pass
- Typecheck errors: 682 → 664 (-18)

* chore: trigger CI re-run (flaky test investigation)
This commit is contained in:
Bogdan
2026-06-10 21:55:14 +08:00
committed by GitHub
parent 9db9427f29
commit 794ccd4f9e
6 changed files with 133 additions and 134 deletions
+2 -2
View File
@@ -217,7 +217,7 @@ test('serves updated success copy after a successful Codex OAuth flow', async ()
headers: { 'Content-Type': 'application/json' },
},
)
}) as typeof fetch
}) as unknown as typeof fetch
const service = new CodexOAuthService({
callbackPort: 0,
@@ -284,7 +284,7 @@ test('cancellation during token exchange returns a cancelled page and rejects th
{ once: true },
)
})
}) as typeof fetch
}) as unknown as typeof fetch
const service = new CodexOAuthService({
callbackPort: 0,
+3 -3
View File
@@ -62,7 +62,7 @@ test('fetchWithProxyRetry retries once with keepalive disabled after socket clos
)
}
return new Response('ok')
}) as FetchType
}) as unknown as FetchType
const response = await fetchWithProxyRetry('https://example.com/search', {
method: 'POST',
@@ -83,7 +83,7 @@ test('fetchWithProxyRetry does not retry non-network errors', async () => {
globalThis.fetch = (async () => {
attempts += 1
throw new Error('400 bad request')
}) as FetchType
}) as unknown as FetchType
await expect(fetchWithProxyRetry('https://example.com')).rejects.toThrow(
'400 bad request',
@@ -100,7 +100,7 @@ test('fetchWithProxyRetry retries and disables keepalive after receiving a 504 r
return new Response('Gateway Timeout', { status: 504 })
}
return new Response('ok')
}) as FetchType
}) as unknown as FetchType
const response = await fetchWithProxyRetry('https://example.com/search')
expect(response.status).toBe(200)
+108 -108
View File
@@ -128,7 +128,7 @@ async function captureChatCompletionRequest(
authorization = headers?.Authorization ?? headers?.authorization ?? null
return makeChatCompletionResponse(model)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -255,7 +255,7 @@ test('strips canonical Anthropic headers from direct shim defaultHeaders', async
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({
defaultHeaders: {
@@ -318,7 +318,7 @@ test('uses OpenAI-compatible responses endpoint when OPENAI_API_FORMAT=responses
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -376,7 +376,7 @@ test('uses OpenAI-compatible responses endpoint with text chunk types when OPENA
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -412,7 +412,7 @@ test('uses correct empty input fallback schema for standard responses and respon
model: 'test',
output: [{ type: 'message', role: 'assistant', content: [{ type: 'output_text', text: 'ok' }] }]
}), { headers: { 'Content-Type': 'application/json' } })
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -475,7 +475,7 @@ test('strips store from strict OpenAI-compatible responses providers', async ()
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -502,7 +502,7 @@ test('strips store when providerOverride routes chat_completions to the Gemini h
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({
defaultHeaders: {},
@@ -542,7 +542,7 @@ test('strips store when providerOverride routes responses API to the Gemini host
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({
defaultHeaders: {},
@@ -583,7 +583,7 @@ test('uses custom OpenAI-compatible auth header value when configured', async ()
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -617,7 +617,7 @@ test('uses Hicap api-key auth header for the Hicap route', async () => {
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -651,7 +651,7 @@ test('defaults Authorization custom auth header to bearer scheme', async () => {
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -685,7 +685,7 @@ test('honors bearer scheme for custom OpenAI-compatible auth headers', async ()
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -719,7 +719,7 @@ test('ignores custom auth header value when no custom header is configured', asy
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -764,7 +764,7 @@ test('strips canonical Anthropic headers from per-request shim headers too', asy
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -847,7 +847,7 @@ test('applies descriptor static headers before client and request headers', asyn
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({
defaultHeaders: {
@@ -939,7 +939,7 @@ test('opengateway sends Accept-Encoding: identity header on chat requests', asyn
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -974,7 +974,7 @@ test('strips Anthropic-specific headers on GitHub Codex transport requests', asy
'Content-Type': 'text/event-stream',
},
})
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1021,7 +1021,7 @@ test('strips Anthropic-specific headers on GitHub Codex transport with providerO
'Content-Type': 'text/event-stream',
},
})
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({
providerOverride: {
@@ -1103,7 +1103,7 @@ test('preserves usage from final OpenAI stream chunk with empty choices', async
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1165,7 +1165,7 @@ test('uses max_tokens instead of max_completion_tokens for local providers', asy
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1210,7 +1210,7 @@ test('keeps max_completion_tokens for non-local non-github providers', async ()
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1258,7 +1258,7 @@ test('uses route-specific credential env vars for descriptor-backed openai-compa
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1303,7 +1303,7 @@ test('preserves Gemini tool call extra_content in follow-up requests', async ()
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1394,7 +1394,7 @@ test('replays Gemini tool signatures for OpenGateway Gemini models', async () =>
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1471,7 +1471,7 @@ test('OpenGateway MiMo replays real reasoning_content without adding empty fallb
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1554,7 +1554,7 @@ test('Xiaomi MiMo replays real reasoning_content without adding empty fallback',
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1635,7 +1635,7 @@ test('OpenGateway MiMo does not synthesize empty reasoning_content when missing'
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1720,7 +1720,7 @@ test('strips unsupported stream_options for Xiaomi MiMo streams', async () => {
},
]),
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1770,7 +1770,7 @@ test('preserves Grep tool pattern field in OpenAI-compatible schemas', async ()
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1844,7 +1844,7 @@ test('does not infer Gemini mode from OPENAI_BASE_URL path substrings', async ()
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1889,7 +1889,7 @@ test('preserves image tool results as placeholders in follow-up requests', async
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -1988,7 +1988,7 @@ test('adds text part for image-only user messages', async () => {
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2064,7 +2064,7 @@ test('preserves mixed text and image tool results as multipart content', async (
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2180,7 +2180,7 @@ test('uses GEMINI_ACCESS_TOKEN for Gemini OpenAI-compatible requests', async ()
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2238,7 +2238,7 @@ test('uses NVIDIA_API_KEY for NVIDIA NIM requests without OPENAI_API_KEY', async
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2288,7 +2288,7 @@ test('does not use stale NVIDIA_API_KEY for non-NVIDIA OpenAI-compatible routes'
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2337,7 +2337,7 @@ test('does not use MINIMAX_API_KEY for non-MiniMax OpenAI-compatible routes', as
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2385,7 +2385,7 @@ test('xiaomi mimo route uses api-key auth header and max_completion_tokens', asy
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2576,7 +2576,7 @@ test('does not use BNKR_API_KEY for non-Bankr OpenAI-compatible routes', async (
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2638,7 +2638,7 @@ test('preserves Gemini tool call extra_content from streaming chunks', async ()
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2725,7 +2725,7 @@ test('preserves Gemini thought signature from streaming delta extra_content', as
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2805,7 +2805,7 @@ test('preserves Gemini thought signature from non-streaming message extra_conten
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2879,7 +2879,7 @@ test('converts Gemini raw tool-call text into streaming tool_use blocks', async
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -2966,7 +2966,7 @@ test('converts Gemini raw tool-call text into non-streaming tool_use blocks', as
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3031,7 +3031,7 @@ test('normalizes plain string Bash tool arguments from OpenAI-compatible respons
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3093,7 +3093,7 @@ test('normalizes Bash tool arguments that are valid JSON strings', async () => {
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3159,7 +3159,7 @@ test.each([
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3220,7 +3220,7 @@ test('keeps terminal empty Bash tool arguments invalid in non-streaming response
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3287,7 +3287,7 @@ test('normalizes plain string Bash tool arguments in streaming responses', async
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3385,7 +3385,7 @@ test('normalizes plain string Bash tool arguments when streaming starts with an
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3483,7 +3483,7 @@ test('normalizes plain string Bash tool arguments when streaming starts with whi
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3559,7 +3559,7 @@ test('keeps terminal whitespace-only Bash arguments invalid in streaming respons
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3635,7 +3635,7 @@ test('normalizes streaming Bash arguments that begin with bracket syntax', async
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3733,7 +3733,7 @@ test('normalizes streaming Bash arguments when the first chunk is only an openin
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3809,7 +3809,7 @@ test('repairs truncated structured Bash JSON in streaming responses', async () =
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3885,7 +3885,7 @@ test('does not normalize incomplete streamed Bash commands when finish_reason is
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -3961,7 +3961,7 @@ test('repairs truncated JSON objects even without command field', async () => {
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4030,7 +4030,7 @@ test('preserves raw input for unknown plain string tool arguments', async () =>
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4090,7 +4090,7 @@ test('preserves parsed string input for unknown JSON string tool arguments', asy
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4145,7 +4145,7 @@ test('sanitizes malformed MCP tool schemas before sending them to OpenAI', async
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4206,7 +4206,7 @@ test('optional tool properties are not added to required[] — fixes Groq/Azure
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4268,7 +4268,7 @@ test('coalesces consecutive user messages to avoid alternation errors (issue #20
globalThis.fetch = (async (_input: unknown, init: RequestInit | undefined) => {
sentMessages = JSON.parse(String(init?.body)).messages
return makeNonStreamResponse()
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4297,7 +4297,7 @@ test('coalesces consecutive assistant messages preserving tool_calls (issue #202
globalThis.fetch = (async (_input: unknown, init: RequestInit | undefined) => {
sentMessages = JSON.parse(String(init?.body)).messages
return makeNonStreamResponse()
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4350,7 +4350,7 @@ test('non-streaming: reasoning_content emitted as thinking block only when conte
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4395,7 +4395,7 @@ test('non-streaming: empty string content does not fall through to reasoning_con
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4440,7 +4440,7 @@ test('non-streaming: real content takes precedence over reasoning_content', asyn
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4482,7 +4482,7 @@ test('non-streaming: strips <think> tag block from assistant content', async ()
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
const result = (await client.beta.messages.create({
@@ -4552,7 +4552,7 @@ test('streaming: thinking block closed before tool call', async () => {
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4624,7 +4624,7 @@ test('streaming: strips <think> tag block from assistant content deltas', async
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
const result = await client.beta.messages
@@ -4709,7 +4709,7 @@ test('streaming: strips <think> tag split across multiple content chunks', async
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4770,7 +4770,7 @@ test('streaming: preserves prose without tags (no phrase-based false positive)',
])
return makeSseResponse(chunks)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
const result = await client.beta.messages
@@ -4805,7 +4805,7 @@ test('strips credentials and query params from URL in fetch network error messag
throw new TypeError(
'fetch failed https://user:password@internal.example.test/v1?token=abc123/chat/completions',
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4838,7 +4838,7 @@ test('classifies localhost transport failures with actionable category marker',
globalThis.fetch = (async () => {
throw transportError
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4873,7 +4873,7 @@ test('transport failures are not labeled with HTTP status 503', async () => {
globalThis.fetch = (async () => {
throw transportError
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4905,7 +4905,7 @@ test('propagates AbortError without wrapping it as transport failure', async ()
const abortError = new DOMException('The operation was aborted.', 'AbortError')
globalThis.fetch = (async () => {
throw abortError
}) as FetchType
}) as unknown as FetchType
const controller = new AbortController()
controller.abort()
@@ -4934,7 +4934,7 @@ test('classifies chat-completions endpoint 404 failures with endpoint_not_found
headers: {
'Content-Type': 'text/plain',
},
})) as FetchType
})) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -4988,7 +4988,7 @@ test('self-heals localhost resolution failures by retrying local loopback base U
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -5048,7 +5048,7 @@ test('self-heals local endpoint_not_found by retrying with /v1 base URL', async
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -5110,7 +5110,7 @@ test('self-heals tool-call incompatibility by retrying local Ollama requests wit
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -5177,7 +5177,7 @@ test('preserves valid tool_result and drops orphan tool_result', async () => {
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -5255,7 +5255,7 @@ test('drops empty assistant message when only thinking block was present and str
choices: [{ message: { role: 'assistant', content: 'hi' }, finish_reason: 'stop' }],
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }
}), { headers: { 'Content-Type': 'application/json' } })
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -5292,7 +5292,7 @@ test('injects semantic assistant message when tool result is followed by user me
choices: [{ message: { role: 'assistant', content: 'hi' }, finish_reason: 'stop' }],
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }
}), { headers: { 'Content-Type': 'application/json' } })
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -5343,7 +5343,7 @@ test('Moonshot: uses max_tokens (not max_completion_tokens) and strips store', a
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5377,7 +5377,7 @@ test('Cerebras: strips unsupported store on chat_completions (#1023)', async ()
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5409,7 +5409,7 @@ test('Local provider (vLLM/Ollama/etc.): strips unsupported store on chat_comple
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5441,7 +5441,7 @@ test('Groq: keeps max_completion_tokens and strips unsupported store', async ()
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5480,7 +5480,7 @@ test('Moonshot: echoes reasoning_content on assistant tool-call messages', async
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5547,7 +5547,7 @@ test('DeepSeek echoes reasoning_content on assistant tool-call messages', async
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5605,7 +5605,7 @@ test('generic OpenAI-compatible providers do not echo reasoning_content on assis
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5664,7 +5664,7 @@ test('gateway-routed DeepSeek models inherit descriptor-backed reasoning and tok
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({
reasoningEffort: 'xhigh',
@@ -5730,7 +5730,7 @@ test('Moonshot: cn host is also detected', async () => {
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5762,7 +5762,7 @@ test('Kimi Code endpoint inherits Moonshot max_tokens/store compatibility', asyn
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5796,7 +5796,7 @@ test('Kimi Code endpoint echoes reasoning_content on assistant tool-call message
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5863,7 +5863,7 @@ test('DeepSeek sends thinking toggle and normalized reasoning effort', async ()
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({
reasoningEffort: 'xhigh',
@@ -5902,7 +5902,7 @@ test('DeepSeek omits thinking controls when the Anthropic-side request does not
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5935,7 +5935,7 @@ test('DeepSeek forwards an explicit thinking disable toggle for V4 models', asyn
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -5983,7 +5983,7 @@ test('collapses multiple text blocks in tool_result to string for DeepSeek compa
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -6060,7 +6060,7 @@ test('collapses multiple text blocks into a single string for DeepSeek compatibi
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -6118,7 +6118,7 @@ test('preserves mixed text and image tool results as multipart content', async (
},
},
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -6191,7 +6191,7 @@ test('Z.AI: uses max_tokens (not max_completion_tokens) and strips store', async
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -6232,7 +6232,7 @@ test('Z.AI: thinking mode enabled when requested', async () => {
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -6269,7 +6269,7 @@ test('strips Anthropic attribution header block from chat-completions system pro
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -6321,7 +6321,7 @@ test('strips Anthropic attribution header block from responses-API instructions
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({ defaultHeaders: {} }) as OpenAIShimClient
@@ -6367,7 +6367,7 @@ test('emits reasoning_effort on chat_completions when reasoningEffort is passed'
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({
reasoningEffort: 'xhigh',
@@ -6405,7 +6405,7 @@ test('omits reasoning_effort on chat_completions when no override and model has
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -6441,7 +6441,7 @@ test('emits reasoning_effort from codex alias default when no override is passed
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
@@ -6473,7 +6473,7 @@ test('DeepSeek: redacted_thinking block preserves continuity with reasoning_cont
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
@@ -6534,7 +6534,7 @@ test('DeepSeek: redacted_thinking block with non-empty data propagates data into
}),
{ headers: { 'Content-Type': 'application/json' } },
)
}) as FetchType
}) as unknown as FetchType
const client = createOpenAIShimClient({}) as OpenAIShimClient
await client.beta.messages.create({
+5 -5
View File
@@ -48,7 +48,7 @@ describe('firecrawl client', () => {
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } },
)
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(firecrawlSearch('openclaude', { limit: 7 })).resolves.toEqual({
web: [{ url: 'https://example.com', title: 'Example', description: 'desc' }],
@@ -79,7 +79,7 @@ describe('firecrawl client', () => {
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } },
)
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(firecrawlScrape('https://example.com')).resolves.toEqual({
markdown: '# Example',
@@ -121,7 +121,7 @@ describe('firecrawl client', () => {
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } },
)
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
firecrawlSearch('openclaude', { maxRetries: 3, backoffFactorSeconds: 0 }),
@@ -144,7 +144,7 @@ describe('firecrawl client', () => {
once: true,
})
})
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
Promise.race([
@@ -176,7 +176,7 @@ describe('firecrawl client', () => {
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } },
)
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
firecrawlSearch('openclaude', { maxRetries: 1, timeoutMs: 20 }),
+4 -4
View File
@@ -47,7 +47,7 @@ describe('preconnectAnthropicApi', () => {
// getAPIProvider() to 'firstParty' here and break these assertions.
test('does not fetch when OpenAI mode is enabled', async () => {
const fetchMock = mock(() => Promise.resolve(new Response(null, { status: 200 })))
globalThis.fetch = fetchMock as typeof globalThis.fetch
globalThis.fetch = fetchMock as unknown as typeof globalThis.fetch
const { preconnectAnthropicApi } = await importFreshModule()
preconnectAnthropicApi('openai')
@@ -57,7 +57,7 @@ describe('preconnectAnthropicApi', () => {
test('does not fetch when Gemini mode is enabled', async () => {
const fetchMock = mock(() => Promise.resolve(new Response(null, { status: 200 })))
globalThis.fetch = fetchMock as typeof globalThis.fetch
globalThis.fetch = fetchMock as unknown as typeof globalThis.fetch
const { preconnectAnthropicApi } = await importFreshModule()
preconnectAnthropicApi('gemini')
@@ -67,7 +67,7 @@ describe('preconnectAnthropicApi', () => {
test('does not fetch when GitHub mode is enabled', async () => {
const fetchMock = mock(() => Promise.resolve(new Response(null, { status: 200 })))
globalThis.fetch = fetchMock as typeof globalThis.fetch
globalThis.fetch = fetchMock as unknown as typeof globalThis.fetch
const { preconnectAnthropicApi } = await importFreshModule()
preconnectAnthropicApi('github')
@@ -107,7 +107,7 @@ describe('preconnectAnthropicApi', () => {
getAPIProvider: () => 'firstParty',
}))
const fetchMock = mock(() => Promise.resolve(new Response(null, { status: 200 })))
globalThis.fetch = fetchMock as typeof globalThis.fetch
globalThis.fetch = fetchMock as unknown as typeof globalThis.fetch
const { preconnectAnthropicApi } = await importFreshModule()
preconnectAnthropicApi('firstParty')
+11 -12
View File
@@ -6,7 +6,6 @@ import {
} from '../test/sharedMutationLock.js'
async function loadProviderDiscoveryModule() {
// @ts-expect-error cache-busting query string for Bun module mocks
return import(`./providerDiscovery.js?ts=${Date.now()}-${Math.random()}`)
}
@@ -57,7 +56,7 @@ test('lists models from a local openai-compatible /models endpoint', async () =>
{ status: 200 },
),
)
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
listOpenAICompatibleModels({
@@ -75,7 +74,7 @@ test('returns null when a local openai-compatible /models request fails', async
globalThis.fetch = mock(() =>
Promise.resolve(new Response('not available', { status: 503 })),
) as typeof globalThis.fetch
) as unknown as typeof globalThis.fetch
await expect(
listOpenAICompatibleModels({ baseUrl: 'http://localhost:1234/v1' }),
@@ -156,7 +155,7 @@ test('ollama generation readiness reports unreachable when tags endpoint is down
const url = typeof input === 'string' ? input : input.url
calledUrls.push(url)
return Promise.resolve(new Response('not available', { status: 503 }))
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
probeOllamaGenerationReadiness({
@@ -185,7 +184,7 @@ test('ollama generation readiness reports no models when server is reachable', a
headers: { 'Content-Type': 'application/json' },
}),
)
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
probeOllamaGenerationReadiness({
@@ -219,7 +218,7 @@ test('ollama generation readiness reports generation_failed when requested model
},
),
)
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
probeOllamaGenerationReadiness({
@@ -255,7 +254,7 @@ test('ollama generation readiness reports generation failures when chat probe fa
}
return Promise.resolve(new Response('model not found', { status: 404 }))
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
probeOllamaGenerationReadiness({
@@ -293,7 +292,7 @@ test('ollama generation readiness reports generation_failed when chat probe retu
headers: { 'Content-Type': 'text/html' },
}),
)
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
probeOllamaGenerationReadiness({
@@ -337,7 +336,7 @@ test('ollama generation readiness reports ready when chat probe succeeds', async
},
),
)
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
probeOllamaGenerationReadiness({
@@ -357,7 +356,7 @@ test('atomic chat readiness reports unreachable when /v1/models is down', async
const url = typeof input === 'string' ? input : input.url
calledUrls.push(url)
return Promise.resolve(new Response('unavailable', { status: 503 }))
}) as typeof globalThis.fetch
}) as unknown as typeof globalThis.fetch
await expect(
probeAtomicChatReadiness({ baseUrl: 'http://127.0.0.1:1337' }),
@@ -376,7 +375,7 @@ test('atomic chat readiness reports no_models when server is reachable but empty
headers: { 'Content-Type': 'application/json' },
}),
),
) as typeof globalThis.fetch
) as unknown as typeof globalThis.fetch
await expect(
probeAtomicChatReadiness({ baseUrl: 'http://127.0.0.1:1337' }),
@@ -401,7 +400,7 @@ test('atomic chat readiness returns loaded model ids when ready', async () => {
},
),
),
) as typeof globalThis.fetch
) as unknown as typeof globalThis.fetch
await expect(
probeAtomicChatReadiness({ baseUrl: 'http://127.0.0.1:1337' }),