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.
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user