From c1b295d003f63f2ec7f524a74f9e464ec0fc4cd3 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 24 Aug 2026 21:31:13 -0700 Subject: [PATCH] test(desktop): stop the syntax-diff mock factory from leaking unhandled rejections (#94415) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The diff-lines error-boundary test mocked './syntax-diff' with a factory that THREW. vitest hoists the factory and registers its module promise in the mocker registry; a throwing factory leaves rejected promises there, and under CI load one escapes as "Vitest caught 1 unhandled error during the test run" attributed to whichever sibling file the worker is running (user-message-edit.test.tsx in run 32803716726) — an intermittent js-tests red on green code. Rework: the factory now resolves to a component that throws the fetch error during render — the same way React surfaces a rejected lazy payload — so no rejected promise ever sits in the registry. Guard proof (sabotage A/B): with the local syntax-diff ErrorBoundary removed from diff-lines.tsx, the reworked test still fails (workspace fallback renders), so the #93479 regression pin is intact. Full ui project: 596 files / 5729 tests green, no unhandled errors in 3 full-run repetitions. --- .../src/components/chat/diff-lines.test.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/components/chat/diff-lines.test.tsx b/apps/desktop/src/components/chat/diff-lines.test.tsx index d33be05f18..7628a3f564 100644 --- a/apps/desktop/src/components/chat/diff-lines.test.tsx +++ b/apps/desktop/src/components/chat/diff-lines.test.tsx @@ -7,11 +7,20 @@ import { afterEach, describe, expect, it, vi } from 'vitest' // covers the *pending* state, so the rejection throws past it to the nearest // error boundary — which in production is the whole workspace `ContribBoundary` // — and blanks the transcript instead of degrading to the plain colored diff. -vi.mock('./syntax-diff', () => { - throw new Error( - 'Failed to fetch dynamically imported module: file:///Hermes.app/Contents/Resources/app.asar/dist/assets/syntax-diff-Bo0962zh.js' - ) -}) +// +// The mock resolves to a component that throws the fetch error during render — +// the same way React surfaces a rejected lazy payload (a rejected import +// re-throws at render time). Do NOT throw inside the factory itself: a +// throwing factory leaves rejected promises in the vitest mocker registry, +// and under CI load one escapes as an "unhandled error during the test run" +// attributed to whichever sibling test file the worker is running (#94415). +vi.mock('./syntax-diff', () => ({ + default: () => { + throw new Error( + 'Failed to fetch dynamically imported module: file:///Hermes.app/Contents/Resources/app.asar/dist/assets/syntax-diff-Bo0962zh.js' + ) + } +})) import { ErrorBoundary } from '@/components/error-boundary'