Repository navigation
fix(commands): list global commands over colliding built-in commands #1736
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
Open
myk1yt
wants to merge
7
commits into
Zoo-Code-Org:main
Choose a base branch
from
myk1yt:fix/slash-command-precedence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
14a9228
fix(commands): list global commands over colliding built-in commands
ac9aace
fix(commands): resolve duplicate command names across symlinked direc…
0fdb37c
test(commands): cover duplicate entries from symlinks sharing one target
6488d03
Merge branch 'main' into fix/slash-command-precedence
taltas b9dbfd3
Merge remote-tracking branch 'origin/main' into fix/slash-command-pre…
myk1yt fbb7340
fix(commands): align command listing with execution resolution
myk1yt 9f764fc
test(commands): make directory-symlink mock consistent for execution …
myk1yt 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
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
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
86 changes: 86 additions & 0 deletions
86
src/services/command/__tests__/symlink-directory-consistency.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,86 @@ | ||
| import fs from "fs/promises" | ||
| import * as path from "path" | ||
| import { tmpdir } from "node:os" | ||
|
|
||
| const mockHome = vi.hoisted(() => ({ path: "" })) | ||
|
|
||
| vi.mock("os", async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import("os")>() | ||
| return { | ||
| ...actual, | ||
| homedir: () => mockHome.path, | ||
| } | ||
| }) | ||
|
|
||
| import { getCommand, getCommands } from "../commands" | ||
|
|
||
| /** | ||
| * Real-filesystem tests for listing/execution consistency. getCommands() (the | ||
| * listing) must surface exactly what getCommand() (execution) can resolve: | ||
| * direct .md files and file symlinks in the commands directory. Directory | ||
| * symlinks are not followed by either path. | ||
| */ | ||
| describe("command listing and execution consistency for symlinks", () => { | ||
| let tempDir: string | ||
| let cwd: string | ||
| let globalCommandsDir: string | ||
|
|
||
| const dirLinkType = process.platform === "win32" ? "junction" : "dir" | ||
|
|
||
| beforeEach(async () => { | ||
| tempDir = await fs.mkdtemp(path.join(tmpdir(), "zoo-command-symlink-")) | ||
| mockHome.path = path.join(tempDir, "home") | ||
| cwd = path.join(tempDir, "workspace") | ||
| globalCommandsDir = path.join(mockHome.path, ".roo", "commands") | ||
| await fs.mkdir(globalCommandsDir, { recursive: true }) | ||
| await fs.mkdir(cwd, { recursive: true }) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await fs.rm(tempDir, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| it("selects the built-in command in both listing and execution when a global directory symlink collides with it", async () => { | ||
| const sharedDir = path.join(tempDir, "shared") | ||
| await fs.mkdir(sharedDir, { recursive: true }) | ||
| await fs.writeFile(path.join(sharedDir, "init.md"), "# Global Init via directory symlink") | ||
| await fs.symlink(sharedDir, path.join(globalCommandsDir, "shared-link"), dirLinkType) | ||
|
|
||
| const listed = (await getCommands(cwd)).filter((command) => command.name === "init") | ||
| expect(listed).toHaveLength(1) | ||
| expect(listed[0].source).toBe("built-in") | ||
|
|
||
| const executed = await getCommand(cwd, "init") | ||
| expect(executed?.source).toBe("built-in") | ||
|
|
||
| // Listing and execution must select the same command. | ||
| expect(listed[0].content).toBe(executed?.content) | ||
| expect(listed[0].filePath).toBe(executed?.filePath) | ||
| }) | ||
|
|
||
| it("does not list or execute a command that is only reachable through a directory symlink", async () => { | ||
| const sharedDir = path.join(tempDir, "shared") | ||
| await fs.mkdir(sharedDir, { recursive: true }) | ||
| await fs.writeFile(path.join(sharedDir, "nested.md"), "# Nested Command") | ||
| await fs.symlink(sharedDir, path.join(globalCommandsDir, "shared-link"), dirLinkType) | ||
|
|
||
| const listed = await getCommands(cwd) | ||
| expect(listed.find((command) => command.name === "nested")).toBeUndefined() | ||
|
|
||
| expect(await getCommand(cwd, "nested")).toBeUndefined() | ||
| }) | ||
|
|
||
| it.skipIf(process.platform === "win32")("lists and executes file symlinks at the commands directory root", async () => { | ||
| const sharedDir = path.join(mockHome.path, ".roo", "shared") | ||
| await fs.mkdir(sharedDir, { recursive: true }) | ||
| await fs.writeFile(path.join(sharedDir, "aliased-target.md"), "# Aliased Command") | ||
| await fs.symlink(path.join(sharedDir, "aliased-target.md"), path.join(globalCommandsDir, "aliased.md"), "file") | ||
|
|
||
| const listed = (await getCommands(cwd)).filter((command) => command.name === "aliased") | ||
| expect(listed).toHaveLength(1) | ||
| expect(listed[0].content).toContain("Aliased Command") | ||
|
|
||
| const executed = await getCommand(cwd, "aliased") | ||
| expect(executed?.content).toContain("Aliased Command") | ||
| }) | ||
| }) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.