fix(sidebar): keep same-host checkouts of one repo as separate groups (#5375)
Multiple local checkouts (clones or worktrees) of the same GitHub repo share the owner/repo slug, so the project-first sidebar grouping added in #5071 collapsed them into one project group named after whichever folder was added first. Each checkout is already a distinct ProjectHostSetup, so group by setup when a project backs more than one setup on the same host. Single-checkout projects and cross-host (Local + SSH) grouping are unchanged, preserving the multi-host workbench behavior.
This commit is contained in:
@@ -343,6 +343,70 @@ describe('buildRows with pinned worktrees', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('splits same-host checkouts of one project into separate per-setup groups', () => {
|
||||
// Why: multiple local clones/worktrees of one repo share the GitHub slug, so
|
||||
// collapsing to the project would merge them into one arbitrarily-named group.
|
||||
// They are distinct ProjectHostSetups on the same host and must stay separate.
|
||||
const repoB: Repo = { ...repo, id: 'repo-2', path: '/tmp/orca-2', displayName: 'orca-2' }
|
||||
const worktreeB: Worktree = {
|
||||
...worktree,
|
||||
id: 'wt-2',
|
||||
repoId: repoB.id,
|
||||
path: '/tmp/orca-2-feature',
|
||||
displayName: 'feature-b'
|
||||
}
|
||||
const localSetupB: ProjectHostSetup = {
|
||||
...projectHostSetups[0]!,
|
||||
id: repoB.id,
|
||||
repoId: repoB.id,
|
||||
path: repoB.path,
|
||||
displayName: repoB.displayName
|
||||
}
|
||||
const rows = buildRows(
|
||||
'repo',
|
||||
[worktree, worktreeB],
|
||||
new Map([
|
||||
[repo.id, repo],
|
||||
[repoB.id, repoB]
|
||||
]),
|
||||
null,
|
||||
new Set(),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{},
|
||||
new Map([
|
||||
[worktree.id, worktree],
|
||||
[worktreeB.id, worktreeB]
|
||||
]),
|
||||
false,
|
||||
undefined,
|
||||
[],
|
||||
new Set(),
|
||||
new Map(),
|
||||
[],
|
||||
{
|
||||
projects: [{ ...project, sourceRepoIds: [repo.id, repoB.id] }],
|
||||
projectHostSetups: [projectHostSetups[0]!, localSetupB]
|
||||
}
|
||||
)
|
||||
|
||||
const headers = rows.filter((row) => row.type === 'header')
|
||||
expect(headers).toHaveLength(2)
|
||||
expect(headers).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
key: 'project:github:stablyai/orca::setup:repo-1',
|
||||
label: 'orca'
|
||||
}),
|
||||
expect.objectContaining({
|
||||
key: 'project:github:stablyai/orca::setup:repo-2',
|
||||
label: 'orca-2'
|
||||
})
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it('uses saved host labels for mixed-host sidebar card badges', () => {
|
||||
const runtimeRepo: Repo = {
|
||||
...remoteRepo,
|
||||
|
||||
@@ -134,6 +134,14 @@ type WorktreeGroupEntry = {
|
||||
type ProjectGroupingIndex = {
|
||||
projectById: Map<string, Project>
|
||||
setupByRepoId: Map<string, ProjectHostSetup>
|
||||
// Why: `${projectId}::${hostId}` pairs that back more than one setup — i.e. the
|
||||
// same project checked out multiple times on one host (independent clones or
|
||||
// worktrees). Those setups must not collapse into a single project group.
|
||||
multiSetupProjectHostKeys: Set<string>
|
||||
}
|
||||
|
||||
function projectHostKey(projectId: string, hostId: string): string {
|
||||
return `${projectId}::${hostId}`
|
||||
}
|
||||
|
||||
function buildProjectGroupingIndex(model?: ProjectGroupingModel): ProjectGroupingIndex | null {
|
||||
@@ -142,9 +150,21 @@ function buildProjectGroupingIndex(model?: ProjectGroupingModel): ProjectGroupin
|
||||
if (projects.length === 0 || projectHostSetups.length === 0) {
|
||||
return null
|
||||
}
|
||||
const setupCountByProjectHost = new Map<string, number>()
|
||||
for (const setup of projectHostSetups) {
|
||||
const key = projectHostKey(setup.projectId, setup.hostId)
|
||||
setupCountByProjectHost.set(key, (setupCountByProjectHost.get(key) ?? 0) + 1)
|
||||
}
|
||||
const multiSetupProjectHostKeys = new Set<string>()
|
||||
for (const [key, count] of setupCountByProjectHost) {
|
||||
if (count > 1) {
|
||||
multiSetupProjectHostKeys.add(key)
|
||||
}
|
||||
}
|
||||
return {
|
||||
projectById: new Map(projects.map((project) => [project.id, project])),
|
||||
setupByRepoId: new Map(projectHostSetups.map((setup) => [setup.repoId, setup]))
|
||||
setupByRepoId: new Map(projectHostSetups.map((setup) => [setup.repoId, setup])),
|
||||
multiSetupProjectHostKeys
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +183,17 @@ function getProjectGroupingForRepo(
|
||||
repo
|
||||
}
|
||||
}
|
||||
if (projectIndex?.multiSetupProjectHostKeys.has(projectHostKey(setup.projectId, setup.hostId))) {
|
||||
// Why: this project is set up more than once on this host, so each checkout
|
||||
// keeps its own group (labelled by its folder) instead of collapsing into a
|
||||
// single project header named after whichever folder was added first.
|
||||
return {
|
||||
key: `project:${project.id}::setup:${repoId}`,
|
||||
label: repo?.displayName ?? setup.displayName,
|
||||
repo,
|
||||
projectId: project.id
|
||||
}
|
||||
}
|
||||
return {
|
||||
key: `project:${project.id}`,
|
||||
label: project.displayName,
|
||||
|
||||
Reference in New Issue
Block a user