feat(session): default JSONL writes to packed rows

This commit is contained in:
Tianyi Cui
2026-07-26 23:44:52 +08:00
parent cad2af4741
commit 4ff496c65c
47 changed files with 521 additions and 251 deletions
@@ -724,7 +724,7 @@ describe('SessionPersistenceJsonl: scanLog unit', () => {
})
})
describe('SessionPersistenceJsonl: packed chunk rows (packChunks: true)', () => {
describe('SessionPersistenceJsonl: default packed chunk rows', () => {
let ctx: Context
beforeEach(async () => {
root = await freshRoot()
@@ -732,7 +732,7 @@ describe('SessionPersistenceJsonl: packed chunk rows (packChunks: true)', () =>
await ctx.plugin(SessionStore)
// compression: 'none' — these tests assert the textual storage-record layout
// (row tags per line); packing is orthogonal to the physical encoding.
await ctx.plugin(SessionPersistenceJsonl, { root, packChunks: true, compression: 'none' })
await ctx.plugin(SessionPersistenceJsonl, { root, compression: 'none' })
})
afterEach(async () => { await ctx.fiber.dispose() })
@@ -754,7 +754,7 @@ describe('SessionPersistenceJsonl: packed chunk rows (packChunks: true)', () =>
]
}
it('writes a delta run as one text-chunks row and loads back identical events', async () => {
it('writes a delta run as one text-chunks row by default and loads back identical events', async () => {
const m = meta('packed', '/work')
const log = chunkRunLog()
await ctx.sessionPersistence.create(m)
@@ -768,6 +768,32 @@ describe('SessionPersistenceJsonl: packed chunk rows (packChunks: true)', () =>
expect(loaded.events).toEqual(log)
})
it('packChunks: false writes one event per line and still loads identical events', async () => {
const unpackedRoot = await freshRoot()
const unpacked = new Context()
await unpacked.plugin(SessionStore)
await unpacked.plugin(SessionPersistenceJsonl, {
root: unpackedRoot,
packChunks: false,
compression: 'none',
})
try {
const m = meta('unpacked', '/work')
const log = chunkRunLog()
await unpacked.sessionPersistence.create(m)
await unpacked.sessionPersistence.append(m.id, log)
const records = (await readFile(rawLogPath(unpackedRoot, '/work', m.id), 'utf8'))
.split('\n').filter(Boolean).slice(1)
.map(line => JSON.parse(line) as { type: string })
expect(records.filter(record => record.type === 'assistant/chunk')).toHaveLength(5)
expect(records.some(record => record.type === 'text-chunks')).toBe(false)
expect((await unpacked.sessionPersistence.load(m.id)).events).toEqual(log)
} finally {
await unpacked.fiber.dispose()
}
})
it('loads a mixed file: verbatim lines from an unpacked writer, then packed appends', async () => {
const m = meta('mixed', '/work')
const log = chunkRunLog()