test: invokable rules
This commit is contained in:
parent
21f78907c3
commit
91a475a290
2 changed files with 101 additions and 0 deletions
78
core/commands/slash/ruleBlockSlashCommand.vitest.ts
Normal file
78
core/commands/slash/ruleBlockSlashCommand.vitest.ts
Normal file
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
@ -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"
|
||||
Loading…
Add table
Reference in a new issue