feat(session-persistence): expose readRaw for per-session artifacts

The persistence contract gains a concrete readRaw default (undefined for
backends without a per-session artifact) and the JSONL backend overrides it
with the decode of its physical zstd frames, so a consumer can read the
stored artifact text verbatim — the session-log export depends on it.
This commit is contained in:
_Kerman
2026-08-10 17:47:17 +08:00
parent d2321d210a
commit 80b7f929ea
11 changed files with 171 additions and 7 deletions
@@ -356,6 +356,27 @@ describe('SessionPersistenceJsonl: default Zstandard encoding', () => {
expect((await ctx.sessionPersistence.load(header.id)).events).toEqual(oneTurnLog())
})
it('readRaw decodes the compressed artifact back to the original JSONL text', async () => {
const root = await freshRoot()
const ctx = await mount(root)
const header = meta('raw-read-zstd', '/work')
await ctx.sessionPersistence.create(header)
await ctx.sessionPersistence.append(header.id, oneTurnLog())
const raw = await ctx.sessionPersistence.readRaw(header.id)
expect(raw).toBeDefined()
// The logical name drops the physical encoding suffix.
expect(raw!.filename).toBe('session.jsonl')
expect(raw!.meta.id).toBe(header.id)
expect(raw!.content).toBe([
JSON.stringify(toHeaderLine(header)),
...oneTurnLog().map(e => JSON.stringify(e)),
'',
].join('\n'))
const scanned = scanLog(Buffer.from(raw!.content))
expect(scanned.events.map(event => event.type)).toEqual(oneTurnLog().map(event => event.type))
})
it('resolves the default when a programmatic wrapper bypasses Loader schema normalization', async () => {
const root = await freshRoot()
const ctx = new Context()