@parcha/agentrun-computer 0.1.0-beta.38 → 0.1.0-beta.40
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/README.md +126 -83
- package/box/Dockerfile +5 -54
- package/box/README.md +9 -3
- package/box/build-daytona.py +2 -2
- package/box/build-e2b.mjs +1 -1
- package/box/install.sh +87 -0
- package/box/recipe.d.mts +5 -0
- package/box/recipe.mjs +12 -10
- package/dist/agent37.d.ts +17 -4
- package/dist/agent37.js +98 -17
- package/dist/box-image.d.ts +14 -0
- package/dist/box-image.js +24 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/agent37.d.ts +9 -4
- package/dist/conformance/agent37.js +23 -11
- package/dist/conformance/browserbase.js +3 -3
- package/dist/conformance/cases/apps.d.ts +1 -1
- package/dist/conformance/cases/apps.js +1 -1
- package/dist/conformance/cases/isolation.d.ts +18 -3
- package/dist/conformance/cases/isolation.js +73 -6
- package/dist/conformance/cases/lifetime.js +30 -0
- package/dist/conformance/cases/mount.js +4 -2
- package/dist/conformance/cases/provider.js +88 -1
- package/dist/conformance/cli.js +29 -9
- package/dist/conformance/e2b.js +9 -4
- package/dist/conformance/exec-stream.d.ts +44 -7
- package/dist/conformance/exec-stream.js +347 -88
- package/dist/conformance/kernel.js +2 -2
- package/dist/conformance/modal.js +1 -1
- package/dist/conformance/orgo.js +2 -2
- package/dist/conformance/report.js +3 -0
- package/dist/conformance/runner.js +127 -9
- package/dist/conformance/types.d.ts +21 -0
- package/dist/daytona.d.ts +0 -5
- package/dist/daytona.js +19 -28
- package/dist/descriptor.d.ts +5 -3
- package/dist/descriptors/agent37.d.ts +3 -11
- package/dist/descriptors/agent37.js +9 -10
- package/dist/descriptors/daytona.d.ts +1 -1
- package/dist/descriptors/daytona.js +5 -2
- package/dist/descriptors/docker.d.ts +13 -1
- package/dist/descriptors/docker.js +3 -1
- package/dist/descriptors/e2b.d.ts +2 -9
- package/dist/descriptors/e2b.js +8 -8
- package/dist/descriptors/index.d.ts +21 -19
- package/dist/descriptors/index.js +1 -3
- package/dist/descriptors/modal.d.ts +2 -6
- package/dist/descriptors/modal.js +8 -6
- package/dist/descriptors/orgo.js +2 -1
- package/dist/docker/egress-main.js +23 -15
- package/dist/docker/egress.d.ts +6 -4
- package/dist/docker/egress.js +24 -16
- package/dist/docker/inspect.d.ts +2 -2
- package/dist/docker/inspect.js +5 -5
- package/dist/docker.d.ts +6 -5
- package/dist/docker.js +12 -11
- package/dist/e2b.d.ts +12 -2
- package/dist/e2b.js +42 -19
- package/dist/host.d.ts +113 -59
- package/dist/host.js +5 -0
- package/dist/hosted/framed-exec.d.ts +49 -0
- package/dist/hosted/framed-exec.js +185 -0
- package/dist/hosted/network.d.ts +23 -0
- package/dist/hosted/network.js +77 -0
- package/dist/hosted/process.d.ts +13 -5
- package/dist/hosted/process.js +35 -12
- package/dist/hosted/provider.d.ts +16 -9
- package/dist/hosted/provider.js +475 -170
- package/dist/hosted/rest.d.ts +20 -2
- package/dist/hosted/rest.js +24 -10
- package/dist/hosted/scripts.d.ts +27 -7
- package/dist/hosted/scripts.js +77 -18
- package/dist/{agent37-ssh.d.ts → hosted/ssh-exec.d.ts} +19 -9
- package/dist/{agent37-ssh.js → hosted/ssh-exec.js} +38 -19
- package/dist/hosted/values.d.ts +21 -0
- package/dist/hosted/values.js +55 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/isolation.d.ts +0 -2
- package/dist/isolation.js +3 -4
- package/dist/modal.d.ts +8 -2
- package/dist/modal.js +21 -15
- package/dist/mount-archil.d.ts +5 -4
- package/dist/mount-archil.js +5 -6
- package/dist/orgo.js +6 -4
- package/dist/providers.d.ts +4 -1
- package/dist/surface/api.d.ts +0 -9
- package/dist/surface/core.d.ts +7 -2
- package/dist/surface/core.js +12 -4
- package/dist/surface/index.d.ts +1 -1
- package/dist/surface/index.js +1 -1
- package/dist/surface/script.d.ts +4 -0
- package/dist/surface/script.js +9 -3
- package/package.json +1 -1
- package/box/build-agent37.mjs +0 -158
|
@@ -1,66 +1,137 @@
|
|
|
1
1
|
// The exec pre-check: the one thing a new vendor proves before writing anything else of its host. AgentRun installs its
|
|
2
2
|
// daemon through MachineHost.exec and then talks to it over that one process's stdin and stdout for the computer's whole
|
|
3
|
-
// life, so exec must be a live, two-way
|
|
4
|
-
// ../host.ts). This runs exec alone, on a machine the vendor made by hand, and says in plain words what it
|
|
3
|
+
// life, so exec must be a live, two-way stream that keeps UTF-8 text intact, with no timeout (the contract is exec's doc
|
|
4
|
+
// comment in ../host.ts). This runs exec alone, on a machine the vendor made by hand, and says in plain words what it
|
|
5
|
+
// did wrong:
|
|
5
6
|
//
|
|
6
7
|
// npm run conformance -w @parcha/agentrun-computer -- --provider <id | ./module.js> --exec-stream --machine <id> [--quick]
|
|
7
8
|
//
|
|
8
9
|
// It calls nothing but host.exec, so a host whose other members are still stubs can run it. Each check starts its own
|
|
9
|
-
// process and kills it when it is done with it, pass or fail.
|
|
10
|
+
// process and kills it when it is done with it, pass or fail. No check ends stdin: the adapter never needs a vendor's
|
|
11
|
+
// end of file, so one with none passes. After the checks, one more exec reads what the machine offers the rest of the
|
|
12
|
+
// host (root's network namespace, /dev/fuse, the arch, the kernel, the TCP listeners): facts, each with what it means
|
|
13
|
+
// for the provider, never a pass or a fail of exec.
|
|
10
14
|
import { createHash, randomBytes } from "node:crypto";
|
|
11
15
|
import { words } from "../hosted/process.js";
|
|
12
16
|
/** The checks, in the order they run. */
|
|
13
|
-
export const EXEC_STREAM_CHECKS = ["stdout-
|
|
17
|
+
export const EXEC_STREAM_CHECKS = ["stdout-text", "stdin-text", "large", "stdout-live", "stdin-live", "stdout-unread", "stderr", "exit-code", "kill", "no-timeout"];
|
|
18
|
+
/** What the capability probe reads, in the order the report gives it. */
|
|
19
|
+
export const EXEC_STREAM_FACTS = ["root", "netns", "fuse", "arch", "kernel", "listeners"];
|
|
14
20
|
export const DEFAULT_LONG_MS = 75_000;
|
|
15
21
|
/** --quick's no-timeout check: long enough to cross a second, short enough for CI. */
|
|
16
22
|
export const QUICK_LONG_MS = 5_000;
|
|
17
23
|
const DEFAULT_STEP_MS = 30_000;
|
|
18
24
|
const DEFAULT_LARGE_BYTES = 8 * 1024 * 1024;
|
|
19
25
|
const DEFAULT_LARGE_MS = 180_000;
|
|
26
|
+
const DEFAULT_UNREAD_MS = 10_000;
|
|
27
|
+
/** stdout-unread's writes: this many, of UNREAD_CHUNK bytes each, spread over unreadMs; 4 MiB, far past a 64 KiB window. */
|
|
28
|
+
const UNREAD_WRITES = 64;
|
|
29
|
+
const UNREAD_CHUNK = 64 * 1024;
|
|
20
30
|
/** What one write gives exec's stdin, as the adapter's own upload does (runToExit). */
|
|
21
31
|
const WRITE_CHUNK = 256 * 1024;
|
|
22
32
|
/** How long stdout-live watches, after "early", that stdout stays open and wait() has no answer. */
|
|
23
33
|
const LIVE_GRACE_MS = 1_000;
|
|
34
|
+
/**
|
|
35
|
+
* kill's probe, `sh -c PID_STATE_SCRIPT sh <pid>`: "running" or "gone". A killed process its parent has not reaped yet
|
|
36
|
+
* is a zombie, which kill -0 still finds; it has ended, so its /proc state (Z, or X) reads gone, and any other state
|
|
37
|
+
* running. Its state is read first, in one read, so a reap during the probe never reads as running; where there is no
|
|
38
|
+
* state to read (no /proc, a status hidden, or the process already gone), kill -0 answers.
|
|
39
|
+
*/
|
|
40
|
+
export const PID_STATE_SCRIPT = 'st=$(sed -n "s/^State:[[:space:]]*\\([A-Z]\\).*/\\1/p" "/proc/$1/status" 2>/dev/null); case "$st" in Z|X) echo gone ;; ?) echo running ;; *) if kill -0 "$1" 2>/dev/null; then echo running; else echo gone; fi ;; esac';
|
|
24
41
|
/** A failed check: its words are the report's. */
|
|
25
42
|
class Problem extends Error {
|
|
26
43
|
}
|
|
27
44
|
const hex = (bytes) => [...bytes].map((b) => b.toString(16).padStart(2, "0")).join(" ");
|
|
28
|
-
const byte = (b) => `0x${b.toString(16).padStart(2, "0")}`;
|
|
29
45
|
const secondsOf = (ms) => `${Math.round(ms / 100) / 10} s`;
|
|
30
46
|
const shown = (argv) => argv.map((word) => (/^[\w./=:-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`)).join(" ");
|
|
31
|
-
const
|
|
32
|
-
/**
|
|
33
|
-
|
|
47
|
+
const range = (from, to) => String.fromCodePoint(...Array.from({ length: to - from + 1 }, (_, i) => from + i));
|
|
48
|
+
/**
|
|
49
|
+
* A BOM first, which a TextDecoder drops from the start of a stream unless told to keep it (ignoreBOM). Then one of
|
|
50
|
+
* each class of code point: all of ASCII but NUL (no text the adapter carries holds one: JSON escapes it), all of
|
|
51
|
+
* Latin-1, the BMP's scripts and its odd ones (the line and paragraph separators, a BOM, U+FFFD), astral ones, and
|
|
52
|
+
* combining marks and a joined emoji, which a normalizer would change. Then \r alone and \r\n, which a terminal changes.
|
|
53
|
+
*/
|
|
54
|
+
const CODE_POINTS = `\u{feff}${range(0x01, 0x7f)}${range(0x80, 0xff)}ĀſΩЖאعह中文日本語한국어€
�𝄞😀\u{10ffff}éä\u{1f469}\u{1f4bb}carriage\rreturn\r\nline`;
|
|
55
|
+
/** 16 KiB of text of every width (1, 2, 3 and 4 bytes a character), no newline: 64 of them are the 1 MiB line. */
|
|
56
|
+
const LONG_PIECE = `${"aé€𝄞".repeat(1638)}abcd`;
|
|
57
|
+
const LONG_PIECES = 64;
|
|
58
|
+
/** What stdout-text and stdin-text carry: every class of code point, \r and \r\n, a line of 1 MiB, and a lone \n at the end. */
|
|
59
|
+
const TEXT = Buffer.from(`${CODE_POINTS}${LONG_PIECE.repeat(LONG_PIECES)}\n`, "utf8");
|
|
60
|
+
/**
|
|
61
|
+
* length bytes of random UTF-8 text: characters of 1, 2, 3 and 4 bytes at random, any code point of each width but NUL
|
|
62
|
+
* and the surrogates (which are no text).
|
|
63
|
+
*/
|
|
64
|
+
export function randomText(length) {
|
|
65
|
+
const text = Buffer.alloc(length);
|
|
66
|
+
const random = randomBytes(4 * length);
|
|
67
|
+
let r = 0;
|
|
68
|
+
const next = (bytes) => {
|
|
69
|
+
let value = 0;
|
|
70
|
+
for (let i = 0; i < bytes; i++)
|
|
71
|
+
value = value * 256 + random[r++];
|
|
72
|
+
return value;
|
|
73
|
+
};
|
|
74
|
+
for (let at = 0; at < length;) {
|
|
75
|
+
const width = Math.min(length - at, 1 + (next(1) & 3));
|
|
76
|
+
if (width === 1)
|
|
77
|
+
text[at] = 1 + (next(1) % 0x7f);
|
|
78
|
+
else if (width === 2)
|
|
79
|
+
text.write(String.fromCodePoint(0x80 + (next(2) % 0x780)), at, "utf8");
|
|
80
|
+
else if (width === 3) {
|
|
81
|
+
const point = 0x800 + (next(2) % 0xf000);
|
|
82
|
+
text.write(String.fromCodePoint(point >= 0xd800 ? point + 0x800 : point), at, "utf8");
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
text.write(String.fromCodePoint(0x10000 + (next(3) % 0x100000)), at, "utf8");
|
|
86
|
+
at += width;
|
|
87
|
+
}
|
|
88
|
+
return text;
|
|
89
|
+
}
|
|
90
|
+
/** printf's format for text: each of its UTF-8 bytes as an octal escape, which dash, bash and busybox all read. */
|
|
91
|
+
const printfOf = (text) => [...Buffer.from(text, "utf8")].map((b) => `\\${b.toString(8).padStart(3, "0")}`).join("");
|
|
92
|
+
/** The code point of the character the byte at i is part of, as U+XXXX, and where that character starts. */
|
|
93
|
+
function characterAt(bytes, i) {
|
|
94
|
+
let start = i;
|
|
95
|
+
while (start > 0 && (bytes[start] & 0xc0) === 0x80)
|
|
96
|
+
start--;
|
|
97
|
+
const point = Buffer.from(bytes.subarray(start, start + 4)).toString("utf8").codePointAt(0) ?? 0;
|
|
98
|
+
return { name: `U+${point.toString(16).toUpperCase().padStart(4, "0")}`, start };
|
|
99
|
+
}
|
|
34
100
|
/**
|
|
35
|
-
* Why `got` is not `sent`, in words, or undefined when they are the same
|
|
36
|
-
*
|
|
101
|
+
* Why `got` is not `sent`, in words, or undefined when they are the same text. Both are UTF-8; `way` is where it went
|
|
102
|
+
* ("on stdout"). The first character that differs is named, and the usual ways an exec changes text are named for what
|
|
103
|
+
* they are.
|
|
37
104
|
*/
|
|
38
|
-
export function
|
|
105
|
+
export function textProblem(sent, got, way) {
|
|
39
106
|
let i = 0;
|
|
40
107
|
while (i < sent.length && i < got.length && sent[i] === got[i])
|
|
41
108
|
i++;
|
|
42
109
|
if (i === sent.length && i === got.length)
|
|
43
110
|
return undefined;
|
|
44
|
-
if (i === got.length)
|
|
45
|
-
|
|
46
|
-
return `only ${got.length} of ${sent.length} bytes came back ${way}${nul}. Pass every byte on as it comes`;
|
|
47
|
-
}
|
|
111
|
+
if (i === got.length)
|
|
112
|
+
return `only ${got.length} of ${sent.length} bytes of text came back ${way}. Pass every character on as it comes`;
|
|
48
113
|
if (i === sent.length)
|
|
49
|
-
return `${got.length - sent.length} bytes came back ${way} that were never sent, after all ${sent.length} that were (${hex(got.subarray(i, i + 8))}): your exec adds output of its own (a shell's login banner, a prompt). Pass only the process's own
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
114
|
+
return `${got.length - sent.length} bytes came back ${way} that were never sent, after all ${sent.length} that were (${hex(got.subarray(i, i + 8))}): your exec adds output of its own (a shell's login banner, a prompt). Pass only the process's own output`;
|
|
115
|
+
const { name, start } = characterAt(sent, i);
|
|
116
|
+
const was = got.subarray(start, start + 4);
|
|
117
|
+
const said = `${name} (at byte ${start}) came back ${way} as ${hex(was)}`;
|
|
118
|
+
const b = sent[start];
|
|
119
|
+
if (b === 0x0a && was[0] === 0x0d && was[1] === 0x0a)
|
|
120
|
+
return `${said}: your exec turns \\n into \\r\\n, as a terminal does. Run the process on pipes, not a terminal`;
|
|
121
|
+
if (b === 0x0d && was[0] === 0x0a)
|
|
122
|
+
return `${said}: your exec turns \\r into \\n, as newline translation does. Pass every character on as it comes`;
|
|
123
|
+
if (b === 0x0d)
|
|
124
|
+
return `${said}: your exec drops \\r, as newline translation does. Pass every character on as it comes`;
|
|
125
|
+
if (b >= 0x80 && was[0] === (0xc0 | (b >> 6)) && was[1] === (0x80 | (b & 0x3f))) {
|
|
126
|
+
return `${said}: your exec reads UTF-8 as Latin-1 and writes it back as UTF-8 again. Read the process's output as UTF-8`;
|
|
127
|
+
}
|
|
128
|
+
if (name === "U+FEFF" && Buffer.from(got.subarray(start, start + 8)).equals(Buffer.from(sent.subarray(start + 3, start + 11)))) {
|
|
129
|
+
return `${said}: your exec drops a U+FEFF that starts its text, as a TextDecoder does unless given ignoreBOM: true. Keep it: it is text like any other`;
|
|
55
130
|
}
|
|
56
|
-
if (
|
|
57
|
-
return `${
|
|
131
|
+
if (was[0] === 0xef && was[1] === 0xbf && was[2] === 0xbd) {
|
|
132
|
+
return `${said}: U+FFFD (ef bf bd), as a decoder makes of half a character: your exec decodes each piece of output as text on its own. Decode the stream as one (TextDecoder's stream: true)`;
|
|
58
133
|
}
|
|
59
|
-
|
|
60
|
-
return `${was}: your exec turns \\n into \\r\\n, as a terminal does. Run the process on pipes, not a terminal`;
|
|
61
|
-
if (b === 0x0d && at[0] === 0x0a)
|
|
62
|
-
return `${was}: your exec drops \\r, as newline translation does. Pass every byte on as it comes`;
|
|
63
|
-
return `${was} (offset ${i}): your exec changes bytes. Pass every byte on as it comes, unchanged`;
|
|
134
|
+
return `${said}: your exec changes text (a terminal, a normalizer, an escape filter). Pass every character on as it comes, unchanged`;
|
|
64
135
|
}
|
|
65
136
|
/** One output stream of a process, read as it comes: its bytes so far, whether it ended, and a wait for more. */
|
|
66
137
|
class Reader {
|
|
@@ -69,10 +140,12 @@ class Reader {
|
|
|
69
140
|
ended = false;
|
|
70
141
|
error;
|
|
71
142
|
#wake = [];
|
|
72
|
-
|
|
73
|
-
|
|
143
|
+
/** Reads the stream as it comes; with `from`, not a byte until it settles: the stream is left unread until then. */
|
|
144
|
+
constructor(stream, from) {
|
|
145
|
+
void this.#pump(stream, from);
|
|
74
146
|
}
|
|
75
|
-
async #pump(stream) {
|
|
147
|
+
async #pump(stream, from) {
|
|
148
|
+
await from;
|
|
76
149
|
try {
|
|
77
150
|
for await (const chunk of stream) {
|
|
78
151
|
// A copy: a vendor's client may reuse its buffer.
|
|
@@ -137,6 +210,8 @@ function within(promise, ms, late, signal) {
|
|
|
137
210
|
});
|
|
138
211
|
}
|
|
139
212
|
const LATE = Symbol("late");
|
|
213
|
+
/** Waits ms, or less when signal aborts. */
|
|
214
|
+
const pause = (ms, signal) => within(new Promise(() => { }), Math.max(0, ms), undefined, signal);
|
|
140
215
|
/** The pre-check's run of host.exec on one machine. */
|
|
141
216
|
class Session {
|
|
142
217
|
#host;
|
|
@@ -158,9 +233,9 @@ class Session {
|
|
|
158
233
|
}
|
|
159
234
|
/**
|
|
160
235
|
* exec(argv), answered within the step's bound; any failure (a throw) is a Problem naming the command. Without stdin,
|
|
161
|
-
* end() is called at once, as the adapter does.
|
|
236
|
+
* end() is called at once, as the adapter does. With `readFrom`, stdout is left unread until it settles.
|
|
162
237
|
*/
|
|
163
|
-
async start(argv, stdin) {
|
|
238
|
+
async start(argv, stdin, readFrom) {
|
|
164
239
|
const what = `exec of ${shown(argv)}`;
|
|
165
240
|
let answer;
|
|
166
241
|
try {
|
|
@@ -191,7 +266,7 @@ class Session {
|
|
|
191
266
|
lacks.unshift("stderr");
|
|
192
267
|
if (lacks.length > 0)
|
|
193
268
|
throw new Problem(`${what} answered a process that lacks ${lacks.join(", ")}: a MachineProcess (src/host.ts) has stdout, stderr, write, end, wait and kill`);
|
|
194
|
-
const run = { proc, out: new Reader(proc.stdout), err: new Reader(proc.stderr), exited: Promise.resolve(0) };
|
|
269
|
+
const run = { proc, out: new Reader(proc.stdout, readFrom), err: new Reader(proc.stderr), exited: Promise.resolve(0) };
|
|
195
270
|
run.exited = Promise.resolve()
|
|
196
271
|
.then(() => proc.wait())
|
|
197
272
|
.then((code) => {
|
|
@@ -206,16 +281,21 @@ class Session {
|
|
|
206
281
|
return run;
|
|
207
282
|
}
|
|
208
283
|
/**
|
|
209
|
-
* Writes
|
|
210
|
-
* is bounded by the step, and by `by` when the
|
|
284
|
+
* Writes UTF-8 text to the process's stdin, in pieces of at most WRITE_CHUNK bytes, each whole characters as the
|
|
285
|
+
* adapter's are, one after another; a refusal is a Problem. Each write is bounded by the step, and by `by` when the
|
|
286
|
+
* check has one deadline for all of its steps.
|
|
211
287
|
*/
|
|
212
288
|
async write(run, bytes, what, by) {
|
|
213
|
-
for (let at = 0; at < bytes.length; at
|
|
289
|
+
for (let at = 0, end = 0; at < bytes.length; at = end) {
|
|
290
|
+
end = Math.min(at + WRITE_CHUNK, bytes.length);
|
|
291
|
+
while (end < bytes.length && (bytes[end] & 0xc0) === 0x80)
|
|
292
|
+
end--;
|
|
293
|
+
const piece = bytes.subarray(at, end);
|
|
214
294
|
const ms = by ? by.left(this.#stepMs) : this.#stepMs;
|
|
215
295
|
// Whether the deadline, not the step, set this bound. Asking by.passed() after the timeout is not enough: a
|
|
216
296
|
// timer can fire a millisecond before Date.now() reads the deadline.
|
|
217
297
|
const deadlineBound = by !== undefined && ms < this.#stepMs;
|
|
218
|
-
const written = await within(Promise.resolve().then(() => run.proc.write(
|
|
298
|
+
const written = await within(Promise.resolve().then(() => run.proc.write(piece)), ms, LATE, this.#signal).catch((error) => {
|
|
219
299
|
throw new Problem(`write() of ${what} failed while the process ran: ${words(error)}`);
|
|
220
300
|
});
|
|
221
301
|
// within() answers LATE for an abort too: a stopped write names no bound that did not run out.
|
|
@@ -225,15 +305,6 @@ class Session {
|
|
|
225
305
|
throw new Problem(by && (deadlineBound || by.passed()) ? `writing ${what} ran past ${secondsOf(by.ms)}, with ${at} bytes written` : `write() of ${what} did not answer within ${secondsOf(ms)}`);
|
|
226
306
|
}
|
|
227
307
|
}
|
|
228
|
-
/** Ends the process's stdin; a refusal is a Problem. */
|
|
229
|
-
async end(run, by) {
|
|
230
|
-
const ms = by ? by.left(this.#stepMs) : this.#stepMs;
|
|
231
|
-
const ended = await within(Promise.resolve().then(() => run.proc.end()), ms, LATE, this.#signal).catch((error) => {
|
|
232
|
-
throw new Problem(`end() failed: ${words(error)}`);
|
|
233
|
-
});
|
|
234
|
-
if (ended === LATE)
|
|
235
|
-
throw new Problem(`end() did not answer within ${secondsOf(ms)}`);
|
|
236
|
-
}
|
|
237
308
|
/** wait()'s exit code within ms; one that never comes, or a wait() that throws, is a Problem. */
|
|
238
309
|
async exit(run, ms, what) {
|
|
239
310
|
let code;
|
|
@@ -274,55 +345,51 @@ class Deadline {
|
|
|
274
345
|
}
|
|
275
346
|
}
|
|
276
347
|
const CHECKS = {
|
|
277
|
-
/**
|
|
278
|
-
async "stdout-
|
|
279
|
-
const
|
|
280
|
-
const run = await s.start(
|
|
348
|
+
/** Text of every kind out, on stdout alone: printf in the machine writes it, the 1 MiB line a piece at a time. */
|
|
349
|
+
async "stdout-text"(s) {
|
|
350
|
+
const script = `printf "$1"; i=0; while [ "$i" -lt ${LONG_PIECES} ]; do printf "$2"; i=$((i+1)); done; printf '\\n'`;
|
|
351
|
+
const run = await s.start(["sh", "-c", script, "sh", printfOf(CODE_POINTS), printfOf(LONG_PIECE)], false);
|
|
281
352
|
if (!(await run.out.end(s.stepMs, s.signal)))
|
|
282
353
|
throw new Problem(`stdout of printf did not end within ${secondsOf(s.stepMs)} of its start`);
|
|
283
354
|
const code = await s.exit(run, s.stepMs, "printf");
|
|
284
355
|
if (code !== 0)
|
|
285
|
-
throw new Problem(`printf of the
|
|
286
|
-
const problem =
|
|
356
|
+
throw new Problem(`printf of the text exited ${code} (stderr: ${run.err.bytes().toString("utf8").trim().slice(0, 200) || "none"})`);
|
|
357
|
+
const problem = textProblem(TEXT, run.out.bytes(), "on stdout");
|
|
287
358
|
if (problem)
|
|
288
359
|
throw new Problem(problem);
|
|
289
|
-
return "
|
|
360
|
+
return "text of every class of code point, \\r and \\r\\n, and a 1 MiB line, printed in the machine, came back unchanged on stdout";
|
|
290
361
|
},
|
|
291
|
-
/**
|
|
292
|
-
async "stdin-
|
|
362
|
+
/** The same text in on stdin and out again, through cat, read until it has all come back: no end of stdin. */
|
|
363
|
+
async "stdin-text"(s, _options, earlier) {
|
|
293
364
|
const run = await s.start(["cat"], true);
|
|
294
|
-
await s.write(run,
|
|
295
|
-
await
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const outOk = earlier.get("stdout-bytes")?.status === "pass";
|
|
300
|
-
const problem = bytesProblem(ALL_BYTES, run.out.bytes(), "through cat");
|
|
365
|
+
await s.write(run, TEXT, "the text");
|
|
366
|
+
const came = await run.out.until(() => run.out.length >= TEXT.length, s.stepMs, s.signal);
|
|
367
|
+
const got = run.out.bytes();
|
|
368
|
+
// What came back is checked as far as it goes: a character changed on the way says so, before any that never came.
|
|
369
|
+
const problem = textProblem(came ? TEXT : TEXT.subarray(0, got.length), got, "through cat");
|
|
301
370
|
if (problem)
|
|
302
|
-
throw new Problem(
|
|
303
|
-
|
|
371
|
+
throw new Problem(earlier.get("stdout-text")?.status === "pass" ? `${problem}. stdout alone passes it (stdout-text), so it changed on the way in, on stdin` : problem);
|
|
372
|
+
if (!came)
|
|
373
|
+
throw new Problem(`only ${got.length} of ${TEXT.length} bytes of text came back through cat within ${secondsOf(s.stepMs)} of the last write: your exec holds stdin, or drops some of it. Pass each write on as it comes`);
|
|
374
|
+
return "the same text written to stdin came back unchanged through cat";
|
|
304
375
|
},
|
|
305
|
-
/**
|
|
376
|
+
/** Large random text through cat, read while it is written, compared by sha256, all within largeMs. */
|
|
306
377
|
async large(s, { largeBytes, largeMs }) {
|
|
307
|
-
const payload =
|
|
378
|
+
const payload = randomText(largeBytes);
|
|
308
379
|
const started = Date.now();
|
|
309
380
|
const by = new Deadline(largeMs);
|
|
310
381
|
const run = await s.start(["cat"], true);
|
|
311
|
-
await s.write(run, payload, `${largeBytes} random
|
|
312
|
-
await
|
|
313
|
-
|
|
314
|
-
throw new Problem(`${run.out.length} of ${largeBytes} bytes came back through cat within ${secondsOf(largeMs)}, and its stdout had not ended: your exec is too slow, or stops passing output on`);
|
|
382
|
+
await s.write(run, payload, `${largeBytes} bytes of random text`, by);
|
|
383
|
+
if (!(await run.out.until(() => run.out.length >= largeBytes, by.left(largeMs), s.signal))) {
|
|
384
|
+
throw new Problem(`${run.out.length} of ${largeBytes} bytes of text came back through cat within ${secondsOf(largeMs)}: your exec is too slow, or stops passing output on`);
|
|
315
385
|
}
|
|
316
|
-
await s.exit(run, by.left(s.stepMs), "cat");
|
|
317
|
-
if (by.passed())
|
|
318
|
-
throw new Problem(`${largeBytes} bytes through cat took ${secondsOf(Date.now() - started)}, past ${secondsOf(largeMs)}: your exec is too slow`);
|
|
319
386
|
const got = run.out.bytes();
|
|
320
387
|
const sent = createHash("sha256").update(payload).digest("hex");
|
|
321
388
|
const back = createHash("sha256").update(got).digest("hex");
|
|
322
389
|
if (sent !== back) {
|
|
323
|
-
throw new Problem(`${largeBytes} random
|
|
390
|
+
throw new Problem(`${largeBytes} bytes of random text went in, ${got.length} came back with sha256 ${back.slice(0, 16)}…, not ${sent.slice(0, 16)}…: ${textProblem(payload, got, "through cat") ?? "they differ"}`);
|
|
324
391
|
}
|
|
325
|
-
return `${largeBytes} random
|
|
392
|
+
return `${largeBytes} bytes of random text came back through cat with the same sha256 in ${secondsOf(Date.now() - started)}`;
|
|
326
393
|
},
|
|
327
394
|
/** Output comes back while the process runs: printf, then a sleep that never ends on its own. */
|
|
328
395
|
async "stdout-live"(s) {
|
|
@@ -361,15 +428,58 @@ const CHECKS = {
|
|
|
361
428
|
: `write ${i + 1} to cat, with stdin still open, never came back on stdout in ${secondsOf(s.stepMs)}: your exec holds stdin until end(), or output until the process exits (see stdout-live)`);
|
|
362
429
|
}
|
|
363
430
|
}
|
|
364
|
-
const problem =
|
|
431
|
+
const problem = textProblem(Buffer.concat(rounds), run.out.bytes(), "through cat");
|
|
365
432
|
if (problem)
|
|
366
433
|
throw new Problem(problem);
|
|
367
|
-
await s.end(run);
|
|
368
|
-
const code = await s.exit(run, s.stepMs, "cat");
|
|
369
|
-
if (code !== 0)
|
|
370
|
-
throw new Problem(`cat exited ${code} after end(), not 0`);
|
|
371
434
|
return "two writes came back through cat, each before the next was written, while stdin stayed open";
|
|
372
435
|
},
|
|
436
|
+
/**
|
|
437
|
+
* stdin keeps coming while stdout is left unread for unreadMs; then stdout is read, and every byte comes back, in
|
|
438
|
+
* order. A write may wait while nobody reads stdout, but once stdout is read it goes on: an exec whose stdin waits on
|
|
439
|
+
* a stalled reader for good deadlocks the daemon's one stream (microsandbox holds a 64 KiB stdin window per execution).
|
|
440
|
+
*/
|
|
441
|
+
async "stdout-unread"(s, { unreadMs }) {
|
|
442
|
+
let read = () => { };
|
|
443
|
+
const run = await s.start(["cat"], true, new Promise((done) => (read = done)));
|
|
444
|
+
const started = Date.now();
|
|
445
|
+
const readAt = started + unreadMs;
|
|
446
|
+
const reading = setTimeout(read, unreadMs);
|
|
447
|
+
const sent = [];
|
|
448
|
+
let written = 0;
|
|
449
|
+
try {
|
|
450
|
+
// Every write, paced over unreadMs: one that waits for the reader goes on once stdout is read, and the rest follow.
|
|
451
|
+
// All of them are answered within stepMs of stdout being read: one deadline, not a step per write.
|
|
452
|
+
for (let i = 0; i < UNREAD_WRITES && !s.signal?.aborted; i++) {
|
|
453
|
+
await pause(started + (i * unreadMs) / UNREAD_WRITES - Date.now(), s.signal);
|
|
454
|
+
const chunk = Buffer.alloc(UNREAD_CHUNK, `write ${String(i + 1).padStart(2, "0")} `);
|
|
455
|
+
const madeUnread = Date.now() < readAt;
|
|
456
|
+
const answered = await within(Promise.resolve().then(() => run.proc.write(chunk)), Math.max(1, readAt + s.stepMs - Date.now()), LATE, s.signal).catch((error) => {
|
|
457
|
+
throw new Problem(`write() to cat failed while its stdout was left unread, with ${written} bytes written: ${words(error)}`);
|
|
458
|
+
});
|
|
459
|
+
if (answered === LATE && s.signal?.aborted)
|
|
460
|
+
throw new Problem(`writing to cat was stopped, with ${written} bytes written`);
|
|
461
|
+
if (answered === LATE && !madeUnread)
|
|
462
|
+
throw new Problem(`the ${UNREAD_WRITES} writes to cat ran past ${secondsOf(s.stepMs)} after stdout was read, with ${written} bytes written: your exec's writes are too slow`);
|
|
463
|
+
if (answered === LATE) {
|
|
464
|
+
throw new Problem(`write ${i + 1} to cat, made while its stdout was left unread, still had no answer ${secondsOf(s.stepMs)} after stdout was read again (${written} bytes written): your exec's stdin waits for stdout to be read and does not go on once it is, so one stalled reader deadlocks the stream. Let stdin wait only until stdout is read`);
|
|
465
|
+
}
|
|
466
|
+
sent.push(chunk);
|
|
467
|
+
written += chunk.length;
|
|
468
|
+
}
|
|
469
|
+
await pause(readAt - Date.now(), s.signal);
|
|
470
|
+
}
|
|
471
|
+
finally {
|
|
472
|
+
clearTimeout(reading);
|
|
473
|
+
read();
|
|
474
|
+
}
|
|
475
|
+
if (!(await run.out.until(() => run.out.length >= written, s.stepMs, s.signal))) {
|
|
476
|
+
throw new Problem(`${run.out.length} of ${written} bytes came back through cat within ${secondsOf(s.stepMs)} of stdout being read`);
|
|
477
|
+
}
|
|
478
|
+
const problem = textProblem(Buffer.concat(sent), run.out.bytes(), "through cat");
|
|
479
|
+
if (problem)
|
|
480
|
+
throw new Problem(`${problem}; stdout was left unread ${secondsOf(unreadMs)} while stdin was written: output nobody reads yet is held until it is read, never dropped`);
|
|
481
|
+
return `${written} bytes written to cat while its stdout was left unread for ${secondsOf(unreadMs)} all came back, in order, once it was read`;
|
|
482
|
+
},
|
|
373
483
|
/** stderr comes back apart from stdout. */
|
|
374
484
|
async stderr(s) {
|
|
375
485
|
const run = await s.start(["sh", "-c", "printf to-stdout; printf to-stderr >&2"], false);
|
|
@@ -412,7 +522,7 @@ const CHECKS = {
|
|
|
412
522
|
throw new Problem(`kill() did not answer within ${secondsOf(s.stepMs)}`);
|
|
413
523
|
// wait() after kill, then the machine's own word on the pid, whichever fails first named by the second.
|
|
414
524
|
const waited = await s.exit(run, s.stepMs, "the killed sleep").then(() => undefined, (error) => error);
|
|
415
|
-
const probe = await s.start(["sh", "-c",
|
|
525
|
+
const probe = await s.start(["sh", "-c", PID_STATE_SCRIPT, "sh", pid], false);
|
|
416
526
|
await probe.out.end(s.stepMs, s.signal);
|
|
417
527
|
await s.exit(probe, s.stepMs, "kill -0");
|
|
418
528
|
const state = probe.out.bytes().toString("latin1").trim();
|
|
@@ -442,12 +552,144 @@ const CHECKS = {
|
|
|
442
552
|
return `a process that slept ${seconds} s, silent, ran to its end and printed "done"`;
|
|
443
553
|
},
|
|
444
554
|
};
|
|
555
|
+
/**
|
|
556
|
+
* The capability probe, one sh script run through exec (as root, as exec runs): a tab-separated line for each thing it
|
|
557
|
+
* reads, each value on one line, and every line of the kernel's TCP tables as a "tcp" line. readFacts reads it. It needs
|
|
558
|
+
* no ss, ip or util-linux beyond unshare, and says "none" where the machine lacks unshare.
|
|
559
|
+
*/
|
|
560
|
+
export const CAPABILITY_SCRIPT = [
|
|
561
|
+
`line() { printf '%s\\t%s\\n' "$1" "$(printf '%s' "$2" | tr '\\n\\t' ' ')"; }`,
|
|
562
|
+
'line uid "$(id -u 2>&1)"',
|
|
563
|
+
'line arch "$(uname -m 2>&1)"',
|
|
564
|
+
'line kernel "$(uname -sr 2>&1)"',
|
|
565
|
+
`if d=$(dmesg 2>/dev/null); then line gvisor "$(printf '%s' "$d" | grep -i gvisor | head -n 1)"; else line gvisor unread; fi`,
|
|
566
|
+
'if command -v unshare >/dev/null 2>&1; then e=$(unshare -n true 2>&1); line netns "$? $e"; e=$(unshare -Urn true 2>&1); line userns "$? $e"; else line netns none; fi',
|
|
567
|
+
'if [ -e /dev/fuse ]; then e=$( (: <>/dev/fuse) 2>&1); line fuse "$? $e"; else line fuse absent; fi',
|
|
568
|
+
`for f in /proc/net/tcp /proc/net/tcp6; do if [ -r "$f" ]; then line table "$f"; while read -r l; do printf 'tcp\\t%s\\n' "$l"; done < "$f"; else line unreadable "$f"; fi; done`,
|
|
569
|
+
"true",
|
|
570
|
+
].join("\n");
|
|
571
|
+
/** A /proc/net/tcp{,6} address, hex as the kernel writes it (each 32-bit word in host order, little-endian here), as text. */
|
|
572
|
+
function tcpAddress(hex) {
|
|
573
|
+
const bytes = Buffer.from(hex, "hex");
|
|
574
|
+
for (let at = 0; at + 4 <= bytes.length; at += 4)
|
|
575
|
+
bytes.subarray(at, at + 4).reverse();
|
|
576
|
+
if (bytes.length === 4)
|
|
577
|
+
return [...bytes].join(".");
|
|
578
|
+
const groups = Array.from({ length: 8 }, (_, i) => bytes.readUInt16BE(i * 2).toString(16));
|
|
579
|
+
return new URL(`http://[${groups.join(":")}]`).hostname;
|
|
580
|
+
}
|
|
581
|
+
/** The most listeners the report names; a vendor's machine has a handful, a developer's box hundreds. */
|
|
582
|
+
const MAX_LISTENERS_SHOWN = 24;
|
|
583
|
+
/** The TCP listeners in the probe's "tcp" lines: address:port, each once, in the order the kernel lists them. */
|
|
584
|
+
export function tcpListeners(lines) {
|
|
585
|
+
const found = [];
|
|
586
|
+
for (const line of lines) {
|
|
587
|
+
const [, local = "", , state] = line.trim().split(/\s+/);
|
|
588
|
+
const match = /^([0-9A-F]{8}|[0-9A-F]{32}):([0-9A-F]{4})$/i.exec(local);
|
|
589
|
+
if (state !== "0A" || match === null)
|
|
590
|
+
continue;
|
|
591
|
+
const at = `${tcpAddress(match[1])}:${Number.parseInt(match[2], 16)}`;
|
|
592
|
+
if (!found.includes(at))
|
|
593
|
+
found.push(at);
|
|
594
|
+
}
|
|
595
|
+
return found;
|
|
596
|
+
}
|
|
597
|
+
/** What `<code> <words>` says of a command the probe ran: whether it worked, and its words. */
|
|
598
|
+
function ranOf(text) {
|
|
599
|
+
const match = /^(\d+) ?(.*)$/.exec(text ?? "");
|
|
600
|
+
return match === null ? undefined : { ok: match[1] === "0", said: match[2].trim() };
|
|
601
|
+
}
|
|
602
|
+
/** The probe's output as facts, each with what it means for the provider. */
|
|
603
|
+
export function readFacts(output) {
|
|
604
|
+
const values = new Map();
|
|
605
|
+
const tcp = [];
|
|
606
|
+
/** The TCP tables read, and those that could not be. */
|
|
607
|
+
const tables = { read: [], unreadable: [] };
|
|
608
|
+
for (const line of output.split("\n")) {
|
|
609
|
+
const tab = line.indexOf("\t");
|
|
610
|
+
if (tab < 0)
|
|
611
|
+
continue;
|
|
612
|
+
const [key, value] = [line.slice(0, tab), line.slice(tab + 1).trim()];
|
|
613
|
+
if (key === "tcp")
|
|
614
|
+
tcp.push(value);
|
|
615
|
+
else if (key === "table")
|
|
616
|
+
tables.read.push(value);
|
|
617
|
+
else if (key === "unreadable")
|
|
618
|
+
tables.unreadable.push(value);
|
|
619
|
+
else if (!values.has(key))
|
|
620
|
+
values.set(key, value);
|
|
621
|
+
}
|
|
622
|
+
const facts = [];
|
|
623
|
+
const uid = values.get("uid") ?? "";
|
|
624
|
+
facts.push(uid === "0"
|
|
625
|
+
? { id: "root", value: "uid 0", means: "exec runs as root, as the adapter needs: the lines below are what root can do" }
|
|
626
|
+
: { id: "root", value: uid === "" ? "not read" : `uid ${uid}`, means: "exec does not run as root: the adapter installs its daemon as root through exec, so run it as root (or through passwordless sudo); the lines below are what this user can do" });
|
|
627
|
+
const netns = values.get("netns");
|
|
628
|
+
const own = ranOf(netns);
|
|
629
|
+
const inUser = ranOf(values.get("userns"));
|
|
630
|
+
if (netns === "none")
|
|
631
|
+
facts.push({ id: "netns", value: "no unshare program", means: "not read: the machine has no unshare (util-linux), so whether root can make a network namespace shows only at the Core run" });
|
|
632
|
+
else if (own?.ok)
|
|
633
|
+
facts.push({ id: "netns", value: "unshare -n works", means: "root makes a network namespace: our fence holds network none, open and allow (netns)" });
|
|
634
|
+
else if (own !== undefined && inUser?.ok) {
|
|
635
|
+
facts.push({ id: "netns", value: `unshare -n failed (${own.said || "no words"}); unshare -Urn works`, means: "root makes a network namespace only inside a user namespace, as on gVisor: our fence holds network none, open and allow there (userns-netns)" });
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
const why = [own && `unshare -n failed (${own.said || "no words"})`, inUser && `unshare -Urn failed (${inUser.said || "no words"})`].filter(Boolean).join("; ") || "not read";
|
|
639
|
+
facts.push({ id: "netns", value: why, means: "no netns: network none, open and allow can't be held by our fence on this vendor" });
|
|
640
|
+
}
|
|
641
|
+
const fuse = values.get("fuse");
|
|
642
|
+
const opened = ranOf(fuse);
|
|
643
|
+
if (fuse === "absent")
|
|
644
|
+
facts.push({ id: "fuse", value: "no /dev/fuse", means: "no Archil mount (mount:archil) on this vendor: the Archil client needs /dev/fuse" });
|
|
645
|
+
else if (opened?.ok)
|
|
646
|
+
facts.push({ id: "fuse", value: "/dev/fuse opens", means: "an Archil mount (mount:archil) can be made here" });
|
|
647
|
+
else
|
|
648
|
+
facts.push({ id: "fuse", value: opened ? `/dev/fuse does not open (${opened.said || "no words"})` : "not read", means: "no Archil mount (mount:archil) on this vendor until root can open /dev/fuse" });
|
|
649
|
+
const arch = values.get("arch") ?? "";
|
|
650
|
+
const goArch = arch === "x86_64" || arch === "amd64" ? "amd64" : arch === "aarch64" || arch === "arm64" ? "arm64" : undefined;
|
|
651
|
+
facts.push({ id: "arch", value: arch || "not read", means: goArch ? `facts.arch "${goArch}"` : "neither amd64 nor arm64: computerd is built for those two alone" });
|
|
652
|
+
const kernel = values.get("kernel") || "not read";
|
|
653
|
+
const gvisor = values.get("gvisor") ?? "unread";
|
|
654
|
+
const isolationCases = "the isolation cases show how its fences hold";
|
|
655
|
+
if (gvisor !== "unread" && gvisor !== "") {
|
|
656
|
+
facts.push({ id: "kernel", value: `gVisor (${kernel} as it reports; dmesg: ${gvisor.slice(0, 80)})`, means: "gVisor: root has no CAP_SYS_ADMIN and the network stack is gVisor's own, so run the isolation cases here; a Docker stand-in does not show how it behaves" });
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
const marker = gvisor === "" ? "no gVisor marker in dmesg" : "dmesg could not be read, so gVisor is not ruled out";
|
|
660
|
+
facts.push({ id: "kernel", value: `${kernel} (${marker})`, means: `the kernel as it reports itself: ${isolationCases}` });
|
|
661
|
+
}
|
|
662
|
+
const listeners = tcpListeners(tcp);
|
|
663
|
+
const shownListeners = listeners.length > MAX_LISTENERS_SHOWN ? `${listeners.slice(0, MAX_LISTENERS_SHOWN).join(", ")} and ${listeners.length - MAX_LISTENERS_SHOWN} more` : listeners.join(", ");
|
|
664
|
+
const unread = tables.unreadable.length > 0 ? ` (${tables.unreadable.join(" and ")} could not be read)` : "";
|
|
665
|
+
if (tables.read.length === 0) {
|
|
666
|
+
facts.push({ id: "listeners", value: `not read${unread}`, means: "the listeners are unknown: find the vendor agent's ports some other way before you set facts.vendorAgentPorts" });
|
|
667
|
+
}
|
|
668
|
+
else if (listeners.length > 0) {
|
|
669
|
+
facts.push({ id: "listeners", value: `${shownListeners}${unread}`, means: "TCP listeners before AgentRun runs anything: the vendor's agent and services. Put the agent's ports in facts.vendorAgentPorts, so isolation.vendor-agent checks the computer's programs reach none of them" });
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
facts.push({ id: "listeners", value: `none${unread}`, means: unread === "" ? "no TCP listener before AgentRun runs anything: facts.vendorAgentPorts may be []" : `no TCP listener in ${tables.read.join(" or ")}: check the table that could not be read before you set facts.vendorAgentPorts to []` });
|
|
673
|
+
}
|
|
674
|
+
return facts;
|
|
675
|
+
}
|
|
676
|
+
/** The capability probe through exec: its facts, or a Problem in words when exec could not run it. */
|
|
677
|
+
async function probe(session) {
|
|
678
|
+
const run = await session.start(["sh", "-c", CAPABILITY_SCRIPT], false);
|
|
679
|
+
if (!(await run.out.end(session.stepMs, session.signal)))
|
|
680
|
+
throw new Problem(`its stdout did not end within ${secondsOf(session.stepMs)}`);
|
|
681
|
+
// The script ends in `true`: any other exit is a shell that broke partway, whose output is not read as facts.
|
|
682
|
+
const code = await session.exit(run, session.stepMs, "the probe");
|
|
683
|
+
if (code !== 0)
|
|
684
|
+
throw new Problem(`the probe's sh exited ${code} (stderr: ${run.err.bytes().toString("utf8").trim().slice(0, 200) || "none"})`);
|
|
685
|
+
return readFacts(run.out.bytes().toString("utf8"));
|
|
686
|
+
}
|
|
445
687
|
/**
|
|
446
688
|
* The exec pre-check on one machine: each check in EXEC_STREAM_CHECKS runs in turn, and the report passes when every one
|
|
447
|
-
* does. host.exec is the only member called.
|
|
689
|
+
* does; then the capability probe, which passes or fails nothing. host.exec is the only member called.
|
|
448
690
|
*/
|
|
449
691
|
export async function checkExecStream(host, machine, options = {}) {
|
|
450
|
-
const { longMs = DEFAULT_LONG_MS, stepMs = DEFAULT_STEP_MS, largeBytes = DEFAULT_LARGE_BYTES, largeMs = DEFAULT_LARGE_MS, signal, onCheck } = options;
|
|
692
|
+
const { longMs = DEFAULT_LONG_MS, stepMs = DEFAULT_STEP_MS, largeBytes = DEFAULT_LARGE_BYTES, largeMs = DEFAULT_LARGE_MS, unreadMs = DEFAULT_UNREAD_MS, signal, onCheck } = options;
|
|
451
693
|
const session = new Session(host, machine, stepMs, signal);
|
|
452
694
|
const done = new Map();
|
|
453
695
|
for (const id of EXEC_STREAM_CHECKS) {
|
|
@@ -457,7 +699,7 @@ export async function checkExecStream(host, machine, options = {}) {
|
|
|
457
699
|
check = { id, status: "fail", words: "the run was aborted before this check", ms: 0 };
|
|
458
700
|
else {
|
|
459
701
|
try {
|
|
460
|
-
const said = await CHECKS[id](session, { longMs, largeBytes, largeMs }, done);
|
|
702
|
+
const said = await CHECKS[id](session, { longMs, largeBytes, largeMs, unreadMs }, done);
|
|
461
703
|
check = { id, status: "pass", words: said, ms: Date.now() - started };
|
|
462
704
|
}
|
|
463
705
|
catch (error) {
|
|
@@ -470,17 +712,34 @@ export async function checkExecStream(host, machine, options = {}) {
|
|
|
470
712
|
onCheck?.(check);
|
|
471
713
|
}
|
|
472
714
|
const checks = [...done.values()];
|
|
473
|
-
|
|
715
|
+
const report = { host: host.descriptor.id, machine, checks, pass: checks.every((check) => check.status === "pass"), facts: [] };
|
|
716
|
+
if (signal?.aborted)
|
|
717
|
+
report.factsProblem = "the run was aborted before the probe";
|
|
718
|
+
else {
|
|
719
|
+
try {
|
|
720
|
+
report.facts = await probe(session);
|
|
721
|
+
}
|
|
722
|
+
catch (error) {
|
|
723
|
+
report.factsProblem = error instanceof Problem ? error.message : `the probe itself failed: ${words(error)}`;
|
|
724
|
+
}
|
|
725
|
+
await session.killAll();
|
|
726
|
+
}
|
|
727
|
+
return report;
|
|
474
728
|
}
|
|
475
|
-
/** The report as a person reads it: one line per check, what failed in words, the verdict last. */
|
|
729
|
+
/** The report as a person reads it: one line per check, what failed in words, the machine's facts, the verdict last. */
|
|
476
730
|
export function formatExecStream(report) {
|
|
477
731
|
const width = Math.max(...EXEC_STREAM_CHECKS.map((id) => id.length));
|
|
478
732
|
const lines = [`exec pre-check · ${report.host} · machine ${report.machine}`];
|
|
479
733
|
for (const check of report.checks)
|
|
480
734
|
lines.push(`${check.status === "pass" ? "✓" : "✗"} ${check.id.padEnd(width)} ${check.words}`);
|
|
735
|
+
lines.push("what the machine offers (facts for the rest of your host, not checks of exec):");
|
|
736
|
+
if (report.factsProblem !== undefined)
|
|
737
|
+
lines.push(` not read: ${report.factsProblem}`);
|
|
738
|
+
for (const fact of report.facts)
|
|
739
|
+
lines.push(`· ${fact.id.padEnd(width)} ${fact.value}: ${fact.means}`);
|
|
481
740
|
const failed = report.checks.filter((check) => check.status === "fail").length;
|
|
482
741
|
lines.push(report.pass
|
|
483
|
-
? "exec PASS: a live, two-way
|
|
742
|
+
? "exec PASS: a live, two-way stream that keeps text intact, with no timeout. Write the rest of your host next."
|
|
484
743
|
: `exec FAIL: ${failed} of ${report.checks.length} checks failed. Fix exec before you write the rest of your host: AgentRun reaches its daemon through it.`);
|
|
485
744
|
return `${lines.join("\n")}\n`;
|
|
486
745
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Kernel for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider kernel`. It makes a
|
|
2
|
-
// real, billed Kernel browser, so it runs only with AGENTRUN_COMPUTER_LIVE_KERNEL=1 and a key
|
|
2
|
+
// real, billed Kernel browser, so it runs only with AGENTRUN_COMPUTER_LIVE_KERNEL=1 and a key for an account you can bill, under
|
|
3
3
|
// COMPUTER_KERNEL_API_KEY. The provider reads no environment: this module reads its own COMPUTER_KERNEL_* names (never
|
|
4
4
|
// KERNEL_API_KEY, which may hold another organization's key) and passes each to create() as its option. The live switch
|
|
5
5
|
// is checked first, before any other setting is read. The run makes one browser, shared by every case, and deletes it.
|
|
@@ -34,7 +34,7 @@ export function conformanceImage() {
|
|
|
34
34
|
/** The provider the CLI runs; throws in words without the live switch, or when the key is missing. */
|
|
35
35
|
export async function createProvider({ env = process.env, ...transport } = {}) {
|
|
36
36
|
if (env[KERNEL_ENV.live] !== "1") {
|
|
37
|
-
throw new Error(`the Kernel conformance module makes a real, billed browser: set ${KERNEL_ENV.live}=1, with a key
|
|
37
|
+
throw new Error(`the Kernel conformance module makes a real, billed browser: set ${KERNEL_ENV.live}=1, with a key for an account you can bill, to run it`);
|
|
38
38
|
}
|
|
39
39
|
return create({ ...settingsFromEnv(env), ...transport });
|
|
40
40
|
}
|