|
| 1 | +import { describe, it, expect } from "vitest" |
| 2 | +import { getBuiltInCommands, getBuiltInCommand, getBuiltInCommandNames } from "../built-in-commands" |
| 3 | + |
| 4 | +describe("Built-in Commands", () => { |
| 5 | + describe("getBuiltInCommands", () => { |
| 6 | + it("should return all built-in commands", async () => { |
| 7 | + const commands = await getBuiltInCommands() |
| 8 | + |
| 9 | + expect(commands).toHaveLength(2) |
| 10 | + expect(commands.map((cmd) => cmd.name)).toEqual(expect.arrayContaining(["init", "create-mode"])) |
| 11 | + |
| 12 | + // Verify all commands have required properties |
| 13 | + commands.forEach((command) => { |
| 14 | + expect(command.name).toBeDefined() |
| 15 | + expect(typeof command.name).toBe("string") |
| 16 | + expect(command.content).toBeDefined() |
| 17 | + expect(typeof command.content).toBe("string") |
| 18 | + expect(command.source).toBe("built-in") |
| 19 | + expect(command.filePath).toMatch(/^<built-in:.+>$/) |
| 20 | + expect(command.description).toBeDefined() |
| 21 | + expect(typeof command.description).toBe("string") |
| 22 | + }) |
| 23 | + }) |
| 24 | + |
| 25 | + it("should return commands with proper content", async () => { |
| 26 | + const commands = await getBuiltInCommands() |
| 27 | + |
| 28 | + const initCommand = commands.find((cmd) => cmd.name === "init") |
| 29 | + expect(initCommand).toBeDefined() |
| 30 | + expect(initCommand!.content).toContain("Initialize Roo Project") |
| 31 | + expect(initCommand!.content).toContain(".roo/rules/") |
| 32 | + expect(initCommand!.description).toBe("Initialize a Roo project with recommended rules and configuration") |
| 33 | + |
| 34 | + const createModeCommand = commands.find((cmd) => cmd.name === "create-mode") |
| 35 | + expect(createModeCommand).toBeDefined() |
| 36 | + expect(createModeCommand!.content).toContain("Create a Custom Mode") |
| 37 | + expect(createModeCommand!.content).toContain("YAML") |
| 38 | + expect(createModeCommand!.description).toBe("Create a custom mode for specialized AI assistance") |
| 39 | + }) |
| 40 | + }) |
| 41 | + |
| 42 | + describe("getBuiltInCommand", () => { |
| 43 | + it("should return specific built-in command by name", async () => { |
| 44 | + const initCommand = await getBuiltInCommand("init") |
| 45 | + |
| 46 | + expect(initCommand).toBeDefined() |
| 47 | + expect(initCommand!.name).toBe("init") |
| 48 | + expect(initCommand!.source).toBe("built-in") |
| 49 | + expect(initCommand!.filePath).toBe("<built-in:init>") |
| 50 | + expect(initCommand!.content).toContain("Initialize Roo Project") |
| 51 | + expect(initCommand!.description).toBe("Initialize a Roo project with recommended rules and configuration") |
| 52 | + }) |
| 53 | + |
| 54 | + it("should return create-mode command", async () => { |
| 55 | + const createModeCommand = await getBuiltInCommand("create-mode") |
| 56 | + |
| 57 | + expect(createModeCommand).toBeDefined() |
| 58 | + expect(createModeCommand!.name).toBe("create-mode") |
| 59 | + expect(createModeCommand!.source).toBe("built-in") |
| 60 | + expect(createModeCommand!.filePath).toBe("<built-in:create-mode>") |
| 61 | + expect(createModeCommand!.content).toContain("Create a Custom Mode") |
| 62 | + expect(createModeCommand!.description).toBe("Create a custom mode for specialized AI assistance") |
| 63 | + }) |
| 64 | + |
| 65 | + it("should return undefined for non-existent command", async () => { |
| 66 | + const nonExistentCommand = await getBuiltInCommand("non-existent") |
| 67 | + expect(nonExistentCommand).toBeUndefined() |
| 68 | + }) |
| 69 | + |
| 70 | + it("should handle empty string command name", async () => { |
| 71 | + const emptyCommand = await getBuiltInCommand("") |
| 72 | + expect(emptyCommand).toBeUndefined() |
| 73 | + }) |
| 74 | + }) |
| 75 | + |
| 76 | + describe("getBuiltInCommandNames", () => { |
| 77 | + it("should return all built-in command names", async () => { |
| 78 | + const names = await getBuiltInCommandNames() |
| 79 | + |
| 80 | + expect(names).toHaveLength(2) |
| 81 | + expect(names).toEqual(expect.arrayContaining(["init", "create-mode"])) |
| 82 | + // Order doesn't matter since it's based on filesystem order |
| 83 | + expect(names.sort()).toEqual(["create-mode", "init"]) |
| 84 | + }) |
| 85 | + |
| 86 | + it("should return array of strings", async () => { |
| 87 | + const names = await getBuiltInCommandNames() |
| 88 | + |
| 89 | + names.forEach((name) => { |
| 90 | + expect(typeof name).toBe("string") |
| 91 | + expect(name.length).toBeGreaterThan(0) |
| 92 | + }) |
| 93 | + }) |
| 94 | + }) |
| 95 | + |
| 96 | + describe("Command Content Validation", () => { |
| 97 | + it("init command should have comprehensive content", async () => { |
| 98 | + const command = await getBuiltInCommand("init") |
| 99 | + const content = command!.content |
| 100 | + |
| 101 | + // Should contain key sections |
| 102 | + expect(content).toContain("What this command does:") |
| 103 | + expect(content).toContain("Recommended starter rules:") |
| 104 | + expect(content).toContain("Getting Started:") |
| 105 | + expect(content).toContain("Example rule file structure:") |
| 106 | + |
| 107 | + // Should mention important concepts |
| 108 | + expect(content).toContain("code-style.md") |
| 109 | + expect(content).toContain("project-context.md") |
| 110 | + expect(content).toContain("testing.md") |
| 111 | + expect(content).toContain("@rules") |
| 112 | + }) |
| 113 | + |
| 114 | + it("create-mode command should have comprehensive content", async () => { |
| 115 | + const command = await getBuiltInCommand("create-mode") |
| 116 | + const content = command!.content |
| 117 | + |
| 118 | + // Should contain key sections |
| 119 | + expect(content).toContain("What are Modes?") |
| 120 | + expect(content).toContain("Mode Configuration") |
| 121 | + expect(content).toContain("Mode Properties") |
| 122 | + expect(content).toContain("Creating Your Mode") |
| 123 | + expect(content).toContain("Mode Examples") |
| 124 | + expect(content).toContain("Best Practices") |
| 125 | + |
| 126 | + // Should mention important concepts |
| 127 | + expect(content).toContain("YAML") |
| 128 | + expect(content).toContain("instructions") |
| 129 | + expect(content).toContain("file_restrictions") |
| 130 | + expect(content).toContain("tools") |
| 131 | + }) |
| 132 | + }) |
| 133 | +}) |
0 commit comments