Commit a351dab
committed
Fix integration test race condition with AI SDK dynamic imports
## Problem
Integration tests were failing in CI with:
"Failed to create model: ReferenceError: You are trying to `import` a
file outside of the scope of the test code."
This only occurred when multiple tests ran concurrently in CI, not locally.
## Root Cause
AI SDK providers use dynamic imports for lazy loading (to optimize startup
time from 6-13s → 3-6s). Under high concurrency in CI (8 workers × 11 test
files × concurrent tests within files), Jest/Bun's module resolution has a
race condition where multiple simultaneous dynamic imports of the same
module can fail.
## Solution
Preload AI SDK providers once during test setup, similar to how we preload
tokenizer modules. This ensures subsequent dynamic imports hit the module
cache instead of racing.
- Added `preloadAISDKProviders()` function to aiService.ts
- Called during `setupWorkspace()` alongside `loadTokenizerModules()`
- Preserves lazy loading in production (startup optimization)
- Eliminates race condition in concurrent test environment
## Testing
- ✅ Tests pass locally with concurrent execution
- ✅ No impact on production startup time (preload only in tests)
- ✅ No changes to test behavior, only timing/reliability
Fixes the flaky integration test failures in PR #259.1 parent 1cbbd4b commit a351dab
2 files changed
+22
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
93 | 110 | | |
94 | 111 | | |
95 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
157 | 162 | | |
158 | 163 | | |
159 | 164 | | |
| |||
0 commit comments