Elffuss BraidHub

kikocis/continue public

main · 14.1 KiBRawPermalink
1import { afterEach, beforeEach, describe, expect, it } from "vitest";
2import { walkDirCache } from "../indexing/walkDir";
3import { testIde } from "../test/fixtures";
4import { addToTestDir, setUpTestDir, tearDownTestDir } from "../test/testDir";
5import {
6 getAllDotContinueDefinitionFiles,
7 LoadAssistantFilesOptions,
8} from "./loadLocalAssistants";
9describe("ASSISTANTS getAllDotContinueDefinitionFiles with fileExtType option", () => {
10 beforeEach(() => {
11 setUpTestDir();
12 walkDirCache.invalidate();
13
14 // Add test files to the test directory
15 addToTestDir([
16 ".continue/assistants/",
17 [".continue/assistants/assistant1.yaml", "yaml content 1"],
18 [".continue/assistants/assistant2.yml", "yaml content 2"],
19 [".continue/assistants/assistant3.md", "markdown content 1"],
20 [".continue/assistants/assistant4.txt", "txt content"],
21 [".continue/assistants/config.yaml", "txt content"],
22 [".continue/assistants/config.yml", "txt content"],
23 ]);
24 });
25
26 afterEach(() => {
27 tearDownTestDir();
28 walkDirCache.invalidate();
29 });
30
31 it("should return only YAML files when fileExtType is 'yaml'", async () => {
32 const options: LoadAssistantFilesOptions = {
33 includeGlobal: false, // Only test workspace for simplicity
34 includeWorkspace: true,
35 fileExtType: "yaml",
36 };
37
38 const result = await getAllDotContinueDefinitionFiles(
39 testIde,
40 options,
41 "assistants",
42 );
43 expect(result).toHaveLength(4);
44 expect(result.map((f) => f.path.split("/").pop())).toEqual(
45 expect.arrayContaining([
46 "assistant1.yaml",
47 "assistant2.yml",
48 "config.yaml",
49 "config.yml",
50 ]),
51 );
52 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
53 "assistant3.md",
54 );
55 });
56
57 it("should return only Markdown files when fileExtType is 'markdown'", async () => {
58 const options: LoadAssistantFilesOptions = {
59 includeGlobal: false,
60 includeWorkspace: true,
61 fileExtType: "markdown",
62 };
63
64 const result = await getAllDotContinueDefinitionFiles(
65 testIde,
66 options,
67 "assistants",
68 );
69 expect(result).toHaveLength(1);
70 expect(result.map((f) => f.path.split("/").pop())).toEqual([
71 "assistant3.md",
72 ]);
73 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
74 "assistant1.yaml",
75 );
76 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
77 "assistant2.yml",
78 );
79 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
80 "config.yml",
81 );
82 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
83 "config.yaml",
84 );
85 });
86
87 it("should return all supported files when fileExtType is not specified", async () => {
88 const options: LoadAssistantFilesOptions = {
89 includeGlobal: false,
90 includeWorkspace: true,
91 // fileExtType not specified
92 };
93
94 const result = await getAllDotContinueDefinitionFiles(
95 testIde,
96 options,
97 "assistants",
98 );
99 expect(result).toHaveLength(5);
100 expect(result.map((f) => f.path.split("/").pop())).toEqual(
101 expect.arrayContaining([
102 "assistant1.yaml",
103 "assistant2.yml",
104 "config.yml",
105 "config.yaml",
106 "assistant3.md",
107 ]),
108 );
109 // Should not include .txt files
110 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
111 "assistant4.txt",
112 );
113 });
114
115 it("should respect includeWorkspace option with fileExtType", async () => {
116 // Test with includeWorkspace: false
117 const workspaceOffOptions: LoadAssistantFilesOptions = {
118 includeGlobal: false,
119 includeWorkspace: false,
120 fileExtType: "yaml",
121 };
122
123 const noWorkspaceResult = await getAllDotContinueDefinitionFiles(
124 testIde,
125 workspaceOffOptions,
126 "assistants",
127 );
128 expect(noWorkspaceResult).toHaveLength(0);
129
130 // Test with includeWorkspace: true
131 const workspaceOnOptions: LoadAssistantFilesOptions = {
132 includeGlobal: false,
133 includeWorkspace: true,
134 fileExtType: "yaml",
135 };
136
137 const workspaceResult = await getAllDotContinueDefinitionFiles(
138 testIde,
139 workspaceOnOptions,
140 "assistants",
141 );
142 expect(workspaceResult).toHaveLength(4);
143 expect(workspaceResult.map((f) => f.path.split("/").pop())).toEqual(
144 expect.arrayContaining([
145 "assistant1.yaml",
146 "assistant2.yml",
147 "config.yaml",
148 "config.yml",
149 ]),
150 );
151 });
152
153 it("should return empty array when no files match the specified extension type", async () => {
154 // Create a test directory with only non-matching files
155 tearDownTestDir();
156 walkDirCache.invalidate();
157 setUpTestDir();
158 addToTestDir([
159 ".continue/assistants/",
160 [".continue/assistants/nonmatch1.txt", "txt content"],
161 [".continue/assistants/nonmatch2.json", "json content"],
162 ]);
163
164 const options: LoadAssistantFilesOptions = {
165 includeGlobal: false,
166 includeWorkspace: true,
167
168 fileExtType: "yaml",
169 };
170
171 const result = await getAllDotContinueDefinitionFiles(
172 testIde,
173 options,
174 "assistants",
175 );
176 expect(result).toHaveLength(0);
177 });
178
179 it("should handle directories that don't exist", async () => {
180 // Create a clean test directory without the assistants folder
181 tearDownTestDir();
182 setUpTestDir();
183
184 const options: LoadAssistantFilesOptions = {
185 includeGlobal: false,
186 includeWorkspace: true,
187 fileExtType: "yaml",
188 };
189
190 const result = await getAllDotContinueDefinitionFiles(
191 testIde,
192 options,
193 "assistants",
194 );
195 expect(result).toHaveLength(0);
196 });
197
198 it("should return correct file content", async () => {
199 const options: LoadAssistantFilesOptions = {
200 includeGlobal: false,
201 includeWorkspace: true,
202 fileExtType: "yaml",
203 };
204
205 const result = await getAllDotContinueDefinitionFiles(
206 testIde,
207 options,
208 "assistants",
209 );
210 expect(result).toHaveLength(4);
211 const yamlFile = result.find((f) => f.path.includes("assistant1.yaml"));
212 expect(yamlFile?.content).toBe("yaml content 1");
213 });
214
215 it("should filter by file extension case sensitively", async () => {
216 // Add files with uppercase extensions
217 addToTestDir([
218 [".continue/assistants/assistant5.YAML", "uppercase yaml"],
219 [".continue/assistants/assistant6.YML", "uppercase yml"],
220 [".continue/assistants/assistant7.MD", "uppercase md"],
221 ]);
222
223 const yamlOptions: LoadAssistantFilesOptions = {
224 includeGlobal: false,
225 includeWorkspace: true,
226 fileExtType: "yaml",
227 };
228
229 const yamlResult = await getAllDotContinueDefinitionFiles(
230 testIde,
231 yamlOptions,
232 "assistants",
233 );
234 // Should only get lowercase extensions (current implementation)
235 expect(yamlResult).toHaveLength(4);
236 expect(yamlResult.map((f) => f.path.split("/").pop())).toEqual(
237 expect.arrayContaining([
238 "assistant1.yaml",
239 "assistant2.yml",
240 "config.yaml",
241 "config.yml",
242 ]),
243 );
244 expect(yamlResult.map((f) => f.path.split("/").pop())).not.toContain(
245 "assistant5.YAML",
246 );
247
248 const markdownOptions: LoadAssistantFilesOptions = {
249 includeGlobal: false,
250 includeWorkspace: true,
251 fileExtType: "markdown",
252 };
253
254 const markdownResult = await getAllDotContinueDefinitionFiles(
255 testIde,
256 markdownOptions,
257 "assistants",
258 );
259 expect(markdownResult).toHaveLength(1);
260 expect(markdownResult.map((f) => f.path.split("/").pop())).toEqual([
261 "assistant3.md",
262 ]);
263 expect(markdownResult.map((f) => f.path.split("/").pop())).not.toContain(
264 "assistant7.MD",
265 );
266 });
267});
268
269describe("AGENTS getAllDotContinueDefinitionFiles with fileExtType option", () => {
270 beforeEach(() => {
271 setUpTestDir();
272 walkDirCache.invalidate();
273
274 // Add test files to the test directory
275 addToTestDir([
276 ".continue/agents/",
277 [".continue/agents/agent1.yaml", "yaml content 1"],
278 [".continue/agents/agent2.yml", "yaml content 2"],
279 [".continue/agents/agent3.md", "markdown content 1"],
280 [".continue/agents/agent4.txt", "txt content"],
281 ]);
282 });
283
284 afterEach(() => {
285 tearDownTestDir();
286 walkDirCache.invalidate();
287 });
288
289 it("should return only YAML files when fileExtType is 'yaml'", async () => {
290 const options: LoadAssistantFilesOptions = {
291 includeGlobal: false, // Only test workspace for simplicity
292 includeWorkspace: true,
293 fileExtType: "yaml",
294 };
295
296 const result = await getAllDotContinueDefinitionFiles(
297 testIde,
298 options,
299 "agents",
300 );
301 expect(result).toHaveLength(2);
302 expect(result.map((f) => f.path.split("/").pop())).toEqual(
303 expect.arrayContaining(["agent1.yaml", "agent2.yml"]),
304 );
305 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
306 "agent3.md",
307 );
308 });
309
310 it("should return only Markdown files when fileExtType is 'markdown'", async () => {
311 const options: LoadAssistantFilesOptions = {
312 includeGlobal: false,
313 includeWorkspace: true,
314 fileExtType: "markdown",
315 };
316
317 const result = await getAllDotContinueDefinitionFiles(
318 testIde,
319 options,
320 "agents",
321 );
322 expect(result).toHaveLength(1);
323 expect(result.map((f) => f.path.split("/").pop())).toEqual(["agent3.md"]);
324 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
325 "agent1.yaml",
326 );
327 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
328 "agent2.yml",
329 );
330 });
331
332 it("should return all supported files when fileExtType is not specified", async () => {
333 const options: LoadAssistantFilesOptions = {
334 includeGlobal: false,
335 includeWorkspace: true,
336 // fileExtType not specified
337 };
338
339 const result = await getAllDotContinueDefinitionFiles(
340 testIde,
341 options,
342 "agents",
343 );
344 expect(result).toHaveLength(3);
345 expect(result.map((f) => f.path.split("/").pop())).toEqual(
346 expect.arrayContaining(["agent1.yaml", "agent2.yml", "agent3.md"]),
347 );
348 // Should not include .txt files
349 expect(result.map((f) => f.path.split("/").pop())).not.toContain(
350 "agent4.txt",
351 );
352 });
353
354 it("should respect includeWorkspace option with fileExtType", async () => {
355 // Test with includeWorkspace: false
356 const workspaceOffOptions: LoadAssistantFilesOptions = {
357 includeGlobal: false,
358 includeWorkspace: false,
359 fileExtType: "yaml",
360 };
361
362 const noWorkspaceResult = await getAllDotContinueDefinitionFiles(
363 testIde,
364 workspaceOffOptions,
365 "agents",
366 );
367 expect(noWorkspaceResult).toHaveLength(0);
368
369 // Test with includeWorkspace: true
370 const workspaceOnOptions: LoadAssistantFilesOptions = {
371 includeGlobal: false,
372 includeWorkspace: true,
373 fileExtType: "yaml",
374 };
375
376 const workspaceResult = await getAllDotContinueDefinitionFiles(
377 testIde,
378 workspaceOnOptions,
379 "agents",
380 );
381 expect(workspaceResult).toHaveLength(2);
382 expect(workspaceResult.map((f) => f.path.split("/").pop())).toEqual(
383 expect.arrayContaining(["agent1.yaml", "agent2.yml"]),
384 );
385 });
386
387 it("should return empty array when no files match the specified extension type", async () => {
388 // Create a test directory with only non-matching files
389 tearDownTestDir();
390 walkDirCache.invalidate();
391 setUpTestDir();
392 addToTestDir([
393 ".continue/agents/",
394 [".continue/agents/nonmatch1.txt", "txt content"],
395 [".continue/agents/nonmatch2.json", "json content"],
396 ]);
397
398 const options: LoadAssistantFilesOptions = {
399 includeGlobal: false,
400 includeWorkspace: true,
401
402 fileExtType: "yaml",
403 };
404
405 const result = await getAllDotContinueDefinitionFiles(
406 testIde,
407 options,
408 "agents",
409 );
410 expect(result).toHaveLength(0);
411 });
412
413 it("should handle directories that don't exist", async () => {
414 // Create a clean test directory without the agents folder
415 tearDownTestDir();
416 setUpTestDir();
417
418 const options: LoadAssistantFilesOptions = {
419 includeGlobal: false,
420 includeWorkspace: true,
421 fileExtType: "yaml",
422 };
423
424 const result = await getAllDotContinueDefinitionFiles(
425 testIde,
426 options,
427 "agents",
428 );
429 expect(result).toHaveLength(0);
430 });
431
432 it("should return correct file content", async () => {
433 const options: LoadAssistantFilesOptions = {
434 includeGlobal: false,
435 includeWorkspace: true,
436 fileExtType: "yaml",
437 };
438
439 const result = await getAllDotContinueDefinitionFiles(
440 testIde,
441 options,
442 "agents",
443 );
444 expect(result).toHaveLength(2);
445 const yamlFile = result.find((f) => f.path.includes("agent1.yaml"));
446 expect(yamlFile?.content).toBe("yaml content 1");
447 });
448
449 it("should filter by file extension case sensitively", async () => {
450 // Add files with uppercase extensions
451 addToTestDir([
452 [".continue/agents/agent5.YAML", "uppercase yaml"],
453 [".continue/agents/agent6.YML", "uppercase yml"],
454 [".continue/agents/agent7.MD", "uppercase md"],
455 ]);
456
457 const yamlOptions: LoadAssistantFilesOptions = {
458 includeGlobal: false,
459 includeWorkspace: true,
460 fileExtType: "yaml",
461 };
462
463 const yamlResult = await getAllDotContinueDefinitionFiles(
464 testIde,
465 yamlOptions,
466 "agents",
467 );
468 // Should only get lowercase extensions (current implementation)
469 expect(yamlResult).toHaveLength(2);
470 expect(yamlResult.map((f) => f.path.split("/").pop())).toEqual(
471 expect.arrayContaining(["agent1.yaml", "agent2.yml"]),
472 );
473 expect(yamlResult.map((f) => f.path.split("/").pop())).not.toContain(
474 "agent5.YAML",
475 );
476
477 const markdownOptions: LoadAssistantFilesOptions = {
478 includeGlobal: false,
479 includeWorkspace: true,
480 fileExtType: "markdown",
481 };
482
483 const markdownResult = await getAllDotContinueDefinitionFiles(
484 testIde,
485 markdownOptions,
486 "agents",
487 );
488 expect(markdownResult).toHaveLength(1);
489 expect(markdownResult.map((f) => f.path.split("/").pop())).toEqual([
490 "agent3.md",
491 ]);
492 expect(markdownResult.map((f) => f.path.split("/").pop())).not.toContain(
493 "agent7.MD",
494 );
495 });
496});