@parcha/agentrun-computer 0.1.0-beta.32 → 0.1.0-beta.34

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.
Files changed (63) hide show
  1. package/README.md +190 -26
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +6 -3
  4. package/dist/browserbase.d.ts +3 -1
  5. package/dist/browserbase.js +3 -1
  6. package/dist/child.d.ts +2 -0
  7. package/dist/child.js +13 -2
  8. package/dist/chrome.d.ts +73 -0
  9. package/dist/chrome.js +224 -0
  10. package/dist/computerd-linux-amd64 +0 -0
  11. package/dist/computerd-linux-arm64 +0 -0
  12. package/dist/conformance/cases/gpu.d.ts +2 -0
  13. package/dist/conformance/cases/gpu.js +108 -0
  14. package/dist/conformance/cases/health.js +83 -3
  15. package/dist/conformance/cases/index.js +2 -0
  16. package/dist/conformance/cases/isolation.js +6 -0
  17. package/dist/conformance/cases/mount.d.ts +8 -1
  18. package/dist/conformance/cases/mount.js +4 -3
  19. package/dist/conformance/cases/provider.js +14 -0
  20. package/dist/conformance/cli.js +46 -7
  21. package/dist/conformance/daytona-sweep.js +17 -9
  22. package/dist/conformance/e2b-sweep.js +17 -10
  23. package/dist/conformance/local.d.ts +30 -0
  24. package/dist/conformance/local.js +36 -0
  25. package/dist/conformance/modal-sweep.js +32 -9
  26. package/dist/conformance/report.js +10 -5
  27. package/dist/conformance/runner.js +45 -13
  28. package/dist/conformance/types.d.ts +63 -16
  29. package/dist/daytona.d.ts +35 -4
  30. package/dist/daytona.js +113 -27
  31. package/dist/docker.d.ts +9 -1
  32. package/dist/docker.js +92 -7
  33. package/dist/drift.d.ts +3 -1
  34. package/dist/drift.js +9 -0
  35. package/dist/e2b.d.ts +6 -2
  36. package/dist/e2b.js +10 -6
  37. package/dist/index.d.ts +4 -2
  38. package/dist/index.js +4 -2
  39. package/dist/isolation.d.ts +0 -2
  40. package/dist/isolation.js +0 -16
  41. package/dist/kernel.d.ts +3 -1
  42. package/dist/kernel.js +3 -1
  43. package/dist/kinds.d.ts +10 -4
  44. package/dist/kinds.js +26 -6
  45. package/dist/labels.d.ts +6 -0
  46. package/dist/labels.js +26 -1
  47. package/dist/local-supervisor.d.ts +51 -0
  48. package/dist/local-supervisor.js +221 -0
  49. package/dist/local.d.ts +89 -0
  50. package/dist/local.js +472 -0
  51. package/dist/modal.d.ts +31 -4
  52. package/dist/modal.js +90 -30
  53. package/dist/orgo.d.ts +3 -1
  54. package/dist/orgo.js +14 -27
  55. package/dist/phone-harness.d.ts +3 -1
  56. package/dist/phone-harness.js +7 -4
  57. package/dist/protocol.d.ts +20 -0
  58. package/dist/protocol.js +9 -0
  59. package/dist/provider.d.ts +63 -3
  60. package/dist/provider.js +28 -0
  61. package/dist/providers.d.ts +7 -1
  62. package/dist/providers.js +1 -0
  63. package/package.json +1 -1
@@ -3,6 +3,7 @@
3
3
  // Exits 0 when Core passes, 1 when it fails, 2 on a usage error, and 3 when --only left Core cases out and every case
4
4
  // that ran passed: a partial run is never a Core pass, so no script reads its exit code as one. With --kind it exits on
5
5
  // the kind's verdict alone: 0 when the provider passes the kind, 1 when it does not.
6
+ import { randomBytes } from "node:crypto";
6
7
  import { resolve } from "node:path";
7
8
  import { pathToFileURL } from "node:url";
8
9
  import { isCommand } from "../entry.js";
@@ -14,24 +15,33 @@ import { formatReport } from "./report.js";
14
15
  import { runConformance } from "./runner.js";
15
16
  /** Writes text and settles once the stream has taken it, so an exit after it cuts nothing off. */
16
17
  const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
17
- const USAGE = `usage: npm run conformance -w @parcha/agentrun-computer -- --provider ${providerIds.join("|")}|<module.js> [--image <image>] [--only <group|case>,... | --kind <kind>] [--fixture <path>] [--json]
18
+ const USAGE = `usage: npm run conformance -w @parcha/agentrun-computer -- --provider ${providerIds.join("|")}|<module.js> [--image <image>] [--only <group|case>,... | --kind <kind>] [--fixture <path>] [--gpu <type>[:<count>]] [--json]
18
19
  --provider a computer in the registry (${providerIds.join(", ")}), or a module path: a provider file that exports
19
20
  create(options), or a conformance module that exports createProvider() (and, for the drift case,
20
21
  createDriftedProvider(); for the mount cases, mountFor(kind), a fresh run folder for that mount kind)
21
22
  --image the image every computer starts from (default the module's conformanceImage(), else debian:bookworm-slim)
22
23
  --only run only these groups (health, exec, files, process, provider, drift, mount, screen, input, touch,
23
- apps, lifetime; browser, run alone for a provider of kind browser) or case ids; a run that leaves Core cases out is partial: no Core verdict, and exit 3 when
24
+ apps, lifetime, gpu; browser, run alone for a provider of kind browser) or case ids; a run that leaves Core cases out is partial: no Core verdict, and exit 3 when
24
25
  every case that ran passed
