@smoothbricks/nx-plugin 0.6.3-0 → 0.7.1

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 (109) hide show
  1. package/README.md +159 -121
  2. package/dist/.build-inputs.json +25 -20
  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/bounded-test-policy.d.ts +1 -1
  10. package/dist/bounded-test-policy.d.ts.map +1 -1
  11. package/dist/bounded-test-policy.js +9 -8
  12. package/dist/cargo-workspace.d.ts +10 -20
  13. package/dist/cargo-workspace.d.ts.map +1 -1
  14. package/dist/cargo-workspace.js +12 -22
  15. package/dist/cross-check-policy.d.ts +2 -2
  16. package/dist/cross-check-policy.js +2 -2
  17. package/dist/deploy-policy.d.ts +6 -0
  18. package/dist/deploy-policy.d.ts.map +1 -1
  19. package/dist/deploy-policy.js +11 -0
  20. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  21. package/dist/executors/bounded-exec/executor.js +49 -37
  22. package/dist/executors/bounded-exec/mbx-pool.d.ts +39 -10
  23. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  24. package/dist/executors/bounded-exec/mbx-pool.js +78 -24
  25. package/dist/executors/bounded-exec/progress.js +5 -5
  26. package/dist/executors/bounded-exec/runner-sizing.d.ts +40 -2
  27. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  28. package/dist/executors/bounded-exec/runner-sizing.js +55 -4
  29. package/dist/executors/bounded-exec/runtime-pin.js +1 -1
  30. package/dist/executors/bounded-exec/verdict.d.ts +6 -0
  31. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  32. package/dist/executors/bounded-exec/verdict.js +6 -0
  33. package/dist/executors/wrangler-deploy/deploy-hash.d.ts +10 -0
  34. package/dist/executors/wrangler-deploy/deploy-hash.d.ts.map +1 -0
  35. package/dist/executors/wrangler-deploy/deploy-hash.js +14 -0
  36. package/dist/executors/wrangler-deploy/executor.d.ts +24 -0
  37. package/dist/executors/wrangler-deploy/executor.d.ts.map +1 -0
  38. package/dist/executors/wrangler-deploy/executor.js +43 -0
  39. package/dist/executors/wrangler-deploy/hasher.d.ts +27 -0
  40. package/dist/executors/wrangler-deploy/hasher.d.ts.map +1 -0
  41. package/dist/executors/wrangler-deploy/hasher.js +90 -0
  42. package/dist/executors/wrangler-deploy/schema.d.ts +5 -0
  43. package/dist/executors/wrangler-deploy/schema.d.ts.map +1 -0
  44. package/dist/go-tests.d.ts +30 -0
  45. package/dist/go-tests.d.ts.map +1 -0
  46. package/dist/go-tests.js +43 -0
  47. package/dist/index.d.ts +9 -2
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +271 -230
  50. package/dist/managed-files/files.d.ts.map +1 -1
  51. package/dist/managed-files/files.js +5 -0
  52. package/dist/process-group.js +2 -2
  53. package/dist/runtime-input-policy.d.ts +3 -3
  54. package/dist/runtime-input-policy.js +3 -3
  55. package/dist/test-timings.d.ts +23 -4
  56. package/dist/test-timings.d.ts.map +1 -1
  57. package/dist/test-timings.js +72 -12
  58. package/dist/version-actions.cjs +10 -11
  59. package/dist/version-actions.d.cts.map +1 -1
  60. package/dist/workspace-config-policy.d.ts.map +1 -1
  61. package/dist/workspace-config-policy.js +17 -22
  62. package/dist/workspace-manifest.js +3 -3
  63. package/executors.json +6 -5
  64. package/managed/raw/patches/nx@23.2.1.patch +118 -24
  65. package/managed/raw/patches/ttsc@0.34.1.patch +64 -0
  66. package/managed/raw/tooling/direnv/developer-links.ts +121 -51
  67. package/managed/raw/tooling/direnv/installed-bun-links.ts +7 -6
  68. package/managed/raw/tooling/direnv/setup-environment.ts +14 -4
  69. package/managed/raw/tooling/git-hooks/pinned-revisions-served.ts +252 -0
  70. package/managed/raw/tooling/git-hooks/pre-push.sh +34 -32
  71. package/package.json +58 -8
  72. package/runtime/nx-publish/.build-inputs.json +11 -0
  73. package/runtime-input.sh +50 -23
  74. package/src/bin/smoo-nx-go-test-build.ts +83 -0
  75. package/src/bin/smoo-nx-go-test-run.ts +140 -0
  76. package/src/bounded-test-policy.ts +9 -8
  77. package/src/cargo-workspace.ts +12 -24
  78. package/src/cross-check-policy.ts +2 -2
  79. package/src/deploy-policy.ts +11 -0
  80. package/src/executors/bounded-exec/executor.ts +61 -42
  81. package/src/executors/bounded-exec/mbx-pool.ts +97 -33
  82. package/src/executors/bounded-exec/progress.ts +5 -5
  83. package/src/executors/bounded-exec/runner-sizing.ts +73 -7
  84. package/src/executors/bounded-exec/runtime-pin.ts +1 -1
  85. package/src/executors/bounded-exec/verdict.ts +7 -0
  86. package/src/executors/wrangler-deploy/deploy-hash.ts +15 -0
  87. package/src/executors/wrangler-deploy/executor.ts +63 -0
  88. package/src/executors/wrangler-deploy/hasher.ts +111 -0
  89. package/src/executors/wrangler-deploy/schema.json +16 -0
  90. package/src/executors/wrangler-deploy/schema.ts +4 -0
  91. package/src/go-tests.ts +67 -0
  92. package/src/index.ts +294 -253
  93. package/src/managed-files/files.ts +5 -0
  94. package/src/process-group.ts +2 -2
  95. package/src/runtime-input-policy.ts +3 -3
  96. package/src/test-timings.ts +72 -14
  97. package/src/version-actions.cts +10 -11
  98. package/src/workspace-config-policy.ts +20 -29
  99. package/src/workspace-manifest.ts +3 -3
  100. package/test-timings.json +131 -130
  101. package/dist/executors/clean-outputs/executor.d.ts +0 -26
  102. package/dist/executors/clean-outputs/executor.d.ts.map +0 -1
  103. package/dist/executors/clean-outputs/executor.js +0 -83
  104. package/dist/executors/clean-outputs/schema.d.ts +0 -4
  105. package/dist/executors/clean-outputs/schema.d.ts.map +0 -1
  106. package/src/executors/clean-outputs/executor.ts +0 -131
  107. package/src/executors/clean-outputs/schema.json +0 -15
  108. package/src/executors/clean-outputs/schema.ts +0 -3
  109. /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,
