@smoothbricks/nx-plugin 0.6.2 → 0.7.0

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 (177) hide show
  1. package/README.md +417 -171
  2. package/dist/.build-inputs.json +39 -28
  3. package/dist/bin/smoo-nx-go-test-build.d.ts +3 -0
  4. package/dist/bin/smoo-nx-go-test-build.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-go-test-build.js +79 -0
  6. package/dist/bin/smoo-nx-go-test-run.d.ts +3 -0
  7. package/dist/bin/smoo-nx-go-test-run.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-go-test-run.js +129 -0
  9. package/dist/bin/smoo-nx-publish.d.ts +3 -0
  10. package/dist/bin/smoo-nx-publish.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-publish.js +3 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +9 -8
  15. package/dist/cargo-retention-hook.d.ts +6 -2
  16. package/dist/cargo-retention-hook.d.ts.map +1 -1
  17. package/dist/cargo-retention-hook.js +13 -7
  18. package/dist/cargo-workspace.d.ts +10 -20
  19. package/dist/cargo-workspace.d.ts.map +1 -1
  20. package/dist/cargo-workspace.js +12 -22
  21. package/dist/cross-check-policy.d.ts +2 -2
  22. package/dist/cross-check-policy.js +2 -2
  23. package/dist/deploy-policy.d.ts +6 -0
  24. package/dist/deploy-policy.d.ts.map +1 -1
  25. package/dist/deploy-policy.js +11 -0
  26. package/dist/eslint-file-set.d.ts +4 -1
  27. package/dist/eslint-file-set.d.ts.map +1 -1
  28. package/dist/eslint-sources.d.ts +25 -0
  29. package/dist/eslint-sources.d.ts.map +1 -0
  30. package/dist/eslint-sources.js +99 -0
  31. package/dist/executors/all-verdicts/executor.d.ts +2 -1
  32. package/dist/executors/all-verdicts/executor.d.ts.map +1 -1
  33. package/dist/executors/all-verdicts/executor.js +48 -2
  34. package/dist/executors/all-verdicts/schema.d.ts +13 -0
  35. package/dist/executors/all-verdicts/schema.d.ts.map +1 -1
  36. package/dist/executors/all-verdicts/schema.js +7 -0
  37. package/dist/executors/bounded-exec/bounds.d.ts +57 -8
  38. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  39. package/dist/executors/bounded-exec/bounds.js +100 -11
  40. package/dist/executors/bounded-exec/executor.d.ts +2 -1
  41. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  42. package/dist/executors/bounded-exec/executor.js +289 -34
  43. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +2 -0
  44. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  45. package/dist/executors/bounded-exec/hang-diagnostics.js +2 -2
  46. package/dist/executors/bounded-exec/mbx-pool.d.ts +56 -10
  47. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  48. package/dist/executors/bounded-exec/mbx-pool.js +145 -11
  49. package/dist/executors/bounded-exec/mbx-queue.d.ts +30 -0
  50. package/dist/executors/bounded-exec/mbx-queue.d.ts.map +1 -0
  51. package/dist/executors/bounded-exec/mbx-queue.js +229 -0
  52. package/dist/executors/bounded-exec/progress.d.ts +9 -2
  53. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  54. package/dist/executors/bounded-exec/progress.js +151 -25
  55. package/dist/executors/bounded-exec/runner-sizing.d.ts +40 -2
  56. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  57. package/dist/executors/bounded-exec/runner-sizing.js +55 -4
  58. package/dist/executors/bounded-exec/runtime-pin.js +1 -1
  59. package/dist/executors/bounded-exec/test-result-writer.d.ts +30 -0
  60. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/test-result-writer.js +126 -0
  62. package/dist/executors/bounded-exec/test-results.d.ts +33 -0
  63. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -0
  64. package/dist/executors/bounded-exec/test-results.js +33 -0
  65. package/dist/executors/bounded-exec/verdict.d.ts +26 -2
  66. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  67. package/dist/executors/bounded-exec/verdict.js +108 -4
  68. package/dist/executors/wrangler-deploy/deploy-hash.d.ts +10 -0
  69. package/dist/executors/wrangler-deploy/deploy-hash.d.ts.map +1 -0
  70. package/dist/executors/wrangler-deploy/deploy-hash.js +14 -0
  71. package/dist/executors/wrangler-deploy/executor.d.ts +24 -0
  72. package/dist/executors/wrangler-deploy/executor.d.ts.map +1 -0
  73. package/dist/executors/wrangler-deploy/executor.js +43 -0
  74. package/dist/executors/wrangler-deploy/hasher.d.ts +27 -0
  75. package/dist/executors/wrangler-deploy/hasher.d.ts.map +1 -0
  76. package/dist/executors/wrangler-deploy/hasher.js +90 -0
  77. package/dist/executors/wrangler-deploy/schema.d.ts +5 -0
  78. package/dist/executors/wrangler-deploy/schema.d.ts.map +1 -0
  79. package/dist/go-tests.d.ts +30 -0
  80. package/dist/go-tests.d.ts.map +1 -0
  81. package/dist/go-tests.js +43 -0
  82. package/dist/index.d.ts +12 -4
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +338 -295
  85. package/dist/managed-files/files.d.ts.map +1 -1
  86. package/dist/managed-files/files.js +5 -0
  87. package/dist/nx-publish.d.ts +24 -0
  88. package/dist/nx-publish.d.ts.map +1 -0
  89. package/dist/nx-publish.js +150 -0
  90. package/dist/process-group.js +2 -2
  91. package/dist/runtime-input-policy.d.ts +17 -3
  92. package/dist/runtime-input-policy.d.ts.map +1 -1
  93. package/dist/runtime-input-policy.js +4 -4
  94. package/dist/test-timings.d.ts +23 -4
  95. package/dist/test-timings.d.ts.map +1 -1
  96. package/dist/test-timings.js +72 -12
  97. package/dist/tool-bins.d.ts +6 -8
  98. package/dist/tool-bins.d.ts.map +1 -1
  99. package/dist/tool-bins.js +7 -5
  100. package/dist/version-actions.cjs +10 -11
  101. package/dist/version-actions.d.cts.map +1 -1
  102. package/dist/workspace-config-policy.d.ts.map +1 -1
  103. package/dist/workspace-config-policy.js +17 -22
  104. package/dist/workspace-index.d.ts +7 -0
  105. package/dist/workspace-index.d.ts.map +1 -1
  106. package/dist/workspace-index.js +11 -0
  107. package/dist/workspace-manifest.js +3 -3
  108. package/executors.json +7 -6
  109. package/managed/raw/patches/nx@23.2.1.patch +118 -24
  110. package/managed/raw/patches/ttsc@0.34.1.patch +139 -0
  111. package/managed/raw/tooling/devenv +1 -2
  112. package/managed/raw/tooling/direnv/developer-links.ts +124 -51
  113. package/managed/raw/tooling/direnv/devenv.smoo.nix +34 -15
  114. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -10
  115. package/managed/raw/tooling/direnv/installed-bun-links.ts +7 -6
  116. package/managed/raw/tooling/direnv/setup-environment.ts +49 -24
  117. package/managed/raw/tooling/direnv/ttsc-env.sh +8 -6
  118. package/managed/raw/tooling/git-hooks/pinned-revisions-served.ts +252 -0
  119. package/managed/raw/tooling/git-hooks/pre-push.sh +34 -32
  120. package/managed/templates/github/actions/cache-node-modules/action.yml +1 -1
  121. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +12 -11
  122. package/package.json +277 -11
  123. package/runtime/nx-publish/.build-inputs.json +11 -0
  124. package/runtime/nx-publish/cache_adapter.js +45 -0
  125. package/runtime/nx-publish/nx_publish.js +60 -0
  126. package/runtime-input.sh +62 -26
  127. package/src/bin/smoo-nx-go-test-build.ts +83 -0
  128. package/src/bin/smoo-nx-go-test-run.ts +140 -0
  129. package/src/bin/smoo-nx-publish.ts +4 -0
  130. package/src/bounded-test-policy.ts +9 -8
  131. package/src/cargo-retention-hook.ts +16 -10
  132. package/src/cargo-workspace.ts +12 -24
  133. package/src/cross-check-policy.ts +2 -2
  134. package/src/deploy-policy.ts +11 -0
  135. package/src/eslint-file-set.ts +4 -1
  136. package/src/eslint-sources.ts +134 -0
  137. package/src/executors/all-verdicts/executor.ts +58 -3
  138. package/src/executors/all-verdicts/schema.json +4 -0
  139. package/src/executors/all-verdicts/schema.ts +14 -0
  140. package/src/executors/bounded-exec/bounds.ts +132 -15
  141. package/src/executors/bounded-exec/executor.ts +329 -34
  142. package/src/executors/bounded-exec/hang-diagnostics.ts +3 -2
  143. package/src/executors/bounded-exec/mbx-pool.ts +158 -17
  144. package/src/executors/bounded-exec/mbx-queue.ts +170 -0
  145. package/src/executors/bounded-exec/progress.ts +171 -18
  146. package/src/executors/bounded-exec/runner-sizing.ts +73 -7
  147. package/src/executors/bounded-exec/runtime-pin.ts +1 -1
  148. package/src/executors/bounded-exec/test-result-writer.ts +152 -0
  149. package/src/executors/bounded-exec/test-results.ts +39 -0
  150. package/src/executors/bounded-exec/verdict.ts +115 -5
  151. package/src/executors/wrangler-deploy/deploy-hash.ts +15 -0
  152. package/src/executors/wrangler-deploy/executor.ts +63 -0
  153. package/src/executors/wrangler-deploy/hasher.ts +111 -0
  154. package/src/executors/wrangler-deploy/schema.json +16 -0
  155. package/src/executors/wrangler-deploy/schema.ts +4 -0
  156. package/src/go-tests.ts +67 -0
  157. package/src/index.ts +368 -323
  158. package/src/managed-files/files.ts +5 -0
  159. package/src/nx-publish.ts +157 -0
  160. package/src/process-group.ts +2 -2
  161. package/src/runtime-input-policy.ts +4 -4
  162. package/src/test-timings.ts +72 -14
  163. package/src/tool-bins.ts +13 -9
  164. package/src/version-actions.cts +10 -11
  165. package/src/workspace-config-policy.ts +20 -29
  166. package/src/workspace-index.ts +12 -0
  167. package/src/workspace-manifest.ts +3 -3
  168. package/test-timings.json +131 -125
  169. package/dist/executors/clean-outputs/executor.d.ts +0 -26
  170. package/dist/executors/clean-outputs/executor.d.ts.map +0 -1
  171. package/dist/executors/clean-outputs/executor.js +0 -83
  172. package/dist/executors/clean-outputs/schema.d.ts +0 -4
  173. package/dist/executors/clean-outputs/schema.d.ts.map +0 -1
  174. package/src/executors/clean-outputs/executor.ts +0 -131
  175. package/src/executors/clean-outputs/schema.json +0 -15
  176. package/src/executors/clean-outputs/schema.ts +0 -3
  177. /package/dist/executors/{clean-outputs → wrangler-deploy}/schema.js +0 -0