25
26
  --kind run a setting kind's cases (sandbox, desktop, phone, browser) and exit on its verdict: the provider passes the kind only
26
27
  when it serves it and every case of each required group passes; not with --only
27
28
  --fixture the fixture the screen, input, touch and apps cases check effects with: computerd-fixture for a
28
29
  desktop, the fixture APK for an Android phone
30
+ --gpu the GPU the gpu case's one computer asks for, a type the provider declares and a count (default 1), such
31
+ as T4 or H100:2; it bills by the second, so without it the gpu case skips
29
32
  --json print the report as JSON
30
33
  exit: 0 Core passes, 1 it fails, 2 usage error, 3 partial (--only) and every case that ran passed; with --kind,
31
34
  0 the provider passes the kind, 1 it does not`;
32
35
  const PROVIDER_METHODS = ["capabilities", "check", "create", "attach", "list", "network", "connect", "release"];
33
36
  class Usage extends Error {
34
37
  }
38
+ /** --gpu's value: a type, then :count (default 1), such as T4 or H100:2; whether the provider offers it is check()'s. */
39
+ function gpuOf(text) {
40
+ const match = /^([^:\s]+)(?::([1-9][0-9]*))?$/.exec(text);
41
+ if (match === null)
42
+ throw new Usage(`--gpu: ${JSON.stringify(text)} is not <type>[:<count>], such as T4 or H100:2`);
43
+ return { type: match[1], count: match[2] === undefined ? 1 : Number(match[2]) };
44
+ }
35
45
  function parse(argv, cases) {
36
46
  const args = { json: false, help: false };
37
47
  for (let i = 0; i < argv.length; i++) {
@@ -59,6 +69,8 @@ function parse(argv, cases) {
59
69
  }
60
70
  else if (flag === "--fixture")
61
71
  args.fixture = value();
72
+ else if (flag === "--gpu")
73
+ args.gpu = gpuOf(value());
62
74
  else if (flag === "--json")
63
75
  args.json = true;
64
76
  else if (flag === "--help" || flag === "-h")
@@ -84,6 +96,7 @@ function parse(argv, cases) {
84
96
  ...(args.only ? { only: args.only } : {}),
85
97
  ...(args.kind ? { kind: args.kind } : {}),
86
98
  ...(args.fixture ? { fixture: args.fixture } : {}),
99
+ ...(args.gpu ? { gpu: args.gpu } : {}),
87
100
  json: args.json,
88
101
  help: false,
89
102
  };
@@ -98,6 +111,13 @@ const BARE = /^[A-Za-z][A-Za-z0-9-]*$/;
98
111
  * reads no environment), with no drifted twin.
99
112
  */
100
113
  async function conformanceModule(name, cwd) {
114
+ const found = await moduleFor(name, cwd);
115
+ // What the provider file declares of itself (its CAPABILITIES; its descriptor once that lands), kept across the switch
116
+ // to its conformance module, for health.declared.
117
+ const declared = found.file.CAPABILITIES;
118
+ return { label: found.label, module: found.module, ...(Array.isArray(declared) ? { declared: declared } : {}) };
119
+ }
120
+ async function moduleFor(name, cwd) {
101
121
  let label = name;
102
122
  let module;
103
123
  if (isProviderId(name)) {
@@ -116,7 +136,7 @@ async function conformanceModule(name, cwd) {
116
136
  }
117
137
  }
118
138
  if (typeof module.conformance === "function")
119
- return { label, module: await module.conformance() };
139
+ return { label, module: await module.conformance(), file: module };
120
140
  if (typeof module.createProvider !== "function" && typeof module.create === "function") {
121
141
  const create = module.create;
122
142
  return {
@@ -127,15 +147,18 @@ async function conformanceModule(name, cwd) {
127
147
  return create(rest);
128
148
  },
129
149
  },
150
+ file: module,
130
151
  };
131
152
  }
132
- return { label, module: module };
153
+ return { label, module: module, file: module };
133
154
  }
155
+ /** A name of a module's ENV that holds a secret: an API key, a token, a token's secret. */
156
+ const SECRET_NAME = /(^|_)(KEY|TOKEN|SECRET)(_|$)/;
134
157
  /**
135
158
  * The provider a conformance module makes, its drifted twin and its run folders (mountFor) when it offers them, and what
136
159
  * it says of its run: conformanceImage(), the image when --image names none, and conformanceNotes, strings for the report.
137
160
  */
138
- async function load(label, module, options) {
161
+ async function load(label, module, options, declared) {
139
162
  const { createProvider, createDriftedProvider, conformanceImage, mountFor } = module;
140
163
  if (typeof createProvider !== "function")
141
164
  throw new Usage(`${label} does not export createProvider() or create()`);
@@ -147,6 +170,19 @@ async function load(label, module, options) {
147
170
  const target = { provider };
148
171
  if (typeof createDriftedProvider === "function")
149
172
  target.drifted = async () => (await createDriftedProvider(options));
173
+ // The provider file's own declaration; without it, the runner takes the kind registry's entry for the provider's id.
174
+ if (declared !== undefined)
175
+ target.declared = declared;
176
+ // The same provider built with a planted value in each name of its ENV that holds a secret: a fresh one each time.
177
+ const secretNames = Object.values(module.ENV ?? {}).filter((name) => typeof name === "string" && SECRET_NAME.test(name));
178
+ if (secretNames.length > 0) {
179
+ target.planted = async () => {
180
+ const secrets = secretNames.map(() => `agentrun-planted-${randomBytes(12).toString("hex")}`);
181
+ const given = options.env ?? process.env;
182
+ const env = { ...given, ...Object.fromEntries(secretNames.map((name, i) => [name, secrets[i]])) };
183
+ return { provider: (await createProvider({ ...options, env })), secrets };
184
+ };
185
+ }
150
186
  if (typeof mountFor === "function")
151
187
  target.mountFor = (kind) => mountFor(kind, options);
152
188
  if (conformanceImage !== undefined) {
@@ -184,8 +220,8 @@ export async function main(argv, io = {}) {
184
220
  const options = { ...(io.providerOptions ?? {}), onNote: (note) => providerNotes.push({ computer: note.computer, note: note.note }) };
185
221
  let target;
186
222
  try {
187
- const { label, module } = await conformanceModule(args.provider, cwd);
188
- target = await load(label, module, options);
223
+ const { label, module, declared } = await conformanceModule(args.provider, cwd);
224
+ target = await load(label, module, options, declared);
189
225
  }
190
226
  catch (error) {
191
227
  await write(stderr, `${error.message}\n`);
@@ -204,8 +240,11 @@ export async function main(argv, io = {}) {
204
240
  ...(args.only ? { only: args.only } : {}),
205
241
  ...(args.kind ? { kind: args.kind } : {}),
206
242
  ...(args.fixture ? { fixture: resolve(cwd, args.fixture) } : {}),
243
+ ...(args.gpu ? { gpu: args.gpu } : {}),
207
244
  ...(signal ? { signal } : {}),
208
245
  ...(target.drifted ? { drifted: target.drifted } : {}),
246
+ ...(target.declared ? { declared: target.declared } : {}),
247
+ ...(target.planted ? { planted: target.planted } : {}),
209
248
  ...(target.mountFor ? { mountFor: target.mountFor } : {}),
210
249
  ...(onResult ? { onResult } : {}),
211
250
  ...(io.cdp ? { cdp: io.cdp } : {}),
@@ -4,20 +4,25 @@
4
4
  // node packages/computer/dist/conformance/daytona-sweep.js --after <file>
5
5
  //
6
6
  // --before records the id of every sandbox carrying agentrun.computer=1 into <file>. --after lists them again, deletes
7
- // (release delete) every one whose id is not in <file>, then reads each of those back with GET /sandbox/{id} until
8
- // Daytona answers 404, up to 60 s each, and prints one JSON line, {"swept":n,"notFound":m,"stillThere":[ids]}: swept is
9
- // every sandbox it found that was not there before, and notFound + stillThere.length = swept. A sandbox in <file> is
10
- // never touched: no call names it. Exit 0 when every swept sandbox reads back 404, 1 when one is still there, 2 on a
11
- // usage error, a before file it cannot read, a missing key or a listing Daytona refused (nothing is deleted then).
7
+ // (release delete) every one whose id is not in <file> and that carries a conformance run's label (agentrun.conformance,
8
+ // RUN_LABEL), then reads each of those back with GET /sandbox/{id} until Daytona answers 404, up to 60 s each, and
9
+ // prints one JSON line, {"swept":n,"notFound":m,"stillThere":[ids],"leftAlone":k}: swept is every conformance sandbox
10
+ // it found that was not there before, notFound + stillThere.length = swept, and leftAlone counts the new labelled
11
+ // sandboxes with no conformance label, which another user of the account made during the run (a server's computers):
12
+ // never touched. A sandbox in <file> is never touched either: no call names it. Exit 0 when every swept sandbox reads
13
+ // back 404, 1 when one is still there, 2 on a usage error, a before file it cannot read, a missing key or a listing
14
+ // Daytona refused (nothing is deleted then).
12
15
  import { readFileSync, writeFileSync } from "node:fs";
13
16
  import { COMPUTER_LABEL } from "../drift.js";
14
17
  import { isCommand } from "../entry.js";
15
18
  import { waitUntil } from "../wait.js";
16
19
  import { createProvider } from "./daytona.js";
20
+ import { RUN_LABEL } from "./runner.js";
17
21
  const USAGE = `usage: node packages/computer/dist/conformance/daytona-sweep.js --before <file> | --after <file>