@@ -42,8 +42,7 @@ import { CARGO_TOOLCHAIN_NAMED_INPUT, cargoRuntimeInput, cargoToolchainInputs }
42
42
  import {
43
43
  type AttributedCargoWorkspacePackage,
44
44
  attributeCargoWorkspacePackages,
45
- CARGO_TEST_ARCHIVE_FILE,
46
- CARGO_TEST_ARCHIVE_TARGET,
45
+ CARGO_TEST_BUILD_TARGET,
47
46
  CARGO_TEST_EXCEPTIONS_SUFFIX,
48
47
  CARGO_TEST_TARGET,
49
48
  type CargoCrossTestTarget,
@@ -96,14 +95,18 @@ import {
96
95
  import { runtimeInput, shellWord } from './runtime-input.js';
97
96
  import { inferredTaskKind, refuseBuildTestDependencies } from './task-graph-policy.js';
98
97
  import { postTasksExecution as postTaskResults, preTasksExecution as preTaskResults } from './task-results.js';
99
- 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';
100
104
  import { assertUpstreamBasePrecondition } from './test-walk-policy.js';
101
105
  import { type NativeTools, nativeToolCommand, nativeToolDependsOn, resolveNativeTools } from './tool-bins.js';
102
106
  import {
103
107
  isBuildOutputTargetName,
104
108
  isTestNamespaceTargetName,
105
109
  isTestRunnerTargetName,
106
- PLATFORM_TARGET_GLOBS,
107
110
  RELEASE_CONFIGURATION,
108
111
  } from './workspace-config-policy.js';
109
112
  import { globIndexedFiles } from './workspace-index.js';
@@ -519,15 +522,33 @@ const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
519
522
  /** The lockfiles of crates no resolved Cargo workspace claims, which have no lock-scope node. */
520
523
  const UNRESOLVED_CARGO_LOCK_INPUT = '{projectRoot}/**/Cargo.lock';
521
524
  /**
522
- * What the uncached `cargo-fetch` reads: the manifests and the lock that name the crates, and the Cargo configuration
523
- * that says where they come from. They key nothing; they are what a producer receipt binds the fetch to. Unnamed, Nx
524
- * plans every file of the project, which for a repository-root project includes its symlinked managed files, and a
525
- * 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.
526
529
  */
527
530
  function cargoFetchInputs(projectRoot: string): string[] {
528
531
  const base = projectRoot === '.' ? '{workspaceRoot}' : '{projectRoot}';
529
532
  return [`${base}/**/Cargo.toml`, `${base}/**/Cargo.lock`, `${base}/**/.cargo/config.toml`, `!${base}/**/target/**`];
530
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
+ }
531
552
  /** A full cargo-mutants sweep's wall-clock backstop: a sweep takes hours, and a hung one must still end. */
532
553
  const MUTATION_TIMEOUT_MS = 6 * 60 * 60 * 1000;
533
554
  // The toolchain half of a cargo task's identity lives in its own module
@@ -542,11 +563,22 @@ function fileHashInput(path: string): { runtime: string } {
542
563
  );
543
564
  }
544
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
+ }
545
577
  /**
546
578
  * One shell command that runs `steps` in order and stops at the first failure.
547
579
  *
548
- * For a step that CONSUMES what an earlier step produces — the archive needs
549
- * 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.
550
582
  * The order lives in the command because that is the only place a
551
583
  * producer-consumer pair inside one task can state it: `nx:run-commands`'
552
584
  * `commands` array is a set of independent commands that Nx runs side by side.
@@ -728,75 +760,105 @@ function createCargoWasmTarget(
728
760
  },
729
761
  };
730
762
  }
731
-
732
763
  /**
733
- * The workspace's test binaries, compiled once and packed into one file the
734
- * per-crate runners execute from.
764
+ * The workspace's test binaries, compiled once and run where they were built.
735
765
  *
736
766
  * This is the only cargo BUILD in the test graph. Before it, every per-crate
737
767
  * target ran `nextest run --workspace -E 'package(X)'`, which is a workspace
738
768
  * build with a filter: 32 such tasks on one repository each re-entered cargo,
739
769
  * re-resolved features and chained behind one another so the flocked `target/`
740
- * had a single writer. Reading from an archive removes the build from the run
741
- * entirely — the runners execute one extraction of it and never write cargo's
742
- * `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.
743
774
  *
744
775
  * It is also the step that keeps compilation out of the bounded test window: a
745
776
  * cold workspace can take many minutes to compile while still making progress,
746
777
  * which is not a property of the tests, and the runners start after it. It is
747
778
  * test work, so no `build` depends on it (a build never consumes test binaries)
748
- * and each target that executes them names the edge itself. There is no separate
749
- * uncached `cargo test --no-run` warm-up: it compiled the same dev units a
750
- * second time, queued on the same `target/` lock.
779
+ * and each target that executes them names the edge itself.
751
780
  *
752
- * Cached because it produces a VALUE: one file, not a mutable build tree Nx
753
- * would have to restore. `--workspace` matches the clippy selection exactly, so
754
- * 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.
755
801
  *
756
802
  * Tests compile the dev profile only, so no test target carries a
757
803
  * RELEASE_CONFIGURATION: Nx forwards a run's configuration down every
758
804
  * `dependsOn` edge to each target that has it, and a release configuration
759
805
  * must never turn the test binaries into release ones nobody runs.
760
806
  *
761
- * The directory and the archive are ONE command: nextest does not create the
762
- * archive's parent, so the archive step consumes what the `mkdir` produced.
763
- * The same command writes the task's hash beside the archive, the key every
764
- * runner's extraction is looked up by (smoo-nx-nextest-extract), and declares it
765
- * 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.
766
811
  */
