Elffuss BraidHub

kikocis/continue public

627d7d0d1f85 · 7.0 KiBRawPermalink
1import { RuleWithSource } from "../..";
2import { getRequestRuleDescription } from "./requestRule";
3
4describe("getRequestRuleDescription", () => {
5 it("should return no rules message when no agent-requested rules exist", () => {
6 const rules: RuleWithSource[] = [
7 {
8 name: "Always Apply Rule",
9 description: "This rule always applies",
10 source: "default-chat",
11 rule: "Always use semicolons",
12 alwaysApply: true,
13 ruleFile: "/path/to/rule1.md",
14 },
15 {
16 name: "Rule with Globs",
17 description: "This rule has globs",
18 source: "rules-block",
19 rule: "Use TypeScript",
20 globs: "**/*.ts",
21 ruleFile: "/path/to/rule2.md",
22 },
23 ];
24
25 const result = getRequestRuleDescription(rules);
26
27 expect(result).toBe(
28 "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\nNo rules available.",
29 );
30 });
31
32 it("should return formatted rules when agent-requested rules exist", () => {
33 const rules: RuleWithSource[] = [
34 {
35 name: "Agent Rule 1",
36 description: "First agent-requested rule",
37 source: "rules-block",
38 rule: "Use consistent formatting",
39 alwaysApply: false,
40 ruleFile: "/path/to/agent-rule1.md",
41 },
42 {
43 name: "Agent Rule 2",
44 description: "Second agent-requested rule",
45 source: "default-agent",
46 rule: "Follow naming conventions",
47 alwaysApply: false,
48 ruleFile: "/path/to/agent-rule2.md",
49 },
50 // These should be filtered out
51 {
52 name: "Always Apply Rule",
53 description: "This rule always applies",
54 source: "default-chat",
55 rule: "Always use semicolons",
56 alwaysApply: true,
57 ruleFile: "/path/to/rule1.md",
58 },
59 {
60 name: "Rule with Globs",
61 description: "This rule has globs",
62 source: "rules-block",
63 rule: "Use TypeScript",
64 globs: "**/*.ts",
65 ruleFile: "/path/to/rule2.md",
66 },
67 ];
68
69 const result = getRequestRuleDescription(rules);
70
71 const expected =
72 "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" +
73 "Agent Rule 1: First agent-requested rule\n" +
74 "Agent Rule 2: Second agent-requested rule";
75
76 expect(result).toBe(expected);
77 });
78
79 it("should handle rules with missing description", () => {
80 const rules: RuleWithSource[] = [
81 {
82 name: "Rule Without Description",
83 source: "rules-block",
84 rule: "Some rule content",
85 alwaysApply: false,
86 ruleFile: "/path/to/no-desc-rule.md",
87 },
88 ];
89
90 const result = getRequestRuleDescription(rules);
91
92 const expected =
93 "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" +
94 "Rule Without Description: undefined";
95
96 expect(result).toBe(expected);
97 });
98
99 it("should handle rules with missing name", () => {
100 const rules: RuleWithSource[] = [
101 {
102 description: "Rule without name",
103 source: "rules-block",
104 rule: "Some rule content",
105 alwaysApply: false,
106 ruleFile: "/path/to/no-name-rule.md",
107 },
108 ];
109
110 const result = getRequestRuleDescription(rules);
111
112 const expected =
113 "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" +
114 "undefined: Rule without name";
115
116 expect(result).toBe(expected);
117 });
118
119 it("should handle rules with missing ruleFile", () => {
120 const rules: RuleWithSource[] = [
121 {
122 name: "Rule Without File",
123 description: "Rule without file path",
124 source: "rules-block",
125 rule: "Some rule content",
126 alwaysApply: false,
127 },
128 ];
129
130 const result = getRequestRuleDescription(rules);
131
132 const expected =
133 "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" +
134 "Rule Without File: Rule without file path";
135
136 expect(result).toBe(expected);
137 });
138
139 it("should filter out rules with alwaysApply undefined (truthy)", () => {
140 const rules: RuleWithSource[] = [
141 {
142 name: "Rule with undefined alwaysApply",
143 description: "This should be filtered out",
144 source: "rules-block",
145 rule: "Some rule",
146 ruleFile: "/path/to/rule.md",
147 // alwaysApply is undefined, which is truthy in the filter condition
148 },
149 {
150 name: "Valid Agent Rule",
151 description: "This should be included",
152 source: "rules-block",
153 rule: "Some rule",
154 alwaysApply: false,
155 ruleFile: "/path/to/valid-rule.md",
156 },
157 ];
158
159 const result = getRequestRuleDescription(rules);
160
161 const expected =
162 "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" +
163 "Valid Agent Rule: This should be included";
164
165 expect(result).toBe(expected);
166 });
167
168 it("should filter out rules with any globs defined", () => {
169 const rules: RuleWithSource[] = [
170 {
171 name: "Rule with string globs",
172 description: "This should be filtered out",
173 source: "rules-block",
174 rule: "Some rule",
175 alwaysApply: false,
176 globs: "**/*.ts",
177 ruleFile: "/path/to/rule1.md",
178 },
179 {
180 name: "Rule with array globs",
181 description: "This should also be filtered out",
182 source: "rules-block",
183 rule: "Some rule",
184 alwaysApply: false,
185 globs: ["**/*.ts", "**/*.js"],
186 ruleFile: "/path/to/rule2.md",
187 },
188 {
189 name: "Valid Agent Rule",
190 description: "This should be included",
191 source: "rules-block",
192 rule: "Some rule",
193 alwaysApply: false,
194 ruleFile: "/path/to/valid-rule.md",
195 },
196 ];
197
198 const result = getRequestRuleDescription(rules);
199
200 const expected =
201 "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" +
202 "Valid Agent Rule: This should be included";
203
204 expect(result).toBe(expected);
205 });
206
207 it("should handle empty rules array", () => {
208 const rules: RuleWithSource[] = [];
209
210 const result = getRequestRuleDescription(rules);
211
212 expect(result).toBe(
213 "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\nNo rules available.",
214 );
215 });
216
217 it("should handle single agent-requested rule", () => {
218 const rules: RuleWithSource[] = [
219 {
220 name: "Single Rule",
221 description: "The only agent-requested rule",
222 source: "rules-block",
223 rule: "Follow this guideline",
224 alwaysApply: false,
225 ruleFile: "/path/to/single-rule.md",
226 },
227 ];
228
229 const result = getRequestRuleDescription(rules);
230
231 const expected =
232 "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" +
233 "Single Rule: The only agent-requested rule";
234
235 expect(result).toBe(expected);
236 });
237});