@smoothbricks/nx-plugin 0.5.0 → 0.5.2

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 (79) hide show
  1. package/README.md +107 -46
  2. package/dist/bin/smoo-nx-test-clocks.js +2 -2
  3. package/dist/bin/smoo-nx-test-walks.js +6 -9
  4. package/dist/cargo-closure-input.d.ts.map +1 -1
  5. package/dist/cargo-closure-input.js +25 -15
  6. package/dist/ensure-built-witness.d.ts +33 -5
  7. package/dist/ensure-built-witness.d.ts.map +1 -1
  8. package/dist/ensure-built-witness.js +84 -18
  9. package/dist/ensure-built.d.ts.map +1 -1
  10. package/dist/ensure-built.js +33 -14
  11. package/dist/executors/bounded-exec/cpu-pool.d.ts +14 -7
  12. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  13. package/dist/executors/bounded-exec/cpu-pool.js +297 -38
  14. package/dist/executors/bounded-exec/cpu-tokens.d.ts +19 -7
  15. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
  16. package/dist/executors/bounded-exec/cpu-tokens.js +21 -7
  17. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  18. package/dist/executors/bounded-exec/executor.js +12 -6
  19. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  20. package/dist/executors/bounded-exec/run-cpu-pool.js +5 -4
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +4 -0
  23. package/dist/owned-installation.d.ts +6 -5
  24. package/dist/owned-installation.d.ts.map +1 -1
  25. package/dist/owned-installation.js +324 -201
  26. package/dist/producer-receipts.d.ts +10 -0
  27. package/dist/producer-receipts.d.ts.map +1 -1
  28. package/dist/producer-receipts.js +30 -5
  29. package/dist/test-walk-policy.d.ts +8 -0
  30. package/dist/test-walk-policy.d.ts.map +1 -1
  31. package/dist/test-walk-policy.js +34 -0
  32. package/dist/workspace-manifest.d.ts +5 -5
  33. package/dist/workspace-manifest.d.ts.map +1 -1
  34. package/managed/raw/patches/nx@23.2.1.patch +14 -3
  35. package/managed/raw/tooling/direnv/developer-links.ts +37 -10
  36. package/managed/raw/tooling/direnv/devenv.smoo.nix +1 -3
  37. package/managed/raw/tooling/direnv/linked-snapshots.ts +49 -12
  38. package/managed/raw/tooling/direnv/repo-path +1 -1
  39. package/managed/raw/tooling/direnv/setup-environment.ts +2 -0
  40. package/managed/raw/tooling/git-hooks/pre-push.sh +34 -11
  41. package/package.json +3 -3
  42. package/runtime-input.sh +21 -9
  43. package/src/__tests__/cargo-closure-filesets.ts +94 -0
  44. package/src/__tests__/counted-cargo.ts +1 -1
  45. package/src/__tests__/owned-installation.ts +5 -6
  46. package/src/bin/smoo-nx-test-clocks.ts +2 -2
  47. package/src/bin/smoo-nx-test-walks.ts +6 -9
  48. package/src/cargo-closure-filesets.test.ts +63 -0
  49. package/src/cargo-closure-input.test.ts +2 -2
  50. package/src/cargo-closure-input.ts +23 -15
  51. package/src/cargo-closure-key.test.ts +1 -1
  52. package/src/cargo-resolve-cache.test.ts +1 -1
  53. package/src/cross-check-policy.test.ts +53 -12
  54. package/src/ensure-built-witness.test.ts +53 -2
  55. package/src/ensure-built-witness.ts +103 -18
  56. package/src/ensure-built.test.ts +79 -5
  57. package/src/ensure-built.ts +51 -15
  58. package/src/executors/bounded-exec/cpu-pool.test.ts +132 -4
  59. package/src/executors/bounded-exec/cpu-pool.ts +300 -46
  60. package/src/executors/bounded-exec/cpu-tokens.test.ts +60 -15
  61. package/src/executors/bounded-exec/cpu-tokens.ts +34 -11
  62. package/src/executors/bounded-exec/executor.test.ts +72 -4
  63. package/src/executors/bounded-exec/executor.ts +12 -6
  64. package/src/executors/bounded-exec/run-cpu-pool.test.ts +3 -0
  65. package/src/executors/bounded-exec/run-cpu-pool.ts +5 -4
  66. package/src/index.ts +4 -0
  67. package/src/linked-snapshots.nx.test.ts +1 -1
  68. package/src/nextest-partitions.test.ts +1 -1
  69. package/src/nx-daemon-validity.test.ts +51 -0
  70. package/src/owned-installation.test.ts +105 -0
  71. package/src/owned-installation.ts +335 -93
  72. package/src/producer-receipts.test.ts +37 -15
  73. package/src/producer-receipts.ts +29 -5
  74. package/src/runtime-input.test.ts +22 -1
  75. package/src/task-results.test.ts +1 -1
  76. package/src/test-walk-policy.test.ts +35 -0
  77. package/src/test-walk-policy.ts +32 -0
  78. package/src/workspace-manifest.ts +5 -5
  79. package/test-timings.json +94 -92