767
- const CARGO_TEST_ARCHIVE_KEY_FILE = `${CARGO_TEST_ARCHIVE_FILE}${NEXTEST_ARCHIVE_KEY_SUFFIX}`;
768
-
769
- 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');
770
818
  return {
771
819
  executor: 'nx:run-commands',
772
820
  metadata: CARGO_PRODUCER_METADATA,
773
821
  cache: true,
774
822
  inputs: CARGO_INPUTS,
775
- 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'),
776
829
  options: {
777
830
  command: sequence([
778
- `mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`,
779
- cargoFrozen(
780
- `nextest archive --workspace --archive-file ${CARGO_TEST_ARCHIVE_FILE} --user-config-file none ${toolConfig}`,
781
- ),
782
- // 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}`,
783
834
  'test -n "$NX_TASK_HASH"',
784
- `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}`,
785
837
  ]),
786
838
  cwd: projectRoot,
787
839
  },
788
840
  };
789
841
  }
790
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
+
791
852
  /**
792
853
  * One foreign triple's test archive, and the target that EXECUTES it.
793
854
  *
794
- * A target-triple VARIANT of `cargo-test-archive`, not a second mechanism: same
795
- * `nextest archive --workspace`, same tool config layering, same
796
- * `--workspace-remap .` on the run — only `--target <triple>` and a distinct
797
- * archive file are added, because both archives coexist as declared Nx outputs
798
- * and one path for two triples would let a restored cache serve the wrong
799
- * 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.
800
862
  *
801
863
  * `cargo-nextest` where every other cargo target spells `cargo --frozen`, and
802
864
  * that is measured, not stylistic: cargo overwrites `CARGO` with its own path
@@ -810,13 +872,14 @@ function createCargoTestArchiveTarget(projectRoot: string, toolConfig: string):
810
872
  * inputs itself: both are otherwise attached by matching the
811
873
  * `cargo --frozen` prefix in a command, and this command does not carry it.
812
874
  *
813
- * The RUNNER declares no dependency on the archive and is not cached. That is
814
- * the whole point of splitting the pair: it runs on a machine where the triple
815
- * is native and the archive arrived as a file, so a dependency edge would ask
816
- * that machine to cross-build what it was sent, and a cache verdict would be
817
- * keyed on sources whose binaries it did not build. It is also the one cargo
818
- * target that needs no cargo: `nextest run --archive-file` extracts prebuilt
819
- * 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).
820
883
  */
821
884
  function createCargoCrossTestTargets(
822
885
  projectRoot: string,
@@ -833,6 +896,10 @@ function createCargoCrossTestTargets(
833
896
  `--archive-file ${archiveFile} --user-config-file none ${toolConfig}`,
834
897
  ]);
