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
This commit is contained in:
Julius Marminge committed 2026-04-27 11:12:07 -07:00
1 parent c421b5d054
commit e8f48ca8ff
2 files changed
+11 -23

No files matched your search

+2 -2
View File
@@ -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)),
);
});
+9 -21
View File
@@ -176,7 +176,6 @@ export function buildLogicalProjectKeyMap(
const assignBucket = (
baseKey: string,
bucket: ReadonlyArray<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>,
discriminatorIndex: number,
) => {
if (!hasDuplicateEnvironment(bucket)) {
for (const project of bucket) {
@@ -185,29 +184,16 @@ export function buildLogicalProjectKeyMap(
return;
}
const discriminatorFns = [
(project: Pick<Project, "cwd" | "repositoryIdentity">) => {
const relativePath = deriveRepositoryRelativeProjectPath(project);
return relativePath === null ? null : formatProjectGroupDiscriminator(relativePath);
},
(project: Pick<Project, "cwd">) => normalizeProjectPathForComparison(project.cwd),
(project: Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">) =>
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<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>
>();
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;