From 74a65bd851e0950f793f3ce21132feb8d3b55833 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Tue, 14 Apr 2026 11:35:32 +0700 Subject: [PATCH] fix(e2e): derive new workspace ID from URL instead of sidebar rows assertNewWorkspaceSidebarAndHeader was scanning all sidebar workspace rows to find the newly created workspace, but would pick up workspaces from concurrent test suites (e.g. archive-tab). Use the page URL as source of truth since the app redirects to the new workspace after creation. --- packages/app/e2e/helpers/new-workspace.ts | 43 ++++------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/packages/app/e2e/helpers/new-workspace.ts b/packages/app/e2e/helpers/new-workspace.ts index e9d9a401a..d5753f8d7 100644 --- a/packages/app/e2e/helpers/new-workspace.ts +++ b/packages/app/e2e/helpers/new-workspace.ts @@ -84,21 +84,6 @@ function parseWorkspaceIdFromPageUrl(page: Page, serverId: string): string | nul return decodeWorkspaceIdFromPathSegment(match[1]); } -function parseWorkspaceIdFromSidebarRowTestId( - testId: string, - input: { serverId: string; previousWorkspaceId: string }, -): string | null { - const prefix = `sidebar-workspace-row-${input.serverId}:`; - if (!testId.startsWith(prefix)) { - return null; - } - const workspaceId = testId.slice(prefix.length).trim(); - if (!workspaceId || workspaceId === input.previousWorkspaceId) { - return null; - } - return workspaceId; -} - export async function connectNewWorkspaceDaemonClient(): Promise { const DaemonClient = await loadDaemonClientConstructor(); const webSocketFactory = createNodeWebSocketFactory(); @@ -185,36 +170,20 @@ export async function assertNewWorkspaceSidebarAndHeader( page: Page, input: { serverId: string; previousWorkspaceId: string; projectDisplayName: string }, ): Promise<{ workspaceId: string }> { + // Wait for URL to redirect to the newly created workspace. + // Uses URL as source of truth to avoid picking up sidebar rows from concurrent tests. let workspaceId: string | null = null; - const sidebarWorkspaceRows = page.locator( - `[data-testid^="sidebar-workspace-row-${input.serverId}:"]`, - ); - const deadline = Date.now() + 30_000; + const deadline = Date.now() + 60_000; while (Date.now() < deadline) { - const sidebarRowTestIds = await sidebarWorkspaceRows.evaluateAll((elements) => - elements.map((element) => element.getAttribute("data-testid") ?? ""), - ); - workspaceId = - sidebarRowTestIds - .map((testId) => parseWorkspaceIdFromSidebarRowTestId(testId, input)) - .find((id) => id !== null) ?? null; - if (workspaceId) { + workspaceId = parseWorkspaceIdFromPageUrl(page, input.serverId); + if (workspaceId && workspaceId !== input.previousWorkspaceId) { break; } await page.waitForTimeout(250); } if (!workspaceId || workspaceId === input.previousWorkspaceId) { - const sidebarWorkspaceRowIds = await sidebarWorkspaceRows.evaluateAll((elements) => - elements.map((element) => element.getAttribute("data-testid") ?? ""), - ); - throw new Error( - [ - "Expected a newly created workspace to load.", - `Current URL: ${page.url()}`, - `Sidebar rows: ${sidebarWorkspaceRowIds.join(", ") || ""}`, - ].join("\n"), - ); + throw new Error(`Expected URL to redirect to a new workspace.\nCurrent URL: ${page.url()}`); } const createdWorkspaceRow = page.getByTestId(