express · Hard · idempotency
A production API needs a idempotent workflow journal repair at its service boundary. A board supports several rapid card moves. When one request fails, the current implementation restores the entire old board and erases later confirmed moves.
Task
Implement the idempotent workflow journal contract used by the supplied HTTP adapter. Reconcile move intents independently so failure restores only the affected intent while later confirmed order remains.
Contract
Input is {initialIds,events}. move has intentId,id,toIndex; success and failure have intentId. Return {ids,pending,failed}. Indices are clamped.
Acceptance criteria
- Apply each move immediately.
- Track the prior neighbor anchors for each intent.
- Success removes only that intent.
- Failure removes that move effect without discarding later intents.
- Return a deterministic JSON-serializable result for the HTTP adapter.
Constraints
- Do not mutate caller-owned input.
- Keep the supplied framework adapter and public contract unchanged.
- Add candidate tests for at least one boundary not covered by the public cases.
Editable files
src/repair.js— Task-specific state or service boundarytests/candidate.test.js— Candidate-authored regression