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