Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

context-overflow.spec.ts

30 lines1003 Bytes

1import { test, expect } from './fixtures'
2​
3/**
4 * aimock answers `[context-overflow-*]` with the provider's own context
5 * overflow error. The adapter maps it, and the `RUN_ERROR` that `chat()`
6 * yields carries the stable `context_overflow` code with the provider's text.
7 */
8for (const [api, text] of [
9 ['anthropic', 'prompt is too long'],
10 ['openai-responses', 'maximum context length'],
11 ['openai-chat-completions', 'maximum context length'],
12] as const) {
13 test(`${api} — context overflow gives RUN_ERROR code context_overflow`, async ({
14 request,
15 }) => {
16 const res = await request.post(`/api/context-overflow?api=${api}`)
17 expect(res.ok()).toBe(true)
18​
19 const { ok, runError, error } = (await res.json()) as {
20 ok: boolean
21 error?: string
22 runError?: { code?: string; message: string }
23 }
24​
25 expect(error ?? null).toBeNull()
26 expect(ok).toBe(true)
27 expect(runError?.code).toBe('context_overflow')
28 expect(runError?.message).toContain(text)
29 })