π OpenHands: AI-Driven Development
test(e2e): add folder browser β workspace β conversation E2E test (#1264)
Rohit Malhotra976413534dc5
diff --git a/.pr/README.md b/.pr/README.mddeleted file mode 100644index cf36399c7b..0000000000--- a/.pr/README.md+++ /dev/null@@ -1,3 +0,0 @@-# PR Artifacts--This directory contains generated PR-only QA artifacts. The PR Artifacts workflow removes it after approval so these files do not enter the final squash merge.diff --git a/.pr/live-e2e/27149471168/live-agent-recording.gif b/.pr/live-e2e/27149471168/live-agent-recording.gifdeleted file mode 100644index b059f27e78..0000000000Binary files a/.pr/live-e2e/27149471168/live-agent-recording.gif and /dev/null differdiff --git a/.pr/live-e2e/27149471168/live-agent-recording.webm b/.pr/live-e2e/27149471168/live-agent-recording.webmdeleted file mode 100644index 69ff026f4c..0000000000Binary files a/.pr/live-e2e/27149471168/live-agent-recording.webm and /dev/null differdiff --git a/.pr/live-e2e/27149471168/live-agent-response.png b/.pr/live-e2e/27149471168/live-agent-response.pngdeleted file mode 100644index bfdfb18d7f..0000000000Binary files a/.pr/live-e2e/27149471168/live-agent-response.png and /dev/null differdiff --git a/playwright.mock-llm-docker.config.ts b/playwright.mock-llm-docker.config.tsindex 8cebe62cff..3ead29ef93 100644--- a/playwright.mock-llm-docker.config.ts+++ b/playwright.mock-llm-docker.config.ts@@ -104,6 +104,17 @@ const USER_SKILLS_CONTAINER_DIR = "/home/openhands/.openhands/skills";mkdirSync(USER_SKILLS_HOST_DIR, { recursive: true });process.env.MOCK_LLM_USER_SKILLS_HOST_DIR = USER_SKILLS_HOST_DIR;+// ββ Folder-workspace test support ββββββββββββββββββββββββββββββββββββββ+// The folder-workspace test creates a temp directory on the host that the+// agent-server's folder browser needs to list. Mount a shared directory into+// the container at the same path so the agent-server can see it.+const FOLDER_WORKSPACE_HOST_DIR = resolve(".tmp/e2e-folder-workspace-test");+const FOLDER_WORKSPACE_CONTAINER_DIR = "/tmp/e2e-folder-workspace-test";+mkdirSync(FOLDER_WORKSPACE_HOST_DIR, { recursive: true });+process.env.MOCK_LLM_FOLDER_WORKSPACE_HOST_DIR = FOLDER_WORKSPACE_HOST_DIR;+process.env.MOCK_LLM_FOLDER_WORKSPACE_CONTAINER_DIR =+ FOLDER_WORKSPACE_CONTAINER_DIR;+// ββ ACP test support ββββββββββββββββββββββββββββββββββββββββββββββββββ// The mock ACP server script lives on the host. We volume-mount it into// the container and tell the test which container-side paths to use when@@ -191,6 +202,9 @@ export default defineConfig({// repos and user skills created by the host-side test code.`-v ${SKILL_REPOS_HOST_DIR}:${SKILL_REPOS_CONTAINER_DIR}`,`-v ${USER_SKILLS_HOST_DIR}:${USER_SKILLS_CONTAINER_DIR}`,+ // Mount the folder-workspace test directory so the agent-server's+ // folder browser can list/navigate it inside the container.+ `-v ${FOLDER_WORKSPACE_HOST_DIR}:${FOLDER_WORKSPACE_CONTAINER_DIR}`,`-e PORT=${INGRESS_PORT}`,`-e SESSION_API_KEY=${sessionApiKey}`,`-e OH_SESSION_API_KEYS_0=${sessionApiKey}`,diff --git a/tests/e2e/mock-llm/mock-llm-folder-workspace.spec.ts b/tests/e2e/mock-llm/mock-llm-folder-workspace.spec.tsnew file mode 100644index 0000000000..b8a594d79d--- /dev/null+++ b/tests/e2e/mock-llm/mock-llm-folder-workspace.spec.ts@@ -0,0 +1,294 @@+/**+ * Mock-LLM E2E test: folder browsing β workspace selection β conversation creation.+ *+ * Covers two "I can" statements from issue #511:+ * - "I can browse local files and folders to choose where to begin"+ * - "I can start a conversation against a local Git repo without typing the path"+ *+ * Flow (serial):+ * 1. Open the folder browser, navigate to a known test directory, click+ * "Use this folder" β verify the workspace appears in the dropdown+ * 2. Select the workspace, type a message, submit β intercept+ * POST /api/conversations and assert workspace.working_dir matches+ * the selected folder path+ * 3. After conversation creation, verify selected_workspace is persisted+ * in localStorage under the conversation's metadata key+ */++import { test, expect } from "@playwright/test";+import {+ seedLocalStorage,+ routeSessionApiKey,+ dismissAnalyticsModal,+ waitForTestId,+ waitForPath,+ ensureMockLLMProfile,+ resetMockLLM,+ deleteConversation,+} from "./utils/mock-llm-helpers";+import * as fs from "fs";+import * as os from "os";+import * as path from "path";++/**+ * The folder-workspace test creates a directory that the agent-server's folder+ * browser must be able to list.+ *+ * **Docker mode**: The Docker config volume-mounts a host dir into the+ * container at /tmp/e2e-folder-workspace-test, and sets two env vars:+ * - MOCK_LLM_FOLDER_WORKSPACE_HOST_DIR β host-side path for fs.mkdirSync+ * - MOCK_LLM_FOLDER_WORKSPACE_CONTAINER_DIR β container-side path the+ * folder browser navigates to+ *+ * **npm mode**: Host IS the agent-server, so both paths resolve identically+ * via os.tmpdir().+ */+const WORKSPACE_DIR_NAME = "e2e-folder-workspace-test";+const HOST_DIR_BASE =+ process.env.MOCK_LLM_FOLDER_WORKSPACE_HOST_DIR ??+ path.join(os.tmpdir(), WORKSPACE_DIR_NAME);+/** Container-side path the agent-server sees (always POSIX). In npm mode+ * this equals HOST_DIR_BASE; in Docker mode it is set by the config. */+const CONTAINER_DIR_BASE =+ process.env.MOCK_LLM_FOLDER_WORKSPACE_CONTAINER_DIR ??+ path.posix.join(os.tmpdir(), WORKSPACE_DIR_NAME);+const TEST_DIR_NAME = "my-test-project";+/** Host-side path where we create the directory via fs.mkdirSync. */+const HOST_DIR = path.join(HOST_DIR_BASE, TEST_DIR_NAME);+/** Container-side path the folder browser UI navigates to (POSIX). */+const TEST_DIR = path.posix.join(CONTAINER_DIR_BASE, TEST_DIR_NAME);++const METADATA_STORAGE_KEY = "openhands-agent-server-conversation-metadata";++test.describe.configure({ mode: "serial" });++test.describe("mock-LLM folder browser β workspace β conversation", () => {+ const conversationIds = new Set<string>();++ test.beforeAll(async ({ browser }) => {+ // Create the test directory hierarchy (host-side path for Docker compat)+ fs.mkdirSync(HOST_DIR, { recursive: true });++ // Ensure the mock LLM profile is configured so conversations can start.+ // beforeAll only has worker-scoped fixtures, so create a temporary page.+ const page = await browser.newPage();+ try {+ await seedLocalStorage(page);+ await ensureMockLLMProfile(page);+ } finally {+ await page.close();+ }+ });++ test.beforeEach(async ({ page }) => {+ await seedLocalStorage(page);+ });++ test.afterEach(async ({ request }) => {+ await resetMockLLM(request);++ // Cleanup conversations created during the test+ for (const id of conversationIds) {+ try {+ await deleteConversation(request, id);+ } catch {+ // best-effort+ }+ }+ conversationIds.clear();+ });++ test.afterAll(async () => {+ // Remove the test directory (host-side path)+ try {+ fs.rmSync(HOST_DIR_BASE, { recursive: true, force: true });+ } catch {+ // best-effort+ }+ });++ // ββ Step 1: Browse to a folder and add it as a workspace ββββββββββββ++ test("step 1: browse to a folder, add it as a workspace, and launch a conversation with the correct working_dir", async ({+ page,+ }) => {+ // Set up passive listener for POST /api/conversations BEFORE navigation.+ // Uses page.on('request') (not page.route) to avoid conflicts with+ // routeSessionApiKey β only one handler can call continue() per request.+ let capturedPayload: Record<string, unknown> | null = null;+ const captureConversationPayload = (+ req: import("@playwright/test").Request,+ ) => {+ if (+ req.method() === "POST" &&+ new URL(req.url()).pathname === "/api/conversations"+ ) {+ try {+ capturedPayload = req.postDataJSON();+ } catch {+ // non-JSON body+ }+ }+ };+ page.on("request", captureConversationPayload);++ await routeSessionApiKey(page);+ await page.goto("/", { waitUntil: "domcontentloaded" });+ await dismissAnalyticsModal(page);+ await waitForTestId(page, "home-chat-launcher");++ // ββ Open the "Open Workspace" dialog ββ+ await test.step("open workspace dialog", async () => {+ await page.getByTestId("open-workspace-button").click();+ await expect(+ page.getByTestId("open-workspace-dialog-body"),+ ).toBeVisible({ timeout: 10_000 });+ });++ // ββ Browse to the test directory using the folder browser UI ββ+ await test.step("open folder browser and navigate to test directory", async () => {+ // The "Add Workspaces" button is inside the dropdown's sticky footer,+ // so we must open the dropdown first.+ await page.getByTestId("workspace-dropdown").click();+ await page.getByTestId("add-workspaces-button").click();+ await expect(page.getByTestId("folder-browser-modal")).toBeVisible({+ timeout: 10_000,+ });++ // Navigate up to root first β click the "up" button repeatedly+ // until we reach "/" (path shows "/" or up button is disabled).+ const upBtn = page.getByTestId("folder-browser-up");+ const currentPathEl = page.getByTestId("folder-browser-current-path");++ // Keep clicking up until the button becomes disabled (at root).+ while (!(await upBtn.isDisabled())) {+ await upBtn.click();+ await page.waitForTimeout(300);+ }+ await expect(currentPathEl).toHaveText("/", { timeout: 5_000 });++ // Navigate down through each segment of the test directory path.+ // e.g. /tmp/e2e-folder-workspace-test/my-test-project β ["tmp", "e2e-...", "my-test-project"]+ const segments = TEST_DIR.split(path.posix.sep).filter(Boolean);+ for (const segment of segments) {+ const entry = page.getByTestId(`folder-browser-entry-${segment}`);+ await expect(entry).toBeVisible({ timeout: 10_000 });+ await entry.click();+ }++ // Verify we're at the correct path+ await expect(currentPathEl).toHaveText(TEST_DIR, { timeout: 5_000 });++ // Click "Use this folder"+ await page.getByTestId("folder-browser-use").click();++ // Modal should close+ await expect(page.getByTestId("folder-browser-modal")).toBeHidden({+ timeout: 5_000,+ });+ });++ // ββ Select the workspace in the dropdown and confirm ββ+ // The workspace dialog is still open after the folder browser closed.+ // The folder browser's onAdd adds the workspace to the store, so the+ // dropdown should now include it.+ await test.step("select the workspace in the dropdown and confirm", async () => {+ // The workspace dialog should still be visible+ await expect(+ page.getByTestId("open-workspace-dialog-body"),+ ).toBeVisible({ timeout: 10_000 });++ // The workspace dropdown should contain our test directory.+ const dropdown = page.getByTestId("workspace-dropdown");+ await expect(dropdown).toBeVisible({ timeout: 10_000 });+ await dropdown.click();++ // Find and click the entry for our test workspace+ const workspaceOption = page.getByRole("option", {+ name: new RegExp(TEST_DIR_NAME),+ });+ await expect(workspaceOption).toBeVisible({ timeout: 10_000 });+ await workspaceOption.click();++ // Click "Confirm" to accept the workspace selection+ const confirmBtn = page.getByRole("button", { name: /confirm/i });+ await confirmBtn.click();++ // The dialog should close+ await expect(+ page.getByTestId("open-workspace-dialog-body"),+ ).toBeHidden({ timeout: 5_000 });+ });++ // ββ Type a message and submit to create a conversation ββ+ await test.step("submit a message to create a conversation", async () => {+ // Type into the home-page chat input (contentEditable div)+ const chatInput = page.getByTestId("home-chat-launcher").locator(+ '[contenteditable="true"]',+ );+ await expect(chatInput).toBeVisible({ timeout: 10_000 });+ await chatInput.click();++ await page.evaluate((msg: string) => {+ const el = document.querySelector(+ '[data-testid="home-chat-launcher"] [contenteditable="true"]',+ );+ if (el) {+ el.textContent = msg;+ el.dispatchEvent(new Event("input", { bubbles: true }));+ }+ }, "Hello from the workspace test");++ // Submit with Enter+ await chatInput.press("Enter");++ // Wait for navigation to a conversation page+ await waitForPath(page, /\/conversations\/.+/, 30_000);+ });++ // Track the conversation for cleanup+ const match = page.url().match(/\/conversations\/([^/?#]+)/);+ const conversationId = match?.[1] ? decodeURIComponent(match[1]) : null;+ expect(conversationId, "Should be on a conversation page").toBeTruthy();+ conversationIds.add(conversationId!);++ // ββ Verify: POST /api/conversations payload has correct working_dir ββ+ await test.step("verify working_dir in POST /api/conversations payload", async () => {+ expect(+ capturedPayload,+ "POST /api/conversations payload was not captured",+ ).not.toBeNull();++ const workspace = capturedPayload?.workspace as+ | Record<string, unknown>+ | undefined;+ expect(workspace, "payload should have a workspace object").toBeTruthy();+ expect(workspace?.working_dir).toBe(TEST_DIR);+ });++ // ββ Verify: selected_workspace in localStorage ββ+ await test.step("verify selected_workspace in localStorage", async () => {+ const metadata = await page.evaluate(+ ({ key, convId }) => {+ const raw = window.localStorage.getItem(key);+ if (!raw) return null;+ try {+ const parsed = JSON.parse(raw);+ return parsed[convId] ?? null;+ } catch {+ return null;+ }+ },+ { key: METADATA_STORAGE_KEY, convId: conversationId! },+ );++ expect(+ metadata,+ `localStorage metadata for conversation ${conversationId} should exist`,+ ).not.toBeNull();+ expect(metadata?.selected_workspace).toBe(TEST_DIR);+ });++ page.off("request", captureConversationPayload);+ });+});