M2: KV driver interface, BaseKVDriver, InMemoryKVDriver, conformance suite
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017Qxbkp4tA7G5SCWjzWuxmE
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { InMemoryKVDriver } from '../../src/kv/memory.js'
|
||||
import { runKVDriverConformance } from '../../src/testing/kv-conformance.js'
|
||||
import { CountingDriver, MinimalDriver } from '../helpers.js'
|
||||
|
||||
runKVDriverConformance('InMemoryKVDriver', () => new InMemoryKVDriver())
|
||||
runKVDriverConformance('BaseKVDriver (minimal)', () => new MinimalDriver())
|
||||
runKVDriverConformance('CountingDriver(InMemory)', () => new CountingDriver())
|
||||
|
||||
describe('InMemoryKVDriver', () => {
|
||||
it('keeps order after large bulk merges', async () => {
|
||||
const d = new InMemoryKVDriver()
|
||||
const keys = Array.from({ length: 5000 }, (_, i) => `k${(i * 7919) % 5000}`)
|
||||
await d.setMany(keys.slice(0, 2500).map((k) => [k, 1]))
|
||||
await d.setMany(keys.slice(2500).map((k) => [k, 2]))
|
||||
const seen: string[] = []
|
||||
for await (const [k] of d.scan({})) seen.push(k)
|
||||
expect(seen).toEqual([...new Set(keys)].sort())
|
||||
expect(d.size).toBe(5000)
|
||||
})
|
||||
|
||||
it('can skip cloning', async () => {
|
||||
const d = new InMemoryKVDriver({ clone: false })
|
||||
const v = { n: 1 }
|
||||
await d.setMany([['k', v]])
|
||||
expect((await d.getMany(['k']))[0]).toBe(v)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user