Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions tests/ipcMain/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<EventCollector> {
const collector = createEventCollector(sentEvents, workspaceId);
await collector.waitForEvent("stream-end", timeoutMs);
Expand Down
24 changes: 19 additions & 5 deletions tests/ipcMain/sendMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down