18
22
  --before <file> record the id of every sandbox carrying ${COMPUTER_LABEL}=1 into <file>
19
- --after <file> delete every sandbox carrying ${COMPUTER_LABEL}=1 whose id is not in <file>, read each back until
20
- Daytona answers 404 (up to 60 s each), and print {"swept":n,"notFound":m,"stillThere":[ids]}
23
+ --after <file> delete every sandbox carrying ${COMPUTER_LABEL}=1 and ${RUN_LABEL} whose id is not in <file>, read
24
+ each back until Daytona answers 404 (up to 60 s each), and print
25
+ {"swept":n,"notFound":m,"stillThere":[ids],"leftAlone":k}; a new one with no ${RUN_LABEL} is left alone
21
26
  settings: COMPUTER_DAYTONA_API_KEY (required) and COMPUTER_DAYTONA_API_URL, as the conformance module reads them
22
27
  exit: 0 every swept sandbox is gone, 1 one is still there, 2 usage error, unreadable before file, no key, or a refused listing`;
23
28
  class Usage extends Error {
@@ -89,7 +94,10 @@ export async function main(argv, io = {}) {
89
94
  return 0;
90
95
  }
91
96
  const known = before;
92
- const fresh = [...new Map(listed.value.filter((sb) => !known.has(sb.id)).map((sb) => [sb.id, sb])).values()];
97
+ const added = [...new Map(listed.value.filter((sb) => !known.has(sb.id)).map((sb) => [sb.id, sb])).values()];
98
+ // Only a conformance run's computers: one another user of the account made during the run is not this sweep's.
99
+ const fresh = added.filter((sb) => Object.hasOwn(sb.labels, RUN_LABEL));
100
+ const leftAlone = added.length - fresh.length;
93
101
  for (const sb of fresh) {
94
102
  const released = await provider.release({ id: sb.id, name: sb.name ?? "" }, "delete");
95
103
  if (!released.ok)
@@ -110,7 +118,7 @@ export async function main(argv, io = {}) {
110
118
  return waited.ok;
111
119
  }));
112
120
  const stillThere = fresh.filter((_, i) => !gone[i]).map((sb) => sb.id);
113
- await write(stdout, `${JSON.stringify({ swept: fresh.length, notFound: fresh.length - stillThere.length, stillThere })}\n`);
121
+ await write(stdout, `${JSON.stringify({ swept: fresh.length, notFound: fresh.length - stillThere.length, stillThere, leftAlone })}\n`);
114
122
  return stillThere.length === 0 ? 0 : 1;
115
123
  }
116
124
  if (isCommand(import.meta)) {
@@ -5,12 +5,14 @@
5
5
  //
6
6
  // --before records into <file> the id of every sandbox E2B lists with the provider's label agentrun.computer=1
7
7
  // (Sandbox.list with that metadata, running and paused ones: e2b@2.63.0 dist/index.mjs:5974-5986, 5793-5835). --after
8
- // lists them again, kills (Sandbox.kill) every one whose id is not in <file>, then reads each of those back with getInfo
9
- // until E2B no longer has it (SandboxNotFoundError, index.mjs:5431) and no longer lists it, up to 60 s each, and prints
10
- // one JSON line, {"swept":n,"gone":m,"stillThere":[ids]}: swept is every labelled sandbox it found that was not there
11
- // before, and gone + stillThere.length = swept. A sandbox in <file> is never touched: no call names it. Exit 0 when
12
- // every swept sandbox is gone, 1 when one is still there, 2 on a usage error, a before file it cannot read, a missing
13
- // key, or a listing E2B refused (nothing is killed then).
8
+ // lists them again, kills (Sandbox.kill) every one whose id is not in <file> and whose metadata carries a conformance
9
+ // run's label (agentrun.conformance, RUN_LABEL), then reads each of those back with getInfo until E2B no longer has it
10
+ // (SandboxNotFoundError, index.mjs:5431) and no longer lists it, up to 60 s each, and prints one JSON line,
11
+ // {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every conformance sandbox it found that was not there
12
+ // before, gone + stillThere.length = swept, and leftAlone counts the new labelled sandboxes with no conformance label,
13
+ // which another user of the account made during the run: never touched. A sandbox in <file> is never touched either:
14
+ // no call names it. Exit 0 when every swept sandbox is gone, 1 when one is still there, 2 on a usage error, a before
15
+ // file it cannot read, a missing key, or a listing E2B refused (nothing is killed then).
14
16
  //
15
17
  // It reads COMPUTER_E2B_API_KEY and COMPUTER_E2B_DOMAIN as the conformance module does (settingsFromEnv in ./e2b.ts)
16
18
  // and builds the provider with create(): the key passed to every SDK call explicitly, an ambient E2B_SANDBOX_URL
@@ -20,11 +22,13 @@ import { COMPUTER_LABEL } from "../drift.js";
20
22
  import { create } from "../e2b.js";
21
23
  import { isCommand } from "../entry.js";
22
24
  import { E2B_ENV as ENV, settingsFromEnv } from "./e2b.js";
25
+ import { RUN_LABEL } from "./runner.js";
23
26
  import { waitUntil } from "../wait.js";
24
27
  const USAGE = `usage: node packages/computer/dist/conformance/e2b-sweep.js --before <file> | --after <file>
