fix(session-persistence): async readRaw default and full branch coverage

The inherited readRaw default now rejects like the async backend overrides
instead of throwing synchronously, and its arms plus the JSONL override's
retry loop, zero-frame, and corrupt-header branches get dedicated tests.
This commit is contained in:
_Kerman
2026-08-10 19:49:57 +08:00
parent ced7caabf8
commit bf70da473b
4 changed files with 46 additions and 2 deletions

View File

@@ -106,9 +106,9 @@ export abstract class SessionPersistence extends Service {
* @returns the raw artifact plus its parsed header, or `undefined` when the
* session is absent or the backend owns no per-session artifact.
*/
readRaw(_id: SessionId, signal?: AbortSignal): Promise<SessionRawArtifact | undefined> {
async readRaw(_id: SessionId, signal?: AbortSignal): Promise<SessionRawArtifact | undefined> {
signal?.throwIfAborted()
return Promise.resolve(undefined)
return undefined
}
/**

View File

@@ -246,6 +246,18 @@ runPersistenceContract('memory', async () => {
}
})
describe('the inherited readRaw default', () => {
it('answers undefined and honors an aborted signal', async () => {
const ctx = new Context()
await ctx.plugin(SessionStore)
await ctx.plugin(MemoryPersistence)
expect(await ctx.sessionPersistence.readRaw(SessionId('any-session'))).toBeUndefined()
await expect(
ctx.sessionPersistence.readRaw(SessionId('any-session'), AbortSignal.abort()),
).rejects.toThrow()
})
})
// Each fixture shares one map across mounts. No `corruptTail` is supplied because map writes are
// atomic; the suite asserts that skip while JSONL and SQLite cover the repair branch.
runCoordinatorContract('memory', async (): Promise<CoordinatorFixture> => {