Elffuss BraidHub

kikocis/continue public

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