25
28
  --before <file> record the id of every sandbox E2B lists with ${COMPUTER_LABEL}=1 into <file>
26
- --after <file> kill every sandbox listed with ${COMPUTER_LABEL}=1 whose id is not in <file>, read each back until
27
- E2B no longer has it (up to 60 s each), and print {"swept":n,"gone":m,"stillThere":[ids]}
29
+ --after <file> kill every sandbox listed with ${COMPUTER_LABEL}=1 and ${RUN_LABEL} whose id is not in <file>, read
30
+ each back until E2B no longer has it (up to 60 s each), and print
31
+ {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; a new one with no ${RUN_LABEL} is left alone
28
32
  settings: ${ENV.key} (required) and ${ENV.domain}, as the conformance module reads them; never E2B_API_KEY
29
33
  exit: 0 every swept sandbox is gone, 1 one is still there, 2 usage error, unreadable before file, no key, or a refused listing`;
30
34
  class Usage extends Error {
@@ -95,7 +99,10 @@ export async function main(argv, io = {}) {
95
99
  return 0;
96
100
  }
97
101
  const known = before;
98
- const fresh = listed.value.filter((sb) => !known.has(sb.id)).map((sb) => sb.id);
102
+ const added = listed.value.filter((sb) => !known.has(sb.id));
103
+ // Only a conformance run's computers: one another user of the account made during the run is not this sweep's.
104
+ const fresh = added.filter((sb) => Object.hasOwn(sb.labels, RUN_LABEL)).map((sb) => sb.id);
105
+ const leftAlone = added.length - fresh.length;
99
106
  for (const id of fresh) {
100
107
  const killed = await provider.killById(id);
101
108
  if (!killed.ok)
@@ -117,7 +124,7 @@ export async function main(argv, io = {}) {
117
124
  return waited.ok;
118
125
  }));
119
126
  const stillThere = fresh.filter((_, i) => !gone[i]);
120
- await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere })}\n`);
127
+ await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone })}\n`);
121
128
  return stillThere.length === 0 ? 0 : 1;
122
129
  }
123
130
  if (isCommand(import.meta)) {
@@ -0,0 +1,30 @@
1
+ import { type LocalBrowserOptions, type LocalBrowserProvider } from "../local.js";
2
+ /** The environment this module reads, by name, each for the option its comment names, and the live switch. */
3
+ export declare const LOCAL_ENV: {
4
+ readonly live: "AGENTRUN_COMPUTER_LIVE_LOCAL";
5
+ /** executablePath: the Chrome or Chromium to run; default the first on PATH, then the usual install places. */
6
+ readonly chrome: "COMPUTER_LOCAL_CHROME";
7
+ /** headed: "1" shows the window. */
8
+ readonly headed: "COMPUTER_LOCAL_HEADED";
9
+ };
10
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
11
+ export declare const ENV: {
12
+ readonly live: "AGENTRUN_COMPUTER_LIVE_LOCAL";
13
+ /** executablePath: the Chrome or Chromium to run; default the first on PATH, then the usual install places. */
14
+ readonly chrome: "COMPUTER_LOCAL_CHROME";
15
+ /** headed: "1" shows the window. */
16
+ readonly headed: "COMPUTER_LOCAL_HEADED";
17
+ };
18
+ export type LocalSettings = Pick<LocalBrowserOptions, "executablePath" | "headed" | "env">;
19
+ /** The provider's options this module reads from env, each only when its name is set; PATH goes in as the provider's env, to find a Chrome on it. */
20
+ export declare function settingsFromEnv(env?: Record<string, string | undefined>): LocalSettings;
21
+ /** For the run's report: what this configuration means for the suite. */
22
+ export declare const conformanceNotes: string[];
23
+ export interface LocalModuleOptions {
24
+ /** Where the settings are read; default process.env. */
25
+ env?: Record<string, string | undefined>;
26
+ }
27
+ /** The image every computer of the run asks for: this machine's Chrome. */
28
+ export declare function conformanceImage(): string;
29
+ /** The provider the CLI runs; throws in words without the live switch. */
30
+ export declare function createProvider({ env }?: LocalModuleOptions): Promise<LocalBrowserProvider>;
@@ -0,0 +1,36 @@
1
+ // The local browser for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider local`. It
2
+ // starts a real Chrome on this machine (nothing billed, no key), so it runs only with AGENTRUN_COMPUTER_LIVE_LOCAL=1. The
3
+ // provider reads no environment: this module reads its own COMPUTER_LOCAL_* names, and PATH to find a Chrome, and passes
4
+ // each to create() as its option.
5
+ import { BROWSER_IMAGE } from "../browser.js";
6
+ import { create } from "../local.js";
7
+ /** The environment this module reads, by name, each for the option its comment names, and the live switch. */
8
+ export const LOCAL_ENV = {
9
+ live: "AGENTRUN_COMPUTER_LIVE_LOCAL",
10
+ /** executablePath: the Chrome or Chromium to run; default the first on PATH, then the usual install places. */
11
+ chrome: "COMPUTER_LOCAL_CHROME",
12
+ /** headed: "1" shows the window. */
13
+ headed: "COMPUTER_LOCAL_HEADED",
14
+ };
15
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
16
+ export const ENV = LOCAL_ENV;
17
+ /** The provider's options this module reads from env, each only when its name is set; PATH goes in as the provider's env, to find a Chrome on it. */
18
+ export function settingsFromEnv(env = process.env) {
19
+ const executablePath = env[LOCAL_ENV.chrome] || undefined;
20
+ const headed = env[LOCAL_ENV.headed] === "1";
21
+ return { ...(executablePath === undefined ? {} : { executablePath }), ...(headed ? { headed } : {}), env: { PATH: env.PATH } };
22
+ }
23
+ /** For the run's report: what this configuration means for the suite. */
24
+ export const conformanceNotes = [
25
+ "local: this machine's Chrome, one browser for the whole run, deleted by its last case and again at the run's end. Its supervisor ends it at its deadline, which list reads.",
26
+ ];
27
+ /** The image every computer of the run asks for: this machine's Chrome. */
28
+ export function conformanceImage() {
29
+ return BROWSER_IMAGE;
30
+ }
31
+ /** The provider the CLI runs; throws in words without the live switch. */
32
+ export async function createProvider({ env = process.env } = {}) {
33
+ if (env[LOCAL_ENV.live] !== "1")
34
+ throw new Error(`the local conformance module starts a real Chrome on this machine: set ${LOCAL_ENV.live}=1 to run it`);
35
+ return create(settingsFromEnv(env));
36
+ }
@@ -8,11 +8,15 @@
8
8
  // agentrun.computer=1: sandboxes.list({ appId, tags }) returns those with at least those tags, and running ones only
