Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/__tests__/command-integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Command Integration Tests", () => {
commands.forEach((command) => {
expect(command.name).toBeDefined()
expect(typeof command.name).toBe("string")
expect(command.source).toMatch(/^(project|global)$/)
expect(command.source).toMatch(/^(project|global|built-in)$/)
expect(command.content).toBeDefined()
expect(typeof command.content).toBe("string")
})
Expand Down Expand Up @@ -43,7 +43,7 @@ describe("Command Integration Tests", () => {

expect(loadedCommand).toBeDefined()
expect(loadedCommand?.name).toBe(firstCommand.name)
expect(loadedCommand?.source).toMatch(/^(project|global)$/)
expect(loadedCommand?.source).toMatch(/^(project|global|built-in)$/)
expect(loadedCommand?.content).toBeDefined()
expect(typeof loadedCommand?.content).toBe("string")
}
Expand Down
1 change: 1 addition & 0 deletions src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,7 @@ export const webviewMessageHandler = async (
source: command.source,
filePath: command.filePath,
description: command.description,
argumentHint: command.argumentHint,
}))
await provider.postMessageToWebview({
type: "commands",
Expand Down
104 changes: 104 additions & 0 deletions src/services/command/__tests__/built-in-commands.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { describe, it, expect } from "vitest"
import { getBuiltInCommands, getBuiltInCommand, getBuiltInCommandNames } from "../built-in-commands"

describe("Built-in Commands", () => {
describe("getBuiltInCommands", () => {
it("should return all built-in commands", async () => {
const commands = await getBuiltInCommands()

expect(commands).toHaveLength(1)
expect(commands.map((cmd) => cmd.name)).toEqual(expect.arrayContaining(["init"]))

// Verify all commands have required properties
commands.forEach((command) => {
expect(command.name).toBeDefined()
expect(typeof command.name).toBe("string")
expect(command.content).toBeDefined()
expect(typeof command.content).toBe("string")
expect(command.source).toBe("built-in")
expect(command.filePath).toMatch(/^<built-in:.+>$/)
expect(command.description).toBeDefined()
expect(typeof command.description).toBe("string")
})
})

it("should return commands with proper content", async () => {
const commands = await getBuiltInCommands()

const initCommand = commands.find((cmd) => cmd.name === "init")
expect(initCommand).toBeDefined()
expect(initCommand!.content).toContain("AGENTS.md")
expect(initCommand!.content).toContain(".roo/rules-")
expect(initCommand!.description).toBe(
"Analyze codebase and create concise AGENTS.md files for AI assistants",
)
})
})

describe("getBuiltInCommand", () => {
it("should return specific built-in command by name", async () => {
const initCommand = await getBuiltInCommand("init")

expect(initCommand).toBeDefined()
expect(initCommand!.name).toBe("init")
expect(initCommand!.source).toBe("built-in")
expect(initCommand!.filePath).toBe("<built-in:init>")
expect(initCommand!.content).toContain("AGENTS.md")
expect(initCommand!.description).toBe(
"Analyze codebase and create concise AGENTS.md files for AI assistants",
)
})

it("should return undefined for non-existent command", async () => {
const nonExistentCommand = await getBuiltInCommand("non-existent")
expect(nonExistentCommand).toBeUndefined()
})

it("should handle empty string command name", async () => {
const emptyCommand = await getBuiltInCommand("")
expect(emptyCommand).toBeUndefined()
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test coverage is good for basic functionality. Consider adding tests for edge cases like:

  • Concurrent access to built-in commands
  • Command name conflicts with user-defined commands
  • Behavior when BUILT_IN_COMMANDS is modified at runtime


describe("getBuiltInCommandNames", () => {
it("should return all built-in command names", async () => {
const names = await getBuiltInCommandNames()

expect(names).toHaveLength(1)
expect(names).toEqual(expect.arrayContaining(["init"]))
// Order doesn't matter since it's based on filesystem order
expect(names.sort()).toEqual(["init"])
})

it("should return array of strings", async () => {
const names = await getBuiltInCommandNames()

names.forEach((name) => {
expect(typeof name).toBe("string")
expect(name.length).toBeGreaterThan(0)
})
})
})

describe("Command Content Validation", () => {
it("init command should have comprehensive content", async () => {
const command = await getBuiltInCommand("init")
const content = command!.content

// Should contain key sections
expect(content).toContain("Please analyze this codebase")
expect(content).toContain("Build/lint/test commands")
expect(content).toContain("Code style guidelines")
expect(content).toContain("mode-specific rule directories")
expect(content).toContain("analysis_workflow")

// Should mention important concepts
expect(content).toContain("AGENTS.md")
expect(content).toContain(".roo/rules-")
expect(content).toContain("rules-code")
expect(content).toContain("rules-debug")
expect(content).toContain("rules-ask")
expect(content).toContain("rules-architect")
})
})
})
5 changes: 5 additions & 0 deletions src/services/command/__tests__/frontmatter-commands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ vi.mock("../roo-config", () => ({
getGlobalRooDirectory: vi.fn(() => "/mock/global/.roo"),
getProjectRooDirectoryForCwd: vi.fn(() => "/mock/project/.roo"),
}))
vi.mock("../built-in-commands", () => ({
getBuiltInCommands: vi.fn(() => Promise.resolve([])),
getBuiltInCommand: vi.fn(() => Promise.resolve(undefined)),
getBuiltInCommandNames: vi.fn(() => Promise.resolve([])),
}))

const mockFs = vi.mocked(fs)

Expand Down
Loading
Loading