Skip to content

Commit 514e0e9

Browse files
committed
🤖 fix: add module preloading to fix flaky stream error tests
Both streamErrorRecovery.test.ts and sendMessage.errors.test.ts were failing intermittently with sendMessageWithModel returning success=false. 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 ed754d8 commit 514e0e9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* test the recovery path without relying on actual network failures.
1717
*/
1818

19-
import { setupWorkspace, shouldRunIntegrationTests, validateApiKeys } from "./setup";
19+
import { setupWorkspace, shouldRunIntegrationTests, validateApiKeys, preloadTestModules } from "./setup";
2020
import {
2121
sendMessageWithModel,
2222
createEventCollector,
@@ -220,6 +220,8 @@ async function collectStreamUntil(
220220
}
221221

222222
describeIntegration("Stream Error Recovery (No Amnesia)", () => {
223+
beforeAll(preloadTestModules);
224+
223225
test.concurrent(
224226
"should preserve exact prefix and continue from exact point after stream error",
225227
async () => {

0 commit comments

Comments
 (0)