From b9ddc81f067188e56bfa06ef0cbb005e169146bd Mon Sep 17 00:00:00 2001 From: can1357 Date: Sat, 8 Aug 2026 19:50:59 +0200 Subject: [PATCH] test(coding-agent): assert dispose-persisted state from the reopened file - PR #8004 dispose() now releases the session manager in-memory transcript; snapcompact-budget rebuilt a session over the closed manager and the exit diagnostics read released entries. - Snapcompact reopens the persisted file for its replacement session; exit diagnostics move to disk-backed managers and assert the exit marker from a reopened manager, proving actual durability. --- .../agent-session-snapcompact-budget.test.ts | 5 +++++ .../test/session-exit-diagnostics.test.ts | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/coding-agent/test/agent-session-snapcompact-budget.test.ts b/packages/coding-agent/test/agent-session-snapcompact-budget.test.ts index d3f3d257e..d100024c3 100644 --- a/packages/coding-agent/test/agent-session-snapcompact-budget.test.ts +++ b/packages/coding-agent/test/agent-session-snapcompact-budget.test.ts @@ -246,6 +246,11 @@ describe("AgentSession snapcompact frame-budget sizing", () => { const model = session.model; if (!model) throw new Error("Expected model"); await session.dispose(); + // dispose() released the manager's in-memory transcript; reopen the + // persisted file for the replacement session, as revival paths do. + const sessionFile = sessionManager.getSessionFile(); + if (!sessionFile) throw new Error("Expected a persisted session file"); + sessionManager = await SessionManager.open(sessionFile, tempDir.path()); const unknownWindowModel = { ...model, contextWindow: 0 }; session = new AgentSession({ agent: new Agent({ diff --git a/packages/coding-agent/test/session-exit-diagnostics.test.ts b/packages/coding-agent/test/session-exit-diagnostics.test.ts index 466f85526..4718716bf 100644 --- a/packages/coding-agent/test/session-exit-diagnostics.test.ts +++ b/packages/coding-agent/test/session-exit-diagnostics.test.ts @@ -67,7 +67,7 @@ describe("session exit diagnostics", () => { const modelRegistry = new ModelRegistry(authStorage); const model = getBundledModel("anthropic", "claude-sonnet-4-5"); if (!model) throw new Error("Expected built-in anthropic model to exist"); - const sessionManager = SessionManager.inMemory(tempDir.path()); + const sessionManager = SessionManager.create(tempDir.path(), tempDir.path()); const agent = new Agent({ initialState: { model, @@ -116,9 +116,15 @@ describe("session exit diagnostics", () => { await session.dispose(); session = undefined; - const exitEntry = sessionManager + // dispose() released the in-memory transcript; the exit marker's contract + // is durability, so assert against the persisted file. + const sessionFile = sessionManager.getSessionFile(); + if (!sessionFile) throw new Error("Expected a persisted session file"); + const reopened = await SessionManager.open(sessionFile, tempDir.path()); + const exitEntry = reopened .getEntries() .find(entry => entry.type === "custom" && entry.customType === SESSION_EXIT_CUSTOM_TYPE); + await reopened.close(); if (exitEntry?.type !== "custom") throw new Error("Expected session exit marker"); expect(exitEntry.data).toMatchObject({ reason: "dispose", @@ -140,7 +146,7 @@ describe("session exit diagnostics", () => { const modelRegistry = new ModelRegistry(authStorage); const model = getBundledModel("anthropic", "claude-sonnet-4-5"); if (!model) throw new Error("Expected built-in anthropic model to exist"); - const sessionManager = SessionManager.inMemory(tempDir.path()); + const sessionManager = SessionManager.create(tempDir.path(), tempDir.path()); const agent = new Agent({ initialState: { model, @@ -187,9 +193,13 @@ describe("session exit diagnostics", () => { await teardown(postmortem.Reason.SIGTERM); session = undefined; - const exitEntry = sessionManager + const sessionFile = sessionManager.getSessionFile(); + if (!sessionFile) throw new Error("Expected a persisted session file"); + const reopened = await SessionManager.open(sessionFile, tempDir.path()); + const exitEntry = reopened .getEntries() .find(entry => entry.type === "custom" && entry.customType === SESSION_EXIT_CUSTOM_TYPE); + await reopened.close(); if (exitEntry?.type !== "custom") throw new Error("Expected session exit marker"); expect(exitEntry.data).toMatchObject({ reason: "sigterm",