9
9
  // (modal-client@64880502:js/src/sandbox.ts:1116-1159, includeFinished: false), so a finished sandbox is in neither list
10
10
  // and needs no sweep. --after refuses a file whose app or server is not the one the environment names now, or that
11
- // names none, before it lists anything: another app's computers would all read as new. Otherwise it lists them again, terminates every one whose id is not in <file>, then reads each of those
12
- // back with sandboxes.fromId and poll (sandbox.ts:960-962, 2766-2772; poll is null while it runs) until it reports an
13
- // exit code, or Modal no longer knows it, up to 60 s each, and prints one JSON line, {"swept":n,"gone":m,"stillThere":
14
- // [ids]}: swept is every tagged sandbox it found that was not there before, and gone + stillThere.length = swept. A
15
- // sandbox in <file> is never touched: no call names it. Exit 0 when every swept sandbox has finished, 1 when one still
11
+ // names none, before it lists anything: another app's computers would all read as new. Otherwise it lists them again,
12
+ // reads the tags of every one whose id is not in <file> (getTags: a list filters by exact tag values, and a run's label
13
+ // differs per run), terminates each that carries a conformance run's label (agentrun.conformance, RUN_LABEL), then
14
+ // reads each of those back with sandboxes.fromId and poll (sandbox.ts:960-962, 2766-2772; poll is null while it runs)
15
+ // until it reports an exit code, or Modal no longer knows it, up to 60 s each, and prints one JSON line,
16
+ // {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every conformance sandbox it found that was not there
17
+ // before, gone + stillThere.length = swept, and leftAlone counts the new tagged sandboxes it did not terminate: no
18
+ // conformance label (another user of the app made them during the run), or tags it could not read (said on stderr).
19
+ // A sandbox in <file> is never touched: no call names it. Exit 0 when every swept sandbox has finished, 1 when one still
16
20
  // runs, 2 on a usage error, a before file it cannot read or of another app or server, a missing token or app, or a
