From 4bad13bda11adaca3a3a84733cf8b1aed0047ef2 Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Fri, 20 Nov 2026 21:53:26 +0000 Subject: [PATCH] fix(web): browser test mocks no longer hang the suite Two browser tests never finished loading, and vitest reports that only as a generic "error when mocking a module" once the run ends. ThreadRelationshipsControl replaced the environments module with two exports, so useEnvironments, which useSettings imports through threads.ts, was missing and the browser rejected the module. The mock now keeps the real module and overrides only the two hooks the test drives. ChatMarkdown's command mock awaited threads.ts from inside the factory that mocks use-atom-command, which useSettings imports while threads.ts is still evaluating, so the factory never resolved and the file collected no tests. The factory now reads threadEnvironment from a module-scope import. Model: grok-4.7 Task: fix the browser test project vi.mock loader failure Agent: magpie Lane: magpie Harness: t3/claude-code Model-family: Grok Model-generation: 4.7 Co-Authored-By: Claude Code --- .../ChatMarkdown.permissions.browser.test.tsx | 24 +++++++++---------- ...hreadRelationshipsControl.browser.test.tsx | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/web/src/components/ChatMarkdown.permissions.browser.test.tsx b/apps/web/src/components/ChatMarkdown.permissions.browser.test.tsx index 324c2c839ccd9..bfaba3e7b6e2f 100644 --- a/apps/web/src/components/ChatMarkdown.permissions.browser.test.tsx +++ b/apps/web/src/components/ChatMarkdown.permissions.browser.test.tsx @@ -12,6 +12,9 @@ import { expect, it, vi } from "vite-plus/test"; import { userEvent } from "vite-plus/test/browser"; import { act, render } from "../../test/render"; +// useSettings loads the mocked command module while threads.ts is still evaluating, +// so the factory reads threadEnvironment from here instead of importing it itself. +import { threadEnvironment } from "../state/threads"; import { useRightPanelStore } from "../rightPanelStore"; const state = vi.hoisted(() => ({ @@ -32,18 +35,15 @@ vi.mock(import("../state/use-atom-query-runner"), async (original) => ({ ...(await original()), useAtomQueryRunner: (() => state.search) as never, })); -vi.mock(import("../state/use-atom-command"), async (original) => { - const { threadEnvironment } = await import("../state/threads"); - return { - ...(await original()), - useAtomCommand: ((command: unknown) => - command === threadEnvironment.linkPullRequest - ? state.link - : command === threadEnvironment.unlinkPullRequest - ? state.unlink - : state.openEditor) as never, - }; -}); +vi.mock(import("../state/use-atom-command"), async (original) => ({ + ...(await original()), + useAtomCommand: ((command: unknown) => + command === threadEnvironment.linkPullRequest + ? state.link + : command === threadEnvironment.unlinkPullRequest + ? state.unlink + : state.openEditor) as never, +})); vi.mock(import("../state/session"), async (original) => { const { useSyncExternalStore } = await import("react"); const readEnvironmentScope = (id: EnvironmentId | null, scope: AuthEnvironmentScope) => diff --git a/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx b/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx index 1a0fb5bd406f8..aae7bc13fdca4 100644 --- a/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx +++ b/apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx @@ -41,7 +41,8 @@ vi.mock(import("../../state/entities"), () => ({ useHiddenThreadKeys: (() => new Set()) as never, useAnyEnvironmentHiding: (() => false) as never, })); -vi.mock(import("../../state/environments"), () => ({ +vi.mock(import("../../state/environments"), async (original) => ({ + ...(await original()), useEnvironment: (() => null) as never, useEnvironmentProviders: (() => new Map()) as never, }));