diff --git a/apps/app/e2e/shell/editor-journey.spec.ts b/apps/app/e2e/shell/editor-journey.spec.ts index 62816544..816c167b 100644 --- a/apps/app/e2e/shell/editor-journey.spec.ts +++ b/apps/app/e2e/shell/editor-journey.spec.ts @@ -22,6 +22,7 @@ import { savedLine, saveDraft, saveLine, + closeSecondSession, secondSession, selectionTag, selectTab, @@ -361,7 +362,7 @@ test.describe('editor journey (owner trial steps)', () => { await clickDialog(again, dict['editor.draft.conflict.keep']) await expect(again).toBeHidden() await expect(saveLine(page)).toHaveText(savedLine(dict, 5)) - await second.context.close() + await closeSecondSession(second) await selectTab(page, dict, 'verification') diff --git a/apps/app/e2e/shell/editor-recovery.spec.ts b/apps/app/e2e/shell/editor-recovery.spec.ts index 8d251b36..e138dcd4 100644 --- a/apps/app/e2e/shell/editor-recovery.spec.ts +++ b/apps/app/e2e/shell/editor-recovery.spec.ts @@ -2,7 +2,11 @@ import { fr } from '@/i18n/fr' import type { Locator, Page, TestInfo } from '@playwright/test' import { rpc } from '../../../../packages/supabase/tests/sandbox/stack' import { expect, expectAccessible, test } from '../support/browser' -import { dropLateReplays, routeToSandbox } from '../support/sandbox' +import { + FAKE_SUPABASE_ORIGIN, + dropLateReplays, + routeToSandbox, +} from '../support/sandbox' import { type Actor, copyKeyOf, @@ -26,7 +30,7 @@ import { UNSAVED_LINE, } from '../support/editor' import { stepUpAdmin } from '../support/admin' -import { secondSession } from '../support/editor' +import { closeSecondSession, secondSession } from '../support/editor' import { signIn } from '../support/shell' // V1-2.6 recovery and concurrency (contract C27 to C30, owner 2026-11-04): two sessions @@ -134,7 +138,7 @@ test.describe('editor recovery and concurrency', () => { // The reloaded session then saves without a conflict. await commitText(nameFr(other.page), 'Seconde session, reprise') await saveDraft(other.page, dict, 3) - await other.context.close() + await closeSecondSession(other) }) test('an older copy restored then saved: conflict, then « Garder ma version » after the confirmation', async ({ @@ -254,6 +258,23 @@ test.describe('editor recovery and concurrency', () => { await expect(nameFr(page)).toBeEditable() }) + test('a second session closed with a read in flight fails nothing (verifier 10)', async ({ + browser, + baseURL, + }) => { + // Gate final3: a replay of the closed context's last read rejected with « Request + // context disposed » inside the route callback, which failed the test. + const other = await secondSession(browser, baseURL ?? '', 'fr-FR') + await other.page.goto('/login') + const replayed = other.page.waitForRequest(/\/rest\/v1\/species/) + // Many reads, so some replays are still running when the context closes. + await other.page.evaluate((url) => { + for (let i = 0; i < 60; i += 1) void fetch(`${url}&n=${i}`).catch(() => 0) + }, `${FAKE_SUPABASE_ORIGIN}/rest/v1/species?select=id`) + await replayed + await closeSecondSession(other) + }) + test('the conflict read in progress can be left with Escape', async ({ page, browser, @@ -268,7 +289,7 @@ test.describe('editor recovery and concurrency', () => { await signInAgain(other.page, actor, seed.sheetId) await commitText(nameFr(other.page), 'Devant') await saveDraft(other.page, dict, 2) - await other.context.close() + await closeSecondSession(other) let release = () => {} const gate = new Promise((resolve) => (release = resolve)) diff --git a/apps/app/e2e/shell/editor-shell-journeys.spec.ts b/apps/app/e2e/shell/editor-shell-journeys.spec.ts index 907c42d8..0e07550a 100644 --- a/apps/app/e2e/shell/editor-shell-journeys.spec.ts +++ b/apps/app/e2e/shell/editor-shell-journeys.spec.ts @@ -1,7 +1,9 @@ import { fr } from '@/i18n/fr' import type { Page, TestInfo } from '@playwright/test' import { expect, test } from '../support/browser' +import { sessionAal, stepUpAdmin } from '../support/admin' import { dropLateReplays, routeToSandbox } from '../support/sandbox' +import { signIn } from '../support/shell' import { TABS, closeFinding, @@ -284,4 +286,27 @@ test.describe('editor shell journeys (H)', () => { .replace('{revision}', String(seed.revision + 1)) await expect(saveLine(page)).toHaveText(new RegExp(`^${timed}$`)) }) + + test('the step-up of the setup survives one GoTrue verify failure (verifier 10)', async ({ + page, + }) => { + // Under the eight-worker sweep GoTrue answered a verify HTTP 500 (gate final.log): + // the step-up shows « indisponible » and the setup must try again, never stop there. + const actor = await editorActor('fr') + let failed = false + await page.route('**/auth/v1/factors/*/verify', (route) => { + if (failed) return route.fallback() + failed = true + return route.fulfill({ + status: 500, + contentType: 'application/json', + body: JSON.stringify({ code: 500, error_code: 'unexpected_failure' }), + }) + }) + await signIn(page, actor.account, dict) + await page.goto('/app/admin') + await stepUpAdmin(page, dict, actor.secret) + expect(failed).toBe(true) + expect(await sessionAal(page)).toBe('aal2') + }) }) diff --git a/apps/app/e2e/support/admin.ts b/apps/app/e2e/support/admin.ts index be182064..9587ebe4 100644 --- a/apps/app/e2e/support/admin.ts +++ b/apps/app/e2e/support/admin.ts @@ -15,7 +15,7 @@ import { } from '../../../../packages/supabase/tests/sandbox/mfa' import { sql, stack } from '../../../../packages/supabase/tests/sandbox/stack' import { currentCode } from '../../../../packages/supabase/tests/sandbox/totp' -import { expect } from './browser' +import { expect, test } from './browser' import type { SandboxAccount } from './sandbox' export type GrantKind = @@ -68,7 +68,10 @@ export async function enrolVerifiedFactor( const token = await passwordToken(account) const enrolment = await enrolTotp(token, name) if (!enrolment.factor) throw new Error(`sandbox enrol: ${refusal(enrolment)}`) - const verified = await verifyTotp(token, enrolment.factor) + let verified = await verifyTotp(token, enrolment.factor) + // The HTTP 500 of the sweep (see `STEP_UP_ATTEMPTS`) is tried once more. + if (verified.status >= 500) + verified = await verifyTotp(token, enrolment.factor) if (verified.status !== 200) throw new Error(`sandbox verify: ${refusal(verified)}`) return enrolment.factor.secret @@ -111,12 +114,48 @@ export const stepUpHeading = (page: Page, dict: Dict) => .getByRole('main') .getByRole('heading', { level: 1, name: dict['admin.step_up.title'] }) -/** Completes the administration step-up; the page behind it then renders. */ -export async function stepUpAdmin(page: Page, dict: Dict, secret: string) { +/** + * GoTrue answers some TOTP verifies HTTP 500 `unexpected_failure` under the eight-worker + * sweep (gate final.log, BLK-015 family): the step-up then shows the network or the + * unavailable failure (supabase-js reads that 500 as a retryable fetch error). The setup + * tries again from a reloaded page, at most this many times in all; a refused code + * (`invalid_code`) is never retried. + */ +const STEP_UP_ATTEMPTS = 3 + +/** The failures of the step-up form that a server or transport fault shows. */ +const transientFailure = (main: Locator, dict: Dict) => + main + .getByText(dict['mfa.failure.unavailable']) + .or(main.getByText(dict['mfa.failure.network'])) + +/** One code sent; resolves once the gate opened (false) or said the server failed (true). */ +async function sendStepUpCode(page: Page, dict: Dict, secret: string) { const heading = stepUpHeading(page, dict) + const main = page.getByRole('main') + const unavailable = transientFailure(main, dict) await expect(heading).toBeVisible() // The gate settles its reads before the code is typed (a re-check remounts the form). await page.waitForLoadState('networkidle') - await enterCode(page.getByRole('main'), dict, secret) - await expect(heading).toBeHidden() + await enterCode(main, dict, secret) + await expect(async () => { + const settled = + (await heading.isHidden()) || (await unavailable.isVisible()) + expect(settled).toBe(true) + }).toPass({ timeout: 10_000 }) + return unavailable.isVisible() +} + +/** Completes the administration step-up; the page behind it then renders. */ +export async function stepUpAdmin(page: Page, dict: Dict, secret: string) { + for (let attempt = 1; ; attempt += 1) { + const unavailable = await sendStepUpCode(page, dict, secret) + if (!unavailable || attempt === STEP_UP_ATTEMPTS) break + test.info().annotations.push({ + type: 'step-up retried', + description: `attempt ${attempt}: GoTrue verify failed on the server`, + }) + await page.reload() + } + await expect(stepUpHeading(page, dict)).toBeHidden() } diff --git a/apps/app/e2e/support/editor.ts b/apps/app/e2e/support/editor.ts index 8269ff32..4c4eb329 100644 --- a/apps/app/e2e/support/editor.ts +++ b/apps/app/e2e/support/editor.ts @@ -27,6 +27,7 @@ import { core } from './catalogue' import { parseOutcome } from '@faunosteo/core-wasm' import { createAccount, + dropLateReplays, FAKE_SUPABASE_ORIGIN, routeToSandbox, type SandboxAccount, @@ -778,6 +779,18 @@ export async function secondSession( return { context, page: await context.newPage() } } +/** + * Closes a session opened by `secondSession`. Its replays still running are dropped + * first: closing the context under them rejects their `route.fetch` or `route.fulfill` + * (« Request context disposed »), which fails the test (verifier 10, gate final3). + */ +export async function closeSecondSession(session: { + context: BrowserContext +}): Promise { + await dropLateReplays(session.context) + await session.context.close() +} + /** The storage key of the tab's recovery copy of a draft (state/recovery.ts). */ export const copyKeyOf = (userId: string, versionId: string) => `osteo:sheet-draft:${userId}:${versionId}`