From fa16a5be44a9519c8d081d7301a57ddf44c465b4 Mon Sep 17 00:00:00 2001 From: le king fu Date: Sat, 24 Oct 2026 17:17:26 -0400 Subject: [PATCH] test(sync): lock refusal replay and marked ids of the push A refused operation replayed with the same idempotency key must come back skipped with an error again (otherwise the app marks it synced and loses it), and pushChanges must mark only the ids kept by classifyOutbox. Both gaps were found by reviewer mutations on PR #159. Refs #151 Co-Authored-By: Claude Opus 5.5 --- tests/smoke.test.cjs | 2 ++ web/src/app/api/sync/route.test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/smoke.test.cjs b/tests/smoke.test.cjs index e28fb93..a85a1d2 100644 --- a/tests/smoke.test.cjs +++ b/tests/smoke.test.cjs @@ -221,6 +221,8 @@ check('syncClient.ts passes the #151 push bounds to sendInBatches', () => { assert.match(merge, /size: BATCH_SIZE,/); assert.match(body('pushChanges'), /\.orderBy\(asc\(syncOutbox\.createdAt\)\)/); assert.match(body('pushChanges'), /classifyOutbox\(unsynced, results,/); + // Only the ids kept by classifyOutbox are marked, never the whole outbox. + assert.match(body('pushChanges'), /\.where\(inArray\(syncOutbox\.id, markIds\)\)/); // Number(null) is 0: a missing Retry-After must go through parseRetryAfter assert.match(src, /retryAfter: parseRetryAfter\(res\.headers\.get\('Retry-After'\)\)/); }); diff --git a/web/src/app/api/sync/route.test.ts b/web/src/app/api/sync/route.test.ts index 46f9c43..c90b828 100644 --- a/web/src/app/api/sync/route.test.ts +++ b/web/src/app/api/sync/route.test.ts @@ -525,4 +525,19 @@ describe('POST /api/sync: results contract (#151)', () => { expect(typeof result.error).toBe('string'); expect((result.error as string).length).toBeGreaterThan(0); }); + + it('answers a refused operation replayed with the same key skipped with an error again', async () => { + // The app replays a refusal with its outbox id as key. If the server + // remembered the key of a refused operation, the replay would come back + // `skipped` without `error` and the app would mark it synced: lost. + const { A, B } = await seed(); + const op = { idempotencyKey: u(), entityType: 'taskTag', action: 'create', entityId: A.task, data: { tagId: B.tag } }; + const [first] = await raw(B.userId, [op]); + expect(first.status).toBe('skipped'); + expect(typeof first.error).toBe('string'); + const [replay] = await raw(B.userId, [op]); + expect(replay.status).toBe('skipped'); + expect(typeof replay.error).toBe('string'); + expect((replay.error as string).length).toBeGreaterThan(0); + }); });