@smoothbricks/nx-plugin 0.7.17 → 0.7.19

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 (199) hide show
  1. package/README.md +315 -114
  2. package/dist/.build-inputs.json +47 -38
  3. package/dist/built-output-packages.js +1 -1
  4. package/dist/bun-lock-scope.d.ts +128 -20
  5. package/dist/bun-lock-scope.d.ts.map +1 -1
  6. package/dist/bun-lock-scope.js +267 -44
  7. package/dist/cargo-closure-input.d.ts +8 -6
  8. package/dist/cargo-closure-input.d.ts.map +1 -1
  9. package/dist/cargo-closure-input.js +15 -12
  10. package/dist/cargo-source-hash.d.ts +26 -25
  11. package/dist/cargo-source-hash.d.ts.map +1 -1
  12. package/dist/cargo-source-hash.js +84 -105
  13. package/dist/cargo-toolchain-paths.d.ts +2 -2
  14. package/dist/cargo-toolchain-paths.js +2 -2
  15. package/dist/cargo-workspace.d.ts +20 -2
  16. package/dist/cargo-workspace.d.ts.map +1 -1
  17. package/dist/cargo-workspace.js +43 -22
  18. package/dist/ensure-built-receipt.d.ts +3 -2
  19. package/dist/ensure-built-receipt.d.ts.map +1 -1
  20. package/dist/ensure-built-receipt.js +3 -2
  21. package/dist/eslint-config-closure.d.ts +8 -3
  22. package/dist/eslint-config-closure.d.ts.map +1 -1
  23. package/dist/eslint-config-closure.js +24 -5
  24. package/dist/executors/bounded-exec/admission-queue.d.ts +3 -1
  25. package/dist/executors/bounded-exec/admission-queue.d.ts.map +1 -1
  26. package/dist/executors/bounded-exec/admission-queue.js +9 -10
  27. package/dist/executors/bounded-exec/awake-clock.d.ts +5 -0
  28. package/dist/executors/bounded-exec/awake-clock.d.ts.map +1 -0
  29. package/dist/executors/bounded-exec/awake-clock.js +22 -0
  30. package/dist/executors/bounded-exec/bounds.d.ts +19 -6
  31. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  32. package/dist/executors/bounded-exec/bounds.js +22 -15
  33. package/dist/executors/bounded-exec/case-gate.d.ts +114 -0
  34. package/dist/executors/bounded-exec/case-gate.d.ts.map +1 -0
  35. package/dist/executors/bounded-exec/case-gate.js +342 -0
  36. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +1 -0
  37. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
  38. package/dist/executors/bounded-exec/cpu-pool-thread.js +2 -2
  39. package/dist/executors/bounded-exec/cpu-pool.d.ts +28 -1
  40. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  41. package/dist/executors/bounded-exec/cpu-pool.js +102 -16
  42. package/dist/executors/bounded-exec/cpu-rise.d.ts +73 -0
  43. package/dist/executors/bounded-exec/cpu-rise.d.ts.map +1 -0
  44. package/dist/executors/bounded-exec/cpu-rise.js +111 -0
  45. package/dist/executors/bounded-exec/endpoint-life.d.ts +146 -0
  46. package/dist/executors/bounded-exec/endpoint-life.d.ts.map +1 -0
  47. package/dist/executors/bounded-exec/endpoint-life.js +228 -0
  48. package/dist/executors/bounded-exec/executor.d.ts +1 -1
  49. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  50. package/dist/executors/bounded-exec/executor.js +256 -86
  51. package/dist/executors/bounded-exec/gateway-lease.d.ts +1 -1
  52. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  53. package/dist/executors/bounded-exec/gateway-lease.js +8 -1
  54. package/dist/executors/bounded-exec/go-run-summary.d.ts +51 -0
  55. package/dist/executors/bounded-exec/go-run-summary.d.ts.map +1 -0
  56. package/dist/executors/bounded-exec/go-run-summary.js +98 -0
  57. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +11 -3
  58. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  59. package/dist/executors/bounded-exec/hang-diagnostics.js +125 -47
  60. package/dist/executors/bounded-exec/lease-wait.d.ts +1 -0
  61. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -1
  62. package/dist/executors/bounded-exec/lease-wait.js +1 -0
  63. package/dist/executors/bounded-exec/mbx-pool.d.ts +42 -7
  64. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  65. package/dist/executors/bounded-exec/mbx-pool.js +45 -8
  66. package/dist/executors/bounded-exec/mbx-reservations.d.ts +12 -6
  67. package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
  68. package/dist/executors/bounded-exec/mbx-reservations.js +190 -284
  69. package/dist/executors/bounded-exec/parent-grant.d.ts +2 -0
  70. package/dist/executors/bounded-exec/parent-grant.d.ts.map +1 -1
  71. package/dist/executors/bounded-exec/parent-grant.js +1 -0
  72. package/dist/executors/bounded-exec/pool-admission.d.ts +29 -3
  73. package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -1
  74. package/dist/executors/bounded-exec/pool-admission.js +47 -1
  75. package/dist/executors/bounded-exec/progress-channel.d.ts +38 -0
  76. package/dist/executors/bounded-exec/progress-channel.d.ts.map +1 -0
  77. package/dist/executors/bounded-exec/progress-channel.js +113 -0
  78. package/dist/executors/bounded-exec/progress.d.ts +5 -1
  79. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  80. package/dist/executors/bounded-exec/progress.js +31 -1
  81. package/dist/executors/bounded-exec/ram-temp.d.ts +24 -1
  82. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  83. package/dist/executors/bounded-exec/ram-temp.js +123 -16
  84. package/dist/executors/bounded-exec/reservation-connection.d.ts +90 -0
  85. package/dist/executors/bounded-exec/reservation-connection.d.ts.map +1 -0
  86. package/dist/executors/bounded-exec/reservation-connection.js +248 -0
  87. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  88. package/dist/executors/bounded-exec/run-cpu-pool.js +3 -0
  89. package/dist/executors/bounded-exec/runner-sizing.d.ts +9 -5
  90. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  91. package/dist/executors/bounded-exec/runner-sizing.js +13 -9
  92. package/dist/executors/bounded-exec/schema.d.ts +7 -2
  93. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  94. package/dist/executors/bounded-exec/schema.js +17 -1
  95. package/dist/executors/bounded-exec/suite-minimum.d.ts +21 -0
  96. package/dist/executors/bounded-exec/suite-minimum.d.ts.map +1 -0
  97. package/dist/executors/bounded-exec/suite-minimum.js +85 -0
  98. package/dist/executors/bounded-exec/test-result-writer.d.ts +2 -0
  99. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -1
  100. package/dist/executors/bounded-exec/test-result-writer.js +1 -0
  101. package/dist/executors/bounded-exec/test-results.d.ts +5 -0
  102. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -1
  103. package/dist/executors/bounded-exec/test-results.js +2 -2
  104. package/dist/executors/bounded-exec/verdict.d.ts +39 -10
  105. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  106. package/dist/executors/bounded-exec/verdict.js +60 -14
  107. package/dist/executors/cargo-zigbuild/executor.d.ts +10 -8
  108. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  109. package/dist/executors/cargo-zigbuild/executor.js +32 -19
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +294 -152
  112. package/dist/managed-files/ci-workflow.d.ts +4 -1
  113. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  114. package/dist/managed-files/ci-workflow.js +9 -14
  115. package/dist/managed-files/files.d.ts +3 -3
  116. package/dist/managed-files/files.js +3 -3
  117. package/dist/managed-files/generator.d.ts +5 -1
  118. package/dist/managed-files/generator.d.ts.map +1 -1
  119. package/dist/managed-files/generator.js +22 -7
  120. package/dist/managed-files/render-memo.d.ts +13 -0
  121. package/dist/managed-files/render-memo.d.ts.map +1 -0
  122. package/dist/managed-files/render-memo.js +94 -0
  123. package/dist/task-results.js +2 -1
  124. package/dist/test-program.d.ts +11 -6
  125. package/dist/test-program.d.ts.map +1 -1
  126. package/dist/test-program.js +39 -35
  127. package/dist/tool-bins.d.ts +12 -0
  128. package/dist/tool-bins.d.ts.map +1 -1
  129. package/dist/tool-bins.js +31 -6
  130. package/dist/typecheck-test-policy.d.ts +10 -1
  131. package/dist/typecheck-test-policy.d.ts.map +1 -1
  132. package/dist/typecheck-test-policy.js +40 -24
  133. package/dist/workspace-config-policy.d.ts.map +1 -1
  134. package/dist/workspace-config-policy.js +135 -42
  135. package/dist/workspace-index.d.ts +14 -1
  136. package/dist/workspace-index.d.ts.map +1 -1
  137. package/dist/workspace-index.js +36 -4
  138. package/executors.json +2 -0
  139. package/managed/raw/envrc +24 -0
  140. package/managed/raw/patches/nx@24.0.3.patch +1851 -221
  141. package/managed/raw/patches/ttsc@0.37.1.patch +1055 -0
  142. package/managed/raw/tooling/direnv/developer-links.ts +122 -14
  143. package/managed/raw/tooling/direnv/devenv.smoo.nix +20 -19
  144. package/managed/templates/github/actions/save-nix-devenv/action.yml +19 -1
  145. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  146. package/package.json +68 -11
  147. package/runtime/nx-publish/.build-inputs.json +2 -2
  148. package/runtime/nx-publish/cache_adapter.js +293 -3
  149. package/runtime/nx-publish/nx_publish.js +36 -14
  150. package/src/built-output-packages.ts +1 -1
  151. package/src/bun-lock-scope.ts +293 -40
  152. package/src/cargo-closure-input.ts +20 -12
  153. package/src/cargo-source-hash.ts +119 -145
  154. package/src/cargo-toolchain-paths.ts +2 -2
  155. package/src/cargo-workspace.ts +59 -21
  156. package/src/ensure-built-receipt.ts +3 -2
  157. package/src/eslint-config-closure.ts +27 -6
  158. package/src/executors/bounded-exec/admission-queue.ts +11 -10
  159. package/src/executors/bounded-exec/awake-clock.ts +20 -0
  160. package/src/executors/bounded-exec/bounds.ts +41 -19
  161. package/src/executors/bounded-exec/case-gate.ts +365 -0
  162. package/src/executors/bounded-exec/cpu-pool-thread.ts +3 -3
  163. package/src/executors/bounded-exec/cpu-pool.ts +139 -12
  164. package/src/executors/bounded-exec/cpu-rise.ts +156 -0
  165. package/src/executors/bounded-exec/endpoint-life.ts +279 -0
  166. package/src/executors/bounded-exec/executor.ts +341 -123
  167. package/src/executors/bounded-exec/gateway-lease.ts +6 -0
  168. package/src/executors/bounded-exec/go-run-summary.ts +137 -0
  169. package/src/executors/bounded-exec/hang-diagnostics.ts +150 -50
  170. package/src/executors/bounded-exec/lease-wait.ts +1 -0
  171. package/src/executors/bounded-exec/mbx-pool.ts +57 -9
  172. package/src/executors/bounded-exec/mbx-reservations.ts +216 -183
  173. package/src/executors/bounded-exec/parent-grant.ts +3 -0
  174. package/src/executors/bounded-exec/pool-admission.ts +59 -2
  175. package/src/executors/bounded-exec/progress-channel.ts +129 -0
  176. package/src/executors/bounded-exec/progress.ts +39 -3
  177. package/src/executors/bounded-exec/ram-temp.ts +137 -17
  178. package/src/executors/bounded-exec/reservation-connection.ts +221 -0
  179. package/src/executors/bounded-exec/run-cpu-pool.ts +2 -0
  180. package/src/executors/bounded-exec/runner-sizing.ts +13 -8
  181. package/src/executors/bounded-exec/schema.json +1 -1
  182. package/src/executors/bounded-exec/schema.ts +21 -2
  183. package/src/executors/bounded-exec/suite-minimum.ts +81 -0
  184. package/src/executors/bounded-exec/test-result-writer.ts +3 -0
  185. package/src/executors/bounded-exec/test-results.ts +5 -0
  186. package/src/executors/bounded-exec/verdict.ts +83 -22
  187. package/src/executors/cargo-zigbuild/executor.ts +30 -19
  188. package/src/index.ts +357 -166
  189. package/src/managed-files/ci-workflow.ts +13 -17
  190. package/src/managed-files/files.ts +3 -3
  191. package/src/managed-files/generator.ts +21 -6
  192. package/src/managed-files/render-memo.ts +135 -0
  193. package/src/test-program.ts +36 -41
  194. package/src/tool-bins.ts +35 -6
  195. package/src/typecheck-test-policy.ts +49 -24
  196. package/src/workspace-config-policy.ts +161 -43
  197. package/src/workspace-index.ts +40 -5
  198. package/test-timings.json +157 -141
  199. package/managed/raw/patches/ttsc@0.36.3.patch +0 -1660
