Repository navigation
Stabilize lazy UI tests by awaiting module completion - #7673
Merged
Merged
Conversation
ymichael
added a commit
that referenced
this pull request
Nov 17, 2026
#7678) ## Human comments ## What was wrong Functional UI suites charged cold module transformation against short setup or DOM assertion deadlines. Cold-load tests also released import gates without waiting for the real import to finish. CI reported missing controls, skipped suites after hook timeouts, and typing into detached placeholder inputs. ## What changed Functional palette and paste tests load their real dependencies before asserting behavior. The separate cold-open palette test retains its unloaded interactions and waits for the existing controlled import to finish after release. Terminal clipboard tests await the actual terminal open call already observed by their fixture. Existing behavior assertions remain, and no retry, timeout, or CI job was added. Thread-search interactions also await the real split-module React commit before capturing input elements. With seed 8821, findByRole returned the placeholder input, which was detached before the test typed into it; importing the module before the suite alone did not wait for the split component to commit. The separate cold-open test still exercises typing during download. ## How you verified Injected a 1.5-second delay into the real lazy module loading paths: all four old cases fail with the observed signatures (263 pass, 4 fail). With the fixes and the same delay, all 267 tests pass. Removed every injection and reran the four full files through Turbo: 267 pass. App lint and typecheck pass; formatting and whitespace checks clean. This follows the same readiness class addressed in #7673. - Full seed 8821 discovered the project-highlight failure. The same 69-case palette file reproduces it, and temporary inspection confirms the captured input is detached and differs from the current combobox. The corrected helper passes all 70 palette/cold-open tests with both seeds 8821 and 7674; 7 static-check tasks pass. All diagnostic logging was removed. - Native Windows exposed the same unfinished-import boundary in sidebar customization retry. A finite sweep found it in the cold HTML and KaTeX tests too. These three tests now await the actual import inside React act after the original cold interactions. A 1.2-second import delay fails all three before and passes after; broken retry, sanitizer removal, and suppressed math rendering still fail. Ten affected/sibling files pass all 29 tests, and 7 static-check tasks pass. Existing timeouts and cold-load assertions are unchanged. - A later native run hit the 10-second hook deadline while importing the queued-message module. Both prompt-area functional suites now prepare that same module during test-file collection. An 11-second delay in the real module reproduces both old hook failures and passes all 77 affected cases afterward; removing actual queued-edit wiring still fails. All 144 functional/real queued-list/cold-list cases and 7 static-check tasks pass. No cold-load assertions or timer budgets changed. - The finite setup sweep covers 16 pure preload hooks across 15 functional files: queued lists, model menus, plugin chat, file diffs, HTML/plugin Markdown, and sidebar customization. The same 11-second delay in each real loader family fails the old hooks and passes after collection-time preparation. Incremental Markdown also prepares the real KaTeX module before its existing render warm-up; the render assertion is preserved and still rejects missing math rendering. All 483 cases across 23 functional/real-rendering/cold-load files pass, as do 7 static-check tasks. Fixture-only hooks and deliberate cold-load gates remain unchanged. The complete integration branch containing this and the related flake repairs passed the unchanged [native CI workflow](https://github.com/get-bb/bb/actions/runs/44130300753): 47 successful jobs and one skipped job. This uses normal Turbo cache reuse; it is not a claim that every task reran from scratch. > AGENT GENERATED
ymichael
added a commit
that referenced
this pull request
Nov 18, 2026
## Human comments
## What was wrong
App tests had no shared way to wait for a lazy module. Each test that
rendered a `defineSplit`, `React.lazy` or dynamic-import loader made up
its own wait: `await import("./X")` inside `act`, deferred gates in
`vi.mock` factories, a `findBy` with its 1 s deadline, counted
`setTimeout(0)` loops, `vi.dynamicImportSettled()`, a `{ timeout: 5_000
}` bump, or a collection-time raw import. On a cold runner the transform
beat whichever deadline the copy had. Tests also passed only because a
sibling test had already loaded the module. Each flake was fixed again
in the file where it appeared.
Past fixes for this root cause:
- #4911: FilePreview and SplitThreadArea assertions relied on sibling
tests warming the lazy renderer and panel.
- #6851: FilePreview asserted before the lazy code renderer loaded.
- #6938: a cold Vite transform counted against `findByText`'s 1 s
deadline (lazy plugin renderers).
- #7673: a 1 s readiness wait raced the real import (voice preferences,
KaTeX clipboard, model picker and palette cold-open).
- #7678: cold transforms raced short deadlines across functional UI
suites (palette, thread search, sidebar retry, KaTeX, cold HTML, queued
messages, terminal clipboard, prompt paste). Its body lists four rounds
of follow-ups in the same PR.
- #7684: the lazy panel preload in ServerMoveOverlay.
Each was a per-file patch. None stops the next test from making the same
mistake.
## What changed
**Guard (`apps/app/vite-test-lazy-imports.ts`, `src/test/setup.ts`).** A
test-only Vite transform wraps every dynamic `import()` in app source.
Production code is unchanged. During each test the setup holds every
such import until the test settles it. A test that asserts lazy content
without waiting now fails deterministically, on every machine and in
every order. Its error names the held or loading module:
> Lazy imports had not settled when this test failed:
"./MicrophonePreferences" (held). …
**One signal (`src/test/lazy-modules.ts`).**
- `await settleLazyModules()` resolves once every import has loaded,
including imports that loading starts, and React has committed.
- `await settleLazyModules(operation)` covers tests that await a
production promise whose chain loads code, such as
`bootPluginFrontends()`.
- Testing Library `findBy*` and `waitFor` settle pending imports before
they poll, so the ordinary idiom is correct for lazy content without
per-test code. `vi.waitFor` does not settle, so cold-load tests use it
to poll while an import is still pending.
**Copies deleted.**
- Module-specific `await import()` waits in VoiceInputButton,
SelectableMessageProse (×2), FilePreview and thread search.
- Raw `beforeAll`/top-level preloads in CommandPalette,
PromptBoxInternal paste and ServerMoveOverlay.
- `ready`/`loaded`/`release` deferred gates in the CommandPalette and
ModelReasoningPicker cold-open tests, KaTeX loader, cold HTML, lazy
plugin renderers, CodeHosts cold-load, sidebar retry and queued
messages. The hold now does their job.
- `vi.importActual` preloads in lazy-plugin-renderers (#6938) and
`vi.dynamicImportSettled()` in useCodeRendererPreloads.
- The `flushLoad` (`setTimeout(0)` in `act`) helper in
ThreadDetailWorkerPoolProvider.
- The "5 ticks" loops in SplitThreadArea.environment-archive.
- The `{ timeout: 5_000 }` waits in AppFileExternalNavigationHost.
- The `await act(async () => { await opened })` wait in the terminal
clipboard fixture.
**Migrated callers.** The guard also found tests that passed only by
order or timing: timeline row isolation, sender metadata and plugin-slot
render counts, which asserted before a lazy row view committed. It also
found the new `plugin-frontend-boot-catch-up.test.ts` from #7615, which
awaited a held import.
**Kept.** Collection-time `await Split.preload()` stays where a whole
suite renders a heavy split. That is fixture preparation through the
production API; it races no deadline. The two plugin-frontend boot tests
now load `./plugin-frontend` at collection time, because that real
import takes about 8.5 s on main too. `docs/ui-code-splitting.md` gains
a "Test lazy boundaries" section describing the contract.
No per-test timeouts, counts or other tuned numbers were added; two 5 s
overrides were removed. No production code, plugin SDK or wire changes.
## How you verified
- **Guard fails on main for the known cases.** With only the hold
applied to main's tests (no signal, no migration), the full `@bb/app`
suite failed 44 files / ~70 tests. That includes every file patched by
#6851, #7673, #7678 and #7684, failing in their current, patched form,
because each waits on a module-specific import rather than the app's own
load.
- **Signal removes the need for the patches.** I injected a 1.5 s delay
into every real lazy import, as #7678 did. Then I ran the naive,
pre-patch forms of the VoiceInputButton (#7673), SelectableMessageProse
(#7673), FilePreview (#6851) and CommandPalette thread-search (#7678)
tests. With main's behaviour: 6 failed, 187 passed. With the signal: 193
passed. The delay and naive forms were reverted afterwards.
- **Mechanism test.** `src/test/lazy-modules.test.tsx` checks four
things: hold until settle, synchronous assertions after settle, `findBy`
without a module wait, and imports started inside an awaited operation.
Re-introducing the deadlock I hit (holding imports while awaiting an
operation) fails the last case.
- `pnpm exec turbo run lint typecheck test --filter=@bb/app` after
rebasing on 77e45fa: 689 files, 7136 tests passed. One failure,
`plugin-frontend-boot-catch-up` from #7615, was migrated above; that
file and its sibling now pass.
- Shuffled (`--sequence.shuffle --sequence.seed=8821`): 685 of 686 files
passed. `SplitThreadArea.test.tsx › carries maximization…` timed out
once at its 1 s `waitFor` with no lazy imports pending. It passed 3 of 3
times alone with the same seed, so I count it as CPU contention, not
this change.
## Follow-up: imports that start just after a wait begins
`defineSplit` starts its `import()` one microtask after render. In
`fireEvent.click(...)` followed by `waitFor(...)`, the wait looked for
pending imports before that import started, found none, skipped
settling, and raced its 1 s deadline again.
`AppFileExternalNavigationHost.test.tsx`, whose 5 s timeout this PR
removed, failed 2 of 3 local runs on its own. `waitFor`/`findBy` now
always settle before and after polling. `lazy-modules.test.tsx` gains a
case for an import that starts a microtask after render and outlasts
`findBy`'s deadline. It fails without the change.
Always settling exposed `PromptBoxInternal.test.tsx › defers compact
content…`. Escape restores focus to the prompt editor through TipTap's
`focus` command, which runs one animation frame later and dismisses any
open plugin popup. The test reopened the popup inside that frame. On
main it passed only because it asserted before the frame fired; the
popup closed right after. It now lets that frame pass before reopening.
Verified with every app lazy import's result delayed 1.5 s: the 9
touched files that failed 6 tests on main pass 216/216.
> AGENT GENERATED
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
The clipboard, microphone-preferences, and cold model-picker tests start Testing Library's default one-second readiness wait while real lazy modules are still loading. Slow module loading fails the test before the asserted interaction can execute. Recent evidence includes math clipboard and model picker failures in run 44026483892, microphone preferences in run 44016714189, and another clipboard failure in run 44029217817. These runs passed on rerun without source changes.
What changed
Await the real KaTeX and microphone module imports inside React act after rendering/opening their UI. Extend the model picker's existing controlled import gate with a completion signal, and await it after releasing the simulated download. Retain all clipboard, focus, selection, accessibility, and action assertions. Keep job counts, runner sizes, test timeouts, and production code unchanged.
How you verified
Temporarily delayed the real imports by 1.5 seconds, preserving their actual implementations. Before the fix, the same three CI test cases failed (79 passed, three failed). With the synchronization fixes and delay still present, all 82 tests passed. Removed all delay instrumentation, then ran:
pnpm exec turbo run test --filter=@bb/app -- src/components/thread/timeline/SelectableMessageProse.clipboard.test.tsx src/components/promptbox/VoiceInputButton.test.tsx src/components/pickers/ModelReasoningPicker.cold-open.test.tsx src/components/ui/markdown-katex-loader.test.tsx— 83 passed.pnpm exec turbo run lint typecheck --filter=@bb/app— passed.The audit sampled 50 recent CI runs, including six with reruns and nine whose latest attempt failed. The most repeated UI signatures were microphone preferences and math clipboard (two failed jobs each). Other failures included terminal/panel/palette readiness, provider replay mismatches, a 15-second database history-fixture timeout, and performance-diagnostics timing assertions. Those are follow-up candidates, not claimed fixed or all classified as flakes by this PR.