diff --git a/src/main/project-groups/nested-repo-import.test.ts b/src/main/project-groups/nested-repo-import.test.ts index 2b591fa9a71..aa8a0502e1f 100644 --- a/src/main/project-groups/nested-repo-import.test.ts +++ b/src/main/project-groups/nested-repo-import.test.ts @@ -138,7 +138,9 @@ describe('createNestedProjectGroupResolver', () => { parentPath: '/workspace', groupName: 'workspace', mode: 'separate', - repoPaths: ['/workspace/services/api', '/workspace/services/worker'], + get repoPaths(): readonly string[] { + throw new Error('separate imports must not build unused folder scopes') + }, createGroup: () => { throw new Error('should not create a group') } @@ -148,6 +150,30 @@ describe('createNestedProjectGroupResolver', () => { expect(resolver.getCreatedGroups()).toEqual([]) }) + it('leaves every separate-import repo ungrouped even when repo paths are supplied', () => { + const { groups, createGroup } = createGroupRecorder() + const repoPaths = [ + '/workspace/services/api', + '/workspace/services/worker', + '/workspace/platform/packages/shared' + ] + const resolver = createNestedProjectGroupResolver({ + parentPath: '/workspace', + groupName: 'workspace', + mode: 'separate', + repoPaths, + createGroup + }) + + expect(repoPaths.map((repoPath) => resolver.getGroupForRepo(repoPath))).toEqual([ + undefined, + undefined, + undefined + ]) + expect(resolver.getRootGroup()).toBeUndefined() + expect(groups).toEqual([]) + }) + it('preserves filesystem root parent paths when creating the root group', () => { const groups: ProjectGroup[] = [] const resolver = createNestedProjectGroupResolver({ diff --git a/src/main/project-groups/nested-repo-import.ts b/src/main/project-groups/nested-repo-import.ts index 17aee4a2994..c08839edc30 100644 --- a/src/main/project-groups/nested-repo-import.ts +++ b/src/main/project-groups/nested-repo-import.ts @@ -150,10 +150,12 @@ export function createNestedProjectGroupResolver(args: { createGroup: (input: CreateGroupInput) => ProjectGroup }): NestedProjectGroupResolver { const createdGroups: ProjectGroup[] = [] - const folderScopes = buildSparseFolderScopes({ - parentPath: args.parentPath, - repoPaths: args.repoPaths ?? [] - }) + // Every folder-scope read sits behind ensureRootGroup, so outside group mode the scopes are + // unreachable. One flag drives both so the skip can never drift from the guard that justifies it. + const createsGroups = args.mode === 'group' + const folderScopes = createsGroups + ? buildSparseFolderScopes({ parentPath: args.parentPath, repoPaths: args.repoPaths ?? [] }) + : [] const folderScopesByRelativePath = new Map( folderScopes.map((scope) => [scope.relativePath, scope]) ) @@ -161,7 +163,7 @@ export function createNestedProjectGroupResolver(args: { let rootGroup: ProjectGroup | undefined const ensureRootGroup = (): ProjectGroup | undefined => { - if (args.mode !== 'group') { + if (!createsGroups) { return undefined } if (rootGroup) {