From 73865b38900610b92dedf0d3de9ab43c12a2381c Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Sun, 30 Aug 2026 13:49:03 -0400 Subject: [PATCH] fix(studio): drop the resurrected WebMCP polyfill assertion #3516 merged from a branch cut before da6514d45 and brought back `expect(document).not.toHaveProperty("modelContext")`, along with the old test title. This re-applies that fix. The assertion is racy, not merely wrong. The hook awaits a dynamic import of the `@mcp-b/global` polyfill inside its mount effect, so whether `document.modelContext` exists when the assertion runs depends only on whether that import has resolved yet. `await act()` usually returns first, which is why main went green while another PR's run went red. Inserting a 100ms wait before the assertion on the current tip makes it fail every time, and the failure dump shows all five tools registered through the polyfill: the real behaviour is the opposite of what the line asserted. Installing `document.modelContext` where the browser has none is the polyfill's job. What the case is really for is that mounting does not throw, so a browser without native WebMCP still boots Studio. --- packages/studio/src/webmcp/useStudioAgentTools.test.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/studio/src/webmcp/useStudioAgentTools.test.tsx b/packages/studio/src/webmcp/useStudioAgentTools.test.tsx index 3a9a3ee988..6a408c583d 100644 --- a/packages/studio/src/webmcp/useStudioAgentTools.test.tsx +++ b/packages/studio/src/webmcp/useStudioAgentTools.test.tsx @@ -178,16 +178,16 @@ describe("useStudioAgentTools", () => { expect(signal?.aborted).toBe(true); }); - it("registers nothing when the browser has no WebMCP", async () => { + it("boots cleanly when the browser has no native WebMCP", async () => { removeModelContext(); await act(async () => { mountTools(deps({ getSnapshot: () => snapshot() })); }); - // The assertion is that mounting did not throw; a browser without the API - // must still boot Studio. - expect(document).not.toHaveProperty("modelContext"); + // The assertion is that mounting did not throw; a browser without the + // native API must still boot Studio. The polyfill may install + // document.modelContext as a fallback — that is expected. }); it("registers nothing when the preference is turned off", async () => {