Give durable user context its producer-owned source kind instead of a generic plugin wrapper. The V3-to-V4 conversion preserves the frozen rename and collision rules, all own JSON metadata, event coordinates, and historical request-only kinds. Native catalog and JSONL admission retain source validation so unknown attribution can survive without its producer while malformed owned sources are refused. Use an explicit user-only RequestUserInput for auxiliary LLM prompts that do not own durable message identity. Auto Review and compaction remove their request-only source registrations while retaining prompt content and freezing; provider serializers and projections keep the same wire data, assistant replay isolation, image ordering, and tool correlation. Session writes, Agent delivery, and recorded title requests continue to require identified durable messages. Bind the saved compatibility policy only to user sources and qualify tmux location attribution without weakening fixed system, model, or tool semantics. Rebuild the current inventory and unpublished V4 acknowledgement on the actual tool-role parent, preserving its rationale and all accepted historical records. The catalog format version records tooling metadata; Session remains V4. Developer-role policy and activation belong to their own feature. The latest-master Messages adapter, serialization, request-input typing, EpochHeader reservation, and attribution checks pass 103 tests across five files. The retained V3 Messages input-history snapshot passes through the source profile; Host/Client typechecks and all 41 documentation gates pass. The generated comparison records four changed roots and 447 unchanged type fingerprints. Latest-master ARIA changes are retained, with producer source labels applied independently; new Messages fixtures retain their producer names as declared source kinds and use the fixed system-message helper; recorded Session generations are unchanged by this regrouping. Co-authored-by: Tianyi Cui <[email protected]>
81 lines
4.1 KiB
TypeScript
81 lines
4.1 KiB
TypeScript
import { Context } from '@deepseek-ai/cordis'
|
|
import { SESSION_FORMAT_VERSION, SessionId } from '@deepseek-ai/dsh-session'
|
|
import { SessionPersistenceCorruptionError } from '@deepseek-ai/dsh-session-persistence'
|
|
import JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
|
|
import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { dirname, join } from 'node:path'
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
import { generationLogPath } from '../src/format.ts'
|
|
import { compressZstdFrame } from '../src/zstd.ts'
|
|
|
|
const id = SessionId('native-source-admission')
|
|
const modes = (['none', 'zstd'] as const).flatMap(compression => (['read', 'write'] as const).map(access => ({ compression, access })))
|
|
let root: string
|
|
const contexts: Context[] = []
|
|
beforeEach(async () => { root = await mkdtemp(join(tmpdir(), 'dsh-native-source-')) })
|
|
afterEach(async () => {
|
|
try {
|
|
for (const ctx of contexts.splice(0).reverse()) await ctx.fiber.dispose()
|
|
} finally {
|
|
await rm(root, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
describe.each(modes)('native message-source admission ($compression, $access)', ({ compression, access }) => {
|
|
async function stored(source: unknown, type = 'agent/inbox/spliced', ignorable = false) {
|
|
const header = { type: 'session', version: SESSION_FORMAT_VERSION, id, createdAt: 1, delegationDepth: 0, isSeeded: false }
|
|
const event = { type, seq: 0, time: 1, ...(ignorable ? { ignorable: true } : {}), data: {
|
|
target: 'next-turn', start: 0, inserted: [{ id: 'input', role: 'user', source, content: [{ type: 'text', text: 'queued' }] }],
|
|
} }
|
|
const lines = [header, event].map(value => JSON.stringify(value) + '\n')
|
|
const bytes = compression === 'none' ? Buffer.from(lines.join('')) : Buffer.concat(await Promise.all(lines.map(compressZstdFrame)))
|
|
const path = generationLogPath(root, undefined, id, SESSION_FORMAT_VERSION, compression)
|
|
await mkdir(dirname(path), { recursive: true })
|
|
await writeFile(path, bytes)
|
|
const ctx = new Context()
|
|
contexts.push(ctx)
|
|
await ctx.plugin(JsonlSessionPersistence, { root, compression })
|
|
return { ctx, path, bytes, event }
|
|
}
|
|
|
|
it.each([null, {}, [], { kind: '' }, { kind: 1 }].map(source => ({ source })))('refuses malformed queued source $source before exposing a handle', async ({ source }) => {
|
|
const { ctx, path, bytes } = await stored(source)
|
|
const opened = ctx.sessionPersistence.open(id, access).then(async (handle) => { await handle.close() })
|
|
await expect(opened).rejects.toBeInstanceOf(SessionPersistenceCorruptionError)
|
|
await expect(opened).rejects.toThrow('producer-owned source kind')
|
|
expect(await readFile(path)).toEqual(bytes)
|
|
expect((await readdir(dirname(path))).filter(name => name !== 'session.lock')).toHaveLength(1)
|
|
})
|
|
|
|
it('still validates known queued events marked ignorable', async () => {
|
|
const { ctx, path, bytes } = await stored({}, 'agent/inbox/spliced', true)
|
|
const opened = ctx.sessionPersistence.open(id, access).then(async (handle) => { await handle.close() })
|
|
await expect(opened).rejects.toThrow('producer-owned source kind')
|
|
expect(await readFile(path)).toEqual(bytes)
|
|
})
|
|
|
|
it('preserves external attribution and own JSON metadata without a producer installed', async () => {
|
|
const source = JSON.parse('{"kind":"external-producer","__proto__":{"retain":true},"metadata":{"count":1}}') as unknown
|
|
const { ctx, path, bytes, event } = await stored(source)
|
|
const handle = await ctx.sessionPersistence.open(id, access)
|
|
try {
|
|
expect((await handle.read()).events[0]).toEqual(event)
|
|
} finally {
|
|
await handle.close()
|
|
}
|
|
expect(await readFile(path)).toEqual(bytes)
|
|
})
|
|
|
|
it('leaves unknown ignorable queued payloads opaque', async () => {
|
|
const { ctx, path, bytes, event } = await stored(null, 'external/inbox', true)
|
|
const handle = await ctx.sessionPersistence.open(id, access)
|
|
try {
|
|
expect((await handle.read()).events[0]).toEqual(event)
|
|
} finally {
|
|
await handle.close()
|
|
}
|
|
expect(await readFile(path)).toEqual(bytes)
|
|
})
|
|
})
|