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

harness-forwarding.spec.ts

81 lines2.6 KB

1import { test, expect } from './fixtures'
2​
3interface Result {
4 error?: string
5 receipt: { status: string }
6 first: string
7 followUp?: string
8 ownerCalls: number
9 otherCalls: number
10 transcript: Array<{ role: string; text: string }>
12​
13test.describe('harness: an input on a host that does not own the thread', () => {
14 test('waits in the log for the owner, and the owner runs it after its turn', async ({
15 request,
16 }) => {
17 const res = await request.post('/api/harness-forwarding')
18 expect(res.ok()).toBe(true)
19 const result: Result = await res.json()
20 expect(result.error ?? null).toBeNull()
21​
22 expect(result.receipt.status).toBe('queued')
23 expect(result.first).toBe('One.')
24 expect(result.followUp).toBe('completed')
25 // Both answers came from the model of the owner.
26 expect(result.ownerCalls).toBe(2)
27 expect(result.otherCalls).toBe(0)
28 expect(result.transcript).toEqual([
29 { role: 'user', text: '[harness-forwarding] go' },
30 { role: 'assistant', text: 'One.' },
31 { role: 'user', text: '[harness-forwarding] and then' },
32 { role: 'assistant', text: 'Two.' },
33 ])
34 })
35})
36​
37test.describe('harness: the host that does not own the thread', () => {
38 test('the host that does not own the thread shows running, then idle', async ({
39 request,
40 }) => {
41 const res = await request.post('/api/harness-forwarding?scenario=status')
42 expect(res.ok()).toBe(true)
43 const result: {
44 error?: string
45 statuses: Array<string>
46 text: string
47 ownerCalls: number
48 otherCalls: number
49 } = await res.json()
50 expect(result.error ?? null).toBeNull()
51​
52 expect(result.text).toBe('One.')
53 // The other host runs nothing. Its status comes from the log tail.
54 expect(result.statuses).toEqual(['idle', 'running', 'idle'])
55 expect(result.ownerCalls).toBe(1)
56 expect(result.otherCalls).toBe(0)
57 })
58​
59 test('a cancel sent to the other host stops the turn', async ({
60 request,
61 }) => {
62 const res = await request.post('/api/harness-forwarding?scenario=cancel')
63 expect(res.ok()).toBe(true)
64 const result: {
65 error?: string
66 receipt: { status: string }
67 outcome: { text?: string; error?: string }
68 turnStatus: string
69 ownerCalls: number
70 otherCalls: number
71 } = await res.json()
72 expect(result.error ?? null).toBeNull()
73​
74 // The other host stores the cancel in the log, and the owner applies it.
75 expect(result.receipt.status).toBe('queued')
76 expect(result.outcome).toEqual({ error: 'Cancelled.' })
77 expect(result.turnStatus).toBe('cancelled')
78 expect(result.ownerCalls).toBe(1)
79 expect(result.otherCalls).toBe(0)
80 })
81})