()
| 8 | } |
| 9 | |
| 10 | async function test() { |
| 11 | console.log("Initializing AgentVM..."); |
| 12 | const vm = new AgentVM(); |
| 13 | |
| 14 | try { |
| 15 | await withTimeout(vm.start(), 5000); |
| 16 | console.log("VM Started."); |
| 17 | |
| 18 | console.log("Running 'echo hello'..."); |
| 19 | let res = await withTimeout(vm.exec("echo hello"), 5000); |
| 20 | console.log("Result:", JSON.stringify(res)); |
| 21 | if (res.stdout.trim() !== "hello") throw new Error("Output mismatch"); |
| 22 | |
| 23 | console.log("Running Python math..."); |
| 24 | res = await withTimeout(vm.exec("python3 -c 'print(100 + 200)'"), 10000); |
| 25 | console.log("Result:", JSON.stringify(res)); |
| 26 | if (res.stdout.trim() !== "300") throw new Error("Python Output mismatch"); |
| 27 | |
| 28 | console.log("Running command with exit code..."); |
| 29 | res = await withTimeout(vm.exec("ls /nonexistent"), 5000); |
| 30 | console.log("Result:", JSON.stringify(res)); |
| 31 | if (res.exitCode === 0) throw new Error("Should have failed"); |
| 32 | |
| 33 | console.log("Running persistence test..."); |
| 34 | await withTimeout(vm.exec("export MYVAR=foobar"), 5000); |
| 35 | res = await withTimeout(vm.exec("echo $MYVAR"), 5000); |
| 36 | console.log("Result:", JSON.stringify(res)); |
| 37 | if (res.stdout.trim() !== "foobar") throw new Error("Persistence failed"); |
| 38 | |
| 39 | } catch (e) { |
| 40 | console.error("TEST FAILED:", e); |
| 41 | process.exit(1); |
| 42 | } finally { |
| 43 | await vm.stop(); |
| 44 | console.log("VM Stopped."); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | test(); |
no test coverage detected