-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintegration_test.js
More file actions
194 lines (165 loc) · 4.9 KB
/
integration_test.js
File metadata and controls
194 lines (165 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Integration test for AgentFlow
// Run with: node integration_test.js
const axios = require('axios');
const WebSocket = require('ws');
const chalk = require('chalk');
// Configuration
const API_BASE_URL = 'http://localhost:8000/api';
const WS_URL = 'ws://localhost:8000/ws/agent-updates';
const TEST_TIMEOUT = 30000; // 30 seconds
// Test results
let passedTests = 0;
let failedTests = 0;
// Helper functions
const log = {
info: (msg) => console.log(chalk.blue(`ℹ️ ${msg}`)),
success: (msg) => console.log(chalk.green(`✅ ${msg}`)),
error: (msg) => console.log(chalk.red(`❌ ${msg}`)),
warning: (msg) => console.log(chalk.yellow(`⚠️ ${msg}`))
};
const testApi = async (endpoint, method = 'get', data = null) => {
try {
const config = {
method,
url: `${API_BASE_URL}${endpoint}`,
...(data && { data })
};
const response = await axios(config);
return response.data;
} catch (error) {
throw new Error(`API Error: ${error.message}`);
}
};
const runTest = async (name, testFn) => {
log.info(`Running test: ${name}`);
try {
await testFn();
log.success(`Test passed: ${name}`);
passedTests++;
} catch (error) {
log.error(`Test failed: ${name}`);
log.error(` ${error.message}`);
failedTests++;
}
};
// Tests
const tests = [
// Test 1: Health check
async () => {
const health = await testApi('/health');
if (health.status !== 'healthy') {
throw new Error('Health check failed');
}
},
// Test 2: Agent status
async () => {
const agents = await testApi('/agents/status');
if (!agents || Object.keys(agents).length === 0) {
throw new Error('No agents found');
}
// Check for required agents
const requiredAgents = ['Cofounder', 'Manager', 'Product', 'Finance', 'Marketing', 'Legal'];
for (const agent of requiredAgents) {
if (!agents[agent]) {
throw new Error(`Required agent not found: ${agent}`);
}
}
},
// Test 3: Start conversation
async () => {
const conversation = await testApi('/conversation/start', 'post', {
message: 'Test startup idea for integration testing'
});
if (!conversation.conversation_id) {
throw new Error('No conversation ID returned');
}
if (!conversation.response) {
throw new Error('No response returned');
}
// Store conversation ID for later tests
global.conversationId = conversation.conversation_id;
},
// Test 4: Continue conversation
async () => {
if (!global.conversationId) {
throw new Error('No conversation ID available');
}
const response = await testApi(`/conversation/${global.conversationId}/message`, 'post', {
message: 'This is a follow-up message for testing'
});
if (!response.response) {
throw new Error('No response returned');
}
},
// Test 5: WebSocket connection
async () => {
return new Promise((resolve, reject) => {
try {
const ws = new WebSocket(WS_URL);
ws.on('open', () => {
log.info('WebSocket connected');
});
ws.on('message', (data) => {
try {
const message = JSON.parse(data);
log.info(`WebSocket message received: ${message.type}`);
ws.close();
resolve();
} catch (error) {
reject(new Error(`Failed to parse WebSocket message: ${error.message}`));
}
});
ws.on('error', (error) => {
reject(new Error(`WebSocket error: ${error.message}`));
});
// Timeout for WebSocket test
setTimeout(() => {
ws.close();
reject(new Error('WebSocket test timed out'));
}, 5000);
} catch (error) {
reject(new Error(`WebSocket connection failed: ${error.message}`));
}
});
},
// Test 6: Get outputs
async () => {
const outputs = await testApi('/outputs');
if (typeof outputs !== 'object') {
throw new Error('Invalid outputs response');
}
},
// Test 7: Generate report
async () => {
const report = await testApi('/reports/comprehensive');
if (!report || !report.report_type) {
throw new Error('Invalid report response');
}
}
];
// Run all tests
const runAllTests = async () => {
log.info('Starting integration tests...');
for (let i = 0; i < tests.length; i++) {
await runTest(`Test ${i + 1}`, tests[i]);
}
log.info('Integration tests completed');
log.success(`Passed: ${passedTests}`);
if (failedTests > 0) {
log.error(`Failed: ${failedTests}`);
process.exit(1);
} else {
log.success('All tests passed!');
process.exit(0);
}
};
// Set timeout for all tests
setTimeout(() => {
log.error('Tests timed out');
process.exit(1);
}, TEST_TIMEOUT);
// Run tests
runAllTests().catch((error) => {
log.error(`Test runner error: ${error.message}`);
process.exit(1);
});