ToolMapper.test.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /**
  2. * Unit tests for ToolMapper
  3. *
  4. * Tests tool name mapping between OAC and other platforms.
  5. */
  6. import { describe, it, expect } from "vitest";
  7. import {
  8. mapToolToOAC,
  9. mapToolFromOAC,
  10. mapToolAccessFromOAC,
  11. mapToolAccessToOAC,
  12. getSupportedTools,
  13. getUnsupportedTools,
  14. isToolSupported,
  15. } from "../../../src/mappers/ToolMapper";
  16. describe("ToolMapper", () => {
  17. // ==========================================================================
  18. // mapToolFromOAC - OAC to Platform
  19. // ==========================================================================
  20. describe("mapToolFromOAC()", () => {
  21. describe("Claude platform", () => {
  22. it("maps bash to Bash", () => {
  23. const result = mapToolFromOAC("bash", "claude");
  24. expect(result.name).toBe("Bash");
  25. expect(result.exact).toBe(true);
  26. expect(result.warning).toBeUndefined();
  27. });
  28. it("maps read to Read", () => {
  29. const result = mapToolFromOAC("read", "claude");
  30. expect(result.name).toBe("Read");
  31. expect(result.exact).toBe(true);
  32. });
  33. it("maps write to Write", () => {
  34. const result = mapToolFromOAC("write", "claude");
  35. expect(result.name).toBe("Write");
  36. expect(result.exact).toBe(true);
  37. });
  38. it("maps edit to Edit", () => {
  39. const result = mapToolFromOAC("edit", "claude");
  40. expect(result.name).toBe("Edit");
  41. expect(result.exact).toBe(true);
  42. });
  43. it("maps task to Task", () => {
  44. const result = mapToolFromOAC("task", "claude");
  45. expect(result.name).toBe("Task");
  46. expect(result.exact).toBe(true);
  47. });
  48. it("maps patch to Edit (Claude uses Edit for patching)", () => {
  49. const result = mapToolFromOAC("patch", "claude");
  50. expect(result.name).toBe("Edit");
  51. expect(result.exact).toBe(true);
  52. });
  53. });
  54. describe("Cursor platform", () => {
  55. it("maps bash to terminal", () => {
  56. const result = mapToolFromOAC("bash", "cursor");
  57. expect(result.name).toBe("terminal");
  58. expect(result.exact).toBe(true);
  59. });
  60. it("maps read to file_read", () => {
  61. const result = mapToolFromOAC("read", "cursor");
  62. expect(result.name).toBe("file_read");
  63. expect(result.exact).toBe(true);
  64. });
  65. it("maps grep to content_search", () => {
  66. const result = mapToolFromOAC("grep", "cursor");
  67. expect(result.name).toBe("content_search");
  68. expect(result.exact).toBe(true);
  69. });
  70. it("warns about unsupported task tool", () => {
  71. const result = mapToolFromOAC("task", "cursor");
  72. expect(result.exact).toBe(false);
  73. expect(result.warning).toContain("not supported");
  74. });
  75. });
  76. describe("Windsurf platform", () => {
  77. it("maps bash to shell", () => {
  78. const result = mapToolFromOAC("bash", "windsurf");
  79. expect(result.name).toBe("shell");
  80. expect(result.exact).toBe(true);
  81. });
  82. it("maps task to delegate", () => {
  83. const result = mapToolFromOAC("task", "windsurf");
  84. expect(result.name).toBe("delegate");
  85. expect(result.exact).toBe(true);
  86. });
  87. it("maps glob to find_files", () => {
  88. const result = mapToolFromOAC("glob", "windsurf");
  89. expect(result.name).toBe("find_files");
  90. expect(result.exact).toBe(true);
  91. });
  92. });
  93. describe("unknown tools", () => {
  94. it("returns tool name as-is with warning for unknown tools", () => {
  95. const result = mapToolFromOAC("unknown_tool", "claude");
  96. expect(result.name).toBe("unknown_tool");
  97. expect(result.exact).toBe(false);
  98. expect(result.warning).toContain("No mapping");
  99. });
  100. });
  101. });
  102. // ==========================================================================
  103. // mapToolToOAC - Platform to OAC
  104. // ==========================================================================
  105. describe("mapToolToOAC()", () => {
  106. describe("from Claude", () => {
  107. it("maps Bash to bash", () => {
  108. const result = mapToolToOAC("Bash", "claude");
  109. expect(result.name).toBe("bash");
  110. expect(result.exact).toBe(true);
  111. });
  112. it("maps Read to read", () => {
  113. const result = mapToolToOAC("Read", "claude");
  114. expect(result.name).toBe("read");
  115. expect(result.exact).toBe(true);
  116. });
  117. it("maps WebSearch to bash (approximation)", () => {
  118. const result = mapToolToOAC("WebSearch", "claude");
  119. expect(result.name).toBe("bash");
  120. expect(result.exact).toBe(true);
  121. });
  122. });
  123. describe("from Cursor", () => {
  124. it("maps terminal to bash", () => {
  125. const result = mapToolToOAC("terminal", "cursor");
  126. expect(result.name).toBe("bash");
  127. expect(result.exact).toBe(true);
  128. });
  129. it("maps file_read to read", () => {
  130. const result = mapToolToOAC("file_read", "cursor");
  131. expect(result.name).toBe("read");
  132. expect(result.exact).toBe(true);
  133. });
  134. it("maps content_search to grep", () => {
  135. const result = mapToolToOAC("content_search", "cursor");
  136. expect(result.name).toBe("grep");
  137. expect(result.exact).toBe(true);
  138. });
  139. });
  140. describe("from Windsurf", () => {
  141. it("maps shell to bash", () => {
  142. const result = mapToolToOAC("shell", "windsurf");
  143. expect(result.name).toBe("bash");
  144. expect(result.exact).toBe(true);
  145. });
  146. it("maps delegate to task", () => {
  147. const result = mapToolToOAC("delegate", "windsurf");
  148. expect(result.name).toBe("task");
  149. expect(result.exact).toBe(true);
  150. });
  151. });
  152. describe("unknown tools", () => {
  153. it("returns lowercase version with warning", () => {
  154. const result = mapToolToOAC("UnknownTool", "claude");
  155. expect(result.name).toBe("unknowntool");
  156. expect(result.exact).toBe(false);
  157. expect(result.warning).toContain("Unknown tool");
  158. });
  159. });
  160. });
  161. // ==========================================================================
  162. // mapToolAccessFromOAC - Batch OAC to Platform
  163. // ==========================================================================
  164. describe("mapToolAccessFromOAC()", () => {
  165. it("maps multiple tools at once", () => {
  166. const tools = { bash: true, read: true, write: false };
  167. const result = mapToolAccessFromOAC(tools, "claude");
  168. expect(result.tools["Bash"]).toBe(true);
  169. expect(result.tools["Read"]).toBe(true);
  170. expect(result.tools["Write"]).toBe(false);
  171. expect(result.warnings).toHaveLength(0);
  172. });
  173. it("skips undefined tools", () => {
  174. const tools = { bash: true, read: undefined };
  175. const result = mapToolAccessFromOAC(tools, "claude");
  176. expect(result.tools["Bash"]).toBe(true);
  177. expect(result.tools["Read"]).toBeUndefined();
  178. });
  179. it("collects warnings for unsupported tools", () => {
  180. const tools = { task: true };
  181. const result = mapToolAccessFromOAC(tools, "cursor");
  182. expect(result.warnings.length).toBeGreaterThan(0);
  183. expect(result.warnings[0]).toContain("not supported");
  184. });
  185. });
  186. // ==========================================================================
  187. // mapToolAccessToOAC - Batch Platform to OAC
  188. // ==========================================================================
  189. describe("mapToolAccessToOAC()", () => {
  190. it("maps multiple tools back to OAC format", () => {
  191. const tools = { terminal: true, file_read: true, file_write: false };
  192. const result = mapToolAccessToOAC(tools, "cursor");
  193. expect(result.tools.bash).toBe(true);
  194. expect(result.tools.read).toBe(true);
  195. expect(result.tools.write).toBe(false);
  196. });
  197. it("handles unknown tools with warnings", () => {
  198. const tools = { unknown_tool: true };
  199. const result = mapToolAccessToOAC(tools, "cursor");
  200. expect(result.warnings.length).toBeGreaterThan(0);
  201. });
  202. });
  203. // ==========================================================================
  204. // Utility Functions
  205. // ==========================================================================
  206. describe("getSupportedTools()", () => {
  207. it("returns list of supported tools for Claude", () => {
  208. const tools = getSupportedTools("claude");
  209. expect(tools).toContain("bash");
  210. expect(tools).toContain("read");
  211. expect(tools).toContain("task");
  212. });
  213. it("returns list of supported tools for Cursor", () => {
  214. const tools = getSupportedTools("cursor");
  215. expect(tools).toContain("bash");
  216. expect(tools).toContain("read");
  217. });
  218. });
  219. describe("getUnsupportedTools()", () => {
  220. it("returns empty array for Claude (supports most tools)", () => {
  221. const tools = getUnsupportedTools("claude");
  222. expect(tools).toHaveLength(0);
  223. });
  224. it("returns task for Cursor (no delegation support)", () => {
  225. const tools = getUnsupportedTools("cursor");
  226. expect(tools).toContain("task");
  227. });
  228. });
  229. describe("isToolSupported()", () => {
  230. it("returns true for supported tools", () => {
  231. expect(isToolSupported("bash", "claude")).toBe(true);
  232. expect(isToolSupported("read", "cursor")).toBe(true);
  233. });
  234. it("returns false for unsupported tools", () => {
  235. expect(isToolSupported("task", "cursor")).toBe(false);
  236. });
  237. });
  238. });