17
21
  // listing Modal refused (nothing is terminated then).
18
22
  //
@@ -25,12 +29,14 @@ import { COMPUTER_LABEL } from "../drift.js";
25
29
  import { isCommand } from "../entry.js";
26
30
  import { MODAL_DEFAULT_SERVER_URL, modalClient, untilFinished } from "../modal.js";
27
31
  import { MODAL_ENV, settingsFromEnv } from "./modal.js";
32
+ import { RUN_LABEL } from "./runner.js";
28
33
  const TAG = { [COMPUTER_LABEL]: "1" };
29
34
  const USAGE = `usage: node packages/computer/dist/conformance/modal-sweep.js --before <file> | --after <file>
30
35
  --before <file> record the app, the server and the id of every running sandbox carrying ${COMPUTER_LABEL}=1 in the app into <file>
31
36
  --after <file> refuse a <file> of another app or server; else terminate every running sandbox carrying ${COMPUTER_LABEL}=1
32
- in the app whose id is not in <file>,
33
- read each back until it has finished (up to 60 s each), and print {"swept":n,"gone":m,"stillThere":[ids]}
37
+ and ${RUN_LABEL} in the app whose id is not in <file>, read each back until it has finished (up to 60 s
38
+ each), and print {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; a new one with no
39
+ ${RUN_LABEL} (or tags it cannot read) is left alone
34
40
  settings: ${MODAL_ENV.tokenId} and ${MODAL_ENV.tokenSecret} (required), ${MODAL_ENV.app} (required) and
35
41
  ${MODAL_ENV.serverUrl}, as the conformance module reads them; never MODAL_TOKEN_ID or MODAL_TOKEN_SECRET
36
42
  exit: 0 every swept sandbox has finished, 1 one still runs, 2 usage error, unreadable before file or one of another app
@@ -167,7 +173,24 @@ export async function main(argv, io = {}) {
167
173
  return 0;
168
174
  }
169
175
  const known = before;
170
- const fresh = listed.value.filter((sandbox) => !known.has(sandbox.sandboxId));
176
+ const added = listed.value.filter((sandbox) => !known.has(sandbox.sandboxId));
177
+ // Only a conformance run's computers: one another user of the app made during the run is not this sweep's. Tags it
178
+ // cannot read leave the sandbox alone, said in words; one Modal no longer knows has finished already.
179
+ const fresh = [];
180
+ let leftAlone = 0;
181
+ for (const sandbox of added) {
182
+ const tags = await bounded(`getTags of ${sandbox.sandboxId}`, () => sandbox.getTags(), callMs);
183
+ if (!tags.ok) {
184
+ if (notFound(tags.error))
185
+ continue;
186
+ await write(stderr, `${sandbox.sandboxId} was left alone: its tags could not be read: ${words(tags.error)}\n`);
187
+ leftAlone += 1;
188
+ }
189
+ else if (Object.hasOwn(tags.value, RUN_LABEL))
190
+ fresh.push(sandbox);
191
+ else
192
+ leftAlone += 1;
193
+ }
171
194
  for (const sandbox of fresh) {
172
195
  const ended = await bounded(`terminate of ${sandbox.sandboxId}`, () => sandbox.terminate(), callMs);
173
196
  if (!ended.ok && !notFound(ended.error))
@@ -182,7 +205,7 @@ export async function main(argv, io = {}) {
182
205
  return waited.ok;
183
206
  }));
184
207
  const stillThere = fresh.filter((_, i) => !gone[i]).map((sandbox) => sandbox.sandboxId);
185
- await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere })}\n`);
208
+ await write(stdout, `${JSON.stringify({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone })}\n`);
186
209
  return stillThere.length === 0 ? 0 : 1;
187
210
  }
