Files
orca/src/main/runtime/runtime-worktree-create-git.test.ts
T
Brennan Benson 30909c77dd perf(worktrees): fetch the base while the host's create picks a name (#26007)
* perf(worktrees): look up a branch's PR only after a name collision on the host's create

The host's create (agent.launch, worktree.create, the phone and the CLI) called gh pr list for every
create, a 1-3 s network round trip, while the desktop create probes only after a branch collision. A
branch with an open PR exists on the remote, so the branch-conflict check already moves past it.

* test(worktrees): pin first-name PR lookup skip on the host's create

The runtime service specs still expected a PR lookup for a free first
name. Update them to the desktop-parity behavior: no lookup without a
branch collision, and a free push-target name is kept. Pin the exact
suffixed name, and that a later name with a PR is skipped.

* perf(worktrees): overlap the host create's base fetch with naming

Keep the first-name PR lookup (restores main's naming) and take it off
the critical path instead: start the base-ref refresh before naming and
await it after, as the desktop create does, so the lookup and the fetch
run concurrently. A refresh rejection while naming fails stays handled.

* test(worktrees): pin the overlapped origin fetch on the host's create

Cover the best-effort fetch origin path: it runs while the first-name PR
lookup is pending, and its rejection while naming fails stays handled.
2026-10-13 21:27:34 -07:00

33 lines
1.0 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import type * as GitHubClient from '../github/client'
const getPRForBranchMock = vi.hoisted(() => vi.fn())
vi.mock('../github/client', async (importOriginal) => ({
...(await importOriginal<typeof GitHubClient>()),
getPRForBranch: getPRForBranchMock
}))
import { getLocalGitHubPrForBranch } from './runtime-worktree-create-git'
beforeEach(() => {
getPRForBranchMock.mockReset()
getPRForBranchMock.mockResolvedValue(null)
})
describe('getLocalGitHubPrForBranch', () => {
it('routes the PR lookup through the WSL distro', async () => {
await getLocalGitHubPrForBranch('/repo', 'app', { wslDistro: 'Ubuntu' })
expect(getPRForBranchMock).toHaveBeenCalledWith('/repo', 'app', null, null, null, {
localGitExecOptions: { wslDistro: 'Ubuntu' }
})
})
it('uses the plain lookup without project git options', async () => {
await getLocalGitHubPrForBranch('/repo', 'app', {})
expect(getPRForBranchMock).toHaveBeenCalledWith('/repo', 'app')
})
})