835
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}`;
836
903
  return {
837
904
  [cargoCrossTestArchiveTargetName(triple)]: {
838
905
  executor: archiveExecutor,
@@ -875,15 +942,22 @@ function createCargoCrossTestTargets(
875
942
  },
876
943
  },
877
944
  [cargoCrossTestTargetName(triple)]: {
878
- executor: '@smoothbricks/nx-plugin:bounded-exec',
879
- cache: false,
880
- 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
+ ],
881
957
  outputs: [],
882
958
  dependsOn: [],
883
959
  options: {
884
- command:
885
- `cargo-nextest nextest run --archive-file ${archiveFile} --workspace-remap . ` +
886
- `--no-tests=pass --user-config-file none ${toolConfig}`,
960
+ command: runCommand,
887
961
  cwd: projectRoot,
888
962
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
889
963
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
@@ -898,7 +972,7 @@ function createCargoTestTarget(projectRoot: string): TargetConfiguration {
898
972
  metadata: CARGO_PRODUCER_METADATA,
899
973
  cache: true,
900
974
  inputs: CARGO_INPUTS,
901
- dependsOn: [CARGO_TEST_ARCHIVE_TARGET],
975
+ dependsOn: [CARGO_TEST_BUILD_TARGET],
902
976
  options: {
903
977
  command: cargoFrozen('test --workspace'),
904
978
  cwd: projectRoot,
@@ -963,8 +1037,8 @@ export function pluginInstalledIn(
963
1037
  /**
964
1038
  * The npm packages a cached cargo target runs, for its `externalDependencies`.
965
1039
  * Cargo runs none. A target this plugin's executor runs, or whose command reads
966
- * the installed plugin's files (the nextest tool config, the archive
967
- * 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
968
1042
  * executor is not an `@nx/` one on every package in the lockfile, so a
969
1043
  * lockfile-only commit re-ran every cargo verdict.
970
1044
  */
@@ -1448,7 +1522,7 @@ function scriptcPlatformTargets(
1448
1522
  const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
1449
1523
 
1450
1524
  /**
1451
- * 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
1452
1526
  * per stage. Pull-request stages are `prN` for unbounded N, so an enumerated
1453
1527
  * `configurations` map cannot describe the surface that actually exists, and a
1454
1528
  * project carrying both spellings would have two ways to say one thing.
@@ -1457,15 +1531,18 @@ const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml
1457
1531
  * statement that CI deploys this project on every stage, and only the repository
1458
1532
  * can make it. A plugin that tagged what it inferred would enrol every private
1459
1533
  * wrangler project in CI deploys by writing the policy it is supposed to read.
1460
- *
1461
- * `{args.stage}` rather than `forwardAllArgs`: run-commands'
1462
- * `interpolateArgsIntoCommand` returns as soon as it sees `{args.` and never
1463
- * appends forwarded arguments, so `nx run web:deploy --stage=pr42` yields
1464
- * exactly one `--stage`, for an arbitrary preview stage no map could enumerate.
1465
- * An omitted stage interpolates to empty and `deploy-stage`'s required
1466
- * `--stage` refuses it, which is the failure we want at the boundary.
1467
1534
  */
1468
- 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
+ ];
1469
1546
 
1470
1547
  async function createProjectTargets(
1471
1548
  packageJsonPath: string,
@@ -1555,10 +1632,8 @@ async function createProjectTargets(
1555
1632
  repoRootPackages,
1556
1633
  );
1557
1634
  const inferCargoWasm = cargoWasmConfig !== null && !('cargo-wasm' in declaredTargets);
1558
- const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
1559
1635
  const hasOrdinaryBuildOutputTarget =
1560
- hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
1561
- const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
1636
+ hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || declaresPackageLocalBuildOutput(packageJson);
1562
1637
  const isDeployableWranglerProject =
1563
1638
  packageJson.private === true && WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
1564
1639
 
@@ -1704,9 +1779,9 @@ async function createProjectTargets(
1704
1779
  // result — duplicating the very edges the spread exists to add.
1705
1780
  //
1706
1781
  // `dependsOn` REPLACES rather than unions. These lists state what each target
1707
- // consumes — the fetched registry, the archive, the debug addon — and a
1782
+ // consumes — the fetched registry, the test build, the debug addon — and a
1708
1783
  // package that must re-route one (build its artifact ahead of the test run,
1709
- // 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
1710
1785
  // so by replacing the list; a union would make every inferred edge
1711
1786
  // unremovable and a corrected order unrepresentable.
1712
1787
  // Additive intent already has a spelling (`"..."` above), so a plugin-local
@@ -1743,24 +1818,26 @@ async function createProjectTargets(
1743
1818
  // as the outputs of the targets a repository adds to `dependsOn`. Hashing
1744
1819
  // those outputs here means a repository never has to restate `inputs` to
1745
1820
  // add them - and a restated `inputs` REPLACES this union with the root
1746
- // 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
1747
1822
  // cache-hits against edited crates while every per-crate test reruns on
1748
1823
  // the stale binary. That verdict is wrong, not merely slow.
1749
1824
  const workspaceCargoInputs: TargetConfiguration['inputs'] = [
1750
1825
  ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
1751
1826
  { dependentTasksOutputFiles: '**/*', transitive: false },
1752
1827
  ];
1753
- targets[CARGO_TEST_ARCHIVE_TARGET] = createCargoTestArchiveTarget(
1828
+ targets[CARGO_TEST_BUILD_TARGET] = createCargoTestBuildTarget(
1754
1829
  cargoWorkspaceRoot,
1755
1830
  nextestToolConfigArg(cargoWorkspaceRoot),
1831
+ nativeTools,
1756
1832
  );
1757
- // `archive.include` lives in the repository's nextest config, so that file
1758
- // decides what the archive CONTAINS, not merely how a run behaves.
1759
- 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}`];
1760
1836
  // One archive per declared foreign triple, from the same inputs and the
