@smoothbricks/nx-plugin 0.3.11 → 0.3.12
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 +23 -2
- package/dist/bounded-test-policy.d.ts +26 -0
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +194 -0
- package/dist/cargo-workspace.d.ts +67 -0
- package/dist/cargo-workspace.d.ts.map +1 -0
- package/dist/cargo-workspace.js +215 -0
- package/dist/cross-check-policy.d.ts +60 -1
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +65 -1
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +86 -51
- package/dist/executors/bounded-exec/schema.d.ts +13 -0
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +344 -57
- package/dist/package-target-policy.d.ts +2 -1
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +54 -13
- package/dist/workspace-config-policy.js +32 -35
- package/nextest.toml +42 -0
- package/package.json +2 -1
- package/src/bounded-test-policy.test.ts +304 -0
- package/src/bounded-test-policy.ts +218 -0
- package/src/cargo-workspace.ts +243 -0
- package/src/cross-check-policy.test.ts +24 -0
- package/src/cross-check-policy.ts +80 -1
- package/src/executors/bounded-exec/executor.test.ts +147 -3
- package/src/executors/bounded-exec/executor.ts +103 -53
- package/src/executors/bounded-exec/schema.json +7 -2
- package/src/executors/bounded-exec/schema.ts +13 -0
- package/src/index.test.ts +373 -25
- package/src/index.ts +390 -65
- package/src/package-target-policy.test.ts +50 -0
- package/src/package-target-policy.ts +58 -9
- package/src/workspace-config-policy.test.ts +15 -30
- package/src/workspace-config-policy.ts +32 -39
package/src/index.test.ts
CHANGED
|
@@ -2,9 +2,14 @@ import { describe, expect, it } from 'bun:test';
|
|
|
2
2
|
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
5
6
|
|
|
6
7
|
import type { CreateNodesContextV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
|
|
7
|
-
import {
|
|
8
|
+
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
9
|
+
import { mergeTargetConfigurations } from 'nx/src/project-graph/utils/project-configuration-utils.js';
|
|
10
|
+
import { BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
|
|
11
|
+
import { exceptionalTestFilter } from './cargo-workspace.js';
|
|
12
|
+
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_LINT_CLIPPY_COMMAND } from './cross-check-policy.js';
|
|
8
13
|
import { createNodesV2 } from './index.js';
|
|
9
14
|
import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
|
|
10
15
|
|
|
@@ -105,6 +110,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
105
110
|
expect(targets.build?.executor).toBe('nx:noop');
|
|
106
111
|
expect(targets.build?.cache).toBe(true);
|
|
107
112
|
expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
|
|
113
|
+
// An `nx:noop` aggregate writes no file, so it must claim none: a
|
|
114
|
+
// `{projectRoot}/dist` claim here would double-cache its children's bytes
|
|
115
|
+
// and make `github-ci nx-run-many --collect-outputs` attribute every file
|
|
116
|
+
// under dist to `build`, including the platform artifacts that collect
|
|
117
|
+
// deliberately leaves to the platform step.
|
|
118
|
+
expect(targets.build?.outputs).toBeUndefined();
|
|
108
119
|
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
109
120
|
expect(targets.clean?.cache).toBe(false);
|
|
110
121
|
|
|
@@ -252,48 +263,110 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
252
263
|
// targets are declared package-locally, never derived from crate metadata.
|
|
253
264
|
expect(Object.keys(targets).sort()).toEqual([
|
|
254
265
|
'bench',
|
|
266
|
+
'cargo-fetch',
|
|
255
267
|
'cargo-lint',
|
|
256
268
|
'cargo-lint-cross',
|
|
269
|
+
'cargo-sweep',
|
|
257
270
|
'cargo-test',
|
|
271
|
+
'cargo-test-compile',
|
|
272
|
+
'cargo-test-ferris-core',
|
|
273
|
+
'cargo-test-ferris-wasm',
|
|
258
274
|
'lint',
|
|
259
275
|
'mutation',
|
|
260
276
|
'test',
|
|
261
277
|
]);
|
|
262
|
-
expect(targets['cargo-
|
|
263
|
-
|
|
264
|
-
|
|
278
|
+
expect(targets['cargo-sweep']?.options).toMatchObject({
|
|
279
|
+
command: 'cargo sweep --time 7',
|
|
280
|
+
cwd: 'packages/ferris',
|
|
281
|
+
});
|
|
282
|
+
expect(targets['cargo-sweep']?.cache).toBe(false);
|
|
283
|
+
// Never cached: the download lands in CARGO_HOME, so a cache hit would
|
|
284
|
+
// report success over a registry that still cannot resolve the lockfile.
|
|
285
|
+
expect(targets['cargo-fetch']?.cache).toBe(false);
|
|
286
|
+
expect(targets['cargo-fetch']?.options).toEqual({
|
|
287
|
+
commands: ['cargo fetch --locked'],
|
|
265
288
|
cwd: 'packages/ferris',
|
|
266
|
-
|
|
289
|
+
parallel: false,
|
|
267
290
|
});
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
291
|
+
// Every frozen cargo command carries the edge, not just the head of the
|
|
292
|
+
// serialization chain: offline cargo fails at resolution, so each one
|
|
293
|
+
// needs the locked graph downloaded whether or not the chain runs first.
|
|
294
|
+
for (const name of ['cargo-test-compile', 'cargo-lint', CARGO_CROSS_LINT_TARGET, 'mutation', 'bench']) {
|
|
295
|
+
expect(targets[name]?.dependsOn).toContain('cargo-fetch');
|
|
296
|
+
}
|
|
297
|
+
expect(targets['cargo-sweep']?.dependsOn).toBeUndefined();
|
|
298
|
+
expect(targets['cargo-test-compile']?.executor).toBe('nx:run-commands');
|
|
299
|
+
expect(targets['cargo-test-compile']?.options).toMatchObject({
|
|
300
|
+
command: 'cargo --frozen test --workspace --no-run',
|
|
301
|
+
cwd: 'packages/ferris',
|
|
302
|
+
});
|
|
303
|
+
expect(targets['cargo-test']?.executor).toBe('nx:noop');
|
|
304
|
+
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-test-ferris-wasm']);
|
|
305
|
+
expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-compile']);
|
|
306
|
+
expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-ferris-core']);
|
|
307
|
+
// `--workspace -E 'package(...)'`, never `--package`: the filterset picks
|
|
308
|
+
// the same tests without re-resolving features, so the run reuses what
|
|
309
|
+
// cargo-test-compile built instead of rebuilding inside the bound.
|
|
310
|
+
expect(targets['cargo-test-ferris-core']?.options?.command).toMatch(
|
|
311
|
+
/^cargo --frozen nextest run --workspace -E 'package\(ferris-core\)' --user-config-file none --config-file /,
|
|
312
|
+
);
|
|
313
|
+
expect(targets['cargo-test-ferris-core']?.inputs).toEqual([
|
|
314
|
+
'{projectRoot}/Cargo.toml',
|
|
315
|
+
'{projectRoot}/Cargo.lock',
|
|
316
|
+
'{projectRoot}/crates/ferris-core/**/*.rs',
|
|
317
|
+
'{projectRoot}/crates/ferris-core/Cargo.toml',
|
|
272
318
|
'{projectRoot}/**/.cargo/config.toml',
|
|
273
319
|
'{projectRoot}/scripts/*.sh',
|
|
274
320
|
'!{projectRoot}/**/target/**',
|
|
275
321
|
]);
|
|
276
322
|
expect(targets['cargo-lint']?.options).toMatchObject({
|
|
277
|
-
commands: ['cargo fmt --all --check',
|
|
323
|
+
commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
|
|
278
324
|
});
|
|
279
325
|
expect(targets.lint?.dependsOn).toEqual(['cargo-lint']);
|
|
280
326
|
expect(targets[CARGO_CROSS_LINT_TARGET]?.options).toMatchObject({
|
|
281
|
-
command:
|
|
327
|
+
command: CARGO_CROSS_LINT_COMMAND,
|
|
282
328
|
cwd: 'packages/ferris',
|
|
283
329
|
});
|
|
284
330
|
expect(targets[CARGO_CROSS_LINT_TARGET]?.cache).toBe(true);
|
|
285
|
-
// The cross gate must never join the lint aggregate: `bun run lint`, and
|
|
286
|
-
// CI's own already-native Linux lint, would then require the opt-in 0.4 GiB
|
|
287
|
-
// cross toolchain to run at all.
|
|
288
331
|
expect(targets.lint?.dependsOn).not.toContain(CARGO_CROSS_LINT_TARGET);
|
|
289
|
-
expect(targets.test?.executor).toBe('
|
|
290
|
-
expect(targets.test?.
|
|
291
|
-
command: 'cargo test --workspace',
|
|
292
|
-
cwd: 'packages/ferris',
|
|
293
|
-
});
|
|
332
|
+
expect(targets.test?.executor).toBe('nx:noop');
|
|
333
|
+
expect(targets.test?.dependsOn).toEqual(['cargo-test']);
|
|
294
334
|
expect(targets.mutation?.cache).toBe(false);
|
|
295
|
-
expect(targets.mutation?.options).toMatchObject({ command: 'cargo mutants --workspace' });
|
|
296
|
-
expect(targets.bench?.options).toMatchObject({ command: 'cargo bench --workspace' });
|
|
335
|
+
expect(targets.mutation?.options).toMatchObject({ command: 'cargo --frozen mutants --workspace' });
|
|
336
|
+
expect(targets.bench?.options).toMatchObject({ command: 'cargo --frozen bench --workspace' });
|
|
337
|
+
} finally {
|
|
338
|
+
await workspace.cleanup();
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('scopes each per-crate cargo-test command to exactly one package', async () => {
|
|
343
|
+
const workspace = await createWorkspace();
|
|
344
|
+
try {
|
|
345
|
+
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
346
|
+
await workspace.write(
|
|
347
|
+
'packages/ferris/Cargo.toml',
|
|
348
|
+
'[workspace]\nmembers = ["crates/ferris-core", "crates/ferris-wasm"]\n',
|
|
349
|
+
);
|
|
350
|
+
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
351
|
+
await workspace.write('packages/ferris/crates/ferris-wasm/Cargo.toml', '[package]\nname = "ferris-wasm"\n');
|
|
352
|
+
|
|
353
|
+
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
354
|
+
|
|
355
|
+
// Scoped by filterset over a workspace build: one crate runs, and the
|
|
356
|
+
// build stays the one cargo-test-compile already paid for.
|
|
357
|
+
expect(cargoPackageSelection(String(targets['cargo-test-ferris-core']?.options?.command ?? ''))).toEqual({
|
|
358
|
+
workspaceBuild: true,
|
|
359
|
+
packageFlags: [],
|
|
360
|
+
filtered: ['ferris-core'],
|
|
361
|
+
});
|
|
362
|
+
expect(cargoPackageSelection(String(targets['cargo-test-ferris-wasm']?.options?.command ?? ''))).toEqual({
|
|
363
|
+
workspaceBuild: true,
|
|
364
|
+
packageFlags: [],
|
|
365
|
+
filtered: ['ferris-wasm'],
|
|
366
|
+
});
|
|
367
|
+
expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-compile']);
|
|
368
|
+
expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-ferris-core']);
|
|
369
|
+
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-test-ferris-wasm']);
|
|
297
370
|
} finally {
|
|
298
371
|
await workspace.cleanup();
|
|
299
372
|
}
|
|
@@ -326,7 +399,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
326
399
|
expect(targets['cargo-wasm']).toMatchObject({
|
|
327
400
|
executor: 'nx:run-commands',
|
|
328
401
|
cache: true,
|
|
329
|
-
dependsOn: ['^build'],
|
|
402
|
+
dependsOn: ['cargo-fetch', '^build'],
|
|
330
403
|
inputs: [
|
|
331
404
|
'{projectRoot}/**/*.rs',
|
|
332
405
|
'{projectRoot}/**/Cargo.toml',
|
|
@@ -340,7 +413,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
340
413
|
outputs: ['{projectRoot}/generated/wasm'],
|
|
341
414
|
options: {
|
|
342
415
|
commands: [
|
|
343
|
-
'cargo build --release --target wasm32-unknown-unknown --target-dir crates/git-do/target/cargo-wasm --manifest-path crates/git-do/Cargo.toml',
|
|
416
|
+
'cargo --frozen build --release --target wasm32-unknown-unknown --target-dir crates/git-do/target/cargo-wasm --manifest-path crates/git-do/Cargo.toml',
|
|
344
417
|
'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/cargo-wasm/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
|
|
345
418
|
'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/cargo-wasm/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
|
|
346
419
|
],
|
|
@@ -348,6 +421,14 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
348
421
|
parallel: false,
|
|
349
422
|
},
|
|
350
423
|
});
|
|
424
|
+
// A wasm-bindgen crate in a nested Cargo workspace still needs its locked
|
|
425
|
+
// graph downloaded, and the project root is not a member of it, so the
|
|
426
|
+
// fetch names the crate manifest instead of relying on cwd.
|
|
427
|
+
expect(targets['cargo-fetch']?.options).toEqual({
|
|
428
|
+
commands: ['cargo fetch --locked --manifest-path crates/git-do/Cargo.toml'],
|
|
429
|
+
cwd: 'packages/git-do',
|
|
430
|
+
parallel: false,
|
|
431
|
+
});
|
|
351
432
|
expect(targets['tsc-js']?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
|
|
352
433
|
expect(targets.typecheck?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
|
|
353
434
|
expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
|
|
@@ -480,13 +561,37 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
480
561
|
expect(platformBuildDependencies).toEqual([]);
|
|
481
562
|
}
|
|
482
563
|
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
564
|
+
// The test suite runs against the dev-profile addon, never a release
|
|
565
|
+
// platform build: napi-debug shares target/debug with cargo-test, keeps
|
|
566
|
+
// the release binaries off the test critical path, and lives outside
|
|
567
|
+
// dist/ so the wholesale-packaged dist/ tree can never ship it.
|
|
568
|
+
expect(targets['napi-debug']).toMatchObject({
|
|
569
|
+
executor: 'nx:run-commands',
|
|
570
|
+
cache: true,
|
|
571
|
+
dependsOn: ['^build', 'cargo-test-compile'],
|
|
572
|
+
outputs: ['{projectRoot}/.cache/native-debug'],
|
|
573
|
+
options: {
|
|
574
|
+
cwd: 'packages/cowshed',
|
|
575
|
+
command:
|
|
576
|
+
'napi build --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir .cache/native-debug',
|
|
577
|
+
},
|
|
578
|
+
});
|
|
579
|
+
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-cowshed-napi']);
|
|
580
|
+
// cargo-fetch survives the napi-debug re-route: the per-crate runner is
|
|
581
|
+
// itself a frozen cargo command, so its precondition is its own edge and
|
|
582
|
+
// not something it inherits from cargo-test-compile's position.
|
|
583
|
+
expect(targets['cargo-test-cowshed-napi']?.dependsOn).toEqual(['cargo-fetch', 'napi-debug']);
|
|
584
|
+
expect(targets['cargo-test-cowshed-napi']?.options?.command).toMatch(
|
|
585
|
+
/^cargo --frozen nextest run --workspace -E 'package\(cowshed-napi\)' --user-config-file none --config-file /,
|
|
586
|
+
);
|
|
483
587
|
expect(targets['napi-test']).toMatchObject({
|
|
484
588
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
485
589
|
cache: true,
|
|
486
|
-
dependsOn: ['cargo-test',
|
|
590
|
+
dependsOn: ['cargo-test', 'napi-debug', 'tsc-js', '^build'],
|
|
487
591
|
options: {
|
|
488
592
|
command: 'bun test --config=../bunfig.toml --timeout=30000 native.test.ts',
|
|
489
593
|
cwd: 'packages/cowshed/src',
|
|
594
|
+
env: { NAPI_DEBUG_ADDON: '1' },
|
|
490
595
|
timeoutMs: 120000,
|
|
491
596
|
killAfterMs: 10000,
|
|
492
597
|
},
|
|
@@ -539,7 +644,98 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
539
644
|
}
|
|
540
645
|
});
|
|
541
646
|
|
|
542
|
-
it('
|
|
647
|
+
it('shards a crate around the tests nextest.toml singles out, not through them', async () => {
|
|
648
|
+
const workspace = await createWorkspace();
|
|
649
|
+
try {
|
|
650
|
+
await workspace.write('packages/rusty/package.json', '{"name":"rusty"}\n');
|
|
651
|
+
await workspace.write('packages/rusty/Cargo.toml', '[workspace]\nmembers = ["crates/big", "crates/small"]\n');
|
|
652
|
+
await workspace.write(
|
|
653
|
+
'packages/rusty/crates/big/Cargo.toml',
|
|
654
|
+
'[package]\nname = "big"\n\n[package.metadata.smoothbricks.test]\nshards = 3\n',
|
|
655
|
+
);
|
|
656
|
+
await workspace.write('packages/rusty/crates/small/Cargo.toml', '[package]\nname = "small"\n');
|
|
657
|
+
|
|
658
|
+
const targets = await inferProjectTargets(workspace, 'packages/rusty/package.json');
|
|
659
|
+
|
|
660
|
+
// An unsharded crate keeps the bare name and takes no --partition, so
|
|
661
|
+
// declaring nothing is exactly the old single-target behaviour.
|
|
662
|
+
expect(targets['cargo-test-small']?.options?.command).toMatch(
|
|
663
|
+
/nextest run --workspace -E 'package\(small\)' --user-config-file none/,
|
|
664
|
+
);
|
|
665
|
+
// The shards partition the crate MINUS the classes nextest.toml singles
|
|
666
|
+
// out, i of N. Those are lifted out because a test-group only holds
|
|
667
|
+
// within one nextest run, and because a test carrying a raised
|
|
668
|
+
// slow-timeout costs what the suite does not — the compile-fail test
|
|
669
|
+
// rustc's a fixture for 25.6s on a cold target dir against 1.8s warm.
|
|
670
|
+
const exceptional = exceptionalTestFilter(fileURLToPath(new URL('../nextest.toml', import.meta.url)));
|
|
671
|
+
if (exceptional === null) {
|
|
672
|
+
throw new Error('nextest.toml declares no overrides; this test asserts the pin that protects them');
|
|
673
|
+
}
|
|
674
|
+
for (const index of [1, 2, 3]) {
|
|
675
|
+
expect(targets[`cargo-test-big-shard${index}`]?.options?.command).toContain(
|
|
676
|
+
`--workspace -E 'package(big) and not (${exceptional})' --partition hash:${index}/3`,
|
|
677
|
+
);
|
|
678
|
+
expect(targets[`cargo-test-big-shard${index}`]?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
|
|
679
|
+
}
|
|
680
|
+
// Exact complement of the shards' filterset, so the union is the crate.
|
|
681
|
+
expect(targets['cargo-test-big-exceptions']?.options?.command).toContain(
|
|
682
|
+
`--workspace -E 'package(big) and (${exceptional})' --no-tests=pass`,
|
|
683
|
+
);
|
|
684
|
+
expect(targets['cargo-test-big-exceptions']?.options?.command).not.toContain('--partition');
|
|
685
|
+
expect(targets['cargo-test-big-exceptions']?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
|
|
686
|
+
// An unsharded crate needs no pin: its whole suite is already one run.
|
|
687
|
+
expect(targets['cargo-test-small-exceptions']).toBeUndefined();
|
|
688
|
+
expect(targets['cargo-test-big']).toBeUndefined();
|
|
689
|
+
// Every piece reaches the aggregate, and they chain rather than fan out:
|
|
690
|
+
// cargo flocks one target/, and chaining also stops the pinned group
|
|
691
|
+
// contending with a shard over a machine-wide resource.
|
|
692
|
+
expect(targets['cargo-test']?.dependsOn).toEqual([
|
|
693
|
+
'cargo-test-big-shard1',
|
|
694
|
+
'cargo-test-big-shard2',
|
|
695
|
+
'cargo-test-big-shard3',
|
|
696
|
+
'cargo-test-big-exceptions',
|
|
697
|
+
'cargo-test-small',
|
|
698
|
+
]);
|
|
699
|
+
expect(targets['cargo-test-big-shard1']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-compile']);
|
|
700
|
+
expect(targets['cargo-test-big-shard2']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-big-shard1']);
|
|
701
|
+
expect(targets['cargo-test-big-shard3']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-big-shard2']);
|
|
702
|
+
expect(targets['cargo-test-big-exceptions']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-big-shard3']);
|
|
703
|
+
expect(targets['cargo-test-small']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-big-exceptions']);
|
|
704
|
+
// Pieces of one crate share its inputs: they are one suite, split only to
|
|
705
|
+
// fit the bound, so any change to the crate invalidates all of them.
|
|
706
|
+
expect(targets['cargo-test-big-shard2']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
|
|
707
|
+
expect(targets['cargo-test-big-exceptions']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
|
|
708
|
+
} finally {
|
|
709
|
+
await workspace.cleanup();
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
it('rejects a shard count that cannot describe a partition', async () => {
|
|
714
|
+
const workspace = await createWorkspace();
|
|
715
|
+
try {
|
|
716
|
+
await workspace.write('packages/rusty/package.json', '{"name":"rusty"}\n');
|
|
717
|
+
await workspace.write('packages/rusty/Cargo.toml', '[workspace]\nmembers = ["crates/big"]\n');
|
|
718
|
+
await workspace.write(
|
|
719
|
+
'packages/rusty/crates/big/Cargo.toml',
|
|
720
|
+
'[package]\nname = "big"\n\n[package.metadata.smoothbricks.test]\nshards = 0\n',
|
|
721
|
+
);
|
|
722
|
+
|
|
723
|
+
// Nx wraps a createNodes throw in AggregateCreateNodesError, so the
|
|
724
|
+
// reason a maintainer needs is in the nested error, not the top message.
|
|
725
|
+
const failure = await inferProjectTargets(workspace, 'packages/rusty/package.json').then(
|
|
726
|
+
() => undefined,
|
|
727
|
+
(error: unknown) => error,
|
|
728
|
+
);
|
|
729
|
+
if (!(failure instanceof AggregateCreateNodesError)) {
|
|
730
|
+
throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
|
|
731
|
+
}
|
|
732
|
+
expect(failure.errors[0]?.[1]?.message).toMatch(/smoothbricks\.test\.shards must be an integer >= 1, got 0/);
|
|
733
|
+
} finally {
|
|
734
|
+
await workspace.cleanup();
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
it('lets explicit nx.targets suppress output and aggregate inference, and skips non-workspace Cargo.toml', async () => {
|
|
543
739
|
const workspace = await createWorkspace();
|
|
544
740
|
try {
|
|
545
741
|
await workspace.write(
|
|
@@ -566,6 +762,107 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
566
762
|
await workspace.cleanup();
|
|
567
763
|
}
|
|
568
764
|
});
|
|
765
|
+
|
|
766
|
+
it('keeps inferring a cargo target the package partially declares', async () => {
|
|
767
|
+
const workspace = await createWorkspace();
|
|
768
|
+
const declared: Record<string, TargetConfiguration> = {
|
|
769
|
+
// One added edge per target. Everything that makes each target do its job
|
|
770
|
+
// — executor, options, inputs, cache, configurations — must survive the
|
|
771
|
+
// declaration instead of being replaced wholesale by it.
|
|
772
|
+
'cargo-test': { dependsOn: ['cargo-test-compile', 'cargo-wasm'] },
|
|
773
|
+
'cargo-test-compile': { dependsOn: ['cargo-wasm'] },
|
|
774
|
+
'cargo-lint': { inputs: ['{projectRoot}/clippy.toml'] },
|
|
775
|
+
mutation: { options: { command: 'cargo mutants --in-diff' } },
|
|
776
|
+
bench: { cache: true },
|
|
777
|
+
};
|
|
778
|
+
try {
|
|
779
|
+
await workspace.write(
|
|
780
|
+
'packages/ferris/package.json',
|
|
781
|
+
JSON.stringify({ name: 'ferris', nx: { targets: declared } }),
|
|
782
|
+
);
|
|
783
|
+
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = []\n');
|
|
784
|
+
|
|
785
|
+
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
786
|
+
|
|
787
|
+
// Inference must still emit the base. Without one Nx has nothing to merge
|
|
788
|
+
// the declaration onto and normalizes a bare `dependsOn` to `nx:noop` with
|
|
789
|
+
// empty options — a cargo-test that passes having run no test binary.
|
|
790
|
+
expect(targets['cargo-test']?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
791
|
+
expect(targets['cargo-test-compile']?.executor).toBe('nx:run-commands');
|
|
792
|
+
expect(targets['cargo-lint']?.options).toMatchObject({
|
|
793
|
+
commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
const cargoTest = resolveDeclaredOverInferred(targets, declared, 'cargo-test');
|
|
797
|
+
expect(cargoTest?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
798
|
+
expect(cargoTest?.cache).toBe(true);
|
|
799
|
+
expect(cargoTest?.dependsOn).toEqual(['cargo-test-compile', 'cargo-wasm']);
|
|
800
|
+
expect(cargoTest?.options).toEqual({
|
|
801
|
+
command: 'cargo --frozen test --workspace',
|
|
802
|
+
cwd: 'packages/ferris',
|
|
803
|
+
timeoutMs: 120000,
|
|
804
|
+
killAfterMs: 10000,
|
|
805
|
+
});
|
|
806
|
+
expect(cargoTest?.configurations).toEqual({
|
|
807
|
+
production: { command: 'cargo --frozen test --workspace --release' },
|
|
808
|
+
});
|
|
809
|
+
expect(cargoTest?.inputs).toContain('{projectRoot}/**/*.rs');
|
|
810
|
+
|
|
811
|
+
const cargoTestCompile = resolveDeclaredOverInferred(targets, declared, 'cargo-test-compile');
|
|
812
|
+
expect(cargoTestCompile?.executor).toBe('nx:run-commands');
|
|
813
|
+
// A replacing array drops every inferred edge, cargo-fetch included: the
|
|
814
|
+
// package now owns ordering the locked fetch ahead of its frozen compile.
|
|
815
|
+
expect(cargoTestCompile?.dependsOn).toEqual(['cargo-wasm']);
|
|
816
|
+
expect(targets['cargo-test-compile']?.dependsOn).toEqual(['cargo-fetch']);
|
|
817
|
+
expect(cargoTestCompile?.options).toMatchObject({
|
|
818
|
+
command: 'cargo --frozen test --workspace --no-run',
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
// A declared array replaces the inferred one; the command it guards stays.
|
|
822
|
+
const cargoLint = resolveDeclaredOverInferred(targets, declared, 'cargo-lint');
|
|
823
|
+
expect(cargoLint?.inputs).toEqual(['{projectRoot}/clippy.toml']);
|
|
824
|
+
expect(cargoLint?.options).toMatchObject({
|
|
825
|
+
commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
// `options` merges key by key, so a declared command overrides only itself.
|
|
829
|
+
const mutation = resolveDeclaredOverInferred(targets, declared, 'mutation');
|
|
830
|
+
expect(mutation?.options).toEqual({ command: 'cargo mutants --in-diff', cwd: 'packages/ferris' });
|
|
831
|
+
expect(mutation?.cache).toBe(false);
|
|
832
|
+
|
|
833
|
+
const bench = resolveDeclaredOverInferred(targets, declared, 'bench');
|
|
834
|
+
expect(bench?.cache).toBe(true);
|
|
835
|
+
expect(bench?.options).toMatchObject({ command: 'cargo --frozen bench --workspace' });
|
|
836
|
+
} finally {
|
|
837
|
+
await workspace.cleanup();
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
it('lets a declared dependsOn spread expand the inferred cargo chain', async () => {
|
|
842
|
+
const workspace = await createWorkspace();
|
|
843
|
+
// Additive intent has Nx's own spelling: `'...'` expands the inferred list
|
|
844
|
+
// at the token, so an added edge keeps the cargo serialization chain.
|
|
845
|
+
const declared: Record<string, TargetConfiguration> = {
|
|
846
|
+
'cargo-test': { dependsOn: ['...', 'cargo-wasm'] },
|
|
847
|
+
};
|
|
848
|
+
try {
|
|
849
|
+
await workspace.write(
|
|
850
|
+
'packages/ferris/package.json',
|
|
851
|
+
JSON.stringify({ name: 'ferris', nx: { targets: declared } }),
|
|
852
|
+
);
|
|
853
|
+
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = []\n');
|
|
854
|
+
|
|
855
|
+
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
856
|
+
|
|
857
|
+
// The spread expands exactly once, against the single inferred base this
|
|
858
|
+
// plugin emits — re-implementing the overlay here would double it.
|
|
859
|
+
const cargoTest = resolveDeclaredOverInferred(targets, declared, 'cargo-test');
|
|
860
|
+
expect(cargoTest?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-compile', 'cargo-wasm']);
|
|
861
|
+
expect(cargoTest?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
862
|
+
} finally {
|
|
863
|
+
await workspace.cleanup();
|
|
864
|
+
}
|
|
865
|
+
});
|
|
569
866
|
//#endregion
|
|
570
867
|
});
|
|
571
868
|
|
|
@@ -605,3 +902,54 @@ async function inferProjectTargets(
|
|
|
605
902
|
): Promise<Record<string, TargetConfiguration>> {
|
|
606
903
|
return (await inferProject(workspace, packageJsonPath))?.targets ?? {};
|
|
607
904
|
}
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* The configuration Nx resolves for a target this plugin infers and the package
|
|
908
|
+
* also declares. Nx merges a package-local `nx.targets` entry over an inference
|
|
909
|
+
* plugin's target one layer later — the precedence order is specified plugins →
|
|
910
|
+
* target defaults → default plugins, and the package.json reader is a default
|
|
911
|
+
* plugin — so composing with the same merge function the graph uses makes these
|
|
912
|
+
* assertions the resolved configuration rather than a guess about it.
|
|
913
|
+
*/
|
|
914
|
+
function resolveDeclaredOverInferred(
|
|
915
|
+
targets: Record<string, TargetConfiguration>,
|
|
916
|
+
declared: Record<string, TargetConfiguration>,
|
|
917
|
+
name: string,
|
|
918
|
+
): TargetConfiguration | undefined {
|
|
919
|
+
const inferred = targets[name];
|
|
920
|
+
return inferred && mergeTargetConfigurations(declared[name] ?? {}, inferred);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* How a cargo test command is scoped to one crate, split into the three facts
|
|
925
|
+
* that can independently go wrong.
|
|
926
|
+
*
|
|
927
|
+
* `--workspace` must be present: it makes the build fingerprint-identical to
|
|
928
|
+
* `cargo-test-compile`'s, so the bounded run reuses those artifacts. Narrowing
|
|
929
|
+
* must come from the nextest filterset, which selects what RUNS without
|
|
930
|
+
* changing what is BUILT. `--package` narrows too, but it re-resolves that
|
|
931
|
+
* crate's features, diverges from the workspace build, and rebuilds inside the
|
|
932
|
+
* bounded window — 57.9s of a 120s budget on a hosted 3-core macOS runner — so
|
|
933
|
+
* its presence is a regression even though it selects the same tests.
|
|
934
|
+
*/
|
|
935
|
+
function cargoPackageSelection(command: string): {
|
|
936
|
+
workspaceBuild: boolean;
|
|
937
|
+
packageFlags: string[];
|
|
938
|
+
filtered: string[];
|
|
939
|
+
} {
|
|
940
|
+
const tokens = command.split(/\s+/);
|
|
941
|
+
const packageFlags: string[] = [];
|
|
942
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
943
|
+
if (tokens[i] === '--package' || tokens[i] === '-p') {
|
|
944
|
+
const name = tokens[i + 1];
|
|
945
|
+
if (name !== undefined && name.length > 0) {
|
|
946
|
+
packageFlags.push(name);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
return {
|
|
951
|
+
workspaceBuild: tokens.includes('--workspace'),
|
|
952
|
+
packageFlags,
|
|
953
|
+
filtered: [...command.matchAll(/\bpackage\(([^)]+)\)/g)].map((match) => match[1] as string),
|
|
954
|
+
};
|
|
955
|
+
}
|