fix: fix flaky tests for use-project-picker-data hook#2355
Merged
Conversation
- Replace vi.clearAllMocks() with vi.resetAllMocks() to prevent mock implementation bleed-through between tests - Hoist DEFAULT_RECENT_IDS to module scope to prevent useMemo recomputation loops from referential instability - Consolidate shared default mock setup into beforeEach - Wrap paired assertions in single waitFor callbacks - Move getNetworkEvent into importMocks() for consistency - Expand beforeEach destructuring to satisfy Prettier printWidth - Remove redundant projectLookupService mock in recentProjects test - Apply Prettier formatting to keyboard-shortcuts.mdx and theming.mdx Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
captaincrazybro
approved these changes
Jun 4, 2026
Contributor
captaincrazybro
left a comment
There was a problem hiding this comment.
LGTM! I'm gonna approve, but make sure you revert the changes review paratext did to the keyboard-shortcuts.mdx and themeing.mdx
Contributor
Author
|
Grrr.... |
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.
Code Review Summary
Branch: fix-flaky-tests
Base: origin/main
Date: 2026-06-02
Review model: Claude Sonnet 4.6
Files changed: 1
Overview
This change fixes flaky tests in
src/renderer/hooks/use-project-picker-data.hook.test.ts. The root cause wasvi.clearAllMocks()inbeforeEach, which only clears call history but leavesmockReturnValue/mockImplementationoverrides intact — allowing one test's mock setup to bleed into subsequent tests. Replacing it withvi.resetAllMocks()fully resets both call history and mock implementations, ensuring proper test isolation.Beyond the root-cause fix, the change consolidates shared default mock setup into
beforeEach(reducing per-test boilerplate), hoists a stableDEFAULT_RECENT_IDSconstant to module scope (preventinguseMemorecomputation loops from referential instability), and wraps paired assertions inside singlewaitForcallbacks (the correct React Testing Library pattern to avoid asserting on intermediate async states).API Changes
None. The only changed file is a test file — no public API surfaces were modified.
Findings
Critical — Must address before merge
None.
Important — Should address before merge
use-project-picker-data.hook.test.ts:92— Prettier formatting violation (fixed during review: expanded single-line destructuring to multi-line so the line fits within Prettier'sprintWidth)Minor — Consider
use-project-picker-data.hook.test.ts:183— Redundant mock setup (fixed during review: removedprojectLookupService.getMetadataForAllProjects.mockResolvedValue([])and unusedprojectLookupServicedestructure binding —beforeEachalready establishes this default aftervi.resetAllMocks())Template Propagation
Shared Regions Modified
None.
Extension Config Changes
None.
Positive Observations
vi.clearAllMocks()→vi.resetAllMocks()with a clear inline comment explaining the distinction (clearresets call history only;resetalso clearsmockReturnValue/mockImplementationoverrides) — makes the fix self-documenting.DEFAULT_RECENT_IDShoisted to module scope with a comment explaining the infinite re-render risk it prevents — good defensive documentation for a subtle referential-equality concern.beforeEachso individual tests only override what they specifically care about, making each test's intent immediately readable.waitForcallback — the right React Testing Library pattern to avoid asserting on stale intermediate render states.getNetworkEventmoved intoimportMocks()so all tests get it through the same consistent path, rather than one test importing it separately out of order.useDatamock factory simplified at the mock definition level now that the stable reference is handled at module scope.Interview Notes
Author purpose: fix flaky tests in
use-project-picker-data.hook.test.ts.Both findings were addressed during the review at the author's request — no dismissals. The author did not volunteer additional context or flag any tradeoffs or uncertainties.
In-Review Quality Check
Two fixes applied during the review interview:
beforeEachdestructuring from a single overlong line to multi-line. No other formatting changes to the test file.mockResolvedValue([])call and cleaned up the now-unusedprojectLookupServicebinding.Post-fix quality results:
npm run typecheck— PASSEDnpm run lint— PASSEDnpm run format— Applied auto-formatting to two pre-existing.mdxfiles (keyboard-shortcuts.mdx,theming.mdx) with unrelated table column drift; test file itself was unchanged.vitest run(test file only) — PASSED (7/7 tests)Suggested Review Focus
vi.resetAllMocks()change is the correct fix for the reported flakiness — verify the flaky tests were caused by mock implementation bleed-through rather than another source (e.g. async timing, module-level state).DEFAULT_RECENT_IDSmodule-scope constant is the right place for this — check whether other tests in the file rely on differentuseDatareturn shapes that could interact with this default.This change is