@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/src/index.ts
CHANGED
|
@@ -16,14 +16,19 @@ import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-t
|
|
|
16
16
|
import {
|
|
17
17
|
type AttributedCargoWorkspacePackage,
|
|
18
18
|
attributeCargoWorkspacePackages,
|
|
19
|
+
CARGO_TEST_ARCHIVE_FILE,
|
|
20
|
+
CARGO_TEST_ARCHIVE_TARGET,
|
|
19
21
|
CARGO_TEST_COMPILE_TARGET,
|
|
20
22
|
CARGO_TEST_EXCEPTIONS_SUFFIX,
|
|
21
23
|
CARGO_TEST_TARGET,
|
|
24
|
+
type CargoInputsCache,
|
|
22
25
|
cargoPackageTestInputs,
|
|
23
26
|
cargoTestPackageTargetName,
|
|
27
|
+
createCargoInputsCache,
|
|
24
28
|
exceptionalTestFilter,
|
|
25
29
|
listCargoWorkspacePackages,
|
|
26
|
-
|
|
30
|
+
NEXTEST_REPO_CONFIG_PATH,
|
|
31
|
+
nextestToolConfigArg,
|
|
27
32
|
} from './cargo-workspace.js';
|
|
28
33
|
import {
|
|
29
34
|
CARGO_CROSS_LINT_COMMAND,
|
|
@@ -134,12 +139,7 @@ function hostPlatformTargetNames(targetNames: Iterable<string>, hostPlatform: Na
|
|
|
134
139
|
*/
|
|
135
140
|
function buildOutputTargetNames(targetNames: Iterable<string>): string[] {
|
|
136
141
|
return [...new Set(targetNames)]
|
|
137
|
-
.filter(
|
|
138
|
-
(name) =>
|
|
139
|
-
BUILD_OUTPUT_TARGET_PATTERN.test(name) &&
|
|
140
|
-
!name.startsWith(`${CARGO_TEST_TARGET}-`) &&
|
|
141
|
-
!name.startsWith('cargo-lint-'),
|
|
142
|
-
)
|
|
142
|
+
.filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) && !name.startsWith(`${CARGO_TEST_TARGET}-`))
|
|
143
143
|
.sort();
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -182,6 +182,21 @@ function cargoRuntimeInput(projectRoot: string, command: string): { runtime: str
|
|
|
182
182
|
const quotedRoot = `'${projectRoot.replaceAll("'", "'\"'\"'")}'`;
|
|
183
183
|
return { runtime: `cd ${quotedRoot} && ${command}` };
|
|
184
184
|
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Everything a target actually runs, as one string. `nx:run-commands` accepts
|
|
188
|
+
* either spelling and inference asks four questions of the text — does it run
|
|
189
|
+
* frozen cargo, which tool's version keys its cache, which target directories
|
|
190
|
+
* does it write — so the two shapes collapse here once rather than at each ask.
|
|
191
|
+
*/
|
|
192
|
+
function targetCommandText(target: TargetConfiguration): string {
|
|
193
|
+
const command: unknown = target.options?.command;
|
|
194
|
+
const commands: unknown = target.options?.commands;
|
|
195
|
+
return [
|
|
196
|
+
typeof command === 'string' ? command : '',
|
|
197
|
+
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
198
|
+
].join('\n');
|
|
199
|
+
}
|
|
185
200
|
const NAPI_INPUTS = CARGO_OUTPUT_INPUTS;
|
|
186
201
|
|
|
187
202
|
interface NapiTargetConvention extends NapiPlatform {
|
|
@@ -276,14 +291,20 @@ function createCargoWasmTarget(
|
|
|
276
291
|
* which is not a property of the tests. `cargo test --no-run` pays that cost
|
|
277
292
|
* in its own unbounded target. Cargo reuses incremental compilation locally;
|
|
278
293
|
* Nx cannot cache this warming action without restoring shared mutable state.
|
|
279
|
-
* The bounded runner then uses the warm directory for the suites' own runtime.
|
|
280
294
|
*
|
|
281
295
|
* Cargo flocks one `target/` per invocation. Nx must not run two cargo
|
|
282
296
|
* writers on that directory at once — that is a mutex, not a deadlock, and
|
|
283
297
|
* the second process sits in "Blocking waiting for file lock" until a
|
|
284
298
|
* timeout. Inference serializes writers that share the default target dir
|
|
285
|
-
* (`napi-debug` after compile
|
|
286
|
-
*
|
|
299
|
+
* (`napi-debug` after compile).
|
|
300
|
+
*
|
|
301
|
+
* Clippy writes ONE shared `--target-dir target/cargo-lint` rather than a
|
|
302
|
+
* directory per crate. Per-crate dirs were never about overlap: clippy of a
|
|
303
|
+
* crate is a check build of its whole closure, so 49 crates meant 49 closure
|
|
304
|
+
* rebuilds and 11 GiB of target directories on one repository, and no
|
|
305
|
+
* per-crate cache hit ever repaid that. Sharing the directory costs nothing:
|
|
306
|
+
* cargo's own lock serializes the invocations that use it and each dependency
|
|
307
|
+
* artifact is then compiled once for all of them.
|
|
287
308
|
*/
|
|
288
309
|
function createCargoTestCompileTarget(projectRoot: string): TargetConfiguration {
|
|
289
310
|
return {
|
|
@@ -301,6 +322,45 @@ function createCargoTestCompileTarget(projectRoot: string): TargetConfiguration
|
|
|
301
322
|
};
|
|
302
323
|
}
|
|
303
324
|
|
|
325
|
+
/**
|
|
326
|
+
* The workspace's test binaries, compiled once and packed into one file the
|
|
327
|
+
* per-crate runners execute from.
|
|
328
|
+
*
|
|
329
|
+
* This is the only cargo BUILD in the test graph. Before it, every per-crate
|
|
330
|
+
* target ran `nextest run --workspace -E 'package(X)'`, which is a workspace
|
|
331
|
+
* build with a filter: 32 such tasks on one repository each re-entered cargo,
|
|
332
|
+
* re-resolved features and chained behind one another so the flocked `target/`
|
|
333
|
+
* had a single writer. Reading from an archive removes the build from the run
|
|
334
|
+
* entirely — the runner extracts binaries into its own temporary directory and
|
|
335
|
+
* touches no shared state — which is what lets the runners fan out.
|
|
336
|
+
*
|
|
337
|
+
* Cached, unlike `cargo-test-compile`, because it produces a VALUE: one file,
|
|
338
|
+
* not a mutable build tree Nx would have to restore. `--workspace` matches the
|
|
339
|
+
* clippy selection exactly, so both gates unify features the same way.
|
|
340
|
+
*/
|
|
341
|
+
function createCargoTestArchiveTarget(projectRoot: string, toolConfig: string): TargetConfiguration {
|
|
342
|
+
const archiveCommand = (profile: string): string =>
|
|
343
|
+
cargoFrozen(
|
|
344
|
+
`nextest archive --workspace${profile} --archive-file ${CARGO_TEST_ARCHIVE_FILE} --user-config-file none ${toolConfig}`,
|
|
345
|
+
);
|
|
346
|
+
return {
|
|
347
|
+
executor: 'nx:run-commands',
|
|
348
|
+
cache: true,
|
|
349
|
+
inputs: CARGO_INPUTS,
|
|
350
|
+
outputs: [`{projectRoot}/${CARGO_TEST_ARCHIVE_FILE}`],
|
|
351
|
+
options: {
|
|
352
|
+
commands: [`mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`, archiveCommand('')],
|
|
353
|
+
cwd: projectRoot,
|
|
354
|
+
parallel: false,
|
|
355
|
+
},
|
|
356
|
+
configurations: {
|
|
357
|
+
production: {
|
|
358
|
+
commands: [`mkdir -p ${posix.dirname(CARGO_TEST_ARCHIVE_FILE)}`, archiveCommand(' --release')],
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
304
364
|
function createCargoTestTarget(projectRoot: string): TargetConfiguration {
|
|
305
365
|
return {
|
|
306
366
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
@@ -621,6 +681,7 @@ async function createProjectTargets(
|
|
|
621
681
|
workspaceRoot,
|
|
622
682
|
absoluteProjectRoot: join(workspaceRoot, cargoWorkspaceRoot),
|
|
623
683
|
memberDir: plan.package.dir,
|
|
684
|
+
cache: cargoWorkspace.inputsCache,
|
|
624
685
|
}),
|
|
625
686
|
),
|
|
626
687
|
)
|
|
@@ -628,6 +689,16 @@ async function createProjectTargets(
|
|
|
628
689
|
),
|
|
629
690
|
];
|
|
630
691
|
targets[CARGO_TEST_COMPILE_TARGET].inputs = workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS;
|
|
692
|
+
targets[CARGO_TEST_ARCHIVE_TARGET] = createCargoTestArchiveTarget(
|
|
693
|
+
cargoWorkspaceRoot,
|
|
694
|
+
nextestToolConfigArg(workspaceRoot, cargoWorkspaceRoot, PLUGIN_NEXTEST_CONFIG),
|
|
695
|
+
);
|
|
696
|
+
// `archive.include` lives in the repository's nextest config, so that file
|
|
697
|
+
// decides what the archive CONTAINS, not merely how a run behaves.
|
|
698
|
+
targets[CARGO_TEST_ARCHIVE_TARGET].inputs = [
|
|
699
|
+
...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
|
|
700
|
+
`{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`,
|
|
701
|
+
];
|
|
631
702
|
const aggregateDependencies = cargoWorkspace.packages.flatMap((plan) =>
|
|
632
703
|
plan.pieces.map((piece) =>
|
|
633
704
|
cargoTargetDependency(projectName, {
|
|
@@ -640,20 +711,24 @@ async function createProjectTargets(
|
|
|
640
711
|
aggregateDependencies.length > 0
|
|
641
712
|
? { executor: 'nx:noop', cache: true, outputs: [], dependsOn: aggregateDependencies }
|
|
642
713
|
: createCargoTestTarget(cargoWorkspaceRoot);
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
714
|
+
// One clippy over the whole workspace, in one target dir. Clippy of a crate
|
|
715
|
+
// is a check build of its closure; a target dir per crate compiled every
|
|
716
|
+
// shared dependency once per crate (49 closures, 11 GiB on one repository)
|
|
717
|
+
// and no per-crate cache hit ever repaid that. The workspace inputs are
|
|
718
|
+
// exactly the union of every crate's, so the verdict caches on the same
|
|
719
|
+
// key set the compile does. Non-root packages depend on this target.
|
|
720
|
+
targets['cargo-lint'] = {
|
|
721
|
+
executor: 'nx:run-commands',
|
|
722
|
+
cache: true,
|
|
723
|
+
inputs: workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS,
|
|
724
|
+
outputs: [],
|
|
725
|
+
options: {
|
|
726
|
+
commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
|
|
727
|
+
cwd: cargoWorkspaceRoot,
|
|
728
|
+
parallel: false,
|
|
729
|
+
},
|
|
730
|
+
};
|
|
731
|
+
validationTargets.push('cargo-lint');
|
|
657
732
|
// The Linux arm of `cargo-lint`, as its own target. Rationale for the name,
|
|
658
733
|
// the command and the absent cross test leg lives in ./cross-check-policy.ts.
|
|
659
734
|
//
|
|
@@ -738,43 +813,19 @@ async function createProjectTargets(
|
|
|
738
813
|
dependsOn: packageTargetNames,
|
|
739
814
|
};
|
|
740
815
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
executor: 'nx:run-commands',
|
|
745
|
-
cache: true,
|
|
746
|
-
inputs: await cargoPackageTestInputs({
|
|
747
|
-
workspaceRoot,
|
|
748
|
-
absoluteProjectRoot: join(workspaceRoot, cargoWorkspace.projectRoot),
|
|
749
|
-
memberDir: plan.package.dir,
|
|
750
|
-
inputRoot:
|
|
751
|
-
projectRoot === cargoWorkspace.projectRoot
|
|
752
|
-
? '{projectRoot}'
|
|
753
|
-
: posix.join('{workspaceRoot}', cargoWorkspace.projectRoot),
|
|
754
|
-
}),
|
|
755
|
-
outputs: [],
|
|
756
|
-
options: {
|
|
757
|
-
commands: [
|
|
758
|
-
`cargo fmt -p ${name} --check`,
|
|
759
|
-
cargoFrozen(`clippy -p ${name} --all-targets --target-dir target/cargo-lint-${name} -- -D warnings`),
|
|
760
|
-
],
|
|
761
|
-
cwd: cargoWorkspace.projectRoot,
|
|
762
|
-
parallel: false,
|
|
763
|
-
},
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
const lintPlans = isCargoWorkspaceRoot ? cargoWorkspace.packages : cargoPackagePlans;
|
|
767
|
-
if (lintPlans.length > 0) {
|
|
816
|
+
if (!isCargoWorkspaceRoot && cargoPackagePlans.length > 0) {
|
|
817
|
+
// The workspace root runs clippy for every member; a package owning
|
|
818
|
+
// crates validates through that one verdict.
|
|
768
819
|
targets['cargo-lint'] = {
|
|
769
820
|
executor: 'nx:noop',
|
|
770
821
|
cache: true,
|
|
771
822
|
outputs: [],
|
|
772
|
-
dependsOn:
|
|
823
|
+
dependsOn: [
|
|
773
824
|
cargoTargetDependency(projectName, {
|
|
774
|
-
projectName:
|
|
775
|
-
targetName:
|
|
825
|
+
projectName: cargoWorkspace.rootProjectName,
|
|
826
|
+
targetName: 'cargo-lint',
|
|
776
827
|
}),
|
|
777
|
-
|
|
828
|
+
],
|
|
778
829
|
};
|
|
779
830
|
validationTargets.push('cargo-lint');
|
|
780
831
|
}
|
|
@@ -853,12 +904,7 @@ async function createProjectTargets(
|
|
|
853
904
|
if (name === CARGO_FETCH_TARGET) {
|
|
854
905
|
continue;
|
|
855
906
|
}
|
|
856
|
-
const
|
|
857
|
-
const commands: unknown = target.options?.commands;
|
|
858
|
-
const text = [
|
|
859
|
-
typeof command === 'string' ? command : '',
|
|
860
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
861
|
-
].join('\n');
|
|
907
|
+
const text = targetCommandText(target);
|
|
862
908
|
if (text.includes(CARGO_FROZEN_PREFIX)) {
|
|
863
909
|
target.dependsOn = [CARGO_FETCH_TARGET, ...(target.dependsOn ?? [])];
|
|
864
910
|
}
|
|
@@ -869,12 +915,7 @@ async function createProjectTargets(
|
|
|
869
915
|
targetName: CARGO_FETCH_TARGET,
|
|
870
916
|
});
|
|
871
917
|
for (const target of Object.values(targets)) {
|
|
872
|
-
const
|
|
873
|
-
const commands: unknown = target.options?.commands;
|
|
874
|
-
const text = [
|
|
875
|
-
typeof command === 'string' ? command : '',
|
|
876
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
877
|
-
].join('\n');
|
|
918
|
+
const text = targetCommandText(target);
|
|
878
919
|
if (text.includes(CARGO_FROZEN_PREFIX)) {
|
|
879
920
|
target.dependsOn = [rootFetch, ...(target.dependsOn ?? [])];
|
|
880
921
|
}
|
|
@@ -884,19 +925,14 @@ async function createProjectTargets(
|
|
|
884
925
|
// Cache verdicts and dedicated artifacts, never Cargo's shared mutable build
|
|
885
926
|
// directories. Resolve tool versions from the command's actual directory.
|
|
886
927
|
for (const [name, target] of Object.entries(targets)) {
|
|
887
|
-
const
|
|
888
|
-
const commands: unknown = target.options?.commands;
|
|
889
|
-
const text = [
|
|
890
|
-
typeof command === 'string' ? command : '',
|
|
891
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
892
|
-
].join('\n');
|
|
928
|
+
const text = targetCommandText(target);
|
|
893
929
|
if (!text.includes(CARGO_FROZEN_PREFIX)) continue;
|
|
894
930
|
target.outputs ??= [];
|
|
895
931
|
if (!target.cache) continue;
|
|
896
932
|
const cwd: unknown = target.options?.cwd;
|
|
897
933
|
const versions = name.startsWith('cargo-lint')
|
|
898
934
|
? ` && cargo clippy -V${name === CARGO_CROSS_LINT_TARGET ? '' : ' && cargo fmt --version'}`
|
|
899
|
-
: text.includes('nextest
|
|
935
|
+
: text.includes('nextest ')
|
|
900
936
|
? ' && cargo nextest --version'
|
|
901
937
|
: '';
|
|
902
938
|
target.inputs = [
|
|
@@ -907,8 +943,7 @@ async function createProjectTargets(
|
|
|
907
943
|
}
|
|
908
944
|
|
|
909
945
|
// Cargo flocks the workspace's default target/. Keep every writer out of the
|
|
910
|
-
// bounded test window by placing N-API debug builds
|
|
911
|
-
// chain as the root compile and per-crate runners.
|
|
946
|
+
// bounded test window by placing N-API debug builds behind the root compile.
|
|
912
947
|
const cargoTestCompileDependency: CargoTargetDependency | null = targets[CARGO_TEST_COMPILE_TARGET]
|
|
913
948
|
? CARGO_TEST_COMPILE_TARGET
|
|
914
949
|
: isCargoProject && cargoWorkspace
|
|
@@ -925,17 +960,18 @@ async function createProjectTargets(
|
|
|
925
960
|
}
|
|
926
961
|
}
|
|
927
962
|
if (napiDebug && cargoWorkspace) {
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
963
|
+
// A crate whose project also builds the debug cdylib runs its tests after
|
|
964
|
+
// that build: the tests dlopen what `napi-debug` writes into `target/debug`,
|
|
965
|
+
// and an archived test binary still loads it from this tree. The old serial
|
|
966
|
+
// chain gave the same guarantee by accident, to whichever crate happened to
|
|
967
|
+
// be first; this states it for exactly the crates that own the artifact.
|
|
968
|
+
for (const plan of cargoPackagePlans) {
|
|
969
|
+
for (const piece of plan.pieces) {
|
|
970
|
+
const target = targets[piece.targetName];
|
|
971
|
+
if (target && !hasCargoTargetDependency(target.dependsOn ?? [], 'napi-debug')) {
|
|
972
|
+
target.dependsOn = [...(target.dependsOn ?? []), 'napi-debug'];
|
|
973
|
+
}
|
|
935
974
|
}
|
|
936
|
-
firstTarget.dependsOn = (firstTarget.dependsOn ?? []).map((dependency) =>
|
|
937
|
-
hasCargoTargetDependency([dependency], previous) ? 'napi-debug' : dependency,
|
|
938
|
-
);
|
|
939
975
|
}
|
|
940
976
|
} else if (napiDebug) {
|
|
941
977
|
for (const [name, target] of Object.entries(targets)) {
|
|
@@ -1022,10 +1058,42 @@ async function createProjectTargets(
|
|
|
1022
1058
|
],
|
|
1023
1059
|
};
|
|
1024
1060
|
}
|
|
1025
|
-
|
|
1061
|
+
// Every cargo build directory this project's own commands write. `clean`
|
|
1062
|
+
// cannot learn them from `outputs`: a clippy or nextest target dir is a
|
|
1063
|
+
// multi-GB build tree that must never enter the Nx cache (`target/cargo-lint`
|
|
1064
|
+
// alone was 11 GiB when each of 49 crates had its own), so the targets
|
|
1065
|
+
// deliberately declare `outputs: []`. Reading `--target-dir` back off the
|
|
1066
|
+
// commands means the list cannot drift from what actually gets written, and a
|
|
1067
|
+
// directory is named relative to the command's own cwd, not the project root.
|
|
1068
|
+
const cargoBuildDirs = [
|
|
1069
|
+
...new Set(
|
|
1070
|
+
Object.entries(targets).flatMap(([name, target]) => {
|
|
1071
|
+
const cwd: unknown = target.options?.cwd;
|
|
1072
|
+
const base = typeof cwd === 'string' ? cwd : projectRoot;
|
|
1073
|
+
const dirs = [...targetCommandText(target).matchAll(/--target-dir\s+(\S+)/g)].flatMap((match) =>
|
|
1074
|
+
match[1] === undefined ? [] : [match[1]],
|
|
1075
|
+
);
|
|
1076
|
+
if (name === CARGO_TEST_ARCHIVE_TARGET) {
|
|
1077
|
+
dirs.push(posix.dirname(CARGO_TEST_ARCHIVE_FILE));
|
|
1078
|
+
}
|
|
1079
|
+
return dirs.map((dir) => `{workspaceRoot}/${posix.normalize(posix.join(base, dir))}`);
|
|
1080
|
+
}),
|
|
1081
|
+
),
|
|
1082
|
+
].sort();
|
|
1083
|
+
if (hasAnyBuildOutputTarget || cargoBuildDirs.length > 0) {
|
|
1084
|
+
const declaredBuild = declaredTargets.build;
|
|
1085
|
+
const declaredBuildOutputs =
|
|
1086
|
+
isRecord(declaredBuild) && Array.isArray(declaredBuild.outputs)
|
|
1087
|
+
? declaredBuild.outputs.filter((output): output is string => typeof output === 'string')
|
|
1088
|
+
: null;
|
|
1026
1089
|
targets.clean = {
|
|
1027
1090
|
executor: '@smoothbricks/nx-plugin:clean-outputs',
|
|
1028
1091
|
cache: false,
|
|
1092
|
+
// Naming any output REPLACES the executor's default, so the build outputs
|
|
1093
|
+
// it would have used are restated here rather than lost.
|
|
1094
|
+
...(cargoBuildDirs.length > 0
|
|
1095
|
+
? { options: { outputs: [...(declaredBuildOutputs ?? ['{projectRoot}/dist']), ...cargoBuildDirs] } }
|
|
1096
|
+
: {}),
|
|
1029
1097
|
};
|
|
1030
1098
|
}
|
|
1031
1099
|
|
|
@@ -1501,7 +1569,6 @@ interface CargoTargetRef {
|
|
|
1501
1569
|
|
|
1502
1570
|
interface CargoTestPiece {
|
|
1503
1571
|
extra: string;
|
|
1504
|
-
previous: CargoTargetRef;
|
|
1505
1572
|
selector: string;
|
|
1506
1573
|
targetName: string;
|
|
1507
1574
|
}
|
|
@@ -1515,6 +1582,8 @@ interface CargoWorkspace {
|
|
|
1515
1582
|
packages: CargoPackagePlan[];
|
|
1516
1583
|
rootProjectName: string;
|
|
1517
1584
|
projectRoot: string;
|
|
1585
|
+
/** One derivation memo for the whole graph computation (see cargoPackageTestInputs). */
|
|
1586
|
+
inputsCache: CargoInputsCache;
|
|
1518
1587
|
}
|
|
1519
1588
|
|
|
1520
1589
|
type CargoTargetDependency = NonNullable<TargetConfiguration['dependsOn']>[number];
|
|
@@ -1559,10 +1628,6 @@ async function resolveCargoWorkspaces(
|
|
|
1559
1628
|
projects,
|
|
1560
1629
|
).map((pkg) => ({ ...pkg, dir: posix.relative(rootProject.root, pkg.dir) || '.' }));
|
|
1561
1630
|
const packages: CargoPackagePlan[] = [];
|
|
1562
|
-
let previous: CargoTargetRef = {
|
|
1563
|
-
projectName: rootProject.name,
|
|
1564
|
-
targetName: CARGO_TEST_COMPILE_TARGET,
|
|
1565
|
-
};
|
|
1566
1631
|
const exceptional = exceptionalTestFilter(PLUGIN_NEXTEST_CONFIG);
|
|
1567
1632
|
for (const pkg of attributed) {
|
|
1568
1633
|
const pieces: CargoTestPiece[] = [];
|
|
@@ -1573,25 +1638,26 @@ async function resolveCargoWorkspaces(
|
|
|
1573
1638
|
const targetName = cargoTestPackageTargetName(pkg.name, sharded ? `shard${index}` : undefined);
|
|
1574
1639
|
pieces.push({
|
|
1575
1640
|
extra: sharded ? ` --partition hash:${index}/${pkg.testShards}` : '',
|
|
1576
|
-
previous,
|
|
1577
1641
|
selector: shardable,
|
|
1578
1642
|
targetName,
|
|
1579
1643
|
});
|
|
1580
|
-
previous = { projectName: pkg.projectName, targetName };
|
|
1581
1644
|
}
|
|
1582
1645
|
if (pin !== null) {
|
|
1583
1646
|
const targetName = cargoTestPackageTargetName(pkg.name, CARGO_TEST_EXCEPTIONS_SUFFIX);
|
|
1584
1647
|
pieces.push({
|
|
1585
1648
|
extra: '',
|
|
1586
|
-
previous,
|
|
1587
1649
|
selector: `package(${pkg.name}) and (${pin})`,
|
|
1588
1650
|
targetName,
|
|
1589
1651
|
});
|
|
1590
|
-
previous = { projectName: pkg.projectName, targetName };
|
|
1591
1652
|
}
|
|
1592
1653
|
packages.push({ package: pkg, pieces });
|
|
1593
1654
|
}
|
|
1594
|
-
workspaces.push({
|
|
1655
|
+
workspaces.push({
|
|
1656
|
+
packages,
|
|
1657
|
+
rootProjectName: rootProject.name,
|
|
1658
|
+
projectRoot: rootProject.root,
|
|
1659
|
+
inputsCache: createCargoInputsCache(),
|
|
1660
|
+
});
|
|
1595
1661
|
}
|
|
1596
1662
|
return workspaces;
|
|
1597
1663
|
}
|
|
@@ -1600,14 +1666,27 @@ async function resolveCargoWorkspaces(
|
|
|
1600
1666
|
* One bounded target per crate; a crate that declares `smoothbricks.test.shards`
|
|
1601
1667
|
* gets one per shard plus one for the tests nextest.toml singles out.
|
|
1602
1668
|
*
|
|
1603
|
-
*
|
|
1604
|
-
*
|
|
1605
|
-
*
|
|
1606
|
-
*
|
|
1607
|
-
*
|
|
1608
|
-
*
|
|
1609
|
-
*
|
|
1610
|
-
*
|
|
1669
|
+
* Every piece EXECUTES, it never builds: `--archive-file` runs the binaries
|
|
1670
|
+
* `cargo-test-archive` compiled once for the whole workspace, extracted into
|
|
1671
|
+
* the runner's own temporary directory. That is what removed the two costs the
|
|
1672
|
+
* old shape could not avoid. `nextest run --workspace -E 'package(X)'` re-entered
|
|
1673
|
+
* cargo once per crate, and the `-p X` form re-resolved that crate's features so
|
|
1674
|
+
* cargo rebuilt the divergent half inside the bounded window — measured at 57.9s
|
|
1675
|
+
* of a 120s budget on a hosted 3-core macOS runner, killing the run with 264
|
|
1676
|
+
* tests still to go. Neither form is reachable from an archive: nextest rejects
|
|
1677
|
+
* `--workspace` and `-p` beside `--archive-file`, so the filterset is the only
|
|
1678
|
+
* selector left, and it selects the same tests it always did.
|
|
1679
|
+
*
|
|
1680
|
+
* `--workspace-remap .` is not cosmetic. An archive records the ABSOLUTE paths
|
|
1681
|
+
* of the tree that produced it; without the remap, a restored archive hands
|
|
1682
|
+
* every test the producing tree's `CARGO_MANIFEST_DIR` — measured on a moved
|
|
1683
|
+
* tree, tests then read another checkout's fixtures, or a path that no longer
|
|
1684
|
+
* exists. With it, the runner's own cargo workspace root wins, so the archive
|
|
1685
|
+
* is relocatable and one cache entry serves every checkout of the same commit.
|
|
1686
|
+
* nextest also re-points `CARGO_BIN_EXE_<name>`/`NEXTEST_BIN_EXE_<name>` at the
|
|
1687
|
+
* extracted binaries at RUNTIME (measured), but `env!` reads them at COMPILE
|
|
1688
|
+
* time: a test that spawns `env!("CARGO_BIN_EXE_x")` holds the producing tree's
|
|
1689
|
+
* path and must read the runtime variable instead to survive relocation.
|
|
1611
1690
|
*
|
|
1612
1691
|
* nextest.toml singles some tests out with an override, and each such class
|
|
1613
1692
|
* breaks a shard in its own way — a `test-group` is scoped to one nextest RUN
|
|
@@ -1628,18 +1707,9 @@ async function resolveCargoWorkspaces(
|
|
|
1628
1707
|
* Detecting that regression requires a separate coverage policy rather than
|
|
1629
1708
|
* making valid empty crates and shards fail execution.
|
|
1630
1709
|
*
|
|
1631
|
-
* Pieces
|
|
1632
|
-
*
|
|
1633
|
-
*
|
|
1634
|
-
*/
|
|
1635
|
-
|
|
1636
|
-
/**
|
|
1637
|
-
* Root mode keeps `--workspace` and adds `-p` only to make the owning crate
|
|
1638
|
-
* explicit in the command Nx attributes to its project. Cargo treats
|
|
1639
|
-
* `--workspace -p X` as the full workspace selection, so `-p` is inert for
|
|
1640
|
-
* feature resolution; the nextest filterset is what narrows the tests that run.
|
|
1641
|
-
* Never drop `--workspace`: `-p X` alone re-resolves features for one package
|
|
1642
|
-
* and defeats the compile target's shared artifacts.
|
|
1710
|
+
* Pieces fan out rather than chain. The chain existed because every runner was
|
|
1711
|
+
* a cargo writer on one flocked `target/`; an archive run writes nothing there,
|
|
1712
|
+
* so the only serialization left is the one the machine's own scheduler does.
|
|
1643
1713
|
*/
|
|
1644
1714
|
async function addCargoTestTargets(
|
|
1645
1715
|
targets: Record<string, TargetConfiguration>,
|
|
@@ -1649,7 +1719,7 @@ async function addCargoTestTargets(
|
|
|
1649
1719
|
workspace: CargoWorkspace,
|
|
1650
1720
|
): Promise<string[]> {
|
|
1651
1721
|
const targetNames: string[] = [];
|
|
1652
|
-
const
|
|
1722
|
+
const toolConfig = nextestToolConfigArg(workspaceRoot, workspace.projectRoot, PLUGIN_NEXTEST_CONFIG);
|
|
1653
1723
|
for (const plan of workspace.packages) {
|
|
1654
1724
|
if (plan.package.projectRoot !== projectRoot) {
|
|
1655
1725
|
continue;
|
|
@@ -1659,6 +1729,10 @@ async function addCargoTestTargets(
|
|
|
1659
1729
|
// A workspace nextest build unifies features across every selected member.
|
|
1660
1730
|
// A sibling manifest can therefore change this crate's tests without being
|
|
1661
1731
|
// a path dependency. Track those manifests, not unrelated sibling sources.
|
|
1732
|
+
//
|
|
1733
|
+
// The repository's own nextest config layers OVER the plugin's tool config,
|
|
1734
|
+
// so it decides timeouts, groups and archive contents: a cached verdict that
|
|
1735
|
+
// ignored it would survive the change that invalidates it.
|
|
1662
1736
|
const inputs: NonNullable<TargetConfiguration['inputs']> = [
|
|
1663
1737
|
...new Set([
|
|
1664
1738
|
...(await cargoPackageTestInputs({
|
|
@@ -1666,35 +1740,39 @@ async function addCargoTestTargets(
|
|
|
1666
1740
|
absoluteProjectRoot: join(workspaceRoot, workspace.projectRoot),
|
|
1667
1741
|
memberDir: plan.package.dir,
|
|
1668
1742
|
inputRoot,
|
|
1743
|
+
cache: workspace.inputsCache,
|
|
1669
1744
|
})),
|
|
1670
1745
|
...workspace.packages.map((member) => posix.join(inputRoot, member.package.dir, 'Cargo.toml')),
|
|
1746
|
+
posix.join(inputRoot, NEXTEST_REPO_CONFIG_PATH),
|
|
1671
1747
|
]),
|
|
1672
1748
|
{
|
|
1673
1749
|
runtime: `bun -e 'console.log(new Bun.CryptoHasher("sha256").update(require("node:fs").readFileSync(process.argv[1])).digest("hex"))' '${PLUGIN_NEXTEST_CONFIG.replaceAll("'", "'\"'\"'")}'`,
|
|
1674
1750
|
},
|
|
1675
1751
|
];
|
|
1752
|
+
const archive = cargoTargetDependency(currentProjectName, {
|
|
1753
|
+
projectName: workspace.rootProjectName,
|
|
1754
|
+
targetName: CARGO_TEST_ARCHIVE_TARGET,
|
|
1755
|
+
});
|
|
1676
1756
|
for (const piece of plan.pieces) {
|
|
1677
1757
|
targetNames.push(piece.targetName);
|
|
1678
1758
|
targets[piece.targetName] = {
|
|
1679
1759
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
1680
1760
|
cache: true,
|
|
1681
1761
|
inputs,
|
|
1682
|
-
dependsOn: [
|
|
1762
|
+
dependsOn: [archive],
|
|
1683
1763
|
options: {
|
|
1684
1764
|
command: cargoFrozen(
|
|
1685
|
-
`nextest run --
|
|
1765
|
+
`nextest run --archive-file ${CARGO_TEST_ARCHIVE_FILE} --workspace-remap . -E '${piece.selector}'${piece.extra} --no-tests=pass --user-config-file none ${toolConfig}`,
|
|
1686
1766
|
),
|
|
1687
1767
|
cwd: workspace.projectRoot,
|
|
1688
1768
|
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
1689
1769
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
1690
1770
|
},
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
},
|
|
1697
|
-
},
|
|
1771
|
+
// The archive already holds the profile it was built with, and nextest
|
|
1772
|
+
// rejects `--release` beside `--archive-file`. Nx propagates the
|
|
1773
|
+
// configuration to this target's dependencies, so `:production` builds
|
|
1774
|
+
// the release archive and this command runs exactly what it finds.
|
|
1775
|
+
configurations: { production: {} },
|
|
1698
1776
|
};
|
|
1699
1777
|
}
|
|
1700
1778
|
}
|