@smoothbricks/nx-plugin 0.4.5 → 0.4.6
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.
- package/README.md +35 -21
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +10 -4
- package/dist/cargo-workspace.d.ts +60 -2
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +96 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +187 -117
- package/nextest.toml +9 -3
- package/package.json +1 -1
- package/src/bounded-test-policy.test.ts +67 -0
- package/src/bounded-test-policy.ts +11 -4
- package/src/cargo-workspace.ts +117 -29
- package/src/index.test.ts +166 -103
- package/src/index.ts +205 -127
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { readJsonFile, } from 'nx/src/devkit-exports.js';
|
|
|
6
6
|
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
7
7
|
import { parse as parseToml } from 'smol-toml';
|
|
8
8
|
import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
|
|
9
|
-
import { attributeCargoWorkspacePackages, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, exceptionalTestFilter, listCargoWorkspacePackages,
|
|
9
|
+
import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_ARCHIVE_TARGET, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, createCargoInputsCache, exceptionalTestFilter, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, } from './cargo-workspace.js';
|
|
10
10
|
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoFrozen, } from './cross-check-policy.js';
|
|
11
11
|
import { isNonSourceDirectory } from './source-directories.js';
|
|
12
12
|
import { PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
@@ -93,9 +93,7 @@ function hostPlatformTargetNames(targetNames, hostPlatform) {
|
|
|
93
93
|
*/
|
|
94
94
|
function buildOutputTargetNames(targetNames) {
|
|
95
95
|
return [...new Set(targetNames)]
|
|
96
|
-
.filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) &&
|
|
97
|
-
!name.startsWith(`${CARGO_TEST_TARGET}-`) &&
|
|
98
|
-
!name.startsWith('cargo-lint-'))
|
|
96
|
+
.filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) && !name.startsWith(`${CARGO_TEST_TARGET}-`))
|
|
99
97
|
.sort();
|
|
100
98
|
}
|
|
101
99
|
//#region smoo!n/rust-output-target-inference
|
|
@@ -136,6 +134,20 @@ function cargoRuntimeInput(projectRoot, command) {
|
|
|
136
134
|
const quotedRoot = `'${projectRoot.replaceAll("'", "'\"'\"'")}'`;
|
|
137
135
|
return { runtime: `cd ${quotedRoot} && ${command}` };
|
|
138
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Everything a target actually runs, as one string. `nx:run-commands` accepts
|
|
139
|
+
* either spelling and inference asks four questions of the text — does it run
|
|
140
|
+
* frozen cargo, which tool's version keys its cache, which target directories
|
|
141
|
+
* does it write — so the two shapes collapse here once rather than at each ask.
|
|
142
|
+
*/
|
|
143
|
+
function targetCommandText(target) {
|
|
144
|
+
const command = target.options?.command;
|
|
145
|
+
const commands = target.options?.commands;
|
|
146
|
+
return [
|
|
147
|
+
typeof command === 'string' ? command : '',
|
|
148
|
+
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
149
|
+
].join('\n');
|
|
150
|
+
}
|
|
139
151
|
const NAPI_INPUTS = CARGO_OUTPUT_INPUTS;
|
|
140
152
|
const NAPI_TARGET_CONVENTIONS = {
|
|
141
153
|
'aarch64-apple-darwin': {
|
|
@@ -207,14 +219,20 @@ function createCargoWasmTarget(projectRoot, config, repoRooted) {
|
|
|
207
219
|
* which is not a property of the tests. `cargo test --no-run` pays that cost
|
|
208
220
|
* in its own unbounded target. Cargo reuses incremental compilation locally;
|
|
209
221
|
* Nx cannot cache this warming action without restoring shared mutable state.
|
|
210
|
-
* The bounded runner then uses the warm directory for the suites' own runtime.
|
|
211
222
|
*
|
|
212
223
|
* Cargo flocks one `target/` per invocation. Nx must not run two cargo
|
|
213
224
|
* writers on that directory at once — that is a mutex, not a deadlock, and
|
|
214
225
|
* the second process sits in "Blocking waiting for file lock" until a
|
|
215
226
|
* timeout. Inference serializes writers that share the default target dir
|
|
216
|
-
* (`napi-debug` after compile
|
|
217
|
-
*
|
|
227
|
+
* (`napi-debug` after compile).
|
|
228
|
+
*
|
|
229
|
+
* Clippy writes ONE shared `--target-dir target/cargo-lint` rather than a
|
|
230
|
+
* directory per crate. Per-crate dirs were never about overlap: clippy of a
|
|
231
|
+
* crate is a check build of its whole closure, so 49 crates meant 49 closure
|
|
232
|
+
* rebuilds and 11 GiB of target directories on one repository, and no
|
|
233
|
+
* per-crate cache hit ever repaid that. Sharing the directory costs nothing:
|
|
234
|
+
* cargo's own lock serializes the invocations that use it and each dependency
|
|
235
|
+
* artifact is then compiled once for all of them.
|
|
218
236
|
*/
|
|
219
237
|
function createCargoTestCompileTarget(projectRoot) {
|
|
220
238
|
return {
|
|
@@ -231,6 +249,41 @@ function createCargoTestCompileTarget(projectRoot) {
|
|
|
231
249
|
},
|
|
232
250
|
};
|
|
233
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* The workspace's test binaries, compiled once and packed into one file the
|
|
254
|
+
* per-crate runners execute from.
|
|
255
|
+
*
|
|
256
|
+
* This is the only cargo BUILD in the test graph. Before it, every per-crate
|
|
257
|
+
* target ran `nextest run --workspace -E 'package(X)'`, which is a workspace
|
|
258
|
+
* build with a filter: 32 such tasks on one repository each re-entered cargo,
|
|
259
|
+
* re-resolved features and chained behind one another so the flocked `target/`
|
|
260
|
+
* had a single writer. Reading from an archive removes the build from the run
|
|
261
|
+
* entirely — the runner extracts binaries into its own temporary directory and
|
|
262
|
+
* touches no shared state — which is what lets the runners fan out.
|
|
263
|
+
*
|
|
264
|
+
* Cached, unlike `cargo-test-compile`, because it produces a VALUE: one file,
|
|
265
|
+
* not a mutable build tree Nx would have to restore. `--workspace` matches the
|
|
266
|
+
* clippy selection exactly, so both gates unify features the same way.
|
|
267
|
+
*/
|
|
268
|
+
function createCargoTestArchiveTarget(projectRoot, toolConfig) {
|
|
269
|
+
const archiveCommand = (profile) => cargoFrozen(`nextest archive --workspace${profile} --archive-file ${CARGO_TEST_ARCHIVE_FILE} --user-config-file none ${toolConfig}`);
|
|
270
|
+
return {
|
|
271
|
+
executor: 'nx:run-commands',
|
|
272
|
+
cache: true,
|
|
273
|
+
inputs: CARGO_INPUTS,
|
|
274
|
+
outputs: [`{projectRoot}/${CARGO_TEST_ARCHIVE_FILE}`],
|
|
275
|
+
options: {
|
|
276
|
+
commands: [`mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`, archiveCommand('')],
|
|
277
|
+
cwd: projectRoot,
|
|
278
|
+
parallel: false,
|
|
279
|
+
},
|
|
280
|
+
configurations: {
|
|
281
|
+
production: {
|
|
282
|
+
commands: [`mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`, archiveCommand(' --release')],
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
}
|
|
234
287
|
function createCargoTestTarget(projectRoot) {
|
|
235
288
|
return {
|
|
236
289
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
@@ -493,9 +546,17 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
493
546
|
workspaceRoot,
|
|
494
547
|
absoluteProjectRoot: join(workspaceRoot, cargoWorkspaceRoot),
|
|
495
548
|
memberDir: plan.package.dir,
|
|
549
|
+
cache: cargoWorkspace.inputsCache,
|
|
496
550
|
})))).flat()),
|
|
497
551
|
];
|
|
498
552
|
targets[CARGO_TEST_COMPILE_TARGET].inputs = workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS;
|
|
553
|
+
targets[CARGO_TEST_ARCHIVE_TARGET] = createCargoTestArchiveTarget(cargoWorkspaceRoot, nextestToolConfigArg(workspaceRoot, cargoWorkspaceRoot, PLUGIN_NEXTEST_CONFIG));
|
|
554
|
+
// `archive.include` lives in the repository's nextest config, so that file
|
|
555
|
+
// decides what the archive CONTAINS, not merely how a run behaves.
|
|
556
|
+
targets[CARGO_TEST_ARCHIVE_TARGET].inputs = [
|
|
557
|
+
...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
|
|
558
|
+
`{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`,
|
|
559
|
+
];
|
|
499
560
|
const aggregateDependencies = cargoWorkspace.packages.flatMap((plan) => plan.pieces.map((piece) => cargoTargetDependency(projectName, {
|
|
500
561
|
projectName: plan.package.projectName,
|
|
501
562
|
targetName: piece.targetName,
|
|
@@ -504,20 +565,24 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
504
565
|
aggregateDependencies.length > 0
|
|
505
566
|
? { executor: 'nx:noop', cache: true, outputs: [], dependsOn: aggregateDependencies }
|
|
506
567
|
: createCargoTestTarget(cargoWorkspaceRoot);
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
568
|
+
// One clippy over the whole workspace, in one target dir. Clippy of a crate
|
|
569
|
+
// is a check build of its closure; a target dir per crate compiled every
|
|
570
|
+
// shared dependency once per crate (49 closures, 11 GiB on one repository)
|
|
571
|
+
// and no per-crate cache hit ever repaid that. The workspace inputs are
|
|
572
|
+
// exactly the union of every crate's, so the verdict caches on the same
|
|
573
|
+
// key set the compile does. Non-root packages depend on this target.
|
|
574
|
+
targets['cargo-lint'] = {
|
|
575
|
+
executor: 'nx:run-commands',
|
|
576
|
+
cache: true,
|
|
577
|
+
inputs: workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS,
|
|
578
|
+
outputs: [],
|
|
579
|
+
options: {
|
|
580
|
+
commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
|
|
581
|
+
cwd: cargoWorkspaceRoot,
|
|
582
|
+
parallel: false,
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
validationTargets.push('cargo-lint');
|
|
521
586
|
// The Linux arm of `cargo-lint`, as its own target. Rationale for the name,
|
|
522
587
|
// the command and the absent cross test leg lives in ./cross-check-policy.ts.
|
|
523
588
|
//
|
|
@@ -595,40 +660,19 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
595
660
|
dependsOn: packageTargetNames,
|
|
596
661
|
};
|
|
597
662
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
executor: 'nx:run-commands',
|
|
602
|
-
cache: true,
|
|
603
|
-
inputs: await cargoPackageTestInputs({
|
|
604
|
-
workspaceRoot,
|
|
605
|
-
absoluteProjectRoot: join(workspaceRoot, cargoWorkspace.projectRoot),
|
|
606
|
-
memberDir: plan.package.dir,
|
|
607
|
-
inputRoot: projectRoot === cargoWorkspace.projectRoot
|
|
608
|
-
? '{projectRoot}'
|
|
609
|
-
: posix.join('{workspaceRoot}', cargoWorkspace.projectRoot),
|
|
610
|
-
}),
|
|
611
|
-
outputs: [],
|
|
612
|
-
options: {
|
|
613
|
-
commands: [
|
|
614
|
-
`cargo fmt -p ${name} --check`,
|
|
615
|
-
cargoFrozen(`clippy -p ${name} --all-targets --target-dir target/cargo-lint-${name} -- -D warnings`),
|
|
616
|
-
],
|
|
617
|
-
cwd: cargoWorkspace.projectRoot,
|
|
618
|
-
parallel: false,
|
|
619
|
-
},
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
const lintPlans = isCargoWorkspaceRoot ? cargoWorkspace.packages : cargoPackagePlans;
|
|
623
|
-
if (lintPlans.length > 0) {
|
|
663
|
+
if (!isCargoWorkspaceRoot && cargoPackagePlans.length > 0) {
|
|
664
|
+
// The workspace root runs clippy for every member; a package owning
|
|
665
|
+
// crates validates through that one verdict.
|
|
624
666
|
targets['cargo-lint'] = {
|
|
625
667
|
executor: 'nx:noop',
|
|
626
668
|
cache: true,
|
|
627
669
|
outputs: [],
|
|
628
|
-
dependsOn:
|
|
629
|
-
projectName
|
|
630
|
-
|
|
631
|
-
|
|
670
|
+
dependsOn: [
|
|
671
|
+
cargoTargetDependency(projectName, {
|
|
672
|
+
projectName: cargoWorkspace.rootProjectName,
|
|
673
|
+
targetName: 'cargo-lint',
|
|
674
|
+
}),
|
|
675
|
+
],
|
|
632
676
|
};
|
|
633
677
|
validationTargets.push('cargo-lint');
|
|
634
678
|
}
|
|
@@ -703,12 +747,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
703
747
|
if (name === CARGO_FETCH_TARGET) {
|
|
704
748
|
continue;
|
|
705
749
|
}
|
|
706
|
-
const
|
|
707
|
-
const commands = target.options?.commands;
|
|
708
|
-
const text = [
|
|
709
|
-
typeof command === 'string' ? command : '',
|
|
710
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
711
|
-
].join('\n');
|
|
750
|
+
const text = targetCommandText(target);
|
|
712
751
|
if (text.includes(CARGO_FROZEN_PREFIX)) {
|
|
713
752
|
target.dependsOn = [CARGO_FETCH_TARGET, ...(target.dependsOn ?? [])];
|
|
714
753
|
}
|
|
@@ -720,12 +759,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
720
759
|
targetName: CARGO_FETCH_TARGET,
|
|
721
760
|
});
|
|
722
761
|
for (const target of Object.values(targets)) {
|
|
723
|
-
const
|
|
724
|
-
const commands = target.options?.commands;
|
|
725
|
-
const text = [
|
|
726
|
-
typeof command === 'string' ? command : '',
|
|
727
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
728
|
-
].join('\n');
|
|
762
|
+
const text = targetCommandText(target);
|
|
729
763
|
if (text.includes(CARGO_FROZEN_PREFIX)) {
|
|
730
764
|
target.dependsOn = [rootFetch, ...(target.dependsOn ?? [])];
|
|
731
765
|
}
|
|
@@ -734,12 +768,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
734
768
|
// Cache verdicts and dedicated artifacts, never Cargo's shared mutable build
|
|
735
769
|
// directories. Resolve tool versions from the command's actual directory.
|
|
736
770
|
for (const [name, target] of Object.entries(targets)) {
|
|
737
|
-
const
|
|
738
|
-
const commands = target.options?.commands;
|
|
739
|
-
const text = [
|
|
740
|
-
typeof command === 'string' ? command : '',
|
|
741
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
742
|
-
].join('\n');
|
|
771
|
+
const text = targetCommandText(target);
|
|
743
772
|
if (!text.includes(CARGO_FROZEN_PREFIX))
|
|
744
773
|
continue;
|
|
745
774
|
target.outputs ??= [];
|
|
@@ -748,7 +777,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
748
777
|
const cwd = target.options?.cwd;
|
|
749
778
|
const versions = name.startsWith('cargo-lint')
|
|
750
779
|
? ` && cargo clippy -V${name === CARGO_CROSS_LINT_TARGET ? '' : ' && cargo fmt --version'}`
|
|
751
|
-
: text.includes('nextest
|
|
780
|
+
: text.includes('nextest ')
|
|
752
781
|
? ' && cargo nextest --version'
|
|
753
782
|
: '';
|
|
754
783
|
target.inputs = [
|
|
@@ -758,8 +787,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
758
787
|
];
|
|
759
788
|
}
|
|
760
789
|
// Cargo flocks the workspace's default target/. Keep every writer out of the
|
|
761
|
-
// bounded test window by placing N-API debug builds
|
|
762
|
-
// chain as the root compile and per-crate runners.
|
|
790
|
+
// bounded test window by placing N-API debug builds behind the root compile.
|
|
763
791
|
const cargoTestCompileDependency = targets[CARGO_TEST_COMPILE_TARGET]
|
|
764
792
|
? CARGO_TEST_COMPILE_TARGET
|
|
765
793
|
: isCargoProject && cargoWorkspace
|
|
@@ -776,15 +804,18 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
776
804
|
}
|
|
777
805
|
}
|
|
778
806
|
if (napiDebug && cargoWorkspace) {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
807
|
+
// A crate whose project also builds the debug cdylib runs its tests after
|
|
808
|
+
// that build: the tests dlopen what `napi-debug` writes into `target/debug`,
|
|
809
|
+
// and an archived test binary still loads it from this tree. The old serial
|
|
810
|
+
// chain gave the same guarantee by accident, to whichever crate happened to
|
|
811
|
+
// be first; this states it for exactly the crates that own the artifact.
|
|
812
|
+
for (const plan of cargoPackagePlans) {
|
|
813
|
+
for (const piece of plan.pieces) {
|
|
814
|
+
const target = targets[piece.targetName];
|
|
815
|
+
if (target && !hasCargoTargetDependency(target.dependsOn ?? [], 'napi-debug')) {
|
|
816
|
+
target.dependsOn = [...(target.dependsOn ?? []), 'napi-debug'];
|
|
817
|
+
}
|
|
786
818
|
}
|
|
787
|
-
firstTarget.dependsOn = (firstTarget.dependsOn ?? []).map((dependency) => hasCargoTargetDependency([dependency], previous) ? 'napi-debug' : dependency);
|
|
788
819
|
}
|
|
789
820
|
}
|
|
790
821
|
else if (napiDebug) {
|
|
@@ -863,10 +894,37 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
863
894
|
],
|
|
864
895
|
};
|
|
865
896
|
}
|
|
866
|
-
|
|
897
|
+
// Every cargo build directory this project's own commands write. `clean`
|
|
898
|
+
// cannot learn them from `outputs`: a clippy or nextest target dir is a
|
|
899
|
+
// multi-GB build tree that must never enter the Nx cache (`target/cargo-lint`
|
|
900
|
+
// alone was 11 GiB when each of 49 crates had its own), so the targets
|
|
901
|
+
// deliberately declare `outputs: []`. Reading `--target-dir` back off the
|
|
902
|
+
// commands means the list cannot drift from what actually gets written, and a
|
|
903
|
+
// directory is named relative to the command's own cwd, not the project root.
|
|
904
|
+
const cargoBuildDirs = [
|
|
905
|
+
...new Set(Object.entries(targets).flatMap(([name, target]) => {
|
|
906
|
+
const cwd = target.options?.cwd;
|
|
907
|
+
const base = typeof cwd === 'string' ? cwd : projectRoot;
|
|
908
|
+
const dirs = [...targetCommandText(target).matchAll(/--target-dir\s+(\S+)/g)].flatMap((match) => match[1] === undefined ? [] : [match[1]]);
|
|
909
|
+
if (name === CARGO_TEST_ARCHIVE_TARGET) {
|
|
910
|
+
dirs.push(posix.dirname(CARGO_TEST_ARCHIVE_FILE));
|
|
911
|
+
}
|
|
912
|
+
return dirs.map((dir) => `{workspaceRoot}/${posix.normalize(posix.join(base, dir))}`);
|
|
913
|
+
})),
|
|
914
|
+
].sort();
|
|
915
|
+
if (hasAnyBuildOutputTarget || cargoBuildDirs.length > 0) {
|
|
916
|
+
const declaredBuild = declaredTargets.build;
|
|
917
|
+
const declaredBuildOutputs = isRecord(declaredBuild) && Array.isArray(declaredBuild.outputs)
|
|
918
|
+
? declaredBuild.outputs.filter((output) => typeof output === 'string')
|
|
919
|
+
: null;
|
|
867
920
|
targets.clean = {
|
|
868
921
|
executor: '@smoothbricks/nx-plugin:clean-outputs',
|
|
869
922
|
cache: false,
|
|
923
|
+
// Naming any output REPLACES the executor's default, so the build outputs
|
|
924
|
+
// it would have used are restated here rather than lost.
|
|
925
|
+
...(cargoBuildDirs.length > 0
|
|
926
|
+
? { options: { outputs: [...(declaredBuildOutputs ?? ['{projectRoot}/dist']), ...cargoBuildDirs] } }
|
|
927
|
+
: {}),
|
|
870
928
|
};
|
|
871
929
|
}
|
|
872
930
|
if (targets['typecheck-tests']) {
|
|
@@ -1288,10 +1346,6 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot) {
|
|
|
1288
1346
|
dir: posix.join(rootProject.root, pkg.dir),
|
|
1289
1347
|
})), projects).map((pkg) => ({ ...pkg, dir: posix.relative(rootProject.root, pkg.dir) || '.' }));
|
|
1290
1348
|
const packages = [];
|
|
1291
|
-
let previous = {
|
|
1292
|
-
projectName: rootProject.name,
|
|
1293
|
-
targetName: CARGO_TEST_COMPILE_TARGET,
|
|
1294
|
-
};
|
|
1295
1349
|
const exceptional = exceptionalTestFilter(PLUGIN_NEXTEST_CONFIG);
|
|
1296
1350
|
for (const pkg of attributed) {
|
|
1297
1351
|
const pieces = [];
|
|
@@ -1302,25 +1356,26 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot) {
|
|
|
1302
1356
|
const targetName = cargoTestPackageTargetName(pkg.name, sharded ? `shard${index}` : undefined);
|
|
1303
1357
|
pieces.push({
|
|
1304
1358
|
extra: sharded ? ` --partition hash:${index}/${pkg.testShards}` : '',
|
|
1305
|
-
previous,
|
|
1306
1359
|
selector: shardable,
|
|
1307
1360
|
targetName,
|
|
1308
1361
|
});
|
|
1309
|
-
previous = { projectName: pkg.projectName, targetName };
|
|
1310
1362
|
}
|
|
1311
1363
|
if (pin !== null) {
|
|
1312
1364
|
const targetName = cargoTestPackageTargetName(pkg.name, CARGO_TEST_EXCEPTIONS_SUFFIX);
|
|
1313
1365
|
pieces.push({
|
|
1314
1366
|
extra: '',
|
|
1315
|
-
previous,
|
|
1316
1367
|
selector: `package(${pkg.name}) and (${pin})`,
|
|
1317
1368
|
targetName,
|
|
1318
1369
|
});
|
|
1319
|
-
previous = { projectName: pkg.projectName, targetName };
|
|
1320
1370
|
}
|
|
1321
1371
|
packages.push({ package: pkg, pieces });
|
|
1322
1372
|
}
|
|
1323
|
-
workspaces.push({
|
|
1373
|
+
workspaces.push({
|
|
1374
|
+
packages,
|
|
1375
|
+
rootProjectName: rootProject.name,
|
|
1376
|
+
projectRoot: rootProject.root,
|
|
1377
|
+
inputsCache: createCargoInputsCache(),
|
|
1378
|
+
});
|
|
1324
1379
|
}
|
|
1325
1380
|
return workspaces;
|
|
1326
1381
|
}
|
|
@@ -1328,14 +1383,27 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot) {
|
|
|
1328
1383
|
* One bounded target per crate; a crate that declares `smoothbricks.test.shards`
|
|
1329
1384
|
* gets one per shard plus one for the tests nextest.toml singles out.
|
|
1330
1385
|
*
|
|
1331
|
-
*
|
|
1332
|
-
*
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
1338
|
-
*
|
|
1386
|
+
* Every piece EXECUTES, it never builds: `--archive-file` runs the binaries
|
|
1387
|
+
* `cargo-test-archive` compiled once for the whole workspace, extracted into
|
|
1388
|
+
* the runner's own temporary directory. That is what removed the two costs the
|
|
1389
|
+
* old shape could not avoid. `nextest run --workspace -E 'package(X)'` re-entered
|
|
1390
|
+
* cargo once per crate, and the `-p X` form re-resolved that crate's features so
|
|
1391
|
+
* cargo rebuilt the divergent half inside the bounded window — measured at 57.9s
|
|
1392
|
+
* of a 120s budget on a hosted 3-core macOS runner, killing the run with 264
|
|
1393
|
+
* tests still to go. Neither form is reachable from an archive: nextest rejects
|
|
1394
|
+
* `--workspace` and `-p` beside `--archive-file`, so the filterset is the only
|
|
1395
|
+
* selector left, and it selects the same tests it always did.
|
|
1396
|
+
*
|
|
1397
|
+
* `--workspace-remap .` is not cosmetic. An archive records the ABSOLUTE paths
|
|
1398
|
+
* of the tree that produced it; without the remap, a restored archive hands
|
|
1399
|
+
* every test the producing tree's `CARGO_MANIFEST_DIR` — measured on a moved
|
|
1400
|
+
* tree, tests then read another checkout's fixtures, or a path that no longer
|
|
1401
|
+
* exists. With it, the runner's own cargo workspace root wins, so the archive
|
|
1402
|
+
* is relocatable and one cache entry serves every checkout of the same commit.
|
|
1403
|
+
* nextest also re-points `CARGO_BIN_EXE_<name>`/`NEXTEST_BIN_EXE_<name>` at the
|
|
1404
|
+
* extracted binaries at RUNTIME (measured), but `env!` reads them at COMPILE
|
|
1405
|
+
* time: a test that spawns `env!("CARGO_BIN_EXE_x")` holds the producing tree's
|
|
1406
|
+
* path and must read the runtime variable instead to survive relocation.
|
|
1339
1407
|
*
|
|
1340
1408
|
* nextest.toml singles some tests out with an override, and each such class
|
|
1341
1409
|
* breaks a shard in its own way — a `test-group` is scoped to one nextest RUN
|
|
@@ -1356,21 +1424,13 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot) {
|
|
|
1356
1424
|
* Detecting that regression requires a separate coverage policy rather than
|
|
1357
1425
|
* making valid empty crates and shards fail execution.
|
|
1358
1426
|
*
|
|
1359
|
-
* Pieces
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1362
|
-
*/
|
|
1363
|
-
/**
|
|
1364
|
-
* Root mode keeps `--workspace` and adds `-p` only to make the owning crate
|
|
1365
|
-
* explicit in the command Nx attributes to its project. Cargo treats
|
|
1366
|
-
* `--workspace -p X` as the full workspace selection, so `-p` is inert for
|
|
1367
|
-
* feature resolution; the nextest filterset is what narrows the tests that run.
|
|
1368
|
-
* Never drop `--workspace`: `-p X` alone re-resolves features for one package
|
|
1369
|
-
* and defeats the compile target's shared artifacts.
|
|
1427
|
+
* Pieces fan out rather than chain. The chain existed because every runner was
|
|
1428
|
+
* a cargo writer on one flocked `target/`; an archive run writes nothing there,
|
|
1429
|
+
* so the only serialization left is the one the machine's own scheduler does.
|
|
1370
1430
|
*/
|
|
1371
1431
|
async function addCargoTestTargets(targets, currentProjectName, projectRoot, workspaceRoot, workspace) {
|
|
1372
1432
|
const targetNames = [];
|
|
1373
|
-
const
|
|
1433
|
+
const toolConfig = nextestToolConfigArg(workspaceRoot, workspace.projectRoot, PLUGIN_NEXTEST_CONFIG);
|
|
1374
1434
|
for (const plan of workspace.packages) {
|
|
1375
1435
|
if (plan.package.projectRoot !== projectRoot) {
|
|
1376
1436
|
continue;
|
|
@@ -1379,6 +1439,10 @@ async function addCargoTestTargets(targets, currentProjectName, projectRoot, wor
|
|
|
1379
1439
|
// A workspace nextest build unifies features across every selected member.
|
|
1380
1440
|
// A sibling manifest can therefore change this crate's tests without being
|
|
1381
1441
|
// a path dependency. Track those manifests, not unrelated sibling sources.
|
|
1442
|
+
//
|
|
1443
|
+
// The repository's own nextest config layers OVER the plugin's tool config,
|
|
1444
|
+
// so it decides timeouts, groups and archive contents: a cached verdict that
|
|
1445
|
+
// ignored it would survive the change that invalidates it.
|
|
1382
1446
|
const inputs = [
|
|
1383
1447
|
...new Set([
|
|
1384
1448
|
...(await cargoPackageTestInputs({
|
|
@@ -1386,31 +1450,37 @@ async function addCargoTestTargets(targets, currentProjectName, projectRoot, wor
|
|
|
1386
1450
|
absoluteProjectRoot: join(workspaceRoot, workspace.projectRoot),
|
|
1387
1451
|
memberDir: plan.package.dir,
|
|
1388
1452
|
inputRoot,
|
|
1453
|
+
cache: workspace.inputsCache,
|
|
1389
1454
|
})),
|
|
1390
1455
|
...workspace.packages.map((member) => posix.join(inputRoot, member.package.dir, 'Cargo.toml')),
|
|
1456
|
+
posix.join(inputRoot, NEXTEST_REPO_CONFIG_PATH),
|
|
1391
1457
|
]),
|
|
1392
1458
|
{
|
|
1393
1459
|
runtime: `bun -e 'console.log(new Bun.CryptoHasher("sha256").update(require("node:fs").readFileSync(process.argv[1])).digest("hex"))' '${PLUGIN_NEXTEST_CONFIG.replaceAll("'", "'\"'\"'")}'`,
|
|
1394
1460
|
},
|
|
1395
1461
|
];
|
|
1462
|
+
const archive = cargoTargetDependency(currentProjectName, {
|
|
1463
|
+
projectName: workspace.rootProjectName,
|
|
1464
|
+
targetName: CARGO_TEST_ARCHIVE_TARGET,
|
|
1465
|
+
});
|
|
1396
1466
|
for (const piece of plan.pieces) {
|
|
1397
1467
|
targetNames.push(piece.targetName);
|
|
1398
1468
|
targets[piece.targetName] = {
|
|
1399
1469
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
1400
1470
|
cache: true,
|
|
1401
1471
|
inputs,
|
|
1402
|
-
dependsOn: [
|
|
1472
|
+
dependsOn: [archive],
|
|
1403
1473
|
options: {
|
|
1404
|
-
command: cargoFrozen(`nextest run --
|
|
1474
|
+
command: cargoFrozen(`nextest run --archive-file ${CARGO_TEST_ARCHIVE_FILE} --workspace-remap . -E '${piece.selector}'${piece.extra} --no-tests=pass --user-config-file none ${toolConfig}`),
|
|
1405
1475
|
cwd: workspace.projectRoot,
|
|
1406
1476
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
1407
1477
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
1408
1478
|
},
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
},
|
|
1479
|
+
// The archive already holds the profile it was built with, and nextest
|
|
1480
|
+
// rejects `--release` beside `--archive-file`. Nx propagates the
|
|
1481
|
+
// configuration to this target's dependencies, so `:production` builds
|
|
1482
|
+
// the release archive and this command runs exactly what it finds.
|
|
1483
|
+
configurations: { production: {} },
|
|
1414
1484
|
};
|
|
1415
1485
|
}
|
|
1416
1486
|
}
|
package/nextest.toml
CHANGED
|
@@ -34,8 +34,14 @@ slow-timeout = { period = "180s", terminate-after = 1 }
|
|
|
34
34
|
# test joins the group by being named for what it touches. A bare `real_*` filter
|
|
35
35
|
# would be wrong here — unrelated `real_*` tests exist in columine-arrow,
|
|
36
36
|
# cowshed-cli and cowshed-gateway that touch no disk image at all.
|
|
37
|
+
#
|
|
38
|
+
# The `@tool:smoo:` prefix is not decoration: this file is passed as
|
|
39
|
+
# `--tool-config-file smoo:...` so a repository's own `.config/nextest.toml`
|
|
40
|
+
# can override it, and nextest REFUSES a tool config whose groups are not
|
|
41
|
+
# namespaced ("test groups must start with '@tool:<tool-name>:'") precisely so
|
|
42
|
+
# a tool cannot collide with a repository's group of the same name.
|
|
37
43
|
[test-groups]
|
|
38
|
-
real-apfs = { max-threads = 1 }
|
|
44
|
+
"@tool:smoo:real-apfs" = { max-threads = 1 }
|
|
39
45
|
|
|
40
46
|
# The full-lifecycle real-APFS tests cannot meet the default deadline, and
|
|
41
47
|
# `specs/cowshed/08_testing.md` already contains the arithmetic that proves it.
|
|
@@ -72,8 +78,8 @@ real-apfs = { max-threads = 1 }
|
|
|
72
78
|
[[profile.default.overrides]]
|
|
73
79
|
filter = 'test(/real_apfs_.*_substrate_lifecycle/)'
|
|
74
80
|
slow-timeout = { period = "60s", terminate-after = 1 }
|
|
75
|
-
test-group = 'real-apfs'
|
|
81
|
+
test-group = '@tool:smoo:real-apfs'
|
|
76
82
|
|
|
77
83
|
[[profile.default.overrides]]
|
|
78
84
|
filter = 'test(/real_apfs_/)'
|
|
79
|
-
test-group = 'real-apfs'
|
|
85
|
+
test-group = '@tool:smoo:real-apfs'
|
package/package.json
CHANGED
|
@@ -512,6 +512,73 @@ describe('cargo-test reachability policy', () => {
|
|
|
512
512
|
}
|
|
513
513
|
});
|
|
514
514
|
|
|
515
|
+
it('treats the workspace nextest archive as a build, never as a runner or a crate', async () => {
|
|
516
|
+
const root = await mkdtemp(join(tmpdir(), 'cargo-reach-archive-'));
|
|
517
|
+
try {
|
|
518
|
+
await writeJson(join(root, 'package.json'), { name: '@scope/root', private: true, workspaces: ['packages/*'] });
|
|
519
|
+
await writeJson(join(root, 'packages/rusty/package.json'), { name: 'rusty', nx: { name: 'rusty' } });
|
|
520
|
+
await mkdir(join(root, 'packages/rusty/crates/core'), { recursive: true });
|
|
521
|
+
await writeFile(join(root, 'packages/rusty/Cargo.toml'), '[workspace]\nmembers = ["crates/core"]\n');
|
|
522
|
+
await writeFile(join(root, 'packages/rusty/crates/core/Cargo.toml'), '[package]\nname = "rusty-core"\n');
|
|
523
|
+
|
|
524
|
+
// `cargo nextest archive` compiles test binaries and packs them. It is
|
|
525
|
+
// the same silent green as `--no-run`: the word "nextest" appears, no
|
|
526
|
+
// test runs. And `cargo-test-archive` is not a crate called "archive".
|
|
527
|
+
const archiveOptions = new Map<string, Record<string, unknown>>([
|
|
528
|
+
[
|
|
529
|
+
'cargo-test-archive',
|
|
530
|
+
{ command: 'cargo --frozen nextest archive --workspace --archive-file target/nextest/archive.tar.zst' },
|
|
531
|
+
],
|
|
532
|
+
]);
|
|
533
|
+
const archiveOnly: ResolvedProjectTargets = {
|
|
534
|
+
root: 'packages/rusty',
|
|
535
|
+
targets: new Set(['test', 'cargo-test', 'cargo-test-archive']),
|
|
536
|
+
targetDependencies: new Map([
|
|
537
|
+
['test', ['cargo-test']],
|
|
538
|
+
['cargo-test', ['cargo-test-archive']],
|
|
539
|
+
]),
|
|
540
|
+
targetExecutors: new Map([
|
|
541
|
+
['test', 'nx:noop'],
|
|
542
|
+
['cargo-test', 'nx:noop'],
|
|
543
|
+
['cargo-test-archive', 'nx:run-commands'],
|
|
544
|
+
]),
|
|
545
|
+
targetOptions: archiveOptions,
|
|
546
|
+
};
|
|
547
|
+
const issues = checkWorkspaceCargoTestReachabilityPolicy(root, {
|
|
548
|
+
resolvedTargetsByProject: new Map([['rusty', archiveOnly]]),
|
|
549
|
+
});
|
|
550
|
+
expect(issues).toHaveLength(1);
|
|
551
|
+
expect(issues[0]?.message).toContain('RUNS tests');
|
|
552
|
+
|
|
553
|
+
const withRunner: ResolvedProjectTargets = {
|
|
554
|
+
...archiveOnly,
|
|
555
|
+
targets: new Set([...archiveOnly.targets, 'cargo-test-rusty-core']),
|
|
556
|
+
targetDependencies: new Map([
|
|
557
|
+
['test', ['cargo-test']],
|
|
558
|
+
['cargo-test', ['cargo-test-rusty-core']],
|
|
559
|
+
['cargo-test-rusty-core', ['cargo-test-archive']],
|
|
560
|
+
]),
|
|
561
|
+
targetOptions: new Map([
|
|
562
|
+
...archiveOptions,
|
|
563
|
+
[
|
|
564
|
+
'cargo-test-rusty-core',
|
|
565
|
+
{
|
|
566
|
+
command:
|
|
567
|
+
"cargo --frozen nextest run --archive-file target/nextest/archive.tar.zst --workspace-remap . -E 'package(rusty-core)'",
|
|
568
|
+
},
|
|
569
|
+
],
|
|
570
|
+
]),
|
|
571
|
+
};
|
|
572
|
+
expect(
|
|
573
|
+
checkWorkspaceCargoTestReachabilityPolicy(root, {
|
|
574
|
+
resolvedTargetsByProject: new Map([['rusty', withRunner]]),
|
|
575
|
+
}),
|
|
576
|
+
).toEqual([]);
|
|
577
|
+
} finally {
|
|
578
|
+
await rm(root, { recursive: true, force: true });
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
|
|
515
582
|
it('ignores projects with no cargo-test target', async () => {
|
|
516
583
|
const root = await mkdtemp(join(tmpdir(), 'cargo-reach-ts-'));
|
|
517
584
|
try {
|
|
@@ -207,9 +207,12 @@ export function checkWorkspaceCargoTestReachabilityPolicy(
|
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
209
|
* True when `target`, or something in its dependency closure, invokes cargo in a
|
|
210
|
-
* mode that executes tests.
|
|
211
|
-
* `cargo test --no-run
|
|
212
|
-
*
|
|
210
|
+
* mode that executes tests. The two workspace-wide preparation targets are
|
|
211
|
+
* deliberately excluded: `cargo-test-compile` is `cargo test --no-run` and
|
|
212
|
+
* `cargo-test-archive` is `cargo nextest archive`. Both prove the binaries
|
|
213
|
+
* build and nothing about them running, and both say "test"/"nextest" in their
|
|
214
|
+
* command — a closure holding only these is the silent green this check exists
|
|
215
|
+
* to catch.
|
|
213
216
|
*/
|
|
214
217
|
function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string): boolean {
|
|
215
218
|
const visiting = new Set<string>();
|
|
@@ -219,7 +222,11 @@ function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string
|
|
|
219
222
|
}
|
|
220
223
|
visiting.add(targetName);
|
|
221
224
|
const command = commandOf(project, targetName);
|
|
222
|
-
const runs =
|
|
225
|
+
const runs =
|
|
226
|
+
command !== undefined &&
|
|
227
|
+
/\btest\b|\bnextest\b/.test(command) &&
|
|
228
|
+
!command.includes('--no-run') &&
|
|
229
|
+
!command.includes('nextest archive');
|
|
223
230
|
const reached =
|
|
224
231
|
runs ||
|
|
225
232
|
(project.targetDependencies?.get(targetName) ?? []).some((dependency) =>
|