@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.
Files changed (173) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +2400 -1
  4. package/box/Dockerfile +69 -0
  5. package/box/agentrun-archil +168 -0
  6. package/box/build-daytona.py +26 -0
  7. package/box/build-e2b.mjs +32 -0
  8. package/box/build-modal.py +17 -0
  9. package/dist/actions.d.ts +18 -0
  10. package/dist/actions.js +139 -0
  11. package/dist/browser.d.ts +151 -0
  12. package/dist/browser.js +305 -0
  13. package/dist/browserbase.d.ts +139 -0
  14. package/dist/browserbase.js +408 -0
  15. package/dist/child.d.ts +40 -0
  16. package/dist/child.js +127 -0
  17. package/dist/client.d.ts +22 -0
  18. package/dist/client.js +136 -0
  19. package/dist/computerd-linux-amd64 +0 -0
  20. package/dist/computerd-linux-arm64 +0 -0
  21. package/dist/conformance/archil.d.ts +68 -0
  22. package/dist/conformance/archil.js +152 -0
  23. package/dist/conformance/browserbase.d.ts +35 -0
  24. package/dist/conformance/browserbase.js +45 -0
  25. package/dist/conformance/cases/apps.d.ts +2 -0
  26. package/dist/conformance/cases/apps.js +155 -0
  27. package/dist/conformance/cases/browser.d.ts +4 -0
  28. package/dist/conformance/cases/browser.js +105 -0
  29. package/dist/conformance/cases/drift.d.ts +2 -0
  30. package/dist/conformance/cases/drift.js +64 -0
  31. package/dist/conformance/cases/exec.d.ts +2 -0
  32. package/dist/conformance/cases/exec.js +125 -0
  33. package/dist/conformance/cases/files.d.ts +2 -0
  34. package/dist/conformance/cases/files.js +294 -0
  35. package/dist/conformance/cases/health.d.ts +2 -0
  36. package/dist/conformance/cases/health.js +71 -0
  37. package/dist/conformance/cases/index.d.ts +9 -0
  38. package/dist/conformance/cases/index.js +37 -0
  39. package/dist/conformance/cases/input.d.ts +12 -0
  40. package/dist/conformance/cases/input.js +109 -0
  41. package/dist/conformance/cases/isolation.d.ts +21 -0
  42. package/dist/conformance/cases/isolation.js +92 -0
  43. package/dist/conformance/cases/lifetime.d.ts +2 -0
  44. package/dist/conformance/cases/lifetime.js +64 -0
  45. package/dist/conformance/cases/mount.d.ts +2 -0
  46. package/dist/conformance/cases/mount.js +252 -0
  47. package/dist/conformance/cases/process.d.ts +2 -0
  48. package/dist/conformance/cases/process.js +240 -0
  49. package/dist/conformance/cases/provider.d.ts +2 -0
  50. package/dist/conformance/cases/provider.js +302 -0
  51. package/dist/conformance/cases/screen.d.ts +9 -0
  52. package/dist/conformance/cases/screen.js +230 -0
  53. package/dist/conformance/cases/settings.d.ts +57 -0
  54. package/dist/conformance/cases/settings.js +142 -0
  55. package/dist/conformance/cases/touch.d.ts +2 -0
  56. package/dist/conformance/cases/touch.js +117 -0
  57. package/dist/conformance/cases/util.d.ts +7 -0
  58. package/dist/conformance/cases/util.js +8 -0
  59. package/dist/conformance/cdp.d.ts +13 -0
  60. package/dist/conformance/cdp.js +88 -0
  61. package/dist/conformance/cli.d.ts +29 -0
  62. package/dist/conformance/cli.js +231 -0
  63. package/dist/conformance/daytona-sweep.d.ts +18 -0
  64. package/dist/conformance/daytona-sweep.js +118 -0
  65. package/dist/conformance/daytona.d.ts +83 -0
  66. package/dist/conformance/daytona.js +107 -0
  67. package/dist/conformance/docker.d.ts +38 -0
  68. package/dist/conformance/docker.js +70 -0
  69. package/dist/conformance/drift-daemon.d.ts +8 -0
  70. package/dist/conformance/drift-daemon.js +41 -0
  71. package/dist/conformance/e2b-diagnose.d.ts +16 -0
  72. package/dist/conformance/e2b-diagnose.js +61 -0
  73. package/dist/conformance/e2b-sweep.d.ts +18 -0
  74. package/dist/conformance/e2b-sweep.js +125 -0
  75. package/dist/conformance/e2b.d.ts +74 -0
  76. package/dist/conformance/e2b.js +111 -0
  77. package/dist/conformance/fixture.d.ts +65 -0
  78. package/dist/conformance/fixture.js +98 -0
  79. package/dist/conformance/index.d.ts +8 -0
  80. package/dist/conformance/index.js +8 -0
  81. package/dist/conformance/kernel.d.ts +31 -0
  82. package/dist/conformance/kernel.js +40 -0
  83. package/dist/conformance/kind.d.ts +23 -0
  84. package/dist/conformance/kind.js +58 -0
  85. package/dist/conformance/modal-sweep.d.ts +22 -0
  86. package/dist/conformance/modal-sweep.js +190 -0
  87. package/dist/conformance/modal.d.ts +69 -0
  88. package/dist/conformance/modal.js +76 -0
  89. package/dist/conformance/orgo.d.ts +41 -0
  90. package/dist/conformance/orgo.js +69 -0
  91. package/dist/conformance/phone-harness.d.ts +61 -0
  92. package/dist/conformance/phone-harness.js +241 -0
  93. package/dist/conformance/png.d.ts +16 -0
  94. package/dist/conformance/png.js +132 -0
  95. package/dist/conformance/report.d.ts +2 -0
  96. package/dist/conformance/report.js +86 -0
  97. package/dist/conformance/runner.d.ts +11 -0
  98. package/dist/conformance/runner.js +585 -0
  99. package/dist/conformance/tar.d.ts +13 -0
  100. package/dist/conformance/tar.js +105 -0
  101. package/dist/conformance/types.d.ts +257 -0
  102. package/dist/conformance/types.js +24 -0
  103. package/dist/daemon-copy.d.ts +40 -0
  104. package/dist/daemon-copy.js +259 -0
  105. package/dist/daytona.d.ts +178 -0
  106. package/dist/daytona.js +1484 -0
  107. package/dist/desktop.d.ts +24 -0
  108. package/dist/desktop.js +68 -0
  109. package/dist/docker/egress-main.d.ts +1 -0
  110. package/dist/docker/egress-main.js +68 -0
  111. package/dist/docker/egress-proxy.d.ts +53 -0
  112. package/dist/docker/egress-proxy.js +450 -0
  113. package/dist/docker/egress-table.d.ts +39 -0
  114. package/dist/docker/egress-table.js +197 -0
  115. package/dist/docker/egress.d.ts +109 -0
  116. package/dist/docker/egress.js +318 -0
  117. package/dist/docker/image.d.ts +49 -0
  118. package/dist/docker/image.js +302 -0
  119. package/dist/docker/stage.d.ts +21 -0
  120. package/dist/docker/stage.js +290 -0
  121. package/dist/docker/volume.d.ts +24 -0
  122. package/dist/docker/volume.js +67 -0
  123. package/dist/docker.d.ts +150 -0
  124. package/dist/docker.js +1200 -0
  125. package/dist/drift.d.ts +200 -0
  126. package/dist/drift.js +416 -0
  127. package/dist/e2b.d.ts +335 -0
  128. package/dist/e2b.js +1515 -0
  129. package/dist/entry.d.ts +2 -0
  130. package/dist/entry.js +24 -0
  131. package/dist/files.d.ts +50 -0
  132. package/dist/files.js +208 -0
  133. package/dist/index.d.ts +27 -0
  134. package/dist/index.js +26 -0
  135. package/dist/isolation.d.ts +29 -0
  136. package/dist/isolation.js +71 -0
  137. package/dist/janitor.d.ts +50 -0
  138. package/dist/janitor.js +135 -0
  139. package/dist/kernel.d.ts +113 -0
  140. package/dist/kernel.js +358 -0
  141. package/dist/kinds.d.ts +79 -0
  142. package/dist/kinds.js +133 -0
  143. package/dist/labels.d.ts +23 -0
  144. package/dist/labels.js +50 -0
  145. package/dist/modal.d.ts +302 -0
  146. package/dist/modal.js +1374 -0
  147. package/dist/mount-archil.d.ts +164 -0
  148. package/dist/mount-archil.js +471 -0
  149. package/dist/mount.d.ts +57 -0
  150. package/dist/mount.js +104 -0
  151. package/dist/orgo-channel.d.ts +96 -0
  152. package/dist/orgo-channel.js +391 -0
  153. package/dist/orgo.d.ts +139 -0
  154. package/dist/orgo.js +1006 -0
  155. package/dist/phone-harness.d.ts +185 -0
  156. package/dist/phone-harness.js +1420 -0
  157. package/dist/processes.d.ts +24 -0
  158. package/dist/processes.js +40 -0
  159. package/dist/protocol.d.ts +729 -0
  160. package/dist/protocol.js +54 -0
  161. package/dist/provider.d.ts +245 -0
  162. package/dist/provider.js +37 -0
  163. package/dist/providers.d.ts +68 -0
  164. package/dist/providers.js +25 -0
  165. package/dist/result.d.ts +15 -0
  166. package/dist/result.js +2 -0
  167. package/dist/screen-watch.d.ts +150 -0
  168. package/dist/screen-watch.js +490 -0
  169. package/dist/test-connection.d.ts +17 -0
  170. package/dist/test-connection.js +26 -0
  171. package/dist/wait.d.ts +23 -0
  172. package/dist/wait.js +65 -0
  173. package/package.json +64 -1
