Skip to content

Commit 2c5365a

Browse files
authored
🤖 fix: add module preloading to fix flaky stream error tests (#746)
Generated with `mux` Fixes intermittent failures in: - `tests/ipcMain/streamErrorRecovery.test.ts` - `tests/ipcMain/sendMessage.errors.test.ts` **Root cause**: Concurrent tests were racing on dynamic module imports (tokenizer, AI SDK providers) which could cause intermittent failures when modules weren't fully loaded before test execution. **Fix**: Add `preloadTestModules()` call to `beforeAll` hooks inside the `describeIntegration` blocks, ensuring modules are loaded before any concurrent tests start. Also moved `beforeAll`/`afterAll` hooks inside the `describeIntegration` blocks so they only run when integration tests are enabled.
1 parent 7fe9486 commit 2c5365a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tests/ipcMain/sendMessage.errors.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
configureTestRetries,
1616
} from "./helpers";
1717
import { createSharedRepo, cleanupSharedRepo, withSharedWorkspace } from "./sendMessageTestHelpers";
18+
import { preloadTestModules } from "./setup";
1819
import type { StreamDeltaEvent } from "../../src/common/types/stream";
1920
import { IPC_CHANNELS } from "../../src/common/constants/ipc-constants";
2021

@@ -40,9 +41,13 @@ const PROVIDER_CONFIGS: Array<[string, string]> = [
4041
// - Longer running tests (tool calls, multiple edits) can take up to 30s
4142
// - Test timeout values (in describe/test) should be 2-3x the expected duration
4243

43-
beforeAll(createSharedRepo);
44-
afterAll(cleanupSharedRepo);
4544
describeIntegration("IpcMain sendMessage integration tests", () => {
45+
beforeAll(async () => {
46+
await preloadTestModules();
47+
await createSharedRepo();
48+
});
49+
afterAll(cleanupSharedRepo);
50+
4651
configureTestRetries(3);
4752

4853
// Run tests for each provider concurrently

tests/ipcMain/streamErrorRecovery.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
* test the recovery path without relying on actual network failures.
1717
*/
1818

19-
import { setupWorkspace, shouldRunIntegrationTests, validateApiKeys } from "./setup";
19+
import {
20+
setupWorkspace,
21+
shouldRunIntegrationTests,
22+
validateApiKeys,
23+
preloadTestModules,
24+
} from "./setup";
2025
import {
2126
sendMessageWithModel,
2227
createEventCollector,
@@ -220,6 +225,8 @@ async function collectStreamUntil(
220225
}
221226

222227
describeIntegration("Stream Error Recovery (No Amnesia)", () => {
228+
beforeAll(preloadTestModules);
229+
223230
test.concurrent(
224231
"should preserve exact prefix and continue from exact point after stream error",
225232
async () => {

0 commit comments

Comments
 (0)