diff --git a/tests/ipcMain/helpers.ts b/tests/ipcMain/helpers.ts index c1d3e69b0..c21f0a3d5 100644 --- a/tests/ipcMain/helpers.ts +++ b/tests/ipcMain/helpers.ts @@ -22,8 +22,17 @@ export const SSH_INIT_WAIT_MS = 7000; // SSH init includes sync + checkout + hoo export const HAIKU_MODEL = "anthropic:claude-haiku-4-5"; // Fast model for tests export const TEST_TIMEOUT_LOCAL_MS = 25000; // Recommended timeout for local runtime tests export const TEST_TIMEOUT_SSH_MS = 60000; // Recommended timeout for SSH runtime tests -export const STREAM_TIMEOUT_LOCAL_MS = 15000; // Stream timeout for local runtime -export const STREAM_TIMEOUT_SSH_MS = 25000; // Stream timeout for SSH runtime +// Stream timeouts: CI environments need longer timeouts due to API rate limits and slower execution +// Local development typically completes faster +const CI_TIMEOUT_MULTIPLIER = 2.5; +const isCI = process.env.CI === "true" || process.env.CI === "1"; + +export const STREAM_TIMEOUT_LOCAL_MS = isCI ? 37500 : 15000; // 37.5s in CI, 15s locally +export const STREAM_TIMEOUT_SSH_MS = isCI ? 62500 : 25000; // 62.5s in CI, 25s locally + +// Additional stream timeout constants for tests (also CI-aware) +export const STREAM_TIMEOUT_SHORT_MS = isCI ? 25000 : 10000; // For quick operations +export const STREAM_TIMEOUT_MEDIUM_MS = isCI ? 75000 : 30000; // For standard operations /** * Generate a unique branch name @@ -613,7 +622,7 @@ export async function waitForInitEnd( export async function waitForStreamSuccess( sentEvents: Array<{ channel: string; data: unknown }>, workspaceId: string, - timeoutMs = 30000 + timeoutMs = STREAM_TIMEOUT_MEDIUM_MS // Use CI-aware timeout (75s in CI, 30s locally) ): Promise { const collector = createEventCollector(sentEvents, workspaceId); await collector.waitForEvent("stream-end", timeoutMs); diff --git a/tests/ipcMain/sendMessage.test.ts b/tests/ipcMain/sendMessage.test.ts index 2363c4bc9..cbdddc859 100644 --- a/tests/ipcMain/sendMessage.test.ts +++ b/tests/ipcMain/sendMessage.test.ts @@ -18,6 +18,8 @@ import { readChatHistory, TEST_IMAGES, modelString, + STREAM_TIMEOUT_SHORT_MS, + STREAM_TIMEOUT_MEDIUM_MS, } from "./helpers"; import type { StreamDeltaEvent } from "../../src/types/stream"; import { IPC_CHANNELS } from "../../src/constants/ipc-constants"; @@ -611,7 +613,7 @@ describeIntegration("IpcMain sendMessage integration tests", () => { const collector = await waitForStreamSuccess( env.sentEvents, workspaceId, - provider === "openai" ? 30000 : 10000 + provider === "openai" ? STREAM_TIMEOUT_MEDIUM_MS : STREAM_TIMEOUT_SHORT_MS ); // Get the final assistant message @@ -858,7 +860,11 @@ These are general instructions that apply to all modes. ); // Collect response - const collector = await waitForStreamSuccess(env.sentEvents, workspaceId, 10000); + const collector = await waitForStreamSuccess( + env.sentEvents, + workspaceId, + STREAM_TIMEOUT_SHORT_MS + ); results[provider] = { success: result.success, @@ -1257,7 +1263,11 @@ These are general instructions that apply to all modes. expect(result.success).toBe(true); // Wait for stream to complete - const collector = await waitForStreamSuccess(env.sentEvents, workspaceId, 10000); + const collector = await waitForStreamSuccess( + env.sentEvents, + workspaceId, + STREAM_TIMEOUT_SHORT_MS + ); // Get the final assistant message const finalMessage = collector.getFinalMessage(); @@ -1531,7 +1541,11 @@ describe.each(PROVIDER_CONFIGS)("%s:%s image support", (provider, model) => { expect(result.success).toBe(true); // Wait for stream to complete - const collector = await waitForStreamSuccess(env.sentEvents, workspaceId, 30000); + const collector = await waitForStreamSuccess( + env.sentEvents, + workspaceId, + STREAM_TIMEOUT_MEDIUM_MS + ); // Verify we got a response about the image const deltas = collector.getDeltas(); @@ -1568,7 +1582,7 @@ describe.each(PROVIDER_CONFIGS)("%s:%s image support", (provider, model) => { expect(result.success).toBe(true); // Wait for stream to complete - await waitForStreamSuccess(env.sentEvents, workspaceId, 30000); + await waitForStreamSuccess(env.sentEvents, workspaceId, STREAM_TIMEOUT_MEDIUM_MS); // Read history from disk const messages = await readChatHistory(env.tempDir, workspaceId);