OH14 — fix offline e2e: ops-sync wait, local list search, vote-pledges registry, B27 POST wait

This commit is contained in:
Cursor Agent 2026-08-02 04:40:25 +00:00
parent d6d3089f7d
commit 12f2d97f0a
No known key found for this signature in database
4 changed files with 33 additions and 12 deletions

View file

@ -1,6 +1,6 @@
'use client' 'use client'
import { createCollection, localOnlyCollectionOptions } from '@tanstack/db' import { createCollection, localOnlyCollectionOptions, type Transaction } from '@tanstack/db'
import { import {
IndexedDBAdapter, IndexedDBAdapter,
NonRetriableError, NonRetriableError,
@ -19,6 +19,7 @@ import {
applyOpsVotePledgeEstimateWrite, applyOpsVotePledgeEstimateWrite,
patchOpsVotePledgeEstimateOptimistic, patchOpsVotePledgeEstimateOptimistic,
readOpsVotePledge, readOpsVotePledge,
votePledgesCollection,
} from '@/components/campaign/opsSync/opsVotePledgeMirror' } from '@/components/campaign/opsSync/opsVotePledgeMirror'
import { opsOutboxKey, type OpsOutboxKey } from '@/lib/campaignOps/opsContract' import { opsOutboxKey, type OpsOutboxKey } from '@/lib/campaignOps/opsContract'
import { import {
@ -28,6 +29,14 @@ import {
const ESTIMATE_MUTATION_FN = 'estimateVotes' const ESTIMATE_MUTATION_FN = 'estimateVotes'
const outboxMutationRow = <TRow>(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( const opsEstimateOutboxCollection = createCollection(
localOnlyCollectionOptions<OpsEstimateOutboxRow, number>({ localOnlyCollectionOptions<OpsEstimateOutboxRow, number>({
id: 'ops-estimate-outbox', id: 'ops-estimate-outbox',
@ -40,17 +49,16 @@ let initPromise: Promise<OfflineExecutor> | null = null
const createEstimateOfflineExecutor = (): OfflineExecutor => const createEstimateOfflineExecutor = (): OfflineExecutor =>
startOfflineExecutor({ 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'), storage: new IndexedDBAdapter('teqo-ops-estimate', 'outbox'),
beforeRetry: collapseEstimateOutboxByPledge, beforeRetry: collapseEstimateOutboxByPledge,
mutationFns: { mutationFns: {
[ESTIMATE_MUTATION_FN]: async ({ transaction }) => { [ESTIMATE_MUTATION_FN]: async ({ transaction }) => {
const mutation = transaction.mutations[0] const row = outboxMutationRow<OpsEstimateOutboxRow>(transaction, 'ops-estimate-outbox')
if (!mutation) {
throw new NonRetriableError('Mutação de estimativa vazia.')
}
const row = mutation.modified as OpsEstimateOutboxRow
try { try {
const updated = await estimateVotesCas({ const updated = await estimateVotesCas({

View file

@ -163,7 +163,10 @@ test.describe('Municípios — jornadas por papel', () => {
// no-op, so the probe retries until the chip sticks. // no-op, so the probe retries until the chip sticks.
await expect(async () => { await expect(async () => {
await search.fill(searchNamePart) 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 }) await expect(chip).toBeVisible({ timeout: 4_000 })
}).toPass({ timeout: 20_000 }) }).toPass({ timeout: 20_000 })

View file

@ -1,5 +1,8 @@
import { expect, test } from './fixtures/campaignE2EFixtures.js' 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. */ /** OH6 — flaky-network outbox for estimateVotes. */
test.describe('OH6 estimate outbox', () => { test.describe('OH6 estimate outbox', () => {
test('offline edit stays queued across reload and flushes when online', async ({ 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 campaign.login(page, advisor.email!, advisor.password)
await page.goto(`${campaign.baseURL}/campanha/municipios/${municipality.slug}`) 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.context().setOffline(true)
await page.getByLabel('Média', { exact: true }).fill('55') await page.getByLabel('Média', { exact: true }).fill('55')
await page.getByLabel('Justificativa').fill('Editado na estrada.') await page.getByLabel('Justificativa').fill('Editado na estrada.')

View file

@ -1,5 +1,8 @@
import { expect, test } from './fixtures/campaignE2EFixtures.js' 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. */ /** OH9/OH11/OH12 — dual-path municipality detail + offline journey + list Local. */
test.describe('OH9/OH11 campaign ops offline', () => { test.describe('OH9/OH11 campaign ops offline', () => {
test('offline swaps to Local header + pledges with honest online-only placeholder', async ({ 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.context().setOffline(true)
await page.goto( await page.getByLabel('Buscar município').fill(municipality.name)
`${campaign.baseURL}/campanha/municipios?q=${encodeURIComponent(municipality.name)}`,
)
await expect(page.getByRole('heading', { name: 'Municípios' })).toBeVisible() await expect(page.getByRole('heading', { name: 'Municípios' })).toBeVisible()
await expect( await expect(