@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
@@ -159,6 +159,46 @@ runs:
159
159
  shell: bash
160
160
  run: echo "DEVENV_WORKDIR=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
161
161
 
162
+ # GitHub's hosted Ubuntu images promise only 14 GB free and fill the rest of
163
+ # the disk with toolchains a Nix-built shell never uses. The store can need
164
+ # more: the largest measured is 17.1 GB unpacked, and a restore or save also
165
+ # holds its 4.9 GB archive in RUNNER_TEMP. A 2-vCPU runner ran out of disk
166
+ # with about 15 GB of store on it, and nothing had printed free space.
167
+ # Delete those trees, most GiB per second first, until / has 32 GiB free.
168
+ # That is an estimate: the store at its peak with its archive, node_modules
169
+ # and build scratch, plus a few GiB of margin; the df lines record what a
170
+ # run really had. A runner that already has it deletes nothing, and the
171
+ # Android SDK, which alone takes minutes to delete, goes only when the rest
172
+ # was not enough.
173
+ # What goes stays gone for the rest of the job: a later actions/setup-*
174
+ # step downloads its runtime instead of finding it in the tool cache, a
175
+ # pwsh step loses the image's PowerShell modules (pwsh itself stays), and
176
+ # a step that runs the image's .NET, GHCup, Swift or Android SDK directly
177
+ # fails. Only a runner that started short of space deletes anything, so
178
+ # such a step would fail on some runs and pass on others.
179
+ # Synchronous on purpose: a background rm would race the store extraction
180
+ # for space and disk I/O. A failed delete warns and the job goes on: this
181
+ # is an optimisation, never a gate. Self-hosted machines keep everything.
182
+ - name: 🧹 Free runner disk
183
+ if: steps.runner-kind.outputs.host != 'true' && runner.os == 'Linux' && runner.environment == 'github-hosted'
184
+ shell: bash
185
+ run: |
186
+ want_kib=$((32 * 1024 * 1024))
187
+ free_kib() { df -k --output=avail / | tail -n 1 | tr -d ' '; }
188
+ df -h /
189
+ for dir in /usr/share/swift /usr/local/share/powershell /usr/local/.ghcup \
190
+ /usr/share/dotnet "${AGENT_TOOLSDIRECTORY:-}" /usr/local/lib/android; do
191
+ [ "$(free_kib)" -lt "$want_kib" ] || break
192
+ [ -n "$dir" ] && [ -d "$dir" ] || continue
193
+ start=$SECONDS
194
+ if sudo rm -rf "$dir"; then
195
+ echo "removed $dir in $((SECONDS - start)) s"
196
+ else
197
+ echo "::warning::could not remove $dir; going on without its space"
198
+ fi
199
+ done
200
+ df -h /
201
+
162
202
  # Devenv segment (own key): tooling/direnv/.devenv + .direnv — includes
163
203
  # nix-eval-cache.db. Independent of the store cache; restored on ephemeral
164
204
  # runners whether or not the store cache hit. Missing store paths are fine:
@@ -207,6 +247,20 @@ runs:
207
247
  # arrives inside /nix, so install-devenv's `nix profile add` of the locked
208
248
  # rev is a link rather than a download, and the devenv in play is the one
209
249
  # devenv.lock names instead of whichever run last populated the prefix.
250
+ #
251
+ # The key is two hashes: the pins (devenv.lock, devenv.yaml), then the files
252
+ # that choose and override packages on top of them (devenv.nix,
253
+ # devenv.smoo.nix, the nixpkgs overlay). The restore prefix ends after the
254
+ # pins, so a miss falls back only to a store saved from the same pins. Once
255
+ # nixpkgs or devenv moved, a store built from other pins is mostly dead
256
+ # weight that still costs its full unpacked size: measured, a pull request
257
+ # whose pins differed from the default branch's restored 7.55 GB, then
258
+ # fetched the same 1319 paths as a cold run, and the runner ran out of
259
+ # disk. The overlay is hashed itself because devenv.lock locks it as a
260
+ # relative path with no narHash: an overlay edit moved neither the lock nor
261
+ # the key, so every later run got an exact hit on a stale store that was
262
+ # never saved again. nix-v7 keeps the bare nix-v6- prefix of the old layout
263
+ # from restoring a store saved under this one.
210
264
  - name: 🧊 Cache Nix store
211
265
  id: nix-cache
212
266
  if: steps.runner-kind.outputs.host != 'true'
@@ -216,8 +270,9 @@ runs:
216
270
  /nix
217
271
  ~/.cache/nix
218
272
  # prettier-ignore
