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

memory.conformance.test.ts

32 lines895 Bytes

1import { runPersistenceConformance } from '../src/testkit/conformance'
2import {
3 memoryLogState,
4 memoryLogStore,
5 memoryPersistence,
6} from '../src/memory'
7import { defineAIPersistence } from '../src/types'
8​
9// One log state, so the twin's log store sees the same log as a second
10// machine does.
11const state = memoryLogState()
12​
13// The log goes on the shared state, so the twin can read it.
14runPersistenceConformance(
15 'memory',
16 () =>
17 defineAIPersistence({
18 stores: {
19 ...memoryPersistence().stores,
20 log: memoryLogStore({ state }),
21 },
22 }),
23 {
24 checks: ['messages.metadata', 'runs.listByThread.state'],
25 // A second log store instance on the same state. The other stores are
26 // shared as they are.
27 twin: (persistence) =>
28 defineAIPersistence({
29 stores: { ...persistence.stores, log: memoryLogStore({ state }) },
30 }),
31 },