Files
deepseek-harness/packages/session/session-format/tests/filename.spec.ts
T
Tianyi Cui c97df989ff refactor(session): share the canonical log basename and JSON snapshots
`session[.vN].jsonl` was assembled independently by the JSONL provider
(twice), the session-log export archive, and the recorded-session fixture
helpers. `dsh-session-format` now owns `sessionFormatLogFilename` and
`parseSessionFormatLogFilename`; the three consumers append only their
compression suffix, and the migration note names the owner.

`snapshotSessionFormatJson` re-implemented the lossless JSON walk that
`dsh-util-values` already publishes as `snapshotJsonValue` + `deepFreeze`,
and the frozen v0 relationship validator carried a third structural JSON
comparison next to `deepEqualJson`. Both now delegate; the format package
reports one `is not lossless JSON` diagnostic per labelled subject instead
of ten member-specific ones, and enumerable accessors whose values survive
a JSON round trip are accepted like `JSON.stringify` accepts them.
2026-09-03 21:48:09 +08:00

32 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { parseSessionFormatLogFilename, sessionFormatLogFilename } from '../src/index.ts'
describe('canonical Session log filenames', () => {
it('names version zero without a generation component and later generations with .vN', () => {
expect(sessionFormatLogFilename(0)).toBe('session.jsonl')
expect(sessionFormatLogFilename(1)).toBe('session.v1.jsonl')
expect(sessionFormatLogFilename(27)).toBe('session.v27.jsonl')
for (const invalid of [-1, -0, 1.5, Number.MAX_SAFE_INTEGER + 1]) {
expect(() => sessionFormatLogFilename(invalid)).toThrow(/non-negative safe integer/)
}
})
it('parses only canonical raw generation names', () => {
expect(parseSessionFormatLogFilename('session.jsonl')).toBe(0)
expect(parseSessionFormatLogFilename('session.v1.jsonl')).toBe(1)
expect(parseSessionFormatLogFilename('session.v27.jsonl')).toBe(27)
expect(parseSessionFormatLogFilename('session.v9007199254740992.jsonl')).toBeUndefined()
for (const name of [
'session.v0.jsonl',
'session.v01.jsonl',
'session.V1.jsonl',
'session.v1.backup.jsonl',
'session.migration.deadbeef.tmp.jsonl',
'session.v1.jsonl.zstd',
'session.1.jsonl',
]) {
expect(parseSessionFormatLogFilename(name)).toBeUndefined()
}
})
})