Skip to content

Commit db9ecdb

Browse files
authored
🤖 ci: reorganize integration tests (#716)
_Generated with `mux`_ Refactors the `sendMessage` integration test suite for better organization, maintainability, and performance. ## Changes ### Test Organization Split monolithic `sendMessage.test.ts` (1628 lines) into 5 thematic files: - `sendMessage.basic.test.ts` — core send/receive, interrupt, reconnection - `sendMessage.context.test.ts` — editing, history truncation, multi-turn conversations - `sendMessage.errors.test.ts` — validation, API key errors, model not found - `sendMessage.heavy.test.ts` — context limit / auto-truncation - `sendMessage.images.test.ts` — vision model tests ### Shared Workspace Helper Added `sendMessageTestHelpers.ts` with: - `withSharedWorkspace(provider, testFn)` — creates one git repo per test file instead of per-test - `withSharedWorkspaceNoProvider(testFn)` — for tests that verify behavior without provider config ### Setup Improvements - `setupWorkspace` and `setupWorkspaceWithoutProvider` now accept optional `existingRepoPath` for repo reuse - `buildLargeHistory` writes directly to `chat.jsonl` instead of sequential appends (30s → <1s) ## Results - Better test isolation and faster failure diagnosis - Reduced I/O overhead from shared git repo pattern - Prevents CI timeouts from monolithic test file
1 parent 75c93e7 commit db9ecdb

File tree

9 files changed

+1883
-1660
lines changed

9 files changed

+1883
-1660
lines changed

tests/ipcMain/helpers.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ export function modelString(provider: string, model: string): string {
4545
return `${provider}:${model}`;
4646
}
4747

48+
/**
49+
* Configure global test retries using Jest
50+
* This helper isolates Jest-specific globals so they don't break other runners (like Bun)
51+
*/
52+
export function configureTestRetries(retries = 3): void {
53+
if (process.env.CI && typeof jest !== "undefined" && jest.retryTimes) {
54+
jest.retryTimes(retries, { logErrorsBeforeRetry: true });
55+
}
56+
}
57+
4858
/**
4959
* Send a message via IPC
5060
*/
@@ -769,37 +779,29 @@ export async function buildLargeHistory(
769779
textPrefix?: string;
770780
} = {}
771781
): Promise<void> {
772-
const { HistoryService } = await import("../../src/node/services/historyService");
782+
const fs = await import("fs/promises");
783+
const path = await import("path");
773784
const { createMuxMessage } = await import("../../src/common/types/message");
774785

775-
// HistoryService only needs getSessionDir, so we can cast the partial config
776-
const historyService = new HistoryService(config as any);
777-
778786
const messageSize = options.messageSize ?? 50_000;
779787
const messageCount = options.messageCount ?? 80;
780788
const textPrefix = options.textPrefix ?? "";
781789

782790
const largeText = textPrefix + "A".repeat(messageSize);
791+
const sessionDir = config.getSessionDir(workspaceId);
792+
const chatPath = path.join(sessionDir, "chat.jsonl");
793+
794+
let content = "";
783795

784796
// Build conversation history with alternating user/assistant messages
785797
for (let i = 0; i < messageCount; i++) {
786798
const isUser = i % 2 === 0;
787799
const role = isUser ? "user" : "assistant";
788800
const message = createMuxMessage(`history-msg-${i}`, role, largeText, {});
789-
790-
const result = await historyService.appendToHistory(workspaceId, message);
791-
if (!result.success) {
792-
throw new Error(`Failed to append message ${i} to history: ${result.error}`);
793-
}
801+
content += JSON.stringify(message) + "\n";
794802
}
795-
}
796803

797-
/**
798-
* Configure test retries for flaky tests in CI
799-
* Only works with Jest
800-
*/
801-
export function configureTestRetries(retries = 3): void {
802-
if (process.env.CI && typeof jest !== "undefined" && jest.retryTimes) {
803-
jest.retryTimes(retries, { logErrorsBeforeRetry: true });
804-
}
804+
// Ensure session directory exists and write file directly for performance
805+
await fs.mkdir(sessionDir, { recursive: true });
806+
await fs.writeFile(chatPath, content, "utf-8");
805807
}

0 commit comments

Comments
 (0)