219
- primary-key: ${{ runner.os }}-${{ runner.arch }}-nix-v6-${{ hashFiles('tooling/direnv/devenv.yaml', 'tooling/direnv/devenv.nix', 'tooling/direnv/devenv.smoo.nix', 'tooling/direnv/devenv.lock') }}
220
- restore-prefixes-first-match: ${{ runner.os }}-${{ runner.arch }}-nix-v6-
273
+ primary-key: ${{ runner.os }}-${{ runner.arch }}-nix-v7-${{ hashFiles('tooling/direnv/devenv.lock', 'tooling/direnv/devenv.yaml') }}-${{ hashFiles('tooling/direnv/devenv.nix', 'tooling/direnv/devenv.smoo.nix', 'tooling/direnv/nixpkgs-overlay/**') }}
274
+ # prettier-ignore
275
+ restore-prefixes-first-match: ${{ runner.os }}-${{ runner.arch }}-nix-v7-${{ hashFiles('tooling/direnv/devenv.lock', 'tooling/direnv/devenv.yaml') }}-
221
276
  gc-max-store-size: 1G
222
277
 
223
278
  # cache-nix-action unpacks through sudo, so the directory it creates on the
@@ -245,11 +300,12 @@ runs:
245
300
  name: devenv
246
301
 
247
302
  # A host runner's devenv belongs to its image, so install-devenv accepts
248
- # whatever is on PATH there. On an ephemeral runner the devenv came out of a
249
- # cache this workflow wrote, so it is held to devenv.lock's rev: the store
250
- # cache restores ~/.nix-profile wholesale and a prefix match hands the job
251
- # the CLI of whichever run last populated the key, which outlived a lock bump
252
- # until the check existed.
303
+ # whatever is on PATH there. On an ephemeral runner it is held to
304
+ # devenv.lock's rev. The store cache once restored ~/.nix-profile, and a
305
+ # prefix match handed the job the CLI of whichever run last populated the
306
+ # key, which outlived a lock bump until the check existed. It now restores
307
+ # no profiles, and only a store saved from the same pins (devenv.lock,
308
+ # devenv.yaml).
253
309
  - name: 🧰 Install devenv
254
310
  shell: bash
255
311
  working-directory: ${{ env.DEVENV_WORKDIR }}/tooling/direnv
package/nextest.toml CHANGED
@@ -1,5 +1,5 @@
1
1
  # Injected by @smoothbricks/nx-plugin as `--config-file` on inferred cargo-test
2
- # package targets. `period` matches bun's `--timeout=30000`. A slow-timeout here
2
+ # package targets. A 30 s `period` names a slow test early. A slow-timeout here
3
3
  # only warns: nextest prints a `SLOW` line naming the test every period, and
4
4
  # never kills it. The run's no-progress bound (`idleTimeoutMs`, README "Bounded
5
5
  # Test Targets") ends a test that never returns, and names it from those lines.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.4.27",
3
+ "version": "0.4.29",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -68,6 +68,11 @@
68
68
  "import": "./dist/test-timings.js",
69
69
  "default": "./dist/test-timings.js"
70
70
  },
