fix(web): preserve saved writes across refresh failures

This commit is contained in:
2026-07-22 13:13:03 +08:00
parent 7980943660
commit 89d2f4659f
11 changed files with 304 additions and 74 deletions

View File

@@ -0,0 +1,41 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { executeSavedMutation } from '../src/app/mutation-refresh.ts'
test('a saved mutation stays successful when its refresh fails', async () => {
const events = []
const refreshFailure = new Error('refresh unavailable')
const outcome = await executeSavedMutation({
mutate: async () => {
events.push('mutate')
return { id: 'created-1' }
},
onSaved: (value) => events.push(`saved:${value.id}`),
refresh: async (value) => {
events.push(`refresh:${value.id}`)
throw refreshFailure
},
})
assert.deepEqual(events, ['mutate', 'saved:created-1', 'refresh:created-1'])
assert.equal(outcome.value.id, 'created-1')
assert.equal(outcome.refreshError, refreshFailure)
})
test('a failed mutation does not close its draft or attempt a refresh', async () => {
const events = []
const mutationFailure = new Error('save rejected')
await assert.rejects(() => executeSavedMutation({
mutate: async () => {
events.push('mutate')
throw mutationFailure
},
onSaved: () => events.push('saved'),
refresh: async () => events.push('refresh'),
}), mutationFailure)
assert.deepEqual(events, ['mutate'])
})