@smoothbricks/nx-plugin 0.4.27 → 0.4.29

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 (124) hide show
  1. package/README.md +203 -83
  2. package/dist/bounded-test-policy.d.ts +10 -3
  3. package/dist/bounded-test-policy.d.ts.map +1 -1
  4. package/dist/bounded-test-policy.js +19 -25
  5. package/dist/cargo-closure-input.d.ts +12 -0
  6. package/dist/cargo-closure-input.d.ts.map +1 -1
  7. package/dist/cargo-closure-input.js +29 -7
  8. package/dist/cargo-source-hash.d.ts.map +1 -1
  9. package/dist/cargo-source-hash.js +42 -19
  10. package/dist/ensure-built-receipt.d.ts +34 -6
  11. package/dist/ensure-built-receipt.d.ts.map +1 -1
  12. package/dist/ensure-built-receipt.js +265 -159
  13. package/dist/ensure-built-witness.d.ts +27 -2
  14. package/dist/ensure-built-witness.d.ts.map +1 -1
  15. package/dist/ensure-built-witness.js +2176 -15
  16. package/dist/ensure-built.d.ts +99 -1
  17. package/dist/ensure-built.d.ts.map +1 -1
  18. package/dist/ensure-built.js +34 -53
  19. package/dist/executors/bounded-exec/cpu-pool.d.ts +16 -5
  20. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  21. package/dist/executors/bounded-exec/cpu-pool.js +43 -19
  22. package/dist/executors/bounded-exec/executor.d.ts +11 -2
  23. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/executor.js +139 -39
  25. package/dist/executors/bounded-exec/ram-temp.d.ts +17 -11
  26. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  27. package/dist/executors/bounded-exec/ram-temp.js +27 -13
  28. package/dist/generators/bun-test-tracing/generator.js +2 -2
  29. package/dist/graph-input-contract.d.ts +98 -0
  30. package/dist/graph-input-contract.d.ts.map +1 -0
  31. package/dist/graph-input-contract.js +624 -0
  32. package/dist/index.d.ts +12 -5
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +17 -3
  35. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  36. package/dist/managed-files/ci-workflow.js +5 -2
  37. package/dist/managed-files/publish-workflow.d.ts +11 -1
  38. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  39. package/dist/producer-receipts.d.ts +19 -0
  40. package/dist/producer-receipts.d.ts.map +1 -0
  41. package/dist/producer-receipts.js +921 -0
  42. package/dist/testing.d.ts +8 -0
  43. package/dist/testing.d.ts.map +1 -1
  44. package/dist/testing.js +58 -0
  45. package/managed/raw/patches/nx@23.2.1.patch +328 -50
  46. package/managed/raw/tooling/direnv/developer-links.ts +147 -21
  47. package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
  48. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
  49. package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
  50. package/managed/raw/tooling/direnv/repo-path +15 -2
  51. package/managed/raw/tooling/direnv/setup-environment.ts +363 -125
  52. package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
  53. package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
  54. package/nextest.toml +1 -1
  55. package/package.json +11 -6
  56. package/src/__tests__/fixture-nx-env.ts +7 -0
  57. package/src/__tests__/owned-installation.ts +174 -0
  58. package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
  59. package/src/bounded-test-policy.test.ts +36 -22
  60. package/src/bounded-test-policy.ts +19 -27
  61. package/src/bun-bootstrap.test.ts +1 -1
  62. package/src/cargo-closure-input.test.ts +60 -11
  63. package/src/cargo-closure-input.ts +28 -6
  64. package/src/cargo-resolve-cache.test.ts +140 -25
  65. package/src/cargo-source-hash.test.ts +78 -3
  66. package/src/cargo-source-hash.ts +48 -30
  67. package/src/cross-check-policy.test.ts +2 -2
  68. package/src/ensure-built-receipt.test.ts +111 -16
  69. package/src/ensure-built-receipt.ts +251 -149
  70. package/src/ensure-built-witness.test.ts +197 -13
  71. package/src/ensure-built-witness.ts +187 -15
  72. package/src/ensure-built.test.ts +156 -102
  73. package/src/ensure-built.ts +114 -64
  74. package/src/executors/bounded-exec/cpu-pool.test.ts +116 -32
  75. package/src/executors/bounded-exec/cpu-pool.ts +55 -17
  76. package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
  77. package/src/executors/bounded-exec/executor-host.test.ts +51 -41
  78. package/src/executors/bounded-exec/executor.test.ts +155 -35
  79. package/src/executors/bounded-exec/executor.ts +156 -45
  80. package/src/executors/bounded-exec/progress.test.ts +1 -1
  81. package/src/executors/bounded-exec/ram-temp-host.test.ts +46 -17
  82. package/src/executors/bounded-exec/ram-temp.test.ts +65 -3
  83. package/src/executors/bounded-exec/ram-temp.ts +32 -16
  84. package/src/executors/bounded-exec/verdict.test.ts +17 -12
  85. package/src/generators/bounded-test-targets/generator.test.ts +1 -3
  86. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  87. package/src/generators/bun-test-tracing/generator.ts +2 -2
  88. package/src/graph-input-contract.test.ts +371 -0
  89. package/src/graph-input-contract.ts +605 -0
  90. package/src/index.test.ts +3 -3
  91. package/src/index.ts +24 -3
  92. package/src/linked-snapshots.nx.test.ts +112 -30
  93. package/src/managed-files/ci-workflow.ts +5 -2
  94. package/src/managed-files/publish-workflow.ts +12 -1
  95. package/src/managed-files/repo-path.test.ts +44 -1
  96. package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
  97. package/src/nextest-code-bound.test.ts +23 -17
  98. package/src/nextest-partitions.test.ts +7 -1
  99. package/src/nx-cache-restore-mtime.test.ts +2 -2
  100. package/src/nx-daemon-claim.test.ts +5 -5
  101. package/src/nx-daemon-idle-cpu.test.ts +0 -1
  102. package/src/nx-daemon-idle-policy.test.ts +56 -0
  103. package/src/nx-daemon-ignore-files.test.ts +2 -2
  104. package/src/nx-daemon-validity.test.ts +31 -9
  105. package/src/nx-dot-input-policy.test.ts +5 -5
  106. package/src/nx-files-archive-racy.test.ts +1 -1
  107. package/src/nx-incomplete-run-summary.test.ts +1 -1
  108. package/src/nx-plugin-load-errors.test.ts +2 -2
  109. package/src/nx-project-graph-errors.test.ts +70 -0
  110. package/src/nx-skipped-task-exit.test.ts +2 -2
  111. package/src/nx-store-resolution.test.ts +7 -25
  112. package/src/nx-task-output-lease.test.ts +3 -3
  113. package/src/nx-use-local.test.ts +7 -5
  114. package/src/producer-receipts.test.ts +164 -0
  115. package/src/producer-receipts.ts +631 -0
  116. package/src/runtime-input.test.ts +1 -1
  117. package/src/serial-group-wiring.test.ts +4 -4
  118. package/src/task-results.test.ts +18 -16
  119. package/src/test-timings.test.ts +2 -2
  120. package/src/testing.test.ts +5 -5
  121. package/src/testing.ts +59 -0
  122. package/src/typecheck-test-policy.test.ts +1 -1
  123. package/src/typescript-resolution.test.ts +76 -0
  124. package/test-timings.json +5 -0
