fix(worktree): collapse duplicate "Local Mac" run targets in the host picker (#10472)
* fix(worktree): collapse duplicate "Local Mac" run targets in the host picker A linked worktree added as its own project projects a second ready host setup on the same project+host, so the run-target picker rendered N identical "Local Mac" rows differing only by path. Only the first was reachable — resolveWorkspaceCreationTarget takes the first project+host match — so the extras pointed at paths that may no longer exist. - Dedupe ready setup options by host in the picker (display fix for profiles that already hold duplicates). - Canonicalize a stale draft's setup id to the setup the picker shows, so the displayed path is the path the workspace is created in. - Reject a linked worktree at repos:add when its main checkout is already tracked, preventing new duplicates. * fix(worktree): only dedupe a linked worktree against a git main checkout Review follow-up: the repos:add guard matched any tracked repo on the main checkout path, including a folder-kind record. A folder repo does not project onto the same project as the git worktree, so matching it would suppress a legitimate add without deduping anything.
This commit is contained in:
@@ -199,6 +199,42 @@ describe('buildProjectHostSetupOptions', () => {
|
||||
expect(options.map((option) => option.id)).toEqual(['ready'])
|
||||
})
|
||||
|
||||
it('collapses duplicate ready setups on one host to the setup creation actually uses', () => {
|
||||
// Why: a linked worktree added as its own project projected a second ready `local` setup for the
|
||||
// same project, which rendered as repeated identical "Local Mac" rows separated only by path.
|
||||
const options = buildProjectHostSetupOptions({
|
||||
projectId: 'project-1',
|
||||
eligibleRepos: [repo('main-checkout'), repo('worktree-a'), repo('worktree-b')],
|
||||
hosts: [host('local')],
|
||||
projectHostSetups: [
|
||||
setup('main', 'project-1', 'local', 'main-checkout', { path: '/Users/dev/projects/orca' }),
|
||||
setup('dup-a', 'project-1', 'local', 'worktree-a', {
|
||||
path: '/Users/dev/worktrees/pr-1908'
|
||||
}),
|
||||
setup('dup-b', 'project-1', 'local', 'worktree-b', { path: '/Users/dev/worktrees/pr-3235' })
|
||||
]
|
||||
})
|
||||
|
||||
expect(options).toEqual([
|
||||
expect.objectContaining({ id: 'main', kind: 'ready', label: LOCAL_HOST_LABEL })
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps one ready choice per host when a project is set up on several hosts', () => {
|
||||
const options = buildProjectHostSetupOptions({
|
||||
projectId: 'project-1',
|
||||
eligibleRepos: [repo('local-repo'), repo('local-dup'), repo('remote-repo')],
|
||||
hosts: [host('local'), host('ssh:builder', { label: 'Builder' })],
|
||||
projectHostSetups: [
|
||||
setup('local', 'project-1', 'local', 'local-repo'),
|
||||
setup('local-dup', 'project-1', 'local', 'local-dup'),
|
||||
setup('remote', 'project-1', 'ssh:builder', 'remote-repo')
|
||||
]
|
||||
})
|
||||
|
||||
expect(options.map((option) => option.id)).toEqual(['local', 'remote'])
|
||||
})
|
||||
|
||||
it('includes known hosts that still need project setup', () => {
|
||||
const options = buildProjectHostSetupOptions({
|
||||
projectId: 'project-1',
|
||||
|
||||
@@ -136,6 +136,23 @@ function buildReadySetupOptions({
|
||||
detail: setup.displayName,
|
||||
path: setup.path
|
||||
}))
|
||||
.filter(dedupeByHost())
|
||||
}
|
||||
|
||||
// Why: a project resolves to at most one setup per host — resolveWorkspaceCreationTarget takes the
|
||||
// first project+host match and ignores the rest, so extra same-host setups are unreachable. Legacy
|
||||
// profiles can still hold them (a linked worktree added as its own project projects a second local
|
||||
// setup), which rendered as repeated identical "Local Mac" rows. Keep the first in input order so
|
||||
// the row shown is the one workspace creation actually uses.
|
||||
function dedupeByHost(): (option: ReadyProjectHostSetupOption) => boolean {
|
||||
const seenHosts = new Set<ExecutionHostId>()
|
||||
return (option) => {
|
||||
if (seenHosts.has(option.hostId)) {
|
||||
return false
|
||||
}
|
||||
seenHosts.add(option.hostId)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function buildNeedsSetupOptions({
|
||||
|
||||
@@ -121,6 +121,51 @@ describe('project-host workspace target resolution', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('canonicalizes a stale same-host setup id to the setup the picker shows', () => {
|
||||
// Why: the run-target picker renders one row per host. A draft persisted before that collapse
|
||||
// can still name a duplicate local setup; creation must land in the displayed path, not a
|
||||
// transient worktree path the user never sees.
|
||||
const repos = [makeRepo('orca-main'), makeRepo('orca-worktree')]
|
||||
const projects = [makeProject('github:stablyai/orca', ['orca-main', 'orca-worktree'])]
|
||||
const projectHostSetups = [
|
||||
makeSetup('orca-main', 'github:stablyai/orca', 'local', 'orca-main'),
|
||||
makeSetup('orca-worktree', 'github:stablyai/orca', 'local', 'orca-worktree')
|
||||
]
|
||||
|
||||
const resolution = resolveWorkspaceCreationTarget({
|
||||
eligibleRepos: repos,
|
||||
projects,
|
||||
projectHostSetups,
|
||||
projectHostSetupId: 'orca-worktree'
|
||||
})
|
||||
|
||||
expect(resolution).toMatchObject({
|
||||
status: 'ready',
|
||||
target: { projectHostSetupId: 'orca-main', repoId: 'orca-main', hostId: 'local' }
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps an explicit setup id that is the only one on its host', () => {
|
||||
const repos = [makeRepo('orca-local'), makeRepo('orca-ssh', { connectionId: 'builder' })]
|
||||
const projects = [makeProject('github:stablyai/orca', ['orca-local', 'orca-ssh'])]
|
||||
const projectHostSetups = [
|
||||
makeSetup('orca-local', 'github:stablyai/orca', 'local', 'orca-local'),
|
||||
makeSetup('orca-ssh', 'github:stablyai/orca', 'ssh:builder', 'orca-ssh')
|
||||
]
|
||||
|
||||
expect(
|
||||
resolveWorkspaceCreationTarget({
|
||||
eligibleRepos: repos,
|
||||
projects,
|
||||
projectHostSetups,
|
||||
projectHostSetupId: 'orca-ssh'
|
||||
})
|
||||
).toMatchObject({
|
||||
status: 'ready',
|
||||
target: { projectHostSetupId: 'orca-ssh', repoId: 'orca-ssh', hostId: 'ssh:builder' }
|
||||
})
|
||||
})
|
||||
|
||||
it('does not merge same-name repos without shared project identity', () => {
|
||||
const repos = [
|
||||
makeRepo('personal-orca', { displayName: 'orca' }),
|
||||
|
||||
@@ -130,9 +130,17 @@ export function resolveWorkspaceCreationTarget(
|
||||
if (!isReadySetup(setup)) {
|
||||
return { status: 'unavailable', reason: 'setup-not-ready' }
|
||||
}
|
||||
const target = createTarget(setup, repoById)
|
||||
if (target) {
|
||||
return { status: 'ready', target }
|
||||
// Why: a project resolves to one setup per host, and the run-target picker shows only the first.
|
||||
// A stale draft can still name a same-host duplicate from a legacy profile; canonicalize to the
|
||||
// same setup the picker displays so the shown path is the path the workspace is created in.
|
||||
const canonical =
|
||||
findReadySetupTarget(
|
||||
setups,
|
||||
repoById,
|
||||
(entry) => entry.projectId === setup.projectId && entry.hostId === setup.hostId
|
||||
) ?? createTarget(setup, repoById)
|
||||
if (canonical) {
|
||||
return { status: 'ready', target: canonical }
|
||||
}
|
||||
return { status: 'unavailable', reason: 'setup-not-found' }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user