()
| 55 | } |
| 56 | |
| 57 | async function runTest() { |
| 58 | const TEST_SIZE = 64 * 1024; // 64KB - enough to span multiple TCP segments |
| 59 | const testData = generateTestData(TEST_SIZE); |
| 60 | const expectedHash = crypto.createHash('md5').update(testData).digest('hex'); |
| 61 | |
| 62 | console.log(`Test data: ${TEST_SIZE} bytes, MD5: ${expectedHash}`); |
| 63 | |
| 64 | // Start a simple HTTP server that serves the test data |
| 65 | const server = http.createServer((req, res) => { |
| 66 | if (req.url === '/test') { |
| 67 | console.log('[Server] Serving test data...'); |
| 68 | res.writeHead(200, { |
| 69 | 'Content-Type': 'application/octet-stream', |
| 70 | 'Content-Length': testData.length.toString() |
| 71 | }); |
| 72 | res.end(testData); |
| 73 | } else if (req.url === '/small') { |
| 74 | // Small response for quick verification |
| 75 | res.writeHead(200, { 'Content-Type': 'text/plain' }); |
| 76 | res.end('OK'); |
| 77 | } else { |
| 78 | res.writeHead(404); |
| 79 | res.end('Not Found'); |
| 80 | } |
| 81 | }); |
| 82 | |
| 83 | await new Promise((resolve) => server.listen(0, '0.0.0.0', resolve)); |
| 84 | const port = server.address().port; |
| 85 | console.log(`[Server] Listening on port ${port}`); |
| 86 | |
| 87 | // Get host IP that VM can reach (192.168.127.1 in VM = localhost on host) |
| 88 | const vmServerUrl = `http://192.168.127.1:${port}`; |
| 89 | |
| 90 | try { |
| 91 | // Start VM |
| 92 | const vm = new AgentVM({ network: true, debug: false }); |
| 93 | await vm.start(); |
| 94 | console.log('[VM] Started'); |
| 95 | |
| 96 | // Verify basic connectivity first |
| 97 | console.log('[Test] Checking basic connectivity...'); |
| 98 | const pingResult = await vm.exec(`curl -s -m 5 ${vmServerUrl}/small`); |
| 99 | if (pingResult.stdout !== 'OK') { |
| 100 | throw new Error(`Basic connectivity failed: ${pingResult.stdout} ${pingResult.stderr}`); |
| 101 | } |
| 102 | console.log('[Test] Basic connectivity OK'); |
| 103 | |
| 104 | // Now test with larger data |
| 105 | console.log('[Test] Downloading test data...'); |
| 106 | |
| 107 | // Download and save to file, then compute hash |
| 108 | const dlResult = await vm.exec(` |
| 109 | curl -s -m 30 -o /tmp/test.bin ${vmServerUrl}/test && \ |
| 110 | md5sum /tmp/test.bin && \ |
| 111 | wc -c /tmp/test.bin |
| 112 | `); |
| 113 | |
| 114 | console.log('[Test] Download result:', dlResult); |
no test coverage detected