From 12f2d97f0ae1dcfcc115f60799113301c708af12 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Aug 2026 04:40:25 +0000 Subject: [PATCH] =?UTF-8?q?OH14=20=E2=80=94=20fix=20offline=20e2e:=20ops-s?= =?UTF-8?q?ync=20wait,=20local=20list=20search,=20vote-pledges=20registry,?= =?UTF-8?q?=20B27=20POST=20wait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../campaign/opsSync/opsEstimateOutbox.ts | 24 ++++++++++++------- tests/e2e/campaignMunicipalities.e2e.spec.ts | 5 +++- .../e2e/campaignOpsEstimateOutbox.e2e.spec.ts | 9 +++++++ tests/e2e/campaignOpsOffline.e2e.spec.ts | 7 +++--- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/components/campaign/opsSync/opsEstimateOutbox.ts b/src/components/campaign/opsSync/opsEstimateOutbox.ts index 1c1ee164..e656d8e9 100644 --- a/src/components/campaign/opsSync/opsEstimateOutbox.ts +++ b/src/components/campaign/opsSync/opsEstimateOutbox.ts @@ -1,6 +1,6 @@ 'use client' -import { createCollection, localOnlyCollectionOptions } from '@tanstack/db' +import { createCollection, localOnlyCollectionOptions, type Transaction } from '@tanstack/db' import { IndexedDBAdapter, NonRetriableError, @@ -19,6 +19,7 @@ import { applyOpsVotePledgeEstimateWrite, patchOpsVotePledgeEstimateOptimistic, readOpsVotePledge, + votePledgesCollection, } from '@/components/campaign/opsSync/opsVotePledgeMirror' import { opsOutboxKey, type OpsOutboxKey } from '@/lib/campaignOps/opsContract' import { @@ -28,6 +29,14 @@ import { const ESTIMATE_MUTATION_FN = 'estimateVotes' +const outboxMutationRow = (transaction: Transaction, collectionId: string): TRow => { + const mutation = transaction.mutations.find((entry) => entry.collection?.id === collectionId) + if (!mutation) { + throw new NonRetriableError(`Mutação de outbox ausente (${collectionId}).`) + } + return mutation.modified as TRow +} + const opsEstimateOutboxCollection = createCollection( localOnlyCollectionOptions({ id: 'ops-estimate-outbox', @@ -40,17 +49,16 @@ let initPromise: Promise | null = null const createEstimateOfflineExecutor = (): OfflineExecutor => startOfflineExecutor({ - collections: { estimateOutbox: opsEstimateOutboxCollection }, + collections: { + estimateOutbox: opsEstimateOutboxCollection, + // Mirror rows touched in onMutate must be registered for persistence. + votePledges: votePledgesCollection, + }, storage: new IndexedDBAdapter('teqo-ops-estimate', 'outbox'), beforeRetry: collapseEstimateOutboxByPledge, mutationFns: { [ESTIMATE_MUTATION_FN]: async ({ transaction }) => { - const mutation = transaction.mutations[0] - if (!mutation) { - throw new NonRetriableError('Mutação de estimativa vazia.') - } - - const row = mutation.modified as OpsEstimateOutboxRow + const row = outboxMutationRow(transaction, 'ops-estimate-outbox') try { const updated = await estimateVotesCas({ diff --git a/tests/e2e/campaignMunicipalities.e2e.spec.ts b/tests/e2e/campaignMunicipalities.e2e.spec.ts index 64b5e9b6..769b5a22 100644 --- a/tests/e2e/campaignMunicipalities.e2e.spec.ts +++ b/tests/e2e/campaignMunicipalities.e2e.spec.ts @@ -163,7 +163,10 @@ test.describe('Municípios — jornadas por papel', () => { // no-op, so the probe retries until the chip sticks. await expect(async () => { await search.fill(searchNamePart) - await option.click({ timeout: 1_000 }) + await Promise.all([ + expectPostResponse(page, '/campanha/municipios'), + option.click({ timeout: 1_000 }), + ]) await expect(chip).toBeVisible({ timeout: 4_000 }) }).toPass({ timeout: 20_000 }) diff --git a/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts b/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts index 56c35adb..88436948 100644 --- a/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts +++ b/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts @@ -1,5 +1,8 @@ import { expect, test } from './fixtures/campaignE2EFixtures.js' +/** Offline specs intentionally hit blocked network resources — allowlist for the guard. */ +test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] }) + /** OH6 — flaky-network outbox for estimateVotes. */ test.describe('OH6 estimate outbox', () => { test('offline edit stays queued across reload and flushes when online', async ({ @@ -37,6 +40,12 @@ test.describe('OH6 estimate outbox', () => { await campaign.login(page, advisor.email!, advisor.password) await page.goto(`${campaign.baseURL}/campanha/municipios/${municipality.slug}`) + await page.waitForResponse( + (response) => + response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET', + { timeout: 30_000 }, + ) + await page.context().setOffline(true) await page.getByLabel('Média', { exact: true }).fill('55') await page.getByLabel('Justificativa').fill('Editado na estrada.') diff --git a/tests/e2e/campaignOpsOffline.e2e.spec.ts b/tests/e2e/campaignOpsOffline.e2e.spec.ts index 34f75d0e..1d0b47c9 100644 --- a/tests/e2e/campaignOpsOffline.e2e.spec.ts +++ b/tests/e2e/campaignOpsOffline.e2e.spec.ts @@ -1,5 +1,8 @@ import { expect, test } from './fixtures/campaignE2EFixtures.js' +/** Offline specs intentionally hit blocked network resources — allowlist for the guard. */ +test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] }) + /** OH9/OH11/OH12 — dual-path municipality detail + offline journey + list Local. */ test.describe('OH9/OH11 campaign ops offline', () => { test('offline swaps to Local header + pledges with honest online-only placeholder', async ({ @@ -141,9 +144,7 @@ test.describe('OH12 municipality list Local', () => { ) await page.context().setOffline(true) - await page.goto( - `${campaign.baseURL}/campanha/municipios?q=${encodeURIComponent(municipality.name)}`, - ) + await page.getByLabel('Buscar município').fill(municipality.name) await expect(page.getByRole('heading', { name: 'Municípios' })).toBeVisible() await expect(