@@ -0,0 +1,252 @@
1
+ // The run's folder: a computer made with a mount of a kind the provider declares has the folder at /workspace, so a file
2
+ // written outside shows inside, one written inside shows outside, and a program run there sees it; the mount reads back
3
+ // as asked, with no Archil token in any read-back. A kind the provider does not declare is refused by check() in words,
4
+ // before any vendor call. Every case is Full: optional for every kind of computer until the cutover decides.
5
+ //
6
+ // An Archil mount is exclusive: what the disk's file API sees of a folder a computer holds, and what the computer sees
7
+ // of a write through the file API while it holds it, are not yet known either way. So for Archil, a file written outside
8
+ // before the computer is made is read inside (the Mode 2 flow), and the two directions while it is held are recorded as
9
+ // seen (observe), not asserted. What is asserted is what the contract promises: a write the computer answered is on the
10
+ // disk once the computer lets the folder go; a new claim takes the folder from a lower epoch, whose computer is gone;
11
+ // the token is nowhere a tool can read it; and, on one computer, a tool reaches no network while its writes reach the
12
+ // disk as each call returns.
13
+ import { randomBytes } from "node:crypto";
14
+ import { EPOCH_LABEL, RUN_LABEL, runLabels as claimLabels } from "../../labels.js";
15
+ import { MOUNT_KINDS, readBackOf, WORKSPACE } from "../../mount.js";
16
+ import { MAX_OUTPUT_BYTES } from "../../protocol.js";
17
+ import { assertIsolated } from "./isolation.js";
18
+ import { b64, CASE_LABEL, decode } from "./util.js";
19
+ /** The claim epoch the run-folder cases make their computers under. */
20
+ const EPOCH = 1;
21
+ const mount = (name, run, extra = {}) => ({
22
+ id: `mount.${name}`,
23
+ level: "full",
24
+ group: "mount",
25
+ needs: [],
26
+ computer: "none",
27
+ run,
28
+ ...extra,
29
+ });
30
+ /** Fails the case when what was read back holds the Archil token; the words never print it. */
31
+ function tokenless(t, asked, read, what) {
32
+ if (asked.kind === "archil")
33
+ t.assert(!JSON.stringify(read ?? null).includes(asked.token), `${what} holds the Archil token`);
34
+ }
35
+ /**
36
+ * The labels of a computer that mounts `folder` under `epoch`, for the folder's own run: the run it says, else the
37
+ * <run> of an Archil folder agents/<agent>/runs/<run>/work (every remote provider refuses a folder of another run than
38
+ * the agentrun.run label), else a fresh one.
39
+ */
40
+ function labelsFor(t, folder, epoch, name) {
41
+ const ofFolder = folder.mount.kind === "archil" ? /^agents\/[^/]+\/runs\/([^/]+)\/work$/.exec(folder.mount.folder)?.[1] : undefined;
42
+ return { ...t.runLabels, ...claimLabels(folder.run ?? ofFolder ?? `mount-${randomBytes(6).toString("hex")}`, epoch), [CASE_LABEL]: name };
43
+ }
44
+ /** A computer made with the folder's mount under `epoch`, after check() takes it; and its read-back, checked. */
45
+ async function mounted(t, folder, epoch, name) {
46
+ const asked = folder.mount;
47
+ const labels = labelsFor(t, folder, epoch, name);
48
+ const spec = t.spec({ labels, mount: asked });
49
+ const refusals = t.provider.check(spec);
50
+ tokenless(t, asked, refusals, "check's refusal of a spec that mounts the run's folder");
51
+ // A provider that declares the kind but whose host cannot give it (a Docker host that remaps user ids, for a bind)
52
+ // fails here in its own words: it declared what this host does not do.
53
+ t.assert(refusals.length === 0, `check refuses a spec that mounts the run's folder of kind ${asked.kind}, which the provider declares: ${refusals.map(({ field, message }) => `${field}: ${message}`).join("; ")}`);
54
+ const ref = await t.create(spec);
55
+ // The mount is read back from the computer, as asked, and no read-back holds the token.
56
+ const attached = t.ok(await t.provider.attach({ id: ref.id }), "attach by id");
57
+ tokenless(t, asked, attached, "attach by id: the mount it reads back");
58
+ t.deepEqual(attached.spec?.mount, readBackOf(asked, epoch), "attach by id: the mount it reads back");
59
+ const listed = t.ok(await t.provider.list(labels), "list");
60
+ tokenless(t, asked, listed, "list: what it reads back of the computer");
61
+ const info = t.present(listed.find((one) => one.ref.name === ref.name), `${ref.name} is listed by the case's labels`);
62
+ t.deepEqual(info.mount, readBackOf(asked, epoch), "list: the mount it reads back");
63
+ return { ref, labels };
64
+ }
65
+ const text = (bytes) => (bytes === undefined ? undefined : Buffer.from(bytes).toString("utf8"));
66
+ /** "mounts the run's folder" for one kind: on a computer of its own, made with a fresh run folder from the run. */
67
+ const runFolder = (kind) => mount(`run-folder-${kind}`, async (t) => {
68
+ const folder = await t.runFolder(kind);
69
+ const asked = folder.mount;
70
+ t.equal(asked.kind, kind, "the kind of the run folder's mount");
71
+ const nonce = randomBytes(6).toString("hex");
72
+ // Outside in, before the computer: a file written to the folder from outside is read at /workspace.
73
+ const before = `before-${nonce}.txt`;
74
+ const beforeText = `written outside before the computer ${nonce}\n`;
75
+ await folder.write(before, Buffer.from(beforeText));
76
+ // A folder made from outside too (a key ending in /), so the computer shows what owner and mode it was given.
77
+ const madeDir = `dir-${nonce}`;
78
+ if (kind === "archil")
79
+ await folder.write(`${madeDir}/`, new Uint8Array());
80
+ const { ref } = await mounted(t, folder, EPOCH, `mount-${kind}`);
81
+ const connected = await t.connect(ref);
82
+ if (kind === "archil") {
83
+ // Recorded, not asserted: the owner and mode a tool (agentrun-tool, 2510) writes against.
84
+ for (const [what, path] of [["a file", before], ["a folder", madeDir]]) {
85
+ const stat = await connected.client.call("files.stat", { path: `${WORKSPACE}/${path}` });
86
+ t.observe(`${what} the file API made, seen at ${WORKSPACE}: ${stat.ok ? `uid ${stat.value.uid}, gid ${stat.value.gid}, mode ${(stat.value.mode & 0o7777).toString(8)}` : `not stated (${stat.error.code}: ${stat.error.message})`}`);
87
+ }
88
+ }
89
+ const read = await t.call("files.read", { path: `${WORKSPACE}/${before}` }, connected.client);
90
+ t.equal(decode(read.data), beforeText, `files.read of ${WORKSPACE}/${before}, a file written outside before the computer`);
91
+ // Outside in, while the computer holds the folder.
92
+ const outside = `outside-${nonce}.txt`;
93
+ const outsideText = `written outside the computer ${nonce}\n`;
94
+ // An Archil computer holds the folder exclusively, so its disk may refuse the write (409, another client holds a
95
+ // write delegation): that is recorded, never a failure. A bind has no such hold, and its write must land.
96
+ const refused = kind === "archil" ? await folder.write(outside, Buffer.from(outsideText)).then(() => undefined, (error) => (error instanceof Error ? error.message : String(error))) : await folder.write(outside, Buffer.from(outsideText));
97
+ if (typeof refused === "string")
98
+ t.observe(`outside in, while held: the file API's write was refused: ${refused.replace(/\s+/g, " ").slice(0, 300)}`);
99
+ else {
100
+ const seen = await connected.client.call("files.read", { path: `${WORKSPACE}/${outside}` });
101
+ const seenText = seen.ok ? decode(seen.value.data) : undefined;
102
+ if (kind === "archil")
103
+ t.observe(`outside in, while held: a file the file API wrote is ${seenText === outsideText ? "read at /workspace as written" : seen.ok ? "read at /workspace with other bytes" : `not read at /workspace (${seen.error.code})`}`);
104
+ else
105
+ t.equal(seenText, outsideText, `files.read of ${WORKSPACE}/${outside}, a file written outside the computer`);
106
+ }
107
+ // Inside out: a file files.write makes at /workspace is in the folder outside.
108
+ const inside = `inside-${nonce}.txt`;
109
+ const insideText = `written inside the computer ${nonce}\n`;
110
+ t.ok(await connected.client.call("files.write", { path: `${WORKSPACE}/${inside}`, data: b64(insideText) }), `files.write of ${WORKSPACE}/${inside}`);
111
+ const back = text(await folder.read(inside));
112
+ if (kind === "archil")
113
+ t.observe(`inside out, while held: a file files.write made (synced before it answered) is ${back === insideText ? "read through the file API as written" : back === undefined ? "not found through the file API" : "read through the file API with other bytes"}`);
114
+ else
115
+ t.equal(t.present(back, `the file files.write made at ${WORKSPACE}/${inside}, read outside the computer`), insideText, `${inside} read outside the computer`);
116
+ // A program run with cwd /workspace sees the folder: a relative path reaches the file written outside.
117
+ const ran = await t.exec(["cat", before], { cwd: WORKSPACE }, connected.client);
118
+ t.equal(ran.exitCode, 0, `cat ${before} run with cwd ${WORKSPACE}: its exit code (${ran.err.trim()})`);
119
+ t.equal(ran.out, beforeText, `cat ${before} run with cwd ${WORKSPACE}: what it printed`);
120
+ }, { needs: [`mount:${kind}`, "exec", "files"] });
121
+ /** "a write the computer answered is on the disk": written inside, the computer released, then read outside. */
122
+ const archilDurable = mount("archil-durable", async (t) => {
123
+ const folder = await t.runFolder("archil");
124
+ const { ref } = await mounted(t, folder, EPOCH, "mount-archil-durable");
125
+ const connected = await t.connect(ref);
126
+ const nonce = randomBytes(6).toString("hex");
127
+ const name = `durable-${nonce}.txt`;
128
+ const body = `written inside, then the computer released ${nonce}\n`;
129
+ t.ok(await connected.client.call("files.write", { path: `${WORKSPACE}/${name}`, data: b64(body) }), `files.write of ${WORKSPACE}/${name}`);
130
+ const ran = await t.exec(["sh", "-c", `printf '%s\\n' ${nonce} > exec-${nonce}.txt`], { cwd: WORKSPACE }, connected.client);
131
+ t.equal(ran.exitCode, 0, `a program's write at ${WORKSPACE}: its exit code (${ran.err.trim()})`);
132
+ await connected.close();
133
+ t.ok(await t.provider.release(ref, "delete"), `release of ${ref.name}`);
134
+ t.equal(text(await folder.read(name)), body, `${name}, written by files.write, read outside once the computer is released`);
135
+ t.equal(text(await folder.read(`exec-${nonce}.txt`)), `${nonce}\n`, `exec-${nonce}.txt, written by a program, read outside once the computer is released`);
136
+ }, { needs: ["mount:archil", "exec", "files"], timeoutMs: 600_000 });
137
+ /** "a new claim takes the folder": epoch 1 writes, epoch 2 of the same run is made, epoch 1 is gone and 2 holds it. */
138
+ const archilTakeover = mount("archil-takeover", async (t) => {
139
+ const folder = await t.runFolder("archil");
140
+ const first = await mounted(t, folder, EPOCH, "mount-archil-takeover-1");
141
+ const one = await t.connect(first.ref);
142
+ const nonce = randomBytes(6).toString("hex");
143
+ const name = `epoch-1-${nonce}.txt`;
144
+ t.ok(await one.client.call("files.write", { path: `${WORKSPACE}/${name}`, data: b64(nonce) }), `files.write by the epoch ${EPOCH} computer`);
145
+ await one.close();
146
+ const second = await mounted(t, folder, EPOCH + 1, "mount-archil-takeover-2");
147
+ t.equal(second.labels[RUN_LABEL], first.labels[RUN_LABEL], "both computers are the same run's");
148
+ t.equal(second.labels[EPOCH_LABEL], String(EPOCH + 1), "the second is the higher epoch's");
149
+ const gone = await t.provider.attach({ id: first.ref.id });
150
+ t.assert(!gone.ok && gone.error.code === "not_found", `the epoch ${EPOCH} computer is gone after the epoch ${EPOCH + 1} create: ${gone.ok ? "it is still there" : gone.error.message}`);
151
+ const two = await t.connect(second.ref);
152
+ const read = await t.call("files.read", { path: `${WORKSPACE}/${name}` }, two.client);
153
+ t.equal(decode(read.data), nonce, `the epoch ${EPOCH + 1} computer reads what the epoch ${EPOCH} one wrote`);
154
+ }, { needs: ["mount:archil", "exec", "files"], timeoutMs: 600_000 });
155
+ /** "the tool user never has the token": not in any process's environment or arguments a tool can read, nor sudo. */
156
+ const archilToken = mount("archil-token", async (t) => {
157
+ const folder = await t.runFolder("archil");
158
+ const asked = folder.mount;
159
+ const { ref } = await mounted(t, folder, EPOCH, "mount-archil-token");
160
+ const connected = await t.connect(ref);
161
+ // What a tool can read of every process: its own and any other it sees (hidepid hides root's), and its own files.
162
+ const seen = await t.exec(["sh", "-c", 'for f in /proc/[0-9]*/environ /proc/[0-9]*/cmdline; do cat "$f" 2>/dev/null; echo; done; env; ls -la /proc | wc -l; ls -A /tmp /run 2>/dev/null'], { maxOutput: MAX_OUTPUT_BYTES }, connected.client);
163
+ // Every byte is read, or the case fails saying so: a cut output proves nothing about the bytes it dropped.
164
+ t.assert(!seen.truncated, `what a tool reads of every process came to more than the ${MAX_OUTPUT_BYTES} bytes exec.run keeps, so the token check did not see all of it`);
165
+ t.assert(!seen.out.includes(asked.token) && !seen.err.includes(asked.token), "a tool reads the Archil token in some process's environment or arguments");
166
+ const sudo = await t.exec(["sh", "-c", "sudo -n true"], {}, connected.client);
167
+ t.assert(sudo.exitCode !== 0, "the tool user ran sudo");
168
+ }, { needs: ["mount:archil", "exec"], timeoutMs: 600_000 });
169
+ /**
170
+ * "isolated, and durable through the root side", on one Archil computer: a tool sees loopback alone and reaches neither a
171
+ * vendor's agent nor any address; and a tool's write in /workspace, by a program (exec.run) and by files.write, is read
172
+ * through the disk's file API right after the call returns, with no checkin. So the per-call sync goes out from the
173
+ * archil client and serve, which run as root outside the tools' namespace.
174
+ */
175
+ const archilIsolatedDurable = mount("archil-isolated-durable", async (t) => {
176
+ const folder = await t.runFolder("archil");
177
+ const { ref } = await mounted(t, folder, EPOCH, "mount-archil-isolated-durable");
178
+ const connected = await t.connect(ref);
179
+ // isolation.vendor-agent's own check, on this Archil computer: lo alone, refused at the vendor's agent and outside,
180
+ // and no path unix socket a tool connects to but the computer's own (computerd's, the sync socket).
181
+ await assertIsolated(t, connected.client);
182
+ const nonce = randomBytes(6).toString("hex");
183
+ const ran = await t.exec(["sh", "-c", `printf '%s\\n' ${nonce} > exec-${nonce}.txt`], { cwd: WORKSPACE }, connected.client);
184
+ t.equal(ran.exitCode, 0, `a program's write at ${WORKSPACE}: its exit code (${ran.err.trim()})`);
185
+ t.equal(text(await folder.read(`exec-${nonce}.txt`)), `${nonce}\n`, `exec-${nonce}.txt, written by a program, read through the file API right after exec.run returned`);
186
+ const body = `written by files.write ${nonce}\n`;
187
+ t.ok(await connected.client.call("files.write", { path: `${WORKSPACE}/write-${nonce}.txt`, data: b64(body) }), "files.write");
188
+ t.equal(text(await folder.read(`write-${nonce}.txt`)), body, `write-${nonce}.txt, written by files.write, read through the file API right after it returned`);
189
+ }, { needs: ["mount:archil", "exec", "files"], timeoutMs: 600_000 });
190
+ /** What the tool runs: the line ($1) appended to the file ($2), as the computer's user, with no shell quoting of either. */
191
+ const APPEND = 'printf "%s\\n" "$1" >> "$2"';
192
+ /**
193
+ * Mode 2's promise: the loop writes a file through the disk's file API, a tool edits it, and the loop reads the edit
194
+ * back. The file is written before the computer mounts the folder (the disk refuses outside writes while it is held);
195
+ * the tool, the computer's user, appends to it, and must be able to; the loop's read while the folder is held is
196
+ * recorded, and once the computer is released the file must read back as the loop's text with the tool's line.
197
+ */
198
+ const archilLoopToolEdit = mount("archil-loop-tool-edit", async (t) => {
199
+ const folder = await t.runFolder("archil");
200
+ const nonce = randomBytes(6).toString("hex");
201
+ const name = `loop-${nonce}.txt`;
202
+ const path = `${WORKSPACE}/${name}`;
203
+ const loopText = `written by the loop through the file API ${nonce}\n`;
204
+ await folder.write(name, Buffer.from(loopText));
205
+ const { ref } = await mounted(t, folder, EPOCH, "mount-archil-loop-tool-edit");
206
+ const connected = await t.connect(ref);
207
+ const stat = await connected.client.call("files.stat", { path });
208
+ t.observe(`the file the loop wrote, seen at ${WORKSPACE} before the tool's edit: ${stat.ok ? `uid ${stat.value.uid}, gid ${stat.value.gid}, mode ${(stat.value.mode & 0o7777).toString(8)}` : `not stated (${stat.error.code}: ${stat.error.message})`}`);
209
+ const line = `edited by a tool ${nonce}`;
210
+ const ran = await t.exec(["sh", "-c", APPEND, "sh", line, path], {}, connected.client);
211
+ t.assert(ran.exitCode === 0, `a tool (the computer's user) could not edit ${path}, which the file API made: exit ${ran.exitCode}: ${ran.err.trim().slice(0, 300)}`);
212
+ const want = `${loopText}${line}\n`;
213
+ const held = await folder.read(name).then((bytes) => (text(bytes) === want ? "the tool's edit, as written" : bytes === undefined ? "not found" : "other bytes"), (error) => `refused: ${(error instanceof Error ? error.message : String(error)).replace(/\s+/g, " ").slice(0, 300)}`);
214
+ t.observe(`the loop's read while the computer holds the folder: ${held}`);
215
+ await connected.close();
216
+ t.ok(await t.provider.release(ref, "delete"), `release of ${ref.name}`);
217
+ t.equal(text(await folder.read(name)), want, `${name}: the loop's text with the tool's line, read through the file API once the computer is released`);
218
+ }, { needs: ["mount:archil", "exec", "files"], timeoutMs: 600_000 });
219
+ /** A mount of each kind the provider does not declare, with a token this case alone knows. */
220
+ function undeclaredMount(kind, token) {
221
+ return kind === "bind" ? { kind, path: "/" } : { kind, disk: "conformance-disk", region: "conformance-region", folder: "agents/conformance/runs/r/work", token };
222
+ }
223
+ export const mountCases = [
224
+ runFolder("bind"),
225
+ runFolder("archil"),
226
+ archilDurable,
227
+ archilTakeover,
228
+ archilToken,
229
+ archilIsolatedDurable,
230
+ archilLoopToolEdit,
231
+ mount("undeclared-kind", async (t) => {
232
+ const declared = t.provider.capabilities().mount ?? [];
233
+ const undeclared = MOUNT_KINDS.filter((kind) => !declared.includes(kind));
234
+ if (undeclared.length === 0)
235
+ t.skip(`the provider declares every mount kind (${MOUNT_KINDS.join(", ")})`);
236
+ const token = `conformance-token-${randomBytes(12).toString("hex")}`;
237
+ const labels = { ...t.runLabels, [CASE_LABEL]: "mount-undeclared" };
238
+ for (const kind of undeclared) {
239
+ const spec = t.spec({ labels, mount: undeclaredMount(kind, token) });
240
+ const refusals = t.provider.check(spec);
241
+ const words = `check refuses a mount of kind ${kind}, which the provider does not declare`;
242
+ t.assert(!JSON.stringify(refusals).includes(token), `${words}: its refusal holds the Archil token`);
243
+ t.assert(refusals.some((r) => r.field === "mount" && r.message !== ""), `${words}, in words: ${JSON.stringify(refusals)}`);
244
+ // create refuses it for what check() refuses, before any vendor call; a computer it makes anyway is deleted.
245
+ const error = t.refused(await t.attempt(spec), `create with a mount of kind ${kind}`, ["refused"]);
246
+ t.assert(!error.message.includes(token), `create's refusal of a mount of kind ${kind} holds the Archil token`);
247
+ t.assert(refusals.some(({ message }) => error.message.includes(message)), `create's refusal of a mount of kind ${kind} names what check() refused (${refusals.map(({ field, message }) => `${field}: ${message}`).join("; ")}), not: ${error.message}`);
248
+ }
249
+ const left = t.ok(await t.provider.list(labels), "list").map((info) => info.ref.name);
250
+ t.deepEqual(left, [], "the computers the refused creates made");
251
+ }),
252
+ ];
@@ -0,0 +1,2 @@
1
+ import type { Case } from "../types.js";
2
+ export declare const processCases: Case[];
@@ -0,0 +1,240 @@
1
+ // process.*: a process outlives the connection that started it, is read by offset, takes stdin, runs in a terminal,
2
+ // is signalled and waited on, is listed, and leaves nothing behind when it ends.
3
+ import { listProcesses, readAll } from "../../processes.js";
4
+ import { PROCESS_LOG_BYTES } from "../../protocol.js";
5
+ import { alive, b64, decode, delay } from "./util.js";
6
+ const processCase = (name, run, needs = ["processes"]) => ({
7
+ id: `process.${name}`,
8
+ level: "core",
9
+ group: "process",
10
+ needs,
11
+ run,
12
+ });
13
+ const TICKER = ["sh", "-c", "i=0; while true; do echo tick $i; i=$((i+1)); sleep 0.2; done"];
14
+ /** Reads a stream from offset until what was read holds want; returns it and where the stream now ends. */
15
+ async function readUntil(t, client, id, stream, offset, want) {
16
+ let text = "";
17
+ let at = offset;
18
+ const holds = () => (typeof want === "string" ? text.includes(want) : want.test(text));
19
+ const shown = typeof want === "string" ? JSON.stringify(want) : String(want);
20
+ await t.until(async () => {
21
+ const read = await t.call("process.read", { id, stream, offset: at, waitMs: 1000 }, client);
22
+ text += decode(read.data);
23
+ at = read.nextOffset;
24
+ if (!holds() && read.exited)
25
+ throw new Error(`${id} ${stream} ended without ${shown}: ${JSON.stringify(text)}`);
26
+ return holds();
27
+ }, `${id} ${stream} to show ${shown} (it showed ${JSON.stringify(text.slice(-200))})`);
28
+ return { text, offset: at };
29
+ }
30
+ const ticker = (t, client = t.client) => t.call("process.start", { argv: TICKER }, client);
31
+ const kill = (t, id) => t.call("process.signal", { id, signal: "KILL" });
32
+ export const processCases = [
33
+ processCase("outlives-connection", async (t) => {
34
+ const a = await t.connect();
35
+ const started = await ticker(t, a.client);
36
+ t.match(started.id, /^\S+$/, "the process's id");
37
+ t.assert(started.pid > 1, `the program's pid, ${started.pid}`);
38
+ await readUntil(t, a.client, started.id, "stdout", 0, "tick 0");
39
+ await a.close();
40
+ const listed = t.ok(await listProcesses(t.client), "listing on another connection");
41
+ const entry = t.present(listed.find((p) => p.id === started.id), `${started.id} is listed on another connection after the first closed`);
42
+ t.equal(entry.running, true, "running");
43
+ t.equal(entry.pid, started.pid, "pid");
44
+ t.deepEqual(entry.argv.slice(0, 2), ["sh", "-c"], "argv");
45
+ const before = (await t.call("process.read", { id: started.id, stream: "stdout", offset: 0 })).nextOffset;
46
+ const { offset } = await readUntil(t, t.client, started.id, "stdout", before, "tick");
47
+ t.assert(offset > before, "it still ticks after the connection that started it closed");
48
+ await kill(t, started.id);
49
+ }),
50
+ processCase("read-by-offset", async (t) => {
51
+ const started = await ticker(t);
52
+ await readUntil(t, t.client, started.id, "stdout", 0, "tick 0");
53
+ const first = await t.call("process.read", { id: started.id, stream: "stdout", offset: 0 });
54
+ t.match(decode(first.data), /^tick 0\n/, "the stream from offset 0");
55
+ t.equal(first.dropped, 0, "dropped");
56
+ t.assert(first.nextOffset > 0, "nextOffset after the first read");
57
+ const { offset } = await readUntil(t, t.client, started.id, "stdout", first.nextOffset, "tick");
58
+ t.assert(offset > first.nextOffset, `nextOffset grows: ${offset} after ${first.nextOffset}`);
59
+ const again = await t.call("process.read", { id: started.id, stream: "stdout", offset: 0, maxBytes: 7 });
60
+ t.equal(decode(again.data), "tick 0\n", "a second read from offset 0, 7 bytes");
61
+ t.equal(again.nextOffset, 7, "its nextOffset");
62
+ t.assert(again.size >= offset, `its size, the stream's bytes so far: ${again.size}, at least the ${offset} already read`);
63
+ t.refused(await t.client.call("process.read", { id: started.id, stream: "stdout", offset: offset + 1_000_000 }), "a read past the end", ["invalid"]);
64
+ await kill(t, started.id);
65
+ }),
66
+ processCase("stdin", async (t) => {
67
+ const cat = await t.call("process.start", { argv: ["cat"], stdin: true });
68
+ await t.call("process.write", { id: cat.id, data: b64("hello from the suite\n") });
69
+ await t.call("process.write", { id: cat.id, data: b64("bye\n"), close: true });
70
+ t.deepEqual(await t.call("process.wait", { id: cat.id, timeoutMs: t.patience }), { running: false, exitCode: 0, signal: null }, "cat's end after stdin closed");
71
+ const read = t.ok(await readAll(t.client, cat.id, "stdout"), "readAll");
72
+ t.equal(Buffer.from(read.data).toString(), "hello from the suite\nbye\n", "what cat wrote back");
73
+ }),
74
+ processCase("stdin-closed", async (t) => {
75
+ const closed = await t.call("process.start", { argv: ["sh", "-c", "exec 0<&-; echo closed; exec sleep 307"], stdin: true });
76
+ await readUntil(t, t.client, closed.id, "stdout", 0, "closed\n");
77
+ t.refused(await t.client.call("process.write", { id: closed.id, data: b64("x\n") }), "a write to a program that closed its stdin, which must fail at once", ["invalid"]);
78
+ t.deepEqual(await t.call("process.wait", { id: closed.id, timeoutMs: 0 }), { running: true, exitCode: null, signal: null }, "the program after the failed write: running");
79
+ await kill(t, closed.id);
80
+ t.deepEqual(await t.call("process.wait", { id: closed.id, timeoutMs: t.patience }), { running: false, exitCode: null, signal: "KILL" }, "wait after KILL");
81
+ }),
82
+ processCase("pty", async (t) => {
83
+ const sh = await t.call("process.start", { argv: ["sh"], pty: { cols: 80, rows: 24 } });
84
+ let offset = 0;
85
+ await t.call("process.write", { id: sh.id, data: b64("echo pty-$((6*7))\n") });
86
+ ({ offset } = await readUntil(t, t.client, sh.id, "pty", offset, "pty-42"));
87
+ await t.call("process.write", { id: sh.id, data: b64("stty size\n") });
88
+ ({ offset } = await readUntil(t, t.client, sh.id, "pty", offset, "24 80"));
89
+ await t.call("process.resize", { id: sh.id, cols: 132, rows: 43 });
90
+ await t.call("process.write", { id: sh.id, data: b64("stty size\n") });
91
+ ({ offset } = await readUntil(t, t.client, sh.id, "pty", offset, "43 132"));
92
+ await t.call("process.write", { id: sh.id, data: b64("exit 5\n") });
93
+ t.deepEqual(await t.call("process.wait", { id: sh.id, timeoutMs: t.patience }), { running: false, exitCode: 5, signal: null }, "the shell's end");
94
+ }),
95
+ processCase("signal", async (t) => {
96
+ const started = await ticker(t);
97
+ await readUntil(t, t.client, started.id, "stdout", 0, "tick 0");
98
+ await t.call("process.signal", { id: started.id, signal: "TERM" });
99
+ t.deepEqual(await t.call("process.wait", { id: started.id, timeoutMs: t.patience }), { running: false, exitCode: null, signal: "TERM" }, "wait after TERM");
100
+ const entry = t.present(t.ok(await listProcesses(t.client), "process.list").find((p) => p.id === started.id), `${started.id} is listed after it ended`);
101
+ t.deepEqual([entry.running, entry.signal], [false, "TERM"], "the listing after TERM");
102
+ t.assert(entry.endedAt !== null && entry.endedAt >= entry.startedAt, "endedAt after startedAt");
103
+ t.deepEqual(await t.call("process.signal", { id: started.id, signal: "KILL" }), {}, "a signal to a process that has ended");
104
+ await t.until(async () => (await t.exec(["sh", "-c", alive([started.pid])])).out === "", `pid ${started.pid} gone`);
105
+ }, ["processes", "exec"]),
106
+ processCase("pty-interrupt", async (t) => {
107
+ // INT on a terminal is ^C: it ends the foreground job, and the shell that started the job reads on. What the
108
+ // terminal echoes of a typed line holds name=$..., never digits, so only the shell's output shows name=<pid>.
109
+ const sh = await t.call("process.start", { argv: ["sh", "-i"], pty: { cols: 80, rows: 24 } });
110
+ let offset = 0;
111
+ const pidAfter = async (line, name) => {
112
+ await t.call("process.write", { id: sh.id, data: b64(line) });
113
+ const pattern = new RegExp(`${name}=(\\d+)\\r?\\n`);
114
+ const read = await readUntil(t, t.client, sh.id, "pty", offset, pattern);
115
+ offset = read.offset;
116
+ return Number(pattern.exec(read.text)?.[1]);
117
+ };
118
+ const stateOf = async (pid) => {
119
+ const stat = (await t.exec(["sh", "-c", alive([pid])])).out;
120
+ return stat.slice(stat.lastIndexOf(")") + 1).trim().split(/\s+/);
121
+ };
122
+ // The shell and its two jobs go however the case ends: a failed or timed-out check aborts the case's signal, so the
123
+ // KILL goes without it, and the guard ends what the shell started.
124
+ let checked = false;
125
+ try {
126
+ const bg = await pidAfter("sleep 306 & echo bg=$!\n", "bg");
127
+ const fg = await pidAfter("sh -c 'echo fg=$$; exec sleep 308'\n", "fg");
128
+ // The job is in the foreground once its group is the terminal's: its stat's pgrp and tpgid are its pid.
129
+ await t.until(async () => {
130
+ const fields = await stateOf(fg);
131
+ return fields[2] === String(fg) && fields[5] === String(fg);
132
+ }, `${fg} in the terminal's foreground`);
133
+ t.deepEqual(await t.call("process.signal", { id: sh.id, signal: "INT" }), {}, "the reply to INT with a foreground job");
134
+ await t.until(async () => ["", "Z"].includes((await stateOf(fg))[0] ?? ""), `the foreground job ${fg} gone`);
135
+ await t.call("process.write", { id: sh.id, data: b64("echo status=$?\n") });
136
+ ({ offset } = await readUntil(t, t.client, sh.id, "pty", offset, "status=130"));
137
+ await t.call("process.write", { id: sh.id, data: b64("echo al''ive\n") });
138
+ ({ offset } = await readUntil(t, t.client, sh.id, "pty", offset, "alive"));
139
+ t.assert(!["", "Z"].includes((await stateOf(bg))[0] ?? ""), `the background job ${bg} still runs`);
140
+ t.deepEqual(await t.call("process.wait", { id: sh.id, timeoutMs: 0 }), { running: true, exitCode: null, signal: null }, "the shell after INT");
141
+ checked = true;
142
+ }
143
+ finally {
144
+ const killed = await t.client.call("process.signal", { id: sh.id, signal: "KILL" });
145
+ if (checked)
146
+ t.ok(killed, "KILL to the shell");
147
+ }
148
+ }, ["processes", "exec"]),
149
+ processCase("wait", async (t) => {
150
+ const sleeper = await t.call("process.start", { argv: ["sleep", "303"] });
151
+ t.deepEqual(await t.call("process.wait", { id: sleeper.id, timeoutMs: 0 }), { running: true, exitCode: null, signal: null }, "wait with timeoutMs 0 on a running process");
152
+ t.deepEqual(await t.call("process.wait", { id: sleeper.id, timeoutMs: 300 }), { running: true, exitCode: null, signal: null }, "wait past its timeout");
153
+ await kill(t, sleeper.id);
154
+ t.deepEqual(await t.call("process.wait", { id: sleeper.id, timeoutMs: t.patience }), { running: false, exitCode: null, signal: "KILL" }, "wait after KILL");
155
+ const three = await t.call("process.start", { argv: ["sh", "-c", "exit 3"] });
156
+ t.deepEqual(await t.call("process.wait", { id: three.id, timeoutMs: t.patience }), { running: false, exitCode: 3, signal: null }, "wait on a program that exits 3");
157
+ t.refused(await t.client.call("process.wait", { id: "no-such-process", timeoutMs: 0 }), "a process that does not exist", ["not_found"]);
158
+ }),
159
+ processCase("list", async (t) => {
160
+ const done = await t.call("process.start", { argv: ["echo", "listed"] });
161
+ const term = await t.call("process.start", { argv: ["sleep", "304"], pty: { cols: 80, rows: 24 } });
162
+ await t.call("process.wait", { id: done.id, timeoutMs: t.patience });
163
+ const listed = t.ok(await listProcesses(t.client), "listProcesses");
164
+ const at = (id) => listed.findIndex((p) => p.id === id);
165
+ t.assert(at(done.id) >= 0 && at(term.id) > at(done.id), "both are listed, in start order");
166
+ const ended = listed[at(done.id)];
167
+ const running = listed[at(term.id)];
168
+ t.deepEqual([ended?.argv, ended?.running, ended?.exitCode, ended?.pty], [["echo", "listed"], false, 0, false], "the ended process");
169
+ t.deepEqual([running?.argv, running?.running, running?.pty, running?.pid], [["sleep", "304"], true, true, term.pid], "the running one, in a terminal");
170
+ // Pages may be any size: follow next while truncated, then the page from the last next is empty.
171
+ let page = await t.call("process.list", {});
172
+ const paged = [...page.processes];
173
+ for (let pages = 1; page.truncated; pages++) {
174
+ t.assert(pages <= listed.length + 1, `process.list still truncated after ${pages} pages for ${listed.length} processes`);
175
+ t.assert(Number.isSafeInteger(page.next), `next is where the page after starts: ${JSON.stringify(page.next)}`);
176
+ page = await t.call("process.list", { from: page.next });
177
+ paged.push(...page.processes);
178
+ }
179
+ t.deepEqual(paged.map((p) => p.id), listed.map((p) => p.id), "the processes paged by from and next, in start order");
180
+ t.assert(Number.isSafeInteger(page.next), `next is where a page after would start: ${JSON.stringify(page.next)}`);
181
+ t.deepEqual((await t.call("process.list", { from: page.next })).processes, [], "the page from next, after the last");
182
+ await kill(t, term.id);
183
+ }),
184
+ processCase("log", async (t) => {
185
+ // A folder of the run's, as the computer's user makes one: the log goes in it, and nothing else does.
186
+ const folder = (await t.exec(["mktemp", "-d"])).out.trim();
187
+ const path = `${folder}/background/1/output.log`;
188
+ const started = await t.call("process.start", { argv: ["sh", "-c", `head -c ${PROCESS_LOG_BYTES + 1000} /dev/zero | tr '\\0' x; echo after >&2`], log: path });
189
+ t.equal((await t.call("process.wait", { id: started.id, timeoutMs: t.patience })).exitCode, 0, "the writer's end");
190
+ t.equal((await t.exec(["stat", "-c", "%s %a %F", path])).out.trim(), `${PROCESS_LOG_BYTES} 644 regular file`, "the file: the first 16 MiB, mode 644");
191
+ t.equal((await t.exec(["sh", "-c", `tail -c 3 ${path}; find ${folder} -type f`])).out, `xxx${path}\n`, "its last bytes are the first output's, and it is the folder's one file");
192
+ const end = await t.call("process.read", { id: started.id, stream: "log", offset: PROCESS_LOG_BYTES - 3 });
193
+ t.deepEqual([decode(end.data), end.nextOffset, end.size, end.capped, end.exited], ["xxx", PROCESS_LOG_BYTES, PROCESS_LOG_BYTES, true, true], "the log stream's end");
194
+ t.refused(await t.client.call("process.read", { id: started.id, stream: "log", offset: PROCESS_LOG_BYTES + 1 }), "a read past the log's end", ["invalid"]);
195
+ }, ["processes", "exec"]),
196
+ processCase("log-links", async (t) => {
197
+ // The run's folder is the program's to write: a link planted at the log or at a directory on its way is refused,
198
+ // and nothing is written where it points.
199
+ const folder = (await t.exec(["mktemp", "-d"])).out.trim();
200
+ await t.exec(["sh", "-c", `mkdir ${folder}/outside ${folder}/a && ln -s ${folder}/outside/target.log ${folder}/a/output.log && ln -s ${folder}/outside ${folder}/background`]);
201
+ for (const path of [`${folder}/a/output.log`, `${folder}/background/1/output.log`]) {
202
+ t.refused(await t.client.call("process.start", { argv: ["sh", "-c", `echo ran > ${folder}/ran`], log: path }), `a log at ${path}, through a link`, ["denied"]);
203
+ }
204
+ t.equal((await t.exec(["sh", "-c", `ls -A ${folder}/outside; ls ${folder}/ran 2>/dev/null; true`])).out, "", "nothing written through a link, and nothing ran");
205
+ await t.exec(["sh", "-c", `echo before > ${folder}/a/existing.log`]);
206
+ t.refused(await t.client.call("process.start", { argv: ["true"], log: `${folder}/a/existing.log` }), "a log where a file is", ["exists"]);
207
+ }, ["processes", "exec"]),
208
+ processCase("wait-group", async (t) => {
209
+ const started = await t.call("process.start", { argv: ["sh", "-c", "sleep 1 & echo started"], waitGroup: true });
210
+ t.deepEqual(await t.call("process.wait", { id: started.id, timeoutMs: 300 }), { running: true, exitCode: null, signal: null }, "running while the job it left runs");
211
+ t.deepEqual(await t.call("process.wait", { id: started.id, timeoutMs: t.patience }), { running: false, exitCode: 0, signal: null }, "the program's exit once the job ended");
212
+ const job = await t.call("process.start", { argv: ["sh", "-c", "sleep 310 >/dev/null 2>&1 & exit 3"], waitGroup: true });
213
+ t.deepEqual(await t.call("process.wait", { id: job.id, timeoutMs: 300 }), { running: true, exitCode: null, signal: null }, "running while sleep 310 runs");
214
+ await t.call("process.signal", { id: job.id, signal: "TERM" });
215
+ t.deepEqual(await t.call("process.wait", { id: job.id, timeoutMs: t.patience }), { running: false, exitCode: 3, signal: null }, "TERM reached the job, and the end is the program's");
216
+ }),
217
+ processCase("orphans-keep", async (t) => {
218
+ const started = await t.call("process.start", { argv: ["sh", "-c", "setsid sleep 311 >/dev/null 2>&1 </dev/null & echo $!"], waitGroup: true, orphans: "keep" });
219
+ t.equal((await t.call("process.wait", { id: started.id, timeoutMs: t.patience })).running, false, "the process ends with its group");
220
+ const pid = Number(Buffer.from(t.ok(await readAll(t.client, started.id, "stdout"), "its output").data).toString().trim());
221
+ try {
222
+ await delay(500);
223
+ t.assert((await t.exec(["sh", "-c", alive([pid])])).out !== "", `the daemon ${pid} runs on after the process ended`);
224
+ }
225
+ finally {
226
+ await t.exec(["sh", "-c", `kill -KILL ${pid}`]);
227
+ }
228
+ }, ["processes", "exec"]),
229
+ processCase("guard-killed", async (t) => {
230
+ // It kills its guard only once the start has returned: a guard killed before it reports the pid fails the start.
231
+ const rogue = await t.call("process.start", { argv: ["sh", "-c", "read go; sleep 305 & echo $$ $!; kill -9 $PPID; wait"], stdin: true });
232
+ await t.call("process.write", { id: rogue.id, data: b64("go\n") });
233
+ const { text } = await readUntil(t, t.client, rogue.id, "stdout", 0, "\n");
234
+ const pids = text.trim().split(/\s+/).map(Number);
235
+ t.equal(pids.length, 2, `two pids from ${JSON.stringify(text)}`);
236
+ t.equal(pids[0], rogue.pid, "the program's pid");
237
+ t.equal((await t.call("process.wait", { id: rogue.id, timeoutMs: t.patience })).running, false, "running, after it killed its own guard");
238
+ await t.until(async () => (await t.exec(["sh", "-c", alive(pids)])).out === "", `pids ${pids.join(" ")} gone`);
239
+ }, ["processes", "exec"]),
240
+ ];
@@ -0,0 +1,2 @@
1
+ import type { Case } from "../types.js";
2
+ export declare const providerCases: Case[];