@smoothbricks/nx-plugin 0.3.11 → 0.3.13

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.
Files changed (38) hide show
  1. package/README.md +23 -2
  2. package/dist/bounded-test-policy.d.ts +26 -0
  3. package/dist/bounded-test-policy.d.ts.map +1 -1
  4. package/dist/bounded-test-policy.js +194 -0
  5. package/dist/cargo-workspace.d.ts +67 -0
  6. package/dist/cargo-workspace.d.ts.map +1 -0
  7. package/dist/cargo-workspace.js +215 -0
  8. package/dist/cross-check-policy.d.ts +60 -1
  9. package/dist/cross-check-policy.d.ts.map +1 -1
  10. package/dist/cross-check-policy.js +65 -1
  11. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  12. package/dist/executors/bounded-exec/executor.js +86 -51
  13. package/dist/executors/bounded-exec/schema.d.ts +13 -0
  14. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  15. package/dist/index.d.ts +10 -5
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +455 -95
  18. package/dist/package-target-policy.d.ts +2 -1
  19. package/dist/package-target-policy.d.ts.map +1 -1
  20. package/dist/package-target-policy.js +54 -13
  21. package/dist/workspace-config-policy.js +32 -35
  22. package/nextest.toml +79 -0
  23. package/package.json +2 -1
  24. package/src/bounded-test-policy.test.ts +304 -0
  25. package/src/bounded-test-policy.ts +218 -0
  26. package/src/cargo-workspace.ts +243 -0
  27. package/src/cross-check-policy.test.ts +24 -0
  28. package/src/cross-check-policy.ts +80 -1
  29. package/src/executors/bounded-exec/executor.test.ts +147 -3
  30. package/src/executors/bounded-exec/executor.ts +103 -53
  31. package/src/executors/bounded-exec/schema.json +7 -2
  32. package/src/executors/bounded-exec/schema.ts +13 -0
  33. package/src/index.test.ts +531 -99
  34. package/src/index.ts +527 -104
  35. package/src/package-target-policy.test.ts +50 -0
  36. package/src/package-target-policy.ts +58 -9
  37. package/src/workspace-config-policy.test.ts +15 -30
  38. package/src/workspace-config-policy.ts +32 -39
