Skip to content

Commit 1ba24b5

Browse files
cliffhallclaude
andcommitted
test(integration): harden connect-race regression test per review
Address the two non-blocking suggestions from the PR review: - Replace the 100ms settle sleep with waitForEvent() on the managers' change events, so the test is deterministic against slow CI instead of racing a fixed timeout. - Assert a second affected primitive (ManagedResourcesState alongside ManagedToolsState). The fix is a single shared line, but covering two distinct capabilities guards against a future change gating one primitive differently. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 2e77e6f commit 1ba24b5

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎clients/web/src/test/integration/mcp/inspectorClient.test.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,15 @@ describe("InspectorClient", () => {
689689
expect((await client.listTools()).tools.length).toBeGreaterThan(0);
690690
});
691691

692-
it("ManagedToolsState populates on connect (regression: capability gate must see capabilities before the connect event)", async () => {
692+
it("managed list states populate on connect (regression: capability gate must see capabilities before the connect event)", async () => {
693693
// Regression for #1395 + connect-ordering: the managed list-state managers
694694
// refresh on the "connect" event and gate their list RPC on
695695
// getCapabilities(). If "connect" is dispatched before fetchServerInfo()
696696
// populates capabilities, the synchronous gate reads undefined and wipes
697697
// the list to empty — tools/prompts/resources all vanish on every connect.
698+
// The single fix is shared by all the managed states, so we cover tools
699+
// and resources (two distinct capabilities) to guard against a future
700+
// change gating only one primitive differently.
698701
client = new InspectorClient(
699702
{
700703
type: "stdio",
@@ -704,15 +707,22 @@ describe("InspectorClient", () => {
704707
{ environment: { transport: createTransportNode } },
705708
);
706709
const toolsState = new ManagedToolsState(client);
710+
const resourcesState = new ManagedResourcesState(client);
707711

712+
// Await the change events the connect-triggered refresh() emits rather than
713+
// a fixed sleep — refresh() is async past its synchronous capability gate.
714+
const toolsChanged = waitForEvent(toolsState, "toolsChange");
715+
const resourcesChanged = waitForEvent(resourcesState, "resourcesChange");
708716
await client.connect();
709-
// Settle: the connect-triggered refresh() is async past its capability gate.
710-
await new Promise((r) => setTimeout(r, 100));
717+
await Promise.all([toolsChanged, resourcesChanged]);
711718

712719
expect(client.getCapabilities()?.tools).toBeDefined();
713720
expect(toolsState.getTools().length).toBeGreaterThan(0);
721+
expect(client.getCapabilities()?.resources).toBeDefined();
722+
expect(resourcesState.getResources().length).toBeGreaterThan(0);
714723

715724
toolsState.destroy();
725+
resourcesState.destroy();
716726
});
717727
});
718728

0 commit comments

Comments
 (0)