package/src/index.ts CHANGED
@@ -4,10 +4,10 @@ import { createRequire } from 'node:module';
4
4
  import { dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import {
7
- EXTRACTED_BINARIES_METADATA,
8
- EXTRACTED_CARGO_METADATA,
9
- EXTRACTED_TARGET_DIR,
10
- NEXTEST_ARCHIVE_KEY_SUFFIX,
7
+ NEXTEST_BINARIES_BUILD_ARGS,
8
+ NEXTEST_BINARIES_METADATA,
9
+ NEXTEST_BUILD_KEY,
10
+ NEXTEST_CARGO_METADATA,
11
11
  } from '@smoothbricks/nextest-extract';
12
12
  import {
13
13
  type CreateDependencies,
@@ -23,7 +23,6 @@ import {
23
23
  } from 'nx/src/devkit-exports.js';
24
24
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
25
25
  import { parse as parseToml } from 'smol-toml';
26
- import { type ParsedCommandLine, parseJsonConfigFileContent, readConfigFile, sys as typescriptSys } from 'typescript';
27
26
  import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './bounded-test-policy.js';
28
27
  import { refuseOverlappingOutputs } from './build-state-output-policy.js';
29
28
  import { bunLockDependencies, bunLockInput, bunLockNode } from './bun-lock-scope.js';
@@ -43,8 +42,7 @@ import { CARGO_TOOLCHAIN_NAMED_INPUT, cargoRuntimeInput, cargoToolchainInputs }
43
42
  import {
44
43
  type AttributedCargoWorkspacePackage,
45
44
  attributeCargoWorkspacePackages,
46
- CARGO_TEST_ARCHIVE_FILE,
47
- CARGO_TEST_ARCHIVE_TARGET,
45
+ CARGO_TEST_BUILD_TARGET,
48
46
  CARGO_TEST_EXCEPTIONS_SUFFIX,
49
47
  CARGO_TEST_TARGET,
50
48
  type CargoCrossTestTarget,
@@ -78,7 +76,12 @@ import {
78
76
  } from './cross-check-policy.js';
79
77
  import { eslintConfigClosure } from './eslint-config-closure.js';
80
78
  import type { EslintFileSet } from './eslint-file-set.js';
81
- import { ALL_VERDICTS_EXECUTOR } from './executors/all-verdicts/schema.js';
79
+ import { ESLINT_SOURCES_GLOB, eslintSources } from './eslint-sources.js';
80
+ import {
81
+ ALL_VERDICTS_EXECUTOR,
82
+ type AllVerdictsOptions,
83
+ ESLINT_SOURCES_TOKEN,
84
+ } from './executors/all-verdicts/schema.js';
82
85
  import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
83
86
  import { ffiPathProblem } from './executors/scriptc-native/ffi-paths.js';
84
87
  import type { ScriptcNativeFfi } from './executors/scriptc-native/schema.js';
@@ -90,17 +93,20 @@ import {
90
93
  preTasksExecution as preProducerReceipts,
91
94
  } from './producer-receipts.js';
92
95
  import { runtimeInput, shellWord } from './runtime-input.js';
93
- import { isNonSourceDirectory } from './source-directories.js';
94
96
  import { inferredTaskKind, refuseBuildTestDependencies } from './task-graph-policy.js';
95
97
  import { postTasksExecution as postTaskResults, preTasksExecution as preTaskResults } from './task-results.js';
96
- import { SHARD_TIMINGS_EXECUTOR, SHARD_TIMINGS_TARGET, timingsShardedSuite } from './test-timings.js';
98
+ import {
99
+ SHARD_TIMINGS_EXECUTOR,
100
+ SHARD_TIMINGS_TARGET,
101
+ timingsShardedSuite,
102
+ timingsSuiteInputs,
103
+ } from './test-timings.js';
97
104
  import { assertUpstreamBasePrecondition } from './test-walk-policy.js';
98
105
  import { type NativeTools, nativeToolCommand, nativeToolDependsOn, resolveNativeTools } from './tool-bins.js';
99
106
  import {
100
107
  isBuildOutputTargetName,
101
108
  isTestNamespaceTargetName,
102
109
  isTestRunnerTargetName,
103
- PLATFORM_TARGET_GLOBS,
104
110
  RELEASE_CONFIGURATION,
105
111
  } from './workspace-config-policy.js';
106
112
  import { globIndexedFiles } from './workspace-index.js';
@@ -371,9 +377,6 @@ const ESLINT_CONFIG_FILES = [
371
377
  'eslint.config.cts',
372
378
  ];
373
379
 
374
- /** Every JavaScript and TypeScript module kind ESLint is handed. */
375
- const ESLINT_SOURCES_GLOB = '**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}';
376
-
377
380
  /** What ESLint lints in this workspace and what its configuration loads. */
378
381
  interface EslintWorkspace {
379
382
  /** The JavaScript and TypeScript files of Nx's workspace file index. */
@@ -386,14 +389,15 @@ interface EslintWorkspace {
386
389
  * The ESLint sources and config closure of Nx's workspace file index, listed
387
390
  * once per graph computation; `null` when no workspace ESLint config enables ESLint.
388
391
  *
389
- * The ESLint file list is part of the lint target's command, metadata and
390
- * inputs, and Nx hashes the whole target configuration into every task that
391
- * reaches the project. A walk of the tree also listed gitignored generated
392
- * modules a build had left on disk, so every such task's key depended on
393
- * whether a build had run in that checkout: one workspace's graph listed them
394
- * and a fresh fork's did not, which alone re-keyed 197 of 510 gate tasks.
395
- * Drawing the list from the index makes the plugin and the hasher agree on one
396
- * file set.
392
+ * The lists the graph records for a project (its lint target's metadata, and
393
+ * the inputs that name its program files) are drawn from the index, not from a
394
+ * walk of the tree. A walk also listed gitignored generated modules a build had
395
+ * left on disk, so every such task's key depended on whether a build had run in
396
+ * that checkout: one workspace's graph listed them and a fresh fork's did not,
397
+ * which alone re-keyed 197 of 510 gate tasks. Drawing them from the index makes
398
+ * the plugin and the hasher agree on one file set. What the lint command runs
399
+ * on is in no graph: the executor reads it when the command runs
400
+ * (eslint-sources.ts).
397
401
  *
398
402
  * The configs key every lint target with exactly the workspace files they
399
403
  * load (eslint-config-closure.ts): a glob over the directory holding a
@@ -410,18 +414,6 @@ async function eslintWorkspace(workspaceRoot: string): Promise<EslintWorkspace |
410
414
  };
411
415
  }
412
416
 
413
- /**
414
- * Read a tsconfig with this plugin's own TypeScript. `@nx/js`'s readTsConfig does an
415
- * undeclared `require('typescript')` resolved from its own location: where that lands on the
416
- * TypeScript 7 native package (whose entry exports only its version), `sys` is undefined and
417
- * graph construction dies reading `sys.readFile`. The plugin declares TypeScript 6, whose
418
- * `sys` this uses, so the resolution is the one this package's manifest promises.
419
- */
420
- function readTestTsConfig(testConfig: string): ParsedCommandLine {
421
- const readResult = readConfigFile(testConfig, typescriptSys.readFile);
422
- return parseJsonConfigFileContent(readResult.config, typescriptSys, dirname(testConfig));
423
- }
424
-
425
417
  function projectLintCommands(
426
418
  projectRoot: string,
427
419
  workspaceRoot: string,
@@ -430,54 +422,22 @@ function projectLintCommands(
430
422
  const commands: string[] = [];
431
423
  const inputs: string[] = [];
432
424
  let eslintFileSet: EslintFileSet | null = null;
433
- const absoluteProjectRoot = join(workspaceRoot, projectRoot);
434
425
  const quote = (path: string) => `'${path.replaceAll("'", "'\"'\"'")}'`;
435
426
  if (BIOME_CONFIG_FILES.some((name) => existsSync(join(workspaceRoot, name)))) {
436
427
  commands.push(`biome check --files-ignore-unknown=true ${quote(projectRoot)}`);
437
428
  }
438
429
  if (eslint !== null) {
439
- const sourcePrefix = projectRoot === '.' ? 'src/' : `${posix.normalize(projectRoot)}/src/`;
440
- const sourceFiles = new Set<string>();
441
- for (const path of eslint.sources) {
442
- if (
443
- path.startsWith(sourcePrefix) &&
444
- !path.slice(sourcePrefix.length).split('/').slice(0, -1).some(isNonSourceDirectory)
445
- ) {
446
- sourceFiles.add(path);
447
- }
448
- }
449
- const testConfig = join(absoluteProjectRoot, 'tsconfig.test.json');
450
- if (existsSync(testConfig)) {
451
- // A test program can live anywhere the declaration selects, not just src.
452
- // Use the compiler's file set and the existing declaration-chain hasher,
453
- // so inherited includes and files outside this project keep their keys.
454
- const program: ParsedCommandLine = readTestTsConfig(testConfig);
455
- const errors = program.errors.filter(({ code }) => code !== 18003);
456
- if (errors.length > 0) {
457
- throw new Error(
458
- `${testConfig}: ${errors.map(({ code, messageText }) => `TS${code}: ${JSON.stringify(messageText)}`).join('; ')}`,
459
- );
460
- }
461
- inputs.push('{projectRoot}/tsconfig.test.json');
462
- for (const file of program.fileNames) {
463
- const path = relative(workspaceRoot, file).split(sep).join('/');
464
- if (path === '..' || path.startsWith('../') || isAbsolute(path)) {
465
- throw new Error(`${testConfig}: test source ${file} is outside the workspace and cannot be hashed`);
466
- }
467
- // Only a module Nx indexes is linted and keyed. An ignored one is build
468
- // output that a fresh checkout lacks; a JSON file is not ESLint's.
469
- if (!eslint.sources.has(path) || path.split('/').some(isNonSourceDirectory)) continue;
470
- sourceFiles.add(path);
471
- inputs.push(`{workspaceRoot}/${path}`);
472
- }
473
- }
474
- if (sourceFiles.size > 0) {
475
- const files = [...sourceFiles].sort();
476
- eslintFileSet = { command: `eslint ${files.map(quote).join(' ')}`, files };
430
+ const sources = eslintSources(workspaceRoot, projectRoot, eslint.sources);
431
+ inputs.push(...sources.inputs);
432
+ // The command names no file: a graph the daemon serves past a deletion or an addition would hand ESLint a pattern
433
+ // no file matches, or leave a new file unlinted. The all-verdicts executor resolves the token when it runs, and the
434
+ // list beside the command is the file set this graph resolved, for the inspectors that read it.
435
+ if (sources.files.length > 0) {
436
+ eslintFileSet = { command: `eslint ${ESLINT_SOURCES_TOKEN}`, files: sources.files };
477
437
  commands.push(eslintFileSet.command);
478
438
  }
479
439
  }
480
- return { commands, inputs: [...new Set(inputs)], eslintFileSet };
440
+ return { commands, inputs, eslintFileSet };
481
441
  }
482
442
 
483
443
  type NapiArchitecture = 'arm64' | 'x64';
@@ -562,15 +522,33 @@ const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
562
522
  /** The lockfiles of crates no resolved Cargo workspace claims, which have no lock-scope node. */
563
523
  const UNRESOLVED_CARGO_LOCK_INPUT = '{projectRoot}/**/Cargo.lock';
564
524
  /**
565
- * What the uncached `cargo-fetch` reads: the manifests and the lock that name the crates, and the Cargo configuration
566
- * that says where they come from. They key nothing; they are what a producer receipt binds the fetch to. Unnamed, Nx
567
- * plans every file of the project, which for a repository-root project includes its symlinked managed files, and a
568
- * receipt binds no symlink. That workspace's members belong to other projects, so its globs start at the repository root.
525
+ * The files `cargo-fetch` reads: the manifests and the lock that name the crates, and the Cargo configuration that says
526
+ * where they come from. With the registry's state (cargoFetchedInput) they are its key. Unnamed, Nx plans every file of
527
+ * the project, which for a repository-root project includes its symlinked managed files, and a receipt binds no
528
+ * symlink. That workspace's members belong to other projects, so its globs start at the repository root.
569
529
  */
570
530
  function cargoFetchInputs(projectRoot: string): string[] {
571
531
  const base = projectRoot === '.' ? '{workspaceRoot}' : '{projectRoot}';
572
532
  return [`${base}/**/Cargo.toml`, `${base}/**/Cargo.lock`, `${base}/**/.cargo/config.toml`, `!${base}/**/target/**`];
573
533
  }
534
+ /** The locked fetch of one manifest, relative to the project it runs in. */
535
+ function cargoFetchCommand(manifestPath: string): string {
536
+ return manifestPath === 'Cargo.toml' ? CARGO_FETCH_COMMAND : `${CARGO_FETCH_COMMAND} --manifest-path ${manifestPath}`;
537
+ }
538
+ /**
539
+ * Whether the registry holds every manifest's locked graph, as the runtime input that brings CARGO_HOME into
540
+ * `cargo-fetch`'s key: the download lands outside the workspace, so no output can stand for it. `fetched` when an
541
+ * offline fetch of each manifest succeeds, which asks no network and fails on any crate the registry lacks. A registry
542
+ * that lacks one gives a value of its own run (the shell's pid and the time), which no cached run matches, so the fetch
543
+ * runs; a registry that holds them all keys an unchanged lock to its cached run.
544
+ */
545
+ function cargoFetchedInput(projectRoot: string, manifests: readonly string[]): { runtime: string } {
546
+ const offline = manifests.map((manifest) => `${cargoFetchCommand(manifest)} --offline --quiet`).join(' && ');
547
+ return cargoRuntimeInput(
548
+ projectRoot,
549
+ `if { ${offline}; } >/dev/null 2>&1; then echo fetched; else echo "unfetched $$ $(date +%s)"; fi`,
550
+ );
551
+ }
574
552
  /** A full cargo-mutants sweep's wall-clock backstop: a sweep takes hours, and a hung one must still end. */
575
553
  const MUTATION_TIMEOUT_MS = 6 * 60 * 60 * 1000;
576
554
  // The toolchain half of a cargo task's identity lives in its own module
@@ -585,11 +563,22 @@ function fileHashInput(path: string): { runtime: string } {
585
563
  );
586
564
  }
587
565
 
566
+ /**
567
+ * The bytes of a file that arrives from elsewhere, as a runtime input: their SHA-256, streamed, or `absent`. A task
568
+ * that needs the file fails without it, and Nx caches no failure, so no cached run is keyed on `absent`.
569
+ */
570
+ export function arrivedFileHashInput(path: string): { runtime: string } {
571
+ const hash =
572
+ 'const file = Bun.file(process.argv[1]); const hash = new Bun.CryptoHasher("sha256"); ' +
573
+ 'if (!(await file.exists())) console.log("absent"); ' +
574
+ 'else { for await (const chunk of file.stream()) hash.update(chunk); console.log(hash.digest("hex")); }';
575
+ return runtimeInput(`bun -e ${shellWord(hash)} ${shellWord(path)}`);
576
+ }
588
577
  /**
589
578
  * One shell command that runs `steps` in order and stops at the first failure.
590
579
  *
591
- * For a step that CONSUMES what an earlier step produces — the archive needs
592
- * its directory, `wasm-bindgen` reads the `.wasm` that `cargo build` writes.
580
+ * For a step that CONSUMES what an earlier step produces — the test build's
581
+ * metadata needs its directory, `wasm-bindgen` reads the `.wasm` that `cargo build` writes.
593
582
  * The order lives in the command because that is the only place a
594
583
  * producer-consumer pair inside one task can state it: `nx:run-commands`'
595
584
  * `commands` array is a set of independent commands that Nx runs side by side.
@@ -771,75 +760,105 @@ function createCargoWasmTarget(
771
760
  },
772
761
  };
773
762
  }
774
-
775
763
  /**
776
- * The workspace's test binaries, compiled once and packed into one file the
777
- * per-crate runners execute from.
764
+ * The workspace's test binaries, compiled once and run where they were built.
778
765
  *
779
766
  * This is the only cargo BUILD in the test graph. Before it, every per-crate
780
767
  * target ran `nextest run --workspace -E 'package(X)'`, which is a workspace
781
768
  * build with a filter: 32 such tasks on one repository each re-entered cargo,
782
769
  * re-resolved features and chained behind one another so the flocked `target/`
783
- * had a single writer. Reading from an archive removes the build from the run
784
- * entirely — the runners execute one extraction of it and never write cargo's
785
- * `target/` build tree — which is what lets the runners fan out.
770
+ * had a single writer. Running from a reused build removes the build from the
771
+ * run entirely — the runners execute the binaries this build left in Cargo's
772
+ * target directory and never write its build tree — which is what lets the
773
+ * runners fan out.
786
774
  *
787
775
  * It is also the step that keeps compilation out of the bounded test window: a
788
776
  * cold workspace can take many minutes to compile while still making progress,
789
777
  * which is not a property of the tests, and the runners start after it. It is
790
778
  * test work, so no `build` depends on it (a build never consumes test binaries)
791
- * and each target that executes them names the edge itself. There is no separate
792
- * uncached `cargo test --no-run` warm-up: it compiled the same dev units a
793
- * second time, queued on the same `target/` lock.
779
+ * and each target that executes them names the edge itself.
794
780
  *
795
- * Cached because it produces a VALUE: one file, not a mutable build tree Nx
796
- * would have to restore. `--workspace` matches the clippy selection exactly, so
797
- * both gates unify features the same way.
781
+ * Cached because it produces VALUES: nextest's reuse-build metadata, the
782
+ * binaries `cargo nextest list --list-type binaries-only` built (an mbx-cached
783
+ * build) and the `cargo metadata` of the workspace they belong to, which is
784
+ * what `nextest run --binaries-metadata … --cargo-metadata …` reads. The
785
+ * binaries themselves stay in Cargo's target directory, where every build of
786
+ * the workspace keeps its warmth: never in an Nx output, which would restore a
787
+ * multi-GB tree per hit, and never in an archive, which a same-platform run
788
+ * would only unpack again (measured: 290 binaries, 678 MB, 4.6s quiet and 21s
789
+ * in a gate, per archive). A binary's path is cargo's `-C metadata` hash, which
790
+ * ignores source content, so the metadata says which binaries, never which
791
+ * bytes: the build's task hash is its third output, the key, and its last step
792
+ * records that key in the target directory it built. A checkout whose build was
793
+ * a cache hit holds another key, or none, and possibly binaries of an older
794
+ * tree at the very paths the metadata names; each runner's fixture rebuilds
795
+ * there first ({@link nextestRunnerFixture}). The key is also what makes a
796
+ * dependent that hashes this target's outputs see a source change the metadata
797
+ * alone would hide. Only a cross lane, whose binaries are built on one platform
798
+ * and run on another, moves them as an archive
799
+ * ({@link createCargoCrossTestTargets}). `--workspace` matches the clippy
800
+ * selection exactly, so both gates unify features the same way.
798
801
  *
799
802
  * Tests compile the dev profile only, so no test target carries a
800
803
  * RELEASE_CONFIGURATION: Nx forwards a run's configuration down every
801
804
  * `dependsOn` edge to each target that has it, and a release configuration
802
805
  * must never turn the test binaries into release ones nobody runs.
803
806
  *
804
- * The directory and the archive are ONE command: nextest does not create the
805
- * archive's parent, so the archive step consumes what the `mkdir` produced.
806
- * The same command writes the task's hash beside the archive, the key every
807
- * runner's extraction is looked up by (smoo-nx-nextest-extract), and declares it
808
- * an output, so a cache hit restores the key with the archive it names.
807
+ * The directory and the metadata are ONE command: a shell redirect does not
808
+ * create its parent, so the build consumes what the `mkdir` produced. Outside
809
+ * Nx there is no task hash, and a build no task names is refused here rather
810
+ * than by every runner.
809
811
  */
810
- const CARGO_TEST_ARCHIVE_KEY_FILE = `${CARGO_TEST_ARCHIVE_FILE}${NEXTEST_ARCHIVE_KEY_SUFFIX}`;
811
-
812
- function createCargoTestArchiveTarget(projectRoot: string, toolConfig: string): TargetConfiguration {
812
+ function createCargoTestBuildTarget(
813
+ projectRoot: string,
814
+ toolConfig: string,
815
+ nativeTools: NativeTools | null,
816
+ ): TargetConfiguration {
817
+ const helper = nativeToolCommand(nativeTools, projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
813
818
  return {
814
819
  executor: 'nx:run-commands',
815
820
  metadata: CARGO_PRODUCER_METADATA,
816
821
  cache: true,
817
822
  inputs: CARGO_INPUTS,
818
- outputs: [`{projectRoot}/${CARGO_TEST_ARCHIVE_FILE}`, `{projectRoot}/${CARGO_TEST_ARCHIVE_KEY_FILE}`],
823
+ outputs: [
824
+ `{projectRoot}/${NEXTEST_BINARIES_METADATA}`,
825
+ `{projectRoot}/${NEXTEST_CARGO_METADATA}`,
826
+ `{projectRoot}/${NEXTEST_BUILD_KEY}`,
827
+ ],
828
+ dependsOn: nativeToolDependsOn(nativeTools, 'nextest-extract'),
819
829
  options: {
820
830
  command: sequence([
821
- `mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`,
822
- cargoFrozen(
823
- `nextest archive --workspace --archive-file ${CARGO_TEST_ARCHIVE_FILE} --user-config-file none ${toolConfig}`,
824
- ),
825
- // Outside Nx there is no task hash, and an archive no task names is refused here, not by every runner.
831
+ `mkdir -p ${posix.dirname(NEXTEST_BINARIES_METADATA)}`,
832
+ `${nextestBinariesBuild(toolConfig)} > ${NEXTEST_BINARIES_METADATA}`,
833
+ `${cargoFrozen('metadata --format-version 1 --all-features')} > ${NEXTEST_CARGO_METADATA}`,
826
834
  'test -n "$NX_TASK_HASH"',
827
- `printf '%s\\n' "$NX_TASK_HASH" > ${CARGO_TEST_ARCHIVE_KEY_FILE}`,
835
+ `printf '%s\\n' "$NX_TASK_HASH" > ${NEXTEST_BUILD_KEY}`,
836
+ `${helper} record ${NEXTEST_BUILD_KEY}`,
828
837
  ]),
829
838
  cwd: projectRoot,
830
839
  },
831
840
  };
832
841
  }
833
842
 
843
+ /**
844
+ * The build of the workspace's test binaries, printing nextest's binaries metadata: the command of
845
+ * `cargo-test-build` and of every runner's fixture, so the binaries a fixture materializes are the
846
+ * ones the metadata names.
847
+ */
848
+ function nextestBinariesBuild(toolConfig: string): string {
849
+ return cargoFrozen(`${NEXTEST_BINARIES_BUILD_ARGS.join(' ')} ${toolConfig}`);
850
+ }
851
+
834
852
  /**
835
853
  * One foreign triple's test archive, and the target that EXECUTES it.
836
854
  *
837
- * A target-triple VARIANT of `cargo-test-archive`, not a second mechanism: same
838
- * `nextest archive --workspace`, same tool config layering, same
839
- * `--workspace-remap .` on the run — only `--target <triple>` and a distinct
840
- * archive file are added, because both archives coexist as declared Nx outputs
841
- * and one path for two triples would let a restored cache serve the wrong
842
- * machine's binaries.
855
+ * The one place a test archive exists: binaries built on one platform and run
856
+ * on another travel as a file, while a same-platform run executes
857
+ * `cargo-test-build`'s binaries where they were built. Same tool config
858
+ * layering and `--workspace-remap .` on the run as the in-place runners;
859
+ * `--target <triple>` and an archive file per triple, because those archives
860
+ * coexist as declared Nx outputs and one path for two triples would let a
861
+ * restored cache serve the wrong machine's binaries.
843
862
  *
844
863
  * `cargo-nextest` where every other cargo target spells `cargo --frozen`, and
845
864
  * that is measured, not stylistic: cargo overwrites `CARGO` with its own path
@@ -853,13 +872,14 @@ function createCargoTestArchiveTarget(projectRoot: string, toolConfig: string):
853
872
  * inputs itself: both are otherwise attached by matching the
854
873
  * `cargo --frozen` prefix in a command, and this command does not carry it.
855
874
  *
856
- * The RUNNER declares no dependency on the archive and is not cached. That is
857
- * the whole point of splitting the pair: it runs on a machine where the triple
858
- * is native and the archive arrived as a file, so a dependency edge would ask
859
- * that machine to cross-build what it was sent, and a cache verdict would be
860
- * keyed on sources whose binaries it did not build. It is also the one cargo
861
- * target that needs no cargo: `nextest run --archive-file` extracts prebuilt
862
- * binaries and never invokes cargo (measured, zero invocations).
875
+ * The RUNNER declares no dependency on the archive. That is the whole point of
876
+ * splitting the pair: it runs on a machine where the triple is native and the
877
+ * archive arrived as a file, so a dependency edge would ask that machine to
878
+ * cross-build what it was sent. It is cached on the archive's own bytes, the
879
+ * binaries it runs, never on the sources: a key of sources would vouch for
880
+ * binaries this machine did not build. It is also the one cargo target that
881
+ * needs no cargo: `nextest run --archive-file` extracts prebuilt binaries and
882
+ * never invokes cargo (measured, zero invocations).
863
883
  */
864
884
  function createCargoCrossTestTargets(
865
885
  projectRoot: string,
@@ -876,6 +896,10 @@ function createCargoCrossTestTargets(
876
896
  `--archive-file ${archiveFile} --user-config-file none ${toolConfig}`,
877
897
  ]);
878
898
  const archiveExecutor = 'nx:run-commands';
899
+ const runExecutor = '@smoothbricks/nx-plugin:bounded-exec';
900
+ const runCommand =
901
+ `cargo-nextest nextest run --archive-file ${archiveFile} --workspace-remap . ` +
902
+ `--no-tests=pass --user-config-file none ${toolConfig}`;
879
903
  return {
880
904
  [cargoCrossTestArchiveTargetName(triple)]: {
881
905
  executor: archiveExecutor,
@@ -918,15 +942,22 @@ function createCargoCrossTestTargets(
918
942
  },
919
943
  },
920
944
  [cargoCrossTestTargetName(triple)]: {
921
- executor: '@smoothbricks/nx-plugin:bounded-exec',
922
- cache: false,
923
- inputs: [],
945
+ executor: runExecutor,
946
+ cache: true,
947
+ // The archive's toolchain, npm and lock keys, as `cargo-test-build`'s: they decided the bytes it runs.
948
+ inputs: [
949
+ arrivedFileHashInput(posix.join(projectRoot, archiveFile)),
950
+ `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`,
951
+ fileHashInput(PLUGIN_NEXTEST_CONFIG_PATH),
952
+ ...cargoToolchainInputs(),
953
+ cargoRuntimeInput(projectRoot, 'cargo-nextest nextest --version'),
954
+ { externalDependencies: cargoCommandNpmPackages({ executor: runExecutor }, runCommand, pluginInstalled) },
955
+ { externalDependencies: [cargoLockNodeName(projectRoot)] },
956
+ ],
924
957
  outputs: [],
925
958
  dependsOn: [],
926
959
  options: {
927
- command:
928
- `cargo-nextest nextest run --archive-file ${archiveFile} --workspace-remap . ` +
929
- `--no-tests=pass --user-config-file none ${toolConfig}`,
960
+ command: runCommand,
930
961
  cwd: projectRoot,
931
962
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
932
963
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
@@ -941,7 +972,7 @@ function createCargoTestTarget(projectRoot: string): TargetConfiguration {
941
972
  metadata: CARGO_PRODUCER_METADATA,
942
973
  cache: true,
943
974
  inputs: CARGO_INPUTS,
944
- dependsOn: [CARGO_TEST_ARCHIVE_TARGET],
975
+ dependsOn: [CARGO_TEST_BUILD_TARGET],
945
976
  options: {
946
977
  command: cargoFrozen('test --workspace'),
947
978
  cwd: projectRoot,
@@ -1006,8 +1037,8 @@ export function pluginInstalledIn(
1006
1037
  /**
1007
1038
  * The npm packages a cached cargo target runs, for its `externalDependencies`.
1008
1039
  * Cargo runs none. A target this plugin's executor runs, or whose command reads
1009
- * the installed plugin's files (the nextest tool config, the archive
1010
- * extractor), runs the plugin. Without the input Nx keys every task whose
1040
+ * the installed plugin's files (the nextest tool config, the test-binaries
1041
+ * helper), runs the plugin. Without the input Nx keys every task whose
1011
1042
  * executor is not an `@nx/` one on every package in the lockfile, so a
1012
1043
  * lockfile-only commit re-ran every cargo verdict.
1013
1044
  */
@@ -1188,8 +1219,9 @@ function isBuildOutputPackageJson(packageJsonPath: string): boolean {
1188
1219
  * hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
1189
1220
  * other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
1190
1221
  * pair also serves a run that inherits no CPU pool its own, which every task inherits (`run-cpu-pool.ts`), and closes
1191
- * it when the run ends. Last, once every task has finished, the post hook reclaims the
1192
- * superseded Cargo unit generations of each Cargo workspace the run built into (`@smoothbricks/cargo-retain`).
1222
+ * it when the run ends. Last, once every task has finished, the post hook starts the reclaim of the
1223
+ * superseded Cargo unit generations of each Cargo workspace the run built into, in a process of its own, never on
1224
+ * Nx's thread (`@smoothbricks/cargo-retain`).
1193
1225
  */
1194
1226
  export const preTasksExecution: PreTasksExecution<ProducerReceiptsOptions> = async (options, context) => {
1195
1227
  // Before any task is hashed: a workspace that declares the test-walk check
@@ -1490,7 +1522,7 @@ function scriptcPlatformTargets(
1490
1522
  const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
1491
1523
 
1492
1524
  /**
1493
- * ONE target that deploys whichever stage it is handed, never a configuration
1525
+ * ONE target that deploys whichever stage it is handed (`--stage`), never a configuration
1494
1526
  * per stage. Pull-request stages are `prN` for unbounded N, so an enumerated
1495
1527
  * `configurations` map cannot describe the surface that actually exists, and a
1496
1528
  * project carrying both spellings would have two ways to say one thing.
@@ -1499,15 +1531,18 @@ const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml
1499
1531
  * statement that CI deploys this project on every stage, and only the repository
1500
1532
  * can make it. A plugin that tagged what it inferred would enrol every private
1501
1533
  * wrangler project in CI deploys by writing the policy it is supposed to read.
1502
- *
1503
- * `{args.stage}` rather than `forwardAllArgs`: run-commands'
1504
- * `interpolateArgsIntoCommand` returns as soon as it sees `{args.` and never
1505
- * appends forwarded arguments, so `nx run web:deploy --stage=pr42` yields
1506
- * exactly one `--stage`, for an arbitrary preview stage no map could enumerate.
1507
- * An omitted stage interpolates to empty and `deploy-stage`'s required
1508
- * `--stage` refuses it, which is the failure we want at the boundary.
1509
1534
  */
1510
- const WRANGLER_DEPLOY_COMMAND = 'smoo wrangler deploy-stage --stage {args.stage}';
1535
+ const WRANGLER_DEPLOY_EXECUTOR = '@smoothbricks/nx-plugin:wrangler-deploy';
1536
+
1537
+ /**
1538
+ * What a deploy uploads: the project's files and its build half's output. Nx keys the
1539
+ * `--stage` override with them, so the hash is the artifact and the stage.
1540
+ */
1541
+ const WRANGLER_DEPLOY_INPUTS: NonNullable<TargetConfiguration['inputs']> = [
1542
+ 'default',
1543
+ '^default',
1544
+ { dependentTasksOutputFiles: '**/*', transitive: false },
1545
+ ];
1511
1546
 
1512
1547
  async function createProjectTargets(
1513
1548
  packageJsonPath: string,
@@ -1597,10 +1632,8 @@ async function createProjectTargets(
1597
1632
  repoRootPackages,
1598
1633
  );
1599
1634
  const inferCargoWasm = cargoWasmConfig !== null && !('cargo-wasm' in declaredTargets);
1600
- const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
1601
1635
  const hasOrdinaryBuildOutputTarget =
1602
- hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
1603
- const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
1636
+ hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || declaresPackageLocalBuildOutput(packageJson);
1604
1637
  const isDeployableWranglerProject =
1605
1638
  packageJson.private === true && WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
1606
1639
 
@@ -1746,9 +1779,9 @@ async function createProjectTargets(
1746
1779
  // result — duplicating the very edges the spread exists to add.
1747
1780
  //
1748
1781
  // `dependsOn` REPLACES rather than unions. These lists state what each target
1749
- // consumes — the fetched registry, the archive, the debug addon — and a
1782
+ // consumes — the fetched registry, the test build, the debug addon — and a
1750
1783
  // package that must re-route one (build its artifact ahead of the test run,
1751
- // or drop `cargo-test-archive` because it compiles differently) can only say
1784
+ // or drop `cargo-test-build` because it compiles differently) can only say
1752
1785
  // so by replacing the list; a union would make every inferred edge
1753
1786
  // unremovable and a corrected order unrepresentable.
1754
1787
  // Additive intent already has a spelling (`"..."` above), so a plugin-local
@@ -1785,24 +1818,26 @@ async function createProjectTargets(
1785
1818
  // as the outputs of the targets a repository adds to `dependsOn`. Hashing
1786
1819
  // those outputs here means a repository never has to restate `inputs` to
1787
1820
  // add them - and a restated `inputs` REPLACES this union with the root
1788
- // project's `default`, which owns no crate file, so the archive then
1821
+ // project's `default`, which owns no crate file, so the test build then
1789
1822
  // cache-hits against edited crates while every per-crate test reruns on
1790
1823
  // the stale binary. That verdict is wrong, not merely slow.
1791
1824
  const workspaceCargoInputs: TargetConfiguration['inputs'] = [
1792
1825
  ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
1793
1826
  { dependentTasksOutputFiles: '**/*', transitive: false },
1794
1827
  ];
1795
- targets[CARGO_TEST_ARCHIVE_TARGET] = createCargoTestArchiveTarget(
1828
+ targets[CARGO_TEST_BUILD_TARGET] = createCargoTestBuildTarget(
1796
1829
  cargoWorkspaceRoot,
1797
1830
  nextestToolConfigArg(cargoWorkspaceRoot),
1831
+ nativeTools,
1798
1832
  );
1799
- // `archive.include` lives in the repository's nextest config, so that file
1800
- // decides what the archive CONTAINS, not merely how a run behaves.
1801
- targets[CARGO_TEST_ARCHIVE_TARGET].inputs = [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`];
1833
+ // The build's `cargo nextest list` loads the repository's nextest config and
1834
+ // refuses an invalid one, so that file keys the build as well as every run.
1835
+ targets[CARGO_TEST_BUILD_TARGET].inputs = [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`];
1802
1836
  // One archive per declared foreign triple, from the same inputs and the
1803
- // same repository nextest config: an archive is the workspace's test
1804
- // binaries whichever machine they are for, so a change that invalidates
1805
- // the host archive must invalidate every cross one.
1837
+ // same repository nextest config, whose `archive.include` decides what an
1838
+ // archive CONTAINS: it is the workspace's test binaries for another
1839
+ // machine, so a change that invalidates the host build must invalidate
1840
+ // every cross archive.
1806
1841
  for (const crossTarget of listCargoCrossTestTargets(join(workspaceRoot, cargoWorkspaceRoot))) {
1807
1842
  Object.assign(
1808
1843
  targets,
@@ -1816,10 +1851,10 @@ async function createProjectTargets(
1816
1851
  );
1817
1852
  }
1818
1853
  // A serial group's filter can span members, so no single crate owns it. The root
1819
- // owns each group's runner beside the archive it executes, and gives it the inputs
1854
+ // owns each group's runner beside the test build it executes, and gives it the inputs
1820
1855
  // of exactly the members its filter can select from (`filterScope`): a group scoped
1821
1856
  // to its packages reruns only when their sources or local dependencies change,
1822
- // and an unscoped one hashes every member, as the archive itself does.
1857
+ // and an unscoped one hashes every member, as the test build itself does.
1823
1858
  for (const group of cargoWorkspace.serialGroups) {
1824
1859
  targets[cargoTestGroupTargetName(group.group)] = cargoTestGroupTarget(
1825
1860
  cargoWorkspace,
@@ -1846,11 +1881,11 @@ async function createProjectTargets(
1846
1881
  // of its closure; a target dir per crate compiled every shared dependency
1847
1882
  // once per crate (49 closures, 11 GiB on one repository) and no per-crate
1848
1883
  // cache hit ever repaid that. The workspace inputs are exactly the union of
1849
- // every crate's, so the verdict caches on the same key set the archive
1884
+ // every crate's, so the verdict caches on the same key set the test build
1850
1885
  // does. Non-root packages depend on this target. Its target dir is its own
1851
1886
  // (CARGO_LINT_CLIPPY_COMMAND, ./cross-check-policy.ts): Cargo flocks one
1852
1887
  // directory per invocation, and a workspace clippy holding the dev build's
1853
- // `target/` queued the archive and every dev build behind it.
1888
+ // `target/` queued the test build and every dev build behind it.
1854
1889
  targets['cargo-lint'] = {
1855
1890
  executor: 'nx:run-commands',
1856
1891
  metadata: CARGO_PRODUCER_METADATA,
@@ -1901,7 +1936,8 @@ async function createProjectTargets(
1901
1936
  cwd: cargoWorkspaceRoot,
1902
1937
  },
1903
1938
  };
1904
- // Mutation runs are minutes-to-hours: never cached, never part of build/lint.
1939
+ // Mutation runs are minutes-to-hours and never part of build/lint. Cached on the code and toolchain they mutate
1940
+ // and on cargo-mutants' configuration, with the report as the output: an unchanged tree mutates nothing new.
1905
1941
  // CI runs these per-PR via `cargo mutants --in-diff` (see mutants.toml docs).
1906
1942
  // bounded-exec sizes cargo-mutants' own jobserver to its CPU grant (its `cargo-mutants` runner kind), which
1907
1943
  // otherwise starts one task per core whatever else runs on the host. It reports no test bounded-exec can read as
@@ -1909,29 +1945,19 @@ async function createProjectTargets(
1909
1945
  targets.mutation = {
1910
1946
  executor: '@smoothbricks/nx-plugin:bounded-exec',
1911
1947
  metadata: CARGO_PRODUCER_METADATA,
1912
- cache: false,
1948
+ cache: true,
1949
+ inputs: [...workspaceCargoInputs, '{projectRoot}/**/.cargo/mutants.toml'],
1950
+ outputs: [`{workspaceRoot}/${posix.join(cargoWorkspaceRoot, 'mutants.out')}`],
1913
1951
  options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot, timeoutMs: MUTATION_TIMEOUT_MS },
1914
1952
  };
1953
+ // Cached on the code and toolchain it measures: a rerun with unchanged inputs measures nothing new.
1915
1954
  targets.bench = {
1916
1955
  executor: 'nx:run-commands',
1917
1956
  metadata: CARGO_PRODUCER_METADATA,
1918
- cache: false,
1957
+ cache: true,
1958
+ inputs: workspaceCargoInputs,
1919
1959
  options: { command: cargoFrozen('bench --workspace'), cwd: cargoWorkspaceRoot },
1920
1960
  };
1921
- // A read-only preview of the retention pass the plugin's postTasksExecution
1922
- // schedules after runs that built (@smoothbricks/cargo-retain): the superseded unit
1923
- // generations it would reclaim and why everything else stays. Never cached:
1924
- // the verdict is about this machine's disk, not the commit.
1925
- const retainTool = nativeToolDependsOn(nativeTools, 'cargo-retain');
1926
- targets['cargo-retention'] = {
1927
- executor: 'nx:run-commands',
1928
- cache: false,
1929
- ...(retainTool.length > 0 ? { dependsOn: retainTool } : {}),
1930
- options: {
1931
- command: nativeToolCommand(nativeTools, cargoWorkspaceRoot, 'cargo-retain', 'smoo-nx-cargo-retain'),
1932
- cwd: cargoWorkspaceRoot,
1933
- },
1934
- };
1935
1961
  }
1936
1962
 
1937
1963
  if (cargoWorkspace) {
@@ -2025,21 +2051,16 @@ async function createProjectTargets(
2025
2051
  if (frozenCargoManifests.size > 0) {
2026
2052
  targets[CARGO_FETCH_TARGET] = {
2027
2053
  executor: 'nx:run-commands',
2028
- // The download lands in CARGO_HOME, outside the workspace: a cache hit
2029
- // would skip work a cold registry still needs. Nothing here is a
2030
- // workspace output, so there is nothing for Nx to restore in its place.
2031
- cache: false,
2032
- inputs: cargoFetchInputs(projectRoot),
2054
+ // The download lands in CARGO_HOME, outside the workspace, so nothing is
2055
+ // a workspace output; the registry's state reaches the key instead
2056
+ // (cargoFetchedInput), and a hit never stands for a crate it lacks.
2057
+ cache: true,
2058
+ inputs: [...cargoFetchInputs(projectRoot), cargoFetchedInput(projectRoot, [...frozenCargoManifests].sort())],
2059
+ outputs: [],
2033
2060
  options: {
2034
2061
  // One fetch per manifest, independent of the others: Cargo's own
2035
2062
  // package-cache lock arbitrates the CARGO_HOME they share.
2036
- commands: [...frozenCargoManifests]
2037
- .sort()
2038
- .map((manifestPath) =>
2039
- manifestPath === 'Cargo.toml'
2040
- ? CARGO_FETCH_COMMAND
2041
- : `${CARGO_FETCH_COMMAND} --manifest-path ${manifestPath}`,
2042
- ),
2063
+ commands: [...frozenCargoManifests].sort().map(cargoFetchCommand),
2043
2064
  cwd: projectRoot,
2044
2065
  },
2045
2066
  };
@@ -2072,7 +2093,8 @@ async function createProjectTargets(
2072
2093
  // lock-scope node of the directory it runs in) unless its inputs already do.
2073
2094
  for (const [name, target] of Object.entries(targets)) {
2074
2095
  const text = targetCommandText(target);
2075
- if (!runsFrozenCargo(text)) continue;
2096
+ // `cargo-fetch` runs cargo unfrozen, as the one task that may reach the network, and is keyed like the rest.
2097
+ if (!runsFrozenCargo(text) && name !== CARGO_FETCH_TARGET) continue;
2076
2098
  target.outputs ??= [];
2077
2099
  if (!target.cache) continue;
2078
2100
  const cwd: unknown = target.options?.cwd;
@@ -2080,7 +2102,9 @@ async function createProjectTargets(
2080
2102
  ? ` && cargo clippy -V${name === CARGO_CROSS_LINT_TARGET ? '' : ' && cargo fmt --version'}`
2081
2103
  : text.includes('nextest ')
2082
2104
  ? ' && cargo nextest --version'
2083
- : '';
2105
+ : text.includes('mutants ')
2106
+ ? ' && cargo mutants --version'
2107
+ : '';
2084
2108
  const inputs = target.inputs ?? CARGO_INPUTS;
2085
2109
  const namesPackages = inputs.some(
2086
2110
  (input) => typeof input === 'object' && 'externalDependencies' in input && !isCargoLockInput(input),
@@ -2107,7 +2131,7 @@ async function createProjectTargets(
2107
2131
  if (napiDebug && cargoWorkspace) {
2108
2132
  // A crate whose project also builds the debug cdylib runs its tests after
2109
2133
  // that build: the tests dlopen what `napi-debug` writes into `target/debug`,
2110
- // and an archived test binary still loads it from this tree.
2134
+ // and a test binary run in place loads it from this tree.
2111
2135
  const runners = [
2112
2136
  ...cargoPackagePlans.flatMap((plan) => plan.pieces.map((piece) => piece.targetName)),
2113
2137
  // The root owns the serial groups' runners, so they take its build as its pieces do.
@@ -2168,37 +2192,39 @@ async function createProjectTargets(
2168
2192
  }
2169
2193
  }
2170
2194
 
2171
- // A deploy is never cached; the build half beside it always is.
2195
+ // A deploy is cached only while its stage serves what it would deploy; the build half beside it
2196
+ // always is.
2172
2197
  //
2173
2198
  // Nx's cache answers "did this exact input set already produce an output". A deploy's real
2174
- // question is "is this exact version live", and the two agree only until someone rolls back.
2175
- // After a rollback the workspace is unchanged, so the hash is unchanged, so a cached `deploy`
2176
- // reports success while the previous version keeps serving. No input tuning repairs that: a
2177
- // `runtime` input cannot even learn WHICH STAGE is being deployed. Nx hashes runtime inputs with
2178
- // the env from `getTaskSpecificEnv`, which deliberately excludes the task coordinates; input
2179
- // strings interpolate only `{workspaceRoot}`/`{projectRoot}`, never `{args.*}`; and overrides
2180
- // are not forwarded to `dependsOn` dependencies, so an auxiliary task cannot carry the stage
2181
- // either. (An executor's custom hasher is the single Nx API that does see `task.overrides`, if
2182
- // hash-level participation is ever genuinely wanted.)
2199
+ // question is "is this exact version live", and the two agree only until someone rolls back:
2200
+ // the workspace is then unchanged, so the hash is unchanged. No input repairs that. A `runtime`
2201
+ // input cannot even learn WHICH STAGE is being deployed (Nx hashes runtime inputs with the env
2202
+ // from `getTaskSpecificEnv`, which excludes the task coordinates, and input strings never
2203
+ // interpolate `{args.*}`), and hashing the live tag in would never converge, because the
2204
+ // deployed version is tagged with the hash. An executor's custom hasher is the one Nx API that
2205
+ // sees `task.overrides`, so `wrangler-deploy`'s asks the question: it hashes the artifact and the
2206
+ // stage, answers that hash only while the stage serves the version tagged with it, and otherwise
2207
+ // adds a nonce, so the run misses and deploys (executors/wrangler-deploy/hasher.ts). The run
2208
+ // still tags the artifact's version, so the next hash, with that version live, is the artifact's
2209
+ // own: `deploy-stage` finds it live and changes nothing, and Nx caches that answer.
2183
2210
  //
2184
- // So the target is split along the line the question actually falls on. `deploy-build` is purely
2185
- // file-derived — build the artifact and whatever the build registers — and caches honestly.
2186
- // `deploy` reads live state every run and no-ops when live already equals the desired tag, which
2187
- // costs two Cloudflare calls and makes a redundant deploy provably free rather than assumed
2188
- // free. That is what lets ordering be an ordinary `dependsOn: ["<other>:deploy"]` edge at any
2189
- // depth, and it is why such an edge must point at `deploy` and not at `deploy-build`: a
2190
- // dependent has to re-check liveness, not inherit someone else's cache hit.
2211
+ // So the target is split along the line the question falls on. `deploy-build` is purely
2212
+ // file-derived — build the artifact and whatever the build registers. `deploy` checks live state
2213
+ // on every run, in its hasher, and a cache hit replays only a deploy that would change nothing.
2214
+ // That is what lets ordering be an ordinary `dependsOn: ["<other>:deploy"]` edge at any depth,
2215
+ // and it is why such an edge must point at `deploy` and not at `deploy-build`: a dependent has
2216
+ // to re-check liveness, not inherit someone else's build.
2191
2217
  //
2192
2218
  // Both are bases for a package-local declaration to land on, per the merge rules above: a
2193
2219
  // declaration naming `cache`, `inputs` or `dependsOn` REPLACES what is set here and inherits
2194
2220
  // everything it does not name, while Nx's `"..."` token expands to the inferred list at its
2195
2221
  // position. So a project adding a cross-project edge writes
2196
- // `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this command —
2222
+ // `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this executor —
2197
2223
  // measured, not assumed, against an inferred base.
2198
2224
  //
2199
2225
  // `deploy` is INFERRED for a private wrangler project rather than patched onto a hand-written
2200
- // one. The command is a constant of the convention, not of the project: every consumer wrote
2201
- // the same `nx:run-commands` wrapper around it. `private: true` is the second half of the
2226
+ // one. The executor is a constant of the convention, not of the project: every consumer wrote
2227
+ // the same `nx:run-commands` wrapper around `smoo wrangler deploy-stage`. `private: true` is the second half of the
2202
2228
  // detection: a PUBLISHED package's wrangler manifest documents a binding for its consumers,
2203
2229
  // so inferring a deploy from it would put a live `wrangler deploy` of someone's documentation
2204
2230
  // one `nx run-many -t deploy` away. A published package that really is deployed declares
@@ -2220,11 +2246,12 @@ async function createProjectTargets(
2220
2246
  ? 'build'
2221
2247
  : null;
2222
2248
  targets[DEPLOY_TARGET] = {
2223
- executor: 'nx:run-commands',
2224
- cache: false,
2249
+ executor: WRANGLER_DEPLOY_EXECUTOR,
2250
+ cache: true,
2251
+ inputs: WRANGLER_DEPLOY_INPUTS,
2225
2252
  outputs: [],
2226
2253
  ...(fileDerivedHalf === null ? {} : { dependsOn: [fileDerivedHalf] }),
2227
- options: { command: WRANGLER_DEPLOY_COMMAND, cwd: projectRoot },
2254
+ options: {},
2228
2255
  };
2229
2256
  }
2230
2257
 
@@ -2258,49 +2285,10 @@ async function createProjectTargets(
2258
2285
  ],
2259
2286
  };
2260
2287
  }
2261
- // Every cargo build directory this project's own commands write. `clean`
2262
- // cannot learn them from `outputs`: a clippy or nextest target dir is a
2263
- // multi-GB build tree that must never enter the Nx cache, so the targets
2264
- // deliberately declare `outputs: []`. Reading `--target-dir` back off the
2265
- // commands means the list cannot drift from what actually gets written, and a
2266
- // directory is named relative to the command's own cwd, not the project root.
2267
- // The workspace's default `target/` is not listed: every dev build shares it.
2268
- const cargoBuildDirs = [
2269
- ...new Set(
2270
- Object.entries(targets).flatMap(([name, target]) => {
2271
- const cwd: unknown = target.options?.cwd;
2272
- const base = typeof cwd === 'string' ? cwd : projectRoot;
2273
- const dirs = [...targetCommandText(target).matchAll(/--target-dir\s+(\S+)/g)].flatMap((match) =>
2274
- match[1] === undefined ? [] : [match[1]],
2275
- );
2276
- if (name === CARGO_TEST_ARCHIVE_TARGET) {
2277
- dirs.push(posix.dirname(CARGO_TEST_ARCHIVE_FILE));
2278
- }
2279
- return dirs.map((dir) => `{workspaceRoot}/${posix.normalize(posix.join(base, dir))}`);
2280
- }),
2281
- ),
2282
- ].sort();
2283
- if (hasAnyBuildOutputTarget || cargoBuildDirs.length > 0) {
2284
- const declaredBuild = declaredTargets.build;
2285
- const declaredBuildOutputs =
2286
- isRecord(declaredBuild) && Array.isArray(declaredBuild.outputs)
2287
- ? declaredBuild.outputs.filter((output): output is string => typeof output === 'string')
2288
- : null;
2289
- targets.clean = {
2290
- executor: '@smoothbricks/nx-plugin:clean-outputs',
2291
- cache: false,
2292
- // Naming any output REPLACES the executor's default, so the build outputs
2293
- // it would have used are restated here rather than lost.
2294
- ...(cargoBuildDirs.length > 0
2295
- ? { options: { outputs: [...(declaredBuildOutputs ?? ['{projectRoot}/dist']), ...cargoBuildDirs] } }
2296
- : {}),
2297
- };
2298
- }
2299
-
2300
2288
  if (targets['typecheck-tests']) {
2301
2289
  if (hasLibTsconfig) {
2302
- // Test configs may resolve the package's own `./index.js` through dist.
2303
- // Rebuild that current-project declaration output after clean, not only
2290
+ // Test configs may resolve the package's own `./index.js` through dist, so the
2291
+ // current-project declaration output is rebuilt first, not only the
2304
2292
  // dependency-project outputs reached through typecheck.
2305
2293
  targets['typecheck-tests'].dependsOn = ['tsc-js', 'typecheck'];
2306
2294
  } else if (targets.build) {
@@ -2311,8 +2299,8 @@ async function createProjectTargets(
2311
2299
  // A Bun suite that `--shard` splits and a `--timings` manifest balances gets a
2312
2300
  // check, which `lint` depends on, that the manifest names every file the
2313
2301
  // shards run: Bun charges an unnamed file the median, and unnamed files
2314
- // cluster into one shard. Uncached, because Bun's discovery also finds
2315
- // gitignored files that no Nx input keys, and the check only walks a tree.
2302
+ // cluster into one shard. Cached on the manifests, the bunfig and the names
2303
+ // Bun's discovery would find, which include gitignored files no file input keys.
2316
2304
  const sharded = timingsShardedSuite(projectRoot, declaredTargets);
2317
2305
  if (!sharded.ok) {
2318
2306
  throw new Error(`${packageJsonPath}: ${sharded.error}`);
@@ -2320,7 +2308,11 @@ async function createProjectTargets(
2320
2308
  if (sharded.suite !== null) {
2321
2309
  targets[SHARD_TIMINGS_TARGET] = {
2322
2310
  executor: SHARD_TIMINGS_EXECUTOR,
2323
- cache: false,
2311
+ cache: true,
2312
+ inputs: [
2313
+ ...timingsSuiteInputs(sharded.suite),
2314
+ { externalDependencies: pluginInstalledIn(workspaceRoot) ? [PLUGIN_PACKAGE] : [] },
2315
+ ],
2324
2316
  outputs: [],
2325
2317
  options: { cwd: sharded.suite.cwd, args: sharded.suite.args },
2326
2318
  };
@@ -2354,12 +2346,56 @@ async function createProjectTargets(
2354
2346
  ],
2355
2347
  ...(lintCommands.length > 0
2356
2348
  ? {
2357
- options: { commands: lintCommands, cwd: '.' },
2349
+ options: {
2350
+ commands: lintCommands,
2351
+ cwd: '.',
2352
+ ...(eslintFileSet === null ? {} : { eslintProjectRoot: projectRoot }),
2353
+ } satisfies AllVerdictsOptions,
2358
2354
  }
2359
2355
  : {}),
2360
2356
  };
2361
2357
  }
2362
2358
 
2359
+ // The process-lineage entry has no full API-generator dependency: the generator check itself is bounded work.
2360
+ const lineageProducer = nativeToolDependsOn(nativeTools, 'cowshed', 'lineage-js');
2361
+ if (lineageProducer.length > 0 && packageJson.name === '@smoothbricks/nx-plugin') {
2362
+ for (const name of ['tsc-js', 'typecheck', 'typecheck-tests']) {
2363
+ const target = targets[name];
2364
+ if (target === undefined) continue;
2365
+ target.dependsOn = [...(target.dependsOn ?? []), ...lineageProducer];
2366
+ target.inputs = [
2367
+ ...(target.inputs ?? ['production']),
2368
+ { dependentTasksOutputFiles: '**/dist/lineage/**/*', transitive: false },
2369
+ ];
2370
+ }
2371
+ }
2372
+
2373
+ // Runtime observers need the local addon, not the package aggregate (which can deliberately build only JS).
2374
+ // Declarations retain these prerequisites and output inputs with Nx's ordinary "..." merge token.
2375
+ // The canonical release-check instead judges prebuilt shipping artifacts and must remain dependency-free.
2376
+ const observerProducers = [...nativeToolDependsOn(nativeTools, 'cowshed'), ...lineageProducer];
2377
+ if (observerProducers.length > 0) {
2378
+ for (const name of new Set([...Object.keys(targets), ...Object.keys(declaredTargets)])) {
2379
+ const declared = declaredTargets[name];
2380
+ const executor =
2381
+ isRecord(declared) && declared.executor !== undefined ? declared.executor : targets[name]?.executor;
2382
+ if (executor !== '@smoothbricks/nx-plugin:bounded-exec' || name === 'release-check') continue;
2383
+ // Nx discards an incompatible executor's inferred configuration; only the observer prerequisites belong below it.
2384
+ if (targets[name]?.executor !== undefined && targets[name]?.executor !== executor) {
2385
+ targets[name] = {};
2386
+ }
2387
+ targets[name] ??= {};
2388
+ const target = targets[name];
2389
+ target.dependsOn = [...(target.dependsOn ?? []), ...observerProducers];
2390
+ const inputs =
2391
+ target.inputs ?? (isRecord(declared) && Array.isArray(declared.inputs) ? [] : ['default', '^production']);
2392
+ target.inputs = [
2393
+ ...inputs,
2394
+ { dependentTasksOutputFiles: '**/*.node', transitive: true },
2395
+ { dependentTasksOutputFiles: '**/dist/lineage/**/*.js', transitive: true },
2396
+ ];
2397
+ }
2398
+ }
2363
2399
  // Publish each inferred target's semantic kind (`inferredTaskKind`) as metadata. Nx merges metadata beneath a
2364
2400
  // declaration, so the final graph still says which tasks are build and which are test work after a package rewrites
2365
2401
  // one. Fresh objects: `CARGO_PRODUCER_METADATA` is shared by every producer.
@@ -2386,7 +2422,9 @@ async function createProjectTargets(
2386
2422
  [VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
2387
2423
  [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
2388
2424
  }),
2389
- ...(Object.keys(targets).some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
2425
+ ...([...Object.keys(targets), ...Object.keys(declaredTargets)].some(
2426
+ (name) => name.startsWith('cargo-') || name.startsWith('napi-'),
2427
+ )
2390
2428
  ? { [CARGO_TOOLCHAIN_NAMED_INPUT]: cargoToolchainInputs() }
2391
2429
  : {}),
2392
2430
  };
@@ -2926,15 +2964,9 @@ function isRecord(value: unknown): value is Record<string, unknown> {
2926
2964
  return value !== null && typeof value === 'object';
2927
2965
  }
2928
2966
 
2929
- function classifyPackageLocalBuildOutputs(packageJson: PackageJson): { ordinary: boolean; platform: boolean } {
2967
+ function declaresPackageLocalBuildOutput(packageJson: PackageJson): boolean {
2930
2968
  const targets = packageJson.nx?.targets;
2931
- const targetNames = isRecord(targets) ? Object.keys(targets) : [];
2932
- return {
2933
- ordinary: targetNames.some(isBuildOutputTargetName),
2934
- platform: targetNames.some((targetName) =>
2935
- PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1))),
2936
- ),
2937
- };
2969
+ return isRecord(targets) && Object.keys(targets).some(isBuildOutputTargetName);
2938
2970
  }
2939
2971
 
2940
2972
  interface CargoTargetRef {
@@ -2957,7 +2989,7 @@ interface CargoWorkspace {
2957
2989
  packages: CargoPackagePlan[];
2958
2990
  rootProjectName: string;
2959
2991
  projectRoot: string;
2960
- /** The repository's serial test groups, each with one runner beside the archive (see `serialTestGroups`). */
2992
+ /** The repository's serial test groups, each with one runner beside the test build (see `serialTestGroups`). */
2961
2993
  serialGroups: SerialTestGroup[];
2962
2994
  /** One derivation memo for the whole graph computation (see cargoPackageTestInputs). */
2963
2995
  inputsCache: CargoInputsCache;
@@ -3105,7 +3137,7 @@ async function resolveCargoWorkspaces(
3105
3137
  * own time bound never delays an ordinary shard.
3106
3138
  *
3107
3139
  * Every piece EXECUTES, it never builds: it runs the binaries
3108
- * `cargo-test-archive` compiled once for the whole workspace. That is what
3140
+ * `cargo-test-build` compiled once for the whole workspace. That is what
3109
3141
  * removed the two costs the old shape could not avoid. `nextest run --workspace
3110
3142
  * -E 'package(X)'` re-entered cargo once per crate, and the `-p X` form
3111
3143
  * re-resolved that crate's features so cargo rebuilt the divergent half inside
@@ -3115,37 +3147,32 @@ async function resolveCargoWorkspaces(
3115
3147
  * it, so the filterset is the only selector left, and it selects the same tests
3116
3148
  * it always did.
3117
3149
  *
3118
- * The archive is unpacked ONCE per content, not once per piece. `nextest run
3119
- * --archive-file` extracts the whole archive into a temporary directory of its
3120
- * own on every run, so N pieces paid N extractions of every binary in the
3121
- * workspace to run 1/N of the tests each: on a workspace with ~200 test
3122
- * binaries, ~25 runners extracting side by side on a loaded host all hit the
3123
- * 120s bound still "Extracting". `smoo-nx-nextest-extract` reads the archive's
3124
- * key, the hash of the task that produced it (createCargoTestArchiveTarget),
3125
- * unpacks it under that key unless a previous runner already did — one
3126
- * extracts while the rest wait — and prints the directory; the run then reuses
3127
- * it through nextest's own reuse-build flags, which is what `--archive-file`
3128
- * does after unpacking. Keyed by the producing task's inputs, so a rebuilt or
3129
- * restored archive of other inputs can never run an older extraction's binaries. The one difference
3130
- * from `--archive-file` is the Rust standard library directory: nextest has no
3131
- * flag to remap it, so a run uses the producing toolchain's own sysroot rather
3132
- * than the archived copy of it — the same toolchain, because the archive's hash
3133
- * covers the toolchain pin. The extraction lives in Cargo's own target
3134
- * directory (`<target_directory>/nextest-extracted`), never in an Nx output: it
3135
- * is a multi-GB tree for a cached verdict that has no outputs, rebuilt from the
3136
- * archive like the rest of the build tree, and a checkout that keeps its build
3137
- * state off its source tree keeps the extraction there with it.
3150
+ * The binaries run where the build left them, never copied. An archive makes
3151
+ * a same-platform run pay for a copy of every binary in the workspace before
3152
+ * its first test (measured: 290 binaries, 678 MB, 4.6s on a quiet host and 21s
3153
+ * in a gate, per archive), which only a cross lane needs
3154
+ * (createCargoCrossTestTargets). A run reads the build's reuse-build metadata,
3155
+ * the build's declared Nx outputs, and remaps the build's target directory onto
3156
+ * this checkout's, which `smoo-nx-nextest-binaries target-dir` reads from
3157
+ * Cargo, so a `build.target-dir` is honoured as every build honours it. The
3158
+ * binaries are not Nx outputs, so a checkout whose build was a cache hit can
3159
+ * hold the metadata without them, or with binaries of an older tree at the very
3160
+ * paths it names: the runner's fixture (nextestRunnerFixture) compares the key
3161
+ * the target directory records with the build's and stats each binary, and
3162
+ * otherwise rebuilds with the build's own command through mbx, in the runner's
3163
+ * build interval and never in its progress-bounded test window.
3138
3164
  *
3139
- * `--workspace-remap .` is not cosmetic. An archive records the ABSOLUTE paths
3140
- * of the tree that produced it; without the remap, a restored archive hands
3141
- * every test the producing tree's `CARGO_MANIFEST_DIR` — measured on a moved
3142
- * tree, tests then read another checkout's fixtures, or a path that no longer
3143
- * exists. With it, the runner's own cargo workspace root wins, so the archive
3144
- * is relocatable and one cache entry serves every checkout of the same commit.
3145
- * nextest also re-points `CARGO_BIN_EXE_<name>`/`NEXTEST_BIN_EXE_<name>` at the
3146
- * extracted binaries at RUNTIME (measured), but `env!` reads them at COMPILE
3147
- * time: a test that spawns `env!("CARGO_BIN_EXE_x")` holds the producing tree's
3148
- * path and must read the runtime variable instead to survive relocation.
3165
+ * `--workspace-remap .` is not cosmetic. Reuse-build metadata records the
3166
+ * ABSOLUTE paths of the tree that produced it; without the remap, metadata
3167
+ * restored from another checkout hands every test the producing tree's
3168
+ * `CARGO_MANIFEST_DIR` — measured on a moved tree, tests then read another
3169
+ * checkout's fixtures, or a path that no longer exists. With it, the runner's
3170
+ * own cargo workspace root wins, so the metadata is relocatable and one cache
3171
+ * entry serves every checkout of the same commit. nextest also re-points
3172
+ * `CARGO_BIN_EXE_<name>`/`NEXTEST_BIN_EXE_<name>` at the remapped binaries at
3173
+ * RUNTIME (measured), but `env!` reads them at COMPILE time: a test that spawns
3174
+ * `env!("CARGO_BIN_EXE_x")` holds the producing tree's path and must read the
3175
+ * runtime variable instead to survive relocation.
3149
3176
  *
3150
3177
  * nextest.toml singles some tests out with an override: a raised `slow-timeout`
3151
3178
  * marks a test whose cost is not the suite's. Those are lifted OUT of the hash
@@ -3166,8 +3193,8 @@ async function resolveCargoWorkspaces(
3166
3193
  * making valid empty crates and shards fail execution.
3167
3194
  *
3168
3195
  * Pieces fan out rather than chain: a reused-build run writes nothing to cargo's
3169
- * `target/`, so no piece waits on another. The one extraction per archive is
3170
- * coordinated by `smoo-nx-nextest-extract` itself.
3196
+ * `target/`, so no piece waits on another. Only a fixture that finds another
3197
+ * build in place builds, once for the checkout's runners, under a lock of its own.
3171
3198
  */
3172
3199
  async function addCargoTestTargets(
3173
3200
  targets: Record<string, TargetConfiguration>,
@@ -3183,13 +3210,13 @@ async function addCargoTestTargets(
3183
3210
  continue;
3184
3211
  }
3185
3212
  const inputs = await cargoTestRunnerInputs(workspaceRoot, workspace, [plan.package.dir]);
3186
- const archive = cargoTargetDependency(currentProjectName, {
3213
+ const build = cargoTargetDependency(currentProjectName, {
3187
3214
  projectName: workspace.rootProjectName,
3188
- targetName: CARGO_TEST_ARCHIVE_TARGET,
3215
+ targetName: CARGO_TEST_BUILD_TARGET,
3189
3216
  });
3190
3217
  for (const piece of plan.pieces) {
3191
3218
  targetNames.push(piece.targetName);
3192
- targets[piece.targetName] = cargoTestRunnerTarget(workspace, nativeTools, archive, inputs, piece);
3219
+ targets[piece.targetName] = cargoTestRunnerTarget(workspace, nativeTools, build, inputs, piece);
3193
3220
  }
3194
3221
  }
3195
3222
  return targetNames;
@@ -3230,7 +3257,7 @@ function serialGroupMemberDirs(workspace: CargoWorkspace, group: SerialTestGroup
3230
3257
  * manifests, not unrelated sibling sources.
3231
3258
  *
3232
3259
  * The repository's own nextest config layers OVER the plugin's tool config, so it
3233
- * decides timeouts, groups and archive contents: a cached verdict that ignored it
3260
+ * decides timeouts, groups and setup scripts: a cached verdict that ignored it
3234
3261
  * would survive the change that invalidates it.
3235
3262
  */
3236
3263
  async function cargoTestRunnerInputs(
@@ -3250,8 +3277,8 @@ async function cargoTestRunnerInputs(
3250
3277
  }),
3251
3278
  ),
3252
3279
  );
3253
- // The archive unifies every built package's manifest into every test binary, and a runner's key does not follow the
3254
- // archive's outputs, so each runner names them all: the ones Nx holds as files, the rest through the repository's
3280
+ // The test build unifies every built package's manifest into every test binary, and a runner's key does not follow
3281
+ // the build's outputs, so each runner names them all: the ones Nx holds as files, the rest through the repository's
3255
3282
  // runtime hash of external sources.
3256
3283
  const manifests: string[] = [];
3257
3284
  const external = new Map<string, string>();
@@ -3284,9 +3311,27 @@ async function cargoTestRunnerInputs(
3284
3311
  }
3285
3312
 
3286
3313
  /**
3287
- * One `nextest run` over a filterset against the workspace's archive. Every runner of the
3288
- * workspace builds its command here, so the extraction, reuse-build, tool config and cwd cannot
3289
- * drift between the per-crate pieces and the serial groups.
3314
+ * A runner's fixture budget: the build interval in which it rebuilds what the target directory lacks. It is a build's
3315
+ * budget, not a test's: on a host whose mbx store lacks the units, the fixture compiles the whole workspace's
3316
+ * tests, which a cold hosted runner takes tens of minutes to do while still making progress.
3317
+ */
3318
+ const NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS = 3_600_000;
3319
+
3320
+ /**
3321
+ * The fixture every runner of the workspace runs before its tests: the binaries live outside Nx outputs, so it checks
3322
+ * that the target directory holds the build whose key the metadata came with, and every binary the metadata names,
3323
+ * and otherwise rebuilds with the build's own command. It reports its own duration and mbx's hits and misses apart
3324
+ * from the run's, and names the crates loudly when mbx had to compile (smoo-nx-nextest-binaries).
3325
+ */
3326
+ function nextestRunnerFixture(workspace: CargoWorkspace, nativeTools: NativeTools | null): string {
3327
+ const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
3328
+ return `${helper} ensure ${NEXTEST_BINARIES_METADATA} ${NEXTEST_BUILD_KEY} -- ${nextestBinariesBuild(nextestToolConfigArg(workspace.projectRoot))}`;
3329
+ }
3330
+
3331
+ /**
3332
+ * One `nextest run` over a filterset against the workspace's test build. Every runner of the
3333
+ * workspace builds its command here, so the reuse-build, the remap, the tool config and the cwd
3334
+ * cannot drift between the per-crate pieces and the serial groups.
3290
3335
  */
3291
3336
  function nextestRunnerCommand(
3292
3337
  workspace: CargoWorkspace,
@@ -3296,24 +3341,20 @@ function nextestRunnerCommand(
3296
3341
  ): string {
3297
3342
  const toolConfig = nextestToolConfigArg(workspace.projectRoot);
3298
3343
  // Relative to the runner's cwd, so the hashed command is the same in every checkout.
3299
- const extract = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-extract');
3300
- const reuseExtraction =
3301
- `--binaries-metadata "$extracted/${EXTRACTED_BINARIES_METADATA}" ` +
3302
- `--cargo-metadata "$extracted/${EXTRACTED_CARGO_METADATA}" ` +
3303
- `--target-dir-remap "$extracted/${EXTRACTED_TARGET_DIR}"`;
3304
- return (
3305
- `extracted="$(${extract} ${CARGO_TEST_ARCHIVE_FILE})" && ` +
3306
- cargoFrozen(
3307
- `nextest run ${reuseExtraction} --workspace-remap . -E ${shellWord(selector)}${flags} --user-config-file none ${toolConfig}`,
3308
- )
3344
+ const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
3345
+ const reuseBuild =
3346
+ `--binaries-metadata ${NEXTEST_BINARIES_METADATA} --cargo-metadata ${NEXTEST_CARGO_METADATA} ` +
3347
+ `--target-dir-remap "$(${helper} target-dir)"`;
3348
+ return cargoFrozen(
3349
+ `nextest run ${reuseBuild} --workspace-remap . -E ${shellWord(selector)}${flags} --user-config-file none ${toolConfig}`,
3309
3350
  );
3310
3351
  }
3311
3352
 
3312
- /** One per-crate piece: a bounded run of its partition of the archive's tests. */
3353
+ /** One per-crate piece: a bounded run of its partition of the test build's tests. */
3313
3354
  function cargoTestRunnerTarget(
3314
3355
  workspace: CargoWorkspace,
3315
3356
  nativeTools: NativeTools | null,
3316
- archive: CargoTargetDependency,
3357
+ build: CargoTargetDependency,
3317
3358
  inputs: NonNullable<TargetConfiguration['inputs']>,
3318
3359
  piece: CargoTestPiece,
3319
3360
  ): TargetConfiguration {
@@ -3321,7 +3362,7 @@ function cargoTestRunnerTarget(
3321
3362
  executor: '@smoothbricks/nx-plugin:bounded-exec',
3322
3363
  cache: true,
3323
3364
  inputs,
3324
- dependsOn: [archive, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3365
+ dependsOn: [build, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3325
3366
  options: {
3326
3367
  command: nextestRunnerCommand(
3327
3368
  workspace,
@@ -3330,6 +3371,8 @@ function cargoTestRunnerTarget(
3330
3371
  `${piece.extra} --no-fail-fast --no-tests=pass`,
3331
3372
  ),
3332
3373
  cwd: workspace.projectRoot,
3374
+ fixtureCommand: nextestRunnerFixture(workspace, nativeTools),
3375
+ fixtureTimeoutMs: NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS,
3333
3376
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
3334
3377
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
3335
3378
  },
@@ -3354,10 +3397,12 @@ function cargoTestGroupTarget(
3354
3397
  executor: '@smoothbricks/nx-plugin:bounded-exec',
3355
3398
  cache: true,
3356
3399
  inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND)],
3357
- dependsOn: [CARGO_TEST_ARCHIVE_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3400
+ dependsOn: [CARGO_TEST_BUILD_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3358
3401
  options: {
3359
3402
  command: nextestRunnerCommand(workspace, nativeTools, group.filter, ' --no-fail-fast --no-tests=fail'),
3360
3403
  cwd: workspace.projectRoot,
3404
+ fixtureCommand: nextestRunnerFixture(workspace, nativeTools),
3405
+ fixtureTimeoutMs: NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS,
3361
3406
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
3362
3407
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
3363
3408
  parallelism: 1,