1761
- // same repository nextest config: an archive is the workspace's test
1762
- // binaries whichever machine they are for, so a change that invalidates
1763
- // 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.
1764
1841
  for (const crossTarget of listCargoCrossTestTargets(join(workspaceRoot, cargoWorkspaceRoot))) {
1765
1842
  Object.assign(
1766
1843
  targets,
@@ -1774,10 +1851,10 @@ async function createProjectTargets(
1774
1851
  );
1775
1852
  }
1776
1853
  // A serial group's filter can span members, so no single crate owns it. The root
1777
- // 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
1778
1855
  // of exactly the members its filter can select from (`filterScope`): a group scoped
1779
1856
  // to its packages reruns only when their sources or local dependencies change,
1780
- // 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.
1781
1858
  for (const group of cargoWorkspace.serialGroups) {
1782
1859
  targets[cargoTestGroupTargetName(group.group)] = cargoTestGroupTarget(
1783
1860
  cargoWorkspace,
@@ -1804,11 +1881,11 @@ async function createProjectTargets(
1804
1881
  // of its closure; a target dir per crate compiled every shared dependency
1805
1882
  // once per crate (49 closures, 11 GiB on one repository) and no per-crate
1806
1883
  // cache hit ever repaid that. The workspace inputs are exactly the union of
1807
- // 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
1808
1885
  // does. Non-root packages depend on this target. Its target dir is its own
1809
1886
  // (CARGO_LINT_CLIPPY_COMMAND, ./cross-check-policy.ts): Cargo flocks one
1810
1887
  // directory per invocation, and a workspace clippy holding the dev build's
1811
- // `target/` queued the archive and every dev build behind it.
1888
+ // `target/` queued the test build and every dev build behind it.
1812
1889
  targets['cargo-lint'] = {
1813
1890
  executor: 'nx:run-commands',
1814
1891
  metadata: CARGO_PRODUCER_METADATA,
@@ -1859,7 +1936,8 @@ async function createProjectTargets(
1859
1936
  cwd: cargoWorkspaceRoot,
1860
1937
  },
1861
1938
  };
1862
- // 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.
1863
1941
  // CI runs these per-PR via `cargo mutants --in-diff` (see mutants.toml docs).
1864
1942
  // bounded-exec sizes cargo-mutants' own jobserver to its CPU grant (its `cargo-mutants` runner kind), which
1865
1943
  // otherwise starts one task per core whatever else runs on the host. It reports no test bounded-exec can read as
@@ -1867,29 +1945,19 @@ async function createProjectTargets(
1867
1945
  targets.mutation = {
1868
1946
  executor: '@smoothbricks/nx-plugin:bounded-exec',
1869
1947
  metadata: CARGO_PRODUCER_METADATA,
1870
- cache: false,
1948
+ cache: true,
1949
+ inputs: [...workspaceCargoInputs, '{projectRoot}/**/.cargo/mutants.toml'],
1950
+ outputs: [`{workspaceRoot}/${posix.join(cargoWorkspaceRoot, 'mutants.out')}`],
1871
1951
  options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot, timeoutMs: MUTATION_TIMEOUT_MS },
1872
1952
  };
1953
+ // Cached on the code and toolchain it measures: a rerun with unchanged inputs measures nothing new.
1873
1954
  targets.bench = {
1874
1955
  executor: 'nx:run-commands',
1875
1956
  metadata: CARGO_PRODUCER_METADATA,
1876
- cache: false,
1957
+ cache: true,
1958
+ inputs: workspaceCargoInputs,
1877
1959
  options: { command: cargoFrozen('bench --workspace'), cwd: cargoWorkspaceRoot },
1878
1960
  };
1879
- // A read-only preview of the retention pass the plugin's postTasksExecution
1880
- // schedules after runs that built (@smoothbricks/cargo-retain): the superseded unit
1881
- // generations it would reclaim and why everything else stays. Never cached:
1882
- // the verdict is about this machine's disk, not the commit.
1883
- const retainTool = nativeToolDependsOn(nativeTools, 'cargo-retain');
1884
- targets['cargo-retention'] = {
1885
- executor: 'nx:run-commands',
1886
- cache: false,
1887
- ...(retainTool.length > 0 ? { dependsOn: retainTool } : {}),
1888
- options: {
1889
- command: nativeToolCommand(nativeTools, cargoWorkspaceRoot, 'cargo-retain', 'smoo-nx-cargo-retain'),
1890
- cwd: cargoWorkspaceRoot,
1891
- },
1892
- };
1893
1961
  }
1894
1962
 
1895
1963
  if (cargoWorkspace) {
@@ -1983,21 +2051,16 @@ async function createProjectTargets(
1983
2051
  if (frozenCargoManifests.size > 0) {
1984
2052
  targets[CARGO_FETCH_TARGET] = {
1985
2053
  executor: 'nx:run-commands',
1986
- // The download lands in CARGO_HOME, outside the workspace: a cache hit
1987
- // would skip work a cold registry still needs. Nothing here is a
1988
- // workspace output, so there is nothing for Nx to restore in its place.
1989
- cache: false,
1990
- 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: [],
1991
2060
  options: {
1992
2061
  // One fetch per manifest, independent of the others: Cargo's own
1993
2062
  // package-cache lock arbitrates the CARGO_HOME they share.
1994
- commands: [...frozenCargoManifests]
1995
- .sort()
1996
- .map((manifestPath) =>
1997
- manifestPath === 'Cargo.toml'
1998
- ? CARGO_FETCH_COMMAND
1999
- : `${CARGO_FETCH_COMMAND} --manifest-path ${manifestPath}`,
2000
- ),
2063
+ commands: [...frozenCargoManifests].sort().map(cargoFetchCommand),
2001
2064
  cwd: projectRoot,
2002
2065
  },
2003
2066
  };
@@ -2030,7 +2093,8 @@ async function createProjectTargets(
2030
2093
  // lock-scope node of the directory it runs in) unless its inputs already do.
2031
2094
  for (const [name, target] of Object.entries(targets)) {
2032
2095
  const text = targetCommandText(target);
2033
- 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;
2034
2098
  target.outputs ??= [];
2035
2099
  if (!target.cache) continue;
2036
2100
  const cwd: unknown = target.options?.cwd;
@@ -2038,7 +2102,9 @@ async function createProjectTargets(
2038
2102
  ? ` && cargo clippy -V${name === CARGO_CROSS_LINT_TARGET ? '' : ' && cargo fmt --version'}`
2039
2103
  : text.includes('nextest ')
2040
2104
  ? ' && cargo nextest --version'
2041
- : '';
2105
+ : text.includes('mutants ')
2106
+ ? ' && cargo mutants --version'
2107
+ : '';
2042
2108
  const inputs = target.inputs ?? CARGO_INPUTS;
2043
2109
  const namesPackages = inputs.some(
2044
2110
  (input) => typeof input === 'object' && 'externalDependencies' in input && !isCargoLockInput(input),
@@ -2065,7 +2131,7 @@ async function createProjectTargets(
2065
2131
  if (napiDebug && cargoWorkspace) {
2066
2132
  // A crate whose project also builds the debug cdylib runs its tests after
2067
2133
  // that build: the tests dlopen what `napi-debug` writes into `target/debug`,
2068
- // and an archived test binary still loads it from this tree.
2134
+ // and a test binary run in place loads it from this tree.
2069
2135
  const runners = [
2070
2136
  ...cargoPackagePlans.flatMap((plan) => plan.pieces.map((piece) => piece.targetName)),
2071
2137
  // The root owns the serial groups' runners, so they take its build as its pieces do.
@@ -2126,37 +2192,39 @@ async function createProjectTargets(
2126
2192
  }
2127
2193
  }
2128
2194
 
2129
- // 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.
2130
2197
  //
2131
2198
  // Nx's cache answers "did this exact input set already produce an output". A deploy's real
2132
- // question is "is this exact version live", and the two agree only until someone rolls back.
2133
- // After a rollback the workspace is unchanged, so the hash is unchanged, so a cached `deploy`
2134
- // reports success while the previous version keeps serving. No input tuning repairs that: a
2135
- // `runtime` input cannot even learn WHICH STAGE is being deployed. Nx hashes runtime inputs with
2136
- // the env from `getTaskSpecificEnv`, which deliberately excludes the task coordinates; input
2137
- // strings interpolate only `{workspaceRoot}`/`{projectRoot}`, never `{args.*}`; and overrides
2138
- // are not forwarded to `dependsOn` dependencies, so an auxiliary task cannot carry the stage
2139
- // either. (An executor's custom hasher is the single Nx API that does see `task.overrides`, if
2140
- // 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.
2141
2210
  //
2142
- // So the target is split along the line the question actually falls on. `deploy-build` is purely
2143
- // file-derived — build the artifact and whatever the build registers — and caches honestly.
2144
- // `deploy` reads live state every run and no-ops when live already equals the desired tag, which
2145
- // costs two Cloudflare calls and makes a redundant deploy provably free rather than assumed
2146
- // free. That is what lets ordering be an ordinary `dependsOn: ["<other>:deploy"]` edge at any
2147
- // depth, and it is why such an edge must point at `deploy` and not at `deploy-build`: a
2148
- // 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.
2149
2217
  //
2150
2218
  // Both are bases for a package-local declaration to land on, per the merge rules above: a
2151
2219
  // declaration naming `cache`, `inputs` or `dependsOn` REPLACES what is set here and inherits
2152
2220
  // everything it does not name, while Nx's `"..."` token expands to the inferred list at its
2153
2221
  // position. So a project adding a cross-project edge writes
2154
- // `"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 —
2155
2223
  // measured, not assumed, against an inferred base.
2156
2224
  //
2157
2225
  // `deploy` is INFERRED for a private wrangler project rather than patched onto a hand-written
2158
- // one. The command is a constant of the convention, not of the project: every consumer wrote
2159
- // 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
2160
2228
  // detection: a PUBLISHED package's wrangler manifest documents a binding for its consumers,
2161
2229
  // so inferring a deploy from it would put a live `wrangler deploy` of someone's documentation
2162
2230
  // one `nx run-many -t deploy` away. A published package that really is deployed declares
@@ -2178,11 +2246,12 @@ async function createProjectTargets(
2178
2246
  ? 'build'
2179
2247
  : null;
2180
2248
  targets[DEPLOY_TARGET] = {
2181
- executor: 'nx:run-commands',
2182
- cache: false,
2249
+ executor: WRANGLER_DEPLOY_EXECUTOR,
2250
+ cache: true,
2251
+ inputs: WRANGLER_DEPLOY_INPUTS,
2183
2252
  outputs: [],
2184
2253
  ...(fileDerivedHalf === null ? {} : { dependsOn: [fileDerivedHalf] }),
2185
- options: { command: WRANGLER_DEPLOY_COMMAND, cwd: projectRoot },
2254
+ options: {},
2186
2255
  };
2187
2256
  }
2188
2257
 
@@ -2216,49 +2285,10 @@ async function createProjectTargets(
2216
2285
  ],
2217
2286
  };
2218
2287
  }
2219
- // Every cargo build directory this project's own commands write. `clean`
2220
- // cannot learn them from `outputs`: a clippy or nextest target dir is a
2221
- // multi-GB build tree that must never enter the Nx cache, so the targets
2222
- // deliberately declare `outputs: []`. Reading `--target-dir` back off the
2223
- // commands means the list cannot drift from what actually gets written, and a
2224
- // directory is named relative to the command's own cwd, not the project root.
2225
- // The workspace's default `target/` is not listed: every dev build shares it.
2226
- const cargoBuildDirs = [
2227
- ...new Set(
2228
- Object.entries(targets).flatMap(([name, target]) => {
2229
- const cwd: unknown = target.options?.cwd;
2230
- const base = typeof cwd === 'string' ? cwd : projectRoot;
2231
- const dirs = [...targetCommandText(target).matchAll(/--target-dir\s+(\S+)/g)].flatMap((match) =>
2232
- match[1] === undefined ? [] : [match[1]],
2233
- );
2234
- if (name === CARGO_TEST_ARCHIVE_TARGET) {
2235
- dirs.push(posix.dirname(CARGO_TEST_ARCHIVE_FILE));
2236
- }
2237
- return dirs.map((dir) => `{workspaceRoot}/${posix.normalize(posix.join(base, dir))}`);
2238
- }),
2239
- ),
2240
- ].sort();
2241
- if (hasAnyBuildOutputTarget || cargoBuildDirs.length > 0) {
2242
- const declaredBuild = declaredTargets.build;
2243
- const declaredBuildOutputs =
2244
- isRecord(declaredBuild) && Array.isArray(declaredBuild.outputs)
2245
- ? declaredBuild.outputs.filter((output): output is string => typeof output === 'string')
2246
- : null;
2247
- targets.clean = {
2248
- executor: '@smoothbricks/nx-plugin:clean-outputs',
2249
- cache: false,
2250
- // Naming any output REPLACES the executor's default, so the build outputs
2251
- // it would have used are restated here rather than lost.
2252
- ...(cargoBuildDirs.length > 0
2253
- ? { options: { outputs: [...(declaredBuildOutputs ?? ['{projectRoot}/dist']), ...cargoBuildDirs] } }
2254
- : {}),
2255
- };
2256
- }
2257
-
2258
2288
  if (targets['typecheck-tests']) {
2259
2289
  if (hasLibTsconfig) {
2260
- // Test configs may resolve the package's own `./index.js` through dist.
2261
- // 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
2262
2292
  // dependency-project outputs reached through typecheck.
2263
2293
  targets['typecheck-tests'].dependsOn = ['tsc-js', 'typecheck'];
2264
2294
  } else if (targets.build) {
@@ -2269,8 +2299,8 @@ async function createProjectTargets(
2269
2299
  // A Bun suite that `--shard` splits and a `--timings` manifest balances gets a
2270
2300
  // check, which `lint` depends on, that the manifest names every file the
2271
2301
  // shards run: Bun charges an unnamed file the median, and unnamed files
2272
- // cluster into one shard. Uncached, because Bun's discovery also finds
2273
- // 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.
2274
2304
  const sharded = timingsShardedSuite(projectRoot, declaredTargets);
2275
2305
  if (!sharded.ok) {
2276
2306
  throw new Error(`${packageJsonPath}: ${sharded.error}`);
@@ -2278,7 +2308,11 @@ async function createProjectTargets(
2278
2308
  if (sharded.suite !== null) {
2279
2309
  targets[SHARD_TIMINGS_TARGET] = {
2280
2310
  executor: SHARD_TIMINGS_EXECUTOR,
2281
- cache: false,
2311
+ cache: true,
2312
+ inputs: [
2313
+ ...timingsSuiteInputs(sharded.suite),
2314
+ { externalDependencies: pluginInstalledIn(workspaceRoot) ? [PLUGIN_PACKAGE] : [] },
2315
+ ],
2282
2316
  outputs: [],
2283
2317
  options: { cwd: sharded.suite.cwd, args: sharded.suite.args },
2284
2318
  };
@@ -2930,15 +2964,9 @@ function isRecord(value: unknown): value is Record<string, unknown> {
2930
2964
  return value !== null && typeof value === 'object';
2931
2965
  }
2932
2966
 
2933
- function classifyPackageLocalBuildOutputs(packageJson: PackageJson): { ordinary: boolean; platform: boolean } {
2967
+ function declaresPackageLocalBuildOutput(packageJson: PackageJson): boolean {
2934
2968
  const targets = packageJson.nx?.targets;
2935
- const targetNames = isRecord(targets) ? Object.keys(targets) : [];
2936
- return {
2937
- ordinary: targetNames.some(isBuildOutputTargetName),
2938
- platform: targetNames.some((targetName) =>
2939
- PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1))),
2940
- ),
2941
- };
2969
+ return isRecord(targets) && Object.keys(targets).some(isBuildOutputTargetName);
2942
2970
  }
2943
2971
 
2944
2972
  interface CargoTargetRef {
@@ -2961,7 +2989,7 @@ interface CargoWorkspace {
2961
2989
  packages: CargoPackagePlan[];
2962
2990
  rootProjectName: string;
2963
2991
  projectRoot: string;
2964
- /** 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`). */
2965
2993
  serialGroups: SerialTestGroup[];
2966
2994
  /** One derivation memo for the whole graph computation (see cargoPackageTestInputs). */
2967
2995
  inputsCache: CargoInputsCache;
@@ -3109,7 +3137,7 @@ async function resolveCargoWorkspaces(
3109
3137
  * own time bound never delays an ordinary shard.
3110
3138
  *
3111
3139
  * Every piece EXECUTES, it never builds: it runs the binaries
3112
- * `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
3113
3141
  * removed the two costs the old shape could not avoid. `nextest run --workspace
3114
3142
  * -E 'package(X)'` re-entered cargo once per crate, and the `-p X` form
3115
3143
  * re-resolved that crate's features so cargo rebuilt the divergent half inside
@@ -3119,37 +3147,32 @@ async function resolveCargoWorkspaces(
3119
3147
  * it, so the filterset is the only selector left, and it selects the same tests
3120
3148
  * it always did.
3121
3149
  *
3122
- * The archive is unpacked ONCE per content, not once per piece. `nextest run
3123
- * --archive-file` extracts the whole archive into a temporary directory of its
3124
- * own on every run, so N pieces paid N extractions of every binary in the
3125
- * workspace to run 1/N of the tests each: on a workspace with ~200 test
3126
- * binaries, ~25 runners extracting side by side on a loaded host all hit the
3127
- * 120s bound still "Extracting". `smoo-nx-nextest-extract` reads the archive's
3128
- * key, the hash of the task that produced it (createCargoTestArchiveTarget),
3129
- * unpacks it under that key unless a previous runner already did — one
3130
- * extracts while the rest wait — and prints the directory; the run then reuses
3131
- * it through nextest's own reuse-build flags, which is what `--archive-file`
3132
- * does after unpacking. Keyed by the producing task's inputs, so a rebuilt or
3133
- * restored archive of other inputs can never run an older extraction's binaries. The one difference
3134
- * from `--archive-file` is the Rust standard library directory: nextest has no
3135
- * flag to remap it, so a run uses the producing toolchain's own sysroot rather
3136
- * than the archived copy of it — the same toolchain, because the archive's hash
3137
- * covers the toolchain pin. The extraction lives in Cargo's own target
3138
- * directory (`<target_directory>/nextest-extracted`), never in an Nx output: it
3139
- * is a multi-GB tree for a cached verdict that has no outputs, rebuilt from the
3140
- * archive like the rest of the build tree, and a checkout that keeps its build
3141
- * 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.
3142
3164
  *
3143
- * `--workspace-remap .` is not cosmetic. An archive records the ABSOLUTE paths
3144
- * of the tree that produced it; without the remap, a restored archive hands
3145
- * every test the producing tree's `CARGO_MANIFEST_DIR` — measured on a moved
3146
- * tree, tests then read another checkout's fixtures, or a path that no longer
3147
- * exists. With it, the runner's own cargo workspace root wins, so the archive
3148
- * is relocatable and one cache entry serves every checkout of the same commit.
3149
- * nextest also re-points `CARGO_BIN_EXE_<name>`/`NEXTEST_BIN_EXE_<name>` at the
3150
- * extracted binaries at RUNTIME (measured), but `env!` reads them at COMPILE
3151
- * time: a test that spawns `env!("CARGO_BIN_EXE_x")` holds the producing tree's
3152
- * 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.
3153
3176
  *
3154
3177
  * nextest.toml singles some tests out with an override: a raised `slow-timeout`
3155
3178
  * marks a test whose cost is not the suite's. Those are lifted OUT of the hash
@@ -3170,8 +3193,8 @@ async function resolveCargoWorkspaces(
3170
3193
  * making valid empty crates and shards fail execution.
3171
3194
  *
3172
3195
  * Pieces fan out rather than chain: a reused-build run writes nothing to cargo's
3173
- * `target/`, so no piece waits on another. The one extraction per archive is
3174
- * 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.
3175
3198
  */
3176
3199
  async function addCargoTestTargets(
3177
3200
  targets: Record<string, TargetConfiguration>,
@@ -3187,13 +3210,13 @@ async function addCargoTestTargets(
3187
3210
  continue;
3188
3211
  }
3189
3212
  const inputs = await cargoTestRunnerInputs(workspaceRoot, workspace, [plan.package.dir]);
3190
- const archive = cargoTargetDependency(currentProjectName, {
3213
+ const build = cargoTargetDependency(currentProjectName, {
3191
3214
  projectName: workspace.rootProjectName,
3192
- targetName: CARGO_TEST_ARCHIVE_TARGET,
3215
+ targetName: CARGO_TEST_BUILD_TARGET,
3193
3216
  });
3194
3217
  for (const piece of plan.pieces) {
3195
3218
  targetNames.push(piece.targetName);
3196
- targets[piece.targetName] = cargoTestRunnerTarget(workspace, nativeTools, archive, inputs, piece);
3219
+ targets[piece.targetName] = cargoTestRunnerTarget(workspace, nativeTools, build, inputs, piece);
3197
3220
  }
3198
3221
  }
3199
3222
  return targetNames;
@@ -3234,7 +3257,7 @@ function serialGroupMemberDirs(workspace: CargoWorkspace, group: SerialTestGroup
3234
3257
  * manifests, not unrelated sibling sources.
3235
3258
  *
3236
3259
  * The repository's own nextest config layers OVER the plugin's tool config, so it
3237
- * 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
3238
3261
  * would survive the change that invalidates it.
3239
3262
  */
3240
3263
  async function cargoTestRunnerInputs(
@@ -3254,8 +3277,8 @@ async function cargoTestRunnerInputs(
3254
3277
  }),
3255
3278
  ),
3256
3279
  );
3257
- // The archive unifies every built package's manifest into every test binary, and a runner's key does not follow the
3258
- // 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
3259
3282
  // runtime hash of external sources.
3260
3283
  const manifests: string[] = [];
3261
3284
  const external = new Map<string, string>();
@@ -3288,9 +3311,27 @@ async function cargoTestRunnerInputs(
3288
3311
  }
3289
3312
 
3290
3313
  /**
3291
- * One `nextest run` over a filterset against the workspace's archive. Every runner of the
3292
- * workspace builds its command here, so the extraction, reuse-build, tool config and cwd cannot
3293
- * 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.
3294
3335
  */
3295
3336
  function nextestRunnerCommand(
3296
3337
  workspace: CargoWorkspace,
@@ -3300,24 +3341,20 @@ function nextestRunnerCommand(
3300
3341
  ): string {
3301
3342
  const toolConfig = nextestToolConfigArg(workspace.projectRoot);
3302
3343
  // Relative to the runner's cwd, so the hashed command is the same in every checkout.
3303
- const extract = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-extract');
3304
- const reuseExtraction =
3305
- `--binaries-metadata "$extracted/${EXTRACTED_BINARIES_METADATA}" ` +
3306
- `--cargo-metadata "$extracted/${EXTRACTED_CARGO_METADATA}" ` +
3307
- `--target-dir-remap "$extracted/${EXTRACTED_TARGET_DIR}"`;
3308
- return (
3309
- `extracted="$(${extract} ${CARGO_TEST_ARCHIVE_FILE})" && ` +
3310
- cargoFrozen(
3311
- `nextest run ${reuseExtraction} --workspace-remap . -E ${shellWord(selector)}${flags} --user-config-file none ${toolConfig}`,
3312
- )
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}`,
3313
3350
  );
3314
3351
  }
3315
3352
 
3316
- /** 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. */
3317
3354
  function cargoTestRunnerTarget(
3318
3355
  workspace: CargoWorkspace,
3319
3356
  nativeTools: NativeTools | null,
3320
- archive: CargoTargetDependency,
3357
+ build: CargoTargetDependency,
3321
3358
  inputs: NonNullable<TargetConfiguration['inputs']>,
3322
3359
  piece: CargoTestPiece,
3323
3360
  ): TargetConfiguration {
@@ -3325,7 +3362,7 @@ function cargoTestRunnerTarget(
3325
3362
  executor: '@smoothbricks/nx-plugin:bounded-exec',
3326
3363
  cache: true,
3327
3364
  inputs,
3328
- dependsOn: [archive, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3365
+ dependsOn: [build, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3329
3366
  options: {
3330
3367
  command: nextestRunnerCommand(
3331
3368
  workspace,
@@ -3334,6 +3371,8 @@ function cargoTestRunnerTarget(
3334
3371
  `${piece.extra} --no-fail-fast --no-tests=pass`,
3335
3372
  ),
3336
3373
  cwd: workspace.projectRoot,
3374
+ fixtureCommand: nextestRunnerFixture(workspace, nativeTools),
3375
+ fixtureTimeoutMs: NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS,
3337
3376
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
3338
3377
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
3339
3378
  },
@@ -3358,10 +3397,12 @@ function cargoTestGroupTarget(
3358
3397
  executor: '@smoothbricks/nx-plugin:bounded-exec',
3359
3398
  cache: true,
3360
3399
  inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND)],
3361
- dependsOn: [CARGO_TEST_ARCHIVE_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3400
+ dependsOn: [CARGO_TEST_BUILD_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3362
3401
  options: {
3363
3402
  command: nextestRunnerCommand(workspace, nativeTools, group.filter, ' --no-fail-fast --no-tests=fail'),
3364
3403
  cwd: workspace.projectRoot,
3404
+ fixtureCommand: nextestRunnerFixture(workspace, nativeTools),
3405
+ fixtureTimeoutMs: NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS,
3365
3406
  idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
3366
3407
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
3367
3408
  parallelism: 1,