#!/usr/bin/env node
/**
* End-to-end test for ClipSense MCP Server
* Tests the complete workflow: upload → analyze → poll → results
*/
import { ClipSenseClient } from './dist/client.js';
import { ApiKeyManager } from './dist/auth.js';
import { existsSync } from 'fs';
async function main() {
console.log('🧪 ClipSense MCP Server - End-to-End Test\n');
console.log('=' .repeat(60));
// Step 1: Get API key
console.log('\n📋 Step 1: Retrieving API key...');
const keyManager = new ApiKeyManager();
const apiKey = await keyManager.getApiKey();
if (!apiKey) {
console.error('❌ No API key found!');
console.error('Set CLIPSENSE_API_KEY environment variable or run:');
console.error(' export CLIPSENSE_API_KEY="cs_sk_YOUR_KEY_HERE"');
process.exit(1);
}
console.log(`✅ API key found: ${apiKey.substring(0, 12)}...`);
// Step 2: Verify test video exists
console.log('\n📋 Step 2: Checking test video file...');
const testVideos = [
'/Users/jerlitaburanday/Pictures/ASUGradBlastClip.mp4',
'/Users/jerlitaburanday/Pictures/ASUGradBlastClip2.mp4',
];
let testVideo = null;
for (const video of testVideos) {
if (existsSync(video)) {
testVideo = video;
break;
}
}
if (!testVideo) {
console.error('❌ No test video found!');
console.error('Expected videos at:');
testVideos.forEach(v => console.error(` - ${v}`));
process.exit(1);
}
console.log(`✅ Test video found: ${testVideo}`);
// Step 3: Initialize client
console.log('\n📋 Step 3: Initializing ClipSense client...');
const client = new ClipSenseClient(apiKey);
console.log('✅ Client initialized');
// Step 4: Start analysis
console.log('\n📋 Step 4: Starting video analysis...');
console.log('⏳ This will take 2-3 minutes...\n');
try {
const startTime = Date.now();
const result = await client.analyzeVideo(
testVideo,
'Analyze this video and identify any issues or describe what you see.'
);
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
console.log('\n' + '='.repeat(60));
console.log('✅ ANALYSIS COMPLETE');
console.log('='.repeat(60));
console.log(`\n📊 Job ID: ${result.jobId}`);
console.log(`⏱️ Duration: ${duration}s\n`);
console.log('📝 Analysis Result:\n');
console.log(result.analysis);
console.log('\n' + '='.repeat(60));
console.log('✅ End-to-end test PASSED');
console.log('='.repeat(60));
} catch (error) {
console.error('\n' + '='.repeat(60));
console.error('❌ ANALYSIS FAILED');
console.error('='.repeat(60));
console.error(`\nError: ${error.message}`);
if (error.response) {
console.error(`Status: ${error.response.status}`);
console.error(`Response: ${JSON.stringify(error.response.data, null, 2)}`);
}
console.error('\n' + '='.repeat(60));
console.error('❌ End-to-end test FAILED');
console.error('='.repeat(60));
process.exit(1);
}
}
main().catch(error => {
console.error('Fatal error:', error);
process.exit(1);
});