71
+ "./graph-input-contract": {
72
+ "types": "./dist/graph-input-contract.d.ts",
73
+ "import": "./dist/graph-input-contract.js",
74
+ "default": "./dist/graph-input-contract.js"
75
+ },
71
76
  "./ensure-built": {
72
77
  "types": "./dist/ensure-built.d.ts",
73
78
  "import": "./dist/ensure-built.js",
@@ -203,7 +208,7 @@
203
208
  "test-shard1": {
204
209
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
205
210
  "options": {
206
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=1/4 --path-ignore-patterns='**/*-host.test.ts'",
211
+ "command": "bun test --timeout=0 --timings=test-timings.json --shard=1/4 --path-ignore-patterns='**/*-host.test.ts'",
207
212
  "cwd": "{projectRoot}",
208
213
  "idleTimeoutMs": 180000,
209
214
  "killAfterMs": 10000
@@ -212,7 +217,7 @@
212
217
  "test-shard2": {
213
218
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
214
219
  "options": {
215
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=2/4 --path-ignore-patterns='**/*-host.test.ts'",
220
+ "command": "bun test --timeout=0 --timings=test-timings.json --shard=2/4 --path-ignore-patterns='**/*-host.test.ts'",
216
221
  "cwd": "{projectRoot}",
217
222
  "idleTimeoutMs": 180000,
218
223
  "killAfterMs": 10000
@@ -221,7 +226,7 @@
221
226
  "test-shard3": {
222
227
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
223
228
  "options": {
224
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=3/4 --path-ignore-patterns='**/*-host.test.ts'",
229
+ "command": "bun test --timeout=0 --timings=test-timings.json --shard=3/4 --path-ignore-patterns='**/*-host.test.ts'",
225
230
  "cwd": "{projectRoot}",
226
231
  "idleTimeoutMs": 180000,
227
232
  "killAfterMs": 10000
@@ -230,7 +235,7 @@
230
235
  "test-shard4": {
231
236
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
232
237
  "options": {
233
- "command": "bun test --timeout=30000 --timings=test-timings.json --shard=4/4 --path-ignore-patterns='**/*-host.test.ts'",
238
+ "command": "bun test --timeout=0 --timings=test-timings.json --shard=4/4 --path-ignore-patterns='**/*-host.test.ts'",
234
239
  "cwd": "{projectRoot}",
235
240
  "idleTimeoutMs": 180000,
236
241
  "killAfterMs": 10000
@@ -247,7 +252,7 @@
247
252
  }
248
253
  ],
249
254
  "options": {
250
- "command": "bun test --timeout=30000 ./src/executors/bounded-exec/ram-temp-host.test.ts ./src/executors/bounded-exec/executor-host.test.ts",
255
+ "command": "bun test --timeout=0 ./src/executors/bounded-exec/ram-temp-host.test.ts ./src/executors/bounded-exec/executor-host.test.ts",
251
256
  "cwd": "{projectRoot}",
252
257
  "env": {
253
258
  "COWSHED_EXECUTABLE": "{workspaceRoot}/packages/cowshed/bin/cowshed"
@@ -42,6 +42,12 @@ const repositoryRoot = join(import.meta.dir, '../../../..');
42
42
  * daemons of one workspace bind two paths. With the directory named, they bind
43
43
  * one: a test whose subject is two daemons on two socket paths names a second
44
44
  * directory for the second. Building the environment publishes nothing.
45
+ *
46
+ * NX_NATIVE_FILE_CACHE_DIRECTORY is the fixture's own too. Nx loads its native
47
+ * binding from a copy in that cache, by default `/tmp/.nx/<uid>/native-cache`,
48
+ * which every Nx on the host shares and any `nx reset` deletes. A load that loses
49
+ * that race falls back to Nx's WASI binding without a word, and fails later on
50
+ * what WASI lacks (`FileLock is not a constructor`, from a task output lease).
45
51
  */
46
52
  export function fixtureNxEnv(workspace: string, socketDirectory: string): Record<string, string> {
47
53
  const env: Record<string, string> = {};
@@ -59,6 +65,7 @@ export function fixtureNxEnv(workspace: string, socketDirectory: string): Record
59
65
  NX_SOCKET_DIR: socketDirectory,
60
66
  NX_WORKSPACE_DATA_DIRECTORY: join(workspace, '.nx/workspace-data'),
61
67
  NX_CACHE_DIRECTORY: join(workspace, '.nx/cache'),
68
+ NX_NATIVE_FILE_CACHE_DIRECTORY: join(workspace, '.nx/native-file-cache'),
62
69
  };
63
70
  }
64
71
 
@@ -0,0 +1,174 @@
1
+ /**
2
+ * A fixture's own copy of the repository's Nx installation, and the check that nothing wrote into it.
3
+ *
4
+ * The graph witness binds node stamps (ctime included) of every file in the closure of Nx, this plugin and
5
+ * TypeScript (README "Ancestor directories bind..."). Linked from the repository, that closure is the host's: on CI
6
+ * its files are hardlinks in the shared Bun store, and any other task that installs, restores or cleans changes their
7
+ * link count, so their ctime, so a fixture's installation identity, between two calls of one test. A fixture must not
8
+ * take an input it does not own.
9
+ *
10
+ * So the closure is copied, exactly as the witness's own census resolves it in the repository: each package once,
11
+ * with the census's own exclusions (`node_modules`, `.git`, `.nx`), each dependency edge relinked beside its copy as
12
+ * Bun's isolated layout does, the top-level packages' bins in `.bin`. Every copy is a new inode, cloned where the
13
+ * volume allows and written otherwise, so no link count is shared with anything outside its owner.
14
+ *
15
+ * A test file makes one copy, on first use, shared by its fixtures; its `afterAll` retires it, failing the suite and
16
+ * naming the changed nodes if any fixture wrote into it.
17
+ */
18
+ import { constants } from 'node:fs';
19
+ import { cp, mkdir, readFile, rm, symlink } from 'node:fs/promises';
20
+ import { basename, dirname, join, relative } from 'node:path';
21
+ import { expandOutputs } from 'nx/src/native';
22
+ import { readModulePackageJson } from 'nx/src/utils/package-json';
23
+ import typia from 'typia';
24
+ import {
25
+ type GraphInstallationCensus,
26
+ graphInstallationCensus,
27
+ graphInstallationIdentity,
28
+ } from '../ensure-built-witness.js';
29
+ import { nxFixtureRoot } from './fixture-nx-env.js';
30
+
31
+ const repositoryRoot = join(import.meta.dir, '../../../..');
32
+
33
+ /** The configuration the census resolves: Nx, this plugin and TypeScript. */
34
+ const CENSUS_NX_JSON = { plugins: ['@smoothbricks/nx-plugin'] };
35
+
36
+ /** An installation made under `root`, and its identity when the copy was made. */
37
+ interface OwnedInstallation {
38
+ readonly root: string;
39
+ readonly identity: string;
40
+ }
41
+
42
+ /** The graph witness's installation identity resolved from `root`; an unproved installation fails loudly. */
43
+ function installationIdentity(root: string): string {
44
+ let unproved = 'no detail';
45
+ const identity = graphInstallationIdentity(
46
+ root,
47
+ CENSUS_NX_JSON,
48
+ readModulePackageJson,
49
+ expandOutputs,
50
+ null,
51
+ (detail) => {
52
+ unproved = detail;
53
+ },
54
+ );
55
+ if (identity === null) throw new Error(`the Nx installation resolved from ${root} is unproved: ${unproved}`);
56
+ return identity;
57
+ }
58
+
59
+ /** Copy the repository's installation closure into `root/node_modules`; `root` is an empty directory the caller owns.
60
+ *
61
+ * Only the closure is read from the repository, never its proof: the repository's installation is the host's, whose
62
+ * shared store other tasks relink while the census reads it, which changes node stamps and would make every test that
63
+ * copies it fail for the host's work rather than its own. The copy, which the fixture owns, is what gets proved.
64
+ */
65
+ async function makeOwnedInstallation(root: string): Promise<OwnedInstallation> {
66
+ let unread = 'no detail';
67
+ const census = graphInstallationCensus(
68
+ repositoryRoot,
69
+ CENSUS_NX_JSON,
70
+ readModulePackageJson,
71
+ expandOutputs,
72
+ null,
73
+ (detail) => {
74
+ unread = detail;
75
+ },
76
+ );
77
+ if (census === null) throw new Error(`the Nx installation closure of ${repositoryRoot} cannot be read: ${unread}`);
78
+ const { resolutions } = census;
79
+ const modules = join(root, 'node_modules');
80
+ // Each source package root's copy, inside a store directory whose node_modules also holds its dependency links.
81
+ const copies = new Map<
82
+ string,
83
+ { readonly store: string; readonly copy: string; readonly bin: string | Record<string, string> | undefined }
84
+ >();
85
+ for (const [, , manifest] of resolutions) {
86
+ if (manifest === null || copies.has(dirname(manifest))) continue;
87
+ const { name, bin } = typia.json.assertParse<{ name: string; bin?: string | Record<string, string> }>(
88
+ await readFile(manifest, 'utf8'),
89
+ );
90
+ const store = join(modules, '.store', String(copies.size), 'node_modules');
91
+ copies.set(dirname(manifest), { store, copy: join(store, name), bin });
92
+ }
93
+ const copyOf = (source: string) => {
94
+ const copied = copies.get(source);
95
+ if (copied === undefined) throw new Error(`${source} resolves dependencies but is not in the census`);
96
+ return copied;
97
+ };
98
+ await Promise.all(
99
+ [...copies].map(([source, { copy }]) =>
100
+ cp(source, copy, {
101
+ recursive: true,
102
+ verbatimSymlinks: true,
103
+ mode: constants.COPYFILE_FICLONE,
104
+ filter: (path) => path === source || !['node_modules', '.git', '.nx'].includes(basename(path)),
105
+ }),
106
+ ),
107
+ );
108
+ for (const [from, name, manifest] of resolutions) {
109
+ if (manifest === null) continue;
110
+ const link = join(from === repositoryRoot ? modules : copyOf(from).store, name);
111
+ await mkdir(dirname(link), { recursive: true });
112
+ await symlink(relative(dirname(link), copyOf(dirname(manifest)).copy), link, 'dir');
113
+ if (from !== repositoryRoot) continue;
114
+ const { bin } = copyOf(dirname(manifest));
115
+ const commands = typeof bin === 'string' ? { [basename(name)]: bin } : (bin ?? {});
116
+ for (const [command, path] of Object.entries(commands)) {
117
+ await mkdir(join(modules, '.bin'), { recursive: true });
118
+ await symlink(relative(join(modules, '.bin'), join(link, path)), join(modules, '.bin', command));
119
+ }
120
+ }
121
+ return { root, identity: installationIdentity(root) };
122
+ }
123
+
124
+ /**
125
+ * Remove an installation, failing, with the changed nodes named, if its identity is no longer the one it was made
126
+ * with: the proof that its sharers only read it.
127
+ */
128
+ async function retireOwnedInstallation({ root, identity }: OwnedInstallation): Promise<void> {
129
+ try {
130
+ const retired = installationIdentity(root);
131
+ if (retired === identity) return;
132
+ const entries = (census: string) => {
133
+ const { nodes, files } = typia.json.assertParse<GraphInstallationCensus>(census);
134
+ return new Set([
135
+ ...nodes.map(({ path, stamp }) => `${path} ${stamp}`),
136
+ ...files.map(({ path, sha256 }) => `${path} ${sha256}`),
137
+ ]);
138
+ };
139
+ const made = entries(identity);
140
+ const now = entries(retired);
141
+ const changed = [
142
+ ...[...made].filter((entry) => !now.has(entry)).map((entry) => `- ${entry}`),
143
+ ...[...now].filter((entry) => !made.has(entry)).map((entry) => `+ ${entry}`),
144
+ ];
145
+ throw new Error(`a fixture changed the installation it shares, in ${root}:\n${changed.slice(0, 20).join('\n')}`);
146
+ } finally {
147
+ await rm(root, { recursive: true, force: true });
148
+ }
149
+ }
150
+
151
+ /** One test file's installation: made on first use and shared by its fixtures, retired by the file's `afterAll`. */
152
+ export interface TestFileInstallation {
153
+ /** The `node_modules` a fixture workspace links. */
154
+ readonly nodeModules: () => Promise<string>;
155
+ /** Fails if a fixture wrote into the copy; a file that never used it has nothing to retire. */
156
+ readonly retire: () => Promise<void>;
157
+ }
158
+
159
+ /**
160
+ * The installation one test file owns, in a fixture root named by `prefix`. Call once per file, at module scope:
161
+ * Bun runs many test files in one process, and each must own its copy.
162
+ */
163
+ export function testFileInstallation(prefix: string): TestFileInstallation {
164
+ let made: Promise<OwnedInstallation> | undefined;
165
+ return {
166
+ nodeModules: async () => {
167
+ made ??= nxFixtureRoot(prefix).then(makeOwnedInstallation);
168
+ return join((await made).root, 'node_modules');
169
+ },
170
+ retire: async () => {
171
+ if (made !== undefined) await retireOwnedInstallation(await made);
172
+ },
173
+ };
174
+ }
@@ -106,7 +106,7 @@ it('names the failed dependency Nx recorded in cacheDir, not the checkout-local
106
106
  if (published) await retireFixtureSocketDirectory(workspace);
107
107
  await rm(root, { recursive: true, force: true });
108
108
  }
109
- }, 90_000);
109
+ });
110
110
 
111
111
  function nxPath(script: string, env: NodeJS.ProcessEnv): string {
112
112
  const printed = spawnSync('node', ['-e', script], { cwd: repositoryRoot, env, encoding: 'utf8' });
@@ -9,9 +9,9 @@ import {
9
9
  BOUNDED_TEST_EXECUTOR,
10
10
  BOUNDED_TEST_IDLE_TIMEOUT_MS,
11
11
  BOUNDED_TEST_KILL_AFTER_MS,
12
- BOUNDED_TEST_PER_TEST_TIMEOUT_MS,
13
12
  type BoundedTestPolicyPackageJson,
14
13
  type BoundedTestPolicyProjectJson,
14
+ BUN_TEST_TIMEOUT_FLAG,
15
15
  boundedTestScriptAlias,
16
16
  checkBoundedTestTargetPolicy,
17
17
  checkWorkspaceBoundedTestTargetPolicy,
@@ -21,7 +21,7 @@ import {
21
21
  } from './bounded-test-policy.js';
22
22
  import type { ResolvedProjectTargets } from './package-target-policy.js';
23
23
 
24
- const TIMEOUT_FLAG = `--timeout=${BOUNDED_TEST_PER_TEST_TIMEOUT_MS}`;
24
+ const TIMEOUT_FLAG = BUN_TEST_TIMEOUT_FLAG;
25
25
  const BOUNDED_POLICY_MESSAGE = `nx.targets.test must use ${BOUNDED_TEST_EXECUTOR} or delegate through no-op targets to bounded test execution`;
26
26
 
27
27
  describe('bounded test target policy', () => {
@@ -226,37 +226,51 @@ describe('bounded test target policy', () => {
226
226
  }
227
227
  });
228
228
 
229
- it("accepts explicit Bun per-test timeouts up to each bounded leg's progress bound", () => {
229
+ it('accepts a bounded bun leg only when it deletes Bun per-test deadline', () => {
230
230
  const packageJson: BoundedTestPolicyPackageJson = {
231
231
  nx: { targets: { test: { executor: 'nx:noop', dependsOn: ['napi-test'] } } },
232
232
  };
233
- const check = (command: string, idleTimeoutMs = 600_000) => {
233
+ const check = (command: string) => {
234
234
  const resolvedProject = resolvedAggregateProject();
235
235
  resolvedProject.targetOptions = new Map([
236
- ['napi-test', { command, cwd: '{projectRoot}', idleTimeoutMs, killAfterMs: BOUNDED_TEST_KILL_AFTER_MS }],
236
+ [
237
+ 'napi-test',
238
+ { command, cwd: '{projectRoot}', idleTimeoutMs: 600_000, killAfterMs: BOUNDED_TEST_KILL_AFTER_MS },
239
+ ],
237
240
  ]);
238
241
  return checkBoundedTestTargetPolicy(packageJson, { projectName: 'cowshed', resolvedProject });
239
242
  };
240
- expect(check('bun test --timeout=600000')).toBe(true);
241
- expect(check('bun test --timeout 600000')).toBe(true);
242
- expect(check('bun test --timeout=1')).toBe(true);
243
- expect(check('bun test --timeout=30000', 30_000)).toBe(true);
243
+ expect(TIMEOUT_FLAG).toBe('--timeout=0');
244
+ expect(check(`bun test ${TIMEOUT_FLAG}`)).toBe(true);
245
+ expect(check(`bun test --config=../bunfig.toml ${TIMEOUT_FLAG} launcher.test.ts`)).toBe(true);
244
246
  for (const command of [
245
247
  'bun test',
246
248
  'bun test --timeout',
247
- 'bun test --timeout=0',
248
- 'bun test --timeout=-1',
249
- 'bun test --timeout=1.5',
250
- 'bun test --timeout=bad',
251
- 'bun test --timeout=9007199254740992',
252
- 'bun test --timeout=600001',
253
- 'bun test --timeout=30000 --timeout=600001',
254
- 'bun test --timeout=30000 --timeout',
255
- 'bun test --timeout=30000 --timeout=',
249
+ 'bun test --timeout=',
250
+ 'bun test --timeout 0',
251
+ 'bun test --timeout=600000',
252
+ 'bun test --timeout=30000',
253
+ `bun test ${TIMEOUT_FLAG} --timeout=30000`,
254
+ `bun test ${TIMEOUT_FLAG} --timeout`,
256
255
  ]) {
257
256
  expect(check(command)).toBe(false);
258
257
  }
259
- expect(check('bun test --timeout=600000', BOUNDED_TEST_IDLE_TIMEOUT_MS)).toBe(false);
258
+ });
259
+
260
+ it('lets a test outlive Bun default deadline under the flag the policy writes', async () => {
261
+ const scratch = await mkdtemp(join(tmpdir(), 'bun-no-deadline-'));
262
+ try {
263
+ const testFile = join(scratch, 'slow.test.ts');
264
+ // Bun's deadline is real time, so only a real wait past 5000 ms shows the flag deletes it.
265
+ await writeFile(
266
+ testFile,
267
+ "import { test } from 'bun:test';\ntest('outlives 5000 ms', () => Bun.sleep(5_200));\n",
268
+ );
269
+ const run = Bun.spawnSync([process.execPath, 'test', TIMEOUT_FLAG, testFile], { cwd: scratch });
270
+ expect({ exitCode: run.exitCode, stderr: run.stderr.toString() }).toMatchObject({ exitCode: 0 });
271
+ } finally {
272
+ await rm(scratch, { recursive: true, force: true });
273
+ }
260
274
  });
261
275
 
262
276
  it('checks every test leg selected by Nx target wildcards', () => {
@@ -430,13 +444,13 @@ describe('bounded test target policy', () => {
430
444
  expect(resolveTestCommand(packageJson)).toBe(`bun test ${TIMEOUT_FLAG}`);
431
445
  });
432
446
 
433
- it('idempotently appends --timeout to bare bun test commands', () => {
447
+ it('idempotently writes the no-deadline --timeout into bare bun test commands', () => {
434
448
  expect(ensureBunTestTimeoutFlag('bun test')).toBe(`bun test ${TIMEOUT_FLAG}`);
435
449
  expect(ensureBunTestTimeoutFlag('bun test --pass-with-no-tests')).toBe(
436
450
  `bun test ${TIMEOUT_FLAG} --pass-with-no-tests`,
437
451
  );
438
452
  expect(ensureBunTestTimeoutFlag(`bun test ${TIMEOUT_FLAG}`)).toBe(`bun test ${TIMEOUT_FLAG}`);
439
- expect(ensureBunTestTimeoutFlag('bun test --timeout=10')).toBe(`bun test ${TIMEOUT_FLAG}`);
453
+ expect(ensureBunTestTimeoutFlag('bun test --timeout=30000')).toBe(`bun test ${TIMEOUT_FLAG}`);
440
454
  expect(ensureBunTestTimeoutFlag('bun test --timeout 10 --bail')).toBe(`bun test ${TIMEOUT_FLAG} --bail`);
441
455
  // Non-bun-test commands are left alone (vitest, custom runners, etc.).
442
456
  expect(ensureBunTestTimeoutFlag('vitest run')).toBe('vitest run');
@@ -532,7 +546,7 @@ describe('bounded test target policy', () => {
532
546
  const shard = {
533
547
  executor: BOUNDED_TEST_EXECUTOR,
534
548
  options: {
535
- command: 'bun test --timeout=600000 --shard=1/2',
549
+ command: `bun test ${TIMEOUT_FLAG} --shard=1/2`,
536
550
  cwd: '{projectRoot}',
537
551
  idleTimeoutMs: 600_000,
538
552
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
@@ -17,15 +17,18 @@ export const BOUNDED_TEST_EXECUTOR = '@smoothbricks/nx-plugin:bounded-exec';
17
17
  * A test target's one bound: the `idleTimeoutMs` with which no test may go unfinished, the hang backstop of
18
18
  * specs/cowshed/08_testing.md. It is no wall-clock ceiling: a suite that keeps finishing tests runs as long as it
19
19
  * needs. It is the longest any single test may run, so it stays above every slow-timeout class in the plugin's
20
- * nextest.toml and every bun `--timeout`.
20
+ * nextest.toml; a bun leg has no per-test deadline of its own (`BUN_TEST_TIMEOUT_FLAG`).
21
21
  */
22
22
  export const BOUNDED_TEST_IDLE_TIMEOUT_MS = 180_000;
23
23
  export const BOUNDED_TEST_KILL_AFTER_MS = 10_000;
24
- // Per-test timeout passed to `bun test --timeout=<ms>`. Bun's default is
25
- // 5000ms which is too tight for git-fixture tests on slower CI runners
26
- // (Actions). The bunfig.toml `[test] timeout` key is silently ignored by
27
- // Bun — the only working surfaces are this CLI flag and `setDefaultTimeout()`.
28
- export const BOUNDED_TEST_PER_TEST_TIMEOUT_MS = 30_000;
24
+ /**
25
+ * Deletes Bun's per-test deadline: 5000 ms unless the command sets one, and Bun ignores a bunfig `[test] timeout`, so
26
+ * the flag is the one place to set it. `0` means no deadline (measured on the pinned Bun 1.4.2: a test blocked 12 s in
27
+ * `spawnSync` and one sleeping 7 s both pass under `--timeout=0`). A test waits for the event it is waiting for, and
28
+ * the leg's `idleTimeoutMs` ends a test that never returns; no per-test bound kills a test, however long a loaded host
29
+ * makes its work take (specs/cowshed/08_testing.md).
30
+ */
31
+ export const BUN_TEST_TIMEOUT_FLAG = '--timeout=0';
29
32
 
30
33
  export interface BoundedTestPolicyPackageJson {
31
34
  name?: string;
@@ -428,7 +431,7 @@ function isBoundedExecutionTarget(executor: unknown, rawOptions: unknown, allowe
428
431
  // A test leg is bounded by progress alone: a wall-clock ceiling fails a suite that is only slow.
429
432
  rawOptions.timeoutMs === undefined &&
430
433
  isPositiveSafeInteger(rawOptions.idleTimeoutMs) &&
431
- bunTestTimeoutIsBounded(command, rawOptions.idleTimeoutMs) &&
434
+ bunTestHasNoDeadline(command) &&
432
435
  typeof rawOptions.cwd === 'string' &&
433
436
  // `bun test` walks its working directory looking for test files, so it must start where that walk is cheap: the
434
437
  // project root or its `src/`. Any other command names what it runs and has no walk to bound. A cargo workspace's
@@ -439,21 +442,14 @@ function isBoundedExecutionTarget(executor: unknown, rawOptions: unknown, allowe
439
442
  );
440
443
  }
441
444
 
442
- /** A bun leg's per-test `--timeout` must fire before the leg's progress bound would. */
443
- function bunTestTimeoutIsBounded(command: string, idleTimeoutMs: number): boolean {
445
+ /** A bun leg deletes Bun's per-test deadline with `BUN_TEST_TIMEOUT_FLAG` and sets no other. */
446
+ function bunTestHasNoDeadline(command: string): boolean {
444
447
  if (!BUN_TEST_PREFIX.test(command)) {
445
448
  return true;
446
449
  }
447
450
  let found = false;
448
- for (const match of command.matchAll(/(?:^|\s)--timeout(?==|\s|$)(?:=(\S*)|\s+(\S+))?/g)) {
449
- const value = match[1] ?? match[2];
450
- const perTestTimeoutMs = Number(value);
451
- if (
452
- value === undefined ||
453
- !/^\d+$/.test(value) ||
454
- !isPositiveSafeInteger(perTestTimeoutMs) ||
455
- perTestTimeoutMs > idleTimeoutMs
456
- ) {
451
+ for (const match of command.matchAll(/(?:^|\s)(--timeout(?==|\s|$)\S*)/g)) {
452
+ if (match[1] !== BUN_TEST_TIMEOUT_FLAG) {
457
453
  return false;
458
454
  }
459
455
  found = true;
@@ -605,23 +601,19 @@ function resolveTargetCommand(existingTarget: unknown): string | null {
605
601
  const BUN_TEST_PREFIX = /^bun\s+test(?=\s|$)/;
606
602
  const EXISTING_BUN_TIMEOUT = /(^|\s)--timeout(?:=|\s+)(\S+)/;
607
603
 
608
- // Bun's `[test] timeout` bunfig key is silently ignored — only the CLI flag
609
- // and `setDefaultTimeout()` actually take effect. Normalize every `bun test`
610
- // command so the policy enforces the workspace per-test timeout in the one
611
- // place where Bun will honor it.
612
- export function ensureBunTestTimeoutFlag(command: string, timeoutMs = BOUNDED_TEST_PER_TEST_TIMEOUT_MS): string {
604
+ // Normalize every `bun test` command to `BUN_TEST_TIMEOUT_FLAG`, the one place Bun honors a per-test bound.
605
+ export function ensureBunTestTimeoutFlag(command: string): string {
613
606
  if (!BUN_TEST_PREFIX.test(command)) {
614
607
  return command;
615
608
  }
616
- const flag = `--timeout=${timeoutMs}`;
617
609
  const existing = EXISTING_BUN_TIMEOUT.exec(command);
618
610
  if (!existing) {
619
- return command.replace(BUN_TEST_PREFIX, `bun test ${flag}`);
611
+ return command.replace(BUN_TEST_PREFIX, () => `bun test ${BUN_TEST_TIMEOUT_FLAG}`);
620
612
  }
621
- if (existing[2] === String(timeoutMs)) {
613
+ if (existing[0].trimStart() === BUN_TEST_TIMEOUT_FLAG) {
622
614
  return command;
623
615
  }
624
- return command.replace(EXISTING_BUN_TIMEOUT, `${existing[1]}${flag}`);
616
+ return command.replace(EXISTING_BUN_TIMEOUT, (_match, lead: string) => `${lead}${BUN_TEST_TIMEOUT_FLAG}`);
625
617
  }
626
618
 
627
619
  function isPackageTestScriptRunnerCommand(command: string): boolean {
@@ -67,7 +67,7 @@ describe('Bun bootstrap imports', () => {
67
67
  expect(typeof policy.BOUNDED_TEST_EXECUTOR).toBe('string');
68
68
  expect(typeof policy.BOUNDED_TEST_IDLE_TIMEOUT_MS).toBe('number');
69
69
  expect(typeof policy.BOUNDED_TEST_KILL_AFTER_MS).toBe('number');
70
- expect(typeof policy.BOUNDED_TEST_PER_TEST_TIMEOUT_MS).toBe('number');
70
+ expect(typeof policy.BUN_TEST_TIMEOUT_FLAG).toBe('string');
71
71
  });
72
72
 
73
73
  it('imports workspace-config-policy', async () => {