OH14 — e2e: offline RSC guard allowlist + strict-mode flakes

- Extend failure guard with path prefixes and RSC prefetch allowance
- Scope WebAuthn empty-state to main; territories use .first()
This commit is contained in:
Cursor Agent 2026-08-02 05:04:05 +00:00
parent 35c5ffd990
commit 512776314b
No known key found for this signature in database
5 changed files with 56 additions and 15 deletions

View file

@ -6,7 +6,11 @@ import {
} from './fixtures/campaignE2EFixtures.js'
/** Offline specs intentionally hit blocked network resources — allowlist for the guard. */
test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] })
test.use({
expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'],
expectedRequestFailurePathPrefixes: ['/campanha'],
allowOfflineRscPrefetchErrors: true,
})
/** OH6 — flaky-network outbox for estimateVotes. */
test.describe('OH6 estimate outbox', () => {

View file

@ -6,7 +6,11 @@ import {
} from './fixtures/campaignE2EFixtures.js'
/** Offline specs intentionally hit blocked network resources — allowlist for the guard. */
test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] })
test.use({
expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'],
expectedRequestFailurePathPrefixes: ['/campanha'],
allowOfflineRscPrefetchErrors: true,
})
/** OH9/OH11/OH12 — dual-path municipality detail + offline journey + list Local. */
test.describe('OH9/OH11 campaign ops offline', () => {

View file

@ -40,11 +40,11 @@ test.describe('Territórios de Identidade', () => {
await campaign.login(page, coordinator.email!, coordinator.password)
await page.goto('/campanha/territorios')
await expect(page.getByText(/27 territórios encontrados/)).toBeVisible()
await expect(page.getByText(/27 territórios encontrados/).first()).toBeVisible()
await page.getByRole('link', { name: 'Ir para a página 2' }).click()
await expect(page).toHaveURL(/\/campanha\/territorios\?page=2/)
await expect(page.getByText(/27 territórios encontrados/)).toBeVisible()
await expect(page.getByText(/27 territórios encontrados/).first()).toBeVisible()
})
test('parent territory rows expose hash anchor ids for deep links', async ({
@ -61,8 +61,8 @@ test.describe('Territórios de Identidade', () => {
await campaign.login(page, email, password)
await page.goto('/campanha/territorios')
await expect(page.locator('#ti-irece')).toBeVisible()
await expect(page.locator('#ti-velho-chico')).toBeVisible()
await expect(page.locator('#ti-irece').first()).toBeVisible()
await expect(page.locator('#ti-velho-chico').first()).toBeVisible()
})
test('leader cannot open the territories page', async ({ campaign, page }) => {

View file

@ -74,7 +74,7 @@ test('enrolls a passkey, signs in with it, then revokes it', async ({
await expectCampaignBiometricsReady(page)
await page.goto('/campanha/perfil')
await expect(page.getByText('Nenhum aparelho cadastrado ainda.')).toBeVisible()
await expect(page.getByRole('main').getByText('Nenhum aparelho cadastrado ainda.')).toBeVisible()
const deviceLabel = page.getByLabel('Nome deste aparelho')
await expect(deviceLabel).toBeVisible()
@ -82,7 +82,7 @@ test('enrolls a passkey, signs in with it, then revokes it', async ({
await page.getByRole('button', { name: 'Ativar neste aparelho' }).click()
await expect(page.getByText('Celular da assessora')).toBeVisible({ timeout: CEREMONY_TIMEOUT })
await expect(page.getByText('Nenhum aparelho cadastrado ainda.')).toBeHidden()
await expect(page.getByRole('main').getByText('Nenhum aparelho cadastrado ainda.')).toBeHidden()
// 2. Password-less sign-in issues the 14-day cookie — enrolling the device IS
// the "remember me" opt-in, so there is no checkbox in this path.
@ -103,7 +103,7 @@ test('enrolls a passkey, signs in with it, then revokes it', async ({
// the profile and it has to actually stop the credential.
await page.goto('/campanha/perfil')
await page.getByRole('button', { name: 'Remover Celular da assessora' }).click()
await expect(page.getByText('Nenhum aparelho cadastrado ainda.')).toBeVisible()
await expect(page.getByRole('main').getByText('Nenhum aparelho cadastrado ainda.')).toBeVisible()
await context.clearCookies()
await page.goto('/campanha/login')

View file

@ -27,6 +27,10 @@ type E2EFailureGuardFixtures = {
* mid-test.
*/
expectedRequestFailurePaths: string[]
/** Pathname prefix allowlist for intentional offline prefetch failures. */
expectedRequestFailurePathPrefixes: string[]
/** Next.js RSC prefetch console noise while the browser context is offline. */
allowOfflineRscPrefetchErrors: boolean
}
const loadFailurePrefix = 'Failed to load resource'
@ -49,6 +53,8 @@ const isAllowedConsoleError = (
message: ConsoleMessage,
origin: string | null,
expectedRequestFailurePaths: string[],
expectedRequestFailurePathPrefixes: string[],
allowOfflineRscPrefetchErrors: boolean,
): boolean => {
const { url } = message.location()
if (!url || origin === null) return false
@ -59,23 +65,50 @@ const isAllowedConsoleError = (
// The app intentionally has no /favicon.ico asset yet.
if (message.text() === missingFaviconConsoleError) return location.pathname === '/favicon.ico'
return (
message.text().startsWith(loadFailurePrefix) &&
expectedRequestFailurePaths.includes(location.pathname)
)
if (
allowOfflineRscPrefetchErrors &&
message.text().includes('Failed to fetch RSC payload') &&
message.text().includes('/campanha')
) {
return true
}
const pathAllowed =
expectedRequestFailurePaths.includes(location.pathname) ||
expectedRequestFailurePathPrefixes.some((prefix) => location.pathname.startsWith(prefix))
return message.text().startsWith(loadFailurePrefix) && pathAllowed
}
export const test = base.extend<E2EFailureGuardFixtures>({
expectedRequestFailurePaths: [[], { option: true }],
expectedRequestFailurePathPrefixes: [[], { option: true }],
allowOfflineRscPrefetchErrors: [false, { option: true }],
e2eFailureGuard: [
async ({ baseURL, context, expectedRequestFailurePaths, page }, use) => {
async (
{
baseURL,
context,
expectedRequestFailurePaths,
expectedRequestFailurePathPrefixes,
allowOfflineRscPrefetchErrors,
page,
},
use,
) => {
const failures: BrowserFailure[] = []
const origin = baseURL ? new URL(baseURL).origin : null
const onConsole = (message: ConsoleMessage) => {
if (
message.type() !== 'error' ||
isAllowedConsoleError(message, origin, expectedRequestFailurePaths)
isAllowedConsoleError(
message,
origin,
expectedRequestFailurePaths,
expectedRequestFailurePathPrefixes,
allowOfflineRscPrefetchErrors,
)
) {
return
}