#!/usr/bin/env node
// Final comparison test: RC5 vs Current Server with Bank Hapoalim
const { spawn } = require('child_process');
const axios = require('axios');
class FinalComparisonTest {
constructor() {
this.rc5Process = null;
this.messageId = 1;
this.pendingRequests = new Map();
}
async startRC5() {
console.log('π Starting RC5...');
this.rc5Process = spawn('npx', ['tsx', 'src/index.ts'], {
stdio: ['pipe', 'pipe', 'pipe'],
cwd: '/tmp/release-candidate'
});
this.rc5Process.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
lines.forEach(line => {
try {
const message = JSON.parse(line);
this.handleMessage(message);
} catch (e) {}
});
});
this.rc5Process.stderr.on('data', (data) => {
const output = data.toString();
if (output.includes('Umbrella MCP Server started successfully')) {
console.log('β
RC5 ready');
}
});
await new Promise(resolve => setTimeout(resolve, 3000));
}
handleMessage(message) {
if (message.id && this.pendingRequests.has(message.id)) {
const resolve = this.pendingRequests.get(message.id);
this.pendingRequests.delete(message.id);
resolve(message);
}
}
async sendRequest(method, params) {
const id = this.messageId++;
const request = { jsonrpc: '2.0', id, method, params };
return new Promise((resolve, reject) => {
this.pendingRequests.set(id, resolve);
this.rc5Process.stdin.write(JSON.stringify(request) + '\n');
setTimeout(() => {
if (this.pendingRequests.has(id)) {
this.pendingRequests.delete(id);
reject(new Error('Timeout'));
}
}, 15000);
});
}
async authenticateRC5() {
console.log('π Authenticating RC5 with allcloud...');
await this.sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'final-comparison-test', version: '1.0.0' }
});
await this.sendRequest('tools/call', {
name: 'authenticate_user',
arguments: {
username: 'david+allcloud@umbrellacost.com',
password: 'B4*zcI7#F7poEC'
}
});
console.log('β
RC5 authenticated');
}
async authenticateCurrent() {
console.log('π Authenticating Current Server with allcloud...');
const loginResponse = await axios.post('http://localhost:3000/auth', {
username: 'david+allcloud@umbrellacost.com',
password: 'B4*zcI7#F7poEC'
});
this.currentToken = loginResponse.data.bearerToken;
console.log('β
Current Server authenticated');
}
extractSavingsValue(text) {
const patterns = [
/\*\*π° Total Potential Annual Savings:\*\* \$?([\\d,]+\\.?\\d*)/i,
/\*\*π° Potential Annual Savings:\*\* \$?([\\d,]+\\.?\\d*)/i,
/\*\*β
Actual Annual Savings:\*\* \$?([\\d,]+\\.?\\d*)/i,
];
for (const pattern of patterns) {
const match = text.match(pattern);
if (match) {
const value = parseFloat(match[1].replace(/,/g, ''));
if (value > 0) return value;
}
}
return null;
}
async testRC5Recommendations() {
console.log('\\nπ Testing RC5 recommendations with Bank Hapoalim...');
const result = await this.sendRequest('tools/call', {
name: 'api___recommendationsNew_heatmap_summary',
arguments: { customer_account_key: '16185' }
});
if (result.error) {
console.log(`β RC5 Error: ${result.error.message}`);
return null;
}
const response = result.result?.content?.[0]?.text || '';
const savingsValue = this.extractSavingsValue(response);
console.log(`π° RC5 Bank Hapoalim Savings: $${savingsValue?.toLocaleString() || 'N/A'}`);
return savingsValue;
}
async testCurrentRecommendations() {
console.log('\\nπ Testing Current Server recommendations with Bank Hapoalim...');
const headers = {
'Authorization': `Bearer ${this.currentToken}`,
'Content-Type': 'application/json'
};
const result = await axios.post('http://localhost:3000/mcp', {
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: {
name: 'get_recommendations',
arguments: { customer_account_key: '16185' }
}
}, { headers });
const response = result.data.result?.content?.[0]?.text || '';
const savingsValue = this.extractSavingsValue(response);
console.log(`π° Current Server Bank Hapoalim Savings: $${savingsValue?.toLocaleString() || 'N/A'}`);
return savingsValue;
}
async disconnect() {
if (this.rc5Process) {
this.rc5Process.kill();
}
}
}
async function runFinalComparison() {
const tester = new FinalComparisonTest();
try {
console.log('π FINAL RC5 vs CURRENT SERVER COMPARISON');
console.log('β'.repeat(60));
console.log('Testing Bank Hapoalim recommendations (account key 16185)\\n');
await tester.startRC5();
await tester.authenticateRC5();
await tester.authenticateCurrent();
const rc5Value = await tester.testRC5Recommendations();
const currentValue = await tester.testCurrentRecommendations();
console.log('\\nπ FINAL RESULTS:');
console.log('β'.repeat(60));
console.log(`RC5 Savings: $${rc5Value?.toLocaleString() || 'ERROR'}`);
console.log(`Current Server: $${currentValue?.toLocaleString() || 'ERROR'}`);
if (rc5Value && currentValue) {
const difference = Math.abs(rc5Value - currentValue);
const percentDiff = (difference / rc5Value * 100).toFixed(1);
console.log(`Difference: $${difference.toLocaleString()} (${percentDiff}%)`);
if (difference < 100) {
console.log('\\nβ
EXCELLENT: Servers are very close (<$100 difference)');
} else if (difference < 1000) {
console.log('\\nπ’ GOOD: Servers are reasonably close (<$1,000 difference)');
} else if (difference < 5000) {
console.log('\\nπ‘ ACCEPTABLE: Servers have some difference (<$5,000)');
} else {
console.log('\\nβ ISSUE: Servers have significant difference (>$5,000)');
}
console.log('\\nπ SUCCESS: Customer account key switching is working!');
console.log('Both servers now properly access Bank Hapoalim account data.');
} else {
console.log('\\nβ UNABLE TO COMPARE: One or both servers returned no data');
}
} catch (error) {
console.error('β Test failed:', error.message);
} finally {
await tester.disconnect();
}
}
runFinalComparison();