@smoothbricks/nx-plugin 0.4.29 → 0.4.31

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 (110) hide show
  1. package/README.md +104 -25
  2. package/dist/bin/smoo-nx-test-clocks.d.ts +3 -0
  3. package/dist/bin/smoo-nx-test-clocks.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-test-clocks.js +28 -0
  5. package/dist/bounded-test-policy.d.ts +1 -8
  6. package/dist/bounded-test-policy.d.ts.map +1 -1
  7. package/dist/bounded-test-policy.js +2 -8
  8. package/dist/cargo-closure-input.d.ts +11 -0
  9. package/dist/cargo-closure-input.d.ts.map +1 -1
  10. package/dist/cargo-closure-input.js +16 -6
  11. package/dist/ensure-built-receipt.d.ts +8 -2
  12. package/dist/ensure-built-receipt.d.ts.map +1 -1
  13. package/dist/ensure-built-receipt.js +45 -13
  14. package/dist/ensure-built-witness.d.ts +40 -4
  15. package/dist/ensure-built-witness.d.ts.map +1 -1
  16. package/dist/ensure-built-witness.js +68 -15
  17. package/dist/ensure-built.d.ts.map +1 -1
  18. package/dist/ensure-built.js +11 -3
  19. package/dist/executors/bounded-exec/cpu-pool.d.ts +7 -3
  20. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  21. package/dist/executors/bounded-exec/cpu-pool.js +9 -4
  22. package/dist/executors/bounded-exec/cpu-tokens.d.ts +22 -5
  23. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/cpu-tokens.js +189 -18
  25. package/dist/executors/bounded-exec/executor.d.ts +1 -1
  26. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  27. package/dist/executors/bounded-exec/executor.js +38 -14
  28. package/dist/executors/bounded-exec/no-space.d.ts +8 -0
  29. package/dist/executors/bounded-exec/no-space.d.ts.map +1 -0
  30. package/dist/executors/bounded-exec/no-space.js +31 -0
  31. package/dist/executors/bounded-exec/ram-temp.d.ts +3 -0
  32. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  33. package/dist/executors/bounded-exec/ram-temp.js +15 -4
  34. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +10 -0
  35. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -0
  36. package/dist/executors/bounded-exec/run-cpu-pool.js +63 -0
  37. package/dist/executors/bounded-exec/verdict.d.ts +34 -4
  38. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  39. package/dist/executors/bounded-exec/verdict.js +54 -3
  40. package/dist/graph-input-contract.d.ts +4 -0
  41. package/dist/graph-input-contract.d.ts.map +1 -1
  42. package/dist/graph-input-contract.js +17 -4
  43. package/dist/index.d.ts +3 -1
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +13 -3
  46. package/dist/owned-installation.d.ts +14 -0
  47. package/dist/owned-installation.d.ts.map +1 -0
  48. package/dist/owned-installation.js +324 -0
  49. package/dist/producer-receipts.d.ts.map +1 -1
  50. package/dist/producer-receipts.js +15 -10
  51. package/dist/test-backstop.d.ts +9 -0
  52. package/dist/test-backstop.d.ts.map +1 -0
  53. package/dist/test-backstop.js +10 -0
  54. package/dist/test-clock-policy.d.ts +30 -0
  55. package/dist/test-clock-policy.d.ts.map +1 -0
  56. package/dist/test-clock-policy.js +686 -0
  57. package/dist/testing.d.ts.map +1 -1
  58. package/dist/testing.js +8 -1
  59. package/managed/raw/tooling/direnv/developer-links.ts +1 -8
  60. package/managed/raw/tooling/direnv/setup-environment.ts +13 -1
  61. package/package.json +15 -4
  62. package/src/__tests__/cargo-closure-fixture.ts +113 -0
  63. package/src/__tests__/counted-cargo.ts +8 -25
  64. package/src/__tests__/directory-change.ts +27 -0
  65. package/src/__tests__/owned-installation.ts +4 -164
  66. package/src/__tests__/past-tick.ts +12 -0
  67. package/src/bin/smoo-nx-test-clocks.ts +29 -0
  68. package/src/bounded-test-policy.ts +2 -8
  69. package/src/cargo-closure-input.property.test.ts +50 -0
  70. package/src/cargo-closure-input.test.ts +15 -112
  71. package/src/cargo-closure-input.ts +23 -6
  72. package/src/cargo-closure-key.test.ts +240 -0
  73. package/src/cargo-resolve-cache.test.ts +29 -7
  74. package/src/ensure-built-receipt.ts +56 -13
  75. package/src/ensure-built-witness.test.ts +113 -4
  76. package/src/ensure-built-witness.ts +75 -16
  77. package/src/ensure-built.test.ts +74 -2
  78. package/src/ensure-built.ts +13 -2
  79. package/src/executors/bounded-exec/cpu-pool.test.ts +18 -0
  80. package/src/executors/bounded-exec/cpu-pool.ts +10 -4
  81. package/src/executors/bounded-exec/cpu-tokens.test.ts +205 -0
  82. package/src/executors/bounded-exec/cpu-tokens.ts +229 -22
  83. package/src/executors/bounded-exec/disk-lease.test.ts +47 -13
  84. package/src/executors/bounded-exec/executor-host.test.ts +23 -11
  85. package/src/executors/bounded-exec/executor.test.ts +189 -63
  86. package/src/executors/bounded-exec/executor.ts +39 -13
  87. package/src/executors/bounded-exec/hang-diagnostics.test.ts +14 -8
  88. package/src/executors/bounded-exec/no-space.ts +40 -0
  89. package/src/executors/bounded-exec/ram-temp-host.test.ts +9 -8
  90. package/src/executors/bounded-exec/ram-temp.test.ts +32 -18
  91. package/src/executors/bounded-exec/ram-temp.ts +17 -4
  92. package/src/executors/bounded-exec/run-cpu-pool.test.ts +76 -0
  93. package/src/executors/bounded-exec/run-cpu-pool.ts +75 -0
  94. package/src/executors/bounded-exec/verdict.test.ts +125 -25
  95. package/src/executors/bounded-exec/verdict.ts +78 -3
  96. package/src/graph-input-contract.test.ts +8 -0
  97. package/src/graph-input-contract.ts +26 -4
  98. package/src/index.test.ts +12 -2
  99. package/src/index.ts +13 -3
  100. package/src/nextest-extraction.test.ts +114 -4
  101. package/src/nx-daemon-claim.test.ts +5 -3
  102. package/src/nx-daemon-idle-policy.test.ts +22 -18
  103. package/src/nx-daemon-validity.test.ts +5 -13
  104. package/src/owned-installation.ts +174 -0
  105. package/src/producer-receipts.ts +15 -10
  106. package/src/test-backstop.ts +11 -0
  107. package/src/test-clock-policy.test.ts +338 -0
  108. package/src/test-clock-policy.ts +708 -0
  109. package/src/testing.ts +8 -1
  110. package/test-timings.json +4 -0
