Repository navigation
test: import mocked-module graphs one at a time after vi.mock - #34103
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit details
No actionable comments were generated in the recent review.
|
Same Vitest registration race as the daemon-init fix: concurrent first imports can load dependencies before pending vi.mock/vi.doMock calls are registered.
55b2d9e to
2cb04e2
Compare
ELI5
Some test setup code loaded several modules at the same time right after registering mocks. Vitest can let those loads go ahead before the mocks are in place, so a test can quietly use the real module instead of the mock. This makes the two remaining places load modules one at a time. It follows up #34085, which fixed the same problem in the daemon-init tests.
What Changed
src/main/jira/__mocks__/jira-client-module.ts(used byclient.test.tsandclient-scoped-token.test.ts): callsvi.doMock('os', …)and then used toPromise.allthree dynamic imports. Now they're imported one after another, so theoshome-dir mock is registered before../clientand its dependencies load.src/renderer/src/lib/pane-manager/pane-tree-reparent-frame.test.ts: one test loadedpane-tree-opsand the mockedpane-dividertogether. It only raced when that test ran first (for example with-t). Now they're imported one at a time.Each site has a one-line comment giving the reason. No assertions changed.
Why
Mechanism (Vitest 5.0.5). The first dynamic import calls
resolveMocks(), which takes the queued mock ids and clears the queue before it awaits their resolution. A module fetch only waits for mocks while that queue is non-empty. So when several imports start at once, the later ones can load dependencies unmocked.Fix. A single first import waits for every mock to register, so loading one at a time closes the race. The modules are still evaluated once per reset and share one module graph, so behavior is unchanged.
Sweep. I checked every
Promise.all([... import(...)])insrc,testsandconfig. The others aren't affected: either the file has no pending mocks, or a static import has already flushed the queue, or the imports run inside a mock factory after registration (session-scanner-opencode-sqlite-coexistence.test.ts,language-detection-reconciliation.test.tsx, the cross-version wire tests).Linked Issue
N/A (follow-up to #34085).
Visual Proof
N/A: test-only change.
Testing
client.test.ts,client-scoped-token.test.tsandpane-tree-reparent-frame.test.tspass (50 tests). The reparent test also passes when run on its own with-t.pnpm tc:node,pnpm tc:web, oxlint, the ast-grep gates and the changed-code gate pass.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
Test-only. There's no runtime, SSH, mobile or wire impact. Until #34085 merges, this PR's unit shard 4 may still hit the daemon-init failure.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)