@@ -1,4 +1,6 @@
1
1
  import { describe, expect, it } from 'bun:test';
2
+ import { spawn } from 'node:child_process';
3
+ import { once } from 'node:events';
2
4
  import {
3
5
  chmodSync,
4
6
  existsSync,
@@ -14,10 +16,11 @@ import {
14
16
  } from 'node:fs';
15
17
  import { tmpdir, userInfo } from 'node:os';
16
18
  import { join } from 'node:path';
19
+ import { setTimeout as sleep } from 'node:timers/promises';
17
20
  import { fileURLToPath } from 'node:url';
18
21
  import type { OpContextBinding } from '@smoothbricks/lmao';
19
22
  import { useTestSpan } from '@smoothbricks/lmao/testing/bun';
20
- import { pidsWorkingIn, processTable, terminate } from '../../testing.js';
23
+ import { processTable, terminate } from '../../testing.js';
21
24
  import {
22
25
  type CommandOutput,
23
26
  createHostCommands,
@@ -25,6 +28,7 @@ import {
25
28
  leaseProcessesOn,
26
29
  mountsBelow,
27
30
  operationDisk,
31
+ pidsInLease,
28
32
  type RamDisk,
29
33
  type RamTempError,
30
34
  type RamTempPaths,
@@ -121,7 +125,7 @@ async function nativeRamVolume(): Promise<void> {
121
125
  async workingIn(directory) {
122
126
  const startedAt = Date.now();
123
127
  const starting = JSON.stringify({
124
- phase: 'cwd-census-start',
128
+ phase: 'lease-census-start',
125
129
  directory,
126
130
  pid: process.pid,
127
131
  wallAtMs: startedAt,
@@ -130,10 +134,10 @@ async function nativeRamVolume(): Promise<void> {
130
134
  trace.log.info(starting);
131
135
  process.stderr.write(`${starting}\n`);
132
136
  try {
133
- const pids = await pidsWorkingIn(directory);
137
+ const pids = await pidsInLease(directory);
134
138
  const endedAt = Date.now();
135
139
  const finished = JSON.stringify({
136
- phase: 'cwd-census-end',
140
+ phase: 'lease-census-end',
137
141
  directory,
138
142
  pid: process.pid,
139
143
  wallAtMs: endedAt,
@@ -149,7 +153,7 @@ async function nativeRamVolume(): Promise<void> {
149
153
  const details = typeof error === 'object' && error !== null ? error : {};
150
154
  const failed = JSON.stringify(
151
155
  {
152
- phase: 'cwd-census-error',
156
+ phase: 'lease-census-error',
153
157
  directory,
154
158
  pid: process.pid,
155
159
  wallAtMs: endedAt,
@@ -364,17 +368,45 @@ async function nativeRamVolume(): Promise<void> {
364
368
  expect(statSync(join(leaseB.directory, 'tree')).mode & 0o777).toBe(0o555);
365
369
 
366
370
  // Once its owner has detached the image, the next task reclaims the lease, and its release,
367
- // the last, detaches the volume.
371
+ // the last, detaches the volume. The dead task left a writer behind, as a test's ttsc plugin
372
+ // build is left: working elsewhere, writing into the lease through its TMPDIR, with a child.
373
+ // The pid the lease is named after is dead; the writer is stopped before the lease goes, so
374
+ // its removal never meets a file made after the lease was judged dead. A second dead lease,
375
+ // that nothing works in, is reclaimed beside it.
368
376
  attachedBelow.image = null;
369
- const fourth = new RamTempVolume(paths, capacity, commands, 101, (pid) => alive.has(pid), processes);
370
- const d = await fourth.acquire();
371
- if (!d.ok || d.value.kind !== 'leased') {
372
- throw new Error(`fourth lease failed: ${JSON.stringify(d)}`);
377
+ const writer = spawn('sh', ['-c', 'sleep 600 & echo $!; i=0; while :; do i=$((i+1)); : > "$TMPDIR/w$i"; done'], {
378
+ cwd: parent,
379
+ env: { ...process.env, TMPDIR: leaseB.directory },
380
+ detached: true,
381
+ stdio: ['ignore', 'pipe', 'ignore'],
382
+ });
383
+ const writerExited = once(writer, 'close');
384
+ const writerChild = Number(String((await once(writer.stdout, 'data'))[0]).trim());
385
+ const quiet = join(paths.mountpoint, '303-quiet1');
386
+ mkdirSync(quiet);
387
+ writeFileSync(join(quiet, 'left'), 'by a task nothing of which still runs');
388
+ try {
389
+ while (!existsSync(join(leaseB.directory, 'w1'))) {
390
+ await sleep(5);
391
+ }
392
+ const fourth = new RamTempVolume(paths, capacity, commands, 101, (pid) => alive.has(pid), processes);
393
+ const d = await fourth.acquire();
394
+ if (!d.ok || d.value.kind !== 'leased') {
395
+ throw new Error(`fourth lease failed: ${JSON.stringify(d)}`);
396
+ }
397
+ expect(d.value.held).toEqual([]);
398
+ expect(d.value.reaped.map((entry) => Number(entry.split(' ')[0])).sort((a, b) => a - b)).toEqual(
399
+ [writer.pid ?? 0, writerChild].sort((a, b) => a - b),
400
+ );
401
+ expect(existsSync(leaseB.directory)).toBe(false);
402
+ expect(existsSync(quiet)).toBe(false);
403
+ expectUntouched(outside);
404
+ expect(await fourth.release(d.value.lease)).toEqual({ ok: true, value: undefined });
405
+ } finally {
406
+ terminate(writer.pid ?? 0, 'SIGKILL');
407
+ terminate(writerChild, 'SIGKILL');
408
+ await writerExited;
373
409
  }
374
- expect(d.value.held).toEqual([]);
375
- expect(existsSync(leaseB.directory)).toBe(false);
376
- expectUntouched(outside);
377
- expect(await fourth.release(d.value.lease)).toEqual({ ok: true, value: undefined });
378
410
  expect(existsSync(paths.mountpoint)).toBe(false);
379
411
  expect(await attachedDisks(paths, capacity)).toEqual([]);
380
412
  } finally {
@@ -588,18 +620,15 @@ describe('temporary-directory policy on this host', () => {
588
620
  it(
589
621
  'reclaims what a dead creator left, shares the volume between leases, and detaches it at the last release, never mounting beside it as "<name> 1"',
590
622
  nativeRamVolume,
591
- 60_000,
592
623
  );
593
624
  it(
594
625
  'leaves no volume under its final name, and no staging directory, when any provisioning step fails',
595
626
  aFailedStepLeavesNoNamedVolume,
596
- 180_000,
597
627
  );
598
628
  } else {
599
629
  it(
600
630
  'keeps inherited temporary storage, honors a target override, and never provisions an APFS disk',
601
631
  inheritedTempDirectory,
602
- 30_000,
603
632
  );
604
633
  }
605
634
  });
@@ -1,12 +1,13 @@
1
1
  import { describe, expect, it } from 'bun:test';
2
2
  import { execFileSync, spawn } from 'node:child_process';
3
3
  import { once } from 'node:events';
4
- import { mkdtempSync, realpathSync, rmSync } from 'node:fs';
4
+ import { mkdirSync, mkdtempSync, readdirSync, realpathSync, rmSync } from 'node:fs';
5
5
  import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
6
6
  import { createServer, type Socket } from 'node:net';
7
7
  import { tmpdir } from 'node:os';
8
8
  import { join } from 'node:path';
9
9
  import { createInterface } from 'node:readline';
10
+ import { setTimeout as sleep } from 'node:timers/promises';
10
11
  import { awaitExit, ownedSocketDirectory, pidsWorkingIn, processTable, terminate } from '../../testing.js';
11
12
  import {
12
13
  COWSHED_EXECUTABLE_ENV,
@@ -186,7 +187,7 @@ describe('RAM temp volume on this host', () => {
186
187
  const spawned = result.stdout.trim();
187
188
  expect(spawned).toMatch(/^\d+$/);
188
189
  // Gone, or a zombie its new parent has yet to reap: either way no longer running.
189
- const state = await createHostCommands().run('/bin/ps', ['-o', 'stat=', '-p', spawned]);
190
+ const state = await createHostCommands().run('ps', ['-o', 'stat=', '-p', spawned]);
190
191
  expect(state.status === 1 || state.stdout.trim().startsWith('Z')).toBe(true);
191
192
  });
192
193
 
@@ -658,15 +659,76 @@ describe('processes a task left working in its RAM lease', () => {
658
659
  }
659
660
  });
660
661
 
662
+ it('stops what writes into the lease through its TMPDIR from elsewhere, so the lease can be removed', async () => {
663
+ const lease = scratch();
664
+ const elsewhere = scratch();
665
+ // As a dead task's ttsc plugin build leaves it: working in its project, writing into `$TMPDIR`
666
+ // as fast as it can (shell builtins only, so it forks nothing), with a child of its own. macOS
667
+ // spells TMPDIR with a trailing slash.
668
+ const writer = spawn('sh', ['-c', 'sleep 600 & echo $!; i=0; while :; do i=$((i+1)); : > "$TMPDIR/w$i"; done'], {
669
+ cwd: elsewhere,
670
+ env: { ...process.env, TMPDIR: `${lease}/` },
671
+ detached: true,
672
+ stdio: ['ignore', 'pipe', 'ignore'],
673
+ });
674
+ // Another, started on its own with a TMPDIR beneath the lease.
675
+ mkdirSync(join(lease, 'nested'));
676
+ const nested = spawn('sleep', ['600'], {
677
+ cwd: elsewhere,
678
+ env: { ...process.env, TMPDIR: join(lease, 'nested') },
679
+ detached: true,
680
+ stdio: 'ignore',
681
+ });
682
+ const exited = [once(writer, 'close'), once(nested, 'close')];
683
+ const pids = [writer.pid ?? 0, nested.pid ?? 0];
684
+ let child = 0;
685
+ try {
686
+ child = Number(String((await once(writer.stdout, 'data'))[0]).trim());
687
+ while (readdirSync(lease).length < 2) {
688
+ await sleep(5);
689
+ }
690
+ // None of them works in the lease by its working directory.
691
+ expect(await pidsWorkingIn(lease)).toEqual([]);
692
+
693
+ const stopped = await hostLeaseProcesses.stopWorkingIn(lease);
694
+
695
+ expect(stopped.map((entry) => Number(entry.split(' ')[0])).sort((a, b) => a - b)).toEqual(
696
+ [...pids, child].sort((a, b) => a - b),
697
+ );
698
+ expect(await liveAmong([...pids, child])).toEqual([]);
699
+ // Nothing writes there any more: the lease goes whole, with no ENOTEMPTY.
700
+ await rm(lease, { recursive: true });
701
+ } finally {
702
+ for (const pid of [...pids, child]) {
703
+ if (pid !== 0) {
704
+ terminate(pid, 'SIGKILL');
705
+ }
706
+ }
707
+ await Promise.all(exited);
708
+ rmSync(lease, { recursive: true, force: true });
709
+ rmSync(elsewhere, { recursive: true, force: true });
710
+ }
711
+ });
712
+
661
713
  it('stops nothing in a lease no process works in, and nothing that works elsewhere', async () => {
662
714
  const lease = scratch();
663
715
  const elsewhere = scratch();
664
716
  const bystander = spawn('sleep', ['600'], { cwd: elsewhere, detached: true, stdio: 'ignore' });
717
+ // A TMPDIR that only starts with the lease's name is another directory.
718
+ const sibling = spawn('sleep', ['600'], {
719
+ cwd: elsewhere,
720
+ env: { ...process.env, TMPDIR: `${lease}x` },
721
+ detached: true,
722
+ stdio: 'ignore',
723
+ });
665
724
  try {
666
725
  expect(await hostLeaseProcesses.stopWorkingIn(lease)).toEqual([]);
667
- expect(bystander.exitCode === null && bystander.signalCode === null).toBe(true);
726
+ for (const left of [bystander, sibling]) {
727
+ expect(left.exitCode === null && left.signalCode === null).toBe(true);
728
+ }
668
729
  } finally {
669
730
  bystander.kill('SIGKILL');
731
+ sibling.kill('SIGKILL');
670
732
  rmSync(lease, { recursive: true, force: true });
671
733
  rmSync(elsewhere, { recursive: true, force: true });
672
734
  }
@@ -22,6 +22,7 @@ import { setTimeout as sleep } from 'node:timers/promises';
22
22
  import {
23
23
  awaitExit,
24
24
  type ProcessEntry,
25
+ pidsWithTempIn,
25
26
  pidsWorkingIn,
26
27
  processTable,
27
28
  terminate,
@@ -80,7 +81,11 @@ import {
80
81
  * checks that the volume, the lease directory and its own claim are still as
81
82
  * it claimed them. A lease is a directory named after the task process's pid;
82
83
  * a lease whose pid is gone is reclaimed by the next task, and the volume is
83
- * detached when the last lease ends.
84
+ * detached when the last lease ends. The pid's death proves only that the task
85
+ * process is gone, not what it started: its command runs in a process group of
86
+ * its own, and every process started with the lease as its `TMPDIR` writes
87
+ * there wherever it works. So a dead lease is removed only once every process
88
+ * working in it, by working directory or by `TMPDIR`, has been stopped.
84
89
  *
85
90
  * The volume is created under its final name and never renamed. It is mounted by `mount_apfs` at a
86
91
  * private staging directory and marked there; the kernel then unmounts it (`umount`) and `diskutil mount`, the
@@ -180,16 +185,16 @@ const LEFTOVER_GRACE_MS = 5_000;
180
185
  */
181
186
  export interface LeaseProcesses {
182
187
  /**
183
- * End every process whose working directory is in `directory`, and everything those started,
184
- * and answer each as `<pid> (<command>)`. Every one has exited when this settles; one that
185
- * would not rejects with its name.
188
+ * End every process that works in `directory` — its working directory or the `TMPDIR` it was
189
+ * started with is there — and everything those started, and answer each as `<pid> (<command>)`.
190
+ * Every one has exited when this settles; one that would not rejects with its name.
186
191
  */
187
192
  stopWorkingIn(directory: string): Promise<string[]>;
188
193
  }
189
194
 
190
195
  /** The host reads and signals cleanup uses; a seam for process ordering and signal failures. */
191
196
  export interface ProcessHost {
192
- /** The processes whose working directory is `directory` or lies beneath it. */
197
+ /** The processes whose working directory, or the `TMPDIR` they were started with, is `directory` or lies beneath it. */
193
198
  workingIn(directory: string): Promise<number[]>;
194
199
  /** Every process on the host. */
195
200
  table(): Promise<ProcessEntry[]>;
@@ -201,13 +206,17 @@ const STARTS_NOTHING = /^[TtZ]/;
201
206
 
202
207
  /**
203
208
  * The processes `host` reads. A lease belongs to one task and its command is gone by the time the
204
- * lease ends, so what still works in it is what the command left behind. A fixture's Nx daemon is
205
- * the usual one: Nx detaches it into a session of its own, so the process-group kill that ends a
206
- * timed-out command never reaches it, and a test process that is killed runs no teardown of its
207
- * own. Deleting the lease asks such a daemon to leave only by deleting its record, which it
208
- * notices within a second when it is idle and not at all while it is wedged; a signal does not
209
- * depend on the daemon noticing, and a process left on the volume is what keeps it from
210
- * detaching.
209
+ * lease ends, so what still works in it is what the command left behind. Most of that works in the
210
+ * lease only through `TMPDIR`, never by working directory: a test's ttsc plugin build copies the
211
+ * typescript-go sources into `$TMPDIR` from a process working in its project, and a Bun or Node
212
+ * process writes its compile cache there as it exits. Neither is known to the task's pid, and
213
+ * whichever outlived that pid would write into a lease being removed (measured 2026-10-18: `rm`
214
+ * failing ENOTEMPTY under a ttsc copy whose task had died). A fixture's Nx daemon is another: Nx
215
+ * detaches it into a session of its own, so the process-group kill that ends a timed-out command
216
+ * never reaches it, and a test process that is killed runs no teardown of its own. Deleting the
217
+ * lease asks such a daemon to leave only by deleting its record, which it notices within a second
218
+ * when it is idle and not at all while it is wedged; a signal does not depend on the daemon
219
+ * noticing, and a process left on the volume is what keeps it from detaching.
211
220
  *
212
221
  * A leftover keeps running while it is looked for, and a child it starts after the process table
213
222
  * was read is in no table that was. So each one found is held with SIGSTOP and the table is read
@@ -290,8 +299,14 @@ export function leaseProcessesOn(host: ProcessHost): LeaseProcesses {
290
299
  };
291
300
  }
292
301
 
302
+ /** What works in `directory` on this host: by working directory, and by the `TMPDIR` it was started with. */
303
+ export async function pidsInLease(directory: string): Promise<number[]> {
304
+ const [working, temp] = await Promise.all([pidsWorkingIn(directory), pidsWithTempIn(directory)]);
305
+ return [...new Set([...working, ...temp])];
306
+ }
307
+
293
308
  export const hostLeaseProcesses: LeaseProcesses = leaseProcessesOn({
294
- workingIn: pidsWorkingIn,
309
+ workingIn: pidsInLease,
295
310
  table: processTable,
296
311
  signal: terminate,
297
312
  });
@@ -1054,9 +1069,10 @@ export class RamTempVolume {
1054
1069
  }
1055
1070
  const reaped: string[] = [];
1056
1071
  for (const candidate of candidates) {
1057
- // Its task is gone, so what works in it is what that task left: stopped before the lease
1058
- // is removed, even where the removal is refused below. A task reaps its own (`reap`).
1059
- if (!candidate.own && (await readdir(candidate.directory)).length > 0) {
1072
+ // Its task is gone, so what works in it is what that task left: stopped before the lease is
1073
+ // removed, even where the removal is refused below. An empty lease is asked too: a leftover
1074
+ // that has not written yet writes once it runs again. A task reaps its own (`reap`).
1075
+ if (!candidate.own) {
1060
1076
  reaped.push(...(await this.processes.stopWorkingIn(candidate.directory)));
1061
1077
  }
1062
1078
  }
@@ -179,12 +179,17 @@ describe('bounded-exec verdicts', () => {
179
179
  });
180
180
 
181
181
  it('records a failing command with no report as a failure, and a passing one as passed', async () => {
182
- expect(await verdictOf('node -e "process.exit(3)"', { timeoutMs: 5_000 })).toEqual({
183
- outcome: 'failed',
184
- exitCode: 3,
185
- tests: [],
186
- });
187
- expect(await verdictOf('node -e ""', { timeoutMs: 5_000 })).toEqual({ outcome: 'passed' });
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' });
188
193
  });
189
194
 
190
195
  it("reads nextest's typed timeout from its JUnit report", () => {
@@ -358,8 +363,8 @@ setInterval(() => console.log('running'), 10);
358
363
  const directory = context.record?.directory ?? '';
359
364
  await mkdir(directory, { recursive: true });
360
365
  const report = join(directory, JUNIT_FILE);
361
- expect(await withJunitReport('bun test --timeout=30000 src', directory)).toBe(
362
- `bun test --reporter=junit --reporter-outfile='${report}' --timeout=30000 src`,
366
+ expect(await withJunitReport('bun test --timeout=0 src', directory)).toBe(
367
+ `bun test --reporter=junit --reporter-outfile='${report}' --timeout=0 src`,
363
368
  );
364
369
  const nextest = await withJunitReport('extracted="$(x)" && cargo --frozen nextest run -E all', directory);
365
370
  expect(nextest).toBe(
@@ -377,15 +382,15 @@ setInterval(() => console.log('running'), 10);
377
382
  const directory = context.record?.directory ?? '';
378
383
  await mkdir(directory, { recursive: true });
379
384
  const flags = `--reporter=junit --reporter-outfile='${join(directory, JUNIT_FILE)}'`;
380
- expect(await withJunitReport('../bun-runtime/.runtime/bun test --timeout=30000 --shard=1/4', directory)).toBe(
381
- `../bun-runtime/.runtime/bun test ${flags} --timeout=30000 --shard=1/4`,
385
+ expect(await withJunitReport('../bun-runtime/.runtime/bun test --timeout=0 --shard=1/4', directory)).toBe(
386
+ `../bun-runtime/.runtime/bun test ${flags} --timeout=0 --shard=1/4`,
382
387
  );
383
388
  expect(
384
389
  await withJunitReport(
385
- 'BUN_EXE=../bun-runtime/.runtime/bun ../bun-runtime/.runtime/bun test --timeout=30000 tests',
390
+ 'BUN_EXE=../bun-runtime/.runtime/bun ../bun-runtime/.runtime/bun test --timeout=0 tests',
386
391
  directory,
387
392
  ),
388
- ).toBe(`BUN_EXE=../bun-runtime/.runtime/bun ../bun-runtime/.runtime/bun test ${flags} --timeout=30000 tests`);
393
+ ).toBe(`BUN_EXE=../bun-runtime/.runtime/bun ../bun-runtime/.runtime/bun test ${flags} --timeout=0 tests`);
389
394
  expect(await withJunitReport('cd pkg && $RUNTIME/bun test src', directory)).toBe(
390
395
  `cd pkg && $RUNTIME/bun test ${flags} src`,
391
396
  );
@@ -6,11 +6,9 @@ import {
6
6
  BOUNDED_TEST_EXECUTOR,
7
7
  BOUNDED_TEST_IDLE_TIMEOUT_MS,
8
8
  BOUNDED_TEST_KILL_AFTER_MS,
9
- BOUNDED_TEST_PER_TEST_TIMEOUT_MS,
9
+ BUN_TEST_TIMEOUT_FLAG as TIMEOUT_FLAG,
10
10
  } from '../../bounded-test-policy.js';
11
11
 
12
- const TIMEOUT_FLAG = `--timeout=${BOUNDED_TEST_PER_TEST_TIMEOUT_MS}`;
13
-
14
12
  import generator from './generator.js';
15
13
 
16
14
  describe('bounded-test-targets generator', () => {
@@ -5,7 +5,7 @@ import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
5
5
  import {
6
6
  BOUNDED_TEST_IDLE_TIMEOUT_MS,
7
7
  BOUNDED_TEST_KILL_AFTER_MS,
8
- BOUNDED_TEST_PER_TEST_TIMEOUT_MS,
8
+ BUN_TEST_TIMEOUT_FLAG,
9
9
  } from '../../bounded-test-policy.js';
10
10
  import generator from './generator.js';
11
11
 
@@ -77,7 +77,7 @@ describe('bun-test-tracing generator', () => {
77
77
  executor: '@smoothbricks/nx-plugin:bounded-exec',
78
78
  dependsOn: ['typecheck-tests', '^build'],
79
79
  options: {
80
- command: `bun test --timeout=${BOUNDED_TEST_PER_TEST_TIMEOUT_MS}`,
80
+ command: `bun test ${BUN_TEST_TIMEOUT_FLAG}`,
81
81
  cwd: '{projectRoot}',
82
82
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
83
83
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
@@ -141,8 +141,8 @@ function writeBunfig(tree: Tree, projectRoot: string): void {
141
141
  // Bun silently ignores `[test] timeout` in bunfig.toml — only the `--timeout`
142
142
  // CLI flag and `setDefaultTimeout()` actually take effect. Strip any stale
143
143
  // `timeout = N` lines so the file isn't lying about what's enforced; the real
144
- // per-test timeout is wired into `bun test --timeout=N` by the bounded-test
145
- // policy (see BOUNDED_TEST_PER_TEST_TIMEOUT_MS).
144
+ // per-test timeout is the leg's `--timeout`, which the bounded-test policy
145
+ // derives from bounded-exec's progress bound (see BUN_TEST_TIMEOUT_FLAG).
146
146
  const current = stripBunTestTimeoutLine(tree.read(bunfigPath, 'utf-8') ?? '');
147
147
 
148
148
  // Already has the package specifier preloads