| 1 | import { describe, expect, it } from "@jest/globals"; |
| 2 | import { ConfigDependentToolParams, GetTool, Tool } from "../.."; |
| 3 | import * as toolDefinitions from "./index"; |
| 4 | |
| 5 | describe("Tool Definitions", () => { |
| 6 | // Mock params for tools that need them |
| 7 | const mockParams: ConfigDependentToolParams = { |
| 8 | rules: [], |
| 9 | enableExperimentalTools: false, |
| 10 | isSignedIn: false, |
| 11 | isRemote: false, |
| 12 | modelName: "a model", |
| 13 | }; |
| 14 | |
| 15 | // Helper function to get the actual tool object |
| 16 | const getToolObject = (toolDefinition: Tool | GetTool): Tool => { |
| 17 | if (typeof toolDefinition === "function") { |
| 18 | return toolDefinition(mockParams); |
| 19 | } |
| 20 | return toolDefinition; |
| 21 | }; |
| 22 | |
| 23 | it("should have all required parameters defined in properties for each tool", () => { |
| 24 | const exportedTools = Object.values(toolDefinitions); |
| 25 | |
| 26 | exportedTools.forEach((toolDefinition) => { |
| 27 | const tool = getToolObject(toolDefinition); |
| 28 | |
| 29 | // Each tool should have the required structure |
| 30 | expect(tool).toHaveProperty("type", "function"); |
| 31 | expect(tool).toHaveProperty("function"); |
| 32 | expect(tool.function).toHaveProperty("parameters"); |
| 33 | |
| 34 | const parameters = tool.function.parameters; |
| 35 | |
| 36 | // If there are required parameters, they should be defined in properties |
| 37 | if ( |
| 38 | parameters && |
| 39 | parameters.required && |
| 40 | Array.isArray(parameters.required) |
| 41 | ) { |
| 42 | expect(parameters).toHaveProperty("properties"); |
| 43 | expect(typeof parameters.properties).toBe("object"); |
| 44 | |
| 45 | // Check each required parameter is defined in properties |
| 46 | parameters.required.forEach((requiredParam: string) => { |
| 47 | expect(parameters.properties).toHaveProperty(requiredParam); |
| 48 | |
| 49 | // Each property should have at least a type |
| 50 | const property = parameters.properties[requiredParam]; |
| 51 | expect(property).toHaveProperty("type"); |
| 52 | expect(typeof property.type).toBe("string"); |
| 53 | }); |
| 54 | } |
| 55 | }); |
| 56 | }); |
| 57 | }); |