introduce onsessioninitialized to avoid race conditions

This commit is contained in:
ihrpr 2025-04-16 11:09:47 +01:00
commit 585dc06708
No known key found for this signature in database

View file

@ -187,15 +187,11 @@ describe("StreamableHTTPServerTransport", () => {
expect(sessionId).toBeDefined();
// Try second initialize
const secondInitMessage: JSONRPCMessage = {
jsonrpc: "2.0",
method: "initialize",
params: {
clientInfo: { name: "test-client-2", version: "1.0" },
protocolVersion: "2025-03-26",
},
id: "init-2",
const secondInitMessage = {
...TEST_MESSAGES.initialize,
id: "second-init"
};
const response = await sendPostRequest(baseUrl, secondInitMessage);
expect(response.status).toBe(400);
@ -1092,14 +1088,7 @@ describe("StreamableHTTPServerTransport in stateless mode", () => {
});
it("should handle POST requests with various session IDs in stateless mode", async () => {
// Initialize the server first
await fetch(baseUrl, {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json, text/event-stream" },
body: JSON.stringify({
jsonrpc: "2.0", method: "initialize", params: { clientInfo: { name: "test-client", version: "1.0" }, protocolVersion: "2025-03-26" }, id: "init-1"
}),
});
await sendPostRequest(baseUrl, TEST_MESSAGES.initialize);
// Try with a random session ID - should be accepted
const response1 = await fetch(baseUrl, {
@ -1131,13 +1120,7 @@ describe("StreamableHTTPServerTransport in stateless mode", () => {
// one standalone SSE stream at a time
// Initialize the server first
await fetch(baseUrl, {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json, text/event-stream" },
body: JSON.stringify({
jsonrpc: "2.0", method: "initialize", params: { clientInfo: { name: "test-client", version: "1.0" }, protocolVersion: "2025-03-26" }, id: "init-1"
}),
});
await sendPostRequest(baseUrl, TEST_MESSAGES.initialize);
// Open first SSE stream
const stream1 = await fetch(baseUrl, {