From 086b52f9860d0ffe8345cb4798247defe175a1f6 Mon Sep 17 00:00:00 2001 From: Tianyi Cui <53024+tianyicui@users.noreply.github.com> Date: Wed, 2 Sep 2026 20:07:48 +0800 Subject: [PATCH] test(session): cover generation scan failures --- .../tests/jsonl.spec.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/session/session-persistence-jsonl/tests/jsonl.spec.ts b/packages/session/session-persistence-jsonl/tests/jsonl.spec.ts index bde9760eaa..10a27a5ad2 100644 --- a/packages/session/session-persistence-jsonl/tests/jsonl.spec.ts +++ b/packages/session/session-persistence-jsonl/tests/jsonl.spec.ts @@ -30,6 +30,11 @@ const statFailure = vi.hoisted(() => ({ error: undefined as Error | undefined, })) +const readdirFailure = vi.hoisted(() => ({ + path: undefined as string | undefined, + error: undefined as Error | undefined, +})) + const readTally = vi.hoisted(() => ({ /** Physical whole-file reads per path suffix; keyed by session id segment. */ bySuffix: new Map(), @@ -55,6 +60,12 @@ vi.mock('node:fs/promises', async (importOriginal) => { } return actual.readFile(...args) }) as typeof actual.readFile, + readdir: (async (...args: Parameters) => { + if (String(args[0]) === readdirFailure.path && readdirFailure.error !== undefined) { + throw readdirFailure.error + } + return actual.readdir(...args) + }) as typeof actual.readdir, } }) @@ -144,6 +155,8 @@ afterEach(async () => { readTally.enabled = false statFailure.path = undefined statFailure.error = undefined + readdirFailure.path = undefined + readdirFailure.error = undefined vi.restoreAllMocks() for (const d of dirs.splice(0)) await rm(d, { recursive: true, force: true }) }) @@ -643,6 +656,20 @@ describe('JsonlSessionPersistence: immutable format generations', () => { await expect(ctx.sessionPersistence.list()).rejects.toThrow(JSON.stringify(highest)) }) + it('propagates a non-ENOENT opposite-generation scan failure during materialization', async () => { + const header = meta('opposite-generation-scan-failure', '/work') + const handle = await ctx.sessionPersistence.create(header) + const failure = Object.assign(new Error('opposite-generation scan denied'), { code: 'EACCES' }) + readdirFailure.path = sessionDir(root, header.cwd, header.id) + readdirFailure.error = failure + + try { + await expect(handle.flush()).rejects.toBe(failure) + } finally { + await handle.close() + } + }) + it('surfaces a file occupying the targeted Session-directory path', async () => { const header = meta('blocked-generation-directory', '/work') const dir = sessionDir(root, header.cwd, header.id)