Skip to content

Commit adeb25d

Browse files
test: add E2E test for session store delete and remove unused import
- Add test verifying onDelete is called when deleting a session - Remove unused getFinalAssistantMessage import Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a0daf7c commit adeb25d

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

nodejs/test/e2e/session_store.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import { describe, expect, it, vi } from "vitest";
66
import { approveAll, type SessionEvent, type SessionStoreConfig } from "../../src/index.js";
77
import { createSdkTestContext } from "./harness/sdkTestContext.js";
8-
import { getFinalAssistantMessage } from "./harness/sdkTestHelper.js";
98

109
/**
1110
* In-memory session event store for testing.
@@ -174,4 +173,33 @@ describe("Session Store", async () => {
174173
}),
175174
).rejects.toThrow(/Cannot change storage backend/);
176175
});
176+
177+
it("should call onDelete when deleting a session", async () => {
178+
const store = new InMemorySessionStore();
179+
const storeConfig = store.toConfig("memory://test-delete");
180+
181+
const session = await client.createSession({
182+
onPermissionRequest: approveAll,
183+
sessionStore: storeConfig,
184+
});
185+
const sessionId = session.sessionId;
186+
187+
// Send a message to create some events
188+
await session.sendAndWait({ prompt: "What is 7 + 7?" });
189+
190+
// Wait for events to flush
191+
await vi.waitFor(
192+
() => expect(store.hasSession(sessionId)).toBe(true),
193+
{ timeout: 10_000, interval: 200 },
194+
);
195+
196+
expect(store.calls.delete).toBe(0);
197+
198+
// Delete the session
199+
await client.deleteSession(sessionId);
200+
201+
// Verify onDelete was called and the session was removed from our store
202+
expect(store.calls.delete).toBeGreaterThan(0);
203+
expect(store.hasSession(sessionId)).toBe(false);
204+
});
177205
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
models:
2+
- claude-sonnet-4.5
3+
conversations:
4+
- messages:
5+
- role: system
6+
content: ${system}
7+
- role: user
8+
content: What is 7 + 7?
9+
- role: assistant
10+
content: 7 + 7 = 14

0 commit comments

Comments
 (0)