Elffuss BraidHub

kikocis/continue public

627d7d0d1f85 · 7.0 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("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});