Normalize Orca worktree branch selectors (#281)

This commit is contained in:
Jinwoo Hong
2026-04-03 22:08:59 -07:00
committed by GitHub
parent 6c78908a7c
commit b3494b63b4
2 changed files with 39 additions and 2 deletions
+20
View File
@@ -179,6 +179,26 @@ describe('OrcaRuntimeService', () => {
expect(shown.ptyId).toBe('pty-1')
})
it('resolves branch selectors when worktrees store refs/heads-prefixed branches', async () => {
vi.mocked(listWorktrees).mockResolvedValueOnce([
{
path: '/tmp/worktree-a',
head: 'abc',
branch: 'refs/heads/Jinwoo-H/test-3a',
isBare: false,
isMainWorktree: false
}
])
const runtime = new OrcaRuntimeService(store)
const worktree = await runtime.showManagedWorktree('branch:Jinwoo-H/test-3a')
expect(worktree).toMatchObject({
branch: 'refs/heads/Jinwoo-H/test-3a',
path: '/tmp/worktree-a'
})
})
it('reads bounded terminal output and writes through the PTY controller', async () => {
const writes: string[] = []
const runtime = new OrcaRuntimeService(store)
+19 -2
View File
@@ -781,7 +781,10 @@ export class OrcaRuntimeService {
} else if (selector.startsWith('path:')) {
candidates = worktrees.filter((worktree) => worktree.path === selector.slice(5))
} else if (selector.startsWith('branch:')) {
candidates = worktrees.filter((worktree) => worktree.branch === selector.slice(7))
const branchSelector = selector.slice(7)
candidates = worktrees.filter((worktree) =>
branchSelectorMatches(worktree.branch, branchSelector)
)
} else if (selector.startsWith('issue:')) {
candidates = worktrees.filter(
(worktree) =>
@@ -790,7 +793,9 @@ export class OrcaRuntimeService {
} else {
candidates = worktrees.filter(
(worktree) =>
worktree.id === selector || worktree.path === selector || worktree.branch === selector
worktree.id === selector ||
worktree.path === selector ||
branchSelectorMatches(worktree.branch, selector)
)
}
@@ -1129,6 +1134,18 @@ function buildTerminalWaitResult(handle: string, leaf: RuntimeLeafRecord): Runti
}
}
function branchSelectorMatches(branch: string, selector: string): boolean {
// Why: Git worktree data can report local branches as either `refs/heads/foo`
// or `foo` depending on which plumbing path produced the record. Orca's
// branch selectors should accept either form so newly created worktrees stay
// discoverable without exposing internal ref-shape differences to users.
return normalizeBranchRef(branch) === normalizeBranchRef(selector)
}
function normalizeBranchRef(branch: string): string {
return branch.startsWith('refs/heads/') ? branch.slice('refs/heads/'.length) : branch
}
function normalizeTerminalChunk(chunk: string): string {
return chunk
.replace(/\r\n/g, '\n')