resumed tool to return value

This commit is contained in:
ihrpr 2025-04-15 16:37:31 +01:00
commit f1e6acb17d
No known key found for this signature in database

View file

@ -242,7 +242,7 @@ describe('Transport resumability', () => {
params: {
name: 'run-notifications',
arguments: {
count: 5,
count: 3,
interval: 10
}
}
@ -251,27 +251,23 @@ describe('Transport resumability', () => {
onresumptiontoken: onLastEventIdUpdate
});
// Wait for some notifications to arrive (not all)
// Wait for some notifications to arrive (not all) - shorter wait time
await new Promise(resolve => setTimeout(resolve, 20));
// Verify we received some notifications and lastEventId was updated
expect(notifications.length).toBeGreaterThan(0);
expect(notifications.length).toBeLessThan(5);
expect(notifications.length).toBeLessThan(4);
expect(onLastEventIdUpdate).toHaveBeenCalled();
expect(lastEventId).toBeDefined();
// Store original notification count for later comparison
const firstClientNotificationCount = notifications.length;
// Disconnect first client without waiting for completion
// When we close the connection, it will cause a ConnectionClosed error for
// any in-progress requests, which is expected behavior
// We need to catch the error since closing the transport will
// cause the pending toolPromise to reject with a ConnectionClosed error
await transport1.close();
// Try to cancel the promise, but ignore errors since it's already being handled
toolPromise.catch(err => {
// Save the promise so we can catch it after closing
const catchPromise = toolPromise.catch(err => {
// This error is expected - the connection was intentionally closed
if (err?.code !== -32000) { // ConnectionClosed error code
console.error("Unexpected error type during transport close:", err);
@ -279,6 +275,14 @@ describe('Transport resumability', () => {
});
// Add a short delay to ensure clean disconnect before reconnecting
await new Promise(resolve => setTimeout(resolve, 10));
// Wait for the rejection to be handled
await catchPromise;
// Create second client with same client ID
const client2 = new Client({
id: clientId,
@ -307,7 +311,7 @@ describe('Transport resumability', () => {
name: 'run-notifications',
arguments: {
count: 1,
interval: 50
interval: 5
}
}
}, CallToolResultSchema, {
@ -316,13 +320,10 @@ describe('Transport resumability', () => {
});
// Verify we eventually received at leaset a few motifications
expect(notifications.length).toBeGreaterThan(2);
expect(notifications.length).toBeGreaterThan(1);
// Verify the second client received notifications that the first client didn't
expect(notifications.length).toBeGreaterThan(firstClientNotificationCount);
// Clean up
await transport2.close();
});