mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-26 21:53:06 +00:00
Merge pull request #6 from fsolla/cursor/p4-e2e-navigation-guards-78a7
Miss #53 + #54 guardrails: WebAuthn readiness gate + unsettled goto→goto guard
This commit is contained in:
commit
faed14b214
4 changed files with 112 additions and 2 deletions
|
|
@ -12,6 +12,8 @@ CI (`.github/workflows/ci-pr.yml`) runs parallel jobs — lint (zero warnings),
|
|||
|
||||
**Local e2e before push (same blast radius as PR CI):** `pnpm test:e2e:affected` — runs `e2e-affected.mjs` against `origin/stage`, migrates/seeds, then `pnpm test:e2e` with the selected specs (or the full suite on high-risk diffs). Forward extra Playwright args after `--` for a narrowed repro. Opt into production mode (after fixing the known municipalities-list prod client bug) with `E2E_PROD=1 pnpm test:e2e:affected`.
|
||||
|
||||
**Navigation discipline in e2e (miss #54, 2026-07-30):** `page.goto` is for cold loads and URL contracts (deep links, redirects, legacy params); when the scenario is _continuity inside the authenticated shell_ — especially after a heavy list route — navigate in-shell instead (sidebar links, buttons, form submits), the way the user does. Never fire two `page.goto` back-to-back with nothing settling the first navigation (an `await expect(...)`, `waitForURL`, or interaction): the second aborts the first's in-flight RSC fetch (`net::ERR_ABORTED`, measured in `campaignSavedFilters`). The `e2eNavigationConventions` unit guard fails the build on unsettled goto pairs. Two sibling rules of the same family: wait for **interactive state** before clicking dynamic controls — `toBeVisible` proves SSR paint, not hydration (pre-hydration clicks no-op silently; `checkRadixWhenHydrated` is the precedent, P3-C class) — and gate WebAuthn ceremonies on `expectCampaignBiometricsReady` before the island's one-shot probe runs (miss #53). **Dev-mode caveat:** `campaignLeaderships`' chip-cell spec currently fails deterministically under `pnpm dev` (suggestion/commit step; prod build green — run it with `E2E_PROD=1` locally; ledgered in TECH-DEBT).
|
||||
|
||||
## Minimal test database (`pnpm db:seed:minimal`)
|
||||
|
||||
The integration suite and any agent/Cloud environment boot from a **minimal synthetic database**: schema from `pnpm migrate` (which seeds the 435-município catalog) plus `pnpm db:seed:minimal` ([`scripts/seed-minimal.mjs`](../scripts/seed-minimal.mjs)), an idempotent upsert of the rows the app refuses to run without:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import type { BrowserContext, Page } from '@playwright/test'
|
|||
|
||||
import { CAMPAIGN_SESSION_TTL_LONG } from '../../src/lib/campaignSessionTtl.js'
|
||||
import { CAMPAIGN_BIOMETRICS_PROMPT_DISMISSED_KEY } from '../../src/utilities/campaignBiometricsPrompt.js'
|
||||
import { expect, test } from './fixtures/campaignE2EFixtures.js'
|
||||
import { expect, expectCampaignBiometricsReady, test } from './fixtures/campaignE2EFixtures.js'
|
||||
|
||||
/**
|
||||
* Biometric login (B40) end to end, against a **virtual authenticator** driven
|
||||
|
|
@ -68,8 +68,10 @@ test('enrolls a passkey, signs in with it, then revokes it', async ({
|
|||
await addVirtualAuthenticator(context, page)
|
||||
|
||||
// 1. Enrollment is authenticated: the passkey card only exists behind a
|
||||
// password login.
|
||||
// password login. The platform answer is gated BEFORE the profile island
|
||||
// runs its one-shot probe (miss #53).
|
||||
await campaign.login(page, email, password)
|
||||
await expectCampaignBiometricsReady(page)
|
||||
await page.goto('/campanha/perfil')
|
||||
|
||||
await expect(page.getByText('Nenhum aparelho cadastrado ainda.')).toBeVisible()
|
||||
|
|
@ -86,6 +88,7 @@ test('enrolls a passkey, signs in with it, then revokes it', async ({
|
|||
// the "remember me" opt-in, so there is no checkbox in this path.
|
||||
await context.clearCookies()
|
||||
await page.goto('/campanha/login')
|
||||
await expectCampaignBiometricsReady(page)
|
||||
const biometricButton = page.getByRole('button', { name: 'Entrar com digital ou Face ID' })
|
||||
await expect(biometricButton).toBeVisible()
|
||||
|
||||
|
|
|
|||
|
|
@ -474,6 +474,25 @@ export const checkRadixWhenHydrated = async (page: Page, label: string) => {
|
|||
}).toPass({ timeout: 15_000 })
|
||||
}
|
||||
|
||||
/**
|
||||
* Miss #53: the app's biometrics probe is ONE-SHOT per island mount
|
||||
* (`useCampaignBiometricsAvailable`) — if
|
||||
* `isUserVerifyingPlatformAuthenticatorAvailable()` resolves before the CDP
|
||||
* virtual authenticator is ready, the enrollment form / biometric button
|
||||
* never mount and no amount of waiting flips them. Gate the ceremony on the
|
||||
* platform answer BEFORE navigating into the surface whose island probes it,
|
||||
* so the race is decided before the app even asks. Requires a loaded page
|
||||
* (secure context) — call after `campaign.login` / `page.goto`.
|
||||
*/
|
||||
export const expectCampaignBiometricsReady = async (page: Page): Promise<void> => {
|
||||
await expect(async () => {
|
||||
const available = await page.evaluate(
|
||||
() => window.PublicKeyCredential?.isUserVerifyingPlatformAuthenticatorAvailable?.() ?? false,
|
||||
)
|
||||
expect(available).toBe(true)
|
||||
}).toPass({ timeout: 15_000 })
|
||||
}
|
||||
|
||||
type CampaignE2EFixture = {
|
||||
baseURL: string
|
||||
fixtures: CampaignE2EOwnership
|
||||
|
|
|
|||
86
tests/unit/e2eNavigationConventions.unit.spec.ts
Normal file
86
tests/unit/e2eNavigationConventions.unit.spec.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import { readdirSync, readFileSync } from 'node:fs'
|
||||
import { relative, resolve } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
// Miss #54 (2026-07-30): a `page.goto` fired while the previous heavy RSC
|
||||
// navigation was still in flight aborted with `net::ERR_ABORTED`
|
||||
// (campaignSavedFilters, prod build). `goto` stays legal for cold loads and
|
||||
// URL contracts — the anti-pattern is two gotos with NOTHING between them
|
||||
// that settles the first navigation. A settle is any awaited interaction
|
||||
// with the landed page (assertion, fill, click, reload, login…): it proves
|
||||
// the previous route rendered before the next one starts.
|
||||
//
|
||||
// Miss #53 (2026-07-30): the biometrics probe is one-shot per island mount,
|
||||
// so a ceremony that starts before the CDP virtual authenticator answers
|
||||
// never sees the enrollment UI. Specs registering a virtual authenticator
|
||||
// must gate on `expectCampaignBiometricsReady` first.
|
||||
|
||||
const e2eRoot = resolve(process.cwd(), 'tests/e2e')
|
||||
|
||||
const specFiles = readdirSync(e2eRoot, { recursive: true, withFileTypes: true })
|
||||
.filter((entry) => entry.isFile() && entry.name.endsWith('.e2e.spec.ts'))
|
||||
.map((entry) => resolve(entry.parentPath, entry.name))
|
||||
|
||||
const SETTLE_TOKENS = [
|
||||
'await expect(',
|
||||
'waitForURL(',
|
||||
'.click(',
|
||||
'.check(',
|
||||
'.fill(',
|
||||
'.press(',
|
||||
'.hover(',
|
||||
'clearCookies(',
|
||||
'.reload(',
|
||||
'campaign.login(',
|
||||
'.catch(',
|
||||
'await request.',
|
||||
'checkRadixWhenHydrated(',
|
||||
'expectCampaignBiometricsReady(',
|
||||
] as const
|
||||
|
||||
describe('e2e navigation discipline (miss #54)', () => {
|
||||
it('never fires two page.goto without settling the first navigation', () => {
|
||||
const offenders: string[] = []
|
||||
|
||||
for (const file of specFiles) {
|
||||
const lines = readFileSync(file, 'utf8').split('\n')
|
||||
let lastGoto: number | null = null
|
||||
let settledSince = false
|
||||
|
||||
for (const [index, line] of lines.entries()) {
|
||||
if (SETTLE_TOKENS.some((token) => line.includes(token))) settledSince = true
|
||||
if (!line.includes('page.goto(')) continue
|
||||
if (lastGoto !== null && !settledSince) {
|
||||
offenders.push(
|
||||
`${relative(process.cwd(), file)}:${index + 1} (goto at ${lastGoto + 1} unsettled)`,
|
||||
)
|
||||
}
|
||||
lastGoto = index
|
||||
settledSince = false
|
||||
}
|
||||
}
|
||||
|
||||
expect(
|
||||
offenders,
|
||||
'settle the first navigation (await expect/waitForURL/click…) before the next page.goto, or navigate in-shell (miss #54)',
|
||||
).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('e2e WebAuthn virtual authenticator (miss #53)', () => {
|
||||
it('gates every virtual-authenticator spec on expectCampaignBiometricsReady', () => {
|
||||
const offenders: string[] = []
|
||||
|
||||
for (const file of specFiles) {
|
||||
const source = readFileSync(file, 'utf8')
|
||||
if (!source.includes('WebAuthn.addVirtualAuthenticator')) continue
|
||||
if (source.includes('expectCampaignBiometricsReady(')) continue
|
||||
offenders.push(relative(process.cwd(), file))
|
||||
}
|
||||
|
||||
expect(
|
||||
offenders,
|
||||
'call expectCampaignBiometricsReady(page) before the surface whose island probes the authenticator',
|
||||
).toEqual([])
|
||||
})
|
||||
})
|
||||
Loading…
Reference in a new issue