package/src/index.test.ts CHANGED
@@ -2,14 +2,17 @@ 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
- import type { CreateNodesContextV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
7
- import { CARGO_CROSS_LINT_TARGET } from './cross-check-policy.js';
8
- import { createNodesV2 } from './index.js';
9
- import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
7
+ import type { CreateNodesContextV2, CreateNodesV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
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';
13
+ import { createNodesV2, createNodesV2ForPlatform } from './index.js';
10
14
 
11
15
  const [, inferTargets] = createNodesV2;
12
- const buildOutputDependencies = ['^build', ...BUILD_OUTPUT_DEPENDENCIES];
13
16
 
14
17
  describe('@smoothbricks/nx-plugin inferred targets', () => {
15
18
  it('names standalone package projects from package metadata', async () => {
@@ -104,7 +107,13 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
104
107
  ]);
105
108
  expect(targets.build?.executor).toBe('nx:noop');
106
109
  expect(targets.build?.cache).toBe(true);
107
- expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
110
+ expect(targets.build?.dependsOn).toEqual(['^build', 'tsc-js']);
111
+ // An `nx:noop` aggregate writes no file, so it must claim none: a
112
+ // `{projectRoot}/dist` claim here would double-cache its children's bytes
113
+ // and make `github-ci nx-run-many --collect-outputs` attribute every file
114
+ // under dist to `build`, including the platform artifacts that collect
115
+ // deliberately leaves to the platform step.
116
+ expect(targets.build?.outputs).toBeUndefined();
108
117
  expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
109
118
  expect(targets.clean?.cache).toBe(false);
110
119
 
@@ -195,7 +204,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
195
204
  expect(targets['tsc-js']).toBeUndefined();
196
205
  expect(targets['tsdown-js']).toBeUndefined();
197
206
  expect(targets.build?.executor).toBe('nx:noop');
198
- expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
207
+ expect(targets.build?.dependsOn).toEqual(['^build', 'tsdown-js']);
199
208
  expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
200
209
  } finally {
201
210
  await workspace.cleanup();
@@ -223,9 +232,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
223
232
 
224
233
  expect(targets.build).toBeUndefined();
225
234
  expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
226
- expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-ios');
227
- expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-macos');
228
- expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-linux');
235
+ // No ordinary aggregate above is the whole assertion: a platform suffix
236
+ // is not an output family, so `bundle-ios`/`-macos`/`-linux` give this
237
+ // project nothing for `build` to aggregate — only a `clean` to own their
238
+ // outputs.
229
239
  } finally {
230
240
  await workspace.cleanup();
231
241
  }
@@ -252,48 +262,110 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
252
262
  // targets are declared package-locally, never derived from crate metadata.
253
263
  expect(Object.keys(targets).sort()).toEqual([
254
264
  'bench',
265
+ 'cargo-fetch',
255
266
  'cargo-lint',
256
267
  'cargo-lint-cross',
268
+ 'cargo-sweep',
257
269
  'cargo-test',
270
+ 'cargo-test-compile',
271
+ 'cargo-test-ferris-core',
272
+ 'cargo-test-ferris-wasm',
258
273
  'lint',
259
274
  'mutation',
260
275
  'test',
261
276
  ]);
262
- expect(targets['cargo-test']?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
263
- expect(targets['cargo-test']?.options).toMatchObject({
264
- command: 'cargo test --workspace',
277
+ expect(targets['cargo-sweep']?.options).toMatchObject({
278
+ command: 'cargo sweep --time 7',
279
+ cwd: 'packages/ferris',
280
+ });
281
+ expect(targets['cargo-sweep']?.cache).toBe(false);
282
+ // Never cached: the download lands in CARGO_HOME, so a cache hit would
283
+ // report success over a registry that still cannot resolve the lockfile.
284
+ expect(targets['cargo-fetch']?.cache).toBe(false);
285
+ expect(targets['cargo-fetch']?.options).toEqual({
286
+ commands: ['cargo fetch --locked'],
265
287
  cwd: 'packages/ferris',
266
- timeoutMs: 1_200_000,
288
+ parallel: false,
267
289
  });
268
- expect(targets['cargo-test']?.inputs).toEqual([
269
- '{projectRoot}/**/*.rs',
270
- '{projectRoot}/**/Cargo.toml',
271
- '{projectRoot}/**/Cargo.lock',
290
+ // Every frozen cargo command carries the edge, not just the head of the
291
+ // serialization chain: offline cargo fails at resolution, so each one
292
+ // needs the locked graph downloaded whether or not the chain runs first.
293
+ for (const name of ['cargo-test-compile', 'cargo-lint', CARGO_CROSS_LINT_TARGET, 'mutation', 'bench']) {
294
+ expect(targets[name]?.dependsOn).toContain('cargo-fetch');
295
+ }
296
+ expect(targets['cargo-sweep']?.dependsOn).toBeUndefined();
297
+ expect(targets['cargo-test-compile']?.executor).toBe('nx:run-commands');
298
+ expect(targets['cargo-test-compile']?.options).toMatchObject({
299
+ command: 'cargo --frozen test --workspace --no-run',
300
+ cwd: 'packages/ferris',
301
+ });
302
+ expect(targets['cargo-test']?.executor).toBe('nx:noop');
303
+ expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-test-ferris-wasm']);
304
+ expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-compile']);
305
+ expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-ferris-core']);
306
+ // `--workspace -E 'package(...)'`, never `--package`: the filterset picks
307
+ // the same tests without re-resolving features, so the run reuses what
308
+ // cargo-test-compile built instead of rebuilding inside the bound.
309
+ expect(targets['cargo-test-ferris-core']?.options?.command).toMatch(
310
+ /^cargo --frozen nextest run --workspace -E 'package\(ferris-core\)' --user-config-file none --config-file /,
311
+ );
312
+ expect(targets['cargo-test-ferris-core']?.inputs).toEqual([
313
+ '{projectRoot}/Cargo.toml',
314
+ '{projectRoot}/Cargo.lock',
315
+ '{projectRoot}/crates/ferris-core/**/*.rs',
316
+ '{projectRoot}/crates/ferris-core/Cargo.toml',
272
317
  '{projectRoot}/**/.cargo/config.toml',
273
318
  '{projectRoot}/scripts/*.sh',
274
319
  '!{projectRoot}/**/target/**',
275
320
  ]);
276
321
  expect(targets['cargo-lint']?.options).toMatchObject({
277
- commands: ['cargo fmt --all --check', 'cargo clippy --workspace --all-targets -- -D warnings'],
322
+ commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
278
323
  });
279
324
  expect(targets.lint?.dependsOn).toEqual(['cargo-lint']);
280
325
  expect(targets[CARGO_CROSS_LINT_TARGET]?.options).toMatchObject({
281
- command: 'cargo clippy --workspace --all-targets --target x86_64-unknown-linux-gnu -- -D warnings',
326
+ command: CARGO_CROSS_LINT_COMMAND,
282
327
  cwd: 'packages/ferris',
283
328
  });
284
329
  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
330
  expect(targets.lint?.dependsOn).not.toContain(CARGO_CROSS_LINT_TARGET);
289
- expect(targets.test?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
290
- expect(targets.test?.options).toMatchObject({
291
- command: 'cargo test --workspace',
292
- cwd: 'packages/ferris',
293
- });
331
+ expect(targets.test?.executor).toBe('nx:noop');
332
+ expect(targets.test?.dependsOn).toEqual(['cargo-test']);
294
333
  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' });
334
+ expect(targets.mutation?.options).toMatchObject({ command: 'cargo --frozen mutants --workspace' });
335
+ expect(targets.bench?.options).toMatchObject({ command: 'cargo --frozen bench --workspace' });
336
+ } finally {
337
+ await workspace.cleanup();
338
+ }
339
+ });
340
+
341
+ it('scopes each per-crate cargo-test command to exactly one package', async () => {
342
+ const workspace = await createWorkspace();
343
+ try {
344
+ await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
345
+ await workspace.write(
346
+ 'packages/ferris/Cargo.toml',
347
+ '[workspace]\nmembers = ["crates/ferris-core", "crates/ferris-wasm"]\n',
348
+ );
349
+ await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
350
+ await workspace.write('packages/ferris/crates/ferris-wasm/Cargo.toml', '[package]\nname = "ferris-wasm"\n');
351
+
352
+ const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
353
+
354
+ // Scoped by filterset over a workspace build: one crate runs, and the
355
+ // build stays the one cargo-test-compile already paid for.
356
+ expect(cargoPackageSelection(String(targets['cargo-test-ferris-core']?.options?.command ?? ''))).toEqual({
357
+ workspaceBuild: true,
358
+ packageFlags: [],
359
+ filtered: ['ferris-core'],
360
+ });
361
+ expect(cargoPackageSelection(String(targets['cargo-test-ferris-wasm']?.options?.command ?? ''))).toEqual({
362
+ workspaceBuild: true,
363
+ packageFlags: [],
364
+ filtered: ['ferris-wasm'],
365
+ });
366
+ expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-compile']);
367
+ expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-ferris-core']);
368
+ expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-test-ferris-wasm']);
297
369
  } finally {
298
370
  await workspace.cleanup();
299
371
  }
@@ -326,7 +398,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
326
398
  expect(targets['cargo-wasm']).toMatchObject({
327
399
  executor: 'nx:run-commands',
328
400
  cache: true,
329
- dependsOn: ['^build'],
401
+ dependsOn: ['cargo-fetch', '^build'],
330
402
  inputs: [
331
403
  '{projectRoot}/**/*.rs',
332
404
  '{projectRoot}/**/Cargo.toml',
@@ -340,7 +412,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
340
412
  outputs: ['{projectRoot}/generated/wasm'],
341
413
  options: {
342
414
  commands: [
343
- 'cargo build --release --target wasm32-unknown-unknown --target-dir crates/git-do/target/cargo-wasm --manifest-path crates/git-do/Cargo.toml',
415
+ 'cargo --frozen build --release --target wasm32-unknown-unknown --target-dir crates/git-do/target/cargo-wasm --manifest-path crates/git-do/Cargo.toml',
344
416
  'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/cargo-wasm/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
345
417
  'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/cargo-wasm/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
346
418
  ],
@@ -348,9 +420,17 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
348
420
  parallel: false,
349
421
  },
350
422
  });
423
+ // A wasm-bindgen crate in a nested Cargo workspace still needs its locked
424
+ // graph downloaded, and the project root is not a member of it, so the
425
+ // fetch names the crate manifest instead of relying on cwd.
426
+ expect(targets['cargo-fetch']?.options).toEqual({
427
+ commands: ['cargo fetch --locked --manifest-path crates/git-do/Cargo.toml'],
428
+ cwd: 'packages/git-do',
429
+ parallel: false,
430
+ });
351
431
  expect(targets['tsc-js']?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
352
432
  expect(targets.typecheck?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
353
- expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
433
+ expect(targets.build?.dependsOn).toEqual(['^build', 'cargo-wasm', 'tsc-js']);
354
434
  expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
355
435
  // A nested crate manifest is enough for output inference, but not for
356
436
  // workspace-wide cargo-test/lint policy.
@@ -401,92 +481,194 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
401
481
 
402
482
  expect(targets['cargo-wasm']).toBeUndefined();
403
483
  expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/ts']);
404
- // Match the production host suffix so both native-platform and dedicated
405
- // cargo-napi host-provider regimes are covered on every runner.
484
+ // This fixture declares all four supported triples, so on EVERY supported
485
+ // runner the host's own triple is present and native: the host provider is
486
+ // that platform target and `cargo-napi` is never inferred. Tying the native
487
+ // regime to `-macos` asserted a macOS-only model and failed on Linux with
488
+ // zero host providers found. The dedicated `cargo-napi` regime is covered
489
+ // below against a platform no declared triple can serve, which reaches it
490
+ // on every runner instead of only on Linux.
406
491
  const hostOs = process.platform === 'darwin' ? 'macos' : process.platform === 'linux' ? 'linux' : null;
407
492
  const hostArch = process.arch === 'arm64' ? 'arm64' : process.arch === 'x64' ? 'x64' : null;
408
493
  const hostSuffix = hostOs !== null && hostArch !== null ? `-${hostArch}-${hostOs}` : null;
409
- const hostPlatformNapiTarget = hostSuffix === null ? null : `napi${hostSuffix}`;
410
- const nativeHostProvider = hostPlatformNapiTarget?.endsWith('-macos') ? hostPlatformNapiTarget : null;
411
- const hostProvider = nativeHostProvider ?? 'cargo-napi';
412
- const hostProviders = ['cargo-napi', nativeHostProvider].filter(
413
- (name): name is string => name !== null && targets[name] !== undefined,
414
- );
415
- expect(hostProviders).toHaveLength(1);
416
- expect(hostProviders[0]).toBe(hostProvider);
417
- if (hostProvider === 'cargo-napi') {
418
- expect(targets['cargo-napi']).toMatchObject({
419
- executor: 'nx:run-commands',
420
- cache: true,
421
- dependsOn: ['^build'],
422
- outputs: ['{projectRoot}/dist/native/host'],
423
- options: {
424
- cwd: 'packages/cowshed',
425
- command:
426
- 'napi build --release --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/host',
427
- },
428
- });
429
- } else {
430
- expect(targets['cargo-napi']).toBeUndefined();
431
- }
494
+ expect(hostSuffix).not.toBeNull();
495
+ expect(targets[`napi${hostSuffix}`]).toBeDefined();
496
+ expect(targets['cargo-napi']).toBeUndefined();
497
+
498
+ // A platform outside NAPI_TARGET_CONVENTIONS leaves no native host target,
499
+ // which is precisely the condition that infers the dedicated host build.
500
+ const unservedHostTargets = await inferProjectTargets(
501
+ workspace,
502
+ 'packages/cowshed/package.json',
503
+ createNodesV2ForPlatform('win32', 'x64'),
504
+ );
505
+ expect(unservedHostTargets['cargo-napi']).toMatchObject({
506
+ executor: 'nx:run-commands',
507
+ cache: true,
508
+ // The dedicated host build is another cargo writer on the default
509
+ // `target/`, and `build` lists it beside cargo-test-compile.
510
+ dependsOn: ['^build', 'cargo-test-compile'],
511
+ outputs: ['{projectRoot}/dist/native/host'],
512
+ options: {
513
+ cwd: 'packages/cowshed',
514
+ command:
515
+ 'napi build --release --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/host',
516
+ },
517
+ });
518
+ expect(unservedHostTargets.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'cargo-napi', 'tsc-js']);
432
519
  expect(targets['napi-arm64-macos']?.outputs).toEqual(['{projectRoot}/dist/native/darwin-arm64']);
433
520
  expect(targets['napi-arm64-macos']?.options).toMatchObject({
434
521
  command:
435
522
  'napi build --release --platform --no-js --dts cowshed.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/darwin-arm64',
436
523
  });
437
524
  expect(targets['napi-arm64-macos']?.options?.env).toBeUndefined();
525
+ // No cargo-test-compile edge here, on ANY host: a platform target's
526
+ // dependency closure may only reach its own family
527
+ // (`validatePlatformTargetDependencies`), so this pair serializes on
528
+ // cargo's flock rather than on a graph edge.
438
529
  expect(targets['napi-arm64-macos']?.dependsOn).toBeUndefined();
439
- expect(targets['napi-toolchain-arm64-linux']).toEqual({
530
+ // A macOS triple never gets a cross toolchain: `usesNapiCross` is
531
+ // `family === 'linux' && target !== host`, so the family decides this one
532
+ // and no host can change it.
533
+ expect(targets['napi-toolchain-x64-macos']).toBeUndefined();
534
+ // Everything else about the cross regime depends on WHICH host is
535
+ // inferring — on an x64 Linux runner `napi-x64-linux` is the native build,
536
+ // with no `--use-napi-cross` and no toolchain prerequisite at all. Those
537
+ // facts are asserted against forced platforms below instead of against
538
+ // whichever machine happens to run the suite.
539
+
540
+ // Exercise both host branches explicitly: this suite usually runs on
541
+ // Darwin, but Linux's native compiler selection is the contract at risk.
542
+ const linuxX64Targets = await inferProjectTargets(
543
+ workspace,
544
+ 'packages/cowshed/package.json',
545
+ createNodesV2ForPlatform('linux', 'x64'),
546
+ );
547
+ expect(linuxX64Targets['napi-x64-linux']?.options?.command).not.toContain('--use-napi-cross');
548
+ expect(linuxX64Targets['napi-x64-linux']?.options?.env).toEqual({ CC: 'cc', CXX: 'c++' });
549
+ expect(linuxX64Targets['napi-x64-linux']?.dependsOn).toBeUndefined();
550
+ expect(linuxX64Targets['napi-toolchain-x64-linux']).toBeUndefined();
551
+ expect(linuxX64Targets['napi-arm64-linux']?.options?.command).toContain('--use-napi-cross');
552
+ expect(linuxX64Targets['napi-arm64-linux']?.options?.env).toEqual({
553
+ TARGET_CC: 'clang',
554
+ TARGET_CXX: 'clang++',
555
+ });
556
+ expect(linuxX64Targets['napi-debug']?.options?.env).toEqual({ CC: 'cc', CXX: 'c++' });
557
+
558
+ const darwinArm64Targets = await inferProjectTargets(
559
+ workspace,
560
+ 'packages/cowshed/package.json',
561
+ createNodesV2ForPlatform('darwin', 'arm64'),
562
+ );
563
+ expect(darwinArm64Targets['napi-x64-linux']?.options?.command).toContain('--use-napi-cross');
564
+ expect(darwinArm64Targets['napi-x64-linux']?.options?.env).toEqual({
565
+ TARGET_CC: 'clang',
566
+ TARGET_CXX: 'clang++',
567
+ });
568
+ expect(darwinArm64Targets['napi-x64-linux']?.dependsOn).toEqual(['napi-toolchain-x64-linux']);
569
+ expect(darwinArm64Targets['napi-debug']?.options?.env).toBeUndefined();
570
+ expect(darwinArm64Targets['napi-toolchain-arm64-linux']).toEqual({
440
571
  executor: '@smoothbricks/nx-plugin:napi-cross-toolchain',
441
572
  cache: false,
442
573
  options: { triple: 'aarch64-unknown-linux-gnu' },
443
574
  });
444
- expect(targets['napi-toolchain-x64-linux']).toEqual({
575
+ expect(darwinArm64Targets['napi-toolchain-x64-linux']).toEqual({
445
576
  executor: '@smoothbricks/nx-plugin:napi-cross-toolchain',
446
577
  cache: false,
447
578
  options: { triple: 'x86_64-unknown-linux-gnu' },
448
579
  });
449
- expect(targets['napi-x64-linux']?.dependsOn).toEqual(['napi-toolchain-x64-linux']);
450
- expect(targets['napi-arm64-linux']?.dependsOn).toEqual(['napi-toolchain-arm64-linux']);
451
- expect(targets['napi-toolchain-x64-macos']).toBeUndefined();
452
- expect(targets['napi-x64-linux']?.outputs).toEqual(['{projectRoot}/dist/native/linux-x64-gnu']);
453
- expect(targets['napi-x64-linux']?.options).toMatchObject({
454
- command:
455
- 'napi build --release --platform --no-js --dts cowshed.linux-x64-gnu.d.ts --target x86_64-unknown-linux-gnu --use-napi-cross --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/linux-x64-gnu',
456
- env: { TARGET_CC: 'clang', TARGET_CXX: 'clang++' },
457
- });
458
- // The aggregate build pulls in exactly the HOST's platform-suffixed
459
- // targets (publish still owns foreign platforms).
460
- const hostNapiTargets = [
461
- 'cli-arm64-macos',
462
- 'cli-x64-linux',
463
- 'napi-arm64-macos',
464
- 'napi-x64-macos',
465
- 'napi-arm64-linux',
466
- 'napi-x64-linux',
467
- ]
468
- .filter((name) => hostSuffix !== null && name.endsWith(hostSuffix))
469
- .sort();
470
- expect(targets.build?.dependsOn).toEqual([...buildOutputDependencies, ...hostNapiTargets]);
471
- const platformBuildDependencies = (targets.build?.dependsOn ?? []).filter(
472
- (dependency): dependency is string =>
473
- typeof dependency === 'string' && /-(?:arm64|x64)-(?:macos|linux)$/.test(dependency),
474
- );
475
- if (hostSuffix !== null) {
476
- for (const name of platformBuildDependencies) {
477
- expect(name.endsWith(hostSuffix)).toBe(true);
580
+ expect(darwinArm64Targets['napi-arm64-linux']?.dependsOn).toEqual(['napi-toolchain-arm64-linux']);
581
+ expect(darwinArm64Targets['napi-x64-linux']?.outputs).toEqual(['{projectRoot}/dist/native/linux-x64-gnu']);
582
+ expect(darwinArm64Targets['napi-x64-linux']?.options?.command).toBe(
583
+ 'napi build --release --platform --no-js --dts cowshed.linux-x64-gnu.d.ts --target x86_64-unknown-linux-gnu --use-napi-cross --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/linux-x64-gnu',
584
+ );
585
+
586
+ // The whole rule, stated once per forced host: a triple gets a cross
587
+ // toolchain exactly when it is a linux triple that is not this host's own.
588
+ // Asserting the pair by name is what broke on Linux, where
589
+ // napi-toolchain-x64-linux legitimately does not exist.
590
+ for (const [inferred, hostTriple] of [
591
+ [linuxX64Targets, 'x64-linux'],
592
+ [darwinArm64Targets, 'arm64-macos'],
593
+ ] as const) {
594
+ for (const suffix of ['arm64-linux', 'x64-linux', 'arm64-macos', 'x64-macos']) {
595
+ const expectsToolchain = suffix.endsWith('-linux') && suffix !== hostTriple;
596
+ expect(inferred[`napi-toolchain-${suffix}`] === undefined).toBe(!expectsToolchain);
597
+ expect(inferred[`napi-${suffix}`]?.options?.command).toContain(
598
+ expectsToolchain ? '--use-napi-cross' : '--target',
599
+ );
600
+ }
601
+ }
602
+ // The aggregate build pulls in exactly the inferring host's
603
+ // platform-suffixed targets (publish still owns foreign platforms), and
604
+ // the only cargo-test work it owns is compiling the executables — every
605
+ // RUNNER is reached through `test`. Both hosts are asserted here so the
606
+ // expectation does not depend on which machine runs the suite: the
607
+ // previous form read `process.platform`, and the macOS answer was the only
608
+ // one anyone checked.
609
+ for (const [inferred, hostSuffix] of [
610
+ [linuxX64Targets, '-x64-linux'],
611
+ [darwinArm64Targets, '-arm64-macos'],
612
+ ] as const) {
613
+ const hostNapiTargets = [
614
+ 'cli-arm64-macos',
615
+ 'cli-x64-linux',
616
+ 'napi-arm64-macos',
617
+ 'napi-x64-macos',
618
+ 'napi-arm64-linux',
619
+ 'napi-x64-linux',
620
+ ]
621
+ .filter((name) => name.endsWith(hostSuffix))
622
+ .sort();
623
+ expect(hostNapiTargets.length).toBeGreaterThan(0);
624
+ expect(inferred.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'tsc-js', ...hostNapiTargets]);
625
+ // Crate `cowshed-napi` names its bounded runner
626
+ // `cargo-test-cowshed-napi`, which the retired `*-napi` output-family
627
+ // glob matched on suffix alone. The runners are one serialized chain, so
628
+ // that single edge put the whole cargo test suite inside
629
+ // `nx run-many -t build`.
630
+ expect(inferred['cargo-test-cowshed-napi']).toBeDefined();
631
+ for (const dependency of inferred.build?.dependsOn ?? []) {
632
+ expect(String(dependency).startsWith('cargo-test-')).toBe(dependency === 'cargo-test-compile');
633
+ }
634
+ for (const dependency of inferred.build?.dependsOn ?? []) {
635
+ if (typeof dependency === 'string' && /-(?:arm64|x64)-(?:macos|linux)$/.test(dependency)) {
636
+ expect(dependency.endsWith(hostSuffix)).toBe(true);
637
+ }
478
638
  }
479
- } else {
480
- expect(platformBuildDependencies).toEqual([]);
481
639
  }
482
640
  expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
641
+ // The test suite runs against the dev-profile addon, never a release
642
+ // platform build: napi-debug shares target/debug with cargo-test, keeps
643
+ // the release binaries off the test critical path, and lives outside
644
+ // dist/ so the wholesale-packaged dist/ tree can never ship it.
645
+ expect(targets['napi-debug']).toMatchObject({
646
+ executor: 'nx:run-commands',
647
+ cache: true,
648
+ dependsOn: ['^build', 'cargo-test-compile'],
649
+ outputs: ['{projectRoot}/.cache/native-debug'],
650
+ options: {
651
+ cwd: 'packages/cowshed',
652
+ command:
653
+ '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',
654
+ },
655
+ });
656
+ expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-cowshed-napi']);
657
+ // cargo-fetch survives the napi-debug re-route: the per-crate runner is
658
+ // itself a frozen cargo command, so its precondition is its own edge and
659
+ // not something it inherits from cargo-test-compile's position.
660
+ expect(targets['cargo-test-cowshed-napi']?.dependsOn).toEqual(['cargo-fetch', 'napi-debug']);
661
+ expect(targets['cargo-test-cowshed-napi']?.options?.command).toMatch(
662
+ /^cargo --frozen nextest run --workspace -E 'package\(cowshed-napi\)' --user-config-file none --config-file /,
663
+ );
483
664
  expect(targets['napi-test']).toMatchObject({
484
665
  executor: '@smoothbricks/nx-plugin:bounded-exec',
485
666
  cache: true,
486
- dependsOn: ['cargo-test', hostProvider, 'tsc-js', '^build', 'build'],
667
+ dependsOn: ['cargo-test', 'napi-debug', 'tsc-js', '^build'],
487
668
  options: {
488
669
  command: 'bun test --config=../bunfig.toml --timeout=30000 native.test.ts',
489
670
  cwd: 'packages/cowshed/src',
671
+ env: { NAPI_DEBUG_ADDON: '1' },
490
672
  timeoutMs: 120000,
491
673
  killAfterMs: 10000,
492
674
  },
@@ -529,17 +711,109 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
529
711
  // The declared target stays the only cargo-wasm: inference never emits a
530
712
  // duplicate for Nx to merge, even with a cdylib *-wasm member crate present.
531
713
  expect(targets['cargo-wasm']).toBeUndefined();
532
- // Its *-wasm output-family name feeds the aggregate build and clean.
533
- expect(buildOutputDependencies).toContain('*-wasm');
714
+ // Its declared *-wasm output-family name feeds the aggregate build and
715
+ // clean by concrete name, and the cargo workspace's test-executable
716
+ // compilation comes with it.
534
717
  expect(targets.build?.executor).toBe('nx:noop');
535
- expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
718
+ expect(targets.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'cargo-wasm']);
536
719
  expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
537
720
  } finally {
538
721
  await workspace.cleanup();
539
722
  }
540
723
  });
541
724
 
542
- it('lets explicit nx.targets suppress cargo inference and skips non-workspace Cargo.toml', async () => {
725
+ it('shards a crate around the tests nextest.toml singles out, not through them', async () => {
726
+ const workspace = await createWorkspace();
727
+ try {
728
+ await workspace.write('packages/rusty/package.json', '{"name":"rusty"}\n');
729
+ await workspace.write('packages/rusty/Cargo.toml', '[workspace]\nmembers = ["crates/big", "crates/small"]\n');
730
+ await workspace.write(
731
+ 'packages/rusty/crates/big/Cargo.toml',
732
+ '[package]\nname = "big"\n\n[package.metadata.smoothbricks.test]\nshards = 3\n',
733
+ );
734
+ await workspace.write('packages/rusty/crates/small/Cargo.toml', '[package]\nname = "small"\n');
735
+
736
+ const targets = await inferProjectTargets(workspace, 'packages/rusty/package.json');
737
+
738
+ // An unsharded crate keeps the bare name and takes no --partition, so
739
+ // declaring nothing is exactly the old single-target behaviour.
740
+ expect(targets['cargo-test-small']?.options?.command).toMatch(
741
+ /nextest run --workspace -E 'package\(small\)' --user-config-file none/,
742
+ );
743
+ // The shards partition the crate MINUS the classes nextest.toml singles
744
+ // out, i of N. Those are lifted out because a test-group only holds
745
+ // within one nextest run, and because a test carrying a raised
746
+ // slow-timeout costs what the suite does not — the compile-fail test
747
+ // rustc's a fixture for 25.6s on a cold target dir against 1.8s warm.
748
+ const exceptional = exceptionalTestFilter(fileURLToPath(new URL('../nextest.toml', import.meta.url)));
749
+ if (exceptional === null) {
750
+ throw new Error('nextest.toml declares no overrides; this test asserts the pin that protects them');
751
+ }
752
+ for (const index of [1, 2, 3]) {
753
+ expect(targets[`cargo-test-big-shard${index}`]?.options?.command).toContain(
754
+ `--workspace -E 'package(big) and not (${exceptional})' --partition hash:${index}/3`,
755
+ );
756
+ expect(targets[`cargo-test-big-shard${index}`]?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
757
+ }
758
+ // Exact complement of the shards' filterset, so the union is the crate.
759
+ expect(targets['cargo-test-big-exceptions']?.options?.command).toContain(
760
+ `--workspace -E 'package(big) and (${exceptional})' --no-tests=pass`,
761
+ );
762
+ expect(targets['cargo-test-big-exceptions']?.options?.command).not.toContain('--partition');
763
+ expect(targets['cargo-test-big-exceptions']?.options?.timeoutMs).toBe(BOUNDED_TEST_TIMEOUT_MS);
764
+ // An unsharded crate needs no pin: its whole suite is already one run.
765
+ expect(targets['cargo-test-small-exceptions']).toBeUndefined();
766
+ expect(targets['cargo-test-big']).toBeUndefined();
767
+ // Every piece reaches the aggregate, and they chain rather than fan out:
768
+ // cargo flocks one target/, and chaining also stops the pinned group
769
+ // contending with a shard over a machine-wide resource.
770
+ expect(targets['cargo-test']?.dependsOn).toEqual([
771
+ 'cargo-test-big-shard1',
772
+ 'cargo-test-big-shard2',
773
+ 'cargo-test-big-shard3',
774
+ 'cargo-test-big-exceptions',
775
+ 'cargo-test-small',
776
+ ]);
777
+ expect(targets['cargo-test-big-shard1']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-compile']);
778
+ expect(targets['cargo-test-big-shard2']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-big-shard1']);
779
+ expect(targets['cargo-test-big-shard3']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-big-shard2']);
780
+ expect(targets['cargo-test-big-exceptions']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-big-shard3']);
781
+ expect(targets['cargo-test-small']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-big-exceptions']);
782
+ // Pieces of one crate share its inputs: they are one suite, split only to
783
+ // fit the bound, so any change to the crate invalidates all of them.
784
+ expect(targets['cargo-test-big-shard2']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
785
+ expect(targets['cargo-test-big-exceptions']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
786
+ } finally {
787
+ await workspace.cleanup();
788
+ }
789
+ });
790
+
791
+ it('rejects a shard count that cannot describe a partition', async () => {
792
+ const workspace = await createWorkspace();
793
+ try {
794
+ await workspace.write('packages/rusty/package.json', '{"name":"rusty"}\n');
795
+ await workspace.write('packages/rusty/Cargo.toml', '[workspace]\nmembers = ["crates/big"]\n');
796
+ await workspace.write(
797
+ 'packages/rusty/crates/big/Cargo.toml',
798
+ '[package]\nname = "big"\n\n[package.metadata.smoothbricks.test]\nshards = 0\n',
799
+ );
800
+
801
+ // Nx wraps a createNodes throw in AggregateCreateNodesError, so the
802
+ // reason a maintainer needs is in the nested error, not the top message.
803
+ const failure = await inferProjectTargets(workspace, 'packages/rusty/package.json').then(
804
+ () => undefined,
805
+ (error: unknown) => error,
806
+ );
807
+ if (!(failure instanceof AggregateCreateNodesError)) {
808
+ throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
809
+ }
810
+ expect(failure.errors[0]?.[1]?.message).toMatch(/smoothbricks\.test\.shards must be an integer >= 1, got 0/);
811
+ } finally {
812
+ await workspace.cleanup();
813
+ }
814
+ });
815
+
816
+ it('lets explicit nx.targets suppress output and aggregate inference, and skips non-workspace Cargo.toml', async () => {
543
817
  const workspace = await createWorkspace();
544
818
  try {
545
819
  await workspace.write(
@@ -566,6 +840,107 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
566
840
  await workspace.cleanup();
567
841
  }
568
842
  });
843
+
844
+ it('keeps inferring a cargo target the package partially declares', async () => {
845
+ const workspace = await createWorkspace();
846
+ const declared: Record<string, TargetConfiguration> = {
847
+ // One added edge per target. Everything that makes each target do its job
848
+ // — executor, options, inputs, cache, configurations — must survive the
849
+ // declaration instead of being replaced wholesale by it.
850
+ 'cargo-test': { dependsOn: ['cargo-test-compile', 'cargo-wasm'] },
851
+ 'cargo-test-compile': { dependsOn: ['cargo-wasm'] },
852
+ 'cargo-lint': { inputs: ['{projectRoot}/clippy.toml'] },
853
+ mutation: { options: { command: 'cargo mutants --in-diff' } },
854
+ bench: { cache: true },
855
+ };
856
+ try {
857
+ await workspace.write(
858
+ 'packages/ferris/package.json',
859
+ JSON.stringify({ name: 'ferris', nx: { targets: declared } }),
860
+ );
861
+ await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = []\n');
862
+
863
+ const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
864
+
865
+ // Inference must still emit the base. Without one Nx has nothing to merge
866
+ // the declaration onto and normalizes a bare `dependsOn` to `nx:noop` with
867
+ // empty options — a cargo-test that passes having run no test binary.
868
+ expect(targets['cargo-test']?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
869
+ expect(targets['cargo-test-compile']?.executor).toBe('nx:run-commands');
870
+ expect(targets['cargo-lint']?.options).toMatchObject({
871
+ commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
872
+ });
873
+
874
+ const cargoTest = resolveDeclaredOverInferred(targets, declared, 'cargo-test');
875
+ expect(cargoTest?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
876
+ expect(cargoTest?.cache).toBe(true);
877
+ expect(cargoTest?.dependsOn).toEqual(['cargo-test-compile', 'cargo-wasm']);
878
+ expect(cargoTest?.options).toEqual({
879
+ command: 'cargo --frozen test --workspace',
880
+ cwd: 'packages/ferris',
881
+ timeoutMs: 120000,
882
+ killAfterMs: 10000,
883
+ });
884
+ expect(cargoTest?.configurations).toEqual({
885
+ production: { command: 'cargo --frozen test --workspace --release' },
886
+ });
887
+ expect(cargoTest?.inputs).toContain('{projectRoot}/**/*.rs');
888
+
889
+ const cargoTestCompile = resolveDeclaredOverInferred(targets, declared, 'cargo-test-compile');
890
+ expect(cargoTestCompile?.executor).toBe('nx:run-commands');
891
+ // A replacing array drops every inferred edge, cargo-fetch included: the
892
+ // package now owns ordering the locked fetch ahead of its frozen compile.
893
+ expect(cargoTestCompile?.dependsOn).toEqual(['cargo-wasm']);
894
+ expect(targets['cargo-test-compile']?.dependsOn).toEqual(['cargo-fetch']);
895
+ expect(cargoTestCompile?.options).toMatchObject({
896
+ command: 'cargo --frozen test --workspace --no-run',
897
+ });
898
+
899
+ // A declared array replaces the inferred one; the command it guards stays.
900
+ const cargoLint = resolveDeclaredOverInferred(targets, declared, 'cargo-lint');
901
+ expect(cargoLint?.inputs).toEqual(['{projectRoot}/clippy.toml']);
902
+ expect(cargoLint?.options).toMatchObject({
903
+ commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
904
+ });
905
+
906
+ // `options` merges key by key, so a declared command overrides only itself.
907
+ const mutation = resolveDeclaredOverInferred(targets, declared, 'mutation');
908
+ expect(mutation?.options).toEqual({ command: 'cargo mutants --in-diff', cwd: 'packages/ferris' });
909
+ expect(mutation?.cache).toBe(false);
910
+
911
+ const bench = resolveDeclaredOverInferred(targets, declared, 'bench');
912
+ expect(bench?.cache).toBe(true);
913
+ expect(bench?.options).toMatchObject({ command: 'cargo --frozen bench --workspace' });
914
+ } finally {
915
+ await workspace.cleanup();
916
+ }
917
+ });
918
+
919
+ it('lets a declared dependsOn spread expand the inferred cargo chain', async () => {
920
+ const workspace = await createWorkspace();
921
+ // Additive intent has Nx's own spelling: `'...'` expands the inferred list
922
+ // at the token, so an added edge keeps the cargo serialization chain.
923
+ const declared: Record<string, TargetConfiguration> = {
924
+ 'cargo-test': { dependsOn: ['...', 'cargo-wasm'] },
925
+ };
926
+ try {
927
+ await workspace.write(
928
+ 'packages/ferris/package.json',
929
+ JSON.stringify({ name: 'ferris', nx: { targets: declared } }),
930
+ );
931
+ await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = []\n');
932
+
933
+ const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
934
+
935
+ // The spread expands exactly once, against the single inferred base this
936
+ // plugin emits — re-implementing the overlay here would double it.
937
+ const cargoTest = resolveDeclaredOverInferred(targets, declared, 'cargo-test');
938
+ expect(cargoTest?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-compile', 'cargo-wasm']);
939
+ expect(cargoTest?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
940
+ } finally {
941
+ await workspace.cleanup();
942
+ }
943
+ });
569
944
  //#endregion
570
945
  });
571
946
 
@@ -594,14 +969,71 @@ interface WorkspaceFixture {
594
969
  cleanup(): Promise<void>;
595
970
  }
596
971
 
597
- async function inferProject(workspace: WorkspaceFixture, packageJsonPath: string) {
598
- const result = await inferTargets([packageJsonPath], undefined, workspace.context);
972
+ async function inferProject(
973
+ workspace: WorkspaceFixture,
974
+ packageJsonPath: string,
975
+ createNodes: CreateNodesV2 = createNodesV2,
976
+ ) {
977
+ const [, infer] = createNodes;
978
+ const result = await infer([packageJsonPath], undefined, workspace.context);
599
979
  return result[0]?.[1].projects?.[dirname(packageJsonPath)];
600
980
  }
601
981
 
602
982
  async function inferProjectTargets(
603
983
  workspace: WorkspaceFixture,
604
984
  packageJsonPath: string,
985
+ createNodes?: CreateNodesV2,
605
986
  ): Promise<Record<string, TargetConfiguration>> {
606
- return (await inferProject(workspace, packageJsonPath))?.targets ?? {};
987
+ return (await inferProject(workspace, packageJsonPath, createNodes))?.targets ?? {};
988
+ }
989
+
990
+ /**
991
+ * The configuration Nx resolves for a target this plugin infers and the package
992
+ * also declares. Nx merges a package-local `nx.targets` entry over an inference
993
+ * plugin's target one layer later — the precedence order is specified plugins →
994
+ * target defaults → default plugins, and the package.json reader is a default
995
+ * plugin — so composing with the same merge function the graph uses makes these
996
+ * assertions the resolved configuration rather than a guess about it.
997
+ */
998
+ function resolveDeclaredOverInferred(
999
+ targets: Record<string, TargetConfiguration>,
1000
+ declared: Record<string, TargetConfiguration>,
1001
+ name: string,
1002
+ ): TargetConfiguration | undefined {
1003
+ const inferred = targets[name];
1004
+ return inferred && mergeTargetConfigurations(declared[name] ?? {}, inferred);
1005
+ }
1006
+
1007
+ /**
1008
+ * How a cargo test command is scoped to one crate, split into the three facts
1009
+ * that can independently go wrong.
1010
+ *
1011
+ * `--workspace` must be present: it makes the build fingerprint-identical to
1012
+ * `cargo-test-compile`'s, so the bounded run reuses those artifacts. Narrowing
1013
+ * must come from the nextest filterset, which selects what RUNS without
1014
+ * changing what is BUILT. `--package` narrows too, but it re-resolves that
1015
+ * crate's features, diverges from the workspace build, and rebuilds inside the
1016
+ * bounded window — 57.9s of a 120s budget on a hosted 3-core macOS runner — so
1017
+ * its presence is a regression even though it selects the same tests.
1018
+ */
1019
+ function cargoPackageSelection(command: string): {
1020
+ workspaceBuild: boolean;
1021
+ packageFlags: string[];
1022
+ filtered: string[];
1023
+ } {
1024
+ const tokens = command.split(/\s+/);
1025
+ const packageFlags: string[] = [];
1026
+ for (let i = 0; i < tokens.length; i++) {
1027
+ if (tokens[i] === '--package' || tokens[i] === '-p') {
1028
+ const name = tokens[i + 1];
1029
+ if (name !== undefined && name.length > 0) {
1030
+ packageFlags.push(name);
1031
+ }
1032
+ }
1033
+ }
1034
+ return {
1035
+ workspaceBuild: tokens.includes('--workspace'),
1036
+ packageFlags,
1037
+ filtered: [...command.matchAll(/\bpackage\(([^)]+)\)/g)].map((match) => match[1] as string),
1038
+ };
607
1039
  }