diff --git a/core/commands/slash/ruleBlockSlashCommand.vitest.ts b/core/commands/slash/ruleBlockSlashCommand.vitest.ts new file mode 100644 index 000000000..2d63e7046 --- /dev/null +++ b/core/commands/slash/ruleBlockSlashCommand.vitest.ts @@ -0,0 +1,78 @@ +import { describe, expect, it } from "vitest"; +import { RuleWithSource } from "../.."; +import { convertRuleBlockToSlashCommand } from "./ruleBlockSlashCommand"; + +describe("convertRuleBlockToSlashCommand", () => { + it("should convert a rule with all properties to a slash command", () => { + const rule: RuleWithSource = { + name: "Code Review", + rule: "Review this code for best practices", + description: "Performs a code review", + source: "rules-block", + ruleFile: "/path/to/rules.yaml", + invokable: true, + }; + + const result = convertRuleBlockToSlashCommand(rule); + + expect(result).toEqual({ + name: "Code Review", + description: "Performs a code review", + prompt: "Review this code for best practices", + source: "invokable-rule", + promptFile: "/path/to/rules.yaml", + }); + }); + + it("should handle a rule without name", () => { + const rule: RuleWithSource = { + rule: "Review this code", + source: "rules-block", + invokable: true, + }; + + const result = convertRuleBlockToSlashCommand(rule); + + expect(result.name).toBe("Unnamed Rule"); + expect(result.prompt).toBe("Review this code"); + }); + + it("should handle a rule without description", () => { + const rule: RuleWithSource = { + name: "Test Rule", + rule: "Test rule content", + source: "rules-block", + invokable: true, + }; + + const result = convertRuleBlockToSlashCommand(rule); + + expect(result.description).toBe(""); + }); + + it("should use rule text as the prompt", () => { + const rule: RuleWithSource = { + name: "Explain Code", + rule: "Explain what this code does in simple terms", + source: "rules-block", + invokable: true, + }; + + const result = convertRuleBlockToSlashCommand(rule); + + expect(result.prompt).toBe("Explain what this code does in simple terms"); + }); + + it("should always set source to 'invokable-rule'", () => { + const rule: RuleWithSource = { + name: "Test", + rule: "Test", + source: "default-chat", + invokable: true, + }; + + const result = convertRuleBlockToSlashCommand(rule); + + expect(result.source).toBe("invokable-rule"); + }); +}); \ No newline at end of file diff --git a/packages/config-yaml/src/__tests__/test-files/invokable-rules.yaml b/packages/config-yaml/src/__tests__/test-files/invokable-rules.yaml new file mode 100644 index 000000000..cccd39457 --- /dev/null +++ b/packages/config-yaml/src/__tests__/test-files/invokable-rules.yaml @@ -0,0 +1,23 @@ +name: Test Invokable Rules +version: 0.0.1 +schema: v1 + +rules: + - name: "Code Review" + rule: "Review this code for best practices and potential issues" + invokable: true + description: "Performs a code review" + + - name: "Explain Code" + rule: "Explain what this code does in simple terms" + invokable: true + + - name: "Regular Rule" + rule: "This is a non-invokable rule" + invokable: false + + - name: "Default Rule" + rule: "This rule has no invokable property" + description: "Should default to non-invokable" + + - "Simple string rule" \ No newline at end of file