From b6aff9c796aaea96256dd2c03fbfcad65df87a26 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Wed, 4 Mar 2026 22:29:47 +0530 Subject: [PATCH] test(e2e): align critical-flow specs with local auth CI --- frontend/cypress/e2e/global_approvals.cy.ts | 26 +++++------ frontend/cypress/e2e/skill_packs_sync.cy.ts | 19 ++------ frontend/cypress/support/testHooks.ts | 49 ++++++++++++++++++++- 3 files changed, 62 insertions(+), 32 deletions(-) diff --git a/frontend/cypress/e2e/global_approvals.cy.ts b/frontend/cypress/e2e/global_approvals.cy.ts index f63afea8..7e0d7fb4 100644 --- a/frontend/cypress/e2e/global_approvals.cy.ts +++ b/frontend/cypress/e2e/global_approvals.cy.ts @@ -2,18 +2,8 @@ import { setupCommonPageTestHooks } from "../support/testHooks"; -// Clerk/Next.js occasionally triggers a hydration mismatch on auth routes in CI. -// This is non-deterministic UI noise for these tests; ignore it so assertions can proceed. -Cypress.on("uncaught:exception", (err) => { - if (err.message?.includes("Hydration failed")) { - return false; - } - return true; -}); - describe("Global approvals", () => { const apiBase = "**/api/v1"; - const email = Cypress.env("CLERK_TEST_EMAIL") || "jane+clerk_test@example.com"; setupCommonPageTestHooks(apiBase); @@ -62,14 +52,20 @@ describe("Global approvals", () => { body: { ...approval, status: "approved" }, }).as("approvalUpdate"); - cy.visit("/sign-in"); - cy.clerkLoaded(); - cy.clerkSignIn({ strategy: "email_code", identifier: email }); - + cy.loginWithLocalAuth(); cy.visit("/approvals"); cy.waitForAppLoaded(); - cy.wait(["@boardsList", "@approvalsList"], { timeout: 20_000 }); + cy.wait( + [ + "@usersMe", + "@organizationsList", + "@orgMeMember", + "@boardsList", + "@approvalsList", + ], + { timeout: 20_000 }, + ); // Pending approval should be visible in the list. cy.contains(/unapproved tasks/i).should("be.visible"); diff --git a/frontend/cypress/e2e/skill_packs_sync.cy.ts b/frontend/cypress/e2e/skill_packs_sync.cy.ts index cc3590fb..d0cb05fb 100644 --- a/frontend/cypress/e2e/skill_packs_sync.cy.ts +++ b/frontend/cypress/e2e/skill_packs_sync.cy.ts @@ -2,18 +2,8 @@ import { setupCommonPageTestHooks } from "../support/testHooks"; -// Clerk/Next.js occasionally triggers a hydration mismatch on auth routes in CI. -// This is non-deterministic UI noise for these tests; ignore it so assertions can proceed. -Cypress.on("uncaught:exception", (err) => { - if (err.message?.includes("Hydration failed")) { - return false; - } - return true; -}); - describe("Skill packs", () => { const apiBase = "**/api/v1"; - const email = Cypress.env("CLERK_TEST_EMAIL") || "jane+clerk_test@example.com"; setupCommonPageTestHooks(apiBase); @@ -41,14 +31,13 @@ describe("Skill packs", () => { }, }).as("packSync"); - cy.visit("/sign-in"); - cy.clerkLoaded(); - cy.clerkSignIn({ strategy: "email_code", identifier: email }); - + cy.loginWithLocalAuth(); cy.visit("/skills/packs"); cy.waitForAppLoaded(); - cy.wait("@packsList", { timeout: 20_000 }); + cy.wait(["@usersMe", "@organizationsList", "@orgMeMember", "@packsList"], { + timeout: 20_000, + }); cy.contains(/openclaw skills/i).should("be.visible"); cy.contains("button", /^sync$/i).click(); diff --git a/frontend/cypress/support/testHooks.ts b/frontend/cypress/support/testHooks.ts index be07765b..4414132f 100644 --- a/frontend/cypress/support/testHooks.ts +++ b/frontend/cypress/support/testHooks.ts @@ -3,13 +3,26 @@ type CommonPageTestHooksOptions = { timeoutMs?: number; orgMemberRole?: string; + organizationId?: string; + organizationName?: string; + userId?: string; + userEmail?: string; + userName?: string; }; export function setupCommonPageTestHooks( apiBase: string, options: CommonPageTestHooksOptions = {}, ): void { - const { timeoutMs = 20_000, orgMemberRole = "owner" } = options; + const { + timeoutMs = 20_000, + orgMemberRole = "owner", + organizationId = "org1", + organizationName = "Testing Org", + userId = "u1", + userEmail = "local-auth-user@example.com", + userName = "Local User", + } = options; const originalDefaultCommandTimeout = Cypress.config("defaultCommandTimeout"); beforeEach(() => { @@ -20,9 +33,41 @@ export function setupCommonPageTestHooks( body: { ok: true }, }).as("healthz"); + cy.intercept("GET", `${apiBase}/users/me*`, { + statusCode: 200, + body: { + id: userId, + clerk_user_id: "local-auth-user", + email: userEmail, + name: userName, + preferred_name: userName, + timezone: "UTC", + }, + }).as("usersMe"); + + cy.intercept("GET", `${apiBase}/organizations/me/list*`, { + statusCode: 200, + body: [ + { + id: organizationId, + name: organizationName, + is_active: true, + role: orgMemberRole, + }, + ], + }).as("organizationsList"); + cy.intercept("GET", `${apiBase}/organizations/me/member*`, { statusCode: 200, - body: { organization_id: "org1", role: orgMemberRole }, + body: { + id: "membership-1", + organization_id: organizationId, + user_id: userId, + role: orgMemberRole, + all_boards_read: true, + all_boards_write: true, + board_access: [], + }, }).as("orgMeMember"); });