Files
deepseek-harness/packages/session/session-persistence-sqlite/tests/fixtures/persistence.ts
T
liukx0205 d16104bd9a test(session): cover SQLite frame storage and document its settings
Fixtures construct the store with the plugin's frame defaults and read
durable history through frames; existing tests query the frames table
and its triggers. New tests cover the frame codec, frame layout per
write and per setting, sliced reads across frame boundaries, decode
grouping, and the corruption refusals for a missing frame, a frame
shorter than its range, an unknown codec, and damaged bytes.

The SQLite README, the persistence subsystem page and the generated
configuration catalog describe `frameEvents` and the frame encoding
selected by `compression`.
2026-11-17 18:00:51 +08:00

40 lines
1.8 KiB
TypeScript

/** Isolated persistence providers sharing one test-owned storage directory. @module */
import { Context } from '@deepseek-ai/cordis'
import { mkdtemp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { onTestFinished } from 'vitest'
import * as SqlitePersistence from '../../src/index.ts'
import * as JsonlPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import type { JsonlCompression } from '@deepseek-ai/dsh-session-persistence-jsonl'
import SessionStore from '@deepseek-ai/dsh-session'
/**
* Allocate private storage and close every mounted provider before removing it.
* @returns storage root and factories for independently owned providers.
*/
export async function persistenceFixture() {
const root = await mkdtemp(join(tmpdir(), 'dsh-sqlite-persistence-'))
const contexts: Context[] = []
onTestFinished(async () => {
let failures: unknown[]
try {
const results = await Promise.allSettled(contexts.map(context => context.fiber.dispose()))
failures = results.filter(result => result.status === 'rejected').map((result): unknown => result.reason)
} finally {
await rm(root, { recursive: true, force: true })
}
if (failures.length > 0) throw new AggregateError(failures, 'Persistence fixture disposal failed')
})
async function mount(storage: 'sqlite' | 'jsonl', compression: JsonlCompression = 'none', frameEvents?: number) {
const context = new Context()
contexts.push(context)
await context.plugin(SessionStore)
const provider = storage === 'sqlite'
? await context.plugin(SqlitePersistence, { root, compression, ...(frameEvents === undefined ? {} : { frameEvents }) })
: await context.plugin(JsonlPersistence, { root, compression })
return { context, persistence: context.sessionPersistence, provider }
}
return { root, mount }
}