Simplify logical project grouping

- Use the configured grouping mode directly for sidebar and thread buckets
- Add coverage for repository-path grouping splitting root and nested projects
- Remove environment-based bucket splitting from logical key mapping
This commit is contained in:
Julius Marminge committed 2026-04-27 11:16:24 -07:00
1 parent e8f48ca8ff
commit e80d4a479c
3 files changed
+48 -78

No files matched your search

+2 -3
View File
@@ -2759,9 +2759,8 @@ export default function Sidebar() {
});
}, [projectOrder, projects]);
// Build a mapping from physical project key -> logical project key. Matching
// projects can group across environments, but each rendered group keeps at
// most one member per environment so thread creation remains unambiguous.
// Build a mapping from physical project key -> logical project key so the
// sidebar, active route, and thread buckets all use the same grouping mode.
const physicalToLogicalKey = useMemo(() => {
return buildPhysicalToLogicalProjectKeyMap({
projects: orderedProjects,
+44 -2
View File
@@ -451,7 +451,7 @@ describe("environment grouping", () => {
});
describe("buildLogicalProjectKeyMap", () => {
it("groups matching projects across environments without merging distinct projects in one environment", () => {
it("groups matching projects by repository under repository grouping", () => {
const localRoot = makeProject({
id: sharedProjectPrimaryId,
environmentId: primaryEnvId,
@@ -524,11 +524,53 @@ describe("environment grouping", () => {
expect(keys.get(derivePhysicalProjectKey(localWeb))).toBe(
keys.get(derivePhysicalProjectKey(remoteWeb)),
);
expect(keys.get(derivePhysicalProjectKey(localRoot))).not.toBe(
expect(keys.get(derivePhysicalProjectKey(localRoot))).toBe(
keys.get(derivePhysicalProjectKey(localWeb)),
);
});
it("splits repo root and nested projects under repository path grouping", () => {
const rootProject = makeProject({
id: sharedProjectPrimaryId,
environmentId: primaryEnvId,
name: "shared-repo",
cwd: "/workspace/repo",
repositoryIdentity: {
canonicalKey: SHARED_REPO_CANONICAL_KEY,
rootPath: "/workspace/repo",
locator: {
source: "git-remote",
remoteName: "origin",
remoteUrl: "https://github.com/example/shared-repo.git",
},
},
});
const nestedProject = makeProject({
id: localOnlyProjectId,
environmentId: primaryEnvId,
name: "web",
cwd: "/workspace/repo/apps/web",
repositoryIdentity: {
canonicalKey: SHARED_REPO_CANONICAL_KEY,
rootPath: "/workspace/repo",
locator: {
source: "git-remote",
remoteName: "origin",
remoteUrl: "https://github.com/example/shared-repo.git",
},
},
});
const keys = buildLogicalProjectKeyMap([rootProject, nestedProject], {
...DEFAULT_GROUPING_SETTINGS,
sidebarProjectGroupingMode: "repository_path",
});
expect(keys.get(derivePhysicalProjectKey(rootProject))).not.toBe(
keys.get(derivePhysicalProjectKey(nestedProject)),
);
});
it("groups duplicate clones in the same environment when repo-relative paths match", () => {
const firstClone = makeProject({
id: sharedProjectPrimaryId,
+2 -73
View File
@@ -51,21 +51,6 @@ function deriveRepositoryRelativeProjectPath(
return normalizedProjectPath.slice(rootPrefix.length).replaceAll("\\", "/");
}
function formatProjectGroupDiscriminator(value: string): string {
return value.length === 0 ? "." : value;
}
function hasDuplicateEnvironment(projects: ReadonlyArray<Pick<Project, "environmentId">>): boolean {
const seen = new Set<string>();
for (const project of projects) {
if (seen.has(project.environmentId)) {
return true;
}
seen.add(project.environmentId);
}
return false;
}
export function derivePhysicalProjectKeyFromPath(environmentId: string, cwd: string): string {
return `${environmentId}:${normalizeProjectPathForComparison(cwd)}`;
}
@@ -151,67 +136,11 @@ export function buildLogicalProjectKeyMap(
projects: ReadonlyArray<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>,
settings: ProjectGroupingSettings,
): Map<string, string> {
const baseBuckets = new Map<
string,
Array<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>
>();
const physicalKeyByProject = new Map<
Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">,
string
>();
const result = new Map<string, string>();
for (const project of projects) {
const physicalKey = derivePhysicalProjectKey(project);
physicalKeyByProject.set(project, physicalKey);
const baseKey = deriveLogicalProjectKeyFromSettings(project, settings);
const bucket = baseBuckets.get(baseKey);
if (bucket) {
bucket.push(project);
} else {
baseBuckets.set(baseKey, [project]);
}
}
const result = new Map<string, string>();
const assignBucket = (
baseKey: string,
bucket: ReadonlyArray<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>,
) => {
if (!hasDuplicateEnvironment(bucket)) {
for (const project of bucket) {
result.set(physicalKeyByProject.get(project)!, baseKey);
}
return;
}
const buckets = new Map<
string,
Array<Pick<Project, "environmentId" | "id" | "cwd" | "repositoryIdentity">>
>();
for (const project of bucket) {
const relativePath = deriveRepositoryRelativeProjectPath(project);
const value =
relativePath === null
? normalizeProjectPathForComparison(project.cwd)
: formatProjectGroupDiscriminator(relativePath);
const key = `${baseKey}::${value}`;
const existing = buckets.get(key);
if (existing) {
existing.push(project);
} else {
buckets.set(key, [project]);
}
}
for (const [key, projectsForKey] of buckets) {
for (const project of projectsForKey) {
result.set(physicalKeyByProject.get(project)!, key);
}
}
};
for (const [baseKey, bucket] of baseBuckets) {
assignBucket(baseKey, bucket);
result.set(physicalKey, deriveLogicalProjectKeyFromSettings(project, settings));
}
return result;