Files
deepseek-harness/packages/core/session/tests
imccyuandimccyu e25df02c51 refactor(session): prepare Session validation and header building for SessionData (#8676)
* refactor(session): move Session log validation into a module

Move header, seed-event envelope, and inherited-cut validation out of the
Session constructor into validation.ts without changing check order or error
text. Export needsInheritedSeedMarker for the fork marker rule the
constructor applies.

* feat(session): validate a Session log without constructing a Session

validateSessionLog composes the header, seed-event, surface, and
inherited-cut checks of Session construction in the same order. Omitting
eventState matches Session.create; an event state matches
Session.fromRestore.

* refactor: validate stored Session logs with validateSessionLog

The chat importer, session-query readSession, the format catalog, and JSONL
generation verification constructed a discarded Session only to validate a
log. They now call validateSessionLog with the same mode, inherited count,
and message interpreters.

* refactor(session): extract buildSessionHeader

Move new-Session header construction out of SessionStore.prepare into the
exported buildSessionHeader and name its input SessionHeaderMeta.
Automatic ids and duplicate checks stay in prepare.

* refactor(session): move header and fork error helpers out of the session index

Move buildSessionHeader into validation.ts and SessionForkError with
SessionForkErrorCode into fork.ts so later modules can import them without
importing index.ts. index.ts re-exports both under the same names. Complete
the JSDoc of the exported validation helpers.

* refactor(session): extract checkSessionLog from the Session constructor

Move header validation, seed acceptance with surface admission, and the inherited-cut check into checkSessionLog in validation.ts, keeping the constructor's order and errors. The Session constructor and validateSessionLog call it.

* test(session): cover Session log validation and construction helpers

Cover validateSessionLog against Session.create and Session.fromRestore in
every event state, buildSessionHeader, needsInheritedSeedMarker,
Session.readEvents range semantics, and the fork subpath export of
SessionForkError.

* docs(session): document Session log validation

Document validateSessionLog, buildSessionHeader, needsInheritedSeedMarker,
Session.readEvents, and the SessionForkError subpath export in the package
README. Align the Session and CreateSessionOptions type blocks, add
SessionHeaderMeta, regenerate the Cordis, event graph, and persistence
catalogs, and update the plugin entry, unknown-cast, and package dependency
registries.

---------

Co-authored-by: imccyu <[email protected]>
2026-11-20 00:11:27 +08:00
..