@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/cargo-workspace.ts
CHANGED
|
@@ -222,21 +222,49 @@ export interface CargoPackageTestInputsOptions {
|
|
|
222
222
|
absoluteProjectRoot: string;
|
|
223
223
|
memberDir: string;
|
|
224
224
|
inputRoot?: string;
|
|
225
|
+
/** Shared across every call of one graph computation; see {@link createCargoInputsCache}. */
|
|
226
|
+
cache?: CargoInputsCache;
|
|
225
227
|
}
|
|
226
228
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
229
|
+
/**
|
|
230
|
+
* Memo for one project-graph computation. Every crate's compile, lint and
|
|
231
|
+
* test targets derive the same closure, and every crate re-reads the same
|
|
232
|
+
* manifests and re-walks the same trees for nested `Cargo.toml` files; with
|
|
233
|
+
* three targets over ~45 crates that was ~135 derivations and the dominant
|
|
234
|
+
* cost of loading the graph. The cache lives exactly as long as one
|
|
235
|
+
* `createNodes` call — Nx recomputes the graph when a manifest changes, so
|
|
236
|
+
* nothing here can go stale across runs.
|
|
237
|
+
*/
|
|
238
|
+
export interface CargoInputsCache {
|
|
239
|
+
readonly manifests: Map<string, Promise<TomlTable>>;
|
|
240
|
+
readonly nestedCrateDirs: Map<string, string[]>;
|
|
241
|
+
readonly results: Map<string, Promise<string[]>>;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function createCargoInputsCache(): CargoInputsCache {
|
|
245
|
+
return { manifests: new Map(), nestedCrateDirs: new Map(), results: new Map() };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function cargoPackageTestInputs(options: CargoPackageTestInputsOptions): Promise<string[]> {
|
|
249
|
+
const cache = options.cache ?? createCargoInputsCache();
|
|
250
|
+
const key = `${options.absoluteProjectRoot}\0${options.memberDir}\0${options.inputRoot ?? '{projectRoot}'}`;
|
|
251
|
+
const cached = cache.results.get(key);
|
|
252
|
+
if (cached !== undefined) return cached;
|
|
253
|
+
const derived = deriveCargoPackageTestInputs(options, cache);
|
|
254
|
+
cache.results.set(key, derived);
|
|
255
|
+
return derived;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function deriveCargoPackageTestInputs(
|
|
259
|
+
{ workspaceRoot, absoluteProjectRoot, memberDir, inputRoot = '{projectRoot}' }: CargoPackageTestInputsOptions,
|
|
260
|
+
cache: CargoInputsCache,
|
|
261
|
+
): Promise<string[]> {
|
|
262
|
+
const loadManifest = (path: string): Promise<TomlTable> => {
|
|
235
263
|
const normalized = resolve(path);
|
|
236
|
-
const cached = manifests.get(normalized);
|
|
264
|
+
const cached = cache.manifests.get(normalized);
|
|
237
265
|
if (cached !== undefined) return cached;
|
|
238
|
-
const parsed =
|
|
239
|
-
manifests.set(normalized, parsed);
|
|
266
|
+
const parsed = readFile(normalized, 'utf-8').then(parseToml);
|
|
267
|
+
cache.manifests.set(normalized, parsed);
|
|
240
268
|
return parsed;
|
|
241
269
|
};
|
|
242
270
|
const rootManifest = await loadManifest(join(absoluteProjectRoot, 'Cargo.toml'));
|
|
@@ -352,21 +380,9 @@ export async function cargoPackageTestInputs({
|
|
|
352
380
|
// Cargo packages can compile include_bytes!, headers, schemas and build.rs,
|
|
353
381
|
// not only Rust sources. Nested packages are separate source owners.
|
|
354
382
|
inputs.add(`${inputPath(absoluteDir)}/**/*`);
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (current === undefined || !existsSync(current)) continue;
|
|
359
|
-
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
360
|
-
if (!entry.isDirectory()) continue;
|
|
361
|
-
const child = join(current, entry.name);
|
|
362
|
-
if (['target', '.git', 'node_modules', '.nx'].includes(entry.name)) {
|
|
363
|
-
} else if (existsSync(join(child, 'Cargo.toml'))) {
|
|
364
|
-
const childDir = relative(absoluteProjectRoot, child).split(sep).join('/');
|
|
365
|
-
if (!dirs.has(childDir)) exclusions.add(`!${inputPath(child)}/**`);
|
|
366
|
-
} else {
|
|
367
|
-
scan.push(child);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
383
|
+
for (const child of nestedCrateDirs(absoluteDir, cache)) {
|
|
384
|
+
const childDir = relative(absoluteProjectRoot, child).split(sep).join('/');
|
|
385
|
+
if (!dirs.has(childDir)) exclusions.add(`!${inputPath(child)}/**`);
|
|
370
386
|
}
|
|
371
387
|
}
|
|
372
388
|
for (const source of [...declaredSources].sort()) {
|
|
@@ -432,6 +448,30 @@ export async function cargoPackageTestInputs({
|
|
|
432
448
|
return [...inputs];
|
|
433
449
|
}
|
|
434
450
|
|
|
451
|
+
/** Every directory beneath `root` that holds its own `Cargo.toml`, the walk stopping at each. */
|
|
452
|
+
function nestedCrateDirs(root: string, cache: CargoInputsCache): string[] {
|
|
453
|
+
const cached = cache.nestedCrateDirs.get(root);
|
|
454
|
+
if (cached !== undefined) return cached;
|
|
455
|
+
const found: string[] = [];
|
|
456
|
+
const scan = [root];
|
|
457
|
+
while (scan.length > 0) {
|
|
458
|
+
const current = scan.pop();
|
|
459
|
+
if (current === undefined || !existsSync(current)) continue;
|
|
460
|
+
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
461
|
+
if (!entry.isDirectory()) continue;
|
|
462
|
+
const child = join(current, entry.name);
|
|
463
|
+
if (['target', '.git', 'node_modules', '.nx'].includes(entry.name)) {
|
|
464
|
+
} else if (existsSync(join(child, 'Cargo.toml'))) {
|
|
465
|
+
found.push(child);
|
|
466
|
+
} else {
|
|
467
|
+
scan.push(child);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
cache.nestedCrateDirs.set(root, found);
|
|
472
|
+
return found;
|
|
473
|
+
}
|
|
474
|
+
|
|
435
475
|
function enqueuePathDependencies(
|
|
436
476
|
scope: Record<string, unknown>,
|
|
437
477
|
memberDir: string,
|
|
@@ -572,6 +612,23 @@ export const CARGO_TEST_TARGET = 'cargo-test';
|
|
|
572
612
|
/** Prerequisite that compiles the workspace; not a per-crate runner. */
|
|
573
613
|
export const CARGO_TEST_COMPILE_TARGET = 'cargo-test-compile';
|
|
574
614
|
|
|
615
|
+
/**
|
|
616
|
+
* The one workspace-wide `cargo nextest archive` every per-crate runner
|
|
617
|
+
* executes from. Named here beside the other cargo target names so the policy
|
|
618
|
+
* that checks a workspace's test graph and the inference that builds it read
|
|
619
|
+
* the same string.
|
|
620
|
+
*/
|
|
621
|
+
export const CARGO_TEST_ARCHIVE_TARGET = 'cargo-test-archive';
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Where that archive lands, relative to the cargo workspace root — the cwd both
|
|
625
|
+
* the archive command and every runner already use. `cargo nextest archive`
|
|
626
|
+
* does NOT create this parent directory and fails the whole build when it is
|
|
627
|
+
* missing ("error writing to archive ... No such file or directory"), so the
|
|
628
|
+
* target mkdir's it first.
|
|
629
|
+
*/
|
|
630
|
+
export const CARGO_TEST_ARCHIVE_FILE = 'target/nextest/archive.tar.zst';
|
|
631
|
+
|
|
575
632
|
/**
|
|
576
633
|
* Tests that nextest.toml singles out are pinned to this suffix instead of
|
|
577
634
|
* being sharded. Only a sharded crate has one: an unsharded crate runs its
|
|
@@ -592,9 +649,17 @@ export function cargoTestPackageTargetName(packageName: string, piece?: string):
|
|
|
592
649
|
* Inverse of `cargoTestPackageTargetName`, used by the reachability policy to
|
|
593
650
|
* check that the per-crate targets cover every workspace member. Pieces of one
|
|
594
651
|
* crate collapse back to that crate, so a split crate counts as covered once.
|
|
652
|
+
*
|
|
653
|
+
* The two workspace-wide `cargo-test-*` targets are not crates: reading them as
|
|
654
|
+
* one would invent members named "compile" and "archive" and report every real
|
|
655
|
+
* crate's coverage against a set that can never match.
|
|
595
656
|
*/
|
|
596
657
|
export function packageNameFromCargoTestTarget(targetName: string): string | null {
|
|
597
|
-
if (
|
|
658
|
+
if (
|
|
659
|
+
!targetName.startsWith('cargo-test-') ||
|
|
660
|
+
targetName === CARGO_TEST_COMPILE_TARGET ||
|
|
661
|
+
targetName === CARGO_TEST_ARCHIVE_TARGET
|
|
662
|
+
) {
|
|
598
663
|
return null;
|
|
599
664
|
}
|
|
600
665
|
const name = targetName
|
|
@@ -639,7 +704,30 @@ export function exceptionalTestFilter(nextestConfigPath: string): string | null
|
|
|
639
704
|
return unique.length === 0 ? null : unique.map((filter) => `(${filter})`).join(' or ');
|
|
640
705
|
}
|
|
641
706
|
|
|
642
|
-
|
|
707
|
+
/**
|
|
708
|
+
* The plugin's own nextest settings, as a config layer BENEATH the repository's.
|
|
709
|
+
*
|
|
710
|
+
* `--config-file` replaces `<workspace>/.config/nextest.toml` outright, which
|
|
711
|
+
* made every plugin default unoverridable and — now that per-crate runs execute
|
|
712
|
+
* from an archive — left a repository no way to declare `archive.include` for a
|
|
713
|
+
* cdylib or fixture its tests need. `--tool-config-file` is nextest's mechanism
|
|
714
|
+
* for exactly this: "lower than --config-file in priority but above the default
|
|
715
|
+
* config shipped with nextest". Measured: with only this layer a 1s
|
|
716
|
+
* slow-timeout terminates a 3s test; adding `.config/nextest.toml` with 10s
|
|
717
|
+
* lets the same test pass.
|
|
718
|
+
*
|
|
719
|
+
* The path must be absolute, and an absolute path written into the command text
|
|
720
|
+
* would differ per checkout and split one Nx cache entry per machine. `$PWD`
|
|
721
|
+
* resolves at exec time — both the archive (`nx:run-commands`) and the runners
|
|
722
|
+
* (`bounded-exec`, which spawns with `shell: true`) go through a shell — so the
|
|
723
|
+
* command text stays identical everywhere. Quoted, because a workspace path may
|
|
724
|
+
* contain spaces.
|
|
725
|
+
*/
|
|
726
|
+
export function nextestToolConfigArg(workspaceRoot: string, projectRoot: string, configAbs: string): string {
|
|
643
727
|
const rel = relative(join(workspaceRoot, projectRoot), configAbs);
|
|
644
|
-
|
|
728
|
+
const path = rel.length === 0 ? configAbs : rel.split(sep).join('/');
|
|
729
|
+
return `--tool-config-file "smoo:$PWD/${path}"`;
|
|
645
730
|
}
|
|
731
|
+
|
|
732
|
+
/** The repository's own nextest config, which now layers over the plugin's. */
|
|
733
|
+
export const NEXTEST_REPO_CONFIG_PATH = '.config/nextest.toml';
|
package/src/index.test.ts
CHANGED
|
@@ -73,7 +73,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
73
73
|
};
|
|
74
74
|
const rustOnly = await runLint();
|
|
75
75
|
expect(rustOnly).toMatchObject({ exitCode: 0 });
|
|
76
|
-
expect(rustOnly.output).toContain('cargo-lint
|
|
76
|
+
expect(rustOnly.output).toContain('cargo-lint');
|
|
77
77
|
await workspace.write('packages/rust/src/check.js', 'debugger;\n');
|
|
78
78
|
const withJavaScript = await runLint();
|
|
79
79
|
expect(withJavaScript.exitCode).not.toBe(0);
|
|
@@ -386,7 +386,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
386
386
|
// needs the locked graph downloaded whether or not the chain runs first.
|
|
387
387
|
for (const name of [
|
|
388
388
|
'cargo-test-compile',
|
|
389
|
-
'cargo-
|
|
389
|
+
'cargo-test-archive',
|
|
390
|
+
'cargo-lint',
|
|
390
391
|
CARGO_CROSS_LINT_TARGET,
|
|
391
392
|
'mutation',
|
|
392
393
|
'bench',
|
|
@@ -403,15 +404,40 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
403
404
|
});
|
|
404
405
|
expect(targets['cargo-test']?.executor).toBe('nx:noop');
|
|
405
406
|
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-test-ferris-wasm']);
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
//
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
407
|
+
// One workspace compile, packed once. Every per-crate runner reads that
|
|
408
|
+
// archive, so the runners fan out instead of chaining: none of them
|
|
409
|
+
// builds, re-resolves features, or writes cargo's flocked `target/`.
|
|
410
|
+
expect(targets['cargo-test-archive']?.executor).toBe('nx:run-commands');
|
|
411
|
+
expect(targets['cargo-test-archive']?.cache).toBe(true);
|
|
412
|
+
expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/target/nextest/archive.tar.zst']);
|
|
413
|
+
expect(targets['cargo-test-archive']?.options).toMatchObject({ cwd: 'packages/ferris', parallel: false });
|
|
414
|
+
// nextest does not create the archive's parent directory and fails the
|
|
415
|
+
// whole build if it is missing (measured: "error writing to archive").
|
|
416
|
+
expect(targets['cargo-test-archive']?.options?.commands?.[0]).toBe('mkdir -p target/nextest');
|
|
417
|
+
// `--tool-config-file`, never `--config-file`: the plugin's settings must
|
|
418
|
+
// sit UNDER the repository's `.config/nextest.toml`, which is the only
|
|
419
|
+
// place an `archive.include` for a cdylib or fixture can be declared.
|
|
420
|
+
// `$PWD` because tool config paths must be absolute and an absolute path
|
|
421
|
+
// in the command text would split one cache entry per checkout.
|
|
422
|
+
expect(String(targets['cargo-test-archive']?.options?.commands?.[1])).toMatch(
|
|
423
|
+
/^cargo --frozen nextest archive --workspace --archive-file target\/nextest\/archive\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
424
|
+
);
|
|
425
|
+
expect(targets['cargo-test-archive']?.inputs).toContain('{projectRoot}/.config/nextest.toml');
|
|
426
|
+
expect(String(targets['cargo-test-archive']?.configurations?.production?.commands?.[1])).toContain(
|
|
427
|
+
'nextest archive --workspace --release --archive-file',
|
|
428
|
+
);
|
|
429
|
+
expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
430
|
+
expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
431
|
+
// The runner executes the archive's binaries and remaps the workspace
|
|
432
|
+
// root: without `--workspace-remap`, a restored archive hands tests the
|
|
433
|
+
// PRODUCING tree's absolute CARGO_MANIFEST_DIR (measured on a moved tree).
|
|
434
|
+
// `--workspace` is not merely redundant here, nextest rejects it with
|
|
435
|
+
// `--archive-file`.
|
|
412
436
|
expect(targets['cargo-test-ferris-core']?.options?.command).toMatch(
|
|
413
|
-
/^cargo --frozen nextest run --workspace -E 'package\(ferris-core\)' --no-tests=pass --user-config-file none --config-file
|
|
437
|
+
/^cargo --frozen nextest run --archive-file target\/nextest\/archive\.tar\.zst --workspace-remap \. -E 'package\(ferris-core\)' --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
414
438
|
);
|
|
439
|
+
expect(targets['cargo-test-ferris-core']?.inputs).toContain('{projectRoot}/.config/nextest.toml');
|
|
440
|
+
expect(targets['cargo-test-ferris-core']?.configurations?.production).toEqual({});
|
|
415
441
|
expect(targets['cargo-test-ferris-core']?.inputs).toEqual(
|
|
416
442
|
expect.arrayContaining([
|
|
417
443
|
'{projectRoot}/Cargo.toml',
|
|
@@ -420,16 +446,20 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
420
446
|
]),
|
|
421
447
|
);
|
|
422
448
|
expect(targets['cargo-test-ferris-core']?.inputs).not.toContain('{projectRoot}/crates/ferris-wasm/**/*');
|
|
423
|
-
|
|
424
|
-
|
|
449
|
+
// One clippy for the workspace in one target dir: a per-crate closure
|
|
450
|
+
// compiled every shared dependency once per crate.
|
|
451
|
+
expect(targets['cargo-lint']?.options).toMatchObject({
|
|
425
452
|
cwd: 'packages/ferris',
|
|
426
453
|
commands: [
|
|
427
|
-
'cargo fmt
|
|
428
|
-
'cargo --frozen clippy
|
|
454
|
+
'cargo fmt --all --check',
|
|
455
|
+
'cargo --frozen clippy --workspace --all-targets --target-dir target/cargo-lint -- -D warnings',
|
|
429
456
|
],
|
|
430
457
|
});
|
|
431
|
-
expect(targets['cargo-lint
|
|
432
|
-
expect(targets['cargo-lint
|
|
458
|
+
expect(targets['cargo-lint']?.cache).toBe(true);
|
|
459
|
+
expect(targets['cargo-lint']?.outputs).toEqual([]);
|
|
460
|
+
expect(targets['cargo-lint']?.inputs).toEqual(
|
|
461
|
+
expect.arrayContaining(['{projectRoot}/crates/ferris-core/**/*', '{projectRoot}/crates/ferris-wasm/**/*']),
|
|
462
|
+
);
|
|
433
463
|
expect(targets.lint?.dependsOn).toEqual(['cargo-lint']);
|
|
434
464
|
expect(targets[CARGO_CROSS_LINT_TARGET]?.options).toMatchObject({
|
|
435
465
|
command: CARGO_CROSS_LINT_COMMAND,
|
|
@@ -447,6 +477,32 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
447
477
|
}
|
|
448
478
|
});
|
|
449
479
|
|
|
480
|
+
it('cleans every cargo directory its own commands write, including the ones caching refuses', async () => {
|
|
481
|
+
const workspace = await createWorkspace();
|
|
482
|
+
try {
|
|
483
|
+
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
484
|
+
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = ["crates/ferris-core"]\n');
|
|
485
|
+
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
486
|
+
|
|
487
|
+
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
488
|
+
|
|
489
|
+
// A clippy target dir is not an Nx output — restoring an 11 GiB build
|
|
490
|
+
// tree from a cache is worse than rebuilding it — so `clean` cannot find
|
|
491
|
+
// these through `outputs`. They are read back off the commands that
|
|
492
|
+
// write them, which is why a new `--target-dir` cannot be forgotten here.
|
|
493
|
+
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
494
|
+
expect(targets.clean?.cache).toBe(false);
|
|
495
|
+
expect(targets.clean?.options?.outputs).toEqual([
|
|
496
|
+
'{projectRoot}/dist',
|
|
497
|
+
'{workspaceRoot}/packages/ferris/target/cargo-lint',
|
|
498
|
+
'{workspaceRoot}/packages/ferris/target/cargo-lint-cross',
|
|
499
|
+
'{workspaceRoot}/packages/ferris/target/nextest',
|
|
500
|
+
]);
|
|
501
|
+
} finally {
|
|
502
|
+
await workspace.cleanup();
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
|
|
450
506
|
it('keeps Rust-only lint source-aware after migrating defaults without replacing mixed or custom lint', async () => {
|
|
451
507
|
const workspace = await createWorkspace();
|
|
452
508
|
const root = 'packages/ferris';
|
|
@@ -567,6 +623,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
567
623
|
const rootProject = '@fixture/codebase';
|
|
568
624
|
const rootFetch = { projects: [rootProject], target: 'cargo-fetch' };
|
|
569
625
|
const rootCompile = { projects: [rootProject], target: 'cargo-test-compile' };
|
|
626
|
+
const rootArchive = { projects: [rootProject], target: 'cargo-test-archive' };
|
|
570
627
|
|
|
571
628
|
expect(
|
|
572
629
|
[...projects]
|
|
@@ -582,28 +639,22 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
582
639
|
command: 'cargo --frozen test --workspace --no-run',
|
|
583
640
|
cwd: '.',
|
|
584
641
|
});
|
|
585
|
-
expect(root['cargo-lint']?.
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
{ projects: ['wasm'], target: 'cargo-lint-runtime-wasm' },
|
|
642
|
+
expect(root['cargo-lint']?.options?.commands).toEqual([
|
|
643
|
+
'cargo fmt --all --check',
|
|
644
|
+
'cargo --frozen clippy --workspace --all-targets --target-dir target/cargo-lint -- -D warnings',
|
|
589
645
|
]);
|
|
646
|
+
expect(root['cargo-lint']?.dependsOn).toContain('cargo-fetch');
|
|
590
647
|
expect(root['cargo-test']?.dependsOn).toHaveLength(5);
|
|
591
648
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
]);
|
|
596
|
-
expect(runtime['cargo-test-runtime-core-shard2']?.dependsOn).toEqual([
|
|
597
|
-
|
|
598
|
-
'cargo-test-runtime-core-shard1',
|
|
599
|
-
]);
|
|
600
|
-
expect(runtime['cargo-test-runtime-core-exceptions']?.dependsOn).toEqual([
|
|
601
|
-
rootFetch,
|
|
602
|
-
'cargo-test-runtime-core-shard2',
|
|
603
|
-
]);
|
|
649
|
+
// Root mode: every piece of every project hangs off the one root archive,
|
|
650
|
+
// in any order. The crate is selected by filterset alone — `-p` would
|
|
651
|
+
// re-resolve features, and there is nothing left to build anyway.
|
|
652
|
+
expect(runtime['cargo-test-runtime-core-shard1']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
653
|
+
expect(runtime['cargo-test-runtime-core-shard2']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
654
|
+
expect(runtime['cargo-test-runtime-core-exceptions']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
604
655
|
expect(runtime['cargo-test-runtime-core-shard1']?.options).toMatchObject({ cwd: '.' });
|
|
605
656
|
expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toContain(
|
|
606
|
-
|
|
657
|
+
"nextest run --archive-file target/nextest/archive.tar.zst --workspace-remap . -E 'package(runtime-core)",
|
|
607
658
|
);
|
|
608
659
|
expect(native['cargo-test-native-napi']?.options?.command).toContain('--no-tests=pass');
|
|
609
660
|
expect(runtime['cargo-test']?.dependsOn).toEqual([
|
|
@@ -611,16 +662,13 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
611
662
|
'cargo-test-runtime-core-shard2',
|
|
612
663
|
'cargo-test-runtime-core-exceptions',
|
|
613
664
|
]);
|
|
614
|
-
|
|
665
|
+
// A package owning crates validates through the root's one clippy verdict.
|
|
666
|
+
expect(runtime['cargo-lint']?.dependsOn).toEqual([{ projects: [rootProject], target: 'cargo-lint' }]);
|
|
615
667
|
expect(runtime.lint?.dependsOn).toEqual(['cargo-lint']);
|
|
616
|
-
expect(runtime['cargo-lint-runtime-core']
|
|
617
|
-
expect(runtime['cargo-lint-runtime-core']?.options?.cwd).toBe('.');
|
|
668
|
+
expect(runtime['cargo-lint-runtime-core']).toBeUndefined();
|
|
618
669
|
expect(runtime.clean).toBeUndefined();
|
|
619
670
|
|
|
620
|
-
expect(wasm['cargo-test-runtime-wasm']?.dependsOn).toEqual([
|
|
621
|
-
rootFetch,
|
|
622
|
-
{ projects: ['runtime'], target: 'cargo-test-runtime-core-exceptions' },
|
|
623
|
-
]);
|
|
671
|
+
expect(wasm['cargo-test-runtime-wasm']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
624
672
|
expect(wasm['cargo-wasm']?.options).toMatchObject({ cwd: '.' });
|
|
625
673
|
expect(wasm['cargo-wasm']?.options?.commands).toContain(
|
|
626
674
|
'cargo --frozen build --release --target wasm32-unknown-unknown --target-dir target/cargo-wasm -p runtime-wasm',
|
|
@@ -630,7 +678,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
630
678
|
expect(wasm.build?.dependsOn).toContainEqual(rootCompile);
|
|
631
679
|
expect(wasm.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
632
680
|
|
|
633
|
-
|
|
681
|
+
// The crate whose project also builds the debug cdylib keeps that edge:
|
|
682
|
+
// its tests load the artifact `napi-debug` writes into `target/debug`.
|
|
683
|
+
expect(native['cargo-test-native-napi']?.dependsOn).toEqual([rootFetch, rootArchive, 'napi-debug']);
|
|
634
684
|
expect(native['napi-debug']?.dependsOn).toContainEqual(rootCompile);
|
|
635
685
|
expect(native['napi-debug']?.options).toMatchObject({
|
|
636
686
|
cwd: '.',
|
|
@@ -652,8 +702,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
652
702
|
it('keeps root packages, nested workspaces and multiple owned crates in their own lint graph', async () => {
|
|
653
703
|
const workspace = await createWorkspace();
|
|
654
704
|
const declared: Record<string, TargetConfiguration> = {
|
|
655
|
-
'cargo-lint
|
|
656
|
-
'cargo-lint': { dependsOn: ['cargo-lint-alpha-core'] },
|
|
705
|
+
'cargo-lint': { dependsOn: ['...', 'prepare-check'] },
|
|
657
706
|
lint: { dependsOn: ['cargo-lint', 'custom-check'] },
|
|
658
707
|
};
|
|
659
708
|
try {
|
|
@@ -686,45 +735,49 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
686
735
|
const group = projects.get('packages/group')?.targets ?? {};
|
|
687
736
|
const inner = projects.get('nested')?.targets ?? {};
|
|
688
737
|
const leaf = projects.get('nested/modules/leaf')?.targets ?? {};
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
'
|
|
693
|
-
|
|
694
|
-
|
|
738
|
+
// Each cargo workspace root runs one clippy over all its members; the
|
|
739
|
+
// packages owning crates validate through that verdict.
|
|
740
|
+
expect(outer['cargo-lint']?.options).toMatchObject({
|
|
741
|
+
cwd: '.',
|
|
742
|
+
commands: [
|
|
743
|
+
'cargo fmt --all --check',
|
|
744
|
+
'cargo --frozen clippy --workspace --all-targets --target-dir target/cargo-lint -- -D warnings',
|
|
745
|
+
],
|
|
746
|
+
});
|
|
747
|
+
expect(outer['cargo-lint']?.inputs).toEqual(
|
|
748
|
+
expect.arrayContaining([
|
|
749
|
+
'{projectRoot}/packages/group/crates/alpha/**/*',
|
|
750
|
+
'{projectRoot}/packages/group/crates/beta/**/*',
|
|
751
|
+
]),
|
|
752
|
+
);
|
|
753
|
+
expect(group['cargo-lint']?.dependsOn).toEqual([{ projects: ['outer-root'], target: 'cargo-lint' }]);
|
|
695
754
|
expect(group.build?.dependsOn).toEqual([
|
|
696
755
|
'^build',
|
|
697
756
|
{ projects: ['outer-root'], target: 'cargo-test-compile' },
|
|
698
757
|
'tsc-js',
|
|
699
758
|
]);
|
|
700
|
-
expect(outer['cargo-lint-host-core']
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
]);
|
|
704
|
-
expect(
|
|
705
|
-
|
|
706
|
-
{ projects: ['inner-leaf-project'], target: 'cargo-lint-inner-leaf' },
|
|
707
|
-
]);
|
|
708
|
-
expect(leaf['cargo-lint-inner-leaf']?.options).toMatchObject({
|
|
709
|
-
cwd: 'nested',
|
|
710
|
-
commands: [
|
|
711
|
-
'cargo fmt -p inner-leaf --check',
|
|
712
|
-
'cargo --frozen clippy -p inner-leaf --all-targets --target-dir target/cargo-lint-inner-leaf -- -D warnings',
|
|
713
|
-
],
|
|
714
|
-
});
|
|
715
|
-
expect(leaf['cargo-lint-inner-leaf']?.dependsOn).toEqual([{ projects: ['inner-root'], target: 'cargo-fetch' }]);
|
|
716
|
-
expect(leaf['cargo-lint-inner-leaf']?.inputs).toContain('{workspaceRoot}/nested/modules/leaf/**/*');
|
|
717
|
-
expect(leaf['cargo-lint-inner-leaf']?.inputs).not.toContain('{workspaceRoot}/packages/group/crates/alpha/**/*');
|
|
759
|
+
expect(outer['cargo-lint-host-core']).toBeUndefined();
|
|
760
|
+
expect(inner['cargo-lint']?.options).toMatchObject({ cwd: 'nested' });
|
|
761
|
+
expect(inner['cargo-lint']?.inputs).toContain('{projectRoot}/**/*');
|
|
762
|
+
expect(inner['cargo-lint']?.inputs).not.toContain('{workspaceRoot}/packages/group/crates/alpha/**/*');
|
|
763
|
+
expect(leaf['cargo-lint']?.dependsOn).toEqual([{ projects: ['inner-root'], target: 'cargo-lint' }]);
|
|
764
|
+
expect(leaf['cargo-lint-inner-leaf']).toBeUndefined();
|
|
718
765
|
expect(leaf['cargo-test-inner-leaf']?.options?.cwd).toBe('nested');
|
|
719
766
|
expect(inner['cargo-test-compile']?.options?.cwd).toBe('nested');
|
|
720
|
-
expect(leaf['cargo-test-inner-leaf']?.
|
|
721
|
-
|
|
722
|
-
|
|
767
|
+
expect(leaf['cargo-test-inner-leaf']?.dependsOn).toEqual([
|
|
768
|
+
{ projects: ['inner-root'], target: 'cargo-fetch' },
|
|
769
|
+
{ projects: ['inner-root'], target: 'cargo-test-archive' },
|
|
770
|
+
]);
|
|
771
|
+
// The profile lives in the archive, so the runner's production
|
|
772
|
+
// configuration has nothing left to say.
|
|
773
|
+
expect(leaf['cargo-test-inner-leaf']?.configurations?.production).toEqual({});
|
|
774
|
+
expect(inner['cargo-test-archive']?.options?.cwd).toBe('nested');
|
|
775
|
+
expect(resolveDeclaredOverInferred(group, declared, 'cargo-lint')).toMatchObject({
|
|
776
|
+
executor: 'nx:noop',
|
|
723
777
|
cache: true,
|
|
724
778
|
outputs: [],
|
|
725
|
-
dependsOn: [{ projects: ['outer-root'], target: 'cargo-
|
|
779
|
+
dependsOn: [{ projects: ['outer-root'], target: 'cargo-lint' }, 'prepare-check'],
|
|
726
780
|
});
|
|
727
|
-
expect(resolveDeclaredOverInferred(group, declared, 'cargo-lint')?.dependsOn).toEqual(['cargo-lint-alpha-core']);
|
|
728
781
|
expect(resolveDeclaredOverInferred(group, declared, 'lint')?.dependsOn).toEqual(['cargo-lint', 'custom-check']);
|
|
729
782
|
} finally {
|
|
730
783
|
await workspace.cleanup();
|
|
@@ -739,7 +792,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
739
792
|
await workspace.write('crate/Cargo.toml', '[package]\nname = "cache-crate"\n');
|
|
740
793
|
await workspace.write('cargo-home/config.toml', '[build]\njobs = 1\n');
|
|
741
794
|
const targets = await inferProjectTargets(workspace, 'package.json');
|
|
742
|
-
const runtimeCommands = (targets['cargo-lint
|
|
795
|
+
const runtimeCommands = (targets['cargo-lint']?.inputs ?? []).flatMap((input) =>
|
|
743
796
|
typeof input !== 'string' && 'runtime' in input ? [input.runtime] : [],
|
|
744
797
|
);
|
|
745
798
|
const capture = async (extraEnv: Record<string, string>) =>
|
|
@@ -784,20 +837,20 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
784
837
|
|
|
785
838
|
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
786
839
|
|
|
787
|
-
// Scoped by filterset over
|
|
788
|
-
//
|
|
840
|
+
// Scoped by filterset over one archived workspace build: exactly one
|
|
841
|
+
// crate runs, and no `-p` re-resolves its features.
|
|
789
842
|
expect(cargoPackageSelection(String(targets['cargo-test-ferris-core']?.options?.command ?? ''))).toEqual({
|
|
790
|
-
|
|
843
|
+
archiveRun: true,
|
|
791
844
|
packageFlags: [],
|
|
792
845
|
filtered: ['ferris-core'],
|
|
793
846
|
});
|
|
794
847
|
expect(cargoPackageSelection(String(targets['cargo-test-ferris-wasm']?.options?.command ?? ''))).toEqual({
|
|
795
|
-
|
|
848
|
+
archiveRun: true,
|
|
796
849
|
packageFlags: [],
|
|
797
850
|
filtered: ['ferris-wasm'],
|
|
798
851
|
});
|
|
799
|
-
expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-
|
|
800
|
-
expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-
|
|
852
|
+
expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
853
|
+
expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
801
854
|
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-test-ferris-wasm']);
|
|
802
855
|
} finally {
|
|
803
856
|
await workspace.cleanup();
|
|
@@ -1083,12 +1136,17 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1083
1136
|
},
|
|
1084
1137
|
});
|
|
1085
1138
|
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-cowshed-napi']);
|
|
1086
|
-
// cargo-fetch survives the napi-debug
|
|
1087
|
-
//
|
|
1088
|
-
//
|
|
1089
|
-
|
|
1139
|
+
// cargo-fetch survives the napi-debug edge: the per-crate runner is itself
|
|
1140
|
+
// a frozen cargo command, so its precondition is its own edge. It reads
|
|
1141
|
+
// the workspace archive and still waits for the debug cdylib its own
|
|
1142
|
+
// project builds, because its tests load that artifact from `target/`.
|
|
1143
|
+
expect(targets['cargo-test-cowshed-napi']?.dependsOn).toEqual([
|
|
1144
|
+
'cargo-fetch',
|
|
1145
|
+
'cargo-test-archive',
|
|
1146
|
+
'napi-debug',
|
|
1147
|
+
]);
|
|
1090
1148
|
expect(targets['cargo-test-cowshed-napi']?.options?.command).toMatch(
|
|
1091
|
-
/^cargo --frozen nextest run --workspace -E 'package\(cowshed-napi\)' --no-tests=pass --user-config-file none --config-file
|
|
1149
|
+
/^cargo --frozen nextest run --archive-file target\/nextest\/archive\.tar\.zst --workspace-remap \. -E 'package\(cowshed-napi\)' --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
1092
1150
|
);
|
|
1093
1151
|
expect(targets['napi-test']).toMatchObject({
|
|
1094
1152
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
@@ -1167,7 +1225,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1167
1225
|
// An unsharded crate keeps the bare name and takes no --partition, so
|
|
1168
1226
|
// declaring nothing is exactly the old single-target behaviour.
|
|
1169
1227
|
expect(targets['cargo-test-small']?.options?.command).toMatch(
|
|
1170
|
-
/nextest run --workspace -E 'package\(small\)' --no-tests=pass --user-config-file none/,
|
|
1228
|
+
/nextest run --archive-file target\/nextest\/archive\.tar\.zst --workspace-remap \. -E 'package\(small\)' --no-tests=pass --user-config-file none/,
|
|
1171
1229
|
);
|
|
1172
1230
|
// The shards partition the crate MINUS the classes nextest.toml singles
|
|
1173
1231
|
// out, i of N. Those are lifted out because a test-group only holds
|
|
@@ -1180,22 +1238,22 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1180
1238
|
}
|
|
1181
1239
|
for (const index of [1, 2, 3]) {
|
|
1182
1240
|
expect(targets[`cargo-test-big-shard${index}`]?.options?.command).toContain(
|
|
1183
|
-
|
|
1241
|
+
`-E 'package(big) and not (${exceptional})' --partition hash:${index}/3 --no-tests=pass`,
|
|
1184
1242
|
);
|
|
1185
1243
|
expect(targets[`cargo-test-big-shard${index}`]?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
|
|
1186
1244
|
}
|
|
1187
1245
|
// Exact complement of the shards' filterset, so the union is the crate.
|
|
1188
1246
|
expect(targets['cargo-test-big-exceptions']?.options?.command).toContain(
|
|
1189
|
-
|
|
1247
|
+
`-E 'package(big) and (${exceptional})' --no-tests=pass`,
|
|
1190
1248
|
);
|
|
1191
1249
|
expect(targets['cargo-test-big-exceptions']?.options?.command).not.toContain('--partition');
|
|
1192
1250
|
expect(targets['cargo-test-big-exceptions']?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
|
|
1193
1251
|
// An unsharded crate needs no pin: its whole suite is already one run.
|
|
1194
1252
|
expect(targets['cargo-test-small-exceptions']).toBeUndefined();
|
|
1195
1253
|
expect(targets['cargo-test-big']).toBeUndefined();
|
|
1196
|
-
// Every piece reaches the aggregate, and they
|
|
1197
|
-
//
|
|
1198
|
-
//
|
|
1254
|
+
// Every piece reaches the aggregate, and they all hang off the one
|
|
1255
|
+
// archive: a run extracts binaries to its own temp directory and writes
|
|
1256
|
+
// nothing to cargo's flocked target/, so nothing is left to serialize.
|
|
1199
1257
|
expect(targets['cargo-test']?.dependsOn).toEqual([
|
|
1200
1258
|
'cargo-test-big-shard1',
|
|
1201
1259
|
'cargo-test-big-shard2',
|
|
@@ -1203,11 +1261,15 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1203
1261
|
'cargo-test-big-exceptions',
|
|
1204
1262
|
'cargo-test-small',
|
|
1205
1263
|
]);
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1264
|
+
for (const name of [
|
|
1265
|
+
'cargo-test-big-shard1',
|
|
1266
|
+
'cargo-test-big-shard2',
|
|
1267
|
+
'cargo-test-big-shard3',
|
|
1268
|
+
'cargo-test-big-exceptions',
|
|
1269
|
+
'cargo-test-small',
|
|
1270
|
+
]) {
|
|
1271
|
+
expect(targets[name]?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
1272
|
+
}
|
|
1211
1273
|
// Pieces of one crate share its inputs: they are one suite, split only to
|
|
1212
1274
|
// fit the bound, so any change to the crate invalidates all of them.
|
|
1213
1275
|
expect(targets['cargo-test-big-shard2']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
|
|
@@ -1464,16 +1526,17 @@ function resolveDeclaredOverInferred(
|
|
|
1464
1526
|
* How a cargo test command is scoped to one crate, split into the three facts
|
|
1465
1527
|
* that can independently go wrong.
|
|
1466
1528
|
*
|
|
1467
|
-
* `--
|
|
1468
|
-
* `cargo
|
|
1469
|
-
*
|
|
1470
|
-
*
|
|
1471
|
-
*
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1529
|
+
* `--archive-file` must be present: the runner executes binaries one workspace
|
|
1530
|
+
* `cargo nextest archive --workspace` already built, so a per-crate run cannot
|
|
1531
|
+
* compile anything. Narrowing comes from the nextest filterset, which selects
|
|
1532
|
+
* what RUNS. `--package` narrows too, but it re-resolves that crate's features,
|
|
1533
|
+
* which is a build — 57.9s of a 120s bounded budget on a hosted 3-core macOS
|
|
1534
|
+
* runner when the runners still built — so its presence is a regression even
|
|
1535
|
+
* though it selects the same tests. nextest rejects it outright beside
|
|
1536
|
+
* `--archive-file`, and this assertion says so before cargo does.
|
|
1474
1537
|
*/
|
|
1475
1538
|
function cargoPackageSelection(command: string): {
|
|
1476
|
-
|
|
1539
|
+
archiveRun: boolean;
|
|
1477
1540
|
packageFlags: string[];
|
|
1478
1541
|
filtered: string[];
|
|
1479
1542
|
} {
|
|
@@ -1488,7 +1551,7 @@ function cargoPackageSelection(command: string): {
|
|
|
1488
1551
|
}
|
|
1489
1552
|
}
|
|
1490
1553
|
return {
|
|
1491
|
-
|
|
1554
|
+
archiveRun: tokens.includes('--archive-file'),
|
|
1492
1555
|
packageFlags,
|
|
1493
1556
|
filtered: [...command.matchAll(/\bpackage\(([^)]+)\)/g)].flatMap((match) =>
|
|
1494
1557
|
match[1] === undefined ? [] : [match[1]],
|