From e8f48ca8fff0c944748416b82612f1fe7436eeeb Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 27 Apr 2026 11:12:07 -0700 Subject: [PATCH] Group duplicate clones by repo-relative path - Treat matching repo-relative paths as the same logical project - Update grouping test to reflect the new duplicate-clone behavior --- apps/web/src/environmentGrouping.test.ts | 4 ++-- apps/web/src/logicalProject.ts | 30 +++++++----------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/apps/web/src/environmentGrouping.test.ts b/apps/web/src/environmentGrouping.test.ts index 1e062c2a2c..a96735487a 100644 --- a/apps/web/src/environmentGrouping.test.ts +++ b/apps/web/src/environmentGrouping.test.ts @@ -529,7 +529,7 @@ describe("environment grouping", () => { ); }); - it("keeps duplicate clones in the same environment separate when repo-relative paths match", () => { + it("groups duplicate clones in the same environment when repo-relative paths match", () => { const firstClone = makeProject({ id: sharedProjectPrimaryId, environmentId: primaryEnvId, @@ -563,7 +563,7 @@ describe("environment grouping", () => { const keys = buildLogicalProjectKeyMap([firstClone, secondClone], DEFAULT_GROUPING_SETTINGS); - expect(keys.get(derivePhysicalProjectKey(firstClone))).not.toBe( + expect(keys.get(derivePhysicalProjectKey(firstClone))).toBe( keys.get(derivePhysicalProjectKey(secondClone)), ); }); diff --git a/apps/web/src/logicalProject.ts b/apps/web/src/logicalProject.ts index 57337b1c07..9b161c515f 100644 --- a/apps/web/src/logicalProject.ts +++ b/apps/web/src/logicalProject.ts @@ -176,7 +176,6 @@ export function buildLogicalProjectKeyMap( const assignBucket = ( baseKey: string, bucket: ReadonlyArray>, - discriminatorIndex: number, ) => { if (!hasDuplicateEnvironment(bucket)) { for (const project of bucket) { @@ -185,29 +184,16 @@ export function buildLogicalProjectKeyMap( return; } - const discriminatorFns = [ - (project: Pick) => { - const relativePath = deriveRepositoryRelativeProjectPath(project); - return relativePath === null ? null : formatProjectGroupDiscriminator(relativePath); - }, - (project: Pick) => normalizeProjectPathForComparison(project.cwd), - (project: Pick) => - physicalKeyByProject.get(project) ?? derivePhysicalProjectKey(project), - ] as const; - const discriminator = discriminatorFns[discriminatorIndex]; - if (!discriminator) { - for (const project of bucket) { - result.set(physicalKeyByProject.get(project)!, physicalKeyByProject.get(project)!); - } - return; - } - const buckets = new Map< string, Array> >(); for (const project of bucket) { - const value = discriminator(project) ?? normalizeProjectPathForComparison(project.cwd); + const relativePath = deriveRepositoryRelativeProjectPath(project); + const value = + relativePath === null + ? normalizeProjectPathForComparison(project.cwd) + : formatProjectGroupDiscriminator(relativePath); const key = `${baseKey}::${value}`; const existing = buckets.get(key); if (existing) { @@ -218,12 +204,14 @@ export function buildLogicalProjectKeyMap( } for (const [key, projectsForKey] of buckets) { - assignBucket(key, projectsForKey, discriminatorIndex + 1); + for (const project of projectsForKey) { + result.set(physicalKeyByProject.get(project)!, key); + } } }; for (const [baseKey, bucket] of baseBuckets) { - assignBucket(baseKey, bucket, 0); + assignBucket(baseKey, bucket); } return result;