π OpenHands: AI-Driven Development
fix(tests): fix two flaky CI tests on Windows (#667)
Rohit Malhotraad5c5533a994
diff --git a/__tests__/components/features/conversation-panel/conversation-panel.test.tsx b/__tests__/components/features/conversation-panel/conversation-panel.test.tsxindex 7664aadd47..e8bb236b9b 100644--- a/__tests__/components/features/conversation-panel/conversation-panel.test.tsx+++ b/__tests__/components/features/conversation-panel/conversation-panel.test.tsx@@ -33,29 +33,37 @@ vi.mock("#/hooks/mutation/use-unified-stop-conversation", () => ({// Helper to create complete AppConversation mock data// Default timestamps use "now" so conversations are considered recent and-// rendered eagerly by the panel.+// rendered eagerly by the panel. Each call produces a timestamp 1 s older+// than the previous one so that the sort-by-updated_at order matches the+// array insertion order (first created β newest β cards[0]).+let _mockConversationCounter = 0;const createMockConversation = (overrides: Partial<AppConversation> = {},-): AppConversation => ({- id: "test-id",- title: "Test Conversation",- selected_repository: null,- git_provider: null,- selected_branch: null,- updated_at: new Date().toISOString(),- created_at: new Date().toISOString(),- execution_status: ExecutionStatus.FINISHED,- conversation_url: null,- created_by_user_id: "user1",- metrics: null,- llm_model: null,- trigger: null,- pr_number: [],- session_api_key: null,- sandbox_id: null,- sub_conversation_ids: [],- ...overrides,-});+): AppConversation => {+ const ts = new Date(+ Date.now() - _mockConversationCounter++ * 1000,+ ).toISOString();+ return {+ id: "test-id",+ title: "Test Conversation",+ selected_repository: null,+ git_provider: null,+ selected_branch: null,+ updated_at: ts,+ created_at: ts,+ execution_status: ExecutionStatus.FINISHED,+ conversation_url: null,+ created_by_user_id: "user1",+ metrics: null,+ llm_model: null,+ trigger: null,+ pr_number: [],+ session_api_key: null,+ sandbox_id: null,+ sub_conversation_ids: [],+ ...overrides,+ };+};// Mock toast handlers to prevent unhandled rejection errorsvi.mock("#/utils/custom-toast-handlers", () => ({diff --git a/__tests__/scripts/dev-with-automation.test.ts b/__tests__/scripts/dev-with-automation.test.tsindex 3f396aa3e9..4cbc3853c1 100644--- a/__tests__/scripts/dev-with-automation.test.ts+++ b/__tests__/scripts/dev-with-automation.test.ts@@ -466,10 +466,15 @@ describe("dev-with-automation CLI", () => {// runners that don't have uv installed. The prerequisite check must// succeed so the LOCAL_PATH validation guard (the actual subject of this// test, which runs immediately after) is exercised.+ const isWindows = process.platform === "win32";const stubBinDir = mkdtempSync(path.join(tmpdir(), "stub-bin-"));- writeFileSync(path.join(stubBinDir, "uvx"), "#!/bin/sh\nexit 0\n", {- mode: 0o755,- });+ if (isWindows) {+ writeFileSync(path.join(stubBinDir, "uvx.cmd"), "@exit /b 0\r\n");+ } else {+ writeFileSync(path.join(stubBinDir, "uvx"), "#!/bin/sh\nexit 0\n", {+ mode: 0o755,+ });+ }// Act: spawn `dev-with-automation.mjs` with that path set. Stubbed `uvx`// is prepended to PATH so the prerequisite check passes; the validation@@ -478,9 +483,17 @@ describe("dev-with-automation CLI", () => {const child = spawn(process.execPath, ["scripts/dev-with-automation.mjs"], {cwd: repoRoot,env: {- PATH: `${stubBinDir}:${process.env.PATH ?? ""}`,+ PATH: `${stubBinDir}${path.delimiter}${process.env.PATH ?? ""}`,HOME: process.env.HOME ?? "",OH_AGENT_SERVER_LOCAL_PATH: emptyDir,+ // Windows needs these for `where.exe` to resolve the stub and npm+ ...(isWindows+ ? {+ PATHEXT: process.env.PATHEXT ?? ".CMD;.EXE;.BAT;.COM",+ SystemRoot: process.env.SystemRoot ?? "",+ USERPROFILE: process.env.USERPROFILE ?? "",+ }+ : {}),},stdio: ["ignore", "pipe", "pipe"],});