@parcha/agentrun-computer 0.0.0-placeholder → 0.1.0-beta.32
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/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +2400 -1
- package/box/Dockerfile +69 -0
- package/box/agentrun-archil +168 -0
- package/box/build-daytona.py +26 -0
- package/box/build-e2b.mjs +32 -0
- package/box/build-modal.py +17 -0
- package/dist/actions.d.ts +18 -0
- package/dist/actions.js +139 -0
- package/dist/browser.d.ts +151 -0
- package/dist/browser.js +305 -0
- package/dist/browserbase.d.ts +139 -0
- package/dist/browserbase.js +408 -0
- package/dist/child.d.ts +40 -0
- package/dist/child.js +127 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.js +136 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/archil.d.ts +68 -0
- package/dist/conformance/archil.js +152 -0
- package/dist/conformance/browserbase.d.ts +35 -0
- package/dist/conformance/browserbase.js +45 -0
- package/dist/conformance/cases/apps.d.ts +2 -0
- package/dist/conformance/cases/apps.js +155 -0
- package/dist/conformance/cases/browser.d.ts +4 -0
- package/dist/conformance/cases/browser.js +105 -0
- package/dist/conformance/cases/drift.d.ts +2 -0
- package/dist/conformance/cases/drift.js +64 -0
- package/dist/conformance/cases/exec.d.ts +2 -0
- package/dist/conformance/cases/exec.js +125 -0
- package/dist/conformance/cases/files.d.ts +2 -0
- package/dist/conformance/cases/files.js +294 -0
- package/dist/conformance/cases/health.d.ts +2 -0
- package/dist/conformance/cases/health.js +71 -0
- package/dist/conformance/cases/index.d.ts +9 -0
- package/dist/conformance/cases/index.js +37 -0
- package/dist/conformance/cases/input.d.ts +12 -0
- package/dist/conformance/cases/input.js +109 -0
- package/dist/conformance/cases/isolation.d.ts +21 -0
- package/dist/conformance/cases/isolation.js +92 -0
- package/dist/conformance/cases/lifetime.d.ts +2 -0
- package/dist/conformance/cases/lifetime.js +64 -0
- package/dist/conformance/cases/mount.d.ts +2 -0
- package/dist/conformance/cases/mount.js +252 -0
- package/dist/conformance/cases/process.d.ts +2 -0
- package/dist/conformance/cases/process.js +240 -0
- package/dist/conformance/cases/provider.d.ts +2 -0
- package/dist/conformance/cases/provider.js +302 -0
- package/dist/conformance/cases/screen.d.ts +9 -0
- package/dist/conformance/cases/screen.js +230 -0
- package/dist/conformance/cases/settings.d.ts +57 -0
- package/dist/conformance/cases/settings.js +142 -0
- package/dist/conformance/cases/touch.d.ts +2 -0
- package/dist/conformance/cases/touch.js +117 -0
- package/dist/conformance/cases/util.d.ts +7 -0
- package/dist/conformance/cases/util.js +8 -0
- package/dist/conformance/cdp.d.ts +13 -0
- package/dist/conformance/cdp.js +88 -0
- package/dist/conformance/cli.d.ts +29 -0
- package/dist/conformance/cli.js +231 -0
- package/dist/conformance/daytona-sweep.d.ts +18 -0
- package/dist/conformance/daytona-sweep.js +118 -0
- package/dist/conformance/daytona.d.ts +83 -0
- package/dist/conformance/daytona.js +107 -0
- package/dist/conformance/docker.d.ts +38 -0
- package/dist/conformance/docker.js +70 -0
- package/dist/conformance/drift-daemon.d.ts +8 -0
- package/dist/conformance/drift-daemon.js +41 -0
- package/dist/conformance/e2b-diagnose.d.ts +16 -0
- package/dist/conformance/e2b-diagnose.js +61 -0
- package/dist/conformance/e2b-sweep.d.ts +18 -0
- package/dist/conformance/e2b-sweep.js +125 -0
- package/dist/conformance/e2b.d.ts +74 -0
- package/dist/conformance/e2b.js +111 -0
- package/dist/conformance/fixture.d.ts +65 -0
- package/dist/conformance/fixture.js +98 -0
- package/dist/conformance/index.d.ts +8 -0
- package/dist/conformance/index.js +8 -0
- package/dist/conformance/kernel.d.ts +31 -0
- package/dist/conformance/kernel.js +40 -0
- package/dist/conformance/kind.d.ts +23 -0
- package/dist/conformance/kind.js +58 -0
- package/dist/conformance/modal-sweep.d.ts +22 -0
- package/dist/conformance/modal-sweep.js +190 -0
- package/dist/conformance/modal.d.ts +69 -0
- package/dist/conformance/modal.js +76 -0
- package/dist/conformance/orgo.d.ts +41 -0
- package/dist/conformance/orgo.js +69 -0
- package/dist/conformance/phone-harness.d.ts +61 -0
- package/dist/conformance/phone-harness.js +241 -0
- package/dist/conformance/png.d.ts +16 -0
- package/dist/conformance/png.js +132 -0
- package/dist/conformance/report.d.ts +2 -0
- package/dist/conformance/report.js +86 -0
- package/dist/conformance/runner.d.ts +11 -0
- package/dist/conformance/runner.js +585 -0
- package/dist/conformance/tar.d.ts +13 -0
- package/dist/conformance/tar.js +105 -0
- package/dist/conformance/types.d.ts +257 -0
- package/dist/conformance/types.js +24 -0
- package/dist/daemon-copy.d.ts +40 -0
- package/dist/daemon-copy.js +259 -0
- package/dist/daytona.d.ts +178 -0
- package/dist/daytona.js +1484 -0
- package/dist/desktop.d.ts +24 -0
- package/dist/desktop.js +68 -0
- package/dist/docker/egress-main.d.ts +1 -0
- package/dist/docker/egress-main.js +68 -0
- package/dist/docker/egress-proxy.d.ts +53 -0
- package/dist/docker/egress-proxy.js +450 -0
- package/dist/docker/egress-table.d.ts +39 -0
- package/dist/docker/egress-table.js +197 -0
- package/dist/docker/egress.d.ts +109 -0
- package/dist/docker/egress.js +318 -0
- package/dist/docker/image.d.ts +49 -0
- package/dist/docker/image.js +302 -0
- package/dist/docker/stage.d.ts +21 -0
- package/dist/docker/stage.js +290 -0
- package/dist/docker/volume.d.ts +24 -0
- package/dist/docker/volume.js +67 -0
- package/dist/docker.d.ts +150 -0
- package/dist/docker.js +1200 -0
- package/dist/drift.d.ts +200 -0
- package/dist/drift.js +416 -0
- package/dist/e2b.d.ts +335 -0
- package/dist/e2b.js +1515 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.js +24 -0
- package/dist/files.d.ts +50 -0
- package/dist/files.js +208 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/isolation.d.ts +29 -0
- package/dist/isolation.js +71 -0
- package/dist/janitor.d.ts +50 -0
- package/dist/janitor.js +135 -0
- package/dist/kernel.d.ts +113 -0
- package/dist/kernel.js +358 -0
- package/dist/kinds.d.ts +79 -0
- package/dist/kinds.js +133 -0
- package/dist/labels.d.ts +23 -0
- package/dist/labels.js +50 -0
- package/dist/modal.d.ts +302 -0
- package/dist/modal.js +1374 -0
- package/dist/mount-archil.d.ts +164 -0
- package/dist/mount-archil.js +471 -0
- package/dist/mount.d.ts +57 -0
- package/dist/mount.js +104 -0
- package/dist/orgo-channel.d.ts +96 -0
- package/dist/orgo-channel.js +391 -0
- package/dist/orgo.d.ts +139 -0
- package/dist/orgo.js +1006 -0
- package/dist/phone-harness.d.ts +185 -0
- package/dist/phone-harness.js +1420 -0
- package/dist/processes.d.ts +24 -0
- package/dist/processes.js +40 -0
- package/dist/protocol.d.ts +729 -0
- package/dist/protocol.js +54 -0
- package/dist/provider.d.ts +245 -0
- package/dist/provider.js +37 -0
- package/dist/providers.d.ts +68 -0
- package/dist/providers.js +25 -0
- package/dist/result.d.ts +15 -0
- package/dist/result.js +2 -0
- package/dist/screen-watch.d.ts +150 -0
- package/dist/screen-watch.js +490 -0
- package/dist/test-connection.d.ts +17 -0
- package/dist/test-connection.js +26 -0
- package/dist/wait.d.ts +23 -0
- package/dist/wait.js +65 -0
- package/package.json +64 -1
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
// The runner: runs each case against a provider, one at a time, and deletes every computer it made.
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
import { sweep } from "../janitor.js";
|
|
6
|
+
import { GROUPS } from "../protocol.js";
|
|
7
|
+
import { fail, ok } from "../result.js";
|
|
8
|
+
import { casesFor } from "./cases/index.js";
|
|
9
|
+
import { dialCdp } from "./cdp.js";
|
|
10
|
+
import { startFixture } from "./fixture.js";
|
|
11
|
+
import { kindCases, kindRunProblem, kindVerdict } from "./kind.js";
|
|
12
|
+
import { coreGroups, } from "./types.js";
|
|
13
|
+
/** The label every computer of a run carries, with the run's id. */
|
|
14
|
+
export const RUN_LABEL = "agentrun.conformance";
|
|
15
|
+
/** The lifetime a run's computers ask for, at most the provider's own cap: a metered phone's cap is its hard stop. */
|
|
16
|
+
const LIFETIME_MS = 30 * 60_000;
|
|
17
|
+
const GROUP_NAMES = new Set(GROUPS);
|
|
18
|
+
const CLOSE_MS = 10_000;
|
|
19
|
+
class Skip extends Error {
|
|
20
|
+
}
|
|
21
|
+
const show = (value) => {
|
|
22
|
+
const text = value === undefined ? "undefined" : JSON.stringify(value);
|
|
23
|
+
return text.length > 300 ? `${text.slice(0, 300)}...` : text;
|
|
24
|
+
};
|
|
25
|
+
const words = (error) => (error instanceof Error ? error.message : String(error)).replace(/\s*\n\s*/g, " ");
|
|
26
|
+
const unwrap = (result, what) => {
|
|
27
|
+
if (result.ok)
|
|
28
|
+
return result.value;
|
|
29
|
+
throw new Error(`${what}: ${result.error.code}: ${result.error.message}`);
|
|
30
|
+
};
|
|
31
|
+
/** Settles with promise, or after ms with undefined: a close that hangs does not hang the run. */
|
|
32
|
+
async function bounded(promise, ms) {
|
|
33
|
+
const stop = new AbortController();
|
|
34
|
+
try {
|
|
35
|
+
return await Promise.race([promise, sleep(ms, undefined, { signal: stop.signal }).catch(() => undefined)]);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
stop.abort();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Settles with promise, or rejects in words when it has not answered within ms, or at once when signal aborts. */
|
|
42
|
+
async function within(promise, ms, what, signal) {
|
|
43
|
+
const stop = new AbortController();
|
|
44
|
+
// The abort's listener goes when this settles, so a later abort rejects nothing left unhandled.
|
|
45
|
+
let off = () => { };
|
|
46
|
+
const aborted = new Promise((_, reject) => {
|
|
47
|
+
if (signal === undefined)
|
|
48
|
+
return;
|
|
49
|
+
const fail = () => reject(signal.reason instanceof Error ? signal.reason : new Error(`${what}: the run was aborted`));
|
|
50
|
+
if (signal.aborted)
|
|
51
|
+
return fail();
|
|
52
|
+
signal.addEventListener("abort", fail, { once: true });
|
|
53
|
+
off = () => signal.removeEventListener("abort", fail);
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
return await Promise.race([
|
|
57
|
+
promise,
|
|
58
|
+
sleep(ms, undefined, { signal: stop.signal }).then(() => {
|
|
59
|
+
throw new Error(`${what} did not answer within ${ms / 1000} s`);
|
|
60
|
+
}),
|
|
61
|
+
aborted,
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
stop.abort();
|
|
66
|
+
off();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Rejects when the signal aborts, with the abort's reason. */
|
|
70
|
+
function whenAborted(signal) {
|
|
71
|
+
return new Promise((_, reject) => {
|
|
72
|
+
const fail = () => reject(signal.reason instanceof Error ? signal.reason : new Error("the run was aborted"));
|
|
73
|
+
if (signal.aborted)
|
|
74
|
+
fail();
|
|
75
|
+
else
|
|
76
|
+
signal.addEventListener("abort", fail, { once: true });
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Runs the cases against the provider and reports each one. Every computer carries the run's label; each one a case
|
|
81
|
+
* makes is deleted when the case ends, the shared one when the run ends, then a janitor provider is swept by the label
|
|
82
|
+
* and the label is listed to show nothing is left. Every provider call is bounded: one that never answers fails its case
|
|
83
|
+
* or is named in the cleanup, and a computer that arrives after its case ended is deleted when it arrives.
|
|
84
|
+
*/
|
|
85
|
+
export async function runConformance(provider, options) {
|
|
86
|
+
// Given no cases, the run takes its computer's suite: a browser's own cases, as the CLI does, else the suite's.
|
|
87
|
+
const { image, only, kind, signal, cases = casesFor(provider.capabilities().kind), drifted, mountFor, onResult, notes, caseTimeoutMs = 180_000, patience = 30_000, cleanupTimeoutMs = 60_000, fixture } = options;
|
|
88
|
+
if (kind !== undefined && only !== undefined)
|
|
89
|
+
throw new TypeError("a run takes kind and only apart: a kind runs its own cases");
|
|
90
|
+
const kindProblem = kind === undefined ? undefined : kindRunProblem(kind);
|
|
91
|
+
if (kindProblem !== undefined)
|
|
92
|
+
throw new TypeError(kindProblem);
|
|
93
|
+
const fetcher = options.fetch ?? ((url, init) => fetch(url, init));
|
|
94
|
+
const dialer = options.cdp ?? dialCdp;
|
|
95
|
+
const clock = options.clock ?? { now: () => Date.now(), sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)) };
|
|
96
|
+
const run = randomBytes(6).toString("hex");
|
|
97
|
+
const runLabels = { [RUN_LABEL]: run };
|
|
98
|
+
const capabilities = provider.capabilities();
|
|
99
|
+
// A provider of the shape before groups declares none, so its kind-consistent case fails in words, not the run.
|
|
100
|
+
const groups = Array.isArray(capabilities.groups) ? capabilities.groups : [];
|
|
101
|
+
/** What this kind of computer must declare: a case missing one fails, where a case missing an optional one skips. */
|
|
102
|
+
const required = new Set(coreGroups(capabilities.kind, capabilities.daemon));
|
|
103
|
+
const selected = kind !== undefined ? kindCases(kind, cases) : only === undefined ? cases : cases.filter((c) => only.includes(c.group) || only.includes(c.id));
|
|
104
|
+
const report = {
|
|
105
|
+
provider: provider.id,
|
|
106
|
+
providerVersion: provider.version,
|
|
107
|
+
kind: capabilities.kind,
|
|
108
|
+
daemonMode: capabilities.daemon,
|
|
109
|
+
image,
|
|
110
|
+
daemon: null,
|
|
111
|
+
...(only === undefined ? {} : { only }),
|
|
112
|
+
...(only === undefined && kind === undefined ? {} : { coreNotRun: cases.filter((c) => c.level === "core" && !selected.includes(c)).map((c) => c.id) }),
|
|
113
|
+
results: [],
|
|
114
|
+
core: "fail",
|
|
115
|
+
undeclared: [],
|
|
116
|
+
cleanup: { deleted: [], left: [], errors: [], late: [] },
|
|
117
|
+
...(notes !== undefined && notes.length > 0 ? { notes: [...notes] } : {}),
|
|
118
|
+
};
|
|
119
|
+
const deleted = new Set();
|
|
120
|
+
/**
|
|
121
|
+
* Provider calls a run stopped waiting for, each with what it is; the cleanup waits for them, bounded, so what they
|
|
122
|
+
* make is deleted, and names each one still pending after that in cleanup.errors.
|
|
123
|
+
*/
|
|
124
|
+
const pending = new Map();
|
|
125
|
+
const keep = (promise, what) => {
|
|
126
|
+
pending.set(promise, what);
|
|
127
|
+
// Both branches handled: a rejection is the caller's to report, never an unhandled one here.
|
|
128
|
+
const done = () => pending.delete(promise);
|
|
129
|
+
void promise.then(done, done);
|
|
130
|
+
};
|
|
131
|
+
// Network none, never wider, wherever the kind requires it: a provider without it fails Core rather than being tested
|
|
132
|
+
// on an open network. A phone, whose kind does not require none, is tested on none when it declares it, else open.
|
|
133
|
+
const network = required.has("network:none") || capabilities.network.includes("none") ? "none" : "open";
|
|
134
|
+
const spec = (extra = {}) => ({
|
|
135
|
+
image,
|
|
136
|
+
lifetimeMs: Number.isSafeInteger(capabilities.maxLifetimeMs) && capabilities.maxLifetimeMs > 0 ? Math.min(LIFETIME_MS, capabilities.maxLifetimeMs) : LIFETIME_MS,
|
|
137
|
+
network,
|
|
138
|
+
...extra,
|
|
139
|
+
labels: { ...extra.labels, ...runLabels },
|
|
140
|
+
});
|
|
141
|
+
const release = async (ref, by = provider) => {
|
|
142
|
+
try {
|
|
143
|
+
const released = await within(by.release(ref, "delete"), cleanupTimeoutMs, `release ${ref.name}`);
|
|
144
|
+
if (released.ok)
|
|
145
|
+
deleted.add(ref.name);
|
|
146
|
+
else
|
|
147
|
+
report.cleanup.errors.push(`release ${ref.name}: ${released.error.code}: ${released.error.message}`);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
report.cleanup.errors.push(words(error).startsWith(`release ${ref.name}`) ? words(error) : `release ${ref.name} threw: ${words(error)}`);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
/** Records the notes a create returned beside its ref, each naming the computer: never dropped with the ref. */
|
|
154
|
+
const noteCreated = (created) => {
|
|
155
|
+
if (!created.ok || !Array.isArray(created.value.notes))
|
|
156
|
+
return;
|
|
157
|
+
for (const note of created.value.notes)
|
|
158
|
+
(report.computerNotes ??= []).push({ computer: created.value.name, note: String(note) });
|
|
159
|
+
};
|
|
160
|
+
/** Deletes the computer a create gives after nobody waits for it any more, and names it in the report. */
|
|
161
|
+
const lateCreate = (creating, what, by = provider) => keep(creating.then(async (created) => {
|
|
162
|
+
noteCreated(created);
|
|
163
|
+
if (!created.ok)
|
|
164
|
+
return;
|
|
165
|
+
report.cleanup.late.push(created.value.name);
|
|
166
|
+
await release(created.value, by);
|
|
167
|
+
}, () => { }), what);
|
|
168
|
+
const createError = (result) => result.ok ? "" : `create ${result.error.code === "refused" ? "was refused" : `failed (${result.error.code})`}: ${result.error.message}`;
|
|
169
|
+
const sawHello = (hello) => {
|
|
170
|
+
report.daemon ??= { version: hello.version, os: hello.os, arch: hello.arch };
|
|
171
|
+
};
|
|
172
|
+
/** The run's shared computer, made the first time a case needs it or the daemon's hello. */
|
|
173
|
+
let shared;
|
|
174
|
+
let sharedRef;
|
|
175
|
+
const getShared = () => (shared ??= (async () => {
|
|
176
|
+
// The run's signal ends the wait at once (Ctrl-C during setup) and reaches the create; a computer that arrives
|
|
177
|
+
// after it is deleted as it lands (lateCreate).
|
|
178
|
+
const stop = new AbortController();
|
|
179
|
+
const creating = provider.create(spec(), { signal: signal ? AbortSignal.any([signal, stop.signal]) : stop.signal });
|
|
180
|
+
let created;
|
|
181
|
+
try {
|
|
182
|
+
created = await within(creating, caseTimeoutMs, "create", signal);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
stop.abort();
|
|
186
|
+
lateCreate(creating, "create (the run's computer)");
|
|
187
|
+
return { error: words(error) };
|
|
188
|
+
}
|
|
189
|
+
noteCreated(created);
|
|
190
|
+
if (!created.ok)
|
|
191
|
+
return { error: createError(created) };
|
|
192
|
+
sharedRef = created.value;
|
|
193
|
+
const connecting = provider.connect(created.value);
|
|
194
|
+
let connected;
|
|
195
|
+
try {
|
|
196
|
+
connected = await within(connecting, caseTimeoutMs, "connect", signal);
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
keep(connecting.then((late) => (late.ok ? bounded(late.value.close(), CLOSE_MS) : undefined), () => { }), `connect to ${created.value.name} (the run's computer)`);
|
|
200
|
+
return { error: words(error) };
|
|
201
|
+
}
|
|
202
|
+
if (!connected.ok)
|
|
203
|
+
return { error: `connect: ${connected.error.code}: ${connected.error.message}` };
|
|
204
|
+
await bounded(connected.value.close(), CLOSE_MS);
|
|
205
|
+
sawHello(connected.value.hello);
|
|
206
|
+
return { ref: created.value, hello: connected.value.hello };
|
|
207
|
+
})().catch((error) => ({ error: `the provider threw: ${words(error)}` })));
|
|
208
|
+
/** Why a case cannot run here, or undefined when everything it needs is declared. */
|
|
209
|
+
const missing = async (needs) => {
|
|
210
|
+
for (const need of needs) {
|
|
211
|
+
// stream is a group (a live view, the provider's) and a provider method: a case that needs it needs stream().
|
|
212
|
+
if (need === "extend" || need === "stream") {
|
|
213
|
+
if (typeof provider[need] !== "function")
|
|
214
|
+
return `the provider has no ${need}()`;
|
|
215
|
+
}
|
|
216
|
+
else if (GROUP_NAMES.has(need)) {
|
|
217
|
+
if (!groups.includes(need))
|
|
218
|
+
return `the provider does not declare ${need}`;
|
|
219
|
+
const got = await getShared();
|
|
220
|
+
if ("hello" in got && !(Array.isArray(got.hello.groups) && got.hello.groups.includes(need))) {
|
|
221
|
+
return `the ${capabilities.daemon === "none" ? "computer's" : "daemon's"} hello does not declare ${need}`;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else if (need.startsWith("mount:")) {
|
|
225
|
+
if (!capabilities.mount?.includes(need.slice("mount:".length)))
|
|
226
|
+
return `the provider does not declare ${need}`;
|
|
227
|
+
}
|
|
228
|
+
else if (need.startsWith("network:")) {
|
|
229
|
+
if (!capabilities.network.includes(need.slice("network:".length)))
|
|
230
|
+
return `the provider does not declare ${need}`;
|
|
231
|
+
}
|
|
232
|
+
else if (need === "lifetime:janitor" && capabilities.lifetime !== "janitor") {
|
|
233
|
+
return `the provider declares lifetime "${capabilities.lifetime}", not ${need}`;
|
|
234
|
+
}
|
|
235
|
+
else if (need.startsWith("user:") && !capabilities.user?.includes(need.slice("user:".length))) {
|
|
236
|
+
return `the provider does not declare ${need}`;
|
|
237
|
+
}
|
|
238
|
+
else if (need === "release:stop" && !(Array.isArray(capabilities.release) && capabilities.release.includes("stop"))) {
|
|
239
|
+
return `the provider does not declare ${need}`;
|
|
240
|
+
}
|
|
241
|
+
else if (need === "vendor-agent" && !Array.isArray(capabilities.vendorAgentPorts)) {
|
|
242
|
+
return `the provider does not declare ${need} (capabilities().vendorAgentPorts): no vendor's agent runs beside its computers' programs`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return undefined;
|
|
246
|
+
};
|
|
247
|
+
const runCase = async (c) => {
|
|
248
|
+
/** What the case saw and records without asserting it, in the order it said it. */
|
|
249
|
+
const observed = [];
|
|
250
|
+
const result = (status, reason) => ({
|
|
251
|
+
id: c.id,
|
|
252
|
+
level: c.level,
|
|
253
|
+
group: c.group,
|
|
254
|
+
status,
|
|
255
|
+
...(reason === undefined ? {} : { reason }),
|
|
256
|
+
...(observed.length > 0 ? { observed: [...observed] } : {}),
|
|
257
|
+
});
|
|
258
|
+
if (signal?.aborted)
|
|
259
|
+
return result("fail", "not run: the run was aborted");
|
|
260
|
+
const why = await missing(c.needs);
|
|
261
|
+
if (why !== undefined) {
|
|
262
|
+
const lacking = [];
|
|
263
|
+
for (const need of c.needs)
|
|
264
|
+
if ((await missing([need])) !== undefined)
|
|
265
|
+
lacking.push(need);
|
|
266
|
+
// A Core case fails when its kind requires what is missing ("a desktop computer must declare screen"); a case
|
|
267
|
+
// whose missing needs are all optional is skipped and named in undeclared.
|
|
268
|
+
const owed = c.level === "core" ? lacking.find((need) => required.has(need)) : undefined;
|
|
269
|
+
if (owed !== undefined) {
|
|
270
|
+
const who = capabilities.daemon === "none" ? `a ${capabilities.kind} computer` : `a ${capabilities.kind} computer with daemon ${capabilities.daemon}`;
|
|
271
|
+
return result("fail", `${who} must declare ${owed}: ${(await missing([owed])) ?? why}`);
|
|
272
|
+
}
|
|
273
|
+
for (const need of lacking)
|
|
274
|
+
if (!report.undeclared.includes(need))
|
|
275
|
+
report.undeclared.push(need);
|
|
276
|
+
return { ...result("skip", why), undeclared: lacking };
|
|
277
|
+
}
|
|
278
|
+
// The shared computer is made, bounded on its own, before the case's time starts.
|
|
279
|
+
const sharedComputer = (c.computer ?? "shared") === "shared" ? await getShared() : undefined;
|
|
280
|
+
const timeoutMs = c.timeoutMs ?? caseTimeoutMs;
|
|
281
|
+
const timer = new AbortController();
|
|
282
|
+
const timeout = setTimeout(() => timer.abort(new Error(`${c.id} did not finish within ${timeoutMs / 1000} s`)), timeoutMs);
|
|
283
|
+
const caseSignal = signal ? AbortSignal.any([signal, timer.signal]) : timer.signal;
|
|
284
|
+
const refs = [];
|
|
285
|
+
const connections = [];
|
|
286
|
+
const sockets = [];
|
|
287
|
+
let started;
|
|
288
|
+
/** The fixture's stop, set as soon as it is launched: one that never logs ready is stopped as well. */
|
|
289
|
+
let stopFixture;
|
|
290
|
+
let dirs = 0;
|
|
291
|
+
/** The run folders the case asked for: each is closed when the case ends, after its computers are deleted. */
|
|
292
|
+
const folders = [];
|
|
293
|
+
// Set when the case ends: what a provider call gives after that is ended at once, not left to the case.
|
|
294
|
+
let ended = false;
|
|
295
|
+
const track = (ref, by = provider) => {
|
|
296
|
+
if (!ended)
|
|
297
|
+
refs.push({ ref, by });
|
|
298
|
+
else {
|
|
299
|
+
report.cleanup.late.push(ref.name);
|
|
300
|
+
keep(release(ref, by), `release ${ref.name}`);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const connect = async (ref) => {
|
|
304
|
+
const connecting = provider.connect(ref).then((connected) => {
|
|
305
|
+
if (!connected.ok)
|
|
306
|
+
return connected;
|
|
307
|
+
let closing;
|
|
308
|
+
const once = { ...connected.value, close: () => (closing ??= connected.value.close()) };
|
|
309
|
+
if (ended)
|
|
310
|
+
keep(bounded(once.close(), CLOSE_MS), `close of a connection to ${ref.name} (${c.id})`);
|
|
311
|
+
else
|
|
312
|
+
connections.push(once);
|
|
313
|
+
return ok(once);
|
|
314
|
+
});
|
|
315
|
+
keep(connecting, `connect to ${ref.name} (${c.id})`);
|
|
316
|
+
const once = unwrap(await connecting, `connect to ${ref.name}`);
|
|
317
|
+
sawHello(once.hello);
|
|
318
|
+
return once;
|
|
319
|
+
};
|
|
320
|
+
/** create through by, kept: what it gives is deleted when the case ends, or as it comes after that. */
|
|
321
|
+
const attempt = (whole, by = provider) => {
|
|
322
|
+
const creating = by.create(whole, { signal: caseSignal }).then((created) => {
|
|
323
|
+
noteCreated(created);
|
|
324
|
+
if (created.ok)
|
|
325
|
+
track(created.value, by);
|
|
326
|
+
return created;
|
|
327
|
+
});
|
|
328
|
+
keep(creating, `create (${c.id})`);
|
|
329
|
+
return creating;
|
|
330
|
+
};
|
|
331
|
+
const create = async (extra) => {
|
|
332
|
+
const created = await attempt(spec(extra));
|
|
333
|
+
if (!created.ok)
|
|
334
|
+
throw new Error(createError(created));
|
|
335
|
+
return created.value;
|
|
336
|
+
};
|
|
337
|
+
const prepareAndRun = async () => {
|
|
338
|
+
let computer;
|
|
339
|
+
if (sharedComputer !== undefined) {
|
|
340
|
+
const got = sharedComputer;
|
|
341
|
+
if ("error" in got)
|
|
342
|
+
throw new Error(`no computer: ${got.error}`);
|
|
343
|
+
computer = { ref: got.ref, connection: await connect(got.ref) };
|
|
344
|
+
}
|
|
345
|
+
else if (c.computer === "fresh") {
|
|
346
|
+
const ref = await create().catch((error) => {
|
|
347
|
+
throw new Error(`no computer: ${words(error)}`);
|
|
348
|
+
});
|
|
349
|
+
computer = { ref, connection: await connect(ref) };
|
|
350
|
+
}
|
|
351
|
+
const needComputer = () => {
|
|
352
|
+
if (computer === undefined)
|
|
353
|
+
throw new Error(`${c.id} asked for a computer, but it runs with none`);
|
|
354
|
+
return computer;
|
|
355
|
+
};
|
|
356
|
+
const t = {
|
|
357
|
+
provider,
|
|
358
|
+
image,
|
|
359
|
+
signal: caseSignal,
|
|
360
|
+
runLabels,
|
|
361
|
+
patience,
|
|
362
|
+
get ref() {
|
|
363
|
+
return needComputer().ref;
|
|
364
|
+
},
|
|
365
|
+
get client() {
|
|
366
|
+
return needComputer().connection.client;
|
|
367
|
+
},
|
|
368
|
+
get hello() {
|
|
369
|
+
return needComputer().connection.hello;
|
|
370
|
+
},
|
|
371
|
+
spec,
|
|
372
|
+
create,
|
|
373
|
+
attempt,
|
|
374
|
+
track,
|
|
375
|
+
connect: (ref) => connect(ref ?? needComputer().ref),
|
|
376
|
+
async home() {
|
|
377
|
+
const env = await t.exec(["env"]);
|
|
378
|
+
const home = /^HOME=(.*)$/m.exec(env.out)?.[1];
|
|
379
|
+
if (home === undefined || !home.startsWith("/"))
|
|
380
|
+
throw new Error(`HOME in the computer is ${show(home)}, not an absolute path`);
|
|
381
|
+
return home.replace(/\/+$/, "") || "/";
|
|
382
|
+
},
|
|
383
|
+
async dir() {
|
|
384
|
+
const path = `${await t.home()}/agentrun-conformance-${run}/${c.id.replace(/[^a-z0-9-]/gi, "-")}-${++dirs}`;
|
|
385
|
+
await t.call("files.mkdir", { path, parents: true });
|
|
386
|
+
return path;
|
|
387
|
+
},
|
|
388
|
+
fixture() {
|
|
389
|
+
if (fixture === undefined) {
|
|
390
|
+
return t.skip("no fixture was given: --fixture names computerd-fixture for a desktop, or the fixture APK for an Android phone");
|
|
391
|
+
}
|
|
392
|
+
started ??= startFixture(t, fixture, (stop) => {
|
|
393
|
+
stopFixture = stop;
|
|
394
|
+
});
|
|
395
|
+
return started;
|
|
396
|
+
},
|
|
397
|
+
fetch: (url, init) => fetcher(url, { ...init, signal: init?.signal ?? caseSignal }),
|
|
398
|
+
async cdp(url) {
|
|
399
|
+
const socket = await dialer(url, { signal: caseSignal });
|
|
400
|
+
if (ended)
|
|
401
|
+
socket.close();
|
|
402
|
+
else
|
|
403
|
+
sockets.push(socket);
|
|
404
|
+
return socket;
|
|
405
|
+
},
|
|
406
|
+
clock,
|
|
407
|
+
async drifted() {
|
|
408
|
+
if (drifted === undefined)
|
|
409
|
+
return t.skip("no drifted provider was given: a provider module exports createDriftedProvider() for the drift cases");
|
|
410
|
+
return await drifted();
|
|
411
|
+
},
|
|
412
|
+
async runFolder(kind) {
|
|
413
|
+
const none = `the run was given no run folder for mount kind ${kind}`;
|
|
414
|
+
if (mountFor === undefined)
|
|
415
|
+
return t.skip(`${none}: a provider's conformance module exports mountFor(kind)`);
|
|
416
|
+
const folder = await mountFor(kind);
|
|
417
|
+
if (folder === undefined)
|
|
418
|
+
return t.skip(`${none}: mountFor(${JSON.stringify(kind)}) made none`);
|
|
419
|
+
if (ended)
|
|
420
|
+
keep(bounded(folder.close().catch(() => { }), CLOSE_MS), `close of a run folder (${c.id})`);
|
|
421
|
+
else
|
|
422
|
+
folders.push(folder);
|
|
423
|
+
return folder;
|
|
424
|
+
},
|
|
425
|
+
async exec(argv, extra = {}, client = t.client) {
|
|
426
|
+
const ran = unwrap(await client.call("exec.run", { argv, timeoutMs: patience, ...extra }, { signal: caseSignal }), `exec.run ${show(argv)}`);
|
|
427
|
+
const decode = (base64) => Buffer.from(base64, "base64").toString("utf8");
|
|
428
|
+
return {
|
|
429
|
+
exitCode: ran.exitCode,
|
|
430
|
+
...(ran.signal === undefined ? {} : { signal: ran.signal }),
|
|
431
|
+
out: decode(ran.stdout),
|
|
432
|
+
err: decode(ran.stderr),
|
|
433
|
+
timedOut: ran.timedOut,
|
|
434
|
+
truncated: ran.truncated,
|
|
435
|
+
};
|
|
436
|
+
},
|
|
437
|
+
async call(method, params, client = t.client) {
|
|
438
|
+
return unwrap(await client.call(method, params, { signal: caseSignal }), method);
|
|
439
|
+
},
|
|
440
|
+
ok: unwrap,
|
|
441
|
+
refused(result, what, codes) {
|
|
442
|
+
if (result.ok)
|
|
443
|
+
throw new Error(`${what}: expected an error${codes ? ` (${codes.join(" or ")})` : ""}, got ok ${show(result.value)}`);
|
|
444
|
+
if (codes && !codes.includes(result.error.code)) {
|
|
445
|
+
throw new Error(`${what}: expected ${codes.join(" or ")}, got ${result.error.code}: ${result.error.message}`);
|
|
446
|
+
}
|
|
447
|
+
return result.error;
|
|
448
|
+
},
|
|
449
|
+
equal(actual, expected, what) {
|
|
450
|
+
if (!Object.is(actual, expected))
|
|
451
|
+
throw new Error(`${what}: expected ${show(expected)}, got ${show(actual)}`);
|
|
452
|
+
},
|
|
453
|
+
deepEqual(actual, expected, what) {
|
|
454
|
+
if (!isDeepStrictEqual(actual, expected))
|
|
455
|
+
throw new Error(`${what}: expected ${show(expected)}, got ${show(actual)}`);
|
|
456
|
+
},
|
|
457
|
+
match(text, pattern, what) {
|
|
458
|
+
if (typeof text !== "string" || !pattern.test(text))
|
|
459
|
+
throw new Error(`${what}: expected to match ${pattern}, got ${show(text)}`);
|
|
460
|
+
},
|
|
461
|
+
assert(condition, what) {
|
|
462
|
+
if (!condition)
|
|
463
|
+
throw new Error(what);
|
|
464
|
+
},
|
|
465
|
+
present(value, what) {
|
|
466
|
+
if (value === undefined || value === null)
|
|
467
|
+
throw new Error(what);
|
|
468
|
+
return value;
|
|
469
|
+
},
|
|
470
|
+
async until(fn, what, ms = patience) {
|
|
471
|
+
const end = Date.now() + ms;
|
|
472
|
+
for (;;) {
|
|
473
|
+
const value = await fn();
|
|
474
|
+
if (value !== undefined && value !== false)
|
|
475
|
+
return value;
|
|
476
|
+
if (Date.now() > end)
|
|
477
|
+
throw new Error(`${what}: still not so after ${ms / 1000} s`);
|
|
478
|
+
if (caseSignal.aborted)
|
|
479
|
+
throw caseSignal.reason;
|
|
480
|
+
await sleep(200);
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
skip(reason) {
|
|
484
|
+
throw new Skip(reason);
|
|
485
|
+
},
|
|
486
|
+
observe(words) {
|
|
487
|
+
observed.push(words);
|
|
488
|
+
},
|
|
489
|
+
};
|
|
490
|
+
await c.run(t);
|
|
491
|
+
};
|
|
492
|
+
try {
|
|
493
|
+
await Promise.race([prepareAndRun(), whenAborted(caseSignal)]);
|
|
494
|
+
return result("pass");
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
if (error instanceof Skip)
|
|
498
|
+
return result("skip", error.message);
|
|
499
|
+
if (signal?.aborted && !timer.signal.aborted)
|
|
500
|
+
return result("fail", "the run was aborted");
|
|
501
|
+
return result("fail", words(error));
|
|
502
|
+
}
|
|
503
|
+
finally {
|
|
504
|
+
ended = true;
|
|
505
|
+
clearTimeout(timeout);
|
|
506
|
+
// The fixture is stopped while the case's connection is still open, whether or not it logged ready; a start still
|
|
507
|
+
// launching is given CLOSE_MS to launch or fail first. A stop that fails is not the case's verdict.
|
|
508
|
+
if (started !== undefined) {
|
|
509
|
+
if (stopFixture === undefined)
|
|
510
|
+
await bounded(started.catch(() => { }), CLOSE_MS);
|
|
511
|
+
if (stopFixture !== undefined)
|
|
512
|
+
await bounded(stopFixture().catch(() => { }), CLOSE_MS);
|
|
513
|
+
}
|
|
514
|
+
for (const socket of sockets)
|
|
515
|
+
socket.close();
|
|
516
|
+
for (const connection of connections)
|
|
517
|
+
await bounded(connection.close().catch(() => { }), CLOSE_MS);
|
|
518
|
+
for (const { ref, by } of refs)
|
|
519
|
+
await release(ref, by);
|
|
520
|
+
// A folder that cannot be removed is left, as a fixture that cannot be stopped is: it is not the case's verdict.
|
|
521
|
+
for (const folder of folders)
|
|
522
|
+
await bounded(folder.close().catch(() => { }), CLOSE_MS);
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
try {
|
|
526
|
+
for (const c of selected) {
|
|
527
|
+
const result = await runCase(c);
|
|
528
|
+
report.results.push(result);
|
|
529
|
+
onResult?.(result);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
finally {
|
|
533
|
+
if (shared !== undefined)
|
|
534
|
+
await shared;
|
|
535
|
+
if (sharedRef !== undefined)
|
|
536
|
+
await release(sharedRef);
|
|
537
|
+
// A kept call may keep another as it settles (a late create, then its release): wait until none is left.
|
|
538
|
+
await bounded((async () => {
|
|
539
|
+
while (pending.size > 0)
|
|
540
|
+
await Promise.allSettled([...pending.keys()]);
|
|
541
|
+
})(), cleanupTimeoutMs);
|
|
542
|
+
// The bound kept: a call still pending may yet make a computer, so the cleanup is incomplete and Core fails.
|
|
543
|
+
for (const what of pending.values()) {
|
|
544
|
+
report.cleanup.errors.push(`${what} did not settle within ${cleanupTimeoutMs / 1000} s of the run's end: what it makes may be left`);
|
|
545
|
+
}
|
|
546
|
+
await cleanup(provider, capabilities.lifetime, runLabels, report, deleted, cleanupTimeoutMs);
|
|
547
|
+
}
|
|
548
|
+
// A Core case skipped for an optional group the computer does not declare is not part of Core's verdict.
|
|
549
|
+
const core = report.results.filter((r) => r.level === "core" && !(r.status === "skip" && r.undeclared !== undefined));
|
|
550
|
+
const clean = report.cleanup.left.length === 0 && report.cleanup.errors.length === 0;
|
|
551
|
+
const corePassed = core.every((r) => r.status === "pass") && clean;
|
|
552
|
+
if ((report.coreNotRun ?? []).length === 0)
|
|
553
|
+
report.core = core.length > 0 && corePassed ? "pass" : "fail";
|
|
554
|
+
else
|
|
555
|
+
report.core = corePassed && report.results.every((r) => r.status !== "fail") ? "partial" : "fail";
|
|
556
|
+
if (kind !== undefined)
|
|
557
|
+
report.kindVerdict = kindVerdict(kind, capabilities, report, selected);
|
|
558
|
+
return report;
|
|
559
|
+
}
|
|
560
|
+
/** Sweeps a janitor provider by the run's label, past every deadline, and lists the label to show nothing is left. */
|
|
561
|
+
async function cleanup(provider, lifetime, labels, report, deleted, ms) {
|
|
562
|
+
try {
|
|
563
|
+
if (lifetime === "janitor") {
|
|
564
|
+
const stop = new AbortController();
|
|
565
|
+
const swept = await within(sweep(provider, { labels, now: new Date(Date.now() + 366 * 24 * 60 * 60_000), signal: stop.signal }), ms, "the sweep").catch((error) => {
|
|
566
|
+
stop.abort();
|
|
567
|
+
return fail("timeout", words(error));
|
|
568
|
+
});
|
|
569
|
+
if (swept.ok)
|
|
570
|
+
for (const name of swept.value.deleted)
|
|
571
|
+
deleted.add(name);
|
|
572
|
+
else
|
|
573
|
+
report.cleanup.errors.push(`sweep: ${swept.error.code}: ${swept.error.message}`);
|
|
574
|
+
}
|
|
575
|
+
const listed = await within(provider.list(labels), ms, `list ${JSON.stringify(labels)}`);
|
|
576
|
+
if (listed.ok)
|
|
577
|
+
report.cleanup.left = listed.value.map((info) => info.ref.name).sort();
|
|
578
|
+
else
|
|
579
|
+
report.cleanup.errors.push(`list ${JSON.stringify(labels)}: ${listed.error.code}: ${listed.error.message}`);
|
|
580
|
+
}
|
|
581
|
+
catch (error) {
|
|
582
|
+
report.cleanup.errors.push(words(error));
|
|
583
|
+
}
|
|
584
|
+
report.cleanup.deleted = [...deleted];
|
|
585
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface TarEntry {
|
|
2
|
+
name: string;
|
|
3
|
+
type: "file" | "dir" | "symlink" | "other";
|
|
4
|
+
mode: number;
|
|
5
|
+
body?: Uint8Array;
|
|
6
|
+
link?: string;
|
|
7
|
+
}
|
|
8
|
+
/** A ustar archive of these entries, names as given (each under 100 bytes). */
|
|
9
|
+
export declare function tarOf(entries: TarEntry[]): Buffer;
|
|
10
|
+
/** Every entry of an archive, in order. Throws in words on an archive it cannot read. */
|
|
11
|
+
export declare function untar(bytes: Uint8Array): TarEntry[];
|
|
12
|
+
/** An entry as one comparable line: its name without "./" or a trailing "/", type, mode, and content hash or target. */
|
|
13
|
+
export declare function describeEntry(entry: TarEntry): string;
|