@@ -3,8 +3,10 @@ import { spawnSync } from 'node:child_process';
3
3
  import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises';
4
4
  import { tmpdir } from 'node:os';
5
5
  import { dirname, join } from 'node:path';
6
+ import fc from 'fast-check';
6
7
 
7
8
  import { onProgressClock } from '../../__tests__/progress-clock.js';
9
+ import { BOUNDED_TEST_IDLE_TIMEOUT_MS } from '../../bounded-test-policy.js';
8
10
  import {
9
11
  type BoundedExecContext,
10
12
  createProcessTreeKiller,
@@ -14,6 +16,7 @@ import {
14
16
  import type { BoundedExecBounds } from './schema.js';
15
17
  import {
16
18
  type BoundedExecVerdict,
19
+ describeVerdict,
17
20
  failedTasksOfRun,
18
21
  JUNIT_FILE,
19
22
  judgeOperationalFailure,
@@ -87,15 +90,20 @@ async function verdictOf(
87
90
  return record?.verdict;
88
91
  }
89
92
 
90
- // The fixtures run in child processes and must really outlive their runner's bound: the verdict
91
- // is about which real bound fired, so no fake clock can stand in for it.
92
- const SLOW_TEST = `import { test } from 'bun:test';\ntest('slow', async () => { await new Promise((r) => setTimeout(r, 5000)); });\n`;
93
+ // The fixtures run in child processes and must really meet their runner's per-test bound: the verdict is about which
94
+ // real bound fired. The slow test never finishes, so nothing can beat that bound; the parent's own required ceiling is
95
+ // the leg's backstop, so it cannot end the run first however long `bun test` takes to start on a loaded host.
96
+ const SLOW_TEST = `import { test } from 'bun:test';\ntest('slow', () => new Promise(() => {}));\n`;
93
97
  const FAILING_TEST = `import { expect, test } from 'bun:test';\ntest('wrong', () => { expect(1).toBe(2); });\n`;
94
98
 
95
99
  describe('bounded-exec verdicts', () => {
96
100
  it('records a bun run whose only failure is a per-test timeout as a bound', async () => {
97
101
  expect(
98
- await verdictOf('bun test --timeout=100 ./slow.test.ts', { timeoutMs: 60_000 }, { 'slow.test.ts': SLOW_TEST }),
102
+ await verdictOf(
103
+ 'bun test --timeout=100 ./slow.test.ts',
104
+ { timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
105
+ { 'slow.test.ts': SLOW_TEST },
106
+ ),
99
107
  ).toEqual({
100
108
  outcome: 'bound',
101
109
  bound: 'test',
@@ -107,7 +115,7 @@ describe('bounded-exec verdicts', () => {
107
115
  expect(
108
116
  await verdictOf(
109
117
  '.runtime/bun test --timeout=100 ./slow.test.ts',
110
- { timeoutMs: 60_000 },
118
+ { timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
111
119
  { 'slow.test.ts': SLOW_TEST },
112
120
  { '.runtime/bun': process.execPath },
113
121
  ),
@@ -118,19 +126,21 @@ describe('bounded-exec verdicts', () => {
118
126
  expect(
119
127
  await verdictOf(
120
128
  'bun test --timeout=100 ./slow.test.ts ./failing.test.ts',
121
- { timeoutMs: 60_000 },
129
+ { timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
122
130
  { 'slow.test.ts': SLOW_TEST, 'failing.test.ts': FAILING_TEST },
123
131
  ),
124
132
  ).toEqual({ outcome: 'failed', exitCode: 1, tests: ['wrong'] });
125
133
  });
126
134
 
127
135
  it('records the total bound as a bound and the progress bound as a wedge', async () => {
128
- expect(await verdictOf('node -e "setInterval(() => console.log(1), 10)"', { timeoutMs: 200 })).toMatchObject({
136
+ // Each command holds on its stdin, which bounded-exec keeps open and never writes: it never exits, so only the
137
+ // bound under test can end it.
138
+ expect(await verdictOf('node -e "process.stdin.resume()"', { timeoutMs: 200 })).toMatchObject({
129
139
  outcome: 'bound',
130
140
  bound: 'total',
131
141
  limitMs: 200,
132
142
  });
133
- expect(await verdictOf('node -e "setTimeout(() => {}, 30000)"', { idleTimeoutMs: 100 })).toMatchObject({
143
+ expect(await verdictOf('node -e "process.stdin.resume()"', { idleTimeoutMs: 100 })).toMatchObject({
134
144
  outcome: 'wedged',
135
145
  idleMs: 100,
136
146
  tests: [],
@@ -174,22 +184,51 @@ describe('bounded-exec verdicts', () => {
174
184
  elapsedMs: 900,
175
185
  expiry: { kind: 'idle', limitMs: 400, tests: ['nt tests::hangs'] },
176
186
  report,
187
+ noSpace: null,
177
188
  }),
178
189
  ).toEqual({ outcome: 'wedged', idleMs: 400, elapsedMs: 900, tests: ['nt tests::hangs', 'nt tests::young'] });
179
190
  });
180
191
 
192
+ it('records a failed run whose output said ENOSPC as out of space, ahead of the tests and the bound that followed', () => {
193
+ // From a downstream land gate: a 1 KB write into the task's RAM lease failed, and two tests failed on it.
194
+ const noSpace = {
195
+ line: 'ENOSPC: no space left on device, write',
196
+ volume: {
197
+ lease: '/Volumes/smoo-ram2-502/37738-AadRCN',
198
+ mountpoint: '/Volumes/smoo-ram2-502',
199
+ capacityBytes: 8 * 1024 ** 3,
200
+ freeBytes: 4096,
201
+ },
202
+ };
203
+ const report = { timedOut: [], cancelled: [], failed: ['lsp-differential hover'] };
204
+ const ran = { exitCode: 1, elapsedMs: 11_580, expiry: null, report, noSpace };
205
+ expect(judgeRun(ran)).toEqual({ outcome: 'no-space', exitCode: 1, tests: ['lsp-differential hover'], ...noSpace });
206
+ // A full disk that then hung the run is still the disk.
207
+ const idle = { kind: 'idle', limitMs: 400, tests: ['nt tests::writes'] } as const;
208
+ expect(judgeRun({ ...ran, exitCode: 143, expiry: idle, report: null })).toEqual({
209
+ outcome: 'no-space',
210
+ exitCode: 143,
211
+ tests: [],
212
+ ...noSpace,
213
+ });
214
+ // A passing run that printed it, as a test of ENOSPC handling does, passed.
215
+ expect(judgeRun({ ...ran, exitCode: 0, report: null })).toEqual({ outcome: 'passed' });
216
+ expect(describeVerdict(judgeRun(ran))).toBe(
217
+ 'ENOSPC (no space left on device): the command printed "ENOSPC: no space left on device, write"; its TMPDIR ' +
218
+ '/Volumes/smoo-ram2-502/37738-AadRCN is on the RAM temp volume /Volumes/smoo-ram2-502, which had 0.0 MiB free ' +
219
+ 'of 8192.0 MiB when that line arrived; the tests that then failed: lsp-differential hover',
220
+ );
221
+ });
222
+
181
223
  it('records a failing command with no report as a failure, and a passing one as passed', async () => {
182
- // How an exit is classified, not how soon it comes: the clock is faked and nothing moves it, so the total bound
183
- // cannot end a `node` still starting on a loaded host (a land gate measured 5243 ms for `node -e ""`). The run
184
- // ends only by exiting.
185
- const exiting = (command: string) =>
186
- onProgressClock(
187
- () => false,
188
- 0,
189
- () => verdictOf(command, { timeoutMs: 5_000 }),
190
- );
191
- expect((await exiting('node -e "process.exit(3)"')).result).toEqual({ outcome: 'failed', exitCode: 3, tests: [] });
192
- expect((await exiting('node -e ""')).result).toEqual({ outcome: 'passed' });
224
+ // How an exit is classified, not how soon it comes: the required ceiling is the leg's backstop, so it cannot end a
225
+ // `node` still starting on a loaded host (a land gate measured 5243 ms for `node -e ""` against 5000 ms).
226
+ expect(await verdictOf('node -e "process.exit(3)"', { timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS })).toEqual({
227
+ outcome: 'failed',
228
+ exitCode: 3,
229
+ tests: [],
230
+ });
231
+ expect(await verdictOf('node -e ""', { timeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS })).toEqual({ outcome: 'passed' });
193
232
  });
194
233
 
195
234
  it("reads nextest's typed timeout from its JUnit report", () => {
@@ -236,7 +275,7 @@ ${abort('t::crash', '11 (SIGSEGV)')}
236
275
  it('records a run its ceiling stopped as a bound when the only failures are the tests the stop aborted', () => {
237
276
  const total = { kind: 'total', limitMs: 120_000 } as const;
238
277
  const cut = { timedOut: [], cancelled: ['nt t::cut'], failed: [] };
239
- expect(judgeRun({ exitCode: 143, elapsedMs: 120_850, expiry: total, report: cut })).toEqual({
278
+ expect(judgeRun({ exitCode: 143, elapsedMs: 120_850, expiry: total, report: cut, noSpace: null })).toEqual({
240
279
  outcome: 'bound',
241
280
  bound: 'total',
242
281
  limitMs: 120_000,
@@ -244,9 +283,15 @@ ${abort('t::crash', '11 (SIGSEGV)')}
244
283
  });
245
284
  // An assertion that failed before the ceiling is still a failure, and an abort nobody asked for is one too.
246
285
  expect(
247
- judgeRun({ exitCode: 143, elapsedMs: 120_850, expiry: total, report: { ...cut, failed: ['nt t::assert'] } }),
286
+ judgeRun({
287
+ exitCode: 143,
288
+ elapsedMs: 120_850,
289
+ expiry: total,
290
+ report: { ...cut, failed: ['nt t::assert'] },
291
+ noSpace: null,
292
+ }),
248
293
  ).toEqual({ outcome: 'failed', exitCode: 143, tests: ['nt t::assert'] });
249
- expect(judgeRun({ exitCode: 143, elapsedMs: 850, expiry: null, report: cut })).toEqual({
294
+ expect(judgeRun({ exitCode: 143, elapsedMs: 850, expiry: null, report: cut, noSpace: null })).toEqual({
250
295
  outcome: 'failed',
251
296
  exitCode: 143,
252
297
  tests: ['nt t::cut'],
@@ -257,7 +302,13 @@ ${abort('t::crash', '11 (SIGSEGV)')}
257
302
  const cancelled = ['nt t::cut'];
258
303
  // Exit 0 with an abort in the report: the abort is still not nothing.
259
304
  expect(
260
- judgeRun({ exitCode: 0, elapsedMs: 850, expiry: null, report: { timedOut: [], cancelled, failed: [] } }),
305
+ judgeRun({
306
+ exitCode: 0,
307
+ elapsedMs: 850,
308
+ expiry: null,
309
+ report: { timedOut: [], cancelled, failed: [] },
310
+ noSpace: null,
311
+ }),
261
312
  ).toEqual({
262
313
  outcome: 'failed',
263
314
  exitCode: 0,
@@ -270,6 +321,7 @@ ${abort('t::crash', '11 (SIGSEGV)')}
270
321
  elapsedMs: 850,
271
322
  expiry: null,
272
323
  report: { timedOut: ['nt t::slow'], cancelled, failed: [] },
324
+ noSpace: null,
273
325
  }),
274
326
  ).toEqual({ outcome: 'failed', exitCode: 100, tests: cancelled });
275
327
  // With the total bound fired, the same report is the bound's own casualties.
@@ -279,6 +331,7 @@ ${abort('t::crash', '11 (SIGSEGV)')}
279
331
  elapsedMs: 120_850,
280
332
  expiry: { kind: 'total', limitMs: 120_000 },
281
333
  report: { timedOut: ['nt t::slow'], cancelled, failed: [] },
334
+ noSpace: null,
282
335
  }),
283
336
  ).toMatchObject({ outcome: 'bound', bound: 'total' });
284
337
  });
@@ -311,13 +364,15 @@ process.on('SIGTERM', () => {
311
364
  process.exit(143);
312
365
  });
313
366
  fs.writeFileSync('runner-ready.fifo', 'ready pid=' + process.pid + '\\n');
314
- setInterval(() => console.log('running'), 10);
367
+ process.stdin.resume();
315
368
  `;
316
369
  let armed: Promise<void> | undefined;
317
370
  let report = '';
318
371
  const verdict = await verdictOf(
319
372
  'exec node runner.js',
320
- { timeoutMs: 300, killAfterMs: 5_000 },
373
+ // The total bound is the subject; the grace after it is the leg's backstop, so the run ends by the runner's own
374
+ // exit on SIGTERM, never by a SIGKILL a loaded host's slow handler would have drawn.
375
+ { timeoutMs: 300, killAfterMs: BOUNDED_TEST_IDLE_TIMEOUT_MS },
321
376
  { 'runner.js': runner },
322
377
  {},
323
378
  async (root) => {
@@ -442,4 +497,49 @@ setInterval(() => console.log('running'), 10);
442
497
  { task: 'd:lint', bound: false, reason: 'no bounded-exec verdict' },
443
498
  ]);
444
499
  });
500
+
501
+ it('judges a run that exits inside its total bound by its exit alone, however far the injected clock moved', async () => {
502
+ // The clock is faked: it moves once, when the command reports, by a generated amount short of the total bound, and
503
+ // then the command exits. Below the bound the verdict is a function of the exit, never of how long a loaded host
504
+ // took to get there (a land gate measured 5243 ms for `node -e ""` under a 5000 ms bound). The step is at least
505
+ // 1 ms: Bun 1.4.3's `advanceTimersByTime(0)` moves the fake clock 1 ms, and a run that never moves it is the case
506
+ // above. The command prints its report through `printf`, so the line naming the command never matches it.
507
+ const reported = 'bounded-exec-property-reported';
508
+ await fc.assert(
509
+ fc.asyncProperty(
510
+ fc.integer({ min: 2, max: 600_000 }).chain((timeoutMs) =>
511
+ fc.record({
512
+ timeoutMs: fc.constant(timeoutMs),
513
+ elapsedMs: fc.integer({ min: 1, max: timeoutMs - 1 }),
514
+ killAfterMs: fc.integer({ min: 0, max: timeoutMs }),
515
+ exitCode: fc.integer({ min: 0, max: 125 }),
516
+ }),
517
+ ),
518
+ async ({ timeoutMs, elapsedMs, killAfterMs, exitCode }) => {
519
+ const { context } = await workspace();
520
+ const { movedMs } = await onProgressClock(
521
+ (chunk) => chunk.includes(reported),
522
+ elapsedMs,
523
+ () =>
524
+ runBoundedExec(
525
+ {
526
+ command: `printf '%s-%s\\n' bounded-exec property-reported; exit ${exitCode}`,
527
+ timeoutMs,
528
+ killAfterMs,
529
+ },
530
+ context,
531
+ createProcessTreeKiller(),
532
+ null,
533
+ null,
534
+ ),
535
+ );
536
+ expect(movedMs).toBe(elapsedMs);
537
+ expect((await readRecord(context.record?.directory ?? ''))?.verdict).toEqual(
538
+ exitCode === 0 ? { outcome: 'passed' } : { outcome: 'failed', exitCode, tests: [] },
539
+ );
540
+ },
541
+ ),
542
+ { numRuns: 40 },
543
+ );
544
+ });
445
545
  });
@@ -12,6 +12,9 @@ import { join } from 'node:path';
12
12
  * tests, so this is a hang, not a slow host, and the fix is the opposite one, so it is never a `bound`. It names
13
13
  * the tests still running: those the runner said were running and never said finished, and those its report says
14
14
  * it aborted when the bound stopped it.
15
+ * - `no-space`: the run failed and its output said a write found no space (ENOSPC). Whatever its tests then reported,
16
+ * they failed on the disk, not on their own: the verdict names the line that said so and, when the task held one,
17
+ * its RAM temp volume as it stood when that line arrived.
15
18
  * - `failed`: anything else that did not pass. That includes an assertion named in the report,
16
19
  * or a non-zero exit with no report to say why.
17
20
  */
@@ -25,8 +28,23 @@ export type BoundedExecVerdict =
25
28
  readonly elapsedMs: number;
26
29
  readonly tests: readonly string[];
27
30
  }
31
+ | ({ readonly outcome: 'no-space'; readonly exitCode: number; readonly tests: readonly string[] } & NoSpaceSighting)
28
32
  | { readonly outcome: 'failed'; readonly exitCode: number; readonly tests: readonly string[] };
29
33
 
34
+ /** The task's RAM temp volume, read when a line saying ENOSPC arrived: the writer's own lease, and the space left. */
35
+ export interface TempVolumeSpace {
36
+ readonly lease: string;
37
+ readonly mountpoint: string;
38
+ readonly capacityBytes: number;
39
+ readonly freeBytes: number;
40
+ }
41
+
42
+ /** The first output line that said a write found no space, and the task's RAM temp volume then; `null` without one. */
43
+ export interface NoSpaceSighting {
44
+ readonly line: string;
45
+ readonly volume: TempVolumeSpace | null;
46
+ }
47
+
30
48
  /** One task's verdict, keyed by the Nx task and the hash it ran at. */
31
49
  export interface BoundedExecRecord {
32
50
  readonly task: string;
@@ -184,14 +202,23 @@ export interface RunEnd {
184
202
  readonly expiry: ExpiredBound | null;
185
203
  /** The run's report, or `null` when the command was asked for none or wrote none. */
186
204
  readonly report: JunitFailures | null;
205
+ /** The first output line that said ENOSPC, or `null` when none did. */
206
+ readonly noSpace: NoSpaceSighting | null;
187
207
  }
188
208
 
189
209
  /**
190
- * Judge a run. A test that failed on its own is a failure even when a bound fired too, and the no-progress bound is
191
- * never load: the report's assertions and the idle bound are read first. A test the runner aborted because the total
192
- * bound told its command to stop is not one that failed; one it aborted at the idle bound is a test still running.
210
+ * Judge a run. A run that failed after its output said ENOSPC failed on the disk: that is read first, ahead of the
211
+ * tests it then failed, a bound it then hit or a hang the full disk caused; a passing run that printed it (a test of
212
+ * its own ENOSPC handling) passed. A test that failed on its own is a failure even when a bound fired too, and the
213
+ * no-progress bound is never load: the report's assertions and the idle bound are read next. A test the runner aborted
214
+ * because the total bound told its command to stop is not one that failed; one it aborted at the idle bound is a test
215
+ * still running.
193
216
  */
194
217
  export function judgeRun(run: RunEnd): BoundedExecVerdict {
218
+ if (run.noSpace !== null && (run.exitCode !== 0 || run.expiry !== null)) {
219
+ const tests = run.report === null ? [] : [...run.report.failed, ...run.report.timedOut, ...run.report.cancelled];
220
+ return { outcome: 'no-space', exitCode: run.exitCode === 0 ? 1 : run.exitCode, tests, ...run.noSpace };
221
+ }
195
222
  if (run.expiry?.kind === 'idle') {
196
223
  const tests = [...new Set([...run.expiry.tests, ...(run.report?.cancelled ?? [])])];
197
224
  return { outcome: 'wedged', idleMs: run.expiry.limitMs, elapsedMs: run.elapsedMs, tests };
@@ -352,6 +379,19 @@ function parseVerdict(value: unknown): BoundedExecVerdict {
352
379
  return { outcome: 'wedged', idleMs: value.idleMs, elapsedMs: value.elapsedMs, tests: value.tests };
353
380
  }
354
381
  break;
382
+ case 'no-space': {
383
+ const volume = parseTempVolumeSpace(value.volume);
384
+ if (typeof value.exitCode === 'number' && isStrings(value.tests) && typeof value.line === 'string' && volume) {
385
+ return {
386
+ outcome: 'no-space',
387
+ exitCode: value.exitCode,
388
+ tests: value.tests,
389
+ line: value.line,
390
+ volume: volume.value,
391
+ };
392
+ }
393
+ break;
394
+ }
355
395
  case 'failed':
356
396
  if (typeof value.exitCode === 'number' && isStrings(value.tests)) {
357
397
  return { outcome: 'failed', exitCode: value.exitCode, tests: value.tests };
@@ -362,6 +402,24 @@ function parseVerdict(value: unknown): BoundedExecVerdict {
362
402
  throw new Error(`not a bounded-exec verdict: ${JSON.stringify(value)}`);
363
403
  }
364
404
 
405
+ /** A recorded volume, wrapped so a well-formed `null` (no RAM volume) differs from a malformed one (`undefined`). */
406
+ function parseTempVolumeSpace(value: unknown): { value: TempVolumeSpace | null } | undefined {
407
+ if (value === null) {
408
+ return { value: null };
409
+ }
410
+ if (
411
+ isObject(value) &&
412
+ typeof value.lease === 'string' &&
413
+ typeof value.mountpoint === 'string' &&
414
+ typeof value.capacityBytes === 'number' &&
415
+ typeof value.freeBytes === 'number'
416
+ ) {
417
+ const { lease, mountpoint, capacityBytes, freeBytes } = value;
418
+ return { value: { lease, mountpoint, capacityBytes, freeBytes } };
419
+ }
420
+ return undefined;
421
+ }
422
+
365
423
  function isObject(value: unknown): value is Record<string, unknown> {
366
424
  return typeof value === 'object' && value !== null && !Array.isArray(value);
367
425
  }
@@ -425,9 +483,26 @@ export function describeVerdict(verdict: BoundedExecVerdict): string {
425
483
  ? `still running: ${verdict.tests.join(', ')}`
426
484
  : 'the runner named no test still running'
427
485
  }`;
486
+ case 'no-space':
487
+ return `${describeNoSpace(verdict)}${verdict.tests.length > 0 ? `; the tests that then failed: ${verdict.tests.join(', ')}` : ''}`;
428
488
  case 'failed':
429
489
  return verdict.tests.length > 0
430
490
  ? `failed: ${verdict.tests.join(', ')}`
431
491
  : `exited ${verdict.exitCode} with no report naming a timeout`;
432
492
  }
433
493
  }
494
+
495
+ /**
496
+ * What a run's output said about a write that found no space, and where the run's temp files lived then. The free
497
+ * space is read when the line arrives, not after the command exits: by then a writer that failed has usually removed
498
+ * its half-written files and the volume no longer looks full.
499
+ */
500
+ export function describeNoSpace(sighting: NoSpaceSighting): string {
501
+ const said = `ENOSPC (no space left on device): the command printed ${JSON.stringify(sighting.line)}`;
502
+ const volume = sighting.volume;
503
+ if (volume === null) {
504
+ return `${said}; it held no RAM temp volume, so the full disk is the one that line's writer wrote to`;
505
+ }
506
+ const mib = (bytes: number) => (bytes / (1024 * 1024)).toFixed(1);
507
+ return `${said}; its TMPDIR ${volume.lease} is on the RAM temp volume ${volume.mountpoint}, which had ${mib(volume.freeBytes)} MiB free of ${mib(volume.capacityBytes)} MiB when that line arrived`;
508
+ }
@@ -19,6 +19,7 @@ import { createRequire } from 'node:module';
19
19
  import { tmpdir } from 'node:os';
20
20
  import { dirname, join } from 'node:path';
21
21
  import { expandOutputs, WorkspaceContext } from 'nx/src/native';
22
+ import { pastTick } from './__tests__/past-tick.js';
22
23
  import { graphInstallationIdentity, workspaceSnapshot } from './ensure-built-witness.js';
23
24
  import {
24
25
  type GraphInputContract,
@@ -66,6 +67,8 @@ beforeEach(async () => {
66
67
  await writeFile(join(root, '.gitignore'), '.nx/\nnode_modules/\n');
67
68
  await writeFile(join(root, 'plugin.ts'), pure);
68
69
  await writeFile(join(external, 'base.json'), '{"include":["src"]}');
70
+ // A witness read in the tick its inputs changed in is unproven, and no reader trusts it.
71
+ await pastTick();
69
72
  });
70
73
  afterEach(async () => {
71
74
  if (inheritedData === undefined) delete process.env.NX_WORKSPACE_DATA_DIRECTORY;
@@ -211,6 +214,7 @@ describe('owning-reader external input byproducts', () => {
211
214
  const path = join(first, 'base.json');
212
215
  await writeFile(path, '{}');
213
216
  await link(path, join(second, 'base.json'));
217
+ await pastTick();
214
218
  const probe = reader();
215
219
  probe.read(path, () => '{}');
216
220
  expect(probe.finish().status).toBe('complete');
@@ -258,6 +262,7 @@ describe('owning-reader external input byproducts', () => {
258
262
  await mkdir(packageRoot);
259
263
  await writeFile(join(packageRoot, 'package.json'), '{"name":"base-config","version":"1","exports":"./base.json"}');
260
264
  await writeFile(join(packageRoot, 'base.json'), '{}');
265
+ await pastTick();
261
266
  const probe = reader();
262
267
  const local = createRequire(join(root, 'package.json'));
263
268
  expect(probe.resolve(root, 'base-config', () => local.resolve('base-config'))).toBe(join(packageRoot, 'base.json'));
@@ -319,6 +324,7 @@ describe('owning-reader external input byproducts', () => {
319
324
  await writeFile(join(root, 'outside-native.ts'), 'export const value = 1;\n');
320
325
  execFileSync('git', ['add', '--', 'outside-native.ts'], { cwd: root });
321
326
  expect(snapshot().files.map(({ file }) => file)).not.toContain('outside-native.ts');
327
+ await pastTick();
322
328
  const probe = reader('reference-scan');
323
329
  probe.git(root, []);
324
330
  expect(probe.finish().status).toBe('complete');
@@ -341,6 +347,7 @@ describe('owning-reader external input byproducts', () => {
341
347
  const before = await stat(input);
342
348
  const physical = await realpath(input);
343
349
  const bytes = await readFile(input, 'utf8');
350
+ await pastTick();
344
351
  const probe = reader();
345
352
  expect(probe.read(input, () => bytes)).toBe(bytes);
346
353
  expect(probe.finish().status).toBe('complete');
@@ -356,6 +363,7 @@ describe('owning-reader external input byproducts', () => {
356
363
  execFileSync('git', ['init', '-q'], { cwd: root });
357
364
  execFileSync('git', ['config', 'include.path', join(external, 'gitconfig')], { cwd: root });
358
365
  await writeFile(join(external, 'gitconfig'), '[core]\n ignorecase = true\n');
366
+ await pastTick();
359
367
  const probe = reader('reference-scan');
360
368
  probe.git(root, ['plugin.ts']);
361
369
  expect(probe.finish().status).toBe('complete');
@@ -24,7 +24,15 @@ import type * as NxCacheDirectory from 'nx/src/utils/cache-directory';
24
24
  import type * as TypeScript from 'typescript';
25
25
  import typia from 'typia';
26
26
  import type { NodeWitness, WorkspaceSnapshot } from './ensure-built-witness.js';
27
- import { nodeStamp, nodesUnchanged, workspaceSnapshot } from './ensure-built-witness.js';
27
+ import {
28
+ censusStart,
29
+ movedNodes,
30
+ nodeStamp,
31
+ nodesUnchanged,
32
+ recordedStamp,
33
+ unproven,
34
+ workspaceSnapshot,
35
+ } from './ensure-built-witness.js';
28
36
 
29
37
  /** An owner-approved contract, pinned to the reviewed module bytes, never an inferred approval. */
30
38
  export interface GraphInputContract {
@@ -175,6 +183,10 @@ export class GraphInputReadCollector {
175
183
  private readonly scanned = new Set<string>();
176
184
  private readonly gitScopes = new Set<string>();
177
185
  private detail: string | undefined;
186
+ /** Read before the first observation: what each node stamp this reader records is judged by (unproven). */
187
+ private readonly start = censusStart();
188
+ /** The witness's stamp of each node this reader read in the tick it changed in (recordedStamp), by path. */
189
+ private readonly unprovenStamps = new Map<string, string>();
178
190
  constructor(
179
191
  readonly workspaceRoot: string,
180
192
  readonly plugin: string,
@@ -234,7 +246,12 @@ export class GraphInputReadCollector {
234
246
  const stamp = scope === 'path' ? pathStamp(stats) : nodeStamp(stats);
235
247
  if (previous !== undefined && previous.stamp !== (previous.scope === scope ? stamp : pathStamp(stats)))
236
248
  this.refuse(`input changed during read: ${path}`);
237
- if (previous === undefined || previous.scope !== scope) this.nodes.set(path, { path, scope, stamp });
249
+ if (previous === undefined || previous.scope !== scope) {
250
+ this.nodes.set(path, { path, scope, stamp });
251
+ // A path stamp holds no time; a node stamp read in its node's change tick is recorded unproven.
252
+ if (scope === 'node' && unproven(stats, this.start))
253
+ this.unprovenStamps.set(path, recordedStamp(stats, this.start));
254
+ }
238
255
  if (stats.isSymbolicLink()) this.observe(realpathSync(path), membership);
239
256
  else if (stats.isFile()) accessSync(path, constants.R_OK);
240
257
  else if (!stats.isDirectory()) this.refuse(`unproved filesystem node: ${path}`);
@@ -408,10 +425,12 @@ export class GraphInputReadCollector {
408
425
  this.protect(() => {
409
426
  if (this.before === undefined) return;
410
427
  const after = captureNative(this.workspaceRoot, this.before);
428
+ // `after` re-hashed every node whose stamp does not prove it (its ctime alone moved, or `before` read it in the
429
+ // tick it changed in), and its native identity must be `before`'s.
411
430
  if (
412
431
  !after.stable ||
413
432
  nativeIdentity(after.files) !== nativeIdentity(this.before.files) ||
414
- !nodesUnchanged(this.before.nodes) ||
433
+ movedNodes(this.before.nodes, () => true) !== null ||
415
434
  !readNodesUnchanged([...this.nodes.values()])
416
435
  )
417
436
  this.refuse('graph inputs changed during the owning reader');
@@ -427,7 +446,10 @@ export class GraphInputReadCollector {
427
446
  status: 'complete',
428
447
  nativeIdentity: nativeIdentity(this.before.files),
429
448
  nativeNodes: this.before.nodes,
430
- nodes: [...this.nodes.values()],
449
+ nodes: [...this.nodes.values()].map((node) => {
450
+ const stamp = this.unprovenStamps.get(node.path);
451
+ return stamp === undefined ? node : { ...node, stamp };
452
+ }),
431
453
  missing: [...this.missing].sort(),
432
454
  resolutions: this.resolutions,
433
455
  tools: [...this.tools.values()],
package/src/index.test.ts CHANGED
@@ -980,7 +980,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
980
980
  expect(targets.test?.executor).toBe('nx:noop');
981
981
  expect(targets.test?.dependsOn).toEqual(['cargo-test']);
982
982
  expect(targets.mutation?.cache).toBe(false);
983
- expect(targets.mutation?.options).toMatchObject({ command: 'cargo --frozen mutants --workspace' });
983
+ // On bounded-exec, so cargo-mutants' own per-core jobserver is sized to a CPU grant.
984
+ expect(targets.mutation?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
985
+ expect(targets.mutation?.options).toMatchObject({
986
+ command: 'cargo --frozen mutants --workspace',
987
+ timeoutMs: 6 * 60 * 60 * 1000,
988
+ });
984
989
  expect(targets.bench?.options).toMatchObject({ command: 'cargo --frozen bench --workspace' });
985
990
  expectNoSchedulerThrottle(targets);
986
991
  } finally {
@@ -2698,7 +2703,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
2698
2703
 
2699
2704
  // `options` merges key by key, so a declared command overrides only itself.
2700
2705
  const mutation = resolveDeclaredOverInferred(targets, declared, 'mutation');
2701
- expect(mutation?.options).toEqual({ command: 'cargo mutants --in-diff', cwd: 'packages/ferris' });
2706
+ expect(mutation?.options).toEqual({
2707
+ command: 'cargo mutants --in-diff',
2708
+ cwd: 'packages/ferris',
2709
+ timeoutMs: 6 * 60 * 60 * 1000,
2710
+ });
2711
+ expect(mutation?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
2702
2712
  expect(mutation?.cache).toBe(false);
2703
2713
 
2704
2714
  const bench = resolveDeclaredOverInferred(targets, declared, 'bench');
package/src/index.ts CHANGED
@@ -66,6 +66,7 @@ import {
66
66
  cargoFrozen,
67
67
  } from './cross-check-policy.js';
68
68
  import type { EslintFileSet } from './eslint-file-set.js';
69
+ import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
69
70
  import { hashVersionlessCrateManifests } from './manifest-hash.js';
70
71
  import {
71
72
  EXTRACTED_BINARIES_METADATA,
@@ -522,6 +523,8 @@ const CARGO_INPUTS = [
522
523
  // build really reads is the package's `napi` block (binary name, targets) and
523
524
  // the `@napi-rs/cli` it runs; those are hashed as such by napiInputs().
524
525
  const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
526
+ /** A full cargo-mutants sweep's wall-clock backstop: a sweep takes hours, and a hung one must still end. */
527
+ const MUTATION_TIMEOUT_MS = 6 * 60 * 60 * 1000;
525
528
  // The toolchain half of a cargo task's identity lives in its own module
526
529
  // because `smoo monorepo validate` reads the same two constants to refuse a
527
530
  // declaration that drops it. See cargo-toolchain-policy.ts for why it is the
@@ -1087,15 +1090,19 @@ function isBuildOutputPackageJson(packageJsonPath: string): boolean {
1087
1090
  /**
1088
1091
  * Nx accepts one pre/post task-hook pair per plugin. Two independent observers share it: the controller's task-results
1089
1092
  * hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
1090
- * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence.
1093
+ * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
1094
+ * pair also serves a run on a host without a gateway its own CPU pool, which every task inherits
1095
+ * (`run-cpu-pool.ts`), and closes it when the run ends.
1091
1096
  */
1092
1097
  export const preTasksExecution: PreTasksExecution<ProducerReceiptsOptions> = async (options, context) => {
1093
1098
  preTaskResults(options, context);
1094
1099
  await preProducerReceipts(options, context);
1100
+ await serveRunCpuPool(context);
1095
1101
  };
1096
1102
  export const postTasksExecution: PostTasksExecution<ProducerReceiptsOptions> = async (options, context) => {
1097
1103
  await postTaskResults(options, context);
1098
1104
  await postProducerReceipts(options, context);
1105
+ await closeRunCpuPool(context);
1099
1106
  };
1100
1107
 
1101
1108
  export default { createNodesV2, postTasksExecution, preTasksExecution };
@@ -1543,10 +1550,13 @@ async function createProjectTargets(
1543
1550
  };
1544
1551
  // Mutation runs are minutes-to-hours: never cached, never part of build/lint.
1545
1552
  // CI runs these per-PR via `cargo mutants --in-diff` (see mutants.toml docs).
1553
+ // bounded-exec sizes cargo-mutants' own jobserver to its CPU grant (its `cargo-mutants` runner kind), which
1554
+ // otherwise starts one task per core whatever else runs on the host. It reports no test bounded-exec can read as
1555
+ // progress, so its bound is a wall-clock backstop, not a performance budget.
1546
1556
  targets.mutation = {
1547
- executor: 'nx:run-commands',
1557
+ executor: '@smoothbricks/nx-plugin:bounded-exec',
1548
1558
  cache: false,
1549
- options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot },
1559
+ options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot, timeoutMs: MUTATION_TIMEOUT_MS },
1550
1560
  };
1551
1561
  targets.bench = {
1552
1562
  executor: 'nx:run-commands',