| 52 | |
| 53 | // Simulate NestJS-like environment where Tokio runtime already exists |
| 54 | async function simulateNestedRuntime() { |
| 55 | console.log('='.repeat(70)); |
| 56 | console.log(' Test: Nested Tokio Runtime (Issue #22)'); |
| 57 | console.log('='.repeat(70)); |
| 58 | console.log(); |
| 59 | |
| 60 | const configPath = findConfig(); |
| 61 | console.log(` Config: ${configPath}`); |
| 62 | console.log(); |
| 63 | |
| 64 | // Simulate NestJS initialization - create agent while "inside" a runtime |
| 65 | console.log(' [1] Simulating NestJS environment (existing Tokio runtime)...'); |
| 66 | console.log(' [2] Calling Agent.create() from within that runtime...'); |
| 67 | console.log(); |
| 68 | |
| 69 | try { |
| 70 | console.log(' Creating agent...'); |
| 71 | const agent = await Agent.create(configPath); |
| 72 | console.log(' ✓ Agent created successfully!'); |
| 73 | console.log(); |
| 74 | |
| 75 | console.log(' Creating session...'); |
| 76 | const session = agent.session('.', { |
| 77 | builtinSkills: true, |
| 78 | planningMode: 'enabled', |
| 79 | }); |
| 80 | console.log(' ✓ Session created successfully!'); |
| 81 | console.log(); |
| 82 | |
| 83 | console.log(' Sending test prompt...'); |
| 84 | const result = await session.send('Say hello in exactly 3 words'); |
| 85 | console.log(` ✓ Response: ${result.text.substring(0, 100)}...`); |
| 86 | console.log(); |
| 87 | |
| 88 | console.log('='.repeat(70)); |
| 89 | console.log(' [PASS] All operations completed successfully!'); |
| 90 | console.log(' Issue #22 is fixed: nested runtime works correctly.'); |
| 91 | console.log('='.repeat(70)); |
| 92 | return true; |
| 93 | } catch (error: any) { |
| 94 | console.error(); |
| 95 | console.error(' [FAIL] Error occurred:', error.message || error); |
| 96 | console.error(); |
| 97 | if (error.message?.includes('Cannot start a runtime from within a runtime')) { |
| 98 | console.error(' This is the original Issue #22 bug - the fix is not working.'); |
| 99 | } |
| 100 | return false; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // Test with multiple concurrent sessions (stress test) |
| 105 | async function testConcurrentSessions() { |