fix(editor): e2e setup retries a GoTrue 500 step-up, drops late replays
This commit is contained in:
1 parent
dca80cb006
commit
0ea94602d1
5 files changed
+110
-11
No files matched your search
@@ -22,6 +22,7 @@ import {
|
|||||||
savedLine,
|
savedLine,
|
||||||
saveDraft,
|
saveDraft,
|
||||||
saveLine,
|
saveLine,
|
||||||
|
closeSecondSession,
|
||||||
secondSession,
|
secondSession,
|
||||||
selectionTag,
|
selectionTag,
|
||||||
selectTab,
|
selectTab,
|
||||||
@@ -361,7 +362,7 @@ test.describe('editor journey (owner trial steps)', () => {
|
|||||||
await clickDialog(again, dict['editor.draft.conflict.keep'])
|
await clickDialog(again, dict['editor.draft.conflict.keep'])
|
||||||
await expect(again).toBeHidden()
|
await expect(again).toBeHidden()
|
||||||
await expect(saveLine(page)).toHaveText(savedLine(dict, 5))
|
await expect(saveLine(page)).toHaveText(savedLine(dict, 5))
|
||||||
await second.context.close()
|
await closeSecondSession(second)
|
||||||
|
|
||||||
await selectTab(page, dict, 'verification')
|
await selectTab(page, dict, 'verification')
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import { fr } from '@/i18n/fr'
|
|||||||
import type { Locator, Page, TestInfo } from '@playwright/test'
|
import type { Locator, Page, TestInfo } from '@playwright/test'
|
||||||
import { rpc } from '../../../../packages/supabase/tests/sandbox/stack'
|
import { rpc } from '../../../../packages/supabase/tests/sandbox/stack'
|
||||||
import { expect, expectAccessible, test } from '../support/browser'
|
import { expect, expectAccessible, test } from '../support/browser'
|
||||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
import {
|
||||||
|
FAKE_SUPABASE_ORIGIN,
|
||||||
|
dropLateReplays,
|
||||||
|
routeToSandbox,
|
||||||
|
} from '../support/sandbox'
|
||||||
import {
|
import {
|
||||||
type Actor,
|
type Actor,
|
||||||
copyKeyOf,
|
copyKeyOf,
|
||||||
@@ -26,7 +30,7 @@ import {
|
|||||||
UNSAVED_LINE,
|
UNSAVED_LINE,
|
||||||
} from '../support/editor'
|
} from '../support/editor'
|
||||||
import { stepUpAdmin } from '../support/admin'
|
import { stepUpAdmin } from '../support/admin'
|
||||||
import { secondSession } from '../support/editor'
|
import { closeSecondSession, secondSession } from '../support/editor'
|
||||||
import { signIn } from '../support/shell'
|
import { signIn } from '../support/shell'
|
||||||
|
|
||||||
// V1-2.6 recovery and concurrency (contract C27 to C30, owner 2026-11-04): two sessions
|
// 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.
|
// The reloaded session then saves without a conflict.
|
||||||
await commitText(nameFr(other.page), 'Seconde session, reprise')
|
await commitText(nameFr(other.page), 'Seconde session, reprise')
|
||||||
await saveDraft(other.page, dict, 3)
|
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 ({
|
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()
|
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 ({
|
test('the conflict read in progress can be left with Escape', async ({
|
||||||
page,
|
page,
|
||||||
browser,
|
browser,
|
||||||
@@ -268,7 +289,7 @@ test.describe('editor recovery and concurrency', () => {
|
|||||||
await signInAgain(other.page, actor, seed.sheetId)
|
await signInAgain(other.page, actor, seed.sheetId)
|
||||||
await commitText(nameFr(other.page), 'Devant')
|
await commitText(nameFr(other.page), 'Devant')
|
||||||
await saveDraft(other.page, dict, 2)
|
await saveDraft(other.page, dict, 2)
|
||||||
await other.context.close()
|
await closeSecondSession(other)
|
||||||
|
|
||||||
let release = () => {}
|
let release = () => {}
|
||||||
const gate = new Promise<void>((resolve) => (release = resolve))
|
const gate = new Promise<void>((resolve) => (release = resolve))
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { fr } from '@/i18n/fr'
|
import { fr } from '@/i18n/fr'
|
||||||
import type { Page, TestInfo } from '@playwright/test'
|
import type { Page, TestInfo } from '@playwright/test'
|
||||||
import { expect, test } from '../support/browser'
|
import { expect, test } from '../support/browser'
|
||||||
|
import { sessionAal, stepUpAdmin } from '../support/admin'
|
||||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||||
|
import { signIn } from '../support/shell'
|
||||||
import {
|
import {
|
||||||
TABS,
|
TABS,
|
||||||
closeFinding,
|
closeFinding,
|
||||||
@@ -284,4 +286,27 @@ test.describe('editor shell journeys (H)', () => {
|
|||||||
.replace('{revision}', String(seed.revision + 1))
|
.replace('{revision}', String(seed.revision + 1))
|
||||||
await expect(saveLine(page)).toHaveText(new RegExp(`^${timed}$`))
|
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')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
} from '../../../../packages/supabase/tests/sandbox/mfa'
|
} from '../../../../packages/supabase/tests/sandbox/mfa'
|
||||||
import { sql, stack } from '../../../../packages/supabase/tests/sandbox/stack'
|
import { sql, stack } from '../../../../packages/supabase/tests/sandbox/stack'
|
||||||
import { currentCode } from '../../../../packages/supabase/tests/sandbox/totp'
|
import { currentCode } from '../../../../packages/supabase/tests/sandbox/totp'
|
||||||
import { expect } from './browser'
|
import { expect, test } from './browser'
|
||||||
import type { SandboxAccount } from './sandbox'
|
import type { SandboxAccount } from './sandbox'
|
||||||
|
|
||||||
export type GrantKind =
|
export type GrantKind =
|
||||||
@@ -68,7 +68,10 @@ export async function enrolVerifiedFactor(
|
|||||||
const token = await passwordToken(account)
|
const token = await passwordToken(account)
|
||||||
const enrolment = await enrolTotp(token, name)
|
const enrolment = await enrolTotp(token, name)
|
||||||
if (!enrolment.factor) throw new Error(`sandbox enrol: ${refusal(enrolment)}`)
|
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)
|
if (verified.status !== 200)
|
||||||
throw new Error(`sandbox verify: ${refusal(verified)}`)
|
throw new Error(`sandbox verify: ${refusal(verified)}`)
|
||||||
return enrolment.factor.secret
|
return enrolment.factor.secret
|
||||||
@@ -111,12 +114,48 @@ export const stepUpHeading = (page: Page, dict: Dict) =>
|
|||||||
.getByRole('main')
|
.getByRole('main')
|
||||||
.getByRole('heading', { level: 1, name: dict['admin.step_up.title'] })
|
.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 heading = stepUpHeading(page, dict)
|
||||||
|
const main = page.getByRole('main')
|
||||||
|
const unavailable = transientFailure(main, dict)
|
||||||
await expect(heading).toBeVisible()
|
await expect(heading).toBeVisible()
|
||||||
// The gate settles its reads before the code is typed (a re-check remounts the form).
|
// The gate settles its reads before the code is typed (a re-check remounts the form).
|
||||||
await page.waitForLoadState('networkidle')
|
await page.waitForLoadState('networkidle')
|
||||||
await enterCode(page.getByRole('main'), dict, secret)
|
await enterCode(main, dict, secret)
|
||||||
await expect(heading).toBeHidden()
|
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()
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,7 @@ import { core } from './catalogue'
|
|||||||
import { parseOutcome } from '@faunosteo/core-wasm'
|
import { parseOutcome } from '@faunosteo/core-wasm'
|
||||||
import {
|
import {
|
||||||
createAccount,
|
createAccount,
|
||||||
|
dropLateReplays,
|
||||||
FAKE_SUPABASE_ORIGIN,
|
FAKE_SUPABASE_ORIGIN,
|
||||||
routeToSandbox,
|
routeToSandbox,
|
||||||
type SandboxAccount,
|
type SandboxAccount,
|
||||||
@@ -778,6 +779,18 @@ export async function secondSession(
|
|||||||
return { context, page: await context.newPage() }
|
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<void> {
|
||||||
|
await dropLateReplays(session.context)
|
||||||
|
await session.context.close()
|
||||||
|
}
|
||||||
|
|
||||||
/** The storage key of the tab's recovery copy of a draft (state/recovery.ts). */
|
/** The storage key of the tab's recovery copy of a draft (state/recovery.ts). */
|
||||||
export const copyKeyOf = (userId: string, versionId: string) =>
|
export const copyKeyOf = (userId: string, versionId: string) =>
|
||||||
`osteo:sheet-draft:${userId}:${versionId}`
|
`osteo:sheet-draft:${userId}:${versionId}`
|
||||||
|
|||||||
Reference in new issue
Block a user