Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { createCapability } from '@tanstack/ai'
3import { makeFakeHandle, makeMiddlewareCtx } from './fakes'
4
5describe('makeMiddlewareCtx', () => {
6 it('tracks provided capabilities and stores their values', () => {
7 const ctx = makeMiddlewareCtx({ threadId: 'thread-1', runId: 'run-1' })
8 const capability = createCapability<{ value: string }>()('fake-capability')
9 const value = { value: 'stored' }
10
11 expect(ctx.capabilities.has(capability)).toBe(false)
12 ctx.provide(capability, value)
13
14 expect(ctx.capabilities.has(capability)).toBe(true)
15 expect(ctx.get(capability)).toBe(value)
16 })
17})
18
19describe('makeFakeHandle', () => {
20 it('reports written files as files', async () => {
21 const handle = makeFakeHandle('id', 'fake')
22 const content = 'export {}\n'
23 await handle.fs.write('/workspace/app.ts', content)
24 await expect(handle.fs.lstat!('/workspace/app.ts')).resolves.toEqual({
25 type: 'file',
26 mode: 0o644,
27 size: new TextEncoder().encode(content).byteLength,
28 })
29 await expect(handle.fs.lstat!('/workspace')).resolves.toEqual({
30 type: 'dir',
31 mode: 0o755,
32 })
33 })
34})