()
| 1 | const { AgentVM } = require("./src/index.js"); |
| 2 | |
| 3 | async function test() { |
| 4 | const vm = new AgentVM({ network: true, debug: true }); |
| 5 | await vm.start(); |
| 6 | console.log("VM READY"); |
| 7 | |
| 8 | // Test DNS first |
| 9 | console.log("\n=== TEST 1: DNS before download ==="); |
| 10 | let r = await vm.exec("nslookup google.com 2>&1 | head -3"); |
| 11 | console.log(r.stdout); |
| 12 | |
| 13 | // Start a download and abort it by running a timeout curl |
| 14 | console.log("\n=== TEST 2: Short download (should complete) ==="); |
| 15 | r = await vm.exec("curl -s -o /dev/null -w '%{http_code}' http://google.com"); |
| 16 | console.log("HTTP status:", r.stdout); |
| 17 | |
| 18 | // Start a larger download with a timeout that will abort it |
| 19 | console.log("\n=== TEST 3: Download with timeout (will abort) ==="); |
| 20 | r = await vm.exec("timeout 3 curl -o /dev/null http://ipv4.download.thinkbroadband.com/10MB.zip 2>&1 || echo 'Download aborted as expected'"); |
| 21 | console.log(r.stdout); |
| 22 | |
| 23 | // Test DNS after abort |
| 24 | console.log("\n=== TEST 4: DNS after aborted download ==="); |
| 25 | r = await vm.exec("nslookup google.com 2>&1 | head -3"); |
| 26 | console.log(r.stdout); |
| 27 | |
| 28 | // Try another download |
| 29 | console.log("\n=== TEST 5: HTTP after aborted download ==="); |
| 30 | r = await vm.exec("curl -s -o /dev/null -w '%{http_code}' http://google.com"); |
| 31 | console.log("HTTP status:", r.stdout); |
| 32 | |
| 33 | console.log("\n=== ALL TESTS COMPLETE ==="); |
| 34 | process.exit(0); |
| 35 | } |
| 36 | |
| 37 | test().catch(e => { |
| 38 | console.error("ERROR:", e); |
no test coverage detected