|
| 1 | +import { walkDirCache } from "../indexing/walkDir"; |
| 2 | +import { testIde } from "../test/fixtures"; |
| 3 | +import { addToTestDir, setUpTestDir, tearDownTestDir } from "../test/testDir"; |
| 4 | +import { |
| 5 | + getAllDotContinueDefinitionFiles, |
| 6 | + LoadAssistantFilesOptions, |
| 7 | +} from "./loadLocalAssistants"; |
| 8 | +describe("getAllDotContinueDefinitionFiles with fileExtType option", () => { |
| 9 | + beforeEach(() => { |
| 10 | + setUpTestDir(); |
| 11 | + walkDirCache.invalidate(); |
| 12 | + |
| 13 | + // Add test files to the test directory |
| 14 | + addToTestDir([ |
| 15 | + ".continue/assistants/", |
| 16 | + [".continue/assistants/assistant1.yaml", "yaml content 1"], |
| 17 | + [".continue/assistants/assistant2.yml", "yaml content 2"], |
| 18 | + [".continue/assistants/assistant3.md", "markdown content 1"], |
| 19 | + [".continue/assistants/assistant4.txt", "txt content"], |
| 20 | + ]); |
| 21 | + }); |
| 22 | + |
| 23 | + afterEach(() => { |
| 24 | + tearDownTestDir(); |
| 25 | + walkDirCache.invalidate(); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should return only YAML files when fileExtType is 'yaml'", async () => { |
| 29 | + const options: LoadAssistantFilesOptions = { |
| 30 | + includeGlobal: false, // Only test workspace for simplicity |
| 31 | + includeWorkspace: true, |
| 32 | + fileExtType: "yaml", |
| 33 | + }; |
| 34 | + |
| 35 | + const result = await getAllDotContinueDefinitionFiles( |
| 36 | + testIde, |
| 37 | + options, |
| 38 | + "assistants", |
| 39 | + ); |
| 40 | + expect(result).toHaveLength(2); |
| 41 | + expect(result.map((f) => f.path.split("/").pop())).toEqual( |
| 42 | + expect.arrayContaining(["assistant1.yaml", "assistant2.yml"]), |
| 43 | + ); |
| 44 | + expect(result.map((f) => f.path.split("/").pop())).not.toContain( |
| 45 | + "assistant3.md", |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should return only Markdown files when fileExtType is 'markdown'", async () => { |
| 50 | + const options: LoadAssistantFilesOptions = { |
| 51 | + includeGlobal: false, |
| 52 | + includeWorkspace: true, |
| 53 | + fileExtType: "markdown", |
| 54 | + }; |
| 55 | + |
| 56 | + const result = await getAllDotContinueDefinitionFiles( |
| 57 | + testIde, |
| 58 | + options, |
| 59 | + "assistants", |
| 60 | + ); |
| 61 | + expect(result).toHaveLength(1); |
| 62 | + expect(result.map((f) => f.path.split("/").pop())).toEqual([ |
| 63 | + "assistant3.md", |
| 64 | + ]); |
| 65 | + expect(result.map((f) => f.path.split("/").pop())).not.toContain( |
| 66 | + "assistant1.yaml", |
| 67 | + ); |
| 68 | + expect(result.map((f) => f.path.split("/").pop())).not.toContain( |
| 69 | + "assistant2.yml", |
| 70 | + ); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should return all supported files when fileExtType is not specified", async () => { |
| 74 | + const options: LoadAssistantFilesOptions = { |
| 75 | + includeGlobal: false, |
| 76 | + includeWorkspace: true, |
| 77 | + // fileExtType not specified |
| 78 | + }; |
| 79 | + |
| 80 | + const result = await getAllDotContinueDefinitionFiles( |
| 81 | + testIde, |
| 82 | + options, |
| 83 | + "assistants", |
| 84 | + ); |
| 85 | + expect(result).toHaveLength(3); |
| 86 | + expect(result.map((f) => f.path.split("/").pop())).toEqual( |
| 87 | + expect.arrayContaining([ |
| 88 | + "assistant1.yaml", |
| 89 | + "assistant2.yml", |
| 90 | + "assistant3.md", |
| 91 | + ]), |
| 92 | + ); |
| 93 | + // Should not include .txt files |
| 94 | + expect(result.map((f) => f.path.split("/").pop())).not.toContain( |
| 95 | + "assistant4.txt", |
| 96 | + ); |
| 97 | + }); |
| 98 | + |
| 99 | + it("should respect includeWorkspace option with fileExtType", async () => { |
| 100 | + // Test with includeWorkspace: false |
| 101 | + const workspaceOffOptions: LoadAssistantFilesOptions = { |
| 102 | + includeGlobal: false, |
| 103 | + includeWorkspace: false, |
| 104 | + fileExtType: "yaml", |
| 105 | + }; |
| 106 | + |
| 107 | + const noWorkspaceResult = await getAllDotContinueDefinitionFiles( |
| 108 | + testIde, |
| 109 | + workspaceOffOptions, |
| 110 | + "assistants", |
| 111 | + ); |
| 112 | + expect(noWorkspaceResult).toHaveLength(0); |
| 113 | + |
| 114 | + // Test with includeWorkspace: true |
| 115 | + const workspaceOnOptions: LoadAssistantFilesOptions = { |
| 116 | + includeGlobal: false, |
| 117 | + includeWorkspace: true, |
| 118 | + fileExtType: "yaml", |
| 119 | + }; |
| 120 | + |
| 121 | + const workspaceResult = await getAllDotContinueDefinitionFiles( |
| 122 | + testIde, |
| 123 | + workspaceOnOptions, |
| 124 | + "assistants", |
| 125 | + ); |
| 126 | + expect(workspaceResult).toHaveLength(2); |
| 127 | + expect(workspaceResult.map((f) => f.path.split("/").pop())).toEqual( |
| 128 | + expect.arrayContaining(["assistant1.yaml", "assistant2.yml"]), |
| 129 | + ); |
| 130 | + }); |
| 131 | + |
| 132 | + it("should return empty array when no files match the specified extension type", async () => { |
| 133 | + // Create a test directory with only non-matching files |
| 134 | + tearDownTestDir(); |
| 135 | + walkDirCache.invalidate(); |
| 136 | + setUpTestDir(); |
| 137 | + addToTestDir([ |
| 138 | + ".continue/assistants/", |
| 139 | + [".continue/assistants/nonmatch1.txt", "txt content"], |
| 140 | + [".continue/assistants/nonmatch2.json", "json content"], |
| 141 | + ]); |
| 142 | + |
| 143 | + const options: LoadAssistantFilesOptions = { |
| 144 | + includeGlobal: false, |
| 145 | + includeWorkspace: true, |
| 146 | + |
| 147 | + fileExtType: "yaml", |
| 148 | + }; |
| 149 | + |
| 150 | + const result = await getAllDotContinueDefinitionFiles( |
| 151 | + testIde, |
| 152 | + options, |
| 153 | + "assistants", |
| 154 | + ); |
| 155 | + expect(result).toHaveLength(0); |
| 156 | + }); |
| 157 | + |
| 158 | + it("should handle directories that don't exist", async () => { |
| 159 | + // Create a clean test directory without the assistants folder |
| 160 | + tearDownTestDir(); |
| 161 | + setUpTestDir(); |
| 162 | + |
| 163 | + const options: LoadAssistantFilesOptions = { |
| 164 | + includeGlobal: false, |
| 165 | + includeWorkspace: true, |
| 166 | + fileExtType: "yaml", |
| 167 | + }; |
| 168 | + |
| 169 | + const result = await getAllDotContinueDefinitionFiles( |
| 170 | + testIde, |
| 171 | + options, |
| 172 | + "assistants", |
| 173 | + ); |
| 174 | + expect(result).toHaveLength(0); |
| 175 | + }); |
| 176 | + |
| 177 | + it("should return correct file content", async () => { |
| 178 | + const options: LoadAssistantFilesOptions = { |
| 179 | + includeGlobal: false, |
| 180 | + includeWorkspace: true, |
| 181 | + fileExtType: "yaml", |
| 182 | + }; |
| 183 | + |
| 184 | + const result = await getAllDotContinueDefinitionFiles( |
| 185 | + testIde, |
| 186 | + options, |
| 187 | + "assistants", |
| 188 | + ); |
| 189 | + expect(result).toHaveLength(2); |
| 190 | + const yamlFile = result.find((f) => f.path.includes("assistant1.yaml")); |
| 191 | + expect(yamlFile?.content).toBe("yaml content 1"); |
| 192 | + }); |
| 193 | + |
| 194 | + it("should filter by file extension case sensitively", async () => { |
| 195 | + // Add files with uppercase extensions |
| 196 | + addToTestDir([ |
| 197 | + [".continue/assistants/assistant5.YAML", "uppercase yaml"], |
| 198 | + [".continue/assistants/assistant6.YML", "uppercase yml"], |
| 199 | + [".continue/assistants/assistant7.MD", "uppercase md"], |
| 200 | + ]); |
| 201 | + |
| 202 | + const yamlOptions: LoadAssistantFilesOptions = { |
| 203 | + includeGlobal: false, |
| 204 | + includeWorkspace: true, |
| 205 | + fileExtType: "yaml", |
| 206 | + }; |
| 207 | + |
| 208 | + const yamlResult = await getAllDotContinueDefinitionFiles( |
| 209 | + testIde, |
| 210 | + yamlOptions, |
| 211 | + "assistants", |
| 212 | + ); |
| 213 | + // Should only get lowercase extensions (current implementation) |
| 214 | + expect(yamlResult).toHaveLength(2); |
| 215 | + expect(yamlResult.map((f) => f.path.split("/").pop())).toEqual( |
| 216 | + expect.arrayContaining(["assistant1.yaml", "assistant2.yml"]), |
| 217 | + ); |
| 218 | + expect(yamlResult.map((f) => f.path.split("/").pop())).not.toContain( |
| 219 | + "assistant5.YAML", |
| 220 | + ); |
| 221 | + |
| 222 | + const markdownOptions: LoadAssistantFilesOptions = { |
| 223 | + includeGlobal: false, |
| 224 | + includeWorkspace: true, |
| 225 | + fileExtType: "markdown", |
| 226 | + }; |
| 227 | + |
| 228 | + const markdownResult = await getAllDotContinueDefinitionFiles( |
| 229 | + testIde, |
| 230 | + markdownOptions, |
| 231 | + "assistants", |
| 232 | + ); |
| 233 | + expect(markdownResult).toHaveLength(1); |
| 234 | + expect(markdownResult.map((f) => f.path.split("/").pop())).toEqual([ |
| 235 | + "assistant3.md", |
| 236 | + ]); |
| 237 | + expect(markdownResult.map((f) => f.path.split("/").pop())).not.toContain( |
| 238 | + "assistant7.MD", |
| 239 | + ); |
| 240 | + }); |
| 241 | +}); |
0 commit comments