|
| 1 | +import { getSharedToolUseSection } from "../tool-use" |
| 2 | +import { TOOL_PROTOCOL } from "@roo-code/types" |
| 3 | + |
| 4 | +describe("getSharedToolUseSection", () => { |
| 5 | + describe("XML protocol", () => { |
| 6 | + it("should include one tool per message requirement", () => { |
| 7 | + const section = getSharedToolUseSection(TOOL_PROTOCOL.XML) |
| 8 | + |
| 9 | + expect(section).toContain("You must use exactly one tool per message") |
| 10 | + expect(section).toContain("every assistant message must include a tool call") |
| 11 | + }) |
| 12 | + |
| 13 | + it("should include XML formatting instructions", () => { |
| 14 | + const section = getSharedToolUseSection(TOOL_PROTOCOL.XML) |
| 15 | + |
| 16 | + expect(section).toContain("XML-style tags") |
| 17 | + expect(section).toContain("Always use the actual tool name as the XML tag name") |
| 18 | + }) |
| 19 | + }) |
| 20 | + |
| 21 | + describe("native protocol", () => { |
| 22 | + it("should include one tool per message requirement when experiment is disabled", () => { |
| 23 | + // No experiment flags passed (default: disabled) |
| 24 | + const section = getSharedToolUseSection(TOOL_PROTOCOL.NATIVE) |
| 25 | + |
| 26 | + expect(section).toContain("You must use exactly one tool call per assistant response") |
| 27 | + expect(section).toContain("Do not call zero tools or more than one tool") |
| 28 | + }) |
| 29 | + |
| 30 | + it("should include one tool per message requirement when experiment is explicitly disabled", () => { |
| 31 | + const section = getSharedToolUseSection(TOOL_PROTOCOL.NATIVE, { multipleNativeToolCalls: false }) |
| 32 | + |
| 33 | + expect(section).toContain("You must use exactly one tool call per assistant response") |
| 34 | + expect(section).toContain("Do not call zero tools or more than one tool") |
| 35 | + }) |
| 36 | + |
| 37 | + it("should NOT include one tool per message requirement when experiment is enabled", () => { |
| 38 | + const section = getSharedToolUseSection(TOOL_PROTOCOL.NATIVE, { multipleNativeToolCalls: true }) |
| 39 | + |
| 40 | + expect(section).not.toContain("You must use exactly one tool per message") |
| 41 | + expect(section).not.toContain("every assistant message must include a tool call") |
| 42 | + expect(section).toContain("You must call at least one tool per assistant response") |
| 43 | + expect(section).toContain("Prefer calling as many tools as are reasonably needed") |
| 44 | + }) |
| 45 | + |
| 46 | + it("should include native tool-calling instructions", () => { |
| 47 | + const section = getSharedToolUseSection(TOOL_PROTOCOL.NATIVE) |
| 48 | + |
| 49 | + expect(section).toContain("provider-native tool-calling mechanism") |
| 50 | + expect(section).toContain("Do not include XML markup or examples") |
| 51 | + }) |
| 52 | + |
| 53 | + it("should NOT include XML formatting instructions", () => { |
| 54 | + const section = getSharedToolUseSection(TOOL_PROTOCOL.NATIVE) |
| 55 | + |
| 56 | + expect(section).not.toContain("XML-style tags") |
| 57 | + expect(section).not.toContain("Always use the actual tool name as the XML tag name") |
| 58 | + }) |
| 59 | + }) |
| 60 | + |
| 61 | + describe("default protocol", () => { |
| 62 | + it("should default to XML protocol when no protocol is specified", () => { |
| 63 | + const section = getSharedToolUseSection() |
| 64 | + |
| 65 | + expect(section).toContain("XML-style tags") |
| 66 | + expect(section).toContain("You must use exactly one tool per message") |
| 67 | + }) |
| 68 | + }) |
| 69 | +}) |
0 commit comments