forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Add hierarchical .roo configuration resolution for mono-repos #8826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1b499c4
feat: add hierarchical .roo configuration resolution for mono-repos
roomote 349b09d
feat(mcp): hierarchical project-level mcp.json resolution and config …
roomote 2727e77
fix(custom-modes): ensure .roomodes precedence and ordering in getCus…
roomote 069aaa5
fix(roo-config): normalize paths for POSIX-like inputs to pass Window…
roomote 1c38e10
test(roo-config): make path assertions separator-agnostic to fix Wind…
roomote d1584a6
test(roo-config): normalize path assertions with path.normalize for c…
roomote 8329a84
fix(windows): make .roomodes YAML parsing and error messages platform…
roomote dac4203
fix(windows): robust path handling for .roomodes and hierarchical mcp…
roomote File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
src/services/roo-config/__tests__/hierarchical-resolution.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from "vitest" | ||
| import * as path from "path" | ||
| import * as os from "os" | ||
| import { getRooDirectoriesForCwd } from "../index" | ||
|
|
||
| vi.mock("os", () => ({ | ||
| homedir: vi.fn(), | ||
| })) | ||
|
|
||
| describe("Hierarchical .roo directory resolution", () => { | ||
| const mockHomedir = vi.mocked(os.homedir) | ||
|
|
||
| beforeEach(() => { | ||
| mockHomedir.mockReturnValue("/home/user") | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| describe("getRooDirectoriesForCwd with hierarchical resolution", () => { | ||
| it("should return only global and project-local when hierarchical is disabled", () => { | ||
| const cwd = "/home/user/projects/myapp" | ||
| const directories = getRooDirectoriesForCwd(cwd, false) | ||
|
|
||
| expect(directories).toEqual([ | ||
| "/home/user/.roo", // Global | ||
| "/home/user/projects/myapp/.roo", // Project-local | ||
| ]) | ||
| }) | ||
|
|
||
| it("should return hierarchical directories for simple project", () => { | ||
| const cwd = "/home/user/projects/myapp" | ||
| const directories = getRooDirectoriesForCwd(cwd, true) | ||
|
|
||
| expect(directories).toEqual([ | ||
| "/home/user/.roo", // Global | ||
| "/home/user/projects/.roo", // Parent directory | ||
| "/home/user/projects/myapp/.roo", // Project-local | ||
| ]) | ||
| }) | ||
|
|
||
| it("should handle deeply nested mono-repo structure", () => { | ||
| const cwd = "/home/user/work/company/mono-repo/packages/frontend/src" | ||
| const directories = getRooDirectoriesForCwd(cwd, true) | ||
|
|
||
| expect(directories).toEqual([ | ||
| "/home/user/.roo", // Global | ||
| "/home/user/work/.roo", | ||
| "/home/user/work/company/.roo", | ||
| "/home/user/work/company/mono-repo/.roo", // Repository root | ||
| "/home/user/work/company/mono-repo/packages/.roo", // Packages folder | ||
| "/home/user/work/company/mono-repo/packages/frontend/.roo", // Frontend package | ||
| "/home/user/work/company/mono-repo/packages/frontend/src/.roo", // Source folder | ||
| ]) | ||
| }) | ||
|
|
||
| it.skipIf(process.platform !== "win32")("should handle Windows paths correctly", () => { | ||
| mockHomedir.mockReturnValue("C:\\Users\\john") | ||
|
|
||
| const cwd = "C:\\Users\\john\\projects\\myapp" | ||
| const directories = getRooDirectoriesForCwd(cwd, true) | ||
|
|
||
| expect(directories).toEqual([ | ||
| "C:\\Users\\john\\.roo", // Global | ||
| "C:\\Users\\john\\projects\\.roo", // Parent directory | ||
| "C:\\Users\\john\\projects\\myapp\\.roo", // Project-local | ||
| ]) | ||
| }) | ||
|
|
||
| it("should stop at home directory and not include it twice", () => { | ||
| const cwd = "/home/user/myproject" | ||
| const directories = getRooDirectoriesForCwd(cwd, true) | ||
|
|
||
| expect(directories).toEqual([ | ||
| "/home/user/.roo", // Global (home directory) | ||
| "/home/user/myproject/.roo", // Project-local | ||
| ]) | ||
|
|
||
| // Should not have duplicate /home/user/.roo entries | ||
| const homeDirRooCount = directories.filter((d) => d === "/home/user/.roo").length | ||
| expect(homeDirRooCount).toBe(1) | ||
| }) | ||
|
|
||
| it("should handle root directory edge case", () => { | ||
| const cwd = "/project" | ||
| const directories = getRooDirectoriesForCwd(cwd, true) | ||
|
|
||
| expect(directories).toEqual([ | ||
| "/home/user/.roo", // Global | ||
| "/project/.roo", // Project at root level | ||
| ]) | ||
| }) | ||
|
|
||
| it("should handle relative paths by resolving them", () => { | ||
| const cwd = "./myproject" | ||
| const directories = getRooDirectoriesForCwd(cwd, true) | ||
|
|
||
| // Should resolve relative path and return proper hierarchy | ||
| expect(directories[0]).toBe("/home/user/.roo") // Global directory | ||
| expect(directories[directories.length - 1]).toMatch(/myproject[\/\\]\.roo$/) | ||
| }) | ||
|
|
||
| it("should use hierarchical resolution by default when not specified", () => { | ||
| const cwd = "/home/user/projects/myapp" | ||
| const directories = getRooDirectoriesForCwd(cwd) // No second parameter | ||
|
|
||
| expect(directories).toEqual([ | ||
| "/home/user/.roo", // Global | ||
| "/home/user/projects/.roo", // Parent directory | ||
| "/home/user/projects/myapp/.roo", // Project-local | ||
| ]) | ||
| }) | ||
|
|
||
| it("should handle edge case of cwd being exactly home directory", () => { | ||
| const cwd = "/home/user" | ||
| const directories = getRooDirectoriesForCwd(cwd, true) | ||
|
|
||
| expect(directories).toEqual([ | ||
| "/home/user/.roo", // Global (and also the cwd) | ||
| ]) | ||
|
|
||
| // Should not have duplicate entries | ||
| expect(directories.length).toBe(1) | ||
| }) | ||
|
|
||
| it("should handle symbolic links and circular references gracefully", () => { | ||
| // This tests that the visitedPaths Set prevents infinite loops | ||
| const cwd = "/home/user/projects/link/to/self" | ||
| const directories = getRooDirectoriesForCwd(cwd, true) | ||
|
|
||
| // Should not throw or hang, should return valid hierarchy | ||
| expect(directories).toBeDefined() | ||
| expect(directories[0]).toBe("/home/user/.roo") | ||
| expect(directories.length).toBeGreaterThan(0) | ||
| }) | ||
| }) | ||
|
|
||
| describe("Integration with configuration loading", () => { | ||
| it("should provide directories in correct order for override behavior", () => { | ||
| // More specific configurations should override more general ones | ||
| const cwd = "/home/user/company/project/submodule" | ||
| const directories = getRooDirectoriesForCwd(cwd, true) | ||
|
|
||
| // Verify order: global first (least specific), then progressively more specific | ||
| expect(directories[0]).toBe("/home/user/.roo") // Least specific | ||
| expect(directories[directories.length - 1]).toBe("/home/user/company/project/submodule/.roo") // Most specific | ||
|
|
||
| // This order ensures that when configs are merged, more specific ones override general ones | ||
| for (let i = 1; i < directories.length; i++) { | ||
| // Each directory should be a child of the previous (when excluding global) | ||
| if (i > 1) { | ||
| expect(directories[i].startsWith(directories[i - 1].replace(/[\/\\]\.roo$/, ""))).toBe(true) | ||
| } | ||
| } | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file watcher pattern
**/.roomodesonly watches files within the workspace directory, butgetHierarchicalRoomodes()walks up to parent directories outside the workspace. This means changes to.roomodesfiles in parent directories won't trigger updates, requiring users to restart VSCode. For example, if the workspace is/home/user/mono-repo/packages/frontendand there's a.roomodesat/home/user/mono-repo/.roomodes, changes to the parent file won't be detected since it's outside the workspace tree being watched.