| 103 | |
| 104 | // Test with multiple concurrent sessions (stress test) |
| 105 | async function testConcurrentSessions() { |
| 106 | console.log(); |
| 107 | console.log('='.repeat(70)); |
| 108 | console.log(' Test: Concurrent Sessions (Stress Test)'); |
| 109 | console.log('='.repeat(70)); |
| 110 | console.log(); |
| 111 | |
| 112 | const configPath = findConfig(); |
| 113 | |
| 114 | try { |
| 115 | const agent = await Agent.create(configPath); |
| 116 | console.log(' ✓ Agent created for concurrent test'); |
| 117 | console.log(); |
| 118 | |
| 119 | console.log(' Creating 3 concurrent sessions...'); |
| 120 | const sessions = [ |
| 121 | agent.session('.', { builtinSkills: true }), |
| 122 | agent.session('.', { builtinSkills: true }), |
| 123 | agent.session('.', { builtinSkills: true }), |
| 124 | ]; |
| 125 | console.log(' ✓ All sessions created'); |
| 126 | console.log(); |
| 127 | |
| 128 | console.log(' Sending concurrent prompts...'); |
| 129 | const results = await Promise.all([ |
| 130 | sessions[0].send('What is 2+2? Answer in numbers only.'), |
| 131 | sessions[1].send('What is 3+3? Answer in numbers only.'), |
| 132 | sessions[2].send('What is 4+4? Answer in numbers only.'), |
| 133 | ]); |
| 134 | |
| 135 | console.log(' ✓ All responses received:'); |
| 136 | results.forEach((r, i) => { |
| 137 | console.log(` Session ${i + 1}: ${r.text.substring(0, 50)}`); |
| 138 | }); |
| 139 | console.log(); |
| 140 | |
| 141 | console.log('='.repeat(70)); |
| 142 | console.log(' [PASS] Concurrent sessions work correctly!'); |
| 143 | console.log('='.repeat(70)); |
| 144 | return true; |
| 145 | } catch (error: any) { |
| 146 | console.error(); |
| 147 | console.error(' [FAIL] Error:', error.message || error); |
| 148 | return false; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // Main |
| 153 | async function main() { |