mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* Support explicit remote branch reuse across workspaces - Preserve selected branch identity, tracking, and busy-branch handling - Add explicit branch-off intent with v2 runtime capability gating * Style existing workspace action in branch reuse UI * Preserve explicit branch reuse with versioned host support - Gate strict reuse on a new request capability while retaining legacy behavior - Warn when a reused remote branch cannot be configured as the push upstream * Clarify selected branch checkout options * Offer existing or new branch choices for worktrees * Preserve new-branch intent when reusing a branch name * Adapt branch composer tests and catalog after rebase * Refresh mobile RPC recordings for branch intent capabilities * Remove retired Russian localization entries * Remove retired German and Turkish localization entries * Add branch selection translations for existing workspaces * Localize mobile worktree branch selection
113 lines
3.9 KiB
TypeScript
113 lines
3.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import type * as GitHubClient from '../github/client'
|
|
|
|
const getPRForBranchMock = vi.hoisted(() => vi.fn())
|
|
const git = vi.hoisted(() => vi.fn())
|
|
const worktrees = vi.hoisted(() => vi.fn())
|
|
vi.mock('../git/runner', () => ({ gitExecFileAsync: git }))
|
|
vi.mock('../git/worktree', () => ({ listWorktrees: worktrees }))
|
|
|
|
vi.mock('../github/client', async (importOriginal) => ({
|
|
...(await importOriginal<typeof GitHubClient>()),
|
|
getPRForBranch: getPRForBranchMock
|
|
}))
|
|
|
|
import {
|
|
canCheckoutExistingLocalBranch,
|
|
getLocalGitHubPrForBranch
|
|
} from './runtime-worktree-create-git'
|
|
|
|
beforeEach(() => {
|
|
getPRForBranchMock.mockReset()
|
|
getPRForBranchMock.mockResolvedValue(null)
|
|
git.mockReset()
|
|
worktrees.mockReset()
|
|
})
|
|
|
|
describe('explicit local branch reuse on the execution host', () => {
|
|
it('routes all probes through the WSL distro and does not compare or reset the remote tip', async () => {
|
|
git.mockResolvedValueOnce({ stdout: 'local-ahead\n' })
|
|
git.mockResolvedValueOnce({ stdout: 'refs/heads/feature/test\n' })
|
|
worktrees.mockResolvedValue([])
|
|
await expect(
|
|
canCheckoutExistingLocalBranch(
|
|
'/repo',
|
|
'feature/test',
|
|
'origin/feature/test',
|
|
{ wslDistro: 'Ubuntu' },
|
|
true
|
|
)
|
|
).resolves.toBe(true)
|
|
expect(git.mock.calls).toEqual([
|
|
[
|
|
['rev-parse', '--verify', '--quiet', 'refs/heads/feature/test^{commit}'],
|
|
{ cwd: '/repo', wslDistro: 'Ubuntu' }
|
|
],
|
|
[
|
|
['for-each-ref', '--format=%(refname)', 'refs/heads/feature/test'],
|
|
{ cwd: '/repo', wslDistro: 'Ubuntu', captureWslLoginShellOutput: true }
|
|
]
|
|
])
|
|
expect(worktrees).toHaveBeenCalledWith('/repo', { wslDistro: 'Ubuntu' })
|
|
})
|
|
|
|
it('rejects a filesystem alias before attempting checkout through WSL', async () => {
|
|
git.mockResolvedValueOnce({ stdout: 'local-ahead\n' })
|
|
git.mockResolvedValueOnce({ stdout: '' })
|
|
await expect(
|
|
canCheckoutExistingLocalBranch(
|
|
'/repo',
|
|
'feature/TEST',
|
|
'origin/feature/test',
|
|
{ wslDistro: 'Ubuntu' },
|
|
true
|
|
)
|
|
).rejects.toThrow('Select its exact branch name')
|
|
expect(worktrees).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('detects a busy alias recorded by an older checkout through WSL', async () => {
|
|
git.mockResolvedValueOnce({ stdout: 'local-ahead\n' })
|
|
git.mockResolvedValueOnce({ stdout: 'refs/heads/feature/test\n' })
|
|
git.mockResolvedValueOnce({ stdout: '' })
|
|
worktrees.mockResolvedValue([{ path: '/busy', branch: 'refs/heads/feature/TEST' }])
|
|
await expect(
|
|
canCheckoutExistingLocalBranch(
|
|
'/repo',
|
|
'feature/test',
|
|
'origin/feature/test',
|
|
{ wslDistro: 'Ubuntu' },
|
|
true
|
|
)
|
|
).rejects.toThrow('already checked out at "/busy"')
|
|
expect(git).toHaveBeenLastCalledWith(
|
|
['for-each-ref', '--format=%(refname)', 'refs/heads/feature/TEST'],
|
|
{ cwd: '/repo', wslDistro: 'Ubuntu', captureWslLoginShellOutput: true }
|
|
)
|
|
})
|
|
|
|
it('propagates an unreadable local ref instead of treating it as permission to create', async () => {
|
|
git.mockRejectedValue(Object.assign(new Error('permission denied'), { code: 128 }))
|
|
await expect(
|
|
canCheckoutExistingLocalBranch('/repo', 'feature/test', 'origin/feature/test', {}, true)
|
|
).rejects.toThrow('permission denied')
|
|
expect(worktrees).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
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')
|
|
})
|
|
})
|