@earendil-works/gondolin 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ws-server.js DELETED
@@ -1,136 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const sandbox_ws_server_1 = require("./sandbox-ws-server");
4
- function parseArgs(argv) {
5
- const args = {};
6
- const fail = (message) => {
7
- console.error(message);
8
- usage();
9
- process.exit(1);
10
- };
11
- for (let i = 0; i < argv.length; i += 1) {
12
- const arg = argv[i];
13
- if (arg === "--") {
14
- continue;
15
- }
16
- switch (arg) {
17
- case "--host":
18
- args.host = argv[++i] ?? args.host;
19
- break;
20
- case "--port":
21
- args.port = Number(argv[++i]);
22
- if (!Number.isFinite(args.port))
23
- fail("--port must be a number");
24
- break;
25
- case "--qemu":
26
- args.qemuPath = argv[++i];
27
- break;
28
- case "--kernel":
29
- args.kernelPath = argv[++i];
30
- break;
31
- case "--initrd":
32
- args.initrdPath = argv[++i];
33
- break;
34
- case "--memory":
35
- args.memory = argv[++i];
36
- break;
37
- case "--cpus":
38
- args.cpus = Number(argv[++i]);
39
- if (!Number.isFinite(args.cpus))
40
- fail("--cpus must be a number");
41
- break;
42
- case "--virtio-sock":
43
- args.virtioSocketPath = argv[++i];
44
- break;
45
- case "--net-sock":
46
- args.netSocketPath = argv[++i];
47
- break;
48
- case "--net-mac":
49
- args.netMac = argv[++i];
50
- break;
51
- case "--no-net":
52
- args.netEnabled = false;
53
- break;
54
- case "--net-debug":
55
- args.netDebug = true;
56
- break;
57
- case "--machine":
58
- args.machineType = argv[++i];
59
- break;
60
- case "--accel":
61
- args.accel = argv[++i];
62
- break;
63
- case "--cpu":
64
- args.cpu = argv[++i];
65
- break;
66
- case "--console":
67
- args.console = argv[++i] === "none" ? "none" : "stdio";
68
- break;
69
- case "--token":
70
- args.token = argv[++i];
71
- break;
72
- case "--no-restart":
73
- args.autoRestart = false;
74
- break;
75
- case "--help":
76
- case "-h":
77
- usage();
78
- process.exit(0);
79
- default:
80
- fail(`Unknown argument: ${arg}`);
81
- }
82
- }
83
- return args;
84
- }
85
- function usage() {
86
- const defaults = (0, sandbox_ws_server_1.resolveSandboxWsServerOptions)();
87
- console.log("Usage: node dist/ws-server.js [options]");
88
- console.log("Options:");
89
- console.log(` --host HOST Host to bind (default ${defaults.host})`);
90
- console.log(` --port PORT Port to bind (default ${defaults.port})`);
91
- console.log(` --qemu PATH QEMU binary (default ${defaults.qemuPath})`);
92
- console.log(" --kernel PATH Kernel path");
93
- console.log(" --initrd PATH Initrd path");
94
- console.log(` --memory SIZE Memory size (default ${defaults.memory})`);
95
- console.log(` --cpus N vCPU count (default ${defaults.cpus})`);
96
- console.log(" --virtio-sock PATH Virtio serial socket path");
97
- console.log(" --net-sock PATH QEMU net socket path");
98
- console.log(` --net-mac MAC MAC address for virtio-net`);
99
- console.log(" --no-net Disable QEMU net backend");
100
- console.log(" --net-debug Enable net backend debug logging");
101
- console.log(" --machine TYPE Override QEMU machine type");
102
- console.log(" --accel TYPE Override QEMU accel (kvm/hvf/tcg)");
103
- console.log(" --cpu TYPE Override QEMU CPU type");
104
- console.log(" --console stdio|none Console output");
105
- console.log(" --token TOKEN Require token in Authorization header");
106
- console.log(" --no-restart Disable auto restart on exit");
107
- }
108
- function formatLog(message) {
109
- if (message.endsWith("\n"))
110
- return message;
111
- return `${message}\n`;
112
- }
113
- async function main() {
114
- const args = parseArgs(process.argv.slice(2));
115
- const server = new sandbox_ws_server_1.SandboxWsServer(args);
116
- server.on("log", (message) => {
117
- process.stdout.write(formatLog(message));
118
- });
119
- server.on("error", (err) => {
120
- const message = err instanceof Error ? err.message : String(err);
121
- process.stdout.write(formatLog(message));
122
- });
123
- const address = await server.start();
124
- console.log(`WebSocket server listening on ${address.url}`);
125
- const shutdown = async () => {
126
- await server.stop();
127
- process.exit(0);
128
- };
129
- process.on("SIGINT", () => {
130
- void shutdown();
131
- });
132
- process.on("SIGTERM", () => {
133
- void shutdown();
134
- });
135
- }
136
- main();
package/dist/ws-test.js DELETED
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vm_1 = require("./vm");
4
- const url = process.env.WS_URL;
5
- const timeoutMs = Number(process.env.WS_TIMEOUT ?? 15000);
6
- const httpUrl = process.env.WS_HTTP_URL ?? "http://icanhazip.com";
7
- const httpsUrl = process.env.WS_HTTPS_URL ?? "https://icanhazip.com";
8
- const token = process.env.ELWING_TOKEN ?? process.env.SANDBOX_WS_TOKEN;
9
- async function withTimeout(promise, ms) {
10
- let timer = null;
11
- const timeout = new Promise((_, reject) => {
12
- timer = setTimeout(() => {
13
- reject(new Error("timeout waiting for response"));
14
- }, ms);
15
- });
16
- try {
17
- return await Promise.race([promise, timeout]);
18
- }
19
- finally {
20
- if (timer)
21
- clearTimeout(timer);
22
- }
23
- }
24
- async function run() {
25
- const vm = new vm_1.VM({ url: url ?? undefined, token: token ?? undefined });
26
- try {
27
- const result = await withTimeout(vm.exec([
28
- "python3",
29
- "-c",
30
- `import sys,urllib.request;\n` +
31
- `print('HTTP');\n` +
32
- `print(urllib.request.urlopen('${httpUrl}', timeout=10).read().decode().strip());\n` +
33
- `print('HTTPS');\n` +
34
- `print(urllib.request.urlopen('${httpsUrl}', timeout=10).read().decode().strip());\n`,
35
- ]), timeoutMs);
36
- const output = result.stdout.toString();
37
- const stderr = result.stderr.toString();
38
- if (result.exitCode !== 0) {
39
- const detail = stderr.trim() ? `\n${stderr.trim()}` : "";
40
- throw new Error(`unexpected exit code: ${result.exitCode}${detail}`);
41
- }
42
- const lines = output.trim().split("\n");
43
- const httpIndex = lines.findIndex((line) => line.trim() === "HTTP");
44
- const httpsIndex = lines.findIndex((line) => line.trim() === "HTTPS");
45
- if (httpIndex === -1 || httpsIndex === -1) {
46
- const detail = stderr.trim() ? `\n${stderr.trim()}` : "";
47
- throw new Error(`missing http/https output: ${output.trim()}${detail}`);
48
- }
49
- const httpValue = lines[httpIndex + 1]?.trim();
50
- const httpsValue = lines[httpsIndex + 1]?.trim();
51
- if (!httpValue || !httpsValue) {
52
- const detail = stderr.trim() ? `\n${stderr.trim()}` : "";
53
- throw new Error(`empty http/https response: ${output.trim()}${detail}`);
54
- }
55
- console.log("WS test passed");
56
- console.log(output);
57
- }
58
- finally {
59
- await vm.stop();
60
- }
61
- }
62
- run().catch((err) => {
63
- console.error(err.message);
64
- process.exit(1);
65
- });