188
211
  if (isCommand(import.meta)) {
@@ -1,4 +1,4 @@
1
- const GROUPS = ["health", "exec", "files", "process", "provider", "drift", "isolation", "mount", "screen", "input", "touch", "apps", "lifetime", "browser"];
1
+ const GROUPS = ["health", "exec", "files", "process", "provider", "drift", "isolation", "mount", "screen", "input", "touch", "apps", "lifetime", "browser", "gpu"];
2
2
  const NAMES_WIDTH = 44;
3
3
  const INDENT = " ".repeat("core ".length + "provider ".length + 1);
4
4
  /** The case names, wrapped to the column's width: the first line, then the rest. */
@@ -14,9 +14,11 @@ function wrap(names) {
14
14
  return lines;
15
15
  }
16
16
  export function formatReport(report) {
17
- const { daemon, results, cleanup } = report;
17
+ const { daemons, results, cleanup } = report;
18
18
  const answers = report.daemonMode === "none" ? "the provider" : "computerd";
19
- const reached = daemon ? `${answers} ${daemon.version} ${daemon.os}/${daemon.arch}` : report.daemonMode === "none" ? "no computer reached" : "no daemon reached";
19
+ const said = (daemon) => `${answers} ${daemon.version} ${daemon.os}/${daemon.arch}`;
20
+ const [first] = daemons;
21
+ const reached = first ? said(first) : report.daemonMode === "none" ? "no computer reached" : "no daemon reached";
20
22
  const lines = [`computer conformance · ${report.provider} · ${report.kind}, daemon ${report.daemonMode} · ${reached}`];
21
23
  // A Core case skipped for an optional group the computer does not declare is not Core for this kind of computer (a
22
24
  // linux computer is never held to screen): it is listed as optional, out of Core's lines and count.
@@ -54,10 +56,13 @@ export function formatReport(report) {
54
56
  const [first = "", ...rest] = wrap(notRun);
55
57
  lines.push(`core ${"not run".padEnd(9)} ${first}`, ...rest.map((more) => `${INDENT}${more}`));
56
58
  }
59
+ // Each computer's daemon, named with its role: computers of one run may answer differently (a GPU computer's fence).
60
+ for (const daemon of daemons)
61
+ lines.push(`daemon ${daemon.computer} (${daemon.role}): ${said(daemon)}${daemon.fence === undefined ? "" : ` · fence ${daemon.fence}`}`);
57
62
  for (const note of report.notes ?? [])
58
63
  lines.push(`note: ${note}`);
59
- for (const { computer, note } of report.computerNotes ?? [])
60
- lines.push(`note ${computer}: ${note}`);
64
+ for (const { computer, role, note } of report.computerNotes ?? [])
65
+ lines.push(`note ${computer} (${role}): ${note}`);
61
66
  // What a provider said through onNote, such as a release whose final sync or checkin did not go cleanly.
62
67
  for (const { computer, note } of report.providerNotes ?? [])
63
68
  lines.push(`provider note ${computer}: ${note}`);
@@ -3,6 +3,7 @@ import { randomBytes } from "node:crypto";
3
3
  import { setTimeout as sleep } from "node:timers/promises";
4
4
  import { isDeepStrictEqual } from "node:util";
5
5
  import { sweep } from "../janitor.js";
6
+ import { PROVIDERS } from "../kinds.js";
6
7
  import { GROUPS } from "../protocol.js";
7
8
  import { fail, ok } from "../result.js";
8
9
  import { casesFor } from "./cases/index.js";
@@ -84,9 +85,11 @@ function whenAborted(signal) {
84
85
  */
85
86
  export async function runConformance(provider, options) {
86
87
  // 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
+ const { image, only, kind, signal, cases = casesFor(provider.capabilities().kind), drifted, planted, mountFor, onResult, notes, caseTimeoutMs = 180_000, patience = 30_000, cleanupTimeoutMs = 60_000, fixture, gpu } = options;
88
89
  if (kind !== undefined && only !== undefined)
89
90
  throw new TypeError("a run takes kind and only apart: a kind runs its own cases");
91
+ // What the provider declares of itself: as given, else the kind registry's entry for its id (health.declared).
92
+ const declared = options.declared ?? PROVIDERS.find((entry) => entry.id === provider.id)?.capabilities;
90
93
  const kindProblem = kind === undefined ? undefined : kindRunProblem(kind);
91
94
  if (kindProblem !== undefined)
92
95
  throw new TypeError(kindProblem);
@@ -107,7 +110,7 @@ export async function runConformance(provider, options) {
107
110
  kind: capabilities.kind,
108
111
  daemonMode: capabilities.daemon,
109
112
  image,
110
- daemon: null,
113
+ daemons: [],
111
114
  ...(only === undefined ? {} : { only }),
112
115
  ...(only === undefined && kind === undefined ? {} : { coreNotRun: cases.filter((c) => c.level === "core" && !selected.includes(c)).map((c) => c.id) }),
113
116
  results: [],
@@ -150,24 +153,35 @@ export async function runConformance(provider, options) {
150
153
  report.cleanup.errors.push(words(error).startsWith(`release ${ref.name}`) ? words(error) : `release ${ref.name} threw: ${words(error)}`);
151
154
  }
152
155
  };
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
+ /** Each computer the run made, by name: its role, "shared" or the id of the case that made it. */
157
+ const roles = new Map();
158
+ /**
159
+ * Records the computer's role, and the notes a create returned beside its ref, each naming the computer and its role:
160
+ * never dropped with the ref.
161
+ */
162
+ const noteCreated = (created, role) => {
163
+ if (!created.ok)
164
+ return;
165
+ roles.set(created.value.name, role);
166
+ if (!Array.isArray(created.value.notes))
156
167
  return;
157
168
  for (const note of created.value.notes)
158
- (report.computerNotes ??= []).push({ computer: created.value.name, note: String(note) });
169
+ (report.computerNotes ??= []).push({ computer: created.value.name, role, note: String(note) });
159
170
  };
160
171
  /** Deletes the computer a create gives after nobody waits for it any more, and names it in the report. */
161
172
  const lateCreate = (creating, what, by = provider) => keep(creating.then(async (created) => {
162
- noteCreated(created);
173
+ noteCreated(created, "shared");
163
174
  if (!created.ok)
164
175
  return;
165
176
  report.cleanup.late.push(created.value.name);
166
177
  await release(created.value, by);
167
178
  }, () => { }), what);
168
179
  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 };
180
+ /** Records a computer's first hello, naming the computer and its role: the one it was made for, else the connecting case's. */
181
+ const sawHello = (computer, hello, role) => {
182
+ if (report.daemons.some((daemon) => daemon.computer === computer))
183
+ return;
184
+ report.daemons.push({ computer, role: roles.get(computer) ?? role, version: hello.version, os: hello.os, arch: hello.arch, ...(hello.fence === undefined ? {} : { fence: hello.fence }) });
171
185
  };
172
186
  /** The run's shared computer, made the first time a case needs it or the daemon's hello. */
173
187
  let shared;
@@ -186,7 +200,7 @@ export async function runConformance(provider, options) {
186
200
  lateCreate(creating, "create (the run's computer)");
187
201
  return { error: words(error) };
188
202
  }
189
- noteCreated(created);
203
+ noteCreated(created, "shared");
190
204
  if (!created.ok)
191
205
  return { error: createError(created) };
192
206
  sharedRef = created.value;
@@ -202,7 +216,7 @@ export async function runConformance(provider, options) {
202
216
  if (!connected.ok)
203
217
  return { error: `connect: ${connected.error.code}: ${connected.error.message}` };
204
218
  await bounded(connected.value.close(), CLOSE_MS);
205
- sawHello(connected.value.hello);
219
+ sawHello(created.value.name, connected.value.hello, "shared");
206
220
  return { ref: created.value, hello: connected.value.hello };
207
221
  })().catch((error) => ({ error: `the provider threw: ${words(error)}` })));
208
222
  /** Why a case cannot run here, or undefined when everything it needs is declared. */
@@ -241,6 +255,12 @@ export async function runConformance(provider, options) {
241
255
  else if (need === "vendor-agent" && !Array.isArray(capabilities.vendorAgentPorts)) {
242
256
  return `the provider does not declare ${need} (capabilities().vendorAgentPorts): no vendor's agent runs beside its computers' programs`;
243
257
  }
258
+ else if (need === "secrets" && planted === undefined) {
259
+ return "the provider takes no secret: its conformance module's ENV names no key, token or secret";
260
+ }
261
+ else if (need === "gpu" && capabilities.gpu === undefined) {
262
+ return "the provider does not declare gpu (capabilities().gpu): it offers no GPU";
263
+ }
244
264
  }
245
265
  return undefined;
246
266
  };