@@ -0,0 +1,279 @@
1
+ import typia from 'typia';
2
+ import { REAP_MS } from './lease-wait.js';
3
+
4
+ /**
5
+ * The life of an Nx run's mbx reservation endpoint in the run that started it (mbx-reservations.ts;
6
+ * specs/cowshed/05_gateway.md, "Parallelism inside a job"), as a state machine over what the run can observe of its
7
+ * child. Pure: no I/O, no clock and no timer. The shell maps the child's and the probe's events into `EndpointEvent`s
8
+ * and executes the `EndpointEffect`s each step answers, in their order; it decides nothing.
9
+ *
10
+ * The run waits in four phases, each for events only:
11
+ *
12
+ * - `starting`, for the child's first line on its standard output, or its end. `listening` opens the probe; any other
13
+ * line is refused and the child killed. A child whose standard output ends without a line can say none: its start
14
+ * is refused, by how it ended when it ends within the reap bound, and it is killed when it does not.
15
+ * - `probing`, for the endpoint's answer to `{"type":"capabilities"}` on the probe's connection, or that connection's
16
+ * end: whether the installed mbx's shim gates test cases (05_gateway.md, "A case starts on a core"). The start is
17
+ * then answered served, which publishes the socket to the run's tasks. A child that ends first is refused by how it
18
+ * ended: no task is told of an endpoint that is gone.
19
+ * - `serving`, for the run's end. A child that ends first is `gone`, and the run's end says how.
20
+ * - `ending`, for the child's end once a pipe of it closed (its standard input by the run, its standard output by
21
+ * itself) or it was killed, with the reap timer armed.
22
+ *
23
+ * The start is answered once (`serve` or `refuse`) and a served endpoint's end once (`conclude`); `ended` takes no
24
+ * event.
25
+ */
26
+ export type EndpointLife =
27
+ | { readonly phase: 'starting'; readonly out: string; readonly said: string; readonly pid: number | undefined }
28
+ | { readonly phase: 'probing'; readonly reply: string; readonly said: string; readonly pid: number | undefined }
29
+ | { readonly phase: 'serving'; readonly said: string; readonly pid: number | undefined }
30
+ | { readonly phase: 'gone'; readonly ended: Ended }
31
+ | {
32
+ readonly phase: 'ending';
33
+ readonly pid: number | undefined;
34
+ readonly said: string;
35
+ /** Whether the child was sent SIGKILL; otherwise a pipe of it closed and its end is awaited. */
36
+ readonly killed: boolean;
37
+ /**
38
+ * Why its start is refused; null for a served endpoint ending with its run. An unkilled child that ends is
39
+ * refused by how it ended instead, which says more.
40
+ */
41
+ readonly refusing: string | null;
42
+ }
43
+ | { readonly phase: 'ended' };
44
+
45
+ /** How a served endpoint ended, and whether that was its ordinary end: status 0 with nothing said, unkilled. */
46
+ export interface Ended {
47
+ readonly how: string;
48
+ readonly clean: boolean;
49
+ }
50
+
51
+ /** What the shell observes. `run-end` is the run's own: its `postTasksExecution`, or a held run's question answered. */
52
+ export type EndpointEvent =
53
+ | { readonly type: 'stdout'; readonly text: string }
54
+ | { readonly type: 'stdout-end' }
55
+ | { readonly type: 'stderr'; readonly text: string }
56
+ /** Node's `error` of the child: it could not be spawned. */
57
+ | { readonly type: 'error'; readonly message: string }
58
+ /** Node's `close` of the child: it has exited and its pipes have ended. */
59
+ | { readonly type: 'close'; readonly code: number | null; readonly signal: string | null }
60
+ | { readonly type: 'probe'; readonly text: string }
61
+ /** The probe's connection ended or failed. */
62
+ | { readonly type: 'probe-end' }
63
+ | { readonly type: 'run-end' }
64
+ /** The reap timer the last `arm` started has run out. */
65
+ | { readonly type: 'expired' };
66
+
67
+ /** What the shell does. `refuse` and `conclude` remove the socket's directory before they answer. */
68
+ export type EndpointEffect =
69
+ /** Connect to the endpoint's socket and send it `{"type":"capabilities"}`. */
70
+ | { readonly do: 'probe' }
71
+ /** End the probe's connection. */
72
+ | { readonly do: 'hang-up' }
73
+ /** Answer the start: the endpoint serves, and its mbx gates test cases or does not. */
74
+ | { readonly do: 'serve'; readonly gates: boolean }
75
+ /** Answer the start: no endpoint, and why. */
76
+ | { readonly do: 'refuse'; readonly why: string }
77
+ | { readonly do: 'close-stdin' }
78
+ | { readonly do: 'kill' }
79
+
80
+ /** Stop the child and its pipes from keeping the run alive, without signalling it again. */
81
+ | { readonly do: 'unref-child' }
82
+ | { readonly do: 'arm'; readonly ms: number }
83
+ | { readonly do: 'disarm' }
84
+ /** Answer the run's end. */
85
+ | { readonly do: 'conclude'; readonly ended: Ended };
86
+
87
+ export type EndpointStep = readonly [EndpointLife, readonly EndpointEffect[]];
88
+
89
+ /** What is kept of the endpoint's stderr to say why it ended: its last bytes. */
90
+ const SAID_BYTES = 4096;
91
+
92
+ /** The life of a child just spawned; `pid` is what names it should it not end when killed. */
93
+ export function spawned(pid: number | undefined): EndpointLife {
94
+ return { phase: 'starting', out: '', said: '', pid };
95
+ }
96
+ const ENDED: EndpointLife = { phase: 'ended' };
97
+
98
+ type CapabilitiesReply = { type: 'capabilities'; test_gate: boolean };
99
+ const parseCapabilities = typia.json.createValidateParse<CapabilitiesReply>();
100
+
101
+ /**
102
+ * Whether the mbx that answered `line` to `{"type":"capabilities"}` gates test cases. One that does not know the
103
+ * request answers an error, which gates nothing.
104
+ */
105
+ /**
106
+ * Whether the mbx that answered `line` to `{"type":"capabilities"}` gates test cases. One that does not know the
107
+ * request answers an error, which gates nothing, and so does a line that is no JSON: typia's parse validates what
108
+ * `JSON.parse` returns and throws what it throws.
109
+ */
110
+ export function gatesTests(line: string): boolean {
111
+ try {
112
+ const reply = parseCapabilities(line);
113
+ return reply.success && reply.data.test_gate;
114
+ } catch {
115
+ return false;
116
+ }
117
+ }
118
+
119
+ /** `text` up to its first line break, or null while it holds none. */
120
+ function firstLine(text: string): string | null {
121
+ const end = text.indexOf('\n');
122
+ return end === -1 ? null : text.slice(0, end);
123
+ }
124
+
125
+ function saying(said: string, text: string): string {
126
+ return (said + text).slice(-SAID_BYTES);
127
+ }
128
+
129
+ function closed(said: string, code: number | null, signal: string | null): Ended {
130
+ const last = said.trim().split('\n').at(-1) ?? '';
131
+ return {
132
+ how: `mbx reservations ended ${signal === null ? `with status ${code}` : `on ${signal}`}${last === '' ? '' : `: ${last}`}`,
133
+ clean: signal === null && code === 0 && last === '',
134
+ };
135
+ }
136
+
137
+ function unspawned(message: string): Ended {
138
+ return { how: `mbx reservations could not run: ${message}`, clean: false };
139
+ }
140
+
141
+ /** How the child ended, when `event` is its end. */
142
+ function endOf(said: string, event: EndpointEvent): Ended | null {
143
+ if (event.type === 'close') return closed(said, event.code, event.signal);
144
+ if (event.type === 'error') return unspawned(event.message);
145
+ return null;
146
+ }
147
+
148
+ /** The next state of `life` at `event`, and what the shell does about it. */
149
+ export function endpointStep(life: EndpointLife, event: EndpointEvent): EndpointStep {
150
+ switch (life.phase) {
151
+ case 'starting':
152
+ return starting(life, event);
153
+ case 'probing':
154
+ return probing(life, event);
155
+ case 'serving':
156
+ return serving(life, event);
157
+ case 'gone':
158
+ return event.type === 'run-end' ? [ENDED, [{ do: 'conclude', ended: life.ended }]] : [life, []];
159
+ case 'ending':
160
+ return ending(life, event);
161
+ case 'ended':
162
+ return [life, []];
163
+ }
164
+ }
165
+
166
+ function unanswered(phase: string): never {
167
+ throw new Error(
168
+ `the run's end reached its endpoint while ${phase}: the run holds no endpoint before its start is answered`,
169
+ );
170
+ }
171
+
172
+ function starting(life: EndpointLife & { phase: 'starting' }, event: EndpointEvent): EndpointStep {
173
+ const ended = endOf(life.said, event);
174
+ if (ended !== null) return [ENDED, [{ do: 'refuse', why: ended.how }]];
175
+ switch (event.type) {
176
+ case 'stderr':
177
+ return [{ ...life, said: saying(life.said, event.text) }, []];
178
+ case 'stdout': {
179
+ const out = life.out + event.text;
180
+ const line = firstLine(out);
181
+ if (line === null) return [{ ...life, out }, []];
182
+ if (line === 'listening') {
183
+ return [{ phase: 'probing', reply: '', said: life.said, pid: life.pid }, [{ do: 'probe' }]];
184
+ }
185
+ return [
186
+ {
187
+ phase: 'ending',
188
+ pid: life.pid,
189
+ said: life.said,
190
+ killed: true,
191
+ refusing: `mbx reservations said ${JSON.stringify(line)}, not that it was listening`,
192
+ },
193
+ [{ do: 'kill' }, { do: 'arm', ms: REAP_MS }],
194
+ ];
195
+ }
196
+ case 'stdout-end': {
197
+ const unsaid = `mbx reservations closed its standard output ${life.out === '' ? '' : `after ${JSON.stringify(life.out)}, `}without saying it was listening`;
198
+ return [
199
+ { phase: 'ending', pid: life.pid, said: life.said, killed: false, refusing: unsaid },
200
+ [{ do: 'arm', ms: REAP_MS }],
201
+ ];
202
+ }
203
+ case 'run-end':
204
+ return unanswered(life.phase);
205
+ default:
206
+ return [life, []];
207
+ }
208
+ }
209
+
210
+ function probing(life: EndpointLife & { phase: 'probing' }, event: EndpointEvent): EndpointStep {
211
+ const served: EndpointLife = { phase: 'serving', said: life.said, pid: life.pid };
212
+ const ended = endOf(life.said, event);
213
+ if (ended !== null) return [ENDED, [{ do: 'hang-up' }, { do: 'refuse', why: ended.how }]];
214
+ switch (event.type) {
215
+ case 'stderr':
216
+ return [{ ...life, said: saying(life.said, event.text) }, []];
217
+ case 'probe': {
218
+ const reply = life.reply + event.text;
219
+ const line = firstLine(reply);
220
+ if (line === null) return [{ ...life, reply }, []];
221
+ return [served, [{ do: 'hang-up' }, { do: 'serve', gates: gatesTests(line) }]];
222
+ }
223
+ case 'probe-end':
224
+ return [served, [{ do: 'serve', gates: false }]];
225
+ case 'run-end':
226
+ return unanswered(life.phase);
227
+ default:
228
+ return [life, []];
229
+ }
230
+ }
231
+
232
+ function serving(life: EndpointLife & { phase: 'serving' }, event: EndpointEvent): EndpointStep {
233
+ const ended = endOf(life.said, event);
234
+ if (ended !== null) return [{ phase: 'gone', ended }, []];
235
+ switch (event.type) {
236
+ case 'stderr':
237
+ return [{ ...life, said: saying(life.said, event.text) }, []];
238
+ case 'run-end':
239
+ return [
240
+ { phase: 'ending', said: life.said, pid: life.pid, killed: false, refusing: null },
241
+ [{ do: 'close-stdin' }, { do: 'arm', ms: REAP_MS }],
242
+ ];
243
+ default:
244
+ return [life, []];
245
+ }
246
+ }
247
+
248
+ function ending(life: EndpointLife & { phase: 'ending' }, event: EndpointEvent): EndpointStep {
249
+ const ended = endOf(life.said, event);
250
+ if (ended !== null) {
251
+ if (life.refusing !== null) {
252
+ return [ENDED, [{ do: 'disarm' }, { do: 'refuse', why: life.killed ? life.refusing : ended.how }]];
253
+ }
254
+ const outlived: Ended = life.killed
255
+ ? { how: `${ended.how}, killed after it outlived its standard input by ${REAP_MS}ms`, clean: false }
256
+ : ended;
257
+ return [ENDED, [{ do: 'disarm' }, { do: 'conclude', ended: outlived }]];
258
+ }
259
+ switch (event.type) {
260
+ case 'stderr':
261
+ return [{ ...life, said: saying(life.said, event.text) }, []];
262
+ case 'expired': {
263
+ // A closed pipe did not end it within the reap bound: kill it, and wait that bound once more.
264
+ if (!life.killed) {
265
+ const refusing = life.refusing === null ? null : `${life.refusing}, and had not ended ${REAP_MS}ms later`;
266
+ return [{ ...life, killed: true, refusing }, [{ do: 'kill' }, { do: 'arm', ms: REAP_MS }]];
267
+ }
268
+ // Neither did the kill: it is stuck in the kernel, or something it started holds its pipes. The wait ends and
269
+ // says so; the child is left as it is (05_gateway.md, "A child's exit and its output are reap-class waits").
270
+ const left = `${life.pid === undefined ? 'it' : `pid ${life.pid}`} had not ended ${REAP_MS}ms after it was killed and is left as it is`;
271
+ if (life.refusing !== null)
272
+ return [ENDED, [{ do: 'unref-child' }, { do: 'refuse', why: `${life.refusing}; ${left}` }]];
273
+ const how = `mbx reservations outlived its standard input by ${REAP_MS}ms; ${left}`;
274
+ return [ENDED, [{ do: 'unref-child' }, { do: 'conclude', ended: { how, clean: false } }]];
275
+ }
276
+ default:
277
+ return [life, []];
278
+ }
279
+ }