|
1 | | -import { describe, it, expect } from "vitest" |
| 1 | +import { describe, it, expect, vi, beforeEach, afterEach } from "vitest" |
2 | 2 | import type OpenAI from "openai" |
3 | 3 | import type { ModeConfig, ModelInfo } from "@roo-code/types" |
4 | 4 | import { filterNativeToolsForMode, filterMcpToolsForMode, applyModelToolCustomization } from "../filter-tools-for-mode" |
| 5 | +import * as toolsModule from "../../../../shared/tools" |
5 | 6 |
|
6 | 7 | describe("filterNativeToolsForMode", () => { |
7 | 8 | const mockNativeTools: OpenAI.Chat.ChatCompletionTool[] = [ |
@@ -621,6 +622,62 @@ describe("filterMcpToolsForMode", () => { |
621 | 622 | expect(result.has("read_file")).toBe(true) |
622 | 623 | expect(result.has("custom_edit_tool")).toBe(false) |
623 | 624 | }) |
| 625 | + |
| 626 | + describe("with customTools defined in TOOL_GROUPS", () => { |
| 627 | + const originalToolGroups = { ...toolsModule.TOOL_GROUPS } |
| 628 | + |
| 629 | + beforeEach(() => { |
| 630 | + // Add a customTool to the edit group |
| 631 | + ;(toolsModule.TOOL_GROUPS as any).edit = { |
| 632 | + ...originalToolGroups.edit, |
| 633 | + customTools: ["special_edit_tool"], |
| 634 | + } |
| 635 | + }) |
| 636 | + |
| 637 | + afterEach(() => { |
| 638 | + // Restore original TOOL_GROUPS |
| 639 | + ;(toolsModule.TOOL_GROUPS as any).edit = originalToolGroups.edit |
| 640 | + }) |
| 641 | + |
| 642 | + it("should include customTools when explicitly specified in includedTools", () => { |
| 643 | + const tools = new Set(["read_file", "write_to_file"]) |
| 644 | + const modelInfo: ModelInfo = { |
| 645 | + contextWindow: 100000, |
| 646 | + supportsPromptCache: false, |
| 647 | + includedTools: ["special_edit_tool"], // customTool from edit group |
| 648 | + } |
| 649 | + const result = applyModelToolCustomization(tools, codeMode, modelInfo) |
| 650 | + expect(result.has("read_file")).toBe(true) |
| 651 | + expect(result.has("write_to_file")).toBe(true) |
| 652 | + expect(result.has("special_edit_tool")).toBe(true) // customTool should be included |
| 653 | + }) |
| 654 | + |
| 655 | + it("should NOT include customTools when not specified in includedTools", () => { |
| 656 | + const tools = new Set(["read_file", "write_to_file"]) |
| 657 | + const modelInfo: ModelInfo = { |
| 658 | + contextWindow: 100000, |
| 659 | + supportsPromptCache: false, |
| 660 | + // No includedTools specified |
| 661 | + } |
| 662 | + const result = applyModelToolCustomization(tools, codeMode, modelInfo) |
| 663 | + expect(result.has("read_file")).toBe(true) |
| 664 | + expect(result.has("write_to_file")).toBe(true) |
| 665 | + expect(result.has("special_edit_tool")).toBe(false) // customTool should NOT be included by default |
| 666 | + }) |
| 667 | + |
| 668 | + it("should NOT include customTools from groups not allowed by mode", () => { |
| 669 | + const tools = new Set(["read_file"]) |
| 670 | + const modelInfo: ModelInfo = { |
| 671 | + contextWindow: 100000, |
| 672 | + supportsPromptCache: false, |
| 673 | + includedTools: ["special_edit_tool"], // customTool from edit group |
| 674 | + } |
| 675 | + // Architect mode doesn't have edit group |
| 676 | + const result = applyModelToolCustomization(tools, architectMode, modelInfo) |
| 677 | + expect(result.has("read_file")).toBe(true) |
| 678 | + expect(result.has("special_edit_tool")).toBe(false) // customTool should NOT be included |
| 679 | + }) |
| 680 | + }) |
624 | 681 | }) |
625 | 682 |
|
626 | 683 | describe("filterNativeToolsForMode with model customization", () => { |
|
0 commit comments