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 <noreply@anthropic.com>
This commit is contained in:
parent
a65d72b7a0
commit
fa16a5be44
2 changed files with 17 additions and 0 deletions
|
|
@ -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'\)\)/);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue