#!/usr/bin/env node /** * Test Tool Execution * Verify that specific tools can be found and executed */ import { ConfigManager } from "./src/config/ConfigManager.js"; import { AuthManager } from "./src/auth/AuthManager.js"; import { ApiClient } from "./src/proxy/ApiClient.js"; import { ToolGenerator } from "./src/tools/ToolGenerator.js"; async function testToolExecution() { try { console.log("๐Ÿงช Testing Tool Execution...\n"); // Initialize components const config = new ConfigManager(); const authManager = new AuthManager(null, config.getAll(true)); const apiClient = new ApiClient(config.getAll(), authManager); const toolGenerator = new ToolGenerator(apiClient); // Generate all tools console.log("๐Ÿ“‹ Generating all tools..."); const allTools = toolGenerator.generateAllTools(); console.log(`โœ… Generated ${allTools.length} tools`); // Test finding specific tool const testToolName = "public_create_login"; console.log(`\n๐Ÿ” Looking for tool: ${testToolName}`); const toolDef = allTools.find((tool) => tool.name === testToolName); if (!toolDef) { console.error(`โŒ Tool ${testToolName} not found in generated tools`); console.log("\n๐Ÿ“‹ Available public tools:"); const publicTools = allTools.filter((tool) => tool.name.startsWith("public_") ); publicTools.slice(0, 10).forEach((tool) => { console.log(` - ${tool.name}`); }); if (publicTools.length > 10) { console.log(` ... and ${publicTools.length - 10} more public tools`); } return false; } console.log(`โœ… Found tool: ${toolDef.name}`); console.log(`๐Ÿ“ Description: ${toolDef.description}`); console.log( `๐Ÿ”ง Input Schema:`, JSON.stringify(toolDef.inputSchema, null, 2) ); // Get the actual tool implementation const tool = toolGenerator.getTool(testToolName); if (!tool || !tool.execute) { console.error(`โŒ Tool ${testToolName} has no execute method`); return false; } console.log(`โœ… Tool has execute method`); console.log(`๐Ÿ“Š Tool details:`, { name: tool.name, authType: tool.authType, endpoint: { path: tool.endpoint.path, method: tool.endpoint.method, controller: tool.endpoint.controller, }, }); // Test tool execution (this will fail due to network, but we can verify the structure) console.log(`\n๐Ÿš€ Testing tool execution structure...`); try { const testParams = { username: "test@example.com", password: "test123", }; console.log(`๐Ÿ“ Test parameters:`, testParams); // This will likely fail due to network/API issues, but we can catch and verify the structure await tool.execute(testParams); console.log(`โœ… Tool execution completed successfully`); } catch (error) { if ( error.message.includes("ENOTFOUND") || error.message.includes("connect") ) { console.log( `โœ… Tool execution structure is correct (network error expected)` ); console.log(`๐Ÿ“‹ Network error: ${error.message}`); } else if ( error.message.includes("Invalid credentials") || error.message.includes("Unauthorized") ) { console.log( `โœ… Tool execution structure is correct (authentication error expected with test credentials)` ); console.log(`๐Ÿ“‹ API response: ${error.message}`); } else { console.error( `โŒ Tool execution failed with unexpected error:`, error.message ); return false; } } console.log("\n๐ŸŽ‰ Tool execution test completed successfully!"); return true; } catch (error) { console.error("โŒ Test failed:", error.message); console.error("๐Ÿ“‹ Stack:", error.stack); return false; } } // Run the test testToolExecution().then((success) => { if (success) { console.log("\nโœ… All tests passed!"); process.exit(0); } else { console.log("\nโŒ Tests failed!"); process.exit(1); } });