@@ -3,9 +3,12 @@ import * as _jsonStringifyNumber_1 from "typia/lib/internal/_jsonStringifyNumber
3
3
  import * as _jsonStringifyString_1 from "typia/lib/internal/_jsonStringifyString";
4
4
  import * as _jsonStringifyTail_1 from "typia/lib/internal/_jsonStringifyTail";
5
5
  import * as _throwTypeGuardError_1 from "typia/lib/internal/_throwTypeGuardError";
6
+ import { execFile } from 'node:child_process';
7
+ import { closeSync, constants, openSync, readSync, writeSync } from 'node:fs';
6
8
  import { chmod, rm } from 'node:fs/promises';
7
- import { createServer } from 'node:net';
9
+ import { createServer, Socket } from 'node:net';
8
10
  import { join } from 'node:path';
11
+ import { promisify } from 'node:util';
9
12
  import typia from 'typia';
10
13
  import { ownedSocketDirectory } from '../../testing.js';
11
14
  import { CPU_TOKENS_ENV, parseInheritedTokens } from './cpu-tokens.js';
@@ -21,22 +24,43 @@ import { holdLease } from './gateway-lease.js';
21
24
  * its FIFO queue. A grant lasts while its connection does, so a child that dies returns its tokens
22
25
  * with its socket. A pool grants only from its own count, and a pool whose upstream grant has gone
23
26
  * grants nothing.
27
+ *
28
+ * The same count is a GNU make jobserver fifo beside the socket, mode 0600, which Cargo, its build
29
+ * scripts and every nested `cargo` read through `CARGO_MAKEFLAGS`/`MAKEFLAGS` (specs/cowshed/05_gateway.md,
30
+ * "The jobserver fifo"). A pool of `g` holds `g − 1` token bytes there; the holder's own command holds the
31
+ * implicit first token. A socket grant takes fifo bytes first and that implicit slot last, which the holder
32
+ * is not using while it waits on the child it lends it to; release writes the bytes back and frees the slot.
33
+ * A Cargo reading the fifo and a nested runner holding a socket grant so share one count.
24
34
  */
25
35
  /** The environment name a child reads its parent's pool endpoint from; its count is `CPU_TOKENS_ENV`. */
26
36
  export const CPU_POOL_ENV = 'BOUNDED_EXEC_CPU_POOL';
