Skip to content

Commit 43ecbd7

Browse files
committed
test: add tests for including customTools via includedTools
1 parent 37ed25e commit 43ecbd7

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

src/core/prompts/tools/__tests__/filter-tools-for-mode.spec.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { describe, it, expect } from "vitest"
1+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"
22
import type OpenAI from "openai"
33
import type { ModeConfig, ModelInfo } from "@roo-code/types"
44
import { filterNativeToolsForMode, filterMcpToolsForMode, applyModelToolCustomization } from "../filter-tools-for-mode"
5+
import * as toolsModule from "../../../../shared/tools"
56

67
describe("filterNativeToolsForMode", () => {
78
const mockNativeTools: OpenAI.Chat.ChatCompletionTool[] = [
@@ -621,6 +622,62 @@ describe("filterMcpToolsForMode", () => {
621622
expect(result.has("read_file")).toBe(true)
622623
expect(result.has("custom_edit_tool")).toBe(false)
623624
})
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+
})
624681
})
625682

626683
describe("filterNativeToolsForMode with model customization", () => {

0 commit comments

Comments
 (0)