Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { memoryPersistence } from '../src/memory'
3import type { ArtifactRecord } from '../src'
4
5const artifact = (
6 overrides: Partial<ArtifactRecord> & Pick<ArtifactRecord, 'artifactId'>,
7): ArtifactRecord => ({
8 runId: 'run-1',
9 threadId: 'thread-1',
10 name: 'file.txt',
11 mimeType: 'text/plain',
12 size: 1,
13 createdAt: 1,
14 ...overrides,
15})
16
17describe('ArtifactStore.listForThread', () => {
18 it('lists a thread artifacts by createdAt then artifactId', async () => {
19 const artifacts = memoryPersistence().stores.artifacts
20 if (!artifacts)
21 throw new Error('memory persistence should provide artifacts')
22
23 await artifacts.save(artifact({ artifactId: 'b', createdAt: 2 }))
24 await artifacts.save(artifact({ artifactId: 'a', createdAt: 2 }))
25 await artifacts.save(artifact({ artifactId: 'earlier', createdAt: 1 }))
26 await artifacts.save(
27 artifact({
28 artifactId: 'other-thread',
29 threadId: 'thread-2',
30 createdAt: 0,
31 }),
32 )
33
34 expect(
35 (await artifacts.listForThread('thread-1')).map((x) => x.artifactId),
36 ).toEqual(['earlier', 'a', 'b'])
37 })
38
39 it('orders mixed ASCII, accented, and astral IDs by UTF-8 bytes', async () => {
40 const artifacts = memoryPersistence().stores.artifacts
41 if (!artifacts)
42 throw new Error('memory persistence should provide artifacts')
43
44 await artifacts.save(artifact({ artifactId: '😀' }))
45 await artifacts.save(artifact({ artifactId: 'é' }))
46 await artifacts.save(artifact({ artifactId: 'a' }))
47
48 expect(
49 (await artifacts.listForThread('thread-1')).map((x) => x.artifactId),
50 ).toEqual(['a', 'é', '😀'])
51 })
52})