27
- const parseRequest = (() => {
28
- const _io0 = input => "cpu-pool" === input.op && ("number" === typeof input.want && (_isTypeUint32_1._isTypeUint32(input.want) && 1 <= input.want)) && (undefined === input.children || "boolean" === typeof input.children) && (undefined === input.grow || "boolean" === typeof input.grow);
29
- const _io1 = input => "host-wait" === input.op;
30
- const _iu0 = input => (() => {
37
+ /** Exactly a request's fields, as the gateway's own pools read them: any other field is an invalid request. */
38
+ const isRequest = (() => {
39
+ const _io0 = (input, _exceptionable = true) => "cpu-pool" === input.op && ("number" === typeof input.want && (_isTypeUint32_1._isTypeUint32(input.want) && 1 <= input.want)) && (undefined === input.children || "boolean" === typeof input.children) && (2 === Object.keys(input).length || Object.keys(input).every(key => {
40
+ if (["op", "want", "children"].some(prop => key === prop))
41
+ return true;
42
+ const value = input[key];
43
+ if (undefined === value)
44
+ return true;
45
+ return false;
46
+ }));
47
+ const _io1 = (input, _exceptionable = true) => "host-wait" === input.op && (1 === Object.keys(input).length || Object.keys(input).every(key => {
48
+ if (["op"].some(prop => key === prop))
49
+ return true;
50
+ const value = input[key];
51
+ if (undefined === value)
52
+ return true;
53
+ return false;
54
+ }));
55
+ const _iu0 = (input, _exceptionable = true) => (() => {
31
56
  if ("cpu-pool" === input.op)
32
- return _io0(input);
57
+ return _io0(input, true && _exceptionable);
33
58
  else if ("host-wait" === input.op)
34
- return _io1(input);
59
+ return _io1(input, true && _exceptionable);
35
60
  else
36
61
  return false;
37
62
  })();
38
- const __is = input => "object" === typeof input && null !== input && _iu0(input);
39
- return input => { input = JSON.parse(input); return __is(input) ? input : null; };
63
+ return (input, _exceptionable = true) => "object" === typeof input && null !== input && _iu0(input, true);
40
64
  })();
41
65
  const stringifyReply = (() => {
42
66
  const _ip0 = input => true === input["ok"];
@@ -74,7 +98,12 @@ const TOO_LONG = `a request is one line of at most ${MAX_REQUEST_BYTES} bytes`;
74
98
  const EMPTY = Buffer.alloc(0);
75
99
  const POOL_DIRECTORY = 'cpu-pool-';
76
100
  const POOL_SOCKET = 'p.sock';
101
+ /** The jobserver fifo's name beside the socket; the directory's random name is what makes the path unguessable. */
102
+ const POOL_FIFO = 'j';
103
+ /** The byte make's protocol writes for a token. Any byte read is one token; the pool writes this one back. */
104
+ const TOKEN = 0x2b;
77
105
  const CLOSED_WHILE_MADE = 'the grant that lends this CPU pool closed while the pool was being made';
106
+ const run = promisify(execFile);
78
107
  /** One framed reply line. The newline is the framing; every reply goes through here. */
79
108
  const frame = (reply) => `${stringifyReply(reply)}\n`;
80
109
  /**
@@ -131,11 +160,142 @@ export async function takeParentCpuTokens(parent, want) {
131
160
  }
132
161
  return { granted: true, tokens, release: lease.release, closed: lease.closed, inherited: true };
133
162
  }
163
+ /** A thrown value's message. */
164
+ const describe = (error) => (error instanceof Error ? error.message : String(error));
165
+ /** Write `count` token bytes to the fifo's descriptor; a short write throws. The fifo holds a pipe buffer of them. */
166
+ function writeTokens(fd, count) {
167
+ if (count === 0) {
168
+ return;
169
+ }
170
+ const written = writeSync(fd, Buffer.alloc(count, TOKEN));
171
+ if (written !== count) {
172
+ throw new Error(`it took ${written} of ${count} token bytes`);
173
+ }
174
+ }
175
+ /** Up to `most` token bytes read from the fifo's non-blocking descriptor: 0 when it is empty. */
176
+ function readTokens(fd, into, most) {
177
+ try {
178
+ return readSync(fd, into, 0, Math.min(most, into.length), null);
179
+ }
180
+ catch (error) {
181
+ const code = error instanceof Error && 'code' in error ? error.code : undefined;
182
+ if (code === 'EAGAIN' || code === 'EWOULDBLOCK') {
183
+ return 0;
184
+ }
185
+ throw error;
186
+ }
187
+ }
188
+ /**
189
+ * Make the jobserver fifo at `path`, mode 0600, holding `bytes` tokens. Node has no mkfifo, so the system's `mkfifo`
190
+ * makes it. The pool keeps it open read-write and non-blocking: the fifo always has a writer, so its bytes outlive
191
+ * every client that opens and closes it, and the pool's own reads and writes never block.
192
+ */
193
+ async function makeJobserverFifo(path, bytes) {
194
+ try {
195
+ await run('mkfifo', ['-m', '600', path]);
196
+ }
197
+ catch (error) {
198
+ return { ok: false, error: `the CPU pool's jobserver fifo could not be made: ${describe(error)}` };
199
+ }
200
+ let fd;
201
+ try {
202
+ fd = openSync(path, constants.O_RDWR | constants.O_NONBLOCK);
203
+ }
204
+ catch (error) {
205
+ return { ok: false, error: `the CPU pool's jobserver fifo could not be opened: ${describe(error)}` };
206
+ }
207
+ try {
208
+ writeTokens(fd, bytes);
209
+ }
210
+ catch (error) {
211
+ const failure = `the CPU pool's jobserver fifo did not take its ${bytes} tokens: ${describe(error)}`;
212
+ try {
213
+ closeSync(fd);
214
+ }
215
+ catch (closing) {
216
+ return { ok: false, error: `${failure}; its descriptor did not close: ${describe(closing)}` };
217
+ }
218
+ return { ok: false, error: failure };
219
+ }
220
+ return { ok: true, fd };
221
+ }
222
+ function isBunFileStreams(runtime) {
223
+ return typeof runtime === 'object' && runtime !== null && 'file' in runtime && typeof runtime.file === 'function';
224
+ }
225
+ const bunRuntime = Reflect.get(globalThis, 'Bun');
226
+ /** Bun's file streams when this process runs on Bun, else null (Node). */
227
+ const bunFiles = isBunFileStreams(bunRuntime) ? bunRuntime : null;
228
+ /**
229
+ * Wait, event-driven, for token bytes in the fifo at `path`: no polling loop and no blocking read on the threadpool.
230
+ * A fresh non-blocking read descriptor is watched by the runtime's event loop. Every byte it reads is taken from the
231
+ * fifo and reaches `took` as tokens in hand, also after `stop`; `stop` leaves unread bytes in the fifo.
232
+ *
233
+ * Node watches the descriptor as a libuv pipe stream (`net.Socket({ fd })`). Bun's `node:net` never reads a fifo, and
234
+ * its `tty` and `fs` read streams leave a blocking read behind that takes the next token after they are destroyed
235
+ * (measured on Bun 1.4.3), so on Bun the wait reads through `Bun.file(fd).stream()`, which polls the descriptor and
236
+ * leaves the fifo untouched when cancelled.
237
+ */
238
+ function watchFifo(path, took, failed) {
239
+ let fd;
240
+ try {
241
+ fd = openSync(path, constants.O_RDONLY | constants.O_NONBLOCK);
242
+ }
243
+ catch (error) {
244
+ return { ok: false, error: describe(error) };
245
+ }
246
+ if (bunFiles !== null) {
247
+ const reader = bunFiles.file(fd).stream().getReader();
248
+ let stopped = false;
249
+ const next = () => {
250
+ void reader.read().then((chunk) => {
251
+ if (chunk.done) {
252
+ return;
253
+ }
254
+ took(chunk.value.byteLength);
255
+ if (!stopped)
256
+ next();
257
+ }, (error) => {
258
+ if (!stopped)
259
+ failed(describe(error));
260
+ });
261
+ };
262
+ next();
263
+ const release = () => {
264
+ try {
265
+ closeSync(fd);
266
+ }
267
+ catch (error) {
268
+ failed(`its watch descriptor did not close: ${describe(error)}`);
269
+ }
270
+ };
271
+ return {
272
+ ok: true,
273
+ watch: {
274
+ stop: () => {
275
+ stopped = true;
276
+ void reader.cancel().then(release, release);
277
+ },
278
+ },
279
+ };
280
+ }
281
+ let reader;
282
+ try {
283
+ reader = new Socket({ fd, readable: true, writable: false });
284
+ }
285
+ catch (error) {
286
+ closeSync(fd);
287
+ return { ok: false, error: describe(error) };
288
+ }
289
+ reader.on('data', (chunk) => took(chunk.length));
290
+ reader.on('error', (error) => failed(error.message));
291
+ // Destroying the stream closes its descriptor and stops its reads at once.
292
+ return { ok: true, watch: { stop: () => reader.destroy() } };
293
+ }
134
294
  /**
135
295
  * Make a pool of `tokens` that lives while `closed` does: when `closed` resolves the pool refuses
136
- * grants, ends its child connections and removes its directory. A child's `host-wait` is reported
137
- * to `waits` for as long as its connection holds it; a sub-pool reports to the same `waits`.
138
- * Setup failures are values; a non-positive or unsafe count is a programmer bug and throws.
296
+ * grants, ends its child connections, drains its jobserver fifo and removes its directory. A child's
297
+ * `host-wait` is reported to `waits` for as long as its connection holds it; a sub-pool reports to the
298
+ * same `waits`. Setup failures are values; a non-positive or unsafe count is a programmer bug and throws.
139
299
  */
140
300
  export async function createCpuPool(tokens, closed, waits) {
141
301
  if (!Number.isSafeInteger(tokens) || tokens < 1) {
@@ -146,13 +306,27 @@ export async function createCpuPool(tokens, closed, waits) {
146
306
  directory = await ownedSocketDirectory(POOL_DIRECTORY, POOL_SOCKET);
147
307
  }
148
308
  catch (error) {
149
- return {
150
- ok: false,
151
- error: `the CPU pool's directory could not be made: ${error instanceof Error ? error.message : String(error)}`,
152
- };
309
+ return { ok: false, error: `the CPU pool's directory could not be made: ${describe(error)}` };
153
310
  }
154
311
  const socketPath = join(directory, POOL_SOCKET);
155
- let free = tokens;
312
+ const fifoPath = join(directory, POOL_FIFO);
313
+ const fifo = await makeJobserverFifo(fifoPath, tokens - 1);
314
+ if (!fifo.ok) {
315
+ try {
316
+ await rm(directory, { recursive: true, force: true });
317
+ }
318
+ catch (error) {
319
+ return { ok: false, error: `${fifo.error}; its directory was not removed: ${describe(error)}` };
320
+ }
321
+ return { ok: false, error: fifo.error };
322
+ }
323
+ const jobserver = fifo.fd;
324
+ // The pool reads at most what it holds at once: the fifo carries no more of its tokens than that.
325
+ const scratch = Buffer.allocUnsafe(tokens);
326
+ // The holder's implicit first token, while a socket child holds it.
327
+ let slotLent = false;
328
+ // The readability wait while the queue's head finds no token, else undefined.
329
+ let watch;
156
330
  let closing = false;
157
331
  let listening = false;
158
332
  let shut;
@@ -167,21 +341,75 @@ export async function createCpuPool(tokens, closed, waits) {
167
341
  const started = new Promise((done) => {
168
342
  resolveStarted = done;
169
343
  });
170
- // FIFO: the head takes `min(want, free)` as one grant once any token is free. A waiting child holds
171
- // nothing, so no child waits while it holds tokens another child needs.
172
- const drain = () => {
173
- while (!closing && free > 0) {
174
- const waiter = queue.shift();
344
+ // A fault in the pool's own fifo, said and recorded; the pool then closes, as on a listener failure.
345
+ const fail = (failure) => {
346
+ failures.push(failure);
347
+ process.stderr.write(`bounded-exec: the CPU pool at ${socketPath} failed: ${failure}\n`);
348
+ closeInBackground();
349
+ };
350
+ const returnTokens = (count) => {
351
+ try {
352
+ writeTokens(jobserver, count);
353
+ }
354
+ catch (error) {
355
+ fail(`its jobserver fifo did not take back ${count} tokens: ${describe(error)}`);
356
+ }
357
+ };
358
+ const stopWatching = () => {
359
+ watch?.stop();
360
+ watch = undefined;
361
+ };
362
+ // The head found no token: wake when a holder outside the pool, such as Cargo, writes one back.
363
+ const watchForTokens = () => {
364
+ if (watch !== undefined) {
365
+ return;
366
+ }
367
+ const watching = watchFifo(fifoPath, drain, (error) => fail(`its jobserver fifo failed while a child waited for a token: ${error}`));
368
+ if (watching.ok) {
369
+ watch = watching.watch;
370
+ }
371
+ else {
372
+ fail(`its jobserver fifo could not be watched for a token: ${watching.error}`);
373
+ }
374
+ };
375
+ // FIFO: the head takes `min(want, available)` as one grant once any token is available, where available is the
376
+ // fifo bytes it can read without blocking plus the implicit slot while no child holds it. `arrived` is bytes the
377
+ // readability wait already took. A waiting child holds nothing, so no child waits while it holds tokens another
378
+ // child needs. Whatever bytes are in hand when no head can use them go straight back to the fifo.
379
+ function drain(arrived) {
380
+ let inHand = arrived;
381
+ while (!closing) {
382
+ const waiter = queue[0];
175
383
  if (waiter === undefined) {
176
- return;
384
+ break;
177
385
  }
178
386
  if (!waiter.child.socket.writable) {
179
387
  // A child that half-closed or failed while queued. Its `close` finds it gone from the queue.
388
+ queue.shift();
180
389
  continue;
181
390
  }
182
- const granted = Math.min(waiter.want, free);
183
- free -= granted;
184
- waiter.child.phase = { kind: 'holding', tokens: granted };
391
+ if (inHand < waiter.want) {
392
+ try {
393
+ inHand += readTokens(jobserver, scratch, waiter.want - inHand);
394
+ }
395
+ catch (error) {
396
+ fail(`its jobserver fifo could not be read: ${describe(error)}`);
397
+ return;
398
+ }
399
+ }
400
+ const granted = Math.min(waiter.want, inHand + (slotLent ? 0 : 1));
401
+ if (granted === 0) {
402
+ watchForTokens();
403
+ return;
404
+ }
405
+ queue.shift();
406
+ // Fifo bytes first, the implicit slot last.
407
+ const bytes = Math.min(granted, inHand);
408
+ inHand -= bytes;
409
+ const slot = granted > bytes;
410
+ if (slot)
411
+ slotLent = true;
412
+ waiter.child.phase = { kind: 'holding', bytes, slot };
185
413
  if (!waiter.children) {
186
414
  waiter.child.socket.write(frame({ ok: true, lease: 'granted', tokens: granted }));
187
415
  continue;
@@ -212,7 +440,10 @@ export async function createCpuPool(tokens, closed, waits) {
212
440
  creating ??= [];
213
441
  creating.push(creation);
214
442
  }
215
- };
443
+ stopWatching();
444
+ if (!closing)
445
+ returnTokens(inHand);
446
+ }
216
447
  const refuse = (child, error) => {
217
448
  child.phase = { kind: 'done' };
218
449
  child.socket.end(frame({ ok: false, code: 'invalid-request', error }));
@@ -236,13 +467,17 @@ export async function createCpuPool(tokens, closed, waits) {
236
467
  }
237
468
  }
238
469
  else if (child.phase.kind === 'holding') {
239
- free += child.phase.tokens;
470
+ // A closing pool drains its fifo whole; until then the bytes go back for the next holder.
471
+ if (child.phase.slot)
472
+ slotLent = false;
473
+ if (!closing)
474
+ returnTokens(child.phase.bytes);
240
475
  }
241
476
  else if (child.phase.kind === 'waiting') {
242
477
  waits.end();
243
478
  }
244
479
  child.phase = { kind: 'done' };
245
- drain();
480
+ drain(0);
246
481
  });
247
482
  let buffered = EMPTY;
248
483
  // Refusing releases what the connection buffered: a refused request holds no storage.
@@ -284,20 +519,20 @@ export async function createCpuPool(tokens, closed, waits) {
284
519
  }
285
520
  const line = buffered.subarray(0, newline).toString('utf8');
286
521
  buffered = EMPTY;
287
- let request;
522
+ let parsed;
288
523
  try {
289
- request = parseRequest(line);
524
+ parsed = JSON.parse(line);
290
525
  }
291
526
  catch (error) {
292
- // isParse returns null for a wrong shape, but JSON syntax errors still throw.
293
527
  if (!(error instanceof SyntaxError))
294
528
  throw error;
295
- request = null;
529
+ parsed = undefined;
296
530
  }
297
- if (request === null) {
531
+ if (!isRequest(parsed)) {
298
532
  refuse(child, 'a request is {"op":"cpu-pool","want":<a whole number of tokens, at least 1>} or {"op":"host-wait"}');
299
533
  return;
300
534
  }
535
+ const request = parsed;
301
536
  if (request.op === 'host-wait') {
302
537
  // Counted from here until the connection closes, which `close` reports however it ends.
303
538
  child.phase = { kind: 'waiting' };
@@ -308,7 +543,7 @@ export async function createCpuPool(tokens, closed, waits) {
308
543
  child.phase = { kind: 'queued' };
309
544
  queue.push({ child, want: request.want, children: request.children === true });
310
545
  socket.write(frame({ ok: true, lease: 'queued' }));
311
- drain();
546
+ drain(0);
312
547
  });
313
548
  };
314
549
  const server = createServer(serve);
@@ -317,6 +552,7 @@ export async function createCpuPool(tokens, closed, waits) {
317
552
  const shutdown = () => {
318
553
  shut ??= (async () => {
319
554
  closing = true;
555
+ stopWatching();
320
556
  await started;
321
557
  for (const socket of children) {
322
558
  socket.destroy();
@@ -340,11 +576,27 @@ export async function createCpuPool(tokens, closed, waits) {
340
576
  failures.push(outcome.error);
341
577
  }
342
578
  }
579
+ // The fifo's bytes are drained before it goes: a Cargo that outlives the pool keeps its descriptor and the tokens
580
+ // it holds, and takes no more.
581
+ try {
582
+ let drained = readTokens(jobserver, scratch, scratch.length);
583
+ while (drained > 0)
584
+ drained = readTokens(jobserver, scratch, scratch.length);
585
+ }
586
+ catch (error) {
587
+ failures.push(`its jobserver fifo was not drained: ${describe(error)}`);
588
+ }
589
+ try {
590
+ closeSync(jobserver);
591
+ }
592
+ catch (error) {
593
+ failures.push(`its jobserver fifo did not close: ${describe(error)}`);
594
+ }
343
595
  try {
344
596
  await rm(directory, { recursive: true, force: true });
345
597
  }
346
598
  catch (error) {
347
- failures.push(`its directory was not removed: ${error instanceof Error ? error.message : String(error)}`);
599
+ failures.push(`its directory was not removed: ${describe(error)}`);
348
600
  }
349
601
  return failures.length === 0
350
602
  ? { ok: true }
@@ -393,15 +645,22 @@ export async function createCpuPool(tokens, closed, waits) {
393
645
  await chmod(socketPath, 0o600);
394
646
  }
395
647
  catch (error) {
396
- return abort(`the CPU pool's socket could not be made private: ${error instanceof Error ? error.message : String(error)}`);
648
+ return abort(`the CPU pool's socket could not be made private: ${describe(error)}`);
397
649
  }
398
650
  if (closing) {
399
651
  return abort(CLOSED_WHILE_MADE);
400
652
  }
653
+ // Cargo and make read the fifo from here; `-j` with a jobserver names no count of its own.
654
+ const jobserverFlags = `-j --jobserver-auth=fifo:${fifoPath}`;
401
655
  return {
402
656
  ok: true,
403
657
  pool: {
404
- environment: { [CPU_POOL_ENV]: socketPath, [CPU_TOKENS_ENV]: String(tokens) },
658
+ environment: {
659
+ [CPU_POOL_ENV]: socketPath,
660
+ [CPU_TOKENS_ENV]: String(tokens),
661
+ CARGO_MAKEFLAGS: jobserverFlags,
662
+ MAKEFLAGS: jobserverFlags,
663
+ },
405
664
  close: shutdown,
406
665
  },
407
666
  };
@@ -25,19 +25,27 @@ export type RunnerKind =
25
25
  /** Anything else, one `bun test` process included: one process unless it declares more. */
26
26
  | 'process';
27
27
  /**
28
- * What a runner asks the budget for. Cargo also carries its independent test-thread ceiling; cargo-mutants carries
29
- * how many cargo processes it runs at once, which share its grant.
28
+ * The inherited ceilings, lowered by configuration, of test threads, which take no make jobserver token: libtest's
29
+ * `RUST_TEST_THREADS` and nextest's `NEXTEST_TEST_THREADS`. Null where neither environment names one.
30
+ */
31
+ export interface TestThreadCeilings {
32
+ readonly rust: number | null;
33
+ readonly nextest: number | null;
34
+ }
35
+ /**
36
+ * What a runner asks the budget for. A cargo build, and a process whose script may start Cargo, carry the test-thread
37
+ * ceilings their sizing keeps; cargo-mutants carries how many cargo processes it runs at once, which share its grant.
30
38
  */
31
39
  export type Demand = {
32
- kind: 'cargo';
40
+ kind: 'cargo' | 'process';
33
41
  want: number;
34
- testThreads: number | null;
42
+ testThreads: TestThreadCeilings;
35
43
  } | {
36
44
  kind: 'cargo-mutants';
37
45
  want: number;
38
46
  jobs: number;
39
47
  } | {
40
- kind: Exclude<RunnerKind, 'cargo' | 'cargo-mutants'>;
48
+ kind: Exclude<RunnerKind, 'cargo' | 'cargo-mutants' | 'process'>;
41
49
  want: number;
42
50
  };
43
51
  /** Every budgeted command learns its grant here, so a script that starts a runner can size it. */
@@ -55,8 +63,12 @@ type WorkerFlagKind = 'stryker' | 'vitest' | 'go-test';
55
63
  */
56
64
  export declare function runnerDemand(command: string, declared: number | undefined, cores: number, inherited: Readonly<NodeJS.ProcessEnv>, configured?: Readonly<NodeJS.ProcessEnv>): Demand;
57
65
  /**
58
- * Size the runner to the lesser of its bounded demand and grant, retaining Cargo's test-thread ceiling.
59
- * Rewrite named flags so they cannot outrank that ceiling. `CPU_TOKENS_ENV` still reports the actual held grant.
66
+ * Size the runner to the lesser of its bounded demand and grant, keeping the test-thread ceilings. Rewrite named flags
67
+ * so they cannot outrank that size. `CPU_TOKENS_ENV` still reports the actual held grant.
68
+ *
69
+ * Cargo's rustc count is the pool's: the executor's sub-pool exports its jobserver fifo, so no `CARGO_BUILD_JOBS`
70
+ * comes from the grant (specs/cowshed/05_gateway.md, "The jobserver fifo"). Test threads take no jobserver token, so a
71
+ * cargo build's test threads are its size, and a process's, whose script may start Cargo, are its whole held grant.
60
72
  */
61
73
  export declare function sizeRunner(demand: Demand, command: string, tokens: number): {
62
74
  command: string;
@@ -1 +1 @@
1
- {"version":3,"file":"cpu-tokens.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/cpu-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnF;;;;;;;;;;GAUG;AAEH,kGAAkG;AAClG,MAAM,MAAM,UAAU;AACpB,mFAAmF;AACjF,SAAS;AACX,mDAAmD;GACjD,cAAc;AAChB,2EAA2E;GACzE,cAAc;AAChB,yHAAyH;GACvH,eAAe;AACjB,kGAAkG;GAChG,OAAO;AACT,2FAA2F;GACzF,SAAS,CAAC;AAEd;;;GAGG;AACH,MAAM,MAAM,MAAM,GACd;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM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runnerDemand(command, declared, cores, inherited, configured) {
69
69
  const want = Math.max(1, Math.min(requested, ceiling ?? requested));
70
70
  switch (kind) {
71
71
  case 'cargo':
72
- return { kind, want, testThreads: inheritedCeiling(inherited.RUST_TEST_THREADS, configured?.RUST_TEST_THREADS) };
72
+ case 'process':
73
+ return {
74
+ kind,
75
+ want,
76
+ testThreads: {
77
+ rust: inheritedCeiling(inherited.RUST_TEST_THREADS, configured?.RUST_TEST_THREADS),
78
+ nextest: inheritedCeiling(inherited.NEXTEST_TEST_THREADS, configured?.NEXTEST_TEST_THREADS),
79
+ },
80
+ };
73
81
  case 'cargo-mutants':
74
82
  return { kind, want, jobs };
75
83
  default:
@@ -181,8 +189,12 @@ function withSizedFlag(command, invocation, flag, sized, add) {
181
189
  return `${command.slice(0, end)}${sizedArgs}${command.slice(argsEnd)}`;
182
190
  }
183
191
  /**
184
- * Size the runner to the lesser of its bounded demand and grant, retaining Cargo's test-thread ceiling.
185
- * Rewrite named flags so they cannot outrank that ceiling. `CPU_TOKENS_ENV` still reports the actual held grant.
192
+ * Size the runner to the lesser of its bounded demand and grant, keeping the test-thread ceilings. Rewrite named flags
193
+ * so they cannot outrank that size. `CPU_TOKENS_ENV` still reports the actual held grant.
194
+ *
195
+ * Cargo's rustc count is the pool's: the executor's sub-pool exports its jobserver fifo, so no `CARGO_BUILD_JOBS`
196
+ * comes from the grant (specs/cowshed/05_gateway.md, "The jobserver fifo"). Test threads take no jobserver token, so a
197
+ * cargo build's test threads are its size, and a process's, whose script may start Cargo, are its whole held grant.
186
198
  */
187
199
  export function sizeRunner(demand, command, tokens) {
188
200
  const runnerCount = Math.min(tokens, demand.want);
@@ -197,14 +209,18 @@ export function sizeRunner(demand, command, tokens) {
197
209
  case 'bun-parallel':
198
210
  return { command: command.replace(BUN_PARALLEL, `--parallel=${count}`), env: { [CPU_TOKENS_ENV]: held } };
199
211
  case 'cargo':
212
+ case 'process': {
213
+ const threads = demand.kind === 'cargo' ? runnerCount : tokens;
214
+ const { rust, nextest } = demand.testThreads;
200
215
  return {
201
216
  command,
202
217
  env: {
203
218
  [CPU_TOKENS_ENV]: held,
204
- CARGO_BUILD_JOBS: count,
205
- RUST_TEST_THREADS: String(Math.min(runnerCount, demand.testThreads ?? runnerCount)),
219
+ RUST_TEST_THREADS: String(Math.min(threads, rust ?? threads)),
220
+ NEXTEST_TEST_THREADS: String(Math.min(threads, nextest ?? threads)),
206
221
  },
207
222
  };
223
+ }
208
224
  case 'stryker':
209
225
  case 'vitest':
210
226
  case 'go-test': {
@@ -231,8 +247,6 @@ export function sizeRunner(demand, command, tokens) {
231
247
  },
232
248
  };
233
249
  }
234
- case 'process':
235
- return { command, env: { [CPU_TOKENS_ENV]: held } };
236
250
  }
237
251
  }
238
252
  /** A configured value may lower an inherited ceiling, never raise it. */
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/executor.ts"],"names":[],"mappings":"AAMA,OAAO,EAKL,KAAK,gBAAgB,EAGtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,sBAAsB,EAAmB,MAAM,uBAAuB,CAAC;AAGhF,OAAO,EAML,aAAa,EAEd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAEL,KAAK,eAAe,EAarB,MAAM,cAAc,CAAC;AAiBtB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,wFAAwF;IACxF,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,uFAAuF;IACvF,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED,qEAAqE;AACrE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE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AAM,EAAE,iBAAiB,EACzB,UAAU,EAAE,UAAU,GAAG,IAAI,EAC7B,MAAM,EAAE,SAAS,GAAG,IAAI,EACxB,SAAS,GAAE,gBAAgB,GAAG,IAAW,EACzC,kBAAkB,GAAE,OAAO,sBAA+C,GACzE,OAAO,CAAC,iBAAiB,CAAC,CA8iB5B;AAED,wBAAgB,uBAAuB,IAAI,iBAAiB,CAM3D"}
@@ -17,8 +17,14 @@ const EXIT_CODE_BY_SIGNAL = {
17
17
  SIGINT: 130,
18
18
  SIGTERM: 143,
19
19
  };
20
- /** The variables the CPU budget sets for the command it grants: no target's environment may set them. */
21
- const BUDGET_ENV = [CPU_TOKENS_ENV, CPU_POOL_ENV];
20
+ /** The pool descriptor: only a grant may give it, so neither the target's nor the inherited environment passes it on. */
21
+ const POOL_ENV = [CPU_TOKENS_ENV, CPU_POOL_ENV];
22
+ /**
23
+ * The variables the CPU budget sets for the command it grants: no target's environment may set them. A jobserver the
24
+ * executor itself inherits, a parent make's, still reaches an ungranted command by Cargo's own rule; a granted one's
25
+ * sub-pool names its own fifo over it.
26
+ */
27
+ const BUDGET_ENV = [...POOL_ENV, 'CARGO_MAKEFLAGS', 'MAKEFLAGS', 'MFLAGS'];
22
28
  /** Workspace-provided cowshed launchers, in the order a workspace that provides one names them. */
23
29
  const WORKSPACE_COWSHED_LAUNCHERS = [
24
30
  'packages/cowshed/bin/cowshed',
@@ -682,13 +688,13 @@ function buildCommand(options) {
682
688
  }
683
689
  /** The lease's directory is the command's TMPDIR unless the target names one itself. */
684
690
  function mergeEnv(lease, env) {
685
- const inherited = withoutBudgetEnv(process.env);
691
+ const inherited = withoutPoolEnv(process.env);
686
692
  return lease === null ? { ...inherited, ...env } : { ...inherited, TMPDIR: lease.directory, ...env };
687
693
  }
688
- /** The process's environment without the CPU budget's variables: a pool and its count only a grant may give. */
689
- function withoutBudgetEnv(env) {
694
+ /** The process's environment without the CPU pool's descriptor: a pool and its count only a grant may give. */
695
+ function withoutPoolEnv(env) {
690
696
  const kept = { ...env };
691
- for (const name of BUDGET_ENV) {
697
+ for (const name of POOL_ENV) {
692
698
  delete kept[name];
693
699
  }
694
700
  return kept;
@@ -1 +1 @@
1
- {"version":3,"file":"run-cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/run-cpu-pool.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAsBtH;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,EAC7C,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,OAAO,GAAE,MAAuB,EAChC,KAAK,GAAE,MAA+B,GACrC,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,uEAAuE;AACvE,wBAAsB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnG"}
1
+ {"version":3,"file":"run-cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/run-cpu-pool.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAuBtH;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,EAC7C,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,OAAO,GAAE,MAAuB,EAChC,KAAK,GAAE,MAA+B,GACrC,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,uEAAuE;AACvE,wBAAsB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnG"}