@parcha/agentrun-computer 0.1.0-beta.37 → 0.1.0-beta.39
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 +341 -260
- package/box/Dockerfile +18 -1
- package/box/README.md +14 -0
- package/box/build-daytona.py +2 -2
- package/box/build-e2b.mjs +41 -18
- package/box/recipe.d.mts +5 -0
- package/box/recipe.mjs +43 -0
- package/dist/agent37.d.ts +18 -66
- package/dist/agent37.js +187 -464
- package/dist/box-image.d.ts +14 -0
- package/dist/box-image.js +24 -0
- package/dist/browserbase.d.ts +0 -6
- package/dist/browserbase.js +1 -5
- package/dist/client.d.ts +12 -3
- package/dist/client.js +39 -4
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +4 -0
- 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 +6 -0
- package/dist/conformance/cases/apps.js +18 -5
- package/dist/conformance/cases/isolation.d.ts +22 -5
- package/dist/conformance/cases/isolation.js +97 -16
- package/dist/conformance/cases/mount.js +5 -3
- package/dist/conformance/cases/provider.js +41 -0
- package/dist/conformance/cli.js +72 -11
- package/dist/conformance/daytona.d.ts +9 -20
- package/dist/conformance/daytona.js +12 -21
- package/dist/conformance/e2b.js +9 -4
- package/dist/conformance/exec-stream.d.ts +52 -0
- package/dist/conformance/exec-stream.js +493 -0
- package/dist/conformance/kernel.js +2 -2
- package/dist/conformance/modal.js +1 -1
- package/dist/conformance/orgo.js +2 -2
- package/dist/conformance/sweep.js +8 -8
- package/dist/conformance/types.d.ts +2 -2
- package/dist/create-requests.d.ts +1 -1
- package/dist/daytona.d.ts +17 -133
- package/dist/daytona.js +396 -1452
- package/dist/descriptor.d.ts +11 -4
- package/dist/descriptor.js +7 -0
- package/dist/descriptors/agent37.d.ts +3 -11
- package/dist/descriptors/agent37.js +9 -10
- package/dist/descriptors/daytona.d.ts +7 -6
- package/dist/descriptors/daytona.js +14 -7
- 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 +25 -24
- 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/descriptors/shared.d.ts +1 -1
- package/dist/descriptors/shared.js +2 -2
- package/dist/desktop.d.ts +18 -4
- package/dist/desktop.js +89 -9
- 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 -11
- package/dist/docker.js +13 -16
- package/dist/drift.js +4 -4
- package/dist/e2b.d.ts +22 -130
- package/dist/e2b.js +163 -243
- package/dist/host.d.ts +136 -104
- package/dist/host.js +8 -1
- package/dist/hosted/network.d.ts +23 -0
- package/dist/hosted/network.js +77 -0
- package/dist/hosted/process.d.ts +24 -8
- package/dist/hosted/process.js +80 -44
- package/dist/hosted/provider.d.ts +38 -22
- package/dist/hosted/provider.js +500 -341
- package/dist/hosted/rest.d.ts +74 -0
- package/dist/hosted/rest.js +126 -0
- package/dist/hosted/scripts.d.ts +21 -3
- package/dist/hosted/scripts.js +76 -14
- package/dist/hosted/ssh-exec.d.ts +99 -0
- package/dist/hosted/ssh-exec.js +464 -0
- package/dist/hosted/values.d.ts +26 -0
- package/dist/hosted/values.js +63 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/isolation.d.ts +0 -2
- package/dist/isolation.js +3 -4
- package/dist/kernel.d.ts +0 -6
- package/dist/kernel.js +1 -5
- package/dist/kinds.d.ts +3 -1
- package/dist/local-chrome.d.ts +0 -6
- package/dist/local-chrome.js +1 -5
- package/dist/modal.d.ts +15 -86
- package/dist/modal.js +67 -185
- package/dist/mount-archil.d.ts +13 -8
- package/dist/mount-archil.js +27 -17
- package/dist/mount.d.ts +10 -4
- package/dist/mount.js +8 -4
- package/dist/orgo.d.ts +0 -9
- package/dist/orgo.js +8 -13
- package/dist/phone-harness.d.ts +0 -6
- package/dist/phone-harness.js +0 -4
- package/dist/protocol.d.ts +4 -1
- package/dist/protocol.js +1 -0
- package/dist/provider.d.ts +2 -2
- package/dist/providers.d.ts +15 -13
- package/dist/screen-watch.js +34 -6
- package/dist/surface/api.d.ts +14 -11
- package/dist/surface/core.d.ts +23 -5
- package/dist/surface/core.js +105 -15
- package/dist/surface/index.d.ts +1 -1
- package/dist/surface/index.js +1 -1
- package/dist/surface/outline.d.ts +2 -0
- package/dist/surface/outline.js +2 -1
- package/dist/surface/script.d.ts +4 -0
- package/dist/surface/script.js +11 -3
- package/dist/ui-engine.js +19 -3
- package/package.json +2 -3
- package/box/build-agent37.mjs +0 -177
- package/dist/conformance/daytona-sweep.d.ts +0 -18
- package/dist/conformance/daytona-sweep.js +0 -126
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
// The exec pre-check: the one thing a new vendor proves before writing anything else of its host. AgentRun installs its
|
|
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, byte-exact stream with no timeout (the contract is exec's doc comment in
|
|
4
|
+
// ../host.ts). This runs exec alone, on a machine the vendor made by hand, and says in plain words what it did wrong:
|
|
5
|
+
//
|
|
6
|
+
// npm run conformance -w @parcha/agentrun-computer -- --provider <id | ./module.js> --exec-stream --machine <id> [--quick]
|
|
7
|
+
//
|
|
8
|
+
// 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
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
11
|
+
import { words } from "../hosted/process.js";
|
|
12
|
+
/** The checks, in the order they run. */
|
|
13
|
+
export const EXEC_STREAM_CHECKS = ["stdout-bytes", "stdin-bytes", "large", "stdout-live", "stdin-live", "stderr", "exit-code", "kill", "no-timeout"];
|
|
14
|
+
export const DEFAULT_LONG_MS = 75_000;
|
|
15
|
+
/** --quick's no-timeout check: long enough to cross a second, short enough for CI. */
|
|
16
|
+
export const QUICK_LONG_MS = 5_000;
|
|
17
|
+
const DEFAULT_STEP_MS = 30_000;
|
|
18
|
+
const DEFAULT_LARGE_BYTES = 8 * 1024 * 1024;
|
|
19
|
+
const DEFAULT_LARGE_MS = 180_000;
|
|
20
|
+
/** What one write gives exec's stdin, as the adapter's own upload does (runToExit). */
|
|
21
|
+
const WRITE_CHUNK = 256 * 1024;
|
|
22
|
+
/** How long stdout-live watches, after "early", that stdout stays open and wait() has no answer. */
|
|
23
|
+
const LIVE_GRACE_MS = 1_000;
|
|
24
|
+
/**
|
|
25
|
+
* kill's probe, `sh -c PID_STATE_SCRIPT sh <pid>`: "running" or "gone". A killed process its parent has not reaped yet
|
|
26
|
+
* is a zombie, which kill -0 still finds; it has ended, so its /proc state (Z, or X) reads gone, and any other state
|
|
27
|
+
* running. Its state is read first, in one read, so a reap during the probe never reads as running; where there is no
|
|
28
|
+
* state to read (no /proc, a status hidden, or the process already gone), kill -0 answers.
|
|
29
|
+
*/
|
|
30
|
+
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';
|
|
31
|
+
/** A failed check: its words are the report's. */
|
|
32
|
+
class Problem extends Error {
|
|
33
|
+
}
|
|
34
|
+
const hex = (bytes) => [...bytes].map((b) => b.toString(16).padStart(2, "0")).join(" ");
|
|
35
|
+
const byte = (b) => `0x${b.toString(16).padStart(2, "0")}`;
|
|
36
|
+
const secondsOf = (ms) => `${Math.round(ms / 100) / 10} s`;
|
|
37
|
+
const shown = (argv) => argv.map((word) => (/^[\w./=:-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`)).join(" ");
|
|
38
|
+
const ALL_BYTES = Uint8Array.from({ length: 256 }, (_, i) => i);
|
|
39
|
+
/** printf's format for every byte value, 0 to 255, each as an octal escape: dash, bash and busybox all read it. */
|
|
40
|
+
const PRINTF_ALL = [...ALL_BYTES].map((b) => `\\${b.toString(8).padStart(3, "0")}`).join("");
|
|
41
|
+
/**
|
|
42
|
+
* Why `got` is not `sent`, in words, or undefined when they are the same bytes. `way` is where they went ("on stdout");
|
|
43
|
+
* the first byte that differs is named, and the usual ways an exec mangles bytes are named for what they are.
|
|
44
|
+
*/
|
|
45
|
+
export function bytesProblem(sent, got, way) {
|
|
46
|
+
let i = 0;
|
|
47
|
+
while (i < sent.length && i < got.length && sent[i] === got[i])
|
|
48
|
+
i++;
|
|
49
|
+
if (i === sent.length && i === got.length)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (i === got.length) {
|
|
52
|
+
const nul = sent[i] === 0 ? ": the first missing byte is 0x00, so your exec may treat output as C strings and stop at a NUL" : "";
|
|
53
|
+
return `only ${got.length} of ${sent.length} bytes came back ${way}${nul}. Pass every byte on as it comes`;
|
|
54
|
+
}
|
|
55
|
+
if (i === sent.length)
|
|
56
|
+
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 bytes`;
|
|
57
|
+
const b = sent[i];
|
|
58
|
+
const at = got.subarray(i, i + 3);
|
|
59
|
+
const was = `byte ${byte(b)} came back ${way} as ${hex(at)}`;
|
|
60
|
+
if (b >= 0x80 && at[0] === 0xef && at[1] === 0xbf && at[2] === 0xbd) {
|
|
61
|
+
return `${was}: your exec decodes UTF-8, which turns each byte that is not UTF-8 into U+FFFD (ef bf bd). Pass the bytes on as bytes, never as text`;
|
|
62
|
+
}
|
|
63
|
+
if (b >= 0x80 && at[0] === (0xc0 | (b >> 6)) && at[1] === (0x80 | (b & 0x3f))) {
|
|
64
|
+
return `${was}: your exec reads bytes as Latin-1 text and writes them back as UTF-8. Pass the bytes on as bytes, never as text`;
|
|
65
|
+
}
|
|
66
|
+
if (b === 0x0a && at[0] === 0x0d && at[1] === 0x0a)
|
|
67
|
+
return `${was}: your exec turns \\n into \\r\\n, as a terminal does. Run the process on pipes, not a terminal`;
|
|
68
|
+
if (b === 0x0d && at[0] === 0x0a)
|
|
69
|
+
return `${was}: your exec drops \\r, as newline translation does. Pass every byte on as it comes`;
|
|
70
|
+
return `${was} (offset ${i}): your exec changes bytes. Pass every byte on as it comes, unchanged`;
|
|
71
|
+
}
|
|
72
|
+
/** One output stream of a process, read as it comes: its bytes so far, whether it ended, and a wait for more. */
|
|
73
|
+
class Reader {
|
|
74
|
+
#chunks = [];
|
|
75
|
+
length = 0;
|
|
76
|
+
ended = false;
|
|
77
|
+
error;
|
|
78
|
+
#wake = [];
|
|
79
|
+
constructor(stream) {
|
|
80
|
+
void this.#pump(stream);
|
|
81
|
+
}
|
|
82
|
+
async #pump(stream) {
|
|
83
|
+
try {
|
|
84
|
+
for await (const chunk of stream) {
|
|
85
|
+
// A copy: a vendor's client may reuse its buffer.
|
|
86
|
+
this.#chunks.push(Buffer.from(chunk));
|
|
87
|
+
this.length += chunk.byteLength;
|
|
88
|
+
this.#nudge();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
this.error = error;
|
|
93
|
+
}
|
|
94
|
+
this.ended = true;
|
|
95
|
+
this.#nudge();
|
|
96
|
+
}
|
|
97
|
+
#nudge() {
|
|
98
|
+
const waiting = this.#wake;
|
|
99
|
+
this.#wake = [];
|
|
100
|
+
for (const wake of waiting)
|
|
101
|
+
wake();
|
|
102
|
+
}
|
|
103
|
+
bytes() {
|
|
104
|
+
return Buffer.concat(this.#chunks);
|
|
105
|
+
}
|
|
106
|
+
/** Waits until `enough` holds, the stream ends, or ms pass; answers whether `enough` holds. */
|
|
107
|
+
async until(enough, ms, signal) {
|
|
108
|
+
const deadline = Date.now() + ms;
|
|
109
|
+
while (!enough() && !this.ended && Date.now() < deadline && !signal?.aborted) {
|
|
110
|
+
await new Promise((done) => {
|
|
111
|
+
const timer = setTimeout(done, Math.max(1, deadline - Date.now()));
|
|
112
|
+
const finish = () => {
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
signal?.removeEventListener("abort", finish);
|
|
115
|
+
done();
|
|
116
|
+
};
|
|
117
|
+
signal?.addEventListener("abort", finish, { once: true });
|
|
118
|
+
this.#wake.push(finish);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return enough();
|
|
122
|
+
}
|
|
123
|
+
/** Waits for the stream's end, at most ms; answers whether it ended. */
|
|
124
|
+
end(ms, signal) {
|
|
125
|
+
return this.until(() => this.ended, ms, signal);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** A promise's value (or its rejection), or `late` once ms pass or signal aborts. */
|
|
129
|
+
function within(promise, ms, late, signal) {
|
|
130
|
+
return new Promise((settle, reject) => {
|
|
131
|
+
const timer = setTimeout(() => finish(() => settle(late)), ms);
|
|
132
|
+
const onAbort = () => finish(() => settle(late));
|
|
133
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
134
|
+
let settled = false;
|
|
135
|
+
function finish(then) {
|
|
136
|
+
if (settled)
|
|
137
|
+
return;
|
|
138
|
+
settled = true;
|
|
139
|
+
clearTimeout(timer);
|
|
140
|
+
signal?.removeEventListener("abort", onAbort);
|
|
141
|
+
then();
|
|
142
|
+
}
|
|
143
|
+
promise.then((value) => finish(() => settle(value)), (error) => finish(() => reject(error)));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const LATE = Symbol("late");
|
|
147
|
+
/** The pre-check's run of host.exec on one machine. */
|
|
148
|
+
class Session {
|
|
149
|
+
#host;
|
|
150
|
+
#machine;
|
|
151
|
+
#stepMs;
|
|
152
|
+
#signal;
|
|
153
|
+
#runs = [];
|
|
154
|
+
constructor(host, machine, stepMs, signal) {
|
|
155
|
+
this.#host = host;
|
|
156
|
+
this.#machine = machine;
|
|
157
|
+
this.#stepMs = stepMs;
|
|
158
|
+
this.#signal = signal;
|
|
159
|
+
}
|
|
160
|
+
get stepMs() {
|
|
161
|
+
return this.#stepMs;
|
|
162
|
+
}
|
|
163
|
+
get signal() {
|
|
164
|
+
return this.#signal;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* exec(argv), answered within the step's bound; any failure (a throw) is a Problem naming the command. Without stdin,
|
|
168
|
+
* end() is called at once, as the adapter does.
|
|
169
|
+
*/
|
|
170
|
+
async start(argv, stdin) {
|
|
171
|
+
const what = `exec of ${shown(argv)}`;
|
|
172
|
+
let answer;
|
|
173
|
+
try {
|
|
174
|
+
answer = Promise.resolve(this.#host.exec(this.#machine, argv, { timeoutMs: this.#stepMs, ...(this.#signal ? { signal: this.#signal } : {}) }));
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
throw new Problem(`${what} threw: ${words(error)}`);
|
|
178
|
+
}
|
|
179
|
+
let answered;
|
|
180
|
+
try {
|
|
181
|
+
answered = await within(answer, this.#stepMs + 5_000, LATE, this.#signal);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
throw new Problem(`${what} failed: ${words(error)}`);
|
|
185
|
+
}
|
|
186
|
+
if (answered === LATE) {
|
|
187
|
+
// One that answers after this gave up is killed as it lands.
|
|
188
|
+
answer.then((late) => late?.kill?.()).catch(() => { });
|
|
189
|
+
throw new Problem(`${what} did not answer within ${secondsOf(this.#stepMs)}: exec answers once the process has started, not when it ends`);
|
|
190
|
+
}
|
|
191
|
+
if (answered === undefined || answered === null || typeof answered !== "object")
|
|
192
|
+
throw new Problem(`${what} answered ${String(answered)}, not a process: answer the MachineProcess or throw`);
|
|
193
|
+
const proc = answered;
|
|
194
|
+
const lacks = ["write", "end", "wait", "kill"].filter((name) => typeof proc?.[name] !== "function");
|
|
195
|
+
if (proc?.stdout?.[Symbol.asyncIterator] === undefined)
|
|
196
|
+
lacks.unshift("stdout");
|
|
197
|
+
if (proc?.stderr?.[Symbol.asyncIterator] === undefined)
|
|
198
|
+
lacks.unshift("stderr");
|
|
199
|
+
if (lacks.length > 0)
|
|
200
|
+
throw new Problem(`${what} answered a process that lacks ${lacks.join(", ")}: a MachineProcess (src/host.ts) has stdout, stderr, write, end, wait and kill`);
|
|
201
|
+
const run = { proc, out: new Reader(proc.stdout), err: new Reader(proc.stderr), exited: Promise.resolve(0) };
|
|
202
|
+
run.exited = Promise.resolve()
|
|
203
|
+
.then(() => proc.wait())
|
|
204
|
+
.then((code) => {
|
|
205
|
+
run.exitCode = code;
|
|
206
|
+
return code;
|
|
207
|
+
});
|
|
208
|
+
run.exited.catch(() => { });
|
|
209
|
+
this.#runs.push(run);
|
|
210
|
+
// Not awaited: a command that reads no input runs on whether or not the vendor answers the close.
|
|
211
|
+
if (!stdin)
|
|
212
|
+
Promise.resolve().then(() => proc.end()).catch(() => { });
|
|
213
|
+
return run;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Writes bytes to the process's stdin, in WRITE_CHUNK pieces, one after another; a refusal is a Problem. Each write
|
|
217
|
+
* is bounded by the step, and by `by` when the check has one deadline for all of its steps.
|
|
218
|
+
*/
|
|
219
|
+
async write(run, bytes, what, by) {
|
|
220
|
+
for (let at = 0; at < bytes.length; at += WRITE_CHUNK) {
|
|
221
|
+
const ms = by ? by.left(this.#stepMs) : this.#stepMs;
|
|
222
|
+
// Whether the deadline, not the step, set this bound. Asking by.passed() after the timeout is not enough: a
|
|
223
|
+
// timer can fire a millisecond before Date.now() reads the deadline.
|
|
224
|
+
const deadlineBound = by !== undefined && ms < this.#stepMs;
|
|
225
|
+
const written = await within(Promise.resolve().then(() => run.proc.write(bytes.subarray(at, at + WRITE_CHUNK))), ms, LATE, this.#signal).catch((error) => {
|
|
226
|
+
throw new Problem(`write() of ${what} failed while the process ran: ${words(error)}`);
|
|
227
|
+
});
|
|
228
|
+
// within() answers LATE for an abort too: a stopped write names no bound that did not run out.
|
|
229
|
+
if (written === LATE && this.#signal?.aborted)
|
|
230
|
+
throw new Problem(`writing ${what} was stopped, with ${at} bytes written`);
|
|
231
|
+
if (written === LATE)
|
|
232
|
+
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)}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/** Ends the process's stdin; a refusal is a Problem. */
|
|
236
|
+
async end(run, by) {
|
|
237
|
+
const ms = by ? by.left(this.#stepMs) : this.#stepMs;
|
|
238
|
+
const ended = await within(Promise.resolve().then(() => run.proc.end()), ms, LATE, this.#signal).catch((error) => {
|
|
239
|
+
throw new Problem(`end() failed: ${words(error)}`);
|
|
240
|
+
});
|
|
241
|
+
if (ended === LATE)
|
|
242
|
+
throw new Problem(`end() did not answer within ${secondsOf(ms)}`);
|
|
243
|
+
}
|
|
244
|
+
/** wait()'s exit code within ms; one that never comes, or a wait() that throws, is a Problem. */
|
|
245
|
+
async exit(run, ms, what) {
|
|
246
|
+
let code;
|
|
247
|
+
try {
|
|
248
|
+
code = await within(run.exited, ms, LATE, this.#signal);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
throw new Problem(`wait() for ${what} threw: ${words(error)}`);
|
|
252
|
+
}
|
|
253
|
+
if (code === LATE)
|
|
254
|
+
throw new Problem(`wait() for ${what} gave no exit code within ${secondsOf(ms)}`);
|
|
255
|
+
if (typeof code !== "number" || !Number.isInteger(code))
|
|
256
|
+
throw new Problem(`wait() for ${what} answered ${String(code)}, not an exit code`);
|
|
257
|
+
return code;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Kills every process this session started, after each check, pass or fail. Every one, ended or not: an exit code
|
|
261
|
+
* from the wait() under test is no proof the process is gone, and kill() of an ended one costs nothing.
|
|
262
|
+
*/
|
|
263
|
+
async killAll() {
|
|
264
|
+
const runs = this.#runs.splice(0);
|
|
265
|
+
await Promise.all(runs.map((run) => within(Promise.resolve().then(() => run.proc.kill()), 10_000, undefined).catch(() => { })));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** One deadline for every step of a check: what is left of it, at most a step's bound. */
|
|
269
|
+
class Deadline {
|
|
270
|
+
ms;
|
|
271
|
+
#at;
|
|
272
|
+
constructor(ms) {
|
|
273
|
+
this.ms = ms;
|
|
274
|
+
this.#at = Date.now() + ms;
|
|
275
|
+
}
|
|
276
|
+
left(most) {
|
|
277
|
+
return Math.max(1, Math.min(most, this.#at - Date.now()));
|
|
278
|
+
}
|
|
279
|
+
passed() {
|
|
280
|
+
return Date.now() >= this.#at;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const CHECKS = {
|
|
284
|
+
/** Every byte value out, on stdout alone: printf in the machine writes them. */
|
|
285
|
+
async "stdout-bytes"(s) {
|
|
286
|
+
const argv = ["sh", "-c", 'printf "$1"', "sh", PRINTF_ALL];
|
|
287
|
+
const run = await s.start(argv, false);
|
|
288
|
+
if (!(await run.out.end(s.stepMs, s.signal)))
|
|
289
|
+
throw new Problem(`stdout of printf did not end within ${secondsOf(s.stepMs)} of its start`);
|
|
290
|
+
const code = await s.exit(run, s.stepMs, "printf");
|
|
291
|
+
if (code !== 0)
|
|
292
|
+
throw new Problem(`printf of the 256 byte values exited ${code} (stderr: ${run.err.bytes().toString("utf8").trim().slice(0, 200) || "none"})`);
|
|
293
|
+
const problem = bytesProblem(ALL_BYTES, run.out.bytes(), "on stdout");
|
|
294
|
+
if (problem)
|
|
295
|
+
throw new Problem(problem);
|
|
296
|
+
return "all 256 byte values printed in the machine came back unchanged on stdout";
|
|
297
|
+
},
|
|
298
|
+
/** Every byte value in on stdin and out again, through cat. */
|
|
299
|
+
async "stdin-bytes"(s, _options, earlier) {
|
|
300
|
+
const run = await s.start(["cat"], true);
|
|
301
|
+
await s.write(run, ALL_BYTES, "the 256 byte values");
|
|
302
|
+
await s.end(run);
|
|
303
|
+
if (!(await run.out.end(s.stepMs, s.signal)))
|
|
304
|
+
throw new Problem(`cat's stdout did not end within ${secondsOf(s.stepMs)} of end(): end() must close the process's stdin, so it reads end of file`);
|
|
305
|
+
await s.exit(run, s.stepMs, "cat");
|
|
306
|
+
const outOk = earlier.get("stdout-bytes")?.status === "pass";
|
|
307
|
+
const problem = bytesProblem(ALL_BYTES, run.out.bytes(), "through cat");
|
|
308
|
+
if (problem)
|
|
309
|
+
throw new Problem(outOk ? `${problem}. stdout alone passes every byte (stdout-bytes), so they changed on the way in, on stdin` : problem);
|
|
310
|
+
return "all 256 byte values written to stdin came back unchanged through cat";
|
|
311
|
+
},
|
|
312
|
+
/** A large random payload through cat, read while it is written, compared by sha256, all within largeMs. */
|
|
313
|
+
async large(s, { largeBytes, largeMs }) {
|
|
314
|
+
const payload = randomBytes(largeBytes);
|
|
315
|
+
const started = Date.now();
|
|
316
|
+
const by = new Deadline(largeMs);
|
|
317
|
+
const run = await s.start(["cat"], true);
|
|
318
|
+
await s.write(run, payload, `${largeBytes} random bytes`, by);
|
|
319
|
+
await s.end(run, by);
|
|
320
|
+
if (!(await run.out.end(by.left(largeMs), s.signal))) {
|
|
321
|
+
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`);
|
|
322
|
+
}
|
|
323
|
+
await s.exit(run, by.left(s.stepMs), "cat");
|
|
324
|
+
if (by.passed())
|
|
325
|
+
throw new Problem(`${largeBytes} bytes through cat took ${secondsOf(Date.now() - started)}, past ${secondsOf(largeMs)}: your exec is too slow`);
|
|
326
|
+
const got = run.out.bytes();
|
|
327
|
+
const sent = createHash("sha256").update(payload).digest("hex");
|
|
328
|
+
const back = createHash("sha256").update(got).digest("hex");
|
|
329
|
+
if (sent !== back) {
|
|
330
|
+
throw new Problem(`${largeBytes} random bytes went in, ${got.length} came back with sha256 ${back.slice(0, 16)}…, not ${sent.slice(0, 16)}…: ${bytesProblem(payload, got, "through cat") ?? "they differ"}`);
|
|
331
|
+
}
|
|
332
|
+
return `${largeBytes} random bytes came back through cat with the same sha256 in ${secondsOf(Date.now() - started)}`;
|
|
333
|
+
},
|
|
334
|
+
/** Output comes back while the process runs: printf, then a sleep that never ends on its own. */
|
|
335
|
+
async "stdout-live"(s) {
|
|
336
|
+
const run = await s.start(["sh", "-c", "printf early; exec sleep 600"], false);
|
|
337
|
+
const came = await run.out.until(() => run.out.length >= 5, s.stepMs, s.signal);
|
|
338
|
+
if (!came) {
|
|
339
|
+
if (run.out.ended)
|
|
340
|
+
throw new Problem(`stdout ended with ${JSON.stringify(run.out.bytes().toString("latin1"))} before the process did: stdout must stay open until the process ends`);
|
|
341
|
+
throw new Problem(`the process printed "early" at once, then slept, and nothing came back on stdout in ${secondsOf(s.stepMs)}: your exec holds output until the process exits. Pass each byte on as it comes`);
|
|
342
|
+
}
|
|
343
|
+
const got = run.out.bytes().toString("latin1");
|
|
344
|
+
if (got !== "early")
|
|
345
|
+
throw new Problem(`stdout read ${JSON.stringify(got)}, not "early"`);
|
|
346
|
+
// "early" alone is not live: the sleep still runs, so stdout stays open and wait() has no answer yet.
|
|
347
|
+
if (await run.out.end(LIVE_GRACE_MS, s.signal))
|
|
348
|
+
throw new Problem(`stdout ended right after "early", while the process still slept: stdout must stay open until the process ends`);
|
|
349
|
+
if (run.exitCode !== undefined)
|
|
350
|
+
throw new Problem(`wait() answered ${run.exitCode} right after "early", while the process still slept: wait() answers once the process ends`);
|
|
351
|
+
return `"early" came back while the process still ran`;
|
|
352
|
+
},
|
|
353
|
+
/** stdin reaches the process as it is written: cat echoes one write, then another, with stdin still open. */
|
|
354
|
+
async "stdin-live"(s, _options, earlier) {
|
|
355
|
+
const run = await s.start(["cat"], true);
|
|
356
|
+
const outLive = earlier.get("stdout-live")?.status === "pass";
|
|
357
|
+
const rounds = [Buffer.from("first write\n"), Buffer.from("second write\n")];
|
|
358
|
+
let want = 0;
|
|
359
|
+
for (const [i, chunk] of rounds.entries()) {
|
|
360
|
+
await s.write(run, chunk, `write ${i + 1}`);
|
|
361
|
+
want += chunk.length;
|
|
362
|
+
const came = await run.out.until(() => run.out.length >= want, s.stepMs, s.signal);
|
|
363
|
+
if (!came) {
|
|
364
|
+
if (run.out.ended)
|
|
365
|
+
throw new Problem(`cat's stdout ended after write ${i + 1}, with stdin still open: exec must keep the process and its stdin open until end()`);
|
|
366
|
+
throw new Problem(outLive
|
|
367
|
+
? `write ${i + 1} to cat, with stdin still open, never came back on stdout in ${secondsOf(s.stepMs)}, though output does come back as it is printed: your exec holds stdin until end(). Pass each write on as it comes`
|
|
368
|
+
: `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)`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
const problem = bytesProblem(Buffer.concat(rounds), run.out.bytes(), "through cat");
|
|
372
|
+
if (problem)
|
|
373
|
+
throw new Problem(problem);
|
|
374
|
+
await s.end(run);
|
|
375
|
+
const code = await s.exit(run, s.stepMs, "cat");
|
|
376
|
+
if (code !== 0)
|
|
377
|
+
throw new Problem(`cat exited ${code} after end(), not 0`);
|
|
378
|
+
return "two writes came back through cat, each before the next was written, while stdin stayed open";
|
|
379
|
+
},
|
|
380
|
+
/** stderr comes back apart from stdout. */
|
|
381
|
+
async stderr(s) {
|
|
382
|
+
const run = await s.start(["sh", "-c", "printf to-stdout; printf to-stderr >&2"], false);
|
|
383
|
+
await run.out.end(s.stepMs, s.signal);
|
|
384
|
+
await run.err.end(s.stepMs, s.signal);
|
|
385
|
+
await s.exit(run, s.stepMs, "the two printfs");
|
|
386
|
+
const out = run.out.bytes().toString("latin1");
|
|
387
|
+
const err = run.err.bytes().toString("latin1");
|
|
388
|
+
if (out.includes("to-stderr"))
|
|
389
|
+
throw new Problem(`what the process wrote to stderr came back on stdout (stdout read ${JSON.stringify(out)}): your exec merges the two streams. Keep them apart`);
|
|
390
|
+
if (err.includes("to-stdout"))
|
|
391
|
+
throw new Problem(`what the process wrote to stdout came back on stderr (stderr read ${JSON.stringify(err)}): keep the two streams apart`);
|
|
392
|
+
if (out !== "to-stdout")
|
|
393
|
+
throw new Problem(`stdout read ${JSON.stringify(out)}, not "to-stdout"`);
|
|
394
|
+
if (err !== "to-stderr")
|
|
395
|
+
throw new Problem(`stderr read ${JSON.stringify(err)}, not "to-stderr": your exec drops or changes stderr`);
|
|
396
|
+
return "stdout and stderr came back apart, each with its own bytes";
|
|
397
|
+
},
|
|
398
|
+
/** wait() gives the process's own exit code. */
|
|
399
|
+
async "exit-code"(s) {
|
|
400
|
+
const run = await s.start(["sh", "-c", "exit 7"], false);
|
|
401
|
+
const code = await s.exit(run, s.stepMs, "sh -c 'exit 7'");
|
|
402
|
+
if (code !== 7)
|
|
403
|
+
throw new Problem(`sh -c 'exit 7' gave ${code} from wait(), not 7: wait() answers the process's own exit code`);
|
|
404
|
+
return "wait() gave 7 for sh -c 'exit 7'";
|
|
405
|
+
},
|
|
406
|
+
/** kill() ends a process that would run for ten minutes, wait() then answers, and the process is gone. */
|
|
407
|
+
async kill(s) {
|
|
408
|
+
const run = await s.start(["sh", "-c", "echo $$; exec sleep 600"], false);
|
|
409
|
+
const line = await run.out.until(() => run.out.bytes().includes(0x0a), s.stepMs, s.signal);
|
|
410
|
+
if (!line)
|
|
411
|
+
throw new Problem(`the process's pid never came back on stdout in ${secondsOf(s.stepMs)}`);
|
|
412
|
+
const pid = run.out.bytes().toString("latin1").trim();
|
|
413
|
+
if (!/^[1-9][0-9]*$/.test(pid))
|
|
414
|
+
throw new Problem(`the process printed ${JSON.stringify(pid)}, not its pid`);
|
|
415
|
+
const killed = await within(Promise.resolve().then(() => run.proc.kill()), s.stepMs, LATE, s.signal).catch((error) => {
|
|
416
|
+
throw new Problem(`kill() threw: ${words(error)}. It ends the process best effort and never throws`);
|
|
417
|
+
});
|
|
418
|
+
if (killed === LATE)
|
|
419
|
+
throw new Problem(`kill() did not answer within ${secondsOf(s.stepMs)}`);
|
|
420
|
+
// wait() after kill, then the machine's own word on the pid, whichever fails first named by the second.
|
|
421
|
+
const waited = await s.exit(run, s.stepMs, "the killed sleep").then(() => undefined, (error) => error);
|
|
422
|
+
const probe = await s.start(["sh", "-c", PID_STATE_SCRIPT, "sh", pid], false);
|
|
423
|
+
await probe.out.end(s.stepMs, s.signal);
|
|
424
|
+
await s.exit(probe, s.stepMs, "kill -0");
|
|
425
|
+
const state = probe.out.bytes().toString("latin1").trim();
|
|
426
|
+
if (state === "running")
|
|
427
|
+
throw new Problem(`kill() answered, but process ${pid} still runs in the machine: kill() must end the process, not only let go of its streams`);
|
|
428
|
+
if (state !== "gone")
|
|
429
|
+
throw new Problem(`kill -0 ${pid} printed ${JSON.stringify(state)}, not "gone"`);
|
|
430
|
+
if (waited !== undefined)
|
|
431
|
+
throw waited;
|
|
432
|
+
return `kill() ended a sleep of 600 s, wait() answered, and process ${pid} is gone`;
|
|
433
|
+
},
|
|
434
|
+
/** A process that runs, silent, past the usual command and idle timeouts is not cut off. */
|
|
435
|
+
async "no-timeout"(s, { longMs }) {
|
|
436
|
+
const seconds = Math.max(1, Math.round(longMs / 1000));
|
|
437
|
+
const started = Date.now();
|
|
438
|
+
const run = await s.start(["sh", "-c", `sleep ${seconds}; printf done`], false);
|
|
439
|
+
await run.out.end(seconds * 1000 + s.stepMs, s.signal);
|
|
440
|
+
const code = await s.exit(run, s.stepMs, `sleep ${seconds}`);
|
|
441
|
+
const ran = Date.now() - started;
|
|
442
|
+
const out = run.out.bytes().toString("latin1");
|
|
443
|
+
if (code !== 0 || out !== "done") {
|
|
444
|
+
const how = code !== 0 ? `exited ${code}` : `printed ${JSON.stringify(out)}`;
|
|
445
|
+
throw new Problem(`a process that sleeps ${seconds} s, silent, then prints "done", ${how} after ${secondsOf(ran)}: your exec has a command timeout, or the stream an idle timeout. Turn both off: AgentRun's daemon talks over one exec for the computer's whole life`);
|
|
446
|
+
}
|
|
447
|
+
if (ran < seconds * 1000 - 1000)
|
|
448
|
+
throw new Problem(`a sleep of ${seconds} s ended after ${secondsOf(ran)}`);
|
|
449
|
+
return `a process that slept ${seconds} s, silent, ran to its end and printed "done"`;
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* The exec pre-check on one machine: each check in EXEC_STREAM_CHECKS runs in turn, and the report passes when every one
|
|
454
|
+
* does. host.exec is the only member called.
|
|
455
|
+
*/
|
|
456
|
+
export async function checkExecStream(host, machine, options = {}) {
|
|
457
|
+
const { longMs = DEFAULT_LONG_MS, stepMs = DEFAULT_STEP_MS, largeBytes = DEFAULT_LARGE_BYTES, largeMs = DEFAULT_LARGE_MS, signal, onCheck } = options;
|
|
458
|
+
const session = new Session(host, machine, stepMs, signal);
|
|
459
|
+
const done = new Map();
|
|
460
|
+
for (const id of EXEC_STREAM_CHECKS) {
|
|
461
|
+
const started = Date.now();
|
|
462
|
+
let check;
|
|
463
|
+
if (signal?.aborted)
|
|
464
|
+
check = { id, status: "fail", words: "the run was aborted before this check", ms: 0 };
|
|
465
|
+
else {
|
|
466
|
+
try {
|
|
467
|
+
const said = await CHECKS[id](session, { longMs, largeBytes, largeMs }, done);
|
|
468
|
+
check = { id, status: "pass", words: said, ms: Date.now() - started };
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
const said = error instanceof Problem ? error.message : `the check itself failed: ${words(error)}`;
|
|
472
|
+
check = { id, status: "fail", words: signal?.aborted ? `aborted: ${said}` : said, ms: Date.now() - started };
|
|
473
|
+
}
|
|
474
|
+
await session.killAll();
|
|
475
|
+
}
|
|
476
|
+
done.set(id, check);
|
|
477
|
+
onCheck?.(check);
|
|
478
|
+
}
|
|
479
|
+
const checks = [...done.values()];
|
|
480
|
+
return { host: host.descriptor.id, machine, checks, pass: checks.every((check) => check.status === "pass") };
|
|
481
|
+
}
|
|
482
|
+
/** The report as a person reads it: one line per check, what failed in words, the verdict last. */
|
|
483
|
+
export function formatExecStream(report) {
|
|
484
|
+
const width = Math.max(...EXEC_STREAM_CHECKS.map((id) => id.length));
|
|
485
|
+
const lines = [`exec pre-check · ${report.host} · machine ${report.machine}`];
|
|
486
|
+
for (const check of report.checks)
|
|
487
|
+
lines.push(`${check.status === "pass" ? "✓" : "✗"} ${check.id.padEnd(width)} ${check.words}`);
|
|
488
|
+
const failed = report.checks.filter((check) => check.status === "fail").length;
|
|
489
|
+
lines.push(report.pass
|
|
490
|
+
? "exec PASS: a live, two-way, byte-exact stream with no timeout. Write the rest of your host next."
|
|
491
|
+
: `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.`);
|
|
492
|
+
return `${lines.join("\n")}\n`;
|
|
493
|
+
}
|
|
@@ -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
|
}
|
|
@@ -39,7 +39,7 @@ export function settingsFromEnv(env = process.env) {
|
|
|
39
39
|
export const CONFORMANCE_MAX_LIFETIME_MS = 30 * 60_000;
|
|
40
40
|
function live(env) {
|
|
41
41
|
if (env[MODAL_ENV.live] !== "1") {
|
|
42
|
-
throw new Error(`the Modal conformance module makes real sandboxes: set ${MODAL_ENV.live}=1, with a key
|
|
42
|
+
throw new Error(`the Modal conformance module makes real sandboxes: set ${MODAL_ENV.live}=1, with a key for an account you can bill, to run it`);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
/** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
|
package/dist/conformance/orgo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Orgo for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider orgo [--image <template>]`.
|
|
2
|
-
// It makes real Orgo desktops, so it runs only with AGENTRUN_COMPUTER_LIVE_ORGO=1 and a key
|
|
2
|
+
// It makes real Orgo desktops, so it runs only with AGENTRUN_COMPUTER_LIVE_ORGO=1 and a key for an account you can bill, under
|
|
3
3
|
// COMPUTER_ORGO_API_KEY (never ORGO_API_KEY), in the workspace COMPUTER_ORGO_WORKSPACE names, or the key's account's one
|
|
4
4
|
// workspace when it names none. The live switch is checked first, before any other setting is read.
|
|
5
5
|
//
|
|
@@ -36,7 +36,7 @@ export const conformanceNotes = [
|
|
|
36
36
|
];
|
|
37
37
|
function live(env) {
|
|
38
38
|
if (env[ORGO_ENV.live] !== "1") {
|
|
39
|
-
throw new Error(`the Orgo conformance module makes real computers: set ${ORGO_ENV.live}=1, with a key
|
|
39
|
+
throw new Error(`the Orgo conformance module makes real computers: set ${ORGO_ENV.live}=1, with a key for an account you can bill, to run it`);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
/** The desktop COMPUTER_ORGO_OS names, linux when it names none; a throw in words for any other. */
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
//
|
|
7
7
|
// --before records into <file> the id of every machine the vendor lists with the adapter's label agentrun.computer=1.
|
|
8
8
|
// --after lists them again, deletes every one whose id is not in <file> and that carries a conformance run's label
|
|
9
|
-
// (agentrun.conformance, RUN_LABEL), then reads each of those back until the vendor no longer has it
|
|
10
|
-
//
|
|
9
|
+
// (agentrun.conformance, RUN_LABEL), then reads each of those back by get until the vendor no longer has it, up to 60 s
|
|
10
|
+
// each, and prints one JSON line, {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every
|
|
11
11
|
// conformance machine it found that was not there before, gone + stillThere.length = swept, and leftAlone counts the new
|
|
12
12
|
// labelled machines with no conformance label, which another user of the account made during the run: never touched. A
|
|
13
13
|
// machine in <file> is never touched either: no call names it, and a before file of another provider is refused, as is
|
|
@@ -22,7 +22,7 @@ import { readFileSync, writeFileSync } from "node:fs";
|
|
|
22
22
|
import { COMPUTER_LABEL } from "../drift.js";
|
|
23
23
|
import { isCommand } from "../entry.js";
|
|
24
24
|
import { hostCall } from "../hosted/process.js";
|
|
25
|
-
import { NAME_LABEL,
|
|
25
|
+
import { foundBy, listedBy, NAME_LABEL, settle } from "../hosted/provider.js";
|
|
26
26
|
import { providerModule } from "../providers.js";
|
|
27
27
|
import { ok } from "../result.js";
|
|
28
28
|
import { RUN_LABEL } from "./runner.js";
|
|
@@ -32,7 +32,7 @@ import { RUN_LABEL } from "./runner.js";
|
|
|
32
32
|
* vendor refused is the error, with nothing deleted.
|
|
33
33
|
*/
|
|
34
34
|
export async function sweepMachines(host, { labels = {}, before = new Set(), waitMs = 60_000, pollMs = 2_000, requestMs = 30_000, listMs = 60_000, onWords = () => { } } = {}) {
|
|
35
|
-
const listed = await
|
|
35
|
+
const listed = await foundBy(host, "the listing", { ...labels, [COMPUTER_LABEL]: "1" }, { listMs, requestMs });
|
|
36
36
|
if (!listed.ok)
|
|
37
37
|
return listed;
|
|
38
38
|
const added = listed.value.filter((machine) => !before.has(machine.id));
|
|
@@ -44,10 +44,10 @@ export async function sweepMachines(host, { labels = {}, before = new Set(), wai
|
|
|
44
44
|
if (!deleted.ok && deleted.error.code !== "not_found")
|
|
45
45
|
onWords(`${machine.id} was not deleted: ${deleted.error.message}`);
|
|
46
46
|
}
|
|
47
|
-
// Each read back on its own, at once: gone once
|
|
47
|
+
// Each read back on its own, at once: gone once get reads it gone (settle).
|
|
48
48
|
const gone = await Promise.all(fresh.map(async (machine) => {
|
|
49
49
|
const name = machine.labels[NAME_LABEL] ?? machine.id;
|
|
50
|
-
const settled = await
|
|
50
|
+
const settled = await settle(host, { id: machine.id, name }, { requestMs, pollMs, goneMs: waitMs });
|
|
51
51
|
if (!settled.ok)
|
|
52
52
|
onWords(`${machine.id} is still there after ${waitMs / 1000} s: ${settled.error.message}`);
|
|
53
53
|
return settled.ok;
|
|
@@ -56,7 +56,7 @@ export async function sweepMachines(host, { labels = {}, before = new Set(), wai
|
|
|
56
56
|
return ok({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone });
|
|
57
57
|
}
|
|
58
58
|
const USAGE = `usage: node packages/computer/dist/conformance/sweep.js --provider <id> --before <file> | --after <file>
|
|
59
|
-
--provider <id> a provider on the shared machine-host adapter (e2b, agent37)
|
|
59
|
+
--provider <id> a provider on the shared machine-host adapter (e2b, agent37, daytona)
|
|
60
60
|
--before <file> record the id of every machine the vendor lists with ${COMPUTER_LABEL}=1 into <file>
|
|
61
61
|
--after <file> delete every machine listed with ${COMPUTER_LABEL}=1 and ${RUN_LABEL} whose id is not in <file>, read
|
|
62
62
|
each back until the vendor no longer has it (up to 60 s each), and print
|
|
@@ -161,7 +161,7 @@ export async function main(argv, io = {}) {
|
|
|
161
161
|
return 2;
|
|
162
162
|
}
|
|
163
163
|
if (before === undefined) {
|
|
164
|
-
const listed = await
|
|
164
|
+
const listed = await listedBy(host, "the listing", { [COMPUTER_LABEL]: "1" }, 60_000);
|
|
165
165
|
if (!listed.ok) {
|
|
166
166
|
await write(stderr, `listing the machines carrying ${COMPUTER_LABEL}=1 failed, so nothing was recorded: ${listed.error.message}\n`);
|
|
167
167
|
return 2;
|
|
@@ -277,8 +277,8 @@ export interface ConformanceOptions {
|
|
|
277
277
|
/** The same provider with a daemon that reports another version, for the drift cases. */
|
|
278
278
|
drifted?: () => Promise<ComputerProvider> | ComputerProvider;
|
|
279
279
|
/**
|
|
280
|
-
* What the provider declares of itself, each configuration's kind and groups, for health.declared: its descriptor
|
|
281
|
-
*
|
|
280
|
+
* What the provider declares of itself, each configuration's kind and groups, for health.declared: its descriptor's
|
|
281
|
+
* capabilities. Without it (a provider module given by path), that case skips.
|
|
282
282
|
*/
|
|
283
283
|
declared?: readonly KindCapabilities[];
|
|
284
284
|
/**
|
|
@@ -23,7 +23,7 @@ export declare function specDiffer(asked: ComputerSpec, have: ComputerSpec, { us
|
|
|
23
23
|
* fields this provider reads back as they were asked: each one asked, or read back, with another value. A size the
|
|
24
24
|
* spec left out is the vendor's default, so it differs from none. Labels are the provider's to compare, by its own.
|
|
25
25
|
*/
|
|
26
|
-
export declare function readBackDiffer(asked: ComputerSpec, have: ReadBackSpec, fields: ReadonlyArray<"image" | "network" | "user" | "cpus" | "memoryMb" | "pids">): string[];
|
|
26
|
+
export declare function readBackDiffer(asked: ComputerSpec, have: ReadBackSpec, fields: ReadonlyArray<"image" | "network" | "user" | "cpus" | "memoryMb" | "pids" | "gpu">): string[];
|
|
27
27
|
export interface CreateOnce {
|
|
28
28
|
refuse: Refuse;
|
|
29
29
|
/** Why the provider does not serve the spec, in words, when it does not: refused once the request id is checked. */
|