π OpenHands: AI-Driven Development
Add Docker projects workspace shortcut (#397)
Xingyao Wangb06ac9114b4e
diff --git a/__tests__/components/features/home/workspace-selection-form.test.tsx b/__tests__/components/features/home/workspace-selection-form.test.tsxindex a68227d468..8376768768 100644--- a/__tests__/components/features/home/workspace-selection-form.test.tsx+++ b/__tests__/components/features/home/workspace-selection-form.test.tsx@@ -116,7 +116,6 @@ describe("WorkspaceSelectionForm", () => {});it("Add Workspace adds only the chosen folder (not its subfolders) and dedupes on repeat", async () => {-mockGetHome.mockResolvedValue({ home: "/Users/me" });const searchSpy = mockSearchSubdirectories;@@ -140,7 +139,6 @@ describe("WorkspaceSelectionForm", () => {throw new Error(`unexpected path ${path}`);});-// Pre-seed one workspace to verify deduprenderForm([{ id: "/Users/me/dev", name: "dev", path: "/Users/me/dev" }]);const user = userEvent.setup();@@ -255,8 +253,8 @@ describe("WorkspaceSelectionForm", () => {if (path === "/projects") {return {items: [- { name: "agent-canvas", path: "/projects/agent-canvas" },- { name: "sdk", path: "/projects/sdk" },+ { name: "demo-app", path: "/projects/demo-app" },+ { name: "sample-tools", path: "/projects/sample-tools" },],next_page_id: null,};@@ -269,12 +267,73 @@ describe("WorkspaceSelectionForm", () => {await user.click(screen.getByTestId("workspace-dropdown"));const dropdownMenu = await screen.findByTestId("workspace-dropdown-menu");- await within(dropdownMenu).findByText("agent-canvas");- await within(dropdownMenu).findByText("sdk");+ await within(dropdownMenu).findByText("demo-app");+ await within(dropdownMenu).findByText("sample-tools");expect(searchSpy).toHaveBeenCalledWith("/projects");});+ it("Add Workspace starts at the docker /projects mount and can save nested folders", async () => {+ mockGetHome.mockResolvedValue({+ home: "/home/openhands",+ favorites: [{ label: "Downloads", path: "/home/openhands/Downloads" }],+ locations: [],+ });+ mockSearchSubdirectories.mockImplementation(async (path: string) => {+ if (path === "/projects") {+ return {+ items: [{ name: "demo-app", path: "/projects/demo-app" }],+ next_page_id: null,+ };+ }+ if (path === "/projects/demo-app") {+ return {+ items: [+ {+ name: "web-client",+ path: "/projects/demo-app/web-client",+ },+ ],+ next_page_id: null,+ };+ }+ if (path === "/projects/demo-app/web-client") {+ return { items: [], next_page_id: null };+ }+ return { items: [], next_page_id: null };+ });++ renderForm();+ const user = userEvent.setup();++ await user.click(screen.getByTestId("workspace-dropdown"));+ await user.click(await screen.findByTestId("add-workspaces-button"));++ await screen.findByTestId("folder-browser-modal");+ expect(+ await screen.findByTestId("folder-browser-current-path"),+ ).toHaveTextContent("/projects");+ expect(+ await screen.findByTestId("folder-browser-sidebar-/projects"),+ ).toBeInTheDocument();+ await user.click(+ await screen.findByTestId("folder-browser-entry-demo-app"),+ );+ await user.click(+ await screen.findByTestId("folder-browser-entry-web-client"),+ );+ await user.click(screen.getByTestId("folder-browser-use"));++ await waitFor(() =>+ expect(+ screen.queryByTestId("folder-browser-modal"),+ ).not.toBeInTheDocument(),+ );+ expect(useWorkspacesStore.getState().workspaces.map((w) => w.path)).toEqual(+ ["/projects/demo-app/web-client"],+ );+ });+it("A stored /projects parent suppresses the implicit duplicate query", async () => {const searchSpy = mockSearchSubdirectories.mockResolvedValue({items: [],@@ -352,7 +411,6 @@ describe("WorkspaceSelectionForm", () => {});it("Add all subdirectories saves a workspace parent and lists its children dynamically", async () => {-mockGetHome.mockResolvedValue({ home: "/Users/me" });const searchSpy = mockSearchSubdirectories;@@ -375,7 +433,6 @@ describe("WorkspaceSelectionForm", () => {throw new Error(`unexpected path ${path}`);});-renderForm();const user = userEvent.setup();diff --git a/src/components/features/home/workspace-dropdown/folder-browser-modal.tsx b/src/components/features/home/workspace-dropdown/folder-browser-modal.tsxindex b3e317ad12..26ea0aa3fe 100644--- a/src/components/features/home/workspace-dropdown/folder-browser-modal.tsx+++ b/src/components/features/home/workspace-dropdown/folder-browser-modal.tsx@@ -6,6 +6,7 @@ import { BrandButton } from "#/components/features/settings/brand-button";import { I18nKey } from "#/i18n/declaration";import { LocalWorkspace, LocalWorkspaceParent } from "#/types/workspace";import {+ type HomeDirectoryResponse,useHomeDirectory,useSearchSubdirs,} from "#/hooks/query/use-search-subdirs";@@ -14,6 +15,8 @@ import { cn } from "#/utils/utils";import FolderIcon from "#/icons/folder.svg?react";import ChevronLeft from "#/icons/chevron-left-small.svg?react";+const DOCKER_PROJECTS_PATH = "/projects";+interface FolderBrowserModalProps {isOpen: boolean;onClose: () => void;@@ -80,6 +83,12 @@ function getParentPath(path: string): string | null {return trimmed.slice(0, idx);}+function shouldDefaultToDockerProjects(+ homeData: HomeDirectoryResponse | undefined,+): boolean {+ return homeData?.home === "/home/openhands";+}+export function FolderBrowserModal({isOpen,onClose,@@ -95,7 +104,11 @@ export function FolderBrowserModal({// Initialize / reset to home each time the modal is openeduseEffect(() => {if (isOpen && homeData?.home && currentPath === null) {- setCurrentPath(homeData.home);+ setCurrentPath(+ shouldDefaultToDockerProjects(homeData)+ ? DOCKER_PROJECTS_PATH+ : homeData.home,+ );}if (!isOpen) {setCurrentPath(null);@@ -118,7 +131,21 @@ export function FolderBrowserModal({const favorites: SidebarEntry[] = useMemo(() => {if (!homeData?.home) return [];const trimmed = homeData.home.replace(/[\\/]+$/, "") || homeData.home;- return [{ label: "Home", path: trimmed }, ...(homeData.favorites ?? [])];+ const backendFavorites = [+ { label: "Home", path: trimmed },+ ...(homeData.favorites ?? []),+ ];+ if (+ shouldDefaultToDockerProjects(homeData) &&+ !backendFavorites.some((entry) => entry.path === DOCKER_PROJECTS_PATH)+ ) {+ backendFavorites.push({+ label: DOCKER_PROJECTS_PATH,+ path: DOCKER_PROJECTS_PATH,+ });+ }++ return backendFavorites;}, [homeData]);const locations: SidebarEntry[] = homeData?.locations ?? [];@@ -133,8 +160,7 @@ export function FolderBrowserModal({// returns no favorites (the only contents are hidden credential dirs).// In that case there's nothing useful for the user to browse, so we// surface the OH_MOUNT_HOST_HOME=1 opt-in instead of the generic empty- // state. Off in production / non-Docker dev because favorites are- // populated there.+ // state when the user navigates back to the container home.const showHostHomeHint =homeData?.home === "/home/openhands" &&(homeData?.favorites?.length ?? 0) === 0 &&diff --git a/src/mocks/file-service-handlers.ts b/src/mocks/file-service-handlers.tsindex f3ef3fdc4c..2b16d62050 100644--- a/src/mocks/file-service-handlers.ts+++ b/src/mocks/file-service-handlers.ts@@ -7,6 +7,37 @@ export const FILE_VARIANTS_2 = ["terminator_blueprint.txt",];+const MOCK_FILE_BROWSER_HOME = {+ home: "/home/openhands",+ favorites: [{ label: "Downloads", path: "/home/openhands/Downloads" }],+ locations: [],+};++const MOCK_SUBDIRECTORIES_BY_PATH: Record<+ string,+ { name: string; path: string }[]+> = {+ "/projects": [+ { name: "demo-app", path: "/projects/demo-app" },+ { name: "sample-tools", path: "/projects/sample-tools" },+ { name: "notes-service", path: "/projects/notes-service" },+ ],+ "/projects/demo-app": [+ {+ name: "web-client",+ path: "/projects/demo-app/web-client",+ },+ {+ name: "api-service",+ path: "/projects/demo-app/api-service",+ },+ ],+ "/projects/demo-app/web-client": [],+};++const shouldReturnDockerProjectMock =+ typeof import.meta.env.MODE === "string" && import.meta.env.MODE !== "test";+export const FILE_SERVICE_HANDLERS = [http.all("*/api/bash/execute_bash_command", async () =>HttpResponse.json({@@ -16,10 +47,25 @@ export const FILE_SERVICE_HANDLERS = [}),),- http.get("*/api/file/search_subdirs", async () =>- HttpResponse.json({ path: "/projects", subdirs: [] }),+ http.get("*/api/file/home", async () =>+ HttpResponse.json(MOCK_FILE_BROWSER_HOME),),+ http.get("*/api/file/search_subdirs", async ({ request }) => {+ const url = new URL(request.url);+ const path = url.searchParams.get("path") ?? "";+ const items = shouldReturnDockerProjectMock+ ? (MOCK_SUBDIRECTORIES_BY_PATH[path] ?? [])+ : [];++ return HttpResponse.json({+ path,+ items,+ subdirs: items,+ next_page_id: null,+ });+ }),+http.get("*/api/file/:path", async ({ params }) =>HttpResponse.json({path: `/${params.path?.toString() ?? "home"}`,diff --git a/tests/e2e/__snapshots__/snapshots/docker-workspace-browser.snapshot.spec.ts/chromium/docker-projects-workspace-browser.png b/tests/e2e/__snapshots__/snapshots/docker-workspace-browser.snapshot.spec.ts/chromium/docker-projects-workspace-browser.pngnew file mode 100644index 0000000000..9d5fb7930eBinary files /dev/null and b/tests/e2e/__snapshots__/snapshots/docker-workspace-browser.snapshot.spec.ts/chromium/docker-projects-workspace-browser.png differdiff --git a/tests/e2e/snapshots/COVERAGE_PLAN.md b/tests/e2e/snapshots/COVERAGE_PLAN.mdindex f84db6547a..851b8ddb49 100644--- a/tests/e2e/snapshots/COVERAGE_PLAN.md+++ b/tests/e2e/snapshots/COVERAGE_PLAN.md@@ -13,7 +13,7 @@ Existing coverage is marked **β done**. Everything else is proposed.## 1. Home Screen-**File:** `home-screen.snapshot.spec.ts`+**File:** `home-screen.snapshot.spec.ts`**Existing:** β `home-screen.png` in `settings-page.snapshot.spec.ts`| Snapshot name | State to capture |@@ -51,7 +51,7 @@ the "Next" / "Back" buttons between snapshots.## 3. Settings Pages-**File:** `settings.snapshot.spec.ts`+**File:** `settings.snapshot.spec.ts`**Existing:** β `settings-page.png`, `settings-app-page.png` in `settings-page.snapshot.spec.ts`### LLM Settings@@ -170,7 +170,7 @@ the "Next" / "Back" buttons between snapshots.## 8. Analytics Consent Modal-**File:** `settings-page.snapshot.spec.ts` (already exists)+**File:** `settings-page.snapshot.spec.ts` (already exists)**Existing:** β `analytics-consent-modal.png`No new snapshots needed; keep existing baseline.@@ -217,7 +217,7 @@ All tests use `navigateToConversation` + `injectEvents` via## 11. Conversation Page β Collapsible Thinking-**File:** `collapsible-thinking.snapshot.spec.ts` (already exists)+**File:** `collapsible-thinking.snapshot.spec.ts` (already exists)**Existing:** β `think-action-collapsed.png`, `think-action-expanded.png`, `reasoning-content-collapsed.png`, `reasoning-content-expanded.png`No new snapshots needed; keep existing baselines.diff --git a/tests/e2e/snapshots/docker-workspace-browser.snapshot.spec.ts b/tests/e2e/snapshots/docker-workspace-browser.snapshot.spec.tsnew file mode 100644index 0000000000..0e5fd6c2b7--- /dev/null+++ b/tests/e2e/snapshots/docker-workspace-browser.snapshot.spec.ts@@ -0,0 +1,49 @@+import { expect, test } from "@playwright/test";++test("captures Docker /projects workspace browser state", async ({ page }) => {+ test.setTimeout(60_000);++ await page.addInitScript(() => {+ window.localStorage.setItem("analytics-consent", "true");+ window.localStorage.setItem("openhands-telemetry-consent", "denied");+ window.localStorage.setItem("openhands-telemetry-first-use", "true");+ window.localStorage.setItem("openhands-onboarded", "1");+ });++ await page.goto("/conversations", { waitUntil: "domcontentloaded" });++ const consentDialog = page.getByRole("dialog", {+ name: "Help improve OpenHands",+ });+ await page+ .getByRole("button", { name: "Confirm preferences" })+ .click({ timeout: 5000 })+ .catch(() => undefined);+ await expect(consentDialog).toHaveCount(0, { timeout: 5000 });++ const workspaceDropdown = page.getByTestId("workspace-dropdown");+ await expect(workspaceDropdown).toBeEnabled({ timeout: 15_000 });+ await workspaceDropdown.click();+ await page.getByTestId("add-workspaces-button").click();++ const modal = page.getByTestId("folder-browser-modal");+ await expect(modal).toBeVisible();+ await expect(page.getByTestId("folder-browser-current-path")).toHaveText(+ "/projects",+ );+ await expect(+ page.getByTestId("folder-browser-sidebar-/projects"),+ ).toBeVisible();+ await expect(page.getByTestId("folder-browser-entry-demo-app")).toBeVisible();++ await page.mouse.move(5, 5);+ await expect(modal).toHaveScreenshot("docker-projects-workspace-browser.png");++ await page.getByTestId("folder-browser-entry-demo-app").click();+ await expect(page.getByTestId("folder-browser-current-path")).toHaveText(+ "/projects/demo-app",+ );+ await expect(+ page.getByTestId("folder-browser-entry-web-client"),+ ).toBeVisible();+});