Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,5 +1,7 @@
import { expect, type Locator, type Page } from "@playwright/test";
import { waitForHydration } from "./navigation";
export type TenantCredentials = {
email: string;
password: string;
@@ -29,8 +31,9 @@ const LOGIN_OFF_URL_TIMEOUT_MS = 15_000;
// back off for the rate-limit case and surface other errors immediately.
const RATE_LIMIT_TEXT_PATTERN = /too many|zu viele/iu;
async function attemptLogin(page: Page, credentials: TenantCredentials): Promise<boolean> {
await page.goto("/login", { waitUntil: "domcontentloaded" });
async function attemptLogin(page: Page, credentials: TenantCredentials, loginPageUrl: string): Promise<boolean> {
await page.goto(loginPageUrl, { waitUntil: "domcontentloaded" });
await waitForHydration(page);
await page.locator('[data-ui-id="ui.auth.login.email"], input[type="email"], input[name="email"], input#email').first().fill(credentials.email);
await page
@@ -50,10 +53,9 @@ async function attemptLogin(page: Page, credentials: TenantCredentials): Promise
// Cache the authenticated cookies after the first real login and reuse them for
// every later spec in the same (workers:1) run. Re-logging-in per test
// saturates the server auth rate limit (10/60s per IP+email), which surfaces as
// flaky "stayed on /login" failures across the large serial suite. /login
// redirects an authenticated session away, so the cache can be validated
// cheaply and a stale entry (e.g. after a sign-out test) falls back to a real
// login.
// flaky "stayed on /login" failures across the large serial suite. The cache is
// validated against an authenticated surface; a stale entry (e.g. after a
// sign-out test) falls back to a real login.
//
// The cache is keyed by EMAIL: the suite logs in as multiple users (the tenant
// admin AND a read-only fixture). A single global cache would hand a later
@@ -61,27 +63,70 @@ async function attemptLogin(page: Page, credentials: TenantCredentials): Promise
// (so /login redirects away and the cache "matches"), silently running the
// read-only test as the admin — which then sees mutation controls and fails.
type StoredCookies = Awaited<ReturnType<ReturnType<Page["context"]>["cookies"]>>;
const cachedCookiesByEmail = new Map<string, StoredCookies>();
const cachedCookiesByIdentity = new Map<string, StoredCookies>();
async function reuseCachedLogin(page: Page, credentials: TenantCredentials): Promise<boolean> {
const cached = cachedCookiesByEmail.get(credentials.email);
async function reuseCachedLogin(page: Page, credentials: TenantCredentials, loginPageUrl: string, sessionProbeUrl: string): Promise<boolean> {
const cacheKey = loginCacheKey(credentials, loginPageUrl);
const cached = cachedCookiesByIdentity.get(cacheKey);
if (!cached || cached.length === 0) return false;
await page.context().addCookies(cached);
await page.goto("/login", { waitUntil: "domcontentloaded" });
await page.goto(sessionProbeUrl, { waitUntil: "domcontentloaded" });
if (!LOGIN_URL_PATTERN.test(page.url())) return true;
cachedCookiesByEmail.delete(credentials.email);
cachedCookiesByIdentity.delete(cacheKey);
return false;
}
async function reuseContextLogin(page: Page, sessionProbeUrl: string): Promise<boolean> {
const probeUrl = new URL(sessionProbeUrl, process.env.E2E_BASE_URL ?? "http://localhost:3000");
const cookies = await page.context().cookies(probeUrl.origin);
if (cookies.length === 0) return false;
await page.goto(sessionProbeUrl, { waitUntil: "domcontentloaded" });
return !LOGIN_URL_PATTERN.test(page.url());
}
export async function loginAsTenantUser(page: Page, credentials: TenantCredentials): Promise<void> {
if (await reuseCachedLogin(page, credentials)) {
await loginAt(page, credentials, "/login");
}
export async function loginAsAdminUser(page: Page, credentials: TenantCredentials): Promise<void> {
await loginAt(page, credentials, resolveAdminLoginUrl(), resolveAdminDashboardUrl());
}
export function resolveAdminLoginUrl(env: NodeJS.ProcessEnv = process.env): string {
return resolveAdminSurfaceUrl("/login", env);
}
export function resolveAdminDashboardUrl(env: NodeJS.ProcessEnv = process.env): string {
return resolveAdminSurfaceUrl("/dashboard", env);
}
function resolveAdminSurfaceUrl(pathname: string, env: NodeJS.ProcessEnv): string {
const explicitAdminUrl = env.E2E_ADMIN_BASE_URL?.trim();
const baseUrl = explicitAdminUrl || env.E2E_BASE_URL?.trim() || "http://localhost:3000";
const url = new URL(baseUrl);
if (!explicitAdminUrl) {
url.hostname = url.hostname === "localhost" ? "admin.localhost" : url.hostname.replace(/^app\./u, "admin.");
}
url.pathname = pathname;
url.search = "";
url.hash = "";
return url.toString();
}
async function loginAt(page: Page, credentials: TenantCredentials, loginPageUrl: string, sessionProbeUrl: string = loginPageUrl): Promise<void> {
if (await reuseContextLogin(page, sessionProbeUrl)) {
return;
}
const cacheKey = loginCacheKey(credentials, loginPageUrl);
if (await reuseCachedLogin(page, credentials, loginPageUrl, sessionProbeUrl)) {
return;
}
let rateLimited = false;
for (let attempt = 0; attempt < LOGIN_MAX_ATTEMPTS; attempt += 1) {
if (await attemptLogin(page, credentials)) {
cachedCookiesByEmail.set(credentials.email, await page.context().cookies());
if (await attemptLogin(page, credentials, loginPageUrl)) {
cachedCookiesByIdentity.set(cacheKey, await page.context().cookies());
return;
}
@@ -107,6 +152,10 @@ export async function loginAsTenantUser(page: Page, credentials: TenantCredentia
await expect(page, `Expected to leave /login after submitting tenant credentials but stayed on ${page.url()}.${hint}`).not.toHaveURL(LOGIN_URL_PATTERN);
}
function loginCacheKey(credentials: TenantCredentials, loginPageUrl: string): string {
return `${credentials.email.trim().toLowerCase()}@${new URL(loginPageUrl, "http://localhost").origin}`;
}
export async function expectPasswordRequirementsVisible(requirements: Locator): Promise<void> {
await expect(requirements).toBeVisible();
const items = requirements.locator("li");
@@ -138,39 +187,43 @@ export function tenantSettingsProfilePath(dashboardPath: string): string {
}
export function tenantSettingsAccountPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "account", process.env.E2E_TENANT_SETTINGS_ACCOUNT_PATH ?? "/app/settings/account");
return tenantSettingsPath(dashboardPath, "workspace", process.env.E2E_TENANT_SETTINGS_ACCOUNT_PATH ?? "/app/settings/workspace");
}
export function tenantSettingsSubscriptionPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "subscription", process.env.E2E_TENANT_SUBSCRIPTION_PATH ?? "/app/settings/subscription");
return tenantSettingsPath(dashboardPath, "billing", process.env.E2E_TENANT_SUBSCRIPTION_PATH ?? "/app/settings/billing");
}
export function tenantSettingsPoliciesPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "policies", process.env.E2E_TENANT_POLICIES_PATH ?? "/app/settings/policies");
return tenantSettingsPath(dashboardPath, "workspace/policies", process.env.E2E_TENANT_POLICIES_PATH ?? "/app/settings/workspace/policies");
}
export function tenantSettingsNotificationsPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "notifications", process.env.E2E_TENANT_NOTIFICATIONS_PATH ?? "/app/settings/notifications");
return tenantSettingsPath(dashboardPath, "profile/notifications", process.env.E2E_TENANT_NOTIFICATIONS_PATH ?? "/app/settings/profile/notifications");
}
export function tenantSettingsMembersPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "members", process.env.E2E_TENANT_MEMBERS_PATH ?? "/app/settings/members");
return tenantSettingsPath(dashboardPath, "team", process.env.E2E_TENANT_MEMBERS_PATH ?? "/app/settings/team");
}
export function tenantSettingsLogsPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "logs", process.env.E2E_TENANT_LOGS_PATH ?? "/app/settings/logs");
return tenantSettingsPath(dashboardPath, "compliance", process.env.E2E_TENANT_LOGS_PATH ?? "/app/settings/compliance");
}
export function tenantSettingsLogEventsPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "logs/events", process.env.E2E_TENANT_LOG_EVENTS_PATH ?? "/app/settings/logs/events");
return tenantSettingsPath(dashboardPath, "compliance/events", process.env.E2E_TENANT_LOG_EVENTS_PATH ?? "/app/settings/compliance/events");
}
export function tenantSettingsAuditExportPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "audit-export", process.env.E2E_TENANT_AUDIT_EXPORT_PATH ?? "/app/settings/audit-export");
return tenantSettingsPath(dashboardPath, "compliance/audit-export", process.env.E2E_TENANT_AUDIT_EXPORT_PATH ?? "/app/settings/compliance/audit-export");
}
export function tenantRolesAndPermissionsPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "roles-and-permissions", process.env.E2E_TENANT_ROLES_AND_PERMISSIONS_PATH ?? "/app/settings/roles-and-permissions");
return tenantSettingsPath(dashboardPath, "team/roles", process.env.E2E_TENANT_ROLES_AND_PERMISSIONS_PATH ?? "/app/settings/team/roles");
}
export function tenantLegacyRolesAndPermissionsPath(dashboardPath: string): string {
return tenantSettingsPath(dashboardPath, "roles-and-permissions", "/app/settings/roles-and-permissions");
}
function tenantSettingsPath(dashboardPath: string, section: string, fallbackPath: string): string {