#!/usr/bin/env node
const { spawn } = require('child_process');
const path = require('path');
async function testV2Recommendations() {
console.log('🧪 Testing V2 Recommendations Tool via stdio...\n');
const serverPath = path.join(__dirname, '../../dist/index.js');
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe']
});
let requestId = 1;
// Helper to send request and wait for response
function sendRequest(method, params = {}) {
return new Promise((resolve, reject) => {
const request = {
jsonrpc: '2.0',
method: method,
params: params,
id: requestId++
};
console.log(`📤 Request: ${method}`);
server.stdin.write(JSON.stringify(request) + '\n');
let responseBuffer = '';
function handleData(data) {
responseBuffer += data.toString();
let lines = responseBuffer.split('\n');
responseBuffer = lines.pop() || '';
for (const line of lines) {
if (line.trim()) {
try {
const response = JSON.parse(line);
if (response.id === request.id) {
server.stdout.removeListener('data', handleData);
resolve(response);
return;
}
} catch (e) {
// Continue parsing
}
}
}
}
server.stdout.on('data', handleData);
// Timeout after 30 seconds
setTimeout(() => {
server.stdout.removeListener('data', handleData);
resolve({ error: 'timeout_30s' });
}, 30000);
});
}
try {
// Wait for server to start
await new Promise(resolve => setTimeout(resolve, 1000));
console.log('🔧 Step 1: Initialize');
await sendRequest('initialize', { protocolVersion: '1.0', capabilities: {} });
console.log('🔧 Step 2: Authenticate');
const authResponse = await sendRequest('tools/call', {
name: 'authenticate_user',
arguments: {
username: 'david+saola@umbrellacost.com',
password: 'Dsamsung1!'
}
});
if (authResponse.result) {
console.log('✅ Authentication SUCCESS');
} else {
console.log('❌ Authentication FAILED:', authResponse.error);
return;
}
console.log('\n🔧 Step 3: List tools to check for get_all_recommendations');
const toolsResponse = await sendRequest('tools/list', {});
if (toolsResponse.result && toolsResponse.result.tools) {
const tools = toolsResponse.result.tools;
const recommendationsTool = tools.find(t => t.name === 'get_all_recommendations');
if (recommendationsTool) {
console.log('✅ Found get_all_recommendations tool!');
console.log(' Description:', recommendationsTool.description);
console.log(' Parameters:', Object.keys(recommendationsTool.inputSchema.properties || {}));
} else {
console.log('❌ get_all_recommendations tool NOT FOUND');
console.log('Available tools:', tools.filter(t => t.name.includes('recommend')).map(t => t.name).join(', '));
}
}
console.log('\n🔧 Step 4: Test get_all_recommendations (default - last 30 days)');
const defaultTestStart = Date.now();
const defaultResponse = await sendRequest('tools/call', {
name: 'get_all_recommendations',
arguments: {}
});
const defaultTestTime = Date.now() - defaultTestStart;
if (defaultResponse.result) {
console.log(`✅ Default test SUCCESS (${defaultTestTime}ms)`);
if (defaultResponse.result.content && defaultResponse.result.content[0]) {
const text = defaultResponse.result.content[0].text;
// Extract summary
const lines = text.split('\n');
const summaryLines = lines.filter(line =>
line.includes('Total Recommendations:') ||
line.includes('Total Potential Savings:') ||
line.includes('Date Range:') ||
line.includes('Pages Fetched:')
);
summaryLines.forEach(line => console.log(' ', line.trim()));
}
} else {
console.log('❌ Default test FAILED:', defaultResponse.error);
}
console.log('\n🔧 Step 5: Test with custom parameters (last 7 days)');
const customTestStart = Date.now();
const customResponse = await sendRequest('tools/call', {
name: 'get_all_recommendations',
arguments: {
daysBack: 7,
pageSize: 500
}
});
const customTestTime = Date.now() - customTestStart;
if (customResponse.result) {
console.log(`✅ Custom test SUCCESS (${customTestTime}ms)`);
if (customResponse.result.content && customResponse.result.content[0]) {
const text = customResponse.result.content[0].text;
const lines = text.split('\n');
const summaryLines = lines.filter(line =>
line.includes('Total Recommendations:') ||
line.includes('Total Potential Savings:') ||
line.includes('Date Range:') ||
line.includes('Pages Fetched:')
);
summaryLines.forEach(line => console.log(' ', line.trim()));
}
} else {
console.log('❌ Custom test FAILED:', customResponse.error);
}
console.log('\n🔧 Step 6: Test with closed/done included');
const allTestStart = Date.now();
const allResponse = await sendRequest('tools/call', {
name: 'get_all_recommendations',
arguments: {
daysBack: 30,
includeClosedAndDone: true,
maxPages: 5
}
});
const allTestTime = Date.now() - allTestStart;
if (allResponse.result) {
console.log(`✅ All recommendations test SUCCESS (${allTestTime}ms)`);
if (allResponse.result.content && allResponse.result.content[0]) {
const text = allResponse.result.content[0].text;
const lines = text.split('\n');
const summaryLines = lines.filter(line =>
line.includes('Total Recommendations:') ||
line.includes('Status Filter:') ||
line.includes('Total Potential Savings:') ||
line.includes('Pages Fetched:')
);
summaryLines.forEach(line => console.log(' ', line.trim()));
}
} else {
console.log('❌ All recommendations test FAILED:', allResponse.error);
}
console.log('\n📊 TEST SUMMARY:');
console.log(`⏱️ Default (30 days, open): ${defaultTestTime}ms`);
console.log(`⏱️ Custom (7 days, open): ${customTestTime}ms`);
console.log(`⏱️ All (30 days, all): ${allTestTime}ms`);
} catch (error) {
console.log('❌ Test failed:', error.message);
} finally {
server.kill();
}
}
testV2Recommendations().catch(console.error);