@@ -314,13 +334,13 @@ export async function runConformance(provider, options) {
314
334
  });
315
335
  keep(connecting, `connect to ${ref.name} (${c.id})`);
316
336
  const once = unwrap(await connecting, `connect to ${ref.name}`);
317
- sawHello(once.hello);
337
+ sawHello(ref.name, once.hello, c.id);
318
338
  return once;
319
339
  };
320
340
  /** create through by, kept: what it gives is deleted when the case ends, or as it comes after that. */
321
341
  const attempt = (whole, by = provider) => {
322
342
  const creating = by.create(whole, { signal: caseSignal }).then((created) => {
323
- noteCreated(created);
343
+ noteCreated(created, c.id);
324
344
  if (created.ok)
325
345
  track(created.value, by);
326
346
  return created;
@@ -409,6 +429,12 @@ export async function runConformance(provider, options) {
409
429
  return t.skip("no drifted provider was given: a provider module exports createDriftedProvider() for the drift cases");
410
430
  return await drifted();
411
431
  },
432
+ declared,
433
+ async planted() {
434
+ if (planted === undefined)
435
+ return t.skip("no provider with planted secrets was given: the provider takes no secret, or its module lists none in ENV");
436
+ return await planted();
437
+ },
412
438
  async runFolder(kind) {
413
439
  const none = `the run was given no run folder for mount kind ${kind}`;
414
440
  if (mountFor === undefined)
@@ -422,6 +448,12 @@ export async function runConformance(provider, options) {
422
448
  folders.push(folder);
423
449
  return folder;
424
450
  },
451
+ gpu() {
452
+ // A GPU bills by the second: the run names the one it pays for, never a default.
453
+ if (gpu === undefined)
454
+ return t.skip("the run named no GPU: give --gpu <type>[:<count>] (or options.gpu), one the provider declares in capabilities().gpu");
455
+ return { type: gpu.type, count: gpu.count };
456
+ },
425
457
  async exec(argv, extra = {}, client = t.client) {
426
458
  const ran = unwrap(await client.call("exec.run", { argv, timeoutMs: patience, ...extra }, { signal: caseSignal }), `exec.run ${show(argv)}`);
427
459
  const decode = (base64) => Buffer.from(base64, "base64").toString("utf8");