π OpenHands: AI-Driven Development
Consolidate e2e regression tests into mock-LLM framework (#1155)
Rohit Malhotrad0853b6055cd
diff --git a/AGENTS.md b/AGENTS.mdindex de861510b1..07f619f7ee 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -194,6 +194,7 @@ you are running inside of β NOT the automation backend.- `mock-llm-image-upload.spec.ts` β Attaches a 1Γ1 PNG via the hidden file input, sends "What is in this image?", verifies the agent replies, that the user message event stores image_urls, and that the mock LLM received an image_url content block with a base64 data: URL in at least one completion call.- `mock-llm-automation.spec.ts` β Full automation lifecycle: registers a trajectory (7 responses total β 4 for the main conversation + 3 for the automation run's spawned conversation) where the LLM creates a cron automation and dispatches a run via terminal `curl` commands to the real automation backend. Verifies: automation created with correct schedule, run reaches COMPLETED status with a conversation_id, automation appears on the `/automations` list page, detail page shows COMPLETED badge (`data-testid="run-status-icon-completed"`), and clicking the run's conversation link navigates to the correct `/conversations/{id}` page.- `mock-llm-partial-stack.spec.ts` β Partial stack mode tests. Unlike other specs, these spawn their own `bin/agent-canvas.mjs` child processes instead of relying on the config's webServer entries. Three describe blocks: (1) `--frontend-only` verifies static frontend is served (200 on `/`), backend routes return 503 (`/server_info`, `/api/settings`, `/api/automation/v1`), and the browser shows the manage-backends modal; (2) `--backend-only` verifies `/server_info` returns 200, `/api/settings` is reachable, automation endpoint works, and root/asset requests return 503; (3) port conflict verifies the process exits non-zero with a clear error message when the ingress port is occupied, then starts successfully on a free port. Each test uses isolated state dirs and high port numbers (18310+ range) to avoid collisions with the main full-stack instance.+ - `mock-llm-ui-regressions.spec.ts` β UI regression tests (CSS isolation scoping, event pagination on scroll-up, workspace selection persistence). Uses `page.route()` to intercept specific API responses where deterministic mock data is needed. Consolidated from the former `tests/e2e/regressions/` directory (which was never wired into CI).- Tests run serially (`workers: 1`, `mode: "serial"` per describe block). Files are discovered alphabetically so the ACP agent test runs first, followed by auth-modes, automation, conversation, etc.; each spec is self-contained (automation test configures its own LLM profile via the settings API, ACP test resets back to OpenHands agent in afterAll). The `afterEach` hook resets the mock LLM to its default trajectory so subsequent specs start fresh even when a preceding test fails.- CI workflow: `.github/workflows/mock-llm-e2e.yml` runs on PRs with the `e2e-tests` label or on manual dispatch. It builds the frontend, starts the mock LLM server, runs the tests, and posts a PR comment with results.- The custom `DoneMarkerReporter` writes `.mock-llm-markers/.tests-done` after all tests complete (before webServer teardown) so the CI wrapper can detect completion and kill the lingering teardown process.@@ -559,7 +560,7 @@ When adding code that needs a new string, decide up front which rule it falls un- Public embedding entry points should use `AgentServerUIProviders` (scoped root on by default) or `AgentServerUIRoot` for manual control. The standalone app already renders its own scoped root in `src/root.tsx`, so `src/entry.client.tsx` must pass `withStyleRoot={false}` to avoid nesting duplicate shells. Keep `AgentServerUIRoot` and the scoping constants re-exported from `src/lib/index.ts` so library consumers can customize the host wrapper without reaching into private paths.- `AgentServerUIRoot`'s themed inner wrapper must set a default `color: var(--foreground)` in addition to the `dark` / `data-theme` markers; otherwise inherited text and `currentColor` SVG icons fall back to dark browser defaults after CSS scoping, causing dark-on-dark regressions on pages like the home screen.- Theme/customization tokens for the embedded shell are exposed as `--oh-*` CSS variables. Override them through `styleOverrides`, `style`, or host CSS targeting `[data-agent-server-ui]`; Tailwind theme tokens in `src/tailwind.css` should continue to reference those variables with `@theme inline` so host apps can restyle the UI without reworking component class names.-- Regression coverage for the CSS isolation work lives in `__tests__/agent-server-ui-providers.test.tsx`, `__tests__/agent-server-ui-style-scope.test.ts`, and the browser-level `tests/e2e/regressions/css-isolation.spec.ts` Playwright test.+- Regression coverage for the CSS isolation work lives in `__tests__/agent-server-ui-providers.test.tsx`, `__tests__/agent-server-ui-style-scope.test.ts`, and the browser-level CSS-isolation test in `tests/e2e/mock-llm/mock-llm-ui-regressions.spec.ts`.- Conversation history is loaded lazily, REST-first then WebSocket:- `useConversationHistory` (in `src/hooks/query/use-conversation-history.ts`) fetches only the most recent `INITIAL_HISTORY_PAGE_SIZE` (default 50) events using `sort_order='TIMESTAMP_DESC'`, then reverses to chronological order. Older pages are paginated in via `useLoadOlderEvents` when the user scrolls near the top of the chat.diff --git a/tests/e2e/mock-llm/mock-llm-ui-regressions.spec.ts b/tests/e2e/mock-llm/mock-llm-ui-regressions.spec.tsnew file mode 100644index 0000000000..759c4fa3c9--- /dev/null+++ b/tests/e2e/mock-llm/mock-llm-ui-regressions.spec.ts@@ -0,0 +1,444 @@+/**+ * Mock-LLM E2E: UI regression tests.+ *+ * Ported from the former `tests/e2e/regressions/` directory so they run+ * against the real agent-server stack (via `bin/agent-canvas.mjs`) instead+ * of the MSW-only dev-mock server that was never wired into CI.+ *+ * Tests use `page.route()` where specific API responses need to be+ * controlled, following the same pattern as+ * `mock-llm-onboarding-regressions.spec.ts`.+ */++import test, { expect, type Page, type Request } from "@playwright/test";+import {+ seedLocalStorage,+ routeSessionApiKey,+} from "./utils/mock-llm-helpers";++test.describe.configure({ mode: "serial" });++// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+// Helpers+// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ++// βββ pagination helpers ββββββββββββββββββββββββββββββββββββββββββββββ++const PAGINATION_CONVERSATION_ID = "pagination-e2e";+const PAGE_SIZE = 50;+const PAGINATION_EVENT_COUNT = 100;+const PAGINATION_BASE_TIME = Date.UTC(2026, 4, 13, 0, 0, 0);++function timestampForEvent(index: number): string {+ return new Date(PAGINATION_BASE_TIME + index * 60_000).toISOString();+}++interface PaginationEvent {+ id: string;+ timestamp: string;+ source: string;+ kind: string;+ llm_message: {+ role: string;+ content: Array<{ type: string; text: string }>;+ };+}++function createPaginationEvent(+ index: number,+ prefix: string,+): PaginationEvent {+ return {+ id: `${prefix.toLowerCase().replaceAll(" ", "-")}-${index}`,+ timestamp: timestampForEvent(index),+ source: "agent",+ kind: "MessageEvent",+ llm_message: {+ role: "assistant",+ content: [{ type: "text", text: `${prefix} ${index}` }],+ },+ };+}++function createAllPaginationEvents(prefix: string): PaginationEvent[] {+ return Array.from({ length: PAGINATION_EVENT_COUNT }, (_, i) =>+ createPaginationEvent(i + 1, prefix),+ );+}++function searchPaginationEvents(+ events: PaginationEvent[],+ searchParams: URLSearchParams,+) {+ const limit = Number(searchParams.get("limit") ?? "100");+ const timestampLt = searchParams.get("timestamp__lt");+ const sortOrder = searchParams.get("sort_order");+ const filtered = timestampLt+ ? events.filter((e) => e.timestamp < timestampLt)+ : events;+ const sorted = [...filtered].sort((a, b) =>+ sortOrder === "TIMESTAMP_DESC"+ ? b.timestamp.localeCompare(a.timestamp)+ : a.timestamp.localeCompare(b.timestamp),+ );+ return {+ items: sorted.slice(0, limit),+ next_page_id: sorted.length > limit ? "next-page" : null,+ };+}++/** Build the mock conversation with the same fields the real agent-server+ * returns so `requireDirectConversationInfo` can parse it and the+ * conversation route doesn't redirect to `/conversations`. */+function buildMockConversation() {+ return {+ id: PAGINATION_CONVERSATION_ID,+ conversation_id: PAGINATION_CONVERSATION_ID,+ status: "STOPPED",+ execution_status: "stopped",+ created_at: timestampForEvent(1),+ updated_at: timestampForEvent(PAGINATION_EVENT_COUNT),+ title: "Pagination test",+ };+}++/** Intercept conversation lookup + event search for pagination tests. */+async function routePaginationConversation(page: Page) {+ const allEvents = createAllPaginationEvents("Pagination message");++ // The app fetches conversations via the batch endpoint:+ // GET /api/conversations?ids=<id>+ // Use a regex to match the query-param form of the URL. The glob `?`+ // character is a single-char wildcard in Playwright, so a regex is+ // more reliable for matching literal query strings.+ await page.route(+ /\/api\/conversations\?/,+ async (route, req) => {+ if (req.method() !== "GET") {+ await route.fallback();+ return;+ }+ const url = new URL(req.url());+ // Axios serializes array params as `ids[]=a&ids[]=b` (bracket notation).+ const ids = [+ ...url.searchParams.getAll("ids"),+ ...url.searchParams.getAll("ids[]"),+ ];+ if (ids.includes(PAGINATION_CONVERSATION_ID)) {+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify([buildMockConversation()]),+ });+ } else {+ await route.fallback();+ }+ },+ );++ // Stub the event search endpoint with the synthetic paginated events.+ await page.route(+ `**/api/conversations/${PAGINATION_CONVERSATION_ID}/events/search**`,+ async (route, req) => {+ if (req.method() !== "GET") {+ await route.fallback();+ return;+ }+ const url = new URL(req.url());+ const result = searchPaginationEvents(allEvents, url.searchParams);+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify(result),+ });+ },+ );+}++async function getChatScroller(page: Page) {+ const chatInterface = page.getByTestId("chat-interface");+ await expect(chatInterface).toBeVisible({ timeout: 15_000 });+ const scroller = chatInterface.locator(".custom-scrollbar-always").first();+ await expect(scroller).toBeVisible();+ return scroller;+}++async function waitForScrollableConversation(page: Page) {+ const scroller = await getChatScroller(page);+ await expect+ .poll(+ () =>+ scroller.evaluate((el) => el.scrollHeight > el.clientHeight),+ { timeout: 15_000 },+ )+ .toBe(true);+ return scroller;+}++async function triggerOlderEventLoad(page: Page) {+ const scroller = await waitForScrollableConversation(page);+ await scroller.evaluate((el) => {+ el.scrollTop = 0;+ el.dispatchEvent(new Event("scroll", { bubbles: true }));+ });+}++// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+// Tests+// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ++test.describe("UI regressions", () => {+ test.beforeEach(async ({ page }) => {+ await seedLocalStorage(page);+ });++ // ββ CSS isolation ββββββββββββββββββββββββββββββββββββββββββββββββ++ test("scopes standalone styles to the agent-server-ui shell", async ({+ page,+ }) => {+ await routeSessionApiKey(page);+ await page.goto("/", { waitUntil: "domcontentloaded" });++ await expect(+ page.locator("[data-agent-server-ui]").first(),+ ).toBeVisible({ timeout: 15_000 });+ const layout = page.getByTestId("root-layout");+ await expect(layout).toBeVisible();++ const insideBackground = await layout.evaluate(+ (el) => getComputedStyle(el).backgroundColor,+ );++ const outsideStyles = await page.evaluate(() => {+ const probe = document.createElement("div");+ probe.className = "bg-base text-content-2";+ probe.textContent = "host";+ document.documentElement.appendChild(probe);+ const styles = getComputedStyle(probe);+ return {+ backgroundColor: styles.backgroundColor,+ color: styles.color,+ };+ });++ expect(insideBackground).not.toBe("rgba(0, 0, 0, 0)");+ expect(outsideStyles.backgroundColor).not.toBe(insideBackground);+ });++ // ββ event pagination on scroll-up ββββββββββββββββββββββββββββββββ++ test("loads older events when scrolling up", async ({ page }) => {+ test.setTimeout(60_000);+ await routeSessionApiKey(page);+ await routePaginationConversation(page);++ const initialRequestPromise = page.waitForRequest((req: Request) => {+ if (req.method() !== "GET") return false;+ if (+ !req+ .url()+ .includes(+ `/api/conversations/${PAGINATION_CONVERSATION_ID}/events/search`,+ )+ )+ return false;+ return !new URL(req.url()).searchParams.has("timestamp__lt");+ });++ await page.goto(`/conversations/${PAGINATION_CONVERSATION_ID}`, {+ waitUntil: "domcontentloaded",+ });++ // Verify initial request sends correct params.+ const initialRequest = await initialRequestPromise;+ const initialUrl = new URL(initialRequest.url());+ expect(initialUrl.searchParams.get("limit")).toBe(String(PAGE_SIZE));+ expect(initialUrl.searchParams.get("sort_order")).toBe("TIMESTAMP_DESC");++ // Most recent message should be visible; older page should not.+ await expect(+ page.getByText("Pagination message 100", { exact: true }),+ ).toBeVisible({ timeout: 15_000 });+ await expect(+ page.getByText("Pagination message 50", { exact: true }),+ ).toHaveCount(0);++ // Scroll to top to trigger older-event loading.+ const olderRequestPromise = page.waitForRequest((req: Request) => {+ if (req.method() !== "GET") return false;+ if (+ !req+ .url()+ .includes(+ `/api/conversations/${PAGINATION_CONVERSATION_ID}/events/search`,+ )+ )+ return false;+ return new URL(req.url()).searchParams.has("timestamp__lt");+ });++ await triggerOlderEventLoad(page);++ await expect(page.getByTestId("loading-older-events")).toContainText(+ "Fetching older messages",+ );++ const olderRequest = await olderRequestPromise;+ const olderUrl = new URL(olderRequest.url());+ expect(olderUrl.searchParams.get("limit")).toBe(String(PAGE_SIZE));+ expect(olderUrl.searchParams.get("sort_order")).toBe("TIMESTAMP_DESC");+ expect(olderUrl.searchParams.get("timestamp__lt")).toBe(+ timestampForEvent(51),+ );++ await expect(+ page.getByText("Pagination message 50", { exact: true }),+ ).toBeAttached({ timeout: 15_000 });+ await expect(page.getByTestId("loading-older-events")).toHaveCount(0);+ });++ // ββ #1076: workspace selection persistence βββββββββββββββββββββββ++ test("selected workspace persists after navigating away and returning", async ({+ page,+ }) => {+ test.setTimeout(60_000);+ await routeSessionApiKey(page);++ // Stub the workspace listing endpoint (GET /api/workspaces) to return+ // deterministic entries in the server-persisted shape:+ // { workspaces: [...], workspaceParents: [...] }+ const workspacesMock = {+ workspaces: [+ {+ id: "/workspace/project/demo-app",+ name: "demo-app",+ path: "/workspace/project/demo-app",+ },+ {+ id: "/workspace/project/sample-tools",+ name: "sample-tools",+ path: "/workspace/project/sample-tools",+ },+ {+ id: "/workspace/project/notes-service",+ name: "notes-service",+ path: "/workspace/project/notes-service",+ },+ ],+ workspaceParents: [],+ };+ await page.route("**/api/workspaces**", async (route, req) => {+ if (req.method() !== "GET") {+ await route.fallback();+ return;+ }+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify(workspacesMock),+ });+ });++ await page.goto("/conversations", { waitUntil: "domcontentloaded" });++ // Open workspace dialog and pick a workspace+ const openButton = page.getByTestId("open-workspace-button");+ await expect(openButton).toBeEnabled({ timeout: 15_000 });+ await openButton.click();+ await expect(+ page.getByTestId("open-workspace-dialog-body"),+ ).toBeVisible();++ const dropdown = page.getByTestId("workspace-dropdown");+ await expect(dropdown).toBeEnabled({ timeout: 15_000 });+ await dropdown.click();++ const menu = page.getByTestId("workspace-dropdown-menu");+ await expect(menu).toBeVisible();+ await menu.getByText("demo-app", { exact: true }).click();++ await expect(dropdown).toHaveValue("demo-app");++ // Close the dialog+ await page.getByTestId("close-open-workspace-dialog").click();+ await expect(+ page.getByTestId("open-workspace-dialog-body"),+ ).not.toBeVisible();++ // Navigate away and back+ await page.goto("/settings", { waitUntil: "domcontentloaded" });+ await expect(page.getByTestId("home-screen")).not.toBeVisible({+ timeout: 5_000,+ });++ await page.goto("/conversations", { waitUntil: "domcontentloaded" });+ await expect(page.getByTestId("home-screen")).toBeVisible({+ timeout: 10_000,+ });++ // Reopen workspace dialog β selection should be restored.+ const reopenButton = page.getByTestId("open-workspace-button");+ await expect(reopenButton).toBeEnabled({ timeout: 15_000 });+ await reopenButton.click();+ await expect(+ page.getByTestId("open-workspace-dialog-body"),+ ).toBeVisible();++ const restored = page.getByTestId("workspace-dropdown");+ await expect(restored).toBeEnabled({ timeout: 15_000 });+ await expect(restored).toHaveValue("demo-app");+ });++ test("cleared sessionStorage yields empty workspace selection", async ({+ page,+ }) => {+ test.setTimeout(60_000);+ await routeSessionApiKey(page);++ await page.route("**/api/workspaces**", async (route, req) => {+ if (req.method() !== "GET") {+ await route.fallback();+ return;+ }+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({+ workspaces: [+ {+ id: "/workspace/project/demo-app",+ name: "demo-app",+ path: "/workspace/project/demo-app",+ },+ {+ id: "/workspace/project/sample-tools",+ name: "sample-tools",+ path: "/workspace/project/sample-tools",+ },+ ],+ workspaceParents: [],+ }),+ });+ });++ // Explicitly clear persisted workspace path+ await page.addInitScript(() => {+ window.sessionStorage.removeItem("oh:home-selected-workspace-path");+ });++ await page.goto("/conversations", { waitUntil: "domcontentloaded" });++ const openButton = page.getByTestId("open-workspace-button");+ await expect(openButton).toBeEnabled({ timeout: 15_000 });+ await openButton.click();+ await expect(+ page.getByTestId("open-workspace-dialog-body"),+ ).toBeVisible();++ const dropdown = page.getByTestId("workspace-dropdown");+ await expect(dropdown).toBeEnabled({ timeout: 15_000 });+ await expect(dropdown).toHaveValue("");+ });+});diff --git a/tests/e2e/regressions/avatar-menu.spec.ts b/tests/e2e/regressions/avatar-menu.spec.tsdeleted file mode 100644index 47a1585bd5..0000000000--- a/tests/e2e/regressions/avatar-menu.spec.ts+++ /dev/null@@ -1,114 +0,0 @@-import test, { expect } from "@playwright/test";--/**- * Test for issue #11933: Avatar context menu closes when moving cursor diagonally- *- * This test verifies that the user can move their cursor diagonally from the- * avatar to the context menu without the menu closing unexpectedly.- *- * The component opens the menu on hover and keeps it open during short- * diagonal movement through the hover bridge.- */-test("avatar context menu stays open when moving cursor diagonally to menu", async ({- page,-}) => {- await page.addInitScript(() => {- window.localStorage.setItem("analytics-consent", "true");- });-- // Intercept GET /api/settings to return settings with a configured provider.- // In OSS mode, the user context menu only renders when providers are configured.- await page.route("**/api/settings", async (route) => {- if (route.request().method() === "GET") {- await route.fulfill({- status: 200,- contentType: "application/json",- body: JSON.stringify({- llm_model: "openhands/claude-opus-4-5-20251101",- llm_base_url: "",- agent: "CodeActAgent",- language: "en",- llm_api_key: null,- llm_api_key_set: false,- search_api_key_set: false,- confirmation_mode: false,- security_analyzer: "llm",- remote_runtime_resource_factor: 1,- provider_tokens_set: { github: "" },- enable_default_condenser: true,- condenser_max_size: 240,- enable_sound_notifications: false,- user_consents_to_analytics: false,- enable_proactive_conversation_starters: false,- enable_solvability_analysis: false,- max_budget_per_task: null,- }),- });- } else {- await route.continue();- }- });-- await page.goto("/");-- 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 });-- // Wait for the page to be fully loaded and check for AI config modal- // The modal may appear for new users in OSS mode without settings- const aiConfigModal = page.getByTestId("ai-config-modal");-- // Give the modal a chance to appear (it may load asynchronously)- try {- await aiConfigModal.waitFor({ state: "visible", timeout: 3000 });- // Modal appeared - dismiss it by clicking save- await page.getByTestId("save-settings-button").click();- await expect(aiConfigModal).toBeHidden();- } catch {- // Modal didn't appear within timeout - that's fine, continue with test- }-- const userAvatar = page.getByTestId("user-avatar");- await expect(userAvatar).toBeVisible();-- await userAvatar.hover();-- const contextMenu = page.getByTestId("user-context-menu");- await expect(contextMenu).toBeVisible();-- const menuWrapper = contextMenu.locator("..");- await expect(menuWrapper).toHaveCSS("opacity", "1");-- // Now test diagonal mouse movement - move from avatar to menu- // The menu should stay open due to the hover bridge in the component- const avatarBox = await userAvatar.boundingBox();- const menuBox = await contextMenu.boundingBox();-- if (!avatarBox || !menuBox) {- throw new Error("Could not get bounding boxes");- }-- // Move diagonally from avatar center toward the menu- const startX = avatarBox.x + avatarBox.width / 2;- const startY = avatarBox.y + avatarBox.height / 2;- const endX = menuBox.x + menuBox.width / 2;- const endY = menuBox.y + menuBox.height / 2;-- // Simulate diagonal movement with multiple steps- const steps = 5;- for (let i = 0; i <= steps; i++) {- const x = startX + ((endX - startX) * i) / steps;- const y = startY + ((endY - startY) * i) / steps;- await page.mouse.move(x, y);- }-- // Menu should still be visible after diagonal movement- await expect(contextMenu).toBeVisible();- await expect(menuWrapper).toHaveCSS("opacity", "1");-});diff --git a/tests/e2e/regressions/css-isolation.spec.ts b/tests/e2e/regressions/css-isolation.spec.tsdeleted file mode 100644index 5ac1e3954e..0000000000--- a/tests/e2e/regressions/css-isolation.spec.ts+++ /dev/null@@ -1,32 +0,0 @@-import { expect, test } from "@playwright/test";--test("scopes standalone styles to the agent server UI shell", async ({- page,-}) => {- await page.goto("/");-- await expect(page.locator("[data-agent-server-ui]").first()).toBeVisible();- const layout = page.getByTestId("root-layout");- await expect(layout).toBeVisible();-- const insideBackground = await layout.evaluate(- (element) => getComputedStyle(element).backgroundColor,- );-- const outsideStyles = await page.evaluate(() => {- const hostProbe = document.createElement("div");- hostProbe.className = "bg-base text-content-2";- hostProbe.textContent = "host";- document.documentElement.appendChild(hostProbe);-- const styles = getComputedStyle(hostProbe);-- return {- backgroundColor: styles.backgroundColor,- color: styles.color,- };- });-- expect(insideBackground).not.toBe("rgba(0, 0, 0, 0)");- expect(outsideStyles.backgroundColor).not.toBe(insideBackground);-});diff --git a/tests/e2e/regressions/event-pagination.spec.ts b/tests/e2e/regressions/event-pagination.spec.tsdeleted file mode 100644index 654af12fa5..0000000000--- a/tests/e2e/regressions/event-pagination.spec.ts+++ /dev/null@@ -1,234 +0,0 @@-import { expect, test, type Page, type Request } from "@playwright/test";--const LOCAL_CONVERSATION_ID = "pagination-local";-const CLOUD_CONVERSATION_ID = "pagination-cloud";-const PAGE_SIZE = 50;-const PAGINATION_BASE_TIME = Date.UTC(2026, 4, 13, 0, 0, 0);--function timestampForEvent(index: number): string {- return new Date(PAGINATION_BASE_TIME + index * 60_000).toISOString();-}--async function seedBackendSelection(- page: Page,- mode: "local" | "cloud",- conversationId: string,-) {- await page.addInitScript(- ({ selectedMode, selectedConversationId }) => {- 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", "true");- window.localStorage.setItem("conversation-right-panel-shown", "false");- window.localStorage.setItem(- `conversation-right-panel-shown-${selectedConversationId}`,- "false",- );-- const localBackend = {- id: "pagination-local-backend",- name: "Local pagination backend",- host: window.location.origin,- apiKey: "",- kind: "local",- };- const cloudBackend = {- id: "pagination-cloud-backend",- name: "Cloud pagination backend",- host: "https://app.all-hands.dev",- apiKey: "mock-cloud-api-key",- kind: "cloud",- };-- window.localStorage.setItem(- "openhands-backends",- JSON.stringify(- selectedMode === "cloud"- ? [localBackend, cloudBackend]- : [localBackend],- ),- );- window.localStorage.setItem(- "openhands-active-backend",- JSON.stringify({- backendId:- selectedMode === "cloud" ? cloudBackend.id : localBackend.id,- orgId: selectedMode === "cloud" ? "org-1" : null,- }),- );- },- { selectedMode: mode, selectedConversationId: conversationId },- );-}--function eventSearchRequestFor(conversationId: string) {- return (request: Request) => {- if (request.method() !== "GET") return false;- if (- !request- .url()- .includes(`/api/conversations/${conversationId}/events/search`)- ) {- return false;- }- return new URL(request.url()).searchParams.has("timestamp__lt");- };-}--function parseCloudProxyPath(request: Request): string {- const body = JSON.parse(request.postData() ?? "{}") as { path?: string };- return body.path ?? "";-}--function cloudEventSearchRequestFor(conversationId: string) {- return (request: Request) => {- if (request.method() !== "POST") return false;- if (!request.url().includes("/api/cloud-proxy")) return false;- const path = parseCloudProxyPath(request);- return (- path.includes(`/api/v1/conversation/${conversationId}/events/search`) &&- path.includes("timestamp__lt")- );- };-}--async function getChatScroller(page: Page) {- const chatInterface = page.getByTestId("chat-interface");- await expect(chatInterface).toBeVisible({ timeout: 15_000 });- const scroller = chatInterface.locator(".custom-scrollbar-always").first();- await expect(scroller).toBeVisible();- return scroller;-}--async function waitForScrollableConversation(page: Page) {- const scroller = await getChatScroller(page);- await expect- .poll(- () =>- scroller.evaluate(- (element) => element.scrollHeight > element.clientHeight,- ),- { timeout: 15_000 },- )- .toBe(true);- return scroller;-}--async function triggerOlderEventLoad(page: Page) {- const scroller = await waitForScrollableConversation(page);- await scroller.evaluate((element) => {- element.scrollTop = 0;- element.dispatchEvent(new Event("scroll", { bubbles: true }));- });-}--test.describe("conversation event pagination", () => {- test.use({ viewport: { width: 1280, height: 720 } });-- test("loads older events when scrolling up on a local backend", async ({- page,- }) => {- await seedBackendSelection(page, "local", LOCAL_CONVERSATION_ID);-- const initialRequestPromise = page.waitForRequest((request) => {- if (request.method() !== "GET") return false;- if (- !request- .url()- .includes(`/api/conversations/${LOCAL_CONVERSATION_ID}/events/search`)- ) {- return false;- }- return !new URL(request.url()).searchParams.has("timestamp__lt");- });-- await page.goto(`/conversations/${LOCAL_CONVERSATION_ID}`);-- const initialRequest = await initialRequestPromise;- const initialUrl = new URL(initialRequest.url());- expect(initialUrl.searchParams.get("limit")).toBe(String(PAGE_SIZE));- expect(initialUrl.searchParams.get("sort_order")).toBe("TIMESTAMP_DESC");- await expect(- page.getByText("Local pagination message 100", { exact: true }),- ).toBeVisible({ timeout: 15_000 });- await expect(- page.getByText("Local pagination message 50", { exact: true }),- ).toHaveCount(0);-- const olderRequestPromise = page.waitForRequest(- eventSearchRequestFor(LOCAL_CONVERSATION_ID),- );- await triggerOlderEventLoad(page);-- await expect(page.getByTestId("loading-older-events")).toContainText(- "Fetching older messages",- );- const olderRequest = await olderRequestPromise;- const olderUrl = new URL(olderRequest.url());- expect(olderUrl.searchParams.get("limit")).toBe(String(PAGE_SIZE));- expect(olderUrl.searchParams.get("sort_order")).toBe("TIMESTAMP_DESC");- expect(olderUrl.searchParams.get("timestamp__lt")).toBe(- timestampForEvent(51),- );-- await expect(- page.getByText("Local pagination message 50", { exact: true }),- ).toBeAttached({ timeout: 15_000 });- await expect(page.getByTestId("loading-older-events")).toHaveCount(0);- });-- test("loads older events when scrolling up on a cloud backend", async ({- page,- }) => {- await seedBackendSelection(page, "cloud", CLOUD_CONVERSATION_ID);-- const initialRequestPromise = page.waitForRequest((request) => {- if (request.method() !== "POST") return false;- if (!request.url().includes("/api/cloud-proxy")) return false;- const path = parseCloudProxyPath(request);- return (- path.includes(- `/api/v1/conversation/${CLOUD_CONVERSATION_ID}/events/search`,- ) && !path.includes("timestamp__lt")- );- });-- await page.goto(`/conversations/${CLOUD_CONVERSATION_ID}`);-- const initialPath = parseCloudProxyPath(await initialRequestPromise);- const initialUrl = new URL(initialPath, "https://mock-cloud.test");- expect(initialUrl.searchParams.get("limit")).toBe(String(PAGE_SIZE));- expect(initialUrl.searchParams.get("sort_order")).toBe("TIMESTAMP_DESC");- await expect(- page.getByText("Cloud pagination message 100", { exact: true }),- ).toBeVisible({ timeout: 15_000 });- await expect(- page.getByText("Cloud pagination message 50", { exact: true }),- ).toHaveCount(0);-- const olderRequestPromise = page.waitForRequest(- cloudEventSearchRequestFor(CLOUD_CONVERSATION_ID),- );- await triggerOlderEventLoad(page);-- await expect(page.getByTestId("loading-older-events")).toContainText(- "Fetching older messages",- );- const olderPath = parseCloudProxyPath(await olderRequestPromise);- const olderUrl = new URL(olderPath, "https://mock-cloud.test");- expect(olderUrl.pathname).toBe(- `/api/v1/conversation/${CLOUD_CONVERSATION_ID}/events/search`,- );- expect(olderUrl.searchParams.get("limit")).toBe(String(PAGE_SIZE));- expect(olderUrl.searchParams.get("sort_order")).toBe("TIMESTAMP_DESC");- expect(olderUrl.searchParams.get("timestamp__lt")).toBe(- timestampForEvent(51),- );-- await expect(- page.getByText("Cloud pagination message 50", { exact: true }),- ).toBeAttached({ timeout: 15_000 });- await expect(page.getByTestId("loading-older-events")).toHaveCount(0);- });-});diff --git a/tests/e2e/regressions/workspace-selection-persistence.spec.ts b/tests/e2e/regressions/workspace-selection-persistence.spec.tsdeleted file mode 100644index 8ab6912dcf..0000000000--- a/tests/e2e/regressions/workspace-selection-persistence.spec.ts+++ /dev/null@@ -1,144 +0,0 @@-import test, { expect, Page } from "@playwright/test";--/**- * Regression test for issue #1076: selected workspace should persist across- * navigation in the new-chat view.- *- * The workspace-selection-form now backs the selected workspace path in- * sessionStorage so it survives unmount/remount cycles caused by navigating- * away from the home page and returning.- *- * The dev-mode MSW mock seeds implicit workspace parents under /projects,- * giving us "demo-app", "sample-tools", "notes-service" in the dropdown- * without any additional API setup.- */--const WORKSPACE_NAME = "demo-app";--async function seedLocalStorage(page: Page) {- await page.addInitScript(() => {- window.localStorage.setItem("openhands-onboarded", "1");- window.localStorage.setItem("openhands-telemetry-consent", "denied");- window.localStorage.setItem("analytics-consent", "true");- window.localStorage.setItem("openhands-telemetry-first-use", "true");- if (!window.localStorage.getItem("openhands-backends")) {- window.localStorage.setItem(- "openhands-backends",- JSON.stringify([- {- id: "default-local",- name: "Local",- host: window.location.origin,- apiKey: "test-session-key",- kind: "local",- },- ]),- );- }- if (!window.localStorage.getItem("openhands-active-backend")) {- window.localStorage.setItem(- "openhands-active-backend",- JSON.stringify({ backendId: "default-local", orgId: null }),- );- }- });-}--async function dismissConsentModal(page: Page) {- 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 });-}--async function openWorkspaceDialog(page: Page) {- const openWorkspaceButton = page.getByTestId("open-workspace-button");- await expect(openWorkspaceButton).toBeEnabled({ timeout: 15_000 });- await openWorkspaceButton.click();- await expect(page.getByTestId("open-workspace-dialog-body")).toBeVisible();-}--async function selectWorkspaceInDropdown(page: Page, workspaceName: string) {- const dropdown = page.getByTestId("workspace-dropdown");- await expect(dropdown).toBeEnabled({ timeout: 15_000 });- await dropdown.click();-- const menu = page.getByTestId("workspace-dropdown-menu");- await expect(menu).toBeVisible();-- const option = menu.getByText(workspaceName, { exact: true });- await expect(option).toBeVisible();- await option.click();-}--test.describe("Workspace selection persistence (#1076)", () => {- test("selected workspace persists after navigating away and returning", async ({- page,- }) => {- test.setTimeout(60_000);-- await seedLocalStorage(page);- await page.goto("/conversations", { waitUntil: "domcontentloaded" });- await dismissConsentModal(page);-- // Step 1: Open workspace dialog and select a workspace- await openWorkspaceDialog(page);- await selectWorkspaceInDropdown(page, WORKSPACE_NAME);-- // Verify the dropdown now shows the selected workspace- const dropdown = page.getByTestId("workspace-dropdown");- await expect(dropdown).toHaveValue(WORKSPACE_NAME);-- // Close the dialog- await page.getByTestId("close-open-workspace-dialog").click();- await expect(- page.getByTestId("open-workspace-dialog-body"),- ).not.toBeVisible();-- // Step 2: Navigate to settings and back- await page.goto("/settings", { waitUntil: "domcontentloaded" });- await expect(page.getByTestId("home-screen")).not.toBeVisible({- timeout: 5000,- });-- await page.goto("/conversations", { waitUntil: "domcontentloaded" });- await expect(page.getByTestId("home-screen")).toBeVisible({- timeout: 10_000,- });-- // Step 3: Open workspace dialog again and verify persistence- await openWorkspaceDialog(page);-- const restoredDropdown = page.getByTestId("workspace-dropdown");- await expect(restoredDropdown).toBeEnabled({ timeout: 15_000 });- await expect(restoredDropdown).toHaveValue(WORKSPACE_NAME);- });-- test("cleared sessionStorage results in empty workspace selection on fresh visit", async ({- page,- }) => {- test.setTimeout(60_000);-- await seedLocalStorage(page);-- // Ensure no persisted workspace path- await page.addInitScript(() => {- window.sessionStorage.removeItem("oh:home-selected-workspace-path");- });-- await page.goto("/conversations", { waitUntil: "domcontentloaded" });- await dismissConsentModal(page);-- await openWorkspaceDialog(page);-- const dropdown = page.getByTestId("workspace-dropdown");- await expect(dropdown).toBeEnabled({ timeout: 15_000 });-- // The dropdown should be empty (no pre-selected workspace)- await expect(dropdown).toHaveValue("");- });-});