|
6 | 6 | getAllDotContinueDefinitionFiles, |
7 | 7 | LoadAssistantFilesOptions, |
8 | 8 | } from "./loadLocalAssistants"; |
9 | | -describe("getAllDotContinueDefinitionFiles with fileExtType option", () => { |
| 9 | +describe("ASSISTANTS getAllDotContinueDefinitionFiles with fileExtType option", () => { |
10 | 10 | beforeEach(() => { |
11 | 11 | setUpTestDir(); |
12 | 12 | walkDirCache.invalidate(); |
@@ -240,3 +240,232 @@ describe("getAllDotContinueDefinitionFiles with fileExtType option", () => { |
240 | 240 | ); |
241 | 241 | }); |
242 | 242 | }); |
| 243 | + |
| 244 | +describe("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 | +}); |
0 commit comments