test(mobile): a folder create resent after a lost reply carries the same mutation id

This commit is contained in:
Brennan Benson
2026-11-08 21:43:27 -08:00
parent c917f245e5
commit 973fc4a9d4
@@ -11,8 +11,14 @@ import {
type FolderRepoTarget
} from './folder-repo-worktree-create'
const idempotency = vi.hoisted(() => {
const state: { support: { dedupeTtlMs: number } | false } = { support: false }
return state
})
vi.mock('../../tasks/worktree-create-capability', () => ({
readNewWorktreeRuntimeCapabilities: async () => ({ worktreeCreateIdempotency: false })
readNewWorktreeRuntimeCapabilities: async () => ({
worktreeCreateIdempotency: idempotency.support
})
}))
const FOLDER = 'folder:f-1'
@@ -20,6 +26,7 @@ const TAKEN = 'Branch payments already exists\nworktree_create_exact_name_taken'
afterEach(() => {
vi.useRealTimers()
idempotency.support = false
})
let repoCount = 0
@@ -125,6 +132,29 @@ describe('createFolderRepoWorktree', () => {
})
})
describe('createFolderRepoWorktree after a lost reply on a host that dedupes', () => {
it.each([
['answers with the worktree', CREATED, { kind: 'created', name: 'payments' }],
['refuses the name as taken', refused(TAKEN), { kind: 'maybe-created' }]
])('resends the same create once reconnected; the host %s', async (_case, replay, expected) => {
idempotency.support = { dedupeTtlMs: 60_000 }
const repo = target()
const client = new FakeSession('connected')
client.sendRequest
.mockImplementationOnce(async () => {
client.publishState('reconnecting')
setTimeout(() => client.publishState('connected'), 0)
throw markRpcDeliveryUnknown(new Error('connection lost'))
})
.mockResolvedValueOnce(replay)
await expect(create(repo, client)).resolves.toEqual(expected)
const [first, second] = client.sendRequest.mock.calls.map(([, params]) => params)
expect(second).toEqual(first)
expect(first).toHaveProperty('clientMutationId')
})
})
describe('reconcileFolderRepoCreates', () => {
it('forgets a create once the folder lists its worktree on the same host, not another', async () => {
const repo = target('runtime:env-1')