From 973fc4a9d4c3b237ada05c0aa80bd2fd78b249cc Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:43:27 -0800 Subject: [PATCH] test(mobile): a folder create resent after a lost reply carries the same mutation id --- .../folder-repo-worktree-create.test.ts | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/mobile/src/source-control/folder/folder-repo-worktree-create.test.ts b/mobile/src/source-control/folder/folder-repo-worktree-create.test.ts index 5a445734a04..2030ab10c00 100644 --- a/mobile/src/source-control/folder/folder-repo-worktree-create.test.ts +++ b/mobile/src/source-control/folder/folder-repo-worktree-create.test.ts @@ -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')