@smoothbricks/nx-plugin 0.4.4 → 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 +189 -118
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +3 -2
- package/dist/source-directories.d.ts +11 -0
- package/dist/source-directories.d.ts.map +1 -0
- package/dist/source-directories.js +19 -0
- 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 +207 -128
- package/src/package-target-policy.test.ts +16 -0
- package/src/package-target-policy.ts +3 -2
- package/src/source-directories.ts +21 -0
package/dist/index.js
CHANGED
|
@@ -6,8 +6,9 @@ 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
|
+
import { isNonSourceDirectory } from './source-directories.js';
|
|
11
12
|
import { PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
12
13
|
export { CARGO_TEST_COMPILE_TARGET };
|
|
13
14
|
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
|
|
@@ -32,7 +33,7 @@ async function javaScriptSourceFiles(directory) {
|
|
|
32
33
|
const files = [];
|
|
33
34
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
34
35
|
if (entry.isDirectory()) {
|
|
35
|
-
if (entry.name
|
|
36
|
+
if (!isNonSourceDirectory(entry.name)) {
|
|
36
37
|
files.push(...(await javaScriptSourceFiles(join(directory, entry.name))));
|
|
37
38
|
}
|
|
38
39
|
}
|
|
@@ -92,9 +93,7 @@ function hostPlatformTargetNames(targetNames, hostPlatform) {
|
|
|
92
93
|
*/
|
|
93
94
|
function buildOutputTargetNames(targetNames) {
|
|
94
95
|
return [...new Set(targetNames)]
|
|
95
|
-
.filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) &&
|
|
96
|
-
!name.startsWith(`${CARGO_TEST_TARGET}-`) &&
|
|
97
|
-
!name.startsWith('cargo-lint-'))
|
|
96
|
+
.filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) && !name.startsWith(`${CARGO_TEST_TARGET}-`))
|
|
98
97
|
.sort();
|
|
99
98
|
}
|
|
100
99
|
//#region smoo!n/rust-output-target-inference
|
|
@@ -135,6 +134,20 @@ function cargoRuntimeInput(projectRoot, command) {
|
|
|
135
134
|
const quotedRoot = `'${projectRoot.replaceAll("'", "'\"'\"'")}'`;
|
|
136
135
|
return { runtime: `cd ${quotedRoot} && ${command}` };
|
|
137
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
|
+
}
|
|
138
151
|
const NAPI_INPUTS = CARGO_OUTPUT_INPUTS;
|
|
139
152
|
const NAPI_TARGET_CONVENTIONS = {
|
|
140
153
|
'aarch64-apple-darwin': {
|
|
@@ -206,14 +219,20 @@ function createCargoWasmTarget(projectRoot, config, repoRooted) {
|
|
|
206
219
|
* which is not a property of the tests. `cargo test --no-run` pays that cost
|
|
207
220
|
* in its own unbounded target. Cargo reuses incremental compilation locally;
|
|
208
221
|
* Nx cannot cache this warming action without restoring shared mutable state.
|
|
209
|
-
* The bounded runner then uses the warm directory for the suites' own runtime.
|
|
210
222
|
*
|
|
211
223
|
* Cargo flocks one `target/` per invocation. Nx must not run two cargo
|
|
212
224
|
* writers on that directory at once — that is a mutex, not a deadlock, and
|
|
213
225
|
* the second process sits in "Blocking waiting for file lock" until a
|
|
214
226
|
* timeout. Inference serializes writers that share the default target dir
|
|
215
|
-
* (`napi-debug` after compile
|
|
216
|
-
*
|
|
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.
|
|
217
236
|
*/
|
|
218
237
|
function createCargoTestCompileTarget(projectRoot) {
|
|
219
238
|
return {
|
|
@@ -230,6 +249,41 @@ function createCargoTestCompileTarget(projectRoot) {
|
|
|
230
249
|
},
|
|
231
250
|
};
|
|
232
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
|
+
}
|
|
233
287
|
function createCargoTestTarget(projectRoot) {
|
|
234
288
|
return {
|
|
235
289
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
@@ -492,9 +546,17 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
492
546
|
workspaceRoot,
|
|
493
547
|
absoluteProjectRoot: join(workspaceRoot, cargoWorkspaceRoot),
|
|
494
548
|
memberDir: plan.package.dir,
|
|
549
|
+
cache: cargoWorkspace.inputsCache,
|
|
495
550
|
})))).flat()),
|
|
496
551
|
];
|
|
497
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
|
+
];
|
|
498
560
|
const aggregateDependencies = cargoWorkspace.packages.flatMap((plan) => plan.pieces.map((piece) => cargoTargetDependency(projectName, {
|
|
499
561
|
projectName: plan.package.projectName,
|
|
500
562
|
targetName: piece.targetName,
|
|
@@ -503,20 +565,24 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
503
565
|
aggregateDependencies.length > 0
|
|
504
566
|
? { executor: 'nx:noop', cache: true, outputs: [], dependsOn: aggregateDependencies }
|
|
505
567
|
: createCargoTestTarget(cargoWorkspaceRoot);
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
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');
|
|
520
586
|
// The Linux arm of `cargo-lint`, as its own target. Rationale for the name,
|
|
521
587
|
// the command and the absent cross test leg lives in ./cross-check-policy.ts.
|
|
522
588
|
//
|
|
@@ -594,40 +660,19 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
594
660
|
dependsOn: packageTargetNames,
|
|
595
661
|
};
|
|
596
662
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
executor: 'nx:run-commands',
|
|
601
|
-
cache: true,
|
|
602
|
-
inputs: await cargoPackageTestInputs({
|
|
603
|
-
workspaceRoot,
|
|
604
|
-
absoluteProjectRoot: join(workspaceRoot, cargoWorkspace.projectRoot),
|
|
605
|
-
memberDir: plan.package.dir,
|
|
606
|
-
inputRoot: projectRoot === cargoWorkspace.projectRoot
|
|
607
|
-
? '{projectRoot}'
|
|
608
|
-
: posix.join('{workspaceRoot}', cargoWorkspace.projectRoot),
|
|
609
|
-
}),
|
|
610
|
-
outputs: [],
|
|
611
|
-
options: {
|
|
612
|
-
commands: [
|
|
613
|
-
`cargo fmt -p ${name} --check`,
|
|
614
|
-
cargoFrozen(`clippy -p ${name} --all-targets --target-dir target/cargo-lint-${name} -- -D warnings`),
|
|
615
|
-
],
|
|
616
|
-
cwd: cargoWorkspace.projectRoot,
|
|
617
|
-
parallel: false,
|
|
618
|
-
},
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
const lintPlans = isCargoWorkspaceRoot ? cargoWorkspace.packages : cargoPackagePlans;
|
|
622
|
-
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.
|
|
623
666
|
targets['cargo-lint'] = {
|
|
624
667
|
executor: 'nx:noop',
|
|
625
668
|
cache: true,
|
|
626
669
|
outputs: [],
|
|
627
|
-
dependsOn:
|
|
628
|
-
projectName
|
|
629
|
-
|
|
630
|
-
|
|
670
|
+
dependsOn: [
|
|
671
|
+
cargoTargetDependency(projectName, {
|
|
672
|
+
projectName: cargoWorkspace.rootProjectName,
|
|
673
|
+
targetName: 'cargo-lint',
|
|
674
|
+
}),
|
|
675
|
+
],
|
|
631
676
|
};
|
|
632
677
|
validationTargets.push('cargo-lint');
|
|
633
678
|
}
|
|
@@ -702,12 +747,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
702
747
|
if (name === CARGO_FETCH_TARGET) {
|
|
703
748
|
continue;
|
|
704
749
|
}
|
|
705
|
-
const
|
|
706
|
-
const commands = target.options?.commands;
|
|
707
|
-
const text = [
|
|
708
|
-
typeof command === 'string' ? command : '',
|
|
709
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
710
|
-
].join('\n');
|
|
750
|
+
const text = targetCommandText(target);
|
|
711
751
|
if (text.includes(CARGO_FROZEN_PREFIX)) {
|
|
712
752
|
target.dependsOn = [CARGO_FETCH_TARGET, ...(target.dependsOn ?? [])];
|
|
713
753
|
}
|
|
@@ -719,12 +759,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
719
759
|
targetName: CARGO_FETCH_TARGET,
|
|
720
760
|
});
|
|
721
761
|
for (const target of Object.values(targets)) {
|
|
722
|
-
const
|
|
723
|
-
const commands = target.options?.commands;
|
|
724
|
-
const text = [
|
|
725
|
-
typeof command === 'string' ? command : '',
|
|
726
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
727
|
-
].join('\n');
|
|
762
|
+
const text = targetCommandText(target);
|
|
728
763
|
if (text.includes(CARGO_FROZEN_PREFIX)) {
|
|
729
764
|
target.dependsOn = [rootFetch, ...(target.dependsOn ?? [])];
|
|
730
765
|
}
|
|
@@ -733,12 +768,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
733
768
|
// Cache verdicts and dedicated artifacts, never Cargo's shared mutable build
|
|
734
769
|
// directories. Resolve tool versions from the command's actual directory.
|
|
735
770
|
for (const [name, target] of Object.entries(targets)) {
|
|
736
|
-
const
|
|
737
|
-
const commands = target.options?.commands;
|
|
738
|
-
const text = [
|
|
739
|
-
typeof command === 'string' ? command : '',
|
|
740
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
741
|
-
].join('\n');
|
|
771
|
+
const text = targetCommandText(target);
|
|
742
772
|
if (!text.includes(CARGO_FROZEN_PREFIX))
|
|
743
773
|
continue;
|
|
744
774
|
target.outputs ??= [];
|
|
@@ -747,7 +777,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
747
777
|
const cwd = target.options?.cwd;
|
|
748
778
|
const versions = name.startsWith('cargo-lint')
|
|
749
779
|
? ` && cargo clippy -V${name === CARGO_CROSS_LINT_TARGET ? '' : ' && cargo fmt --version'}`
|
|
750
|
-
: text.includes('nextest
|
|
780
|
+
: text.includes('nextest ')
|
|
751
781
|
? ' && cargo nextest --version'
|
|
752
782
|
: '';
|
|
753
783
|
target.inputs = [
|
|
@@ -757,8 +787,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
757
787
|
];
|
|
758
788
|
}
|
|
759
789
|
// Cargo flocks the workspace's default target/. Keep every writer out of the
|
|
760
|
-
// bounded test window by placing N-API debug builds
|
|
761
|
-
// chain as the root compile and per-crate runners.
|
|
790
|
+
// bounded test window by placing N-API debug builds behind the root compile.
|
|
762
791
|
const cargoTestCompileDependency = targets[CARGO_TEST_COMPILE_TARGET]
|
|
763
792
|
? CARGO_TEST_COMPILE_TARGET
|
|
764
793
|
: isCargoProject && cargoWorkspace
|
|
@@ -775,15 +804,18 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
775
804
|
}
|
|
776
805
|
}
|
|
777
806
|
if (napiDebug && cargoWorkspace) {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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
|
+
}
|
|
785
818
|
}
|
|
786
|
-
firstTarget.dependsOn = (firstTarget.dependsOn ?? []).map((dependency) => hasCargoTargetDependency([dependency], previous) ? 'napi-debug' : dependency);
|
|
787
819
|
}
|
|
788
820
|
}
|
|
789
821
|
else if (napiDebug) {
|
|
@@ -862,10 +894,37 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
862
894
|
],
|
|
863
895
|
};
|
|
864
896
|
}
|
|
865
|
-
|
|
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;
|
|
866
920
|
targets.clean = {
|
|
867
921
|
executor: '@smoothbricks/nx-plugin:clean-outputs',
|
|
868
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
|
+
: {}),
|
|
869
928
|
};
|
|
870
929
|
}
|
|
871
930
|
if (targets['typecheck-tests']) {
|
|
@@ -1287,10 +1346,6 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot) {
|
|
|
1287
1346
|
dir: posix.join(rootProject.root, pkg.dir),
|
|
1288
1347
|
})), projects).map((pkg) => ({ ...pkg, dir: posix.relative(rootProject.root, pkg.dir) || '.' }));
|
|
1289
1348
|
const packages = [];
|
|
1290
|
-
let previous = {
|
|
1291
|
-
projectName: rootProject.name,
|
|
1292
|
-
targetName: CARGO_TEST_COMPILE_TARGET,
|
|
1293
|
-
};
|
|
1294
1349
|
const exceptional = exceptionalTestFilter(PLUGIN_NEXTEST_CONFIG);
|
|
1295
1350
|
for (const pkg of attributed) {
|
|
1296
1351
|
const pieces = [];
|
|
@@ -1301,25 +1356,26 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot) {
|
|
|
1301
1356
|
const targetName = cargoTestPackageTargetName(pkg.name, sharded ? `shard${index}` : undefined);
|
|
1302
1357
|
pieces.push({
|
|
1303
1358
|
extra: sharded ? ` --partition hash:${index}/${pkg.testShards}` : '',
|
|
1304
|
-
previous,
|
|
1305
1359
|
selector: shardable,
|
|
1306
1360
|
targetName,
|
|
1307
1361
|
});
|
|
1308
|
-
previous = { projectName: pkg.projectName, targetName };
|
|
1309
1362
|
}
|
|
1310
1363
|
if (pin !== null) {
|
|
1311
1364
|
const targetName = cargoTestPackageTargetName(pkg.name, CARGO_TEST_EXCEPTIONS_SUFFIX);
|
|
1312
1365
|
pieces.push({
|
|
1313
1366
|
extra: '',
|
|
1314
|
-
previous,
|
|
1315
1367
|
selector: `package(${pkg.name}) and (${pin})`,
|
|
1316
1368
|
targetName,
|
|
1317
1369
|
});
|
|
1318
|
-
previous = { projectName: pkg.projectName, targetName };
|
|
1319
1370
|
}
|
|
1320
1371
|
packages.push({ package: pkg, pieces });
|
|
1321
1372
|
}
|
|
1322
|
-
workspaces.push({
|
|
1373
|
+
workspaces.push({
|
|
1374
|
+
packages,
|
|
1375
|
+
rootProjectName: rootProject.name,
|
|
1376
|
+
projectRoot: rootProject.root,
|
|
1377
|
+
inputsCache: createCargoInputsCache(),
|
|
1378
|
+
});
|
|
1323
1379
|
}
|
|
1324
1380
|
return workspaces;
|
|
1325
1381
|
}
|
|
@@ -1327,14 +1383,27 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot) {
|
|
|
1327
1383
|
* One bounded target per crate; a crate that declares `smoothbricks.test.shards`
|
|
1328
1384
|
* gets one per shard plus one for the tests nextest.toml singles out.
|
|
1329
1385
|
*
|
|
1330
|
-
*
|
|
1331
|
-
*
|
|
1332
|
-
*
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
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.
|
|
1338
1407
|
*
|
|
1339
1408
|
* nextest.toml singles some tests out with an override, and each such class
|
|
1340
1409
|
* breaks a shard in its own way — a `test-group` is scoped to one nextest RUN
|
|
@@ -1355,21 +1424,13 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot) {
|
|
|
1355
1424
|
* Detecting that regression requires a separate coverage policy rather than
|
|
1356
1425
|
* making valid empty crates and shards fail execution.
|
|
1357
1426
|
*
|
|
1358
|
-
* Pieces
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
1361
|
-
*/
|
|
1362
|
-
/**
|
|
1363
|
-
* Root mode keeps `--workspace` and adds `-p` only to make the owning crate
|
|
1364
|
-
* explicit in the command Nx attributes to its project. Cargo treats
|
|
1365
|
-
* `--workspace -p X` as the full workspace selection, so `-p` is inert for
|
|
1366
|
-
* feature resolution; the nextest filterset is what narrows the tests that run.
|
|
1367
|
-
* Never drop `--workspace`: `-p X` alone re-resolves features for one package
|
|
1368
|
-
* 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.
|
|
1369
1430
|
*/
|
|
1370
1431
|
async function addCargoTestTargets(targets, currentProjectName, projectRoot, workspaceRoot, workspace) {
|
|
1371
1432
|
const targetNames = [];
|
|
1372
|
-
const
|
|
1433
|
+
const toolConfig = nextestToolConfigArg(workspaceRoot, workspace.projectRoot, PLUGIN_NEXTEST_CONFIG);
|
|
1373
1434
|
for (const plan of workspace.packages) {
|
|
1374
1435
|
if (plan.package.projectRoot !== projectRoot) {
|
|
1375
1436
|
continue;
|
|
@@ -1378,6 +1439,10 @@ async function addCargoTestTargets(targets, currentProjectName, projectRoot, wor
|
|
|
1378
1439
|
// A workspace nextest build unifies features across every selected member.
|
|
1379
1440
|
// A sibling manifest can therefore change this crate's tests without being
|
|
1380
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.
|
|
1381
1446
|
const inputs = [
|
|
1382
1447
|
...new Set([
|
|
1383
1448
|
...(await cargoPackageTestInputs({
|
|
@@ -1385,31 +1450,37 @@ async function addCargoTestTargets(targets, currentProjectName, projectRoot, wor
|
|
|
1385
1450
|
absoluteProjectRoot: join(workspaceRoot, workspace.projectRoot),
|
|
1386
1451
|
memberDir: plan.package.dir,
|
|
1387
1452
|
inputRoot,
|
|
1453
|
+
cache: workspace.inputsCache,
|
|
1388
1454
|
})),
|
|
1389
1455
|
...workspace.packages.map((member) => posix.join(inputRoot, member.package.dir, 'Cargo.toml')),
|
|
1456
|
+
posix.join(inputRoot, NEXTEST_REPO_CONFIG_PATH),
|
|
1390
1457
|
]),
|
|
1391
1458
|
{
|
|
1392
1459
|
runtime: `bun -e 'console.log(new Bun.CryptoHasher("sha256").update(require("node:fs").readFileSync(process.argv[1])).digest("hex"))' '${PLUGIN_NEXTEST_CONFIG.replaceAll("'", "'\"'\"'")}'`,
|
|
1393
1460
|
},
|
|
1394
1461
|
];
|
|
1462
|
+
const archive = cargoTargetDependency(currentProjectName, {
|
|
1463
|
+
projectName: workspace.rootProjectName,
|
|
1464
|
+
targetName: CARGO_TEST_ARCHIVE_TARGET,
|
|
1465
|
+
});
|
|
1395
1466
|
for (const piece of plan.pieces) {
|
|
1396
1467
|
targetNames.push(piece.targetName);
|
|
1397
1468
|
targets[piece.targetName] = {
|
|
1398
1469
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
1399
1470
|
cache: true,
|
|
1400
1471
|
inputs,
|
|
1401
|
-
dependsOn: [
|
|
1472
|
+
dependsOn: [archive],
|
|
1402
1473
|
options: {
|
|
1403
|
-
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}`),
|
|
1404
1475
|
cwd: workspace.projectRoot,
|
|
1405
1476
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
1406
1477
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
1407
1478
|
},
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
},
|
|
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: {} },
|
|
1413
1484
|
};
|
|
1414
1485
|
}
|
|
1415
1486
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,IAAI,EAAc,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,IAAI,EAAc,MAAM,0BAA0B,CAAC;AAIxF,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,kBAAkB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACvE,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AA0HD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGhF;AA6LD,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAMR;AAgoBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAsBlH;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8B1G;AAwJD,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACrC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACjC,aAAa,EAAE,CAEjB;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,EACnC,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAAC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAO,GAC1F,OAAO,CAMT;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAoBhH;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8BxG"}
|
|
@@ -2,6 +2,7 @@ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { getProjects, readJson, updateJson } from 'nx/src/devkit-exports.js';
|
|
4
4
|
import { boundedTestScriptAlias } from './bounded-test-policy.js';
|
|
5
|
+
import { isNonSourceDirectory } from './source-directories.js';
|
|
5
6
|
import { BUILD_OUTPUT_DEPENDENCIES, LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, } from './workspace-config-policy.js';
|
|
6
7
|
export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
7
8
|
const workspaceDependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
|
|
@@ -446,7 +447,7 @@ function directoryContainsTestFiles(path) {
|
|
|
446
447
|
return false;
|
|
447
448
|
}
|
|
448
449
|
for (const entry of readdirSync(path, { withFileTypes: true })) {
|
|
449
|
-
if (entry.name
|
|
450
|
+
if (isNonSourceDirectory(entry.name)) {
|
|
450
451
|
continue;
|
|
451
452
|
}
|
|
452
453
|
const entryPath = join(path, entry.name);
|
|
@@ -756,7 +757,7 @@ function directoryContainsTestFilesTree(tree, path) {
|
|
|
756
757
|
return false;
|
|
757
758
|
}
|
|
758
759
|
for (const entry of tree.children(path)) {
|
|
759
|
-
if (entry
|
|
760
|
+
if (isNonSourceDirectory(entry)) {
|
|
760
761
|
continue;
|
|
761
762
|
}
|
|
762
763
|
const entryPath = `${path}/${entry}`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directories no source walk descends into. Every walker in this plugin runs on
|
|
3
|
+
* project load, so descending into a build output is paid on each graph
|
|
4
|
+
* computation: a `target/` at 50k files or a `dist-test/` left by an old config
|
|
5
|
+
* dominated the load. Anything a build writes is excluded by shape rather than
|
|
6
|
+
* by an enumerated name: every `dist*` variant, cargo's `target`, and any
|
|
7
|
+
* dot-directory (`.runtime`, `.cache`, `.venv`, `.git`, tooling state) — a
|
|
8
|
+
* source tree never starts with a dot.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isNonSourceDirectory(name: string): boolean;
|
|
11
|
+
//# sourceMappingURL=source-directories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-directories.d.ts","sourceRoot":"","sources":["../src/source-directories.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAW1D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directories no source walk descends into. Every walker in this plugin runs on
|
|
3
|
+
* project load, so descending into a build output is paid on each graph
|
|
4
|
+
* computation: a `target/` at 50k files or a `dist-test/` left by an old config
|
|
5
|
+
* dominated the load. Anything a build writes is excluded by shape rather than
|
|
6
|
+
* by an enumerated name: every `dist*` variant, cargo's `target`, and any
|
|
7
|
+
* dot-directory (`.runtime`, `.cache`, `.venv`, `.git`, tooling state) — a
|
|
8
|
+
* source tree never starts with a dot.
|
|
9
|
+
*/
|
|
10
|
+
export function isNonSourceDirectory(name) {
|
|
11
|
+
return (name.startsWith('.') ||
|
|
12
|
+
name === 'node_modules' ||
|
|
13
|
+
name === 'target' ||
|
|
14
|
+
name === 'coverage' ||
|
|
15
|
+
name === 'build' ||
|
|
16
|
+
name === '__pycache__' ||
|
|
17
|
+
name === 'dist' ||
|
|
18
|
+
name.startsWith('dist-'));
|
|
19
|
+
}
|
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'
|