MCPcopy Create free account
hub / github.com/deepclause/agentvm / test

Function test

test/network/http.test.js:19–265  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17const INCLUDE_HTTPS = process.env.INCLUDE_HTTPS === '1';
18
19async function test() {
20 console.log("=== HTTP/HTTPS Network Tests ===\n");
21 if (!INCLUDE_HTTPS) {
22 console.log("Note: HTTPS tests skipped. Set INCLUDE_HTTPS=1 to include them.\n");
23 }
24
25 const vm = new AgentVM({ network: true, debug: false });
26 let passed = 0;
27 let failed = 0;
28 let skipped = 0;
29
30 try {
31 await withTimeout(vm.start(), 10000);
32 console.log("VM Started with network enabled.\n");
33
34 // Test 1: Basic HTTP download with wget
35 console.log("Test 1: HTTP download with wget");
36 let start = Date.now();
37 let res = await withTimeout(
38 vm.exec("wget -q -O /tmp/http-test.txt http://httpbin.org/robots.txt && cat /tmp/http-test.txt"),
39 20000
40 );
41 let elapsed = Date.now() - start;
42 if (res.exitCode === 0 && res.stdout.includes('User-agent')) {
43 console.log(` PASS (${elapsed}ms)\n`);
44 passed++;
45 } else {
46 console.log(` FAIL (${elapsed}ms): ${res.stderr || 'unexpected response'}\n`);
47 failed++;
48 }
49
50 // Test 2: HTTPS download with wget
51 console.log("Test 2: HTTPS download with wget");
52 if (!INCLUDE_HTTPS) {
53 console.log(" SKIP (HTTPS tests disabled)\n");
54 skipped++;
55 } else {
56 start = Date.now();
57 res = await withTimeout(
58 vm.exec("wget -q -O /tmp/https-test.txt https://httpbin.org/get && cat /tmp/https-test.txt"),
59 60000 // Longer timeout for TLS
60 );
61 elapsed = Date.now() - start;
62 if (res.exitCode === 0 && res.stdout.includes('"url"')) {
63 console.log(` PASS (${elapsed}ms)\n`);
64 passed++;
65 } else {
66 console.log(` FAIL (${elapsed}ms): ${res.stderr || 'unexpected response'}\n`);
67 failed++;
68 }
69 }
70
71 // Test 3: HTTP GET with curl (if available)
72 console.log("Test 3: HTTP GET with curl");
73 start = Date.now();
74 res = await withTimeout(
75 vm.exec("which curl && curl -s http://httpbin.org/ip || echo 'curl not available'"),
76 20000

Callers 1

http.test.jsFile · 0.70

Calls 4

startMethod · 0.95
execMethod · 0.95
stopMethod · 0.95
withTimeoutFunction · 0.70

Tested by

no test coverage detected