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

copilot-wire.spec.ts

119 lines4.0 KB

1import { test, expect } from './fixtures'
2​
3for (const api of ['chat-completions', 'responses'] as const) {
4 test(`github copilot -- ${api} sends the Copilot headers and body`, async ({
5 request,
6 aimockPort,
7 testId,
8 }) => {
9 const response = await request.post('/api/copilot-wire', {
10 data: { testId, api },
11 })
12 expect(response.ok()).toBe(true)
13 const result: {
14 text: string
15 sent?: { store?: unknown; include?: unknown }
16 } = await response.json()
17 expect(result.text).toContain('Stratocaster')
18​
19 const journal = await request.get(
20 `http://127.0.0.1:${aimockPort}/v1/_requests`,
21 )
22 const entries: Array<{ headers?: Record<string, string> }> =
23 await journal.json()
24 const calls = entries.filter(
25 (entry) => entry.headers?.['x-test-id'] === testId,
26 )
27 expect(calls).toHaveLength(1)
28 const headers = calls[0]?.headers
29 // aimock redacts the token in its journal. The header must still be there.
30 expect(headers?.['authorization']).toBe('[REDACTED]')
31 expect(headers?.['openai-intent']).toBe('conversation-edits')
32 expect(headers?.['x-github-api-version']).toBe('2026-08-01')
33 expect(headers?.['x-initiator']).toBe('user')
34 if (api === 'responses') {
35 // aimock logs a converted body for /v1/responses. The route sends back
36 // the body that the adapter sent.
37 expect(result.sent?.store).toBe(false)
38 expect(result.sent?.include).toStrictEqual([
39 'reasoning.encrypted_content',
40 ])
41 }
42 })
44​
45test('github copilot -- claude sends the bearer token and the Copilot headers', async ({
46 request,
47 testId,
48}) => {
49 const response = await request.post('/api/copilot-wire', {
50 data: { testId, api: 'anthropic' },
51 })
52 expect(response.ok()).toBe(true)
53 const result: {
54 text: string
55 url: string
56 headers: Record<string, string>
57 } = await response.json()
58 expect(result.text).toContain('Stratocaster')
59 expect(new URL(result.url).pathname).toBe('/v1/messages')
60 expect(result.headers['authorization']).toBe('Bearer copilot-token')
61 expect(result.headers['x-api-key']).toBeUndefined()
62 expect(result.headers['user-agent']).toBe('e2e/1.0.0')
63 expect(result.headers['openai-intent']).toBe('conversation-edits')
64 expect(result.headers['x-github-api-version']).toBe('2026-08-01')
65 expect(result.headers['x-interaction-type']).toBe('conversation-agent')
66 expect(result.headers['x-interaction-id']).toBe('session-1')
67 expect(result.headers['x-initiator']).toBe('user')
68 expect(result.headers['anthropic-beta']).toBe(
69 'interleaved-thinking-2025-05-14',
70 )
71})
72​
73test('github copilot -- chat completions streams the reasoning_text thinking', async ({
74 request,
75}) => {
76 const response = await request.post('/api/copilot-wire', {
77 data: { api: 'reasoning-text' },
78 })
79 expect(response.ok()).toBe(true)
80 const result: { text: string; thinking: string } = await response.json()
81 expect(result.thinking).toBe('Say hi back.')
82 expect(result.text).toBe('Hi')
83})
84​
85test('github copilot -- responses streams one tool call when the item id changes on each event', async ({
86 request,
87}) => {
88 const response = await request.post('/api/copilot-wire', {
89 data: { api: 'rotating-ids' },
90 })
91 expect(response.ok()).toBe(true)
92 const result: {
93 text: string
94 toolCallStarts: number
95 toolCalls: Array<{ id: string; input: unknown }>
96 } = await response.json()
97 expect(result.toolCallStarts).toBe(1)
98 expect(result.toolCalls).toStrictEqual([
99 { id: 'call_1', input: { city: 'Paris' } },
100 ])
101 expect(result.text).toBe('Sunny')
102})
103​
104test('chatgpt plan -- responses runs the tool when response.completed has an empty output', async ({
105 request,
106}) => {
107 const response = await request.post('/api/copilot-wire', {
108 data: { api: 'empty-completed-output' },
109 })
110 expect(response.ok()).toBe(true)
111 const result: {
112 text: string
113 toolCalls: Array<{ id: string; input: unknown }>
114 } = await response.json()
115 expect(result.toolCalls).toStrictEqual([
116 { id: 'call_1', input: { city: 'Paris' } },
117 ])
118 expect(result.text).toBe('Sunny')
119})