@smoothbricks/nx-plugin 0.5.7 → 0.6.1
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 +1097 -360
- package/dist/.build-inputs.json +141 -0
- package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
- package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
- package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
- package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
- package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
- package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
- package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
- package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
- package/dist/bin/smoo-nx-nextest-timings.js +28 -0
- package/dist/bounded-test-policy.d.ts +1 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +14 -15
- package/dist/build-state-output-policy.d.ts +95 -1
- package/dist/build-state-output-policy.d.ts.map +1 -1
- package/dist/build-state-output-policy.js +368 -30
- package/dist/bun-lock-scope.d.ts +44 -0
- package/dist/bun-lock-scope.d.ts.map +1 -0
- package/dist/bun-lock-scope.js +97 -0
- package/dist/cargo-build-script-env.d.ts +49 -0
- package/dist/cargo-build-script-env.d.ts.map +1 -0
- package/dist/cargo-build-script-env.js +324 -0
- package/dist/cargo-closure-input.d.ts +31 -4
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +66 -6
- package/dist/cargo-retention-hook.d.ts +17 -0
- package/dist/cargo-retention-hook.d.ts.map +1 -0
- package/dist/cargo-retention-hook.js +85 -0
- package/dist/cargo-source-hash.d.ts +25 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +108 -43
- package/dist/cargo-toolchain-paths.d.ts +40 -0
- package/dist/cargo-toolchain-paths.d.ts.map +1 -0
- package/dist/cargo-toolchain-paths.js +84 -0
- package/dist/cargo-toolchain-policy.d.ts +25 -8
- package/dist/cargo-toolchain-policy.d.ts.map +1 -1
- package/dist/cargo-toolchain-policy.js +39 -5
- package/dist/cargo-workspace.d.ts +10 -4
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +65 -95
- package/dist/cross-check-policy.d.ts +9 -9
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +11 -11
- package/dist/disk-command-policy.d.ts.map +1 -1
- package/dist/disk-command-policy.js +1 -0
- package/dist/ensure-built-receipt.d.ts +22 -5
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +168 -48
- package/dist/ensure-built-witness.d.ts +27 -8
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +45 -15
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +9 -1
- package/dist/eslint-config-closure.d.ts +7 -0
- package/dist/eslint-config-closure.d.ts.map +1 -0
- package/dist/eslint-config-closure.js +346 -0
- package/dist/executors/bounded-exec/bounds.d.ts +56 -0
- package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
- package/dist/executors/bounded-exec/bounds.js +43 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +28 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.js +20 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +35 -38
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +56 -120
- package/dist/executors/bounded-exec/executor.d.ts +19 -12
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +389 -239
- package/dist/executors/bounded-exec/gateway-lease.d.ts +23 -19
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
- package/dist/executors/bounded-exec/gateway-lease.js +102 -29
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
- package/dist/executors/bounded-exec/lease-wait.d.ts +64 -0
- package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
- package/dist/executors/bounded-exec/lease-wait.js +72 -0
- package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
- package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
- package/dist/executors/bounded-exec/lock-wait.js +108 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts +31 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/mbx-pool.js +24 -0
- package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
- package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
- package/dist/executors/bounded-exec/owned-subtree.js +178 -0
- package/dist/executors/bounded-exec/progress.d.ts +4 -1
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/progress.js +5 -2
- package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
- package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-attach.js +207 -0
- package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
- package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-detach.js +207 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +1213 -399
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts +10 -4
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +122 -35
- package/dist/executors/bounded-exec/runner-hook.js +14 -5
- package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
- package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
- package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
- package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
- package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
- package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
- package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
- package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
- package/dist/executors/bounded-exec/runtime-pin.js +167 -0
- package/dist/executors/bounded-exec/schema.d.ts +18 -1
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.d.ts +48 -11
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +89 -20
- package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
- package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
- package/dist/executors/cargo-zigbuild/executor.js +67 -12
- package/dist/executors/clean-outputs/executor.js +1 -0
- package/dist/executors/scriptc-native/executor.d.ts +79 -0
- package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
- package/dist/executors/scriptc-native/executor.js +367 -0
- package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
- package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
- package/dist/executors/scriptc-native/ffi-paths.js +25 -0
- package/dist/executors/scriptc-native/schema.d.ts +34 -0
- package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
- package/dist/executors/scriptc-native/schema.js +1 -0
- package/dist/executors/typescript-emit/emit-overrides.d.ts +14 -0
- package/dist/executors/typescript-emit/emit-overrides.d.ts.map +1 -0
- package/dist/executors/typescript-emit/emit-overrides.js +24 -0
- package/dist/executors/typescript-emit/executor.d.ts +3 -1
- package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
- package/dist/executors/typescript-emit/executor.js +146 -33
- package/dist/forbidden-spelling-policy.d.ts +56 -0
- package/dist/forbidden-spelling-policy.d.ts.map +1 -0
- package/dist/forbidden-spelling-policy.js +176 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +3 -4
- package/dist/graph-input-contract.d.ts +14 -0
- package/dist/graph-input-contract.d.ts.map +1 -1
- package/dist/graph-input-contract.js +67 -2
- package/dist/index.d.ts +23 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +672 -214
- package/dist/managed-assets.d.ts +2 -0
- package/dist/managed-assets.d.ts.map +1 -1
- package/dist/managed-files/files.d.ts +3 -3
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +28 -3
- package/dist/managed-files/managed-format.d.ts.map +1 -1
- package/dist/managed-files/managed-format.js +1 -0
- package/dist/managed-files/publish-workflow.js +14 -11
- package/dist/nextest-code-bound.js +1 -0
- package/dist/nextest-timings.d.ts +35 -0
- package/dist/nextest-timings.d.ts.map +1 -0
- package/dist/nextest-timings.js +168 -0
- package/dist/owned-installation.d.ts +6 -5
- package/dist/owned-installation.d.ts.map +1 -1
- package/dist/owned-installation.js +150 -26
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +2 -3
- package/dist/process-children.d.ts +7 -0
- package/dist/process-children.d.ts.map +1 -0
- package/dist/process-children.darwin.d.ts +7 -0
- package/dist/process-children.darwin.d.ts.map +1 -0
- package/dist/process-children.darwin.js +13 -0
- package/dist/process-children.js +14 -0
- package/dist/process-children.linux.d.ts +8 -0
- package/dist/process-children.linux.d.ts.map +1 -0
- package/dist/process-children.linux.js +25 -0
- package/dist/process-group.d.ts +108 -0
- package/dist/process-group.d.ts.map +1 -0
- package/dist/process-group.js +171 -0
- package/dist/process-listing.d.ts +7 -0
- package/dist/process-listing.d.ts.map +1 -0
- package/dist/process-listing.js +51 -0
- package/dist/producer-receipts.d.ts +8 -2
- package/dist/producer-receipts.d.ts.map +1 -1
- package/dist/producer-receipts.js +514 -47
- package/dist/task-graph-policy.d.ts +21 -0
- package/dist/task-graph-policy.d.ts.map +1 -0
- package/dist/task-graph-policy.js +91 -0
- package/dist/test-timings.js +4 -4
- package/dist/test-walk-policy.d.ts +14 -5
- package/dist/test-walk-policy.d.ts.map +1 -1
- package/dist/test-walk-policy.js +8 -2
- package/dist/testing.d.ts +73 -28
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +217 -223
- package/dist/tool-bins.d.ts +33 -0
- package/dist/tool-bins.d.ts.map +1 -0
- package/dist/tool-bins.js +72 -0
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +3 -4
- package/dist/wait-why-policy.d.ts +28 -0
- package/dist/wait-why-policy.d.ts.map +1 -0
- package/dist/wait-why-policy.js +223 -0
- package/dist/workspace-config-policy.d.ts +14 -8
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +60 -16
- package/dist/workspace-manifest.d.ts +41 -6
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/dist/workspace-manifest.js +57 -0
- package/executors.json +16 -1
- package/loader.js +2 -0
- package/managed/raw/envrc +11 -0
- package/managed/raw/patches/nx@23.2.1.patch +2840 -199
- package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
- package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
- package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
- package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
- package/managed/raw/tooling/direnv/developer-links.ts +464 -25
- package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
- package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
- package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
- package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
- package/managed/raw/tooling/direnv/repo-path +68 -6
- package/managed/raw/tooling/direnv/secret-references.ts +13 -4
- package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
- package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
- package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
- package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
- package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
- package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
- package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
- package/package.json +95 -14
- package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
- package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
- package/src/bin/smoo-nx-nextest-timings.ts +31 -0
- package/src/bounded-test-policy.ts +12 -14
- package/src/build-state-output-policy.ts +458 -34
- package/src/bun-lock-scope.ts +108 -0
- package/src/cargo-build-script-env.ts +265 -0
- package/src/cargo-closure-input.ts +74 -7
- package/src/cargo-retention-hook.ts +94 -0
- package/src/cargo-source-hash.ts +138 -41
- package/src/cargo-toolchain-paths.ts +95 -0
- package/src/cargo-toolchain-policy.ts +49 -5
- package/src/cargo-workspace.ts +72 -123
- package/src/cross-check-policy.ts +12 -10
- package/src/disk-command-policy.ts +1 -0
- package/src/ensure-built-receipt.ts +173 -39
- package/src/ensure-built-witness.ts +62 -10
- package/src/ensure-built.ts +11 -1
- package/src/eslint-config-closure.ts +357 -0
- package/src/executors/bounded-exec/bounds.ts +76 -0
- package/src/executors/bounded-exec/cpu-pool-thread.ts +43 -0
- package/src/executors/bounded-exec/cpu-pool.ts +55 -120
- package/src/executors/bounded-exec/executor.ts +442 -260
- package/src/executors/bounded-exec/gateway-lease.ts +94 -35
- package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
- package/src/executors/bounded-exec/lease-wait.ts +116 -0
- package/src/executors/bounded-exec/lock-wait.ts +141 -0
- package/src/executors/bounded-exec/mbx-pool.ts +48 -0
- package/src/executors/bounded-exec/owned-subtree.ts +235 -0
- package/src/executors/bounded-exec/progress.ts +9 -3
- package/src/executors/bounded-exec/ram-attach.ts +238 -0
- package/src/executors/bounded-exec/ram-detach.ts +226 -0
- package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
- package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
- package/src/executors/bounded-exec/ram-temp.ts +1497 -460
- package/src/executors/bounded-exec/run-cpu-pool.ts +129 -35
- package/src/executors/bounded-exec/runner-hook.ts +14 -6
- package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
- package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
- package/src/executors/bounded-exec/runtime-pin.ts +232 -0
- package/src/executors/bounded-exec/schema.json +11 -2
- package/src/executors/bounded-exec/schema.ts +19 -1
- package/src/executors/bounded-exec/verdict.ts +145 -35
- package/src/executors/cargo-zigbuild/executor.ts +82 -8
- package/src/executors/clean-outputs/executor.ts +1 -0
- package/src/executors/scriptc-native/executor.ts +394 -0
- package/src/executors/scriptc-native/ffi-paths.ts +29 -0
- package/src/executors/scriptc-native/schema.json +60 -0
- package/src/executors/scriptc-native/schema.ts +34 -0
- package/src/executors/typescript-emit/emit-overrides.ts +24 -0
- package/src/executors/typescript-emit/executor.ts +186 -38
- package/src/forbidden-spelling-policy.ts +226 -0
- package/src/generators/create-package/generator.ts +7 -7
- package/src/graph-input-contract.ts +61 -2
- package/src/index.ts +788 -224
- package/src/managed-assets.ts +3 -0
- package/src/managed-files/files.ts +28 -3
- package/src/managed-files/managed-format.ts +1 -0
- package/src/managed-files/publish-workflow.ts +20 -15
- package/src/nextest-code-bound.ts +1 -0
- package/src/nextest-timings.ts +106 -0
- package/src/owned-installation.ts +150 -23
- package/src/package-target-policy.ts +2 -3
- package/src/process-children.darwin.ts +14 -0
- package/src/process-children.linux.ts +33 -0
- package/src/process-children.ts +22 -0
- package/src/process-group.ts +209 -0
- package/src/process-listing.ts +54 -0
- package/src/producer-receipts.ts +92 -41
- package/src/task-graph-policy.ts +98 -0
- package/src/test-walk-policy.ts +23 -8
- package/src/testing.ts +240 -232
- package/src/tool-bins.ts +108 -0
- package/src/typecheck-test-policy.ts +2 -3
- package/src/wait-why-policy.ts +226 -0
- package/src/workspace-config-policy.ts +63 -15
- package/src/workspace-manifest.ts +89 -6
- package/test-timings.json +124 -99
- package/dist/bin/smoo-nx-failures.d.ts +0 -3
- package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
- package/dist/bin/smoo-nx-failures.js +0 -3
- package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
- package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
- package/dist/bin/smoo-nx-nextest-extract.js +0 -42
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
- package/dist/failure-summary.d.ts +0 -5
- package/dist/failure-summary.d.ts.map +0 -1
- package/dist/failure-summary.js +0 -118
- package/dist/nextest-extraction.d.ts +0 -117
- package/dist/nextest-extraction.d.ts.map +0 -1
- package/dist/nextest-extraction.js +0 -303
- package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
- package/src/__tests__/cargo-closure-filesets.ts +0 -94
- package/src/__tests__/cargo-closure-fixture.ts +0 -113
- package/src/__tests__/counted-cargo-process.ts +0 -286
- package/src/__tests__/counted-cargo.ts +0 -713
- package/src/__tests__/directory-change.ts +0 -27
- package/src/__tests__/fixture-cargo-home.ts +0 -36
- package/src/__tests__/fixture-nx-env.ts +0 -193
- package/src/__tests__/owned-installation.ts +0 -13
- package/src/__tests__/past-tick.ts +0 -12
- package/src/__tests__/progress-clock.ts +0 -43
- package/src/__tests__/runtime-input.ts +0 -23
- package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
- package/src/bin/smoo-nx-failures.ts +0 -4
- package/src/bin/smoo-nx-nextest-extract.ts +0 -44
- package/src/bounded-test-policy.test.ts +0 -1029
- package/src/build-state-output-policy.test.ts +0 -115
- package/src/bun-bootstrap.test.ts +0 -102
- package/src/bun-file-packages.test.ts +0 -47
- package/src/cargo-closure-filesets.test.ts +0 -63
- package/src/cargo-closure-input.property.test.ts +0 -50
- package/src/cargo-closure-input.test.ts +0 -506
- package/src/cargo-closure-key.test.ts +0 -240
- package/src/cargo-resolve-cache.test.ts +0 -1181
- package/src/cargo-source-hash.test.ts +0 -707
- package/src/cargo-workspace.test.ts +0 -615
- package/src/cross-check-policy.test.ts +0 -316
- package/src/disk-command-policy.test.ts +0 -61
- package/src/ensure-built-receipt.test.ts +0 -279
- package/src/ensure-built-witness.test.ts +0 -688
- package/src/ensure-built.test.ts +0 -1462
- package/src/executors/all-verdicts/executor.test.ts +0 -135
- package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
- package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
- package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
- package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
- package/src/executors/bounded-exec/executor-host.test.ts +0 -800
- package/src/executors/bounded-exec/executor.test.ts +0 -1819
- package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
- package/src/executors/bounded-exec/progress.test.ts +0 -139
- package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
- package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
- package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
- package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
- package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
- package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
- package/src/executors/bounded-exec/verdict.test.ts +0 -545
- package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
- package/src/executors/clean-outputs/executor.test.ts +0 -20
- package/src/executors/typescript-emit/executor.test.ts +0 -83
- package/src/failure-summary.ts +0 -119
- package/src/generators/bounded-test-targets/generator.test.ts +0 -138
- package/src/generators/bun-test-tracing/generator.test.ts +0 -250
- package/src/generators/create-package/generator.test.ts +0 -190
- package/src/generators/make-public/generator.test.ts +0 -137
- package/src/graph-input-contract.test.ts +0 -379
- package/src/host-controller-wiring.test.ts +0 -31
- package/src/index.test.ts +0 -3321
- package/src/linked-snapshots.nx.test.ts +0 -254
- package/src/managed-files/forgejo-artifact.test.ts +0 -395
- package/src/managed-files/generator.test.ts +0 -243
- package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
- package/src/managed-files/json-edit.test.ts +0 -216
- package/src/managed-files/managed-content.test.ts +0 -166
- package/src/managed-files/managed-format-json.test.ts +0 -308
- package/src/managed-files/repo-path.test.ts +0 -172
- package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
- package/src/managed-files/trace-db-artifact.test.ts +0 -7
- package/src/managed-files/tree-permissions.test.ts +0 -109
- package/src/managed-files/tree.test.ts +0 -123
- package/src/manifest-hash.test.ts +0 -219
- package/src/nextest-code-bound.test.ts +0 -161
- package/src/nextest-extraction.test.ts +0 -216
- package/src/nextest-extraction.ts +0 -371
- package/src/nextest-partitions.test.ts +0 -501
- package/src/nx-cache-bound.test.ts +0 -109
- package/src/nx-cache-restore-mtime.test.ts +0 -170
- package/src/nx-daemon-claim.test.ts +0 -279
- package/src/nx-daemon-idle-cpu.test.ts +0 -80
- package/src/nx-daemon-idle-policy.test.ts +0 -111
- package/src/nx-daemon-ignore-files.test.ts +0 -210
- package/src/nx-daemon-root-normalization.test.ts +0 -105
- package/src/nx-daemon-start-never.test.ts +0 -292
- package/src/nx-daemon-validity.test.ts +0 -1055
- package/src/nx-dot-input-policy.test.ts +0 -353
- package/src/nx-failure-life-cycles.test.ts +0 -207
- package/src/nx-files-archive-racy.test.ts +0 -97
- package/src/nx-foreign-workspace-env.test.ts +0 -329
- package/src/nx-incomplete-run-summary.test.ts +0 -70
- package/src/nx-plugin-load-errors.test.ts +0 -120
- package/src/nx-project-graph-errors.test.ts +0 -70
- package/src/nx-project-resolution-cache.test.ts +0 -176
- package/src/nx-raw-inputs.test.ts +0 -166
- package/src/nx-resident-graph-workers.test.ts +0 -112
- package/src/nx-run-information.test.ts +0 -118
- package/src/nx-skipped-task-exit.test.ts +0 -180
- package/src/nx-state-location.test.ts +0 -63
- package/src/nx-store-resolution.test.ts +0 -81
- package/src/nx-task-graph-cycles.test.ts +0 -148
- package/src/nx-task-output-lease.test.ts +0 -550
- package/src/nx-use-local.test.ts +0 -105
- package/src/owned-installation.test.ts +0 -105
- package/src/package-target-policy.test.ts +0 -1014
- package/src/producer-receipts.test.ts +0 -285
- package/src/release-config-policy.test.ts +0 -311
- package/src/runtime-input.test.ts +0 -393
- package/src/serial-group-wiring.test.ts +0 -326
- package/src/task-history-namespace.test.ts +0 -181
- package/src/task-results.test.ts +0 -228
- package/src/test-clock-policy.test.ts +0 -338
- package/src/test-program.test.ts +0 -303
- package/src/test-timings.test.ts +0 -240
- package/src/test-walk-policy.test.ts +0 -620
- package/src/testing.test.ts +0 -509
- package/src/typecheck-test-policy.test.ts +0 -1468
- package/src/typescript-resolution.test.ts +0 -76
- package/src/version-actions.test.ts +0 -80
- package/src/workspace-config-policy.test.ts +0 -737
package/src/index.test.ts
DELETED
|
@@ -1,3321 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import { chmod, mkdir, mkdtemp, readdir, readFile, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { isEslintFileSet } from '@smoothbricks/nx-plugin/eslint-file-set';
|
|
7
|
-
import type {
|
|
8
|
-
CreateNodesContextV2,
|
|
9
|
-
CreateNodesV2,
|
|
10
|
-
ProjectGraph,
|
|
11
|
-
ProjectGraphProjectNode,
|
|
12
|
-
TargetConfiguration,
|
|
13
|
-
} from 'nx/src/devkit-exports.js';
|
|
14
|
-
import { WorkspaceContext } from 'nx/src/native/index.js';
|
|
15
|
-
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
16
|
-
import { createTargetDefaultsResults } from 'nx/src/project-graph/utils/project-configuration/target-defaults.js';
|
|
17
|
-
import { mergeTargetConfigurations } from 'nx/src/project-graph/utils/project-configuration-utils.js';
|
|
18
|
-
import { createTaskGraph } from 'nx/src/tasks-runner/create-task-graph.js';
|
|
19
|
-
import { getOutputsForTargetAndConfiguration } from 'nx/src/tasks-runner/utils.js';
|
|
20
|
-
import { resetWorkspaceContext } from 'nx/src/utils/workspace-context.js';
|
|
21
|
-
import { useFixtureCargoHome } from './__tests__/fixture-cargo-home.js';
|
|
22
|
-
import { runtimeInputValue } from './__tests__/runtime-input.js';
|
|
23
|
-
import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './bounded-test-policy.js';
|
|
24
|
-
import { CARGO_CLOSURE_INPUT } from './cargo-closure-input.js';
|
|
25
|
-
import { exceptionalTestFilter, packageNameFromCargoTestTarget } from './cargo-workspace.js';
|
|
26
|
-
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_LINT_CLIPPY_COMMAND } from './cross-check-policy.js';
|
|
27
|
-
import { ALL_VERDICTS_EXECUTOR } from './executors/all-verdicts/schema.js';
|
|
28
|
-
import { cargoCommandNpmPackages, createNodesV2, createNodesV2ForPlatform } from './index.js';
|
|
29
|
-
import { NEXTEST_EXTRACTION_DIRECTORY } from './nextest-extraction.js';
|
|
30
|
-
import { applyWorkspaceConfig, RELEASE_CONFIGURATION } from './workspace-config-policy.js';
|
|
31
|
-
|
|
32
|
-
useFixtureCargoHome();
|
|
33
|
-
|
|
34
|
-
const [, rawInferTargets] = createNodesV2;
|
|
35
|
-
const inferTargets: typeof rawInferTargets = async (files, options, context) => {
|
|
36
|
-
await prepareCargoFixture(context.workspaceRoot);
|
|
37
|
-
return rawInferTargets(files, options, context);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
41
|
-
it('never lets a cache hit on the build aggregate restore its children’s dist', async () => {
|
|
42
|
-
const workspace = await createWorkspace();
|
|
43
|
-
// The emitter keys on one input outside its project, as a transform or toolchain does. The
|
|
44
|
-
// aggregate hashes only the project, so a toolchain change moves the emitter's key and not the
|
|
45
|
-
// aggregate's: the aggregate replays from cache right after the emitter reran.
|
|
46
|
-
const emit: TargetConfiguration = {
|
|
47
|
-
executor: 'nx:run-commands',
|
|
48
|
-
cache: true,
|
|
49
|
-
inputs: ['{projectRoot}/source.txt', '{workspaceRoot}/toolchain.txt'],
|
|
50
|
-
outputs: ['{projectRoot}/dist'],
|
|
51
|
-
options: { command: 'mkdir -p dist && cat source.txt ../../toolchain.txt > dist/app.js', cwd: '{projectRoot}' },
|
|
52
|
-
};
|
|
53
|
-
const declared = { 'emit-js': emit };
|
|
54
|
-
try {
|
|
55
|
-
await workspace.write(
|
|
56
|
-
'packages/app/package.json',
|
|
57
|
-
JSON.stringify({ name: 'app', private: true, nx: { targets: declared } }),
|
|
58
|
-
);
|
|
59
|
-
const targets = await inferProjectTargets(workspace, 'packages/app/package.json');
|
|
60
|
-
const build = resolveDeclaredOverInferred(targets, declared, 'build');
|
|
61
|
-
expect(build?.dependsOn).toContain('emit-js');
|
|
62
|
-
expect(build?.cache).toBe(true);
|
|
63
|
-
if (build === undefined) throw new Error('app infers no build aggregate over emit-js');
|
|
64
|
-
|
|
65
|
-
// A replay restores exactly what Nx resolves as the task's outputs. Left without `outputs`, a
|
|
66
|
-
// `build` target gets Nx's legacy defaults, `{projectRoot}/dist` among them, and the replay
|
|
67
|
-
// puts back the dist the emitter wrote on the run that last produced the aggregate's key.
|
|
68
|
-
const app: ProjectGraphProjectNode = {
|
|
69
|
-
name: 'app',
|
|
70
|
-
type: 'lib',
|
|
71
|
-
data: { root: 'packages/app', targets: { build, 'emit-js': emit } },
|
|
72
|
-
};
|
|
73
|
-
expect(getOutputsForTargetAndConfiguration({ project: 'app', target: 'build' }, {}, app)).toEqual([]);
|
|
74
|
-
expect(getOutputsForTargetAndConfiguration({ project: 'app', target: 'emit-js' }, {}, app)).toEqual([
|
|
75
|
-
'packages/app/dist',
|
|
76
|
-
]);
|
|
77
|
-
} finally {
|
|
78
|
-
await workspace.cleanup();
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('names standalone package projects from package metadata', async () => {
|
|
83
|
-
const workspace = await createWorkspace();
|
|
84
|
-
try {
|
|
85
|
-
await workspace.write(
|
|
86
|
-
'specs/prototype/package.json',
|
|
87
|
-
'{"name":"standalone-package","nx":{"name":"standalone-project"}}\n',
|
|
88
|
-
);
|
|
89
|
-
await workspace.write('specs/package-fallback/package.json', '{"name":"package-fallback"}\n');
|
|
90
|
-
|
|
91
|
-
const explicit = await inferProject(workspace, 'specs/prototype/package.json');
|
|
92
|
-
const fallback = await inferProject(workspace, 'specs/package-fallback/package.json');
|
|
93
|
-
|
|
94
|
-
expect(explicit?.name).toBe('standalone-project');
|
|
95
|
-
expect(explicit?.targets).toEqual({});
|
|
96
|
-
expect(fallback?.name).toBe('package-fallback');
|
|
97
|
-
expect(fallback?.targets).toEqual({});
|
|
98
|
-
} finally {
|
|
99
|
-
await workspace.cleanup();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('skips smoo managed raw package.json sources as projects', async () => {
|
|
104
|
-
const workspace = await createWorkspace();
|
|
105
|
-
try {
|
|
106
|
-
await workspace.write(
|
|
107
|
-
'packages/nx-plugin/managed/raw/tooling/typescript-api/package.json',
|
|
108
|
-
'{"name":"@smoothbricks/typescript-api","private":true}\n',
|
|
109
|
-
);
|
|
110
|
-
await workspace.write(
|
|
111
|
-
'tooling/typescript-api/package.json',
|
|
112
|
-
'{"name":"@smoothbricks/typescript-api","private":true}\n',
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const managed = await inferTargets(
|
|
116
|
-
['packages/nx-plugin/managed/raw/tooling/typescript-api/package.json'],
|
|
117
|
-
undefined,
|
|
118
|
-
workspace.context,
|
|
119
|
-
);
|
|
120
|
-
expect(managed[0]?.[1]).toEqual({});
|
|
121
|
-
|
|
122
|
-
const live = await inferProject(workspace, 'tooling/typescript-api/package.json');
|
|
123
|
-
expect(live?.name).toBe('@smoothbricks/typescript-api');
|
|
124
|
-
} finally {
|
|
125
|
-
await workspace.cleanup();
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('never infers a project from a package.json a build wrote', async () => {
|
|
130
|
-
const workspace = await createWorkspace();
|
|
131
|
-
try {
|
|
132
|
-
await workspace.write('packages/cowshed/package.json', '{"name":"cowshed","private":true}\n');
|
|
133
|
-
// napi's platform build, a dist tree, cargo's target dir, a package cache: every
|
|
134
|
-
// one of these is written by a task, and a graph recomputed while it is being
|
|
135
|
-
// written must not see a second `cowshed` and drop the real one.
|
|
136
|
-
const outputs = [
|
|
137
|
-
'packages/cowshed/.cache/native-debug/package.json',
|
|
138
|
-
'packages/cowshed/dist/npm/linux-x64-gnu/package.json',
|
|
139
|
-
'packages/cowshed/target/debug/build/x/out/package.json',
|
|
140
|
-
'packages/cowshed/node_modules/dep/package.json',
|
|
141
|
-
];
|
|
142
|
-
for (const path of outputs) {
|
|
143
|
-
await workspace.write(path, '{"name":"cowshed","private":true}\n');
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const inferred = await inferTargets(outputs, undefined, workspace.context);
|
|
147
|
-
for (const [, result] of inferred) {
|
|
148
|
-
expect(result).toEqual({});
|
|
149
|
-
}
|
|
150
|
-
const live = await inferProject(workspace, 'packages/cowshed/package.json');
|
|
151
|
-
expect(live?.name).toBe('cowshed');
|
|
152
|
-
} finally {
|
|
153
|
-
await workspace.cleanup();
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('keys installed patch data and pins without keying patch documentation', async () => {
|
|
158
|
-
const workspace = await createWorkspace();
|
|
159
|
-
try {
|
|
160
|
-
await workspace.write('packages/example/package.json', '{"name":"example","scripts":{"test":"bun test"}}\n');
|
|
161
|
-
await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
|
|
162
|
-
await workspace.write('packages/example/tsconfig.test.json', '{}\n');
|
|
163
|
-
await workspace.write('patches/nx.patch', 'patch-one\n');
|
|
164
|
-
await workspace.write('patches/compiler/PIN', 'revision-one\n');
|
|
165
|
-
await workspace.write('patches/compiler/VERSION', 'version-one\n');
|
|
166
|
-
await workspace.write('patches/README.md', 'documentation-one\n');
|
|
167
|
-
await workspace.write('patches/compiler/notes.md', 'nested documentation-one\n');
|
|
168
|
-
await workspace.write('packages/unrelated/source.ts', 'export const value = 1;\n');
|
|
169
|
-
const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
170
|
-
const context = new WorkspaceContext(
|
|
171
|
-
workspace.context.workspaceRoot,
|
|
172
|
-
join(workspace.context.workspaceRoot, '.nx/patch-input-context'),
|
|
173
|
-
);
|
|
174
|
-
for (const name of ['tsc-js', 'typecheck', 'typecheck-tests', 'lint']) {
|
|
175
|
-
const inputs = targets[name]?.inputs ?? [];
|
|
176
|
-
const patchInputs = inputs.filter(
|
|
177
|
-
(input): input is string => typeof input === 'string' && input.includes('{workspaceRoot}/patches/'),
|
|
178
|
-
);
|
|
179
|
-
expect(patchInputs.length).toBeGreaterThan(0);
|
|
180
|
-
const positive = patchInputs
|
|
181
|
-
.filter((input) => !input.startsWith('!'))
|
|
182
|
-
.map((input) => input.slice('{workspaceRoot}/'.length));
|
|
183
|
-
const negative = patchInputs
|
|
184
|
-
.filter((input) => input.startsWith('!'))
|
|
185
|
-
.map((input) => input.slice('!{workspaceRoot}/'.length));
|
|
186
|
-
expect(context.glob(positive, negative).sort()).toEqual([
|
|
187
|
-
'patches/compiler/PIN',
|
|
188
|
-
'patches/compiler/VERSION',
|
|
189
|
-
'patches/nx.patch',
|
|
190
|
-
]);
|
|
191
|
-
const before = context.hashFilesMatchingGlob(positive, negative);
|
|
192
|
-
await workspace.write('patches/README.md', `${name} docs\n`);
|
|
193
|
-
await workspace.write('patches/compiler/notes.md', `${name} nested docs\n`);
|
|
194
|
-
await workspace.write('packages/unrelated/source.ts', `export const value = ${name.length};\n`);
|
|
195
|
-
context.incrementalUpdate(
|
|
196
|
-
['patches/README.md', 'patches/compiler/notes.md', 'packages/unrelated/source.ts'],
|
|
197
|
-
[],
|
|
198
|
-
);
|
|
199
|
-
expect(context.hashFilesMatchingGlob(positive, negative)).toBe(before);
|
|
200
|
-
let previous = before;
|
|
201
|
-
for (const file of ['patches/nx.patch', 'patches/compiler/PIN', 'patches/compiler/VERSION']) {
|
|
202
|
-
await workspace.write(file, `${name} changed ${file}\n`);
|
|
203
|
-
context.incrementalUpdate([file], []);
|
|
204
|
-
const changed = context.hashFilesMatchingGlob(positive, negative);
|
|
205
|
-
expect(changed).not.toBe(previous);
|
|
206
|
-
previous = changed;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
} finally {
|
|
210
|
-
await workspace.cleanup();
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('uses the transformer-aware compiler for emit and validation', async () => {
|
|
215
|
-
const workspace = await createWorkspace();
|
|
216
|
-
try {
|
|
217
|
-
await workspace.write(
|
|
218
|
-
'packages/example/package.json',
|
|
219
|
-
'{"name":"example","bin":{"example":"./dist/bin/example.js"},"scripts":{"test":"bun test --pass-with-no-tests"}}\n',
|
|
220
|
-
);
|
|
221
|
-
await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
|
|
222
|
-
await workspace.write('packages/example/tsconfig.test.json', '{}\n');
|
|
223
|
-
|
|
224
|
-
const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
225
|
-
|
|
226
|
-
expect(targets['tsc-js']?.executor).toBe('@smoothbricks/nx-plugin:typescript-emit');
|
|
227
|
-
expect(targets['tsc-js']?.options).toEqual({
|
|
228
|
-
executableOutputs: ['./dist/bin/example.js'],
|
|
229
|
-
tsConfig: 'tsconfig.lib.json',
|
|
230
|
-
cwd: 'packages/example',
|
|
231
|
-
});
|
|
232
|
-
const toolchainInputs = [
|
|
233
|
-
'{workspaceRoot}/package.json',
|
|
234
|
-
'{workspaceRoot}/bun.lock',
|
|
235
|
-
'{workspaceRoot}/patches/**/*',
|
|
236
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
237
|
-
'{workspaceRoot}/tsconfig.base.json',
|
|
238
|
-
];
|
|
239
|
-
// An emit is a shipped artifact: it hashes the raw manifests, so a
|
|
240
|
-
// version bump reruns it rather than restoring a stale one.
|
|
241
|
-
expect(targets['tsc-js']?.inputs).toEqual([
|
|
242
|
-
'production',
|
|
243
|
-
'^production',
|
|
244
|
-
...toolchainInputs,
|
|
245
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
246
|
-
]);
|
|
247
|
-
expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}']);
|
|
248
|
-
// Typecheck runs the compiler devenv.smoo.nix pins (SMOO_TYPECHECK_TSC) itself, not through
|
|
249
|
-
// ttsc, whose auto-loaded transform plugins would check with their own compiler; and it refuses
|
|
250
|
-
// to fall back to another when the shell does not provide it.
|
|
251
|
-
const typecheckCompiler =
|
|
252
|
-
'"${SMOO_TYPECHECK_TSC:?is unset, enter the devenv shell (devenv.smoo.nix builds the typecheck compiler)}"';
|
|
253
|
-
expect(targets.typecheck?.options).toMatchObject({
|
|
254
|
-
command: `${typecheckCompiler} -p tsconfig.lib.json --noEmit`,
|
|
255
|
-
cwd: 'packages/example',
|
|
256
|
-
});
|
|
257
|
-
const checkToolchainInputs = [
|
|
258
|
-
'{workspaceRoot}/patches/**/*',
|
|
259
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
260
|
-
'{workspaceRoot}/tsconfig.base.json',
|
|
261
|
-
{ json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
|
|
262
|
-
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
263
|
-
];
|
|
264
|
-
// The compiler's store path names its pinned revision, so a compiler bump misses the cache.
|
|
265
|
-
expect(targets.typecheck?.inputs).toEqual([
|
|
266
|
-
'versionlessProduction',
|
|
267
|
-
'^production',
|
|
268
|
-
...checkToolchainInputs,
|
|
269
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
270
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
271
|
-
]);
|
|
272
|
-
expect(targets.build?.executor).toBe('nx:noop');
|
|
273
|
-
expect(targets.build?.cache).toBe(true);
|
|
274
|
-
expect(targets.build?.dependsOn).toEqual(['^build', 'tsc-js']);
|
|
275
|
-
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
276
|
-
expect(targets.clean?.cache).toBe(false);
|
|
277
|
-
|
|
278
|
-
expect(targets['typecheck-tests']?.executor).toBe('nx:run-commands');
|
|
279
|
-
expect(targets['typecheck-tests']?.cache).toBe(true);
|
|
280
|
-
expect(targets['typecheck-tests']?.dependsOn).toEqual(['tsc-js', 'typecheck']);
|
|
281
|
-
expect(targets['typecheck-tests']?.options).toMatchObject({
|
|
282
|
-
command: `${typecheckCompiler} -p tsconfig.test.json --noEmit`,
|
|
283
|
-
cwd: 'packages/example',
|
|
284
|
-
});
|
|
285
|
-
expect(targets['typecheck-tests']?.inputs).toEqual([
|
|
286
|
-
'versionlessDefault',
|
|
287
|
-
'^production',
|
|
288
|
-
...checkToolchainInputs,
|
|
289
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
290
|
-
'{projectRoot}/tsconfig.test.json',
|
|
291
|
-
]);
|
|
292
|
-
|
|
293
|
-
expect(targets['typecheck-tests:watch']?.executor).toBe('nx:run-commands');
|
|
294
|
-
expect(targets['typecheck-tests:watch']?.continuous).toBe(true);
|
|
295
|
-
expect(targets['typecheck-tests:watch']?.options).toMatchObject({
|
|
296
|
-
command: `${typecheckCompiler} -p tsconfig.test.json --noEmit --watch`,
|
|
297
|
-
cwd: 'packages/example',
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
expect(targets['test-watch']?.executor).toBe('nx:run-commands');
|
|
301
|
-
expect(targets['test-watch']?.continuous).toBe(true);
|
|
302
|
-
expect(targets['test-watch']?.dependsOn).toEqual(['typecheck-tests']);
|
|
303
|
-
expect(targets['test-watch']?.options).toMatchObject({
|
|
304
|
-
command: 'bun test --watch --pass-with-no-tests',
|
|
305
|
-
cwd: 'packages/example',
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
expect(targets.lint?.cache).toBe(true);
|
|
309
|
-
expect(targets.lint?.dependsOn).toEqual(['typecheck-tests']);
|
|
310
|
-
expect(targets.lint?.inputs).toContain('^production');
|
|
311
|
-
} finally {
|
|
312
|
-
await workspace.cleanup();
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it('hashes the manifests without their versions for checks, raw for artifacts', async () => {
|
|
317
|
-
const workspace = await createWorkspace();
|
|
318
|
-
try {
|
|
319
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
320
|
-
await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
|
|
321
|
-
await workspace.write('packages/example/tsconfig.test.json', '{}\n');
|
|
322
|
-
|
|
323
|
-
const project = await inferProjectWithNxJson(workspace, 'packages/example/package.json', {
|
|
324
|
-
namedInputs: { versionlessProduction: ['production'] },
|
|
325
|
-
});
|
|
326
|
-
const targets = project?.targets ?? {};
|
|
327
|
-
const checkToolchain = [
|
|
328
|
-
'{workspaceRoot}/patches/**/*',
|
|
329
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
330
|
-
'{workspaceRoot}/tsconfig.base.json',
|
|
331
|
-
// Hashed by Nx itself: a `json` input costs no process, and neither
|
|
332
|
-
// does the crate digest that replaces the manifests below.
|
|
333
|
-
// The root manifest's scripts, smoo and nx sections are read by no check: an
|
|
334
|
-
// edit to a script or a developer link must not re-key every lint and typecheck.
|
|
335
|
-
{ json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
|
|
336
|
-
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
337
|
-
];
|
|
338
|
-
|
|
339
|
-
// No crate manifest in this project, so no crate digest is declared at
|
|
340
|
-
// all — nothing is hashed that nothing reads.
|
|
341
|
-
expect(project?.namedInputs).toEqual({
|
|
342
|
-
versionlessProduction: [
|
|
343
|
-
'production',
|
|
344
|
-
'!{projectRoot}/package.json',
|
|
345
|
-
{ json: '{projectRoot}/package.json', excludeFields: ['version'] },
|
|
346
|
-
],
|
|
347
|
-
versionlessDefault: [
|
|
348
|
-
'default',
|
|
349
|
-
'!{projectRoot}/package.json',
|
|
350
|
-
{ json: '{projectRoot}/package.json', excludeFields: ['version'] },
|
|
351
|
-
],
|
|
352
|
-
});
|
|
353
|
-
expect(targets.typecheck?.inputs).toEqual([
|
|
354
|
-
'versionlessProduction',
|
|
355
|
-
{ input: 'versionlessProduction', dependencies: true },
|
|
356
|
-
...checkToolchain,
|
|
357
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
358
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
359
|
-
]);
|
|
360
|
-
expect(targets['typecheck-tests']?.inputs).toEqual([
|
|
361
|
-
'versionlessDefault',
|
|
362
|
-
{ input: 'versionlessProduction', dependencies: true },
|
|
363
|
-
...checkToolchain,
|
|
364
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
365
|
-
'{projectRoot}/tsconfig.test.json',
|
|
366
|
-
]);
|
|
367
|
-
expect(targets.lint?.inputs).toEqual([
|
|
368
|
-
'versionlessDefault',
|
|
369
|
-
{ input: 'versionlessProduction', dependencies: true },
|
|
370
|
-
...checkToolchain,
|
|
371
|
-
...[
|
|
372
|
-
'biome.json',
|
|
373
|
-
'biome.jsonc',
|
|
374
|
-
'eslint.config.js',
|
|
375
|
-
'eslint.config.mjs',
|
|
376
|
-
'eslint.config.cjs',
|
|
377
|
-
'eslint.config.ts',
|
|
378
|
-
'eslint.config.mts',
|
|
379
|
-
'eslint.config.cts',
|
|
380
|
-
].flatMap((name) => [`{workspaceRoot}/${name}`, `{projectRoot}/${name}`]),
|
|
381
|
-
'{workspaceRoot}/tooling/checks/**/*',
|
|
382
|
-
]);
|
|
383
|
-
|
|
384
|
-
// The guard this whole treatment lives or dies on. A declaration emit is
|
|
385
|
-
// a shipped artifact, and a crate compiled beside it embeds its version
|
|
386
|
-
// through `env!("CARGO_PKG_VERSION")`, so an artifact target that stopped
|
|
387
|
-
// hashing the raw manifests could hit a pre-bump entry and publish a
|
|
388
|
-
// binary reporting the previous version.
|
|
389
|
-
expect(targets['tsc-js']?.inputs).toEqual([
|
|
390
|
-
'production',
|
|
391
|
-
'^production',
|
|
392
|
-
'{workspaceRoot}/package.json',
|
|
393
|
-
'{workspaceRoot}/bun.lock',
|
|
394
|
-
'{workspaceRoot}/patches/**/*',
|
|
395
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
396
|
-
'{workspaceRoot}/tsconfig.base.json',
|
|
397
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
398
|
-
]);
|
|
399
|
-
} finally {
|
|
400
|
-
await workspace.cleanup();
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
it('hashes crate manifests into a digest, only where crates exist', async () => {
|
|
405
|
-
const workspace = await createWorkspace();
|
|
406
|
-
try {
|
|
407
|
-
const manifest = (version: string) =>
|
|
408
|
-
`[package]\nname = "rust-example"\nversion = "${version}"\n\n[dependencies]\nserde = { version = "1.0.200" }\n`;
|
|
409
|
-
await workspace.write('packages/rust/package.json', '{"name":"rust-example"}\n');
|
|
410
|
-
await workspace.write('packages/rust/tsconfig.lib.json', '{}\n');
|
|
411
|
-
await workspace.write('packages/rust/Cargo.toml', manifest('0.1.0'));
|
|
412
|
-
const production = async () =>
|
|
413
|
-
(await inferProjectWithNxJson(workspace, 'packages/rust/package.json', {}))?.namedInputs?.versionlessProduction;
|
|
414
|
-
|
|
415
|
-
const baseline = await production();
|
|
416
|
-
|
|
417
|
-
// TOML has no `json` input, so this is the one manifest kind the plugin
|
|
418
|
-
// hashes itself. There is no command behind it: the value IS the input,
|
|
419
|
-
// and Nx hashes it through the project configuration.
|
|
420
|
-
expect(baseline).toEqual([
|
|
421
|
-
'production',
|
|
422
|
-
'!{projectRoot}/package.json',
|
|
423
|
-
{ json: '{projectRoot}/package.json', excludeFields: ['version'] },
|
|
424
|
-
'!{projectRoot}/**/Cargo.toml',
|
|
425
|
-
expect.stringMatching(/^\{projectRoot\}\/\.versionless-crate-manifests\/[0-9a-f]{64}$/),
|
|
426
|
-
]);
|
|
427
|
-
|
|
428
|
-
// What the digest exists for: the release moves the crate's own version
|
|
429
|
-
// and nothing else, so the input a check hashes must not move with it.
|
|
430
|
-
await workspace.write('packages/rust/Cargo.toml', manifest('9.9.9'));
|
|
431
|
-
expect(await production()).toEqual(baseline);
|
|
432
|
-
|
|
433
|
-
// And a dependency really changing must still reach the hash, or the
|
|
434
|
-
// exclusion above would be hiding it.
|
|
435
|
-
await workspace.write('packages/rust/Cargo.toml', manifest('0.1.0').replace('1.0.200', '1.0.201'));
|
|
436
|
-
expect(await production()).not.toEqual(baseline);
|
|
437
|
-
} finally {
|
|
438
|
-
await workspace.cleanup();
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
it('keeps the dependency half raw until the workspace defines the named input', async () => {
|
|
443
|
-
const workspace = await createWorkspace();
|
|
444
|
-
try {
|
|
445
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
446
|
-
await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
|
|
447
|
-
|
|
448
|
-
// `{ input, dependencies: true }` resolves the name in each dependency's
|
|
449
|
-
// own context and Nx throws when one has no definition for it. A
|
|
450
|
-
// project.json project this plugin never inferred has none, so the
|
|
451
|
-
// transitive half waits for the workspace-wide definition that covers it.
|
|
452
|
-
const targets = (await inferProjectWithNxJson(workspace, 'packages/example/package.json', {}))?.targets ?? {};
|
|
453
|
-
|
|
454
|
-
expect(targets.typecheck?.inputs).toEqual([
|
|
455
|
-
'versionlessProduction',
|
|
456
|
-
'^production',
|
|
457
|
-
'{workspaceRoot}/patches/**/*',
|
|
458
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
459
|
-
'{workspaceRoot}/tsconfig.base.json',
|
|
460
|
-
{ json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
|
|
461
|
-
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
462
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
463
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
464
|
-
]);
|
|
465
|
-
} finally {
|
|
466
|
-
await workspace.cleanup();
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
it('hashes every tsconfig the extends chain reaches, not just the one the command names', async () => {
|
|
471
|
-
const workspace = await createWorkspace();
|
|
472
|
-
try {
|
|
473
|
-
// The shape that made this a silent cache hit: the options a check
|
|
474
|
-
// resolves live one file ABOVE the config its command names.
|
|
475
|
-
await workspace.write('tsconfig.base.json', '{"compilerOptions":{"strict":true}}\n');
|
|
476
|
-
await workspace.write(
|
|
477
|
-
'packages/tsconfig.base.json',
|
|
478
|
-
'{"extends":"../tsconfig.base.json","compilerOptions":{"noUnusedLocals":true}}\n',
|
|
479
|
-
);
|
|
480
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
481
|
-
await workspace.write('packages/example/tsconfig.lib.json', '{"extends":"../tsconfig.base.json"}\n');
|
|
482
|
-
// A deeper chain reached from the other config, named without the
|
|
483
|
-
// extension TypeScript lets a specifier omit.
|
|
484
|
-
await workspace.write('packages/example/tsconfig.strict.json', '{"extends":"../tsconfig.base"}\n');
|
|
485
|
-
await workspace.write('packages/example/tsconfig.test.json', '{"extends":"./tsconfig.strict.json"}\n');
|
|
486
|
-
|
|
487
|
-
const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
488
|
-
|
|
489
|
-
// Every file in the chain, once, whichever config reached it.
|
|
490
|
-
const configChain = [
|
|
491
|
-
'{workspaceRoot}/tsconfig.base.json',
|
|
492
|
-
'{workspaceRoot}/packages/tsconfig.base.json',
|
|
493
|
-
'{workspaceRoot}/packages/example/tsconfig.strict.json',
|
|
494
|
-
];
|
|
495
|
-
const checkToolchain = [
|
|
496
|
-
'{workspaceRoot}/patches/**/*',
|
|
497
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
498
|
-
...configChain,
|
|
499
|
-
{ json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
|
|
500
|
-
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
501
|
-
];
|
|
502
|
-
expect(targets.typecheck?.inputs).toEqual([
|
|
503
|
-
'versionlessProduction',
|
|
504
|
-
'^production',
|
|
505
|
-
...checkToolchain,
|
|
506
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
507
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
508
|
-
]);
|
|
509
|
-
expect(targets['typecheck-tests']?.inputs).toEqual([
|
|
510
|
-
'versionlessDefault',
|
|
511
|
-
'^production',
|
|
512
|
-
...checkToolchain,
|
|
513
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
514
|
-
'{projectRoot}/tsconfig.test.json',
|
|
515
|
-
]);
|
|
516
|
-
// An emit reads the same options, and a stale artifact is worse than a
|
|
517
|
-
// stale verdict.
|
|
518
|
-
expect(targets['tsc-js']?.inputs).toEqual([
|
|
519
|
-
'production',
|
|
520
|
-
'^production',
|
|
521
|
-
'{workspaceRoot}/package.json',
|
|
522
|
-
'{workspaceRoot}/bun.lock',
|
|
523
|
-
'{workspaceRoot}/patches/**/*',
|
|
524
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
525
|
-
...configChain,
|
|
526
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
527
|
-
]);
|
|
528
|
-
// Typed lint runs the same program (`projectService`), so its verdict
|
|
529
|
-
// moves with the same files.
|
|
530
|
-
expect(targets.lint?.inputs).toEqual(expect.arrayContaining(configChain));
|
|
531
|
-
} finally {
|
|
532
|
-
await workspace.cleanup();
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
it('refuses a project whose tsconfig extends a file that is not there', async () => {
|
|
537
|
-
const workspace = await createWorkspace();
|
|
538
|
-
try {
|
|
539
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
540
|
-
await workspace.write('packages/example/tsconfig.lib.json', '{"extends":"../tsconfig.base.json"}\n');
|
|
541
|
-
|
|
542
|
-
// Fail-closed, and the only safe direction: an ancestor left out of the
|
|
543
|
-
// hash is a cached verdict nobody can invalidate. Nx wraps a createNodes
|
|
544
|
-
// throw, so the reason lives in the nested error.
|
|
545
|
-
const failure = await inferProjectTargets(workspace, 'packages/example/package.json').then(
|
|
546
|
-
() => undefined,
|
|
547
|
-
(error: unknown) => error,
|
|
548
|
-
);
|
|
549
|
-
if (!(failure instanceof AggregateCreateNodesError)) {
|
|
550
|
-
throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
|
|
551
|
-
}
|
|
552
|
-
expect(failure.errors[0]?.[1]?.message).toMatch(/"extends": "\.\.\/tsconfig\.base\.json" names no file/);
|
|
553
|
-
} finally {
|
|
554
|
-
await workspace.cleanup();
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
it('walks an extends cycle once, and leaves an installed config to the lockfile wherever it is stored', async () => {
|
|
559
|
-
const workspace = await createWorkspace();
|
|
560
|
-
// WHERE an installed config's bytes sit is the installer's business: bun
|
|
561
|
-
// keeps them in a global store and points node_modules at it, so this one
|
|
562
|
-
// is outside the workspace entirely.
|
|
563
|
-
const store = await mkdtemp(join(tmpdir(), 'smoothbricks-nx-plugin-store-'));
|
|
564
|
-
try {
|
|
565
|
-
await workspace.write('tsconfig.base.json', '{"compilerOptions":{"strict":true}}\n');
|
|
566
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
567
|
-
// TypeScript rejects a cycle; this walk must terminate on one anyway,
|
|
568
|
-
// with both files hashed.
|
|
569
|
-
await workspace.write('packages/example/tsconfig.lib.json', '{"extends":"./tsconfig.cycle.json"}\n');
|
|
570
|
-
await workspace.write('packages/example/tsconfig.cycle.json', '{"extends":"./tsconfig.lib.json"}\n');
|
|
571
|
-
// Which bytes are in that store is pinned by the lockfile and the root
|
|
572
|
-
// manifest, both already inputs; naming the path would hash nothing.
|
|
573
|
-
await writeFile(join(store, 'package.json'), '{"name":"@fixture/tsconfig"}\n');
|
|
574
|
-
await writeFile(join(store, 'tsconfig.json'), '{"compilerOptions":{"noUnusedLocals":true}}\n');
|
|
575
|
-
await mkdir(join(workspace.context.workspaceRoot, 'node_modules/@fixture'), { recursive: true });
|
|
576
|
-
await symlink(store, join(workspace.context.workspaceRoot, 'node_modules/@fixture/tsconfig'), 'dir');
|
|
577
|
-
await workspace.write('packages/example/tsconfig.test.json', '{"extends":"@fixture/tsconfig/tsconfig.json"}\n');
|
|
578
|
-
|
|
579
|
-
const { result: targets, stderr } = await withCapturedStderr(() =>
|
|
580
|
-
inferProjectTargets(workspace, 'packages/example/package.json'),
|
|
581
|
-
);
|
|
582
|
-
const inputs = targets.typecheck?.inputs ?? [];
|
|
583
|
-
|
|
584
|
-
expect(inputs).toEqual([
|
|
585
|
-
'versionlessProduction',
|
|
586
|
-
'^production',
|
|
587
|
-
'{workspaceRoot}/patches/**/*',
|
|
588
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
589
|
-
'{workspaceRoot}/tsconfig.base.json',
|
|
590
|
-
'{workspaceRoot}/packages/example/tsconfig.cycle.json',
|
|
591
|
-
'{workspaceRoot}/packages/example/tsconfig.lib.json',
|
|
592
|
-
{ json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
|
|
593
|
-
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
594
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
595
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
596
|
-
]);
|
|
597
|
-
expect(JSON.stringify(inputs)).not.toContain('node_modules');
|
|
598
|
-
// And silently, because nothing was lost. The noisy version of this fires
|
|
599
|
-
// on every graph build in a workspace that installs one Expo package.
|
|
600
|
-
expect(stderr).toBe('');
|
|
601
|
-
} finally {
|
|
602
|
-
await rm(store, { recursive: true, force: true });
|
|
603
|
-
await workspace.cleanup();
|
|
604
|
-
}
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
it("hashes a workspace member's config reached through its package name", async () => {
|
|
608
|
-
const workspace = await createWorkspace();
|
|
609
|
-
try {
|
|
610
|
-
const root = workspace.context.workspaceRoot;
|
|
611
|
-
await workspace.write('tsconfig.base.json', '{"compilerOptions":{"strict":true}}\n');
|
|
612
|
-
// The other half of that judgement: a package name can resolve to
|
|
613
|
-
// workspace SOURCE, which no lockfile pins. Dropping it would be the
|
|
614
|
-
// original bug wearing a package name.
|
|
615
|
-
await workspace.write('packages/tsconfig/package.json', '{"name":"@fixture/tsconfig"}\n');
|
|
616
|
-
await workspace.write(
|
|
617
|
-
'packages/tsconfig/base.json',
|
|
618
|
-
'{"extends":"../../tsconfig.base.json","compilerOptions":{"noUnusedLocals":true}}\n',
|
|
619
|
-
);
|
|
620
|
-
await mkdir(join(root, 'node_modules/@fixture'), { recursive: true });
|
|
621
|
-
await symlink(join(root, 'packages/tsconfig'), join(root, 'node_modules/@fixture/tsconfig'), 'dir');
|
|
622
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
623
|
-
await workspace.write('packages/example/tsconfig.lib.json', '{"extends":"@fixture/tsconfig/base.json"}\n');
|
|
624
|
-
|
|
625
|
-
const { result: targets, stderr } = await withCapturedStderr(() =>
|
|
626
|
-
inferProjectTargets(workspace, 'packages/example/package.json'),
|
|
627
|
-
);
|
|
628
|
-
|
|
629
|
-
expect(targets.typecheck?.inputs).toEqual([
|
|
630
|
-
'versionlessProduction',
|
|
631
|
-
'^production',
|
|
632
|
-
'{workspaceRoot}/patches/**/*',
|
|
633
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
634
|
-
'{workspaceRoot}/tsconfig.base.json',
|
|
635
|
-
'{workspaceRoot}/packages/tsconfig/base.json',
|
|
636
|
-
{ json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
|
|
637
|
-
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
638
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
639
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
640
|
-
]);
|
|
641
|
-
expect(stderr).toBe('');
|
|
642
|
-
} finally {
|
|
643
|
-
await workspace.cleanup();
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
it('says so when an extends chain leaves the workspace, where nothing can hash it', async () => {
|
|
648
|
-
const workspace = await createWorkspace();
|
|
649
|
-
const outside = await mkdtemp(join(tmpdir(), 'smoothbricks-nx-plugin-outside-'));
|
|
650
|
-
try {
|
|
651
|
-
await writeFile(join(outside, 'tsconfig.base.json'), '{"compilerOptions":{"noUnusedLocals":true}}\n');
|
|
652
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
653
|
-
await workspace.write(
|
|
654
|
-
'packages/example/tsconfig.lib.json',
|
|
655
|
-
`${JSON.stringify({ extends: join(outside, 'tsconfig.base.json') })}\n`,
|
|
656
|
-
);
|
|
657
|
-
|
|
658
|
-
const { result: targets, stderr } = await withCapturedStderr(() =>
|
|
659
|
-
inferProjectTargets(workspace, 'packages/example/package.json'),
|
|
660
|
-
);
|
|
661
|
-
|
|
662
|
-
// Nx hashes workspace files only, and no lockfile pins this one either,
|
|
663
|
-
// so the verdict really can go stale. A silent drop here is the bug this
|
|
664
|
-
// walk exists to close, so it is said out loud instead.
|
|
665
|
-
expect(stderr).toContain(join(outside, 'tsconfig.base.json'));
|
|
666
|
-
expect(stderr).toContain('outside the workspace');
|
|
667
|
-
expect(targets.typecheck?.inputs).toEqual([
|
|
668
|
-
'versionlessProduction',
|
|
669
|
-
'^production',
|
|
670
|
-
'{workspaceRoot}/patches/**/*',
|
|
671
|
-
'!{workspaceRoot}/patches/**/*.md',
|
|
672
|
-
'{workspaceRoot}/tsconfig.base.json',
|
|
673
|
-
{ json: '{workspaceRoot}/package.json', excludeFields: ['version', 'scripts', 'smoo', 'nx'] },
|
|
674
|
-
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
675
|
-
{ env: 'SMOO_TYPECHECK_TSC' },
|
|
676
|
-
'{projectRoot}/tsconfig.lib.json',
|
|
677
|
-
]);
|
|
678
|
-
} finally {
|
|
679
|
-
await rm(outside, { recursive: true, force: true });
|
|
680
|
-
await workspace.cleanup();
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
|
|
684
|
-
it('rebuilds current library declarations before test typechecking after clean', async () => {
|
|
685
|
-
const workspace = await createWorkspace();
|
|
686
|
-
try {
|
|
687
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
688
|
-
await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
|
|
689
|
-
await workspace.write('packages/example/tsconfig.test.json', '{}\n');
|
|
690
|
-
|
|
691
|
-
const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
692
|
-
|
|
693
|
-
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
694
|
-
expect(targets['typecheck-tests']?.dependsOn).toEqual(['tsc-js', 'typecheck']);
|
|
695
|
-
} finally {
|
|
696
|
-
await workspace.cleanup();
|
|
697
|
-
}
|
|
698
|
-
});
|
|
699
|
-
|
|
700
|
-
it('infers vitest watch targets from explicit test commands', async () => {
|
|
701
|
-
const workspace = await createWorkspace();
|
|
702
|
-
try {
|
|
703
|
-
await workspace.write(
|
|
704
|
-
'packages/example/package.json',
|
|
705
|
-
'{"name":"example","scripts":{"test":"vitest run --coverage"}}\n',
|
|
706
|
-
);
|
|
707
|
-
await workspace.write('packages/example/tsconfig.test.json', '{}\n');
|
|
708
|
-
|
|
709
|
-
const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
710
|
-
|
|
711
|
-
expect(targets['test-watch']?.continuous).toBe(true);
|
|
712
|
-
expect(targets['test-watch']?.options).toMatchObject({
|
|
713
|
-
command: 'vitest --coverage',
|
|
714
|
-
cwd: 'packages/example',
|
|
715
|
-
});
|
|
716
|
-
} finally {
|
|
717
|
-
await workspace.cleanup();
|
|
718
|
-
}
|
|
719
|
-
});
|
|
720
|
-
|
|
721
|
-
it('makes lint check that the timing manifest names every file a timings-sharded Bun suite runs', async () => {
|
|
722
|
-
const workspace = await createWorkspace();
|
|
723
|
-
try {
|
|
724
|
-
const shard = (n: number) => ({
|
|
725
|
-
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
726
|
-
options: { command: `bun test --timings=test-timings.json --shard=${n}/2`, cwd: '{projectRoot}' },
|
|
727
|
-
});
|
|
728
|
-
await workspace.write(
|
|
729
|
-
'packages/sharded/package.json',
|
|
730
|
-
JSON.stringify({ name: 'sharded', nx: { targets: { 'test-a': shard(1), 'test-b': shard(2) } } }),
|
|
731
|
-
);
|
|
732
|
-
await workspace.write(
|
|
733
|
-
'packages/counted/package.json',
|
|
734
|
-
JSON.stringify({
|
|
735
|
-
name: 'counted',
|
|
736
|
-
nx: { targets: { 'test-a': { options: { command: 'bun test --shard=1/1', cwd: '{projectRoot}' } } } },
|
|
737
|
-
}),
|
|
738
|
-
);
|
|
739
|
-
|
|
740
|
-
const sharded = await inferProjectTargets(workspace, 'packages/sharded/package.json');
|
|
741
|
-
const counted = await inferProjectTargets(workspace, 'packages/counted/package.json');
|
|
742
|
-
|
|
743
|
-
expect(sharded['shard-timings']).toEqual({
|
|
744
|
-
executor: '@smoothbricks/nx-plugin:shard-timings',
|
|
745
|
-
cache: false,
|
|
746
|
-
outputs: [],
|
|
747
|
-
options: { cwd: 'packages/sharded', args: ['--timings=test-timings.json'] },
|
|
748
|
-
});
|
|
749
|
-
expect(sharded.lint?.dependsOn).toEqual(['shard-timings']);
|
|
750
|
-
expect(counted['shard-timings']).toBeUndefined();
|
|
751
|
-
expect(counted.lint).toBeUndefined();
|
|
752
|
-
} finally {
|
|
753
|
-
await workspace.cleanup();
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
it('infers aggregate build for package-local output targets without owning them', async () => {
|
|
758
|
-
const workspace = await createWorkspace();
|
|
759
|
-
try {
|
|
760
|
-
await workspace.write(
|
|
761
|
-
'packages/tsdown/package.json',
|
|
762
|
-
JSON.stringify({ name: 'tsdown', nx: { targets: { 'tsdown-js': { executor: 'nx:run-commands' } } } }),
|
|
763
|
-
);
|
|
764
|
-
|
|
765
|
-
const targets = await inferProjectTargets(workspace, 'packages/tsdown/package.json');
|
|
766
|
-
|
|
767
|
-
expect(targets['tsc-js']).toBeUndefined();
|
|
768
|
-
expect(targets['tsdown-js']).toBeUndefined();
|
|
769
|
-
expect(targets.build?.executor).toBe('nx:noop');
|
|
770
|
-
expect(targets.build?.dependsOn).toEqual(['^build', 'tsdown-js']);
|
|
771
|
-
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
772
|
-
} finally {
|
|
773
|
-
await workspace.cleanup();
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
it('keeps a test runner out of the aggregate build however its name ends', async () => {
|
|
778
|
-
const workspace = await createWorkspace();
|
|
779
|
-
try {
|
|
780
|
-
await workspace.write(
|
|
781
|
-
'packages/suites/package.json',
|
|
782
|
-
JSON.stringify({
|
|
783
|
-
name: 'suites',
|
|
784
|
-
nx: {
|
|
785
|
-
targets: {
|
|
786
|
-
// A runner reading as "tool=test, output=bun". Suffix alone would
|
|
787
|
-
// sweep it into `build`, which is a serialized test suite behind
|
|
788
|
-
// every consumer's build.
|
|
789
|
-
'test-bun': { executor: 'nx:run-commands' },
|
|
790
|
-
'test-watch': { executor: 'nx:run-commands' },
|
|
791
|
-
// A real emitter in the same family, to prove the exclusion is
|
|
792
|
-
// the test-runner class and not the family itself.
|
|
793
|
-
'bundle-bun': { executor: 'nx:run-commands' },
|
|
794
|
-
},
|
|
795
|
-
},
|
|
796
|
-
}),
|
|
797
|
-
);
|
|
798
|
-
|
|
799
|
-
const targets = await inferProjectTargets(workspace, 'packages/suites/package.json');
|
|
800
|
-
|
|
801
|
-
expect(targets.build?.dependsOn).toEqual(['^build', 'bundle-bun']);
|
|
802
|
-
} finally {
|
|
803
|
-
await workspace.cleanup();
|
|
804
|
-
}
|
|
805
|
-
});
|
|
806
|
-
|
|
807
|
-
it('keeps platform-only output families out of the ordinary aggregate build', async () => {
|
|
808
|
-
const workspace = await createWorkspace();
|
|
809
|
-
try {
|
|
810
|
-
await workspace.write(
|
|
811
|
-
'packages/platform/package.json',
|
|
812
|
-
JSON.stringify({
|
|
813
|
-
name: 'platform',
|
|
814
|
-
nx: {
|
|
815
|
-
targets: {
|
|
816
|
-
'bundle-ios': { executor: 'nx:run-commands' },
|
|
817
|
-
'bundle-macos': { executor: 'nx:run-commands' },
|
|
818
|
-
'bundle-linux': { executor: 'nx:run-commands' },
|
|
819
|
-
},
|
|
820
|
-
},
|
|
821
|
-
}),
|
|
822
|
-
);
|
|
823
|
-
|
|
824
|
-
const targets = await inferProjectTargets(workspace, 'packages/platform/package.json');
|
|
825
|
-
|
|
826
|
-
expect(targets.build).toBeUndefined();
|
|
827
|
-
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
828
|
-
// No ordinary aggregate above is the whole assertion: a platform suffix
|
|
829
|
-
// is not an output family, so `bundle-ios`/`-macos`/`-linux` give this
|
|
830
|
-
// project nothing for `build` to aggregate — only a `clean` to own their
|
|
831
|
-
// outputs.
|
|
832
|
-
} finally {
|
|
833
|
-
await workspace.cleanup();
|
|
834
|
-
}
|
|
835
|
-
});
|
|
836
|
-
|
|
837
|
-
//#region smoo!n/rust-output-target-inference
|
|
838
|
-
it('infers generic cargo workspace targets without any rust output targets', async () => {
|
|
839
|
-
const workspace = await createWorkspace();
|
|
840
|
-
try {
|
|
841
|
-
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
842
|
-
await workspace.write(
|
|
843
|
-
'packages/ferris/Cargo.toml',
|
|
844
|
-
'[workspace]\nmembers = ["crates/ferris-core", "crates/ferris-wasm"]\n\n[profile.wasm-release]\ninherits = "release"\n',
|
|
845
|
-
);
|
|
846
|
-
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
847
|
-
await workspace.write(
|
|
848
|
-
'packages/ferris/crates/ferris-wasm/Cargo.toml',
|
|
849
|
-
'[package]\nname = "ferris-wasm"\n\n[lib]\ncrate-type = ["cdylib", "rlib"]\n',
|
|
850
|
-
);
|
|
851
|
-
|
|
852
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
853
|
-
|
|
854
|
-
// Even a cdylib crate named *-wasm infers no cargo-wasm: rust output
|
|
855
|
-
// targets are declared package-locally, never derived from crate metadata.
|
|
856
|
-
expect(targets['cargo-wasm']).toBeUndefined();
|
|
857
|
-
expect(targets['cargo-napi']).toBeUndefined();
|
|
858
|
-
expect(targets['cargo-sweep']?.options).toMatchObject({
|
|
859
|
-
command: 'cargo sweep --time 7',
|
|
860
|
-
cwd: 'packages/ferris',
|
|
861
|
-
});
|
|
862
|
-
expect(targets['cargo-sweep']?.cache).toBe(false);
|
|
863
|
-
// Never cached: the download lands in CARGO_HOME, so a cache hit would
|
|
864
|
-
// report success over a registry that still cannot resolve the lockfile.
|
|
865
|
-
expect(targets['cargo-fetch']?.cache).toBe(false);
|
|
866
|
-
expect(targets['cargo-fetch']?.options).toEqual({
|
|
867
|
-
commands: ['cargo fetch --locked'],
|
|
868
|
-
cwd: 'packages/ferris',
|
|
869
|
-
});
|
|
870
|
-
// Every frozen cargo command carries the edge: offline cargo fails at
|
|
871
|
-
// resolution, so each one needs the locked graph downloaded before it runs.
|
|
872
|
-
for (const name of [
|
|
873
|
-
'cargo-test-compile',
|
|
874
|
-
'cargo-test-archive',
|
|
875
|
-
'cargo-lint',
|
|
876
|
-
CARGO_CROSS_LINT_TARGET,
|
|
877
|
-
'mutation',
|
|
878
|
-
'bench',
|
|
879
|
-
]) {
|
|
880
|
-
expect(targets[name]?.dependsOn).toContain('cargo-fetch');
|
|
881
|
-
}
|
|
882
|
-
expect(targets['cargo-sweep']?.dependsOn).toBeUndefined();
|
|
883
|
-
// The archive and the compile it stands for hash every crate's sources
|
|
884
|
-
// AND the outputs of the targets they depend on: generated crate inputs
|
|
885
|
-
// are gitignored, so a repository that had to restate `inputs` to add
|
|
886
|
-
// them replaced the crate union with the root's `default` and shipped a
|
|
887
|
-
// stale archive to every per-crate test.
|
|
888
|
-
for (const name of ['cargo-test-compile', 'cargo-test-archive', 'cargo-lint', CARGO_CROSS_LINT_TARGET]) {
|
|
889
|
-
const inputs = targets[name]?.inputs ?? [];
|
|
890
|
-
expect(inputs).toContainEqual({ dependentTasksOutputFiles: '**/*', transitive: false });
|
|
891
|
-
expect(inputs).toContain('{workspaceRoot}/packages/ferris/crates/ferris-core/**/*');
|
|
892
|
-
}
|
|
893
|
-
expect(targets['cargo-test-compile']?.executor).toBe('nx:run-commands');
|
|
894
|
-
expect(targets['cargo-test-compile']?.cache).toBe(false);
|
|
895
|
-
expect(targets['cargo-test-compile']?.outputs).toEqual([]);
|
|
896
|
-
expect(targets['cargo-test-compile']?.options).toMatchObject({
|
|
897
|
-
command: 'cargo --frozen test --workspace --no-run',
|
|
898
|
-
cwd: 'packages/ferris',
|
|
899
|
-
});
|
|
900
|
-
expect(targets['cargo-test']?.executor).toBe('nx:noop');
|
|
901
|
-
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-test-ferris-wasm']);
|
|
902
|
-
// One workspace compile, packed once. Every per-crate runner reads that
|
|
903
|
-
// archive, so the runners fan out instead of chaining: none of them
|
|
904
|
-
// builds, re-resolves features, or writes cargo's flocked `target/`.
|
|
905
|
-
expect(targets['cargo-test-archive']?.executor).toBe('nx:run-commands');
|
|
906
|
-
expect(targets['cargo-test-archive']?.cache).toBe(true);
|
|
907
|
-
expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/.cache/nextest/archive.tar.zst']);
|
|
908
|
-
expect(targets['cargo-test-archive']?.options).toMatchObject({ cwd: 'packages/ferris' });
|
|
909
|
-
// nextest does not create the archive's parent directory and fails the
|
|
910
|
-
// whole build if it is missing (measured: "error writing to archive").
|
|
911
|
-
// The directory and the archive are ONE command, in the order the archive needs.
|
|
912
|
-
expect(targets['cargo-test-archive']?.options?.commands).toBeUndefined();
|
|
913
|
-
// `--tool-config-file`, never `--config-file`: the plugin's settings must
|
|
914
|
-
// sit UNDER the repository's `.config/nextest.toml`, which is the only
|
|
915
|
-
// place an `archive.include` for a cdylib or fixture can be declared.
|
|
916
|
-
// `$PWD` because tool config paths must be absolute and an absolute path
|
|
917
|
-
// in the command text would split one cache entry per checkout; through
|
|
918
|
-
// the root `node_modules` link because the plugin's real location is a
|
|
919
|
-
// different number of `../` away from each checkout.
|
|
920
|
-
expect(String(targets['cargo-test-archive']?.options?.command)).toBe(
|
|
921
|
-
'mkdir -p .cache/nextest && cargo --frozen nextest archive --workspace --archive-file .cache/nextest/archive.tar.zst --user-config-file none --tool-config-file "smoo:$PWD/../../node_modules/@smoothbricks/nx-plugin/nextest.toml"',
|
|
922
|
-
);
|
|
923
|
-
expect(targets['cargo-test-archive']?.inputs).toContain('{projectRoot}/.config/nextest.toml');
|
|
924
|
-
// Tests compile the dev profile only. Nx forwards a run's configuration
|
|
925
|
-
// down every edge to each target that has it, so a release configuration
|
|
926
|
-
// here would make a release `build` compile test binaries nobody runs.
|
|
927
|
-
for (const name of ['cargo-test-compile', 'cargo-test-archive', 'cargo-test', 'cargo-test-ferris-core', 'test']) {
|
|
928
|
-
expect(targets[name]).toBeDefined();
|
|
929
|
-
expect(targets[name]?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
|
|
930
|
-
}
|
|
931
|
-
expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
932
|
-
expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
933
|
-
// The runner executes the archive's binaries, unpacked once for every
|
|
934
|
-
// runner by the plugin's helper (through the root `node_modules` link,
|
|
935
|
-
// so the hashed command names no machine path), and remaps the
|
|
936
|
-
// workspace root: without `--workspace-remap`, a restored archive hands
|
|
937
|
-
// tests the PRODUCING tree's absolute CARGO_MANIFEST_DIR (measured on a
|
|
938
|
-
// moved tree). `--workspace` is not merely redundant here, nextest
|
|
939
|
-
// rejects it beside a reused build.
|
|
940
|
-
expect(targets['cargo-test-ferris-core']?.options?.command).toMatch(
|
|
941
|
-
/^extracted="\$\(node \.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/dist\/bin\/smoo-nx-nextest-extract\.js \.cache\/nextest\/archive\.tar\.zst\)" && cargo --frozen nextest run --binaries-metadata "\$extracted\/target\/nextest\/binaries-metadata\.json" --cargo-metadata "\$extracted\/target\/nextest\/cargo-metadata\.json" --target-dir-remap "\$extracted\/target" --workspace-remap \. -E 'package\(ferris-core\)' --no-fail-fast --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/\.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/nextest\.toml"$/,
|
|
942
|
-
);
|
|
943
|
-
expect(targets['cargo-test-ferris-core']?.inputs).toContain(
|
|
944
|
-
'{workspaceRoot}/packages/ferris/.config/nextest.toml',
|
|
945
|
-
);
|
|
946
|
-
expect(targets['cargo-test-ferris-core']?.inputs).toEqual(
|
|
947
|
-
expect.arrayContaining([
|
|
948
|
-
'{workspaceRoot}/packages/ferris/Cargo.toml',
|
|
949
|
-
'{workspaceRoot}/packages/ferris/Cargo.lock',
|
|
950
|
-
'{workspaceRoot}/packages/ferris/crates/ferris-core/**/*',
|
|
951
|
-
]),
|
|
952
|
-
);
|
|
953
|
-
expect(targets['cargo-test-ferris-core']?.inputs).not.toContain(
|
|
954
|
-
'{workspaceRoot}/packages/ferris/crates/ferris-wasm/**/*',
|
|
955
|
-
);
|
|
956
|
-
// One clippy for the workspace, writing the same `target/` as the dev
|
|
957
|
-
// test compile: a directory of its own compiled every host unit twice.
|
|
958
|
-
const [fmt, clippy] = targets['cargo-lint']?.options?.commands ?? [];
|
|
959
|
-
expect(fmt).toBe('cargo fmt --all --check');
|
|
960
|
-
expect(clippy).toBe(CARGO_LINT_CLIPPY_COMMAND);
|
|
961
|
-
expect(clippy).toMatch(/^cargo --frozen clippy --workspace --all-targets /);
|
|
962
|
-
for (const command of [clippy, targets['cargo-test-compile']?.options?.command]) {
|
|
963
|
-
expect(command).not.toContain('--target-dir');
|
|
964
|
-
}
|
|
965
|
-
expect(targets['cargo-lint']?.options?.cwd).toBe(targets['cargo-test-compile']?.options?.cwd);
|
|
966
|
-
expect(targets['cargo-lint']?.cache).toBe(true);
|
|
967
|
-
expect(targets['cargo-lint']?.outputs).toEqual([]);
|
|
968
|
-
expect(targets['cargo-lint']?.inputs).toEqual(
|
|
969
|
-
expect.arrayContaining([
|
|
970
|
-
'{workspaceRoot}/packages/ferris/crates/ferris-core/**/*',
|
|
971
|
-
'{workspaceRoot}/packages/ferris/crates/ferris-wasm/**/*',
|
|
972
|
-
]),
|
|
973
|
-
);
|
|
974
|
-
expect(targets.lint?.dependsOn).toEqual(['cargo-lint']);
|
|
975
|
-
expect(targets[CARGO_CROSS_LINT_TARGET]?.options).toMatchObject({
|
|
976
|
-
command: CARGO_CROSS_LINT_COMMAND,
|
|
977
|
-
cwd: 'packages/ferris',
|
|
978
|
-
});
|
|
979
|
-
expect(targets[CARGO_CROSS_LINT_TARGET]?.cache).toBe(true);
|
|
980
|
-
expect(targets.lint?.dependsOn).not.toContain(CARGO_CROSS_LINT_TARGET);
|
|
981
|
-
expect(targets.test?.executor).toBe('nx:noop');
|
|
982
|
-
expect(targets.test?.dependsOn).toEqual(['cargo-test']);
|
|
983
|
-
expect(targets.mutation?.cache).toBe(false);
|
|
984
|
-
// On bounded-exec, so cargo-mutants' own per-core jobserver is sized to a CPU grant.
|
|
985
|
-
expect(targets.mutation?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
986
|
-
expect(targets.mutation?.options).toMatchObject({
|
|
987
|
-
command: 'cargo --frozen mutants --workspace',
|
|
988
|
-
timeoutMs: 6 * 60 * 60 * 1000,
|
|
989
|
-
});
|
|
990
|
-
expect(targets.bench?.options).toMatchObject({ command: 'cargo --frozen bench --workspace' });
|
|
991
|
-
expectNoSchedulerThrottle(targets);
|
|
992
|
-
} finally {
|
|
993
|
-
await workspace.cleanup();
|
|
994
|
-
}
|
|
995
|
-
});
|
|
996
|
-
|
|
997
|
-
it('cleans every cargo directory its own commands write, including the ones caching refuses', async () => {
|
|
998
|
-
const workspace = await createWorkspace();
|
|
999
|
-
try {
|
|
1000
|
-
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
1001
|
-
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = ["crates/ferris-core"]\n');
|
|
1002
|
-
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
1003
|
-
|
|
1004
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
1005
|
-
|
|
1006
|
-
// A clippy target dir is not an Nx output — restoring a multi-GiB build
|
|
1007
|
-
// tree from a cache is worse than rebuilding it — so `clean` cannot find
|
|
1008
|
-
// these through `outputs`. They are read back off the commands that
|
|
1009
|
-
// write them, which is why a new `--target-dir` cannot be forgotten here.
|
|
1010
|
-
// The workspace `target/` every dev build shares is not one of them.
|
|
1011
|
-
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
1012
|
-
expect(targets.clean?.cache).toBe(false);
|
|
1013
|
-
expect(targets.clean?.options?.outputs).toEqual([
|
|
1014
|
-
'{projectRoot}/dist',
|
|
1015
|
-
'{workspaceRoot}/packages/ferris/.cache/nextest',
|
|
1016
|
-
'{workspaceRoot}/packages/ferris/target/cargo-lint-cross',
|
|
1017
|
-
]);
|
|
1018
|
-
} finally {
|
|
1019
|
-
await workspace.cleanup();
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
|
-
|
|
1023
|
-
it('keeps Rust-only lint source-aware after migrating defaults without replacing mixed or custom lint', async () => {
|
|
1024
|
-
const workspace = await createWorkspace();
|
|
1025
|
-
const root = 'packages/ferris';
|
|
1026
|
-
const defaults = {
|
|
1027
|
-
targetDefaults: {
|
|
1028
|
-
lint: {
|
|
1029
|
-
executor: 'nx:run-commands',
|
|
1030
|
-
options: { commands: ['biome check {projectRoot}', 'eslint {projectRoot}/src'] },
|
|
1031
|
-
},
|
|
1032
|
-
},
|
|
1033
|
-
};
|
|
1034
|
-
applyWorkspaceConfig(defaults);
|
|
1035
|
-
const resolveLint = (targets: Record<string, TargetConfiguration>, declared: TargetConfiguration = {}) => {
|
|
1036
|
-
let lint = targets.lint ?? {};
|
|
1037
|
-
const synthesized = createTargetDefaultsResults(
|
|
1038
|
-
{ [root]: { root, targets } },
|
|
1039
|
-
{ [root]: { root, targets: { lint: declared } } },
|
|
1040
|
-
defaults,
|
|
1041
|
-
);
|
|
1042
|
-
for (const [, , result] of synthesized) {
|
|
1043
|
-
const target = result.projects?.[root]?.targets?.lint;
|
|
1044
|
-
if (target) lint = mergeTargetConfigurations(target, lint);
|
|
1045
|
-
}
|
|
1046
|
-
return mergeTargetConfigurations(declared, lint);
|
|
1047
|
-
};
|
|
1048
|
-
try {
|
|
1049
|
-
await workspace.write('biome.json', '{}\n');
|
|
1050
|
-
await workspace.write('eslint.config.mjs', 'export default [{ files: ["**/*.ts"] }];\n');
|
|
1051
|
-
await workspace.write(`${root}/package.json`, '{"name":"ferris"}\n');
|
|
1052
|
-
await workspace.write(`${root}/Cargo.toml`, '[workspace]\nmembers = ["crates/core"]\n');
|
|
1053
|
-
await workspace.write(`${root}/crates/core/Cargo.toml`, '[package]\nname = "ferris-core"\n');
|
|
1054
|
-
const biome = `biome check --files-ignore-unknown=true '${root}'`;
|
|
1055
|
-
const rust = await inferProjectTargets(workspace, `${root}/package.json`);
|
|
1056
|
-
const rustLint = resolveLint(rust);
|
|
1057
|
-
expect(rustLint.executor).toBe(ALL_VERDICTS_EXECUTOR);
|
|
1058
|
-
expect(rustLint.dependsOn).toEqual(['cargo-lint']);
|
|
1059
|
-
expect(rustLint.options?.commands).toEqual([biome]);
|
|
1060
|
-
|
|
1061
|
-
// A JavaScript source joins ESLint's file list the moment it appears, with no tsconfig to announce it.
|
|
1062
|
-
await workspace.write(`${root}/src/check.js`, 'debugger;\n');
|
|
1063
|
-
const withJavaScript = resolveLint(await inferProjectTargets(workspace, `${root}/package.json`));
|
|
1064
|
-
expect(withJavaScript.executor).toBe(ALL_VERDICTS_EXECUTOR);
|
|
1065
|
-
expect(withJavaScript.dependsOn).toEqual(['cargo-lint']);
|
|
1066
|
-
expect(withJavaScript.options?.commands).toEqual([biome, `eslint '${root}/src/check.js'`]);
|
|
1067
|
-
|
|
1068
|
-
const custom = { executor: 'nx:run-commands', options: { command: 'custom-linter package.json' } };
|
|
1069
|
-
await workspace.write(
|
|
1070
|
-
`${root}/package.json`,
|
|
1071
|
-
JSON.stringify({ name: 'ferris', nx: { targets: { lint: custom } } }),
|
|
1072
|
-
);
|
|
1073
|
-
const declared = await inferProjectTargets(workspace, `${root}/package.json`);
|
|
1074
|
-
expect(resolveLint(declared, custom).options?.command).toBe(custom.options.command);
|
|
1075
|
-
|
|
1076
|
-
await workspace.write(`${root}/package.json`, '{"name":"ferris"}\n');
|
|
1077
|
-
await workspace.write(`${root}/tsconfig.lib.json`, '{"compilerOptions":{"outDir":"dist"}}\n');
|
|
1078
|
-
await workspace.write(`${root}/src/index.ts`, 'export const value = 1;\n');
|
|
1079
|
-
const mixed = await inferProjectTargets(workspace, `${root}/package.json`);
|
|
1080
|
-
expect(resolveLint(mixed).options?.commands).toEqual([
|
|
1081
|
-
biome,
|
|
1082
|
-
`eslint '${root}/src/check.js' '${root}/src/index.ts'`,
|
|
1083
|
-
]);
|
|
1084
|
-
expectNoSchedulerThrottle(mixed);
|
|
1085
|
-
} finally {
|
|
1086
|
-
await workspace.cleanup();
|
|
1087
|
-
}
|
|
1088
|
-
});
|
|
1089
|
-
|
|
1090
|
-
it('lints the declared test program outside src and keys its sources and inherited declaration', async () => {
|
|
1091
|
-
const workspace = await createWorkspace();
|
|
1092
|
-
try {
|
|
1093
|
-
await workspace.write('eslint.config.mjs', 'export default [{ files: ["**/*.ts"] }];\n');
|
|
1094
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
1095
|
-
await workspace.write(
|
|
1096
|
-
'packages/test-base.json',
|
|
1097
|
-
JSON.stringify({
|
|
1098
|
-
include: ['\u0024{configDir}/tests/**/*.ts'],
|
|
1099
|
-
exclude: ['\u0024{configDir}/tests/excluded.ts'],
|
|
1100
|
-
files: ['contract/schema.d.ts'],
|
|
1101
|
-
}),
|
|
1102
|
-
);
|
|
1103
|
-
await workspace.write('packages/example/tsconfig.test.json', '{"extends":"../test-base.json"}\n');
|
|
1104
|
-
await workspace.write('packages/example/src/index.ts', 'export const value = 1;\n');
|
|
1105
|
-
await workspace.write('packages/example/tests/check.test.ts', 'export const check = 1;\n');
|
|
1106
|
-
await workspace.write('packages/example/tests/helper.ts', 'export const helper = 1;\n');
|
|
1107
|
-
await workspace.write('packages/example/tests/excluded.ts', 'export const excluded = 1;\n');
|
|
1108
|
-
await workspace.write('packages/example/other/stray.test.ts', 'export const stray = 1;\n');
|
|
1109
|
-
await workspace.write('packages/contract/schema.d.ts', 'export interface Contract { value: number }\n');
|
|
1110
|
-
|
|
1111
|
-
const { lint } = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
1112
|
-
expect(lint?.options?.commands).toEqual([
|
|
1113
|
-
"eslint 'packages/contract/schema.d.ts' 'packages/example/src/index.ts' 'packages/example/tests/check.test.ts' 'packages/example/tests/helper.ts'",
|
|
1114
|
-
]);
|
|
1115
|
-
expect(lint?.metadata?.eslintFileSet).toEqual({
|
|
1116
|
-
command: lint?.options?.commands?.[0],
|
|
1117
|
-
files: [
|
|
1118
|
-
'packages/contract/schema.d.ts',
|
|
1119
|
-
'packages/example/src/index.ts',
|
|
1120
|
-
'packages/example/tests/check.test.ts',
|
|
1121
|
-
'packages/example/tests/helper.ts',
|
|
1122
|
-
],
|
|
1123
|
-
});
|
|
1124
|
-
expect(isEslintFileSet(lint?.metadata?.eslintFileSet)).toBe(true);
|
|
1125
|
-
expect(isEslintFileSet({ command: 'eslint invalid', files: [null] })).toBe(false);
|
|
1126
|
-
expect(lint?.inputs).toEqual(
|
|
1127
|
-
expect.arrayContaining([
|
|
1128
|
-
'{projectRoot}/tsconfig.test.json',
|
|
1129
|
-
'{workspaceRoot}/packages/test-base.json',
|
|
1130
|
-
'{workspaceRoot}/packages/contract/schema.d.ts',
|
|
1131
|
-
'{workspaceRoot}/packages/example/tests/check.test.ts',
|
|
1132
|
-
'{workspaceRoot}/packages/example/tests/helper.ts',
|
|
1133
|
-
]),
|
|
1134
|
-
);
|
|
1135
|
-
expect(lint?.inputs).not.toContain('{workspaceRoot}/packages/example/tests/excluded.ts');
|
|
1136
|
-
expect(lint?.inputs).not.toContain('{workspaceRoot}/packages/example/other/stray.test.ts');
|
|
1137
|
-
} finally {
|
|
1138
|
-
await workspace.cleanup();
|
|
1139
|
-
}
|
|
1140
|
-
});
|
|
1141
|
-
|
|
1142
|
-
it('lints and keys only the sources Nx indexes, never ignored files a build left on disk', async () => {
|
|
1143
|
-
const workspace = await createWorkspace();
|
|
1144
|
-
try {
|
|
1145
|
-
await workspace.write('eslint.config.mjs', 'export default [{ files: ["**/*.ts"] }];\n');
|
|
1146
|
-
// Generated outputs one build wrote and a fresh checkout lacks: a root ignore, a
|
|
1147
|
-
// project-level one, and an .nxignore, the three ways Nx keeps a file out of its index.
|
|
1148
|
-
await workspace.write('.gitignore', 'packages/example/src/generated/\n');
|
|
1149
|
-
await workspace.write('packages/example/.gitignore', '*.generated.ts\n');
|
|
1150
|
-
await workspace.write('.nxignore', 'packages/example/tests/nx-ignored.ts\n');
|
|
1151
|
-
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
1152
|
-
await workspace.write('packages/example/tsconfig.test.json', '{"include":["tests/**/*.ts"]}\n');
|
|
1153
|
-
await workspace.write('packages/example/src/index.ts', 'export const value = 1;\n');
|
|
1154
|
-
await workspace.write('packages/example/src/generated/schemas.gen.ts', 'export const schemas = 1;\n');
|
|
1155
|
-
await workspace.write('packages/example/src/catalog.generated.ts', 'export const catalog = 1;\n');
|
|
1156
|
-
await workspace.write('packages/example/tests/check.test.ts', 'export const check = 1;\n');
|
|
1157
|
-
await workspace.write('packages/example/tests/helpers/catalog.generated.ts', 'export const c = 1;\n');
|
|
1158
|
-
await workspace.write('packages/example/tests/nx-ignored.ts', 'export const ignored = 1;\n');
|
|
1159
|
-
|
|
1160
|
-
const { lint } = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
1161
|
-
const files = ['packages/example/src/index.ts', 'packages/example/tests/check.test.ts'];
|
|
1162
|
-
expect(lint?.metadata?.eslintFileSet).toEqual({
|
|
1163
|
-
command: `eslint ${files.map((file) => `'${file}'`).join(' ')}`,
|
|
1164
|
-
files,
|
|
1165
|
-
});
|
|
1166
|
-
expect(lint?.options?.commands).toEqual([lint?.metadata?.eslintFileSet.command]);
|
|
1167
|
-
const programInputs = (lint?.inputs ?? []).filter(
|
|
1168
|
-
(input): input is string => typeof input === 'string' && input.startsWith('{workspaceRoot}/packages/example/'),
|
|
1169
|
-
);
|
|
1170
|
-
expect(programInputs).toEqual(['{workspaceRoot}/packages/example/tests/check.test.ts']);
|
|
1171
|
-
} finally {
|
|
1172
|
-
await workspace.cleanup();
|
|
1173
|
-
}
|
|
1174
|
-
});
|
|
1175
|
-
|
|
1176
|
-
it('attributes one repository-root Cargo workspace across package projects', async () => {
|
|
1177
|
-
const workspace = await createWorkspace();
|
|
1178
|
-
try {
|
|
1179
|
-
await workspace.write('package.json', '{"name":"@fixture/codebase"}\n');
|
|
1180
|
-
await workspace.write('packages/runtime/package.json', '{"name":"@fixture/runtime","nx":{"name":"runtime"}}\n');
|
|
1181
|
-
await workspace.write('packages/wasm/package.json', '{"name":"@fixture/wasm","nx":{"name":"wasm"}}\n');
|
|
1182
|
-
await workspace.write(
|
|
1183
|
-
'packages/native/package.json',
|
|
1184
|
-
JSON.stringify({
|
|
1185
|
-
name: '@fixture/native',
|
|
1186
|
-
nx: { name: 'native' },
|
|
1187
|
-
napi: {
|
|
1188
|
-
binaryName: 'native',
|
|
1189
|
-
targets: ['aarch64-apple-darwin'],
|
|
1190
|
-
},
|
|
1191
|
-
}),
|
|
1192
|
-
);
|
|
1193
|
-
await workspace.write(
|
|
1194
|
-
'Cargo.toml',
|
|
1195
|
-
[
|
|
1196
|
-
'[workspace]',
|
|
1197
|
-
'members = ["packages/runtime/crates/*", "packages/wasm", "packages/native/crates/*"]',
|
|
1198
|
-
'',
|
|
1199
|
-
].join('\n'),
|
|
1200
|
-
);
|
|
1201
|
-
await workspace.write(
|
|
1202
|
-
'packages/runtime/crates/runtime-core/Cargo.toml',
|
|
1203
|
-
'[package]\nname = "runtime-core"\n\n[package.metadata.smoothbricks.test]\nshards = 2\n',
|
|
1204
|
-
);
|
|
1205
|
-
await workspace.write(
|
|
1206
|
-
'packages/wasm/Cargo.toml',
|
|
1207
|
-
[
|
|
1208
|
-
'[package]',
|
|
1209
|
-
'name = "runtime-wasm"',
|
|
1210
|
-
'',
|
|
1211
|
-
'[lib]',
|
|
1212
|
-
'crate-type = ["cdylib", "rlib"]',
|
|
1213
|
-
'',
|
|
1214
|
-
'[package.metadata.smoothbricks.wasm-bindgen]',
|
|
1215
|
-
'targets = ["web"]',
|
|
1216
|
-
'',
|
|
1217
|
-
].join('\n'),
|
|
1218
|
-
);
|
|
1219
|
-
await workspace.write(
|
|
1220
|
-
'packages/native/crates/native-napi/Cargo.toml',
|
|
1221
|
-
'[package]\nname = "native-napi"\n\n[lib]\ncrate-type = ["cdylib"]\n',
|
|
1222
|
-
);
|
|
1223
|
-
|
|
1224
|
-
const inferred = await inferTargets(
|
|
1225
|
-
['package.json', 'packages/runtime/package.json', 'packages/wasm/package.json', 'packages/native/package.json'],
|
|
1226
|
-
undefined,
|
|
1227
|
-
workspace.context,
|
|
1228
|
-
);
|
|
1229
|
-
const projects = new Map(inferred.flatMap(([, result]) => Object.entries(result.projects ?? {})));
|
|
1230
|
-
const root = projects.get('.')?.targets ?? {};
|
|
1231
|
-
const runtime = projects.get('packages/runtime')?.targets ?? {};
|
|
1232
|
-
const wasm = projects.get('packages/wasm')?.targets ?? {};
|
|
1233
|
-
const native = projects.get('packages/native')?.targets ?? {};
|
|
1234
|
-
const rootProject = '@fixture/codebase';
|
|
1235
|
-
const rootFetch = { projects: [rootProject], target: 'cargo-fetch' };
|
|
1236
|
-
const rootCompile = { projects: [rootProject], target: 'cargo-test-compile' };
|
|
1237
|
-
const rootArchive = { projects: [rootProject], target: 'cargo-test-archive' };
|
|
1238
|
-
|
|
1239
|
-
expect(
|
|
1240
|
-
[...projects]
|
|
1241
|
-
.filter(([, project]) => project.targets?.['cargo-test-compile'])
|
|
1242
|
-
.map(([projectRoot]) => projectRoot),
|
|
1243
|
-
).toEqual(['.']);
|
|
1244
|
-
expect(root['cargo-fetch']?.options).toEqual({
|
|
1245
|
-
commands: ['cargo fetch --locked'],
|
|
1246
|
-
cwd: '.',
|
|
1247
|
-
});
|
|
1248
|
-
expect(root['cargo-test-compile']?.options).toMatchObject({
|
|
1249
|
-
command: 'cargo --frozen test --workspace --no-run',
|
|
1250
|
-
cwd: '.',
|
|
1251
|
-
});
|
|
1252
|
-
// The root owns the one workspace clippy, run where the dev build runs.
|
|
1253
|
-
expect(String(root['cargo-lint']?.options?.commands?.[1])).toContain('clippy --workspace');
|
|
1254
|
-
expect(root['cargo-lint']?.options?.cwd).toBe(root['cargo-test-compile']?.options?.cwd);
|
|
1255
|
-
expect(root['cargo-lint']?.dependsOn).toContain('cargo-fetch');
|
|
1256
|
-
expect(root['cargo-test']?.dependsOn).toHaveLength(6);
|
|
1257
|
-
|
|
1258
|
-
// Root mode: every piece of every project hangs off the one root archive,
|
|
1259
|
-
// in any order. The crate is selected by filterset alone — `-p` would
|
|
1260
|
-
// re-resolve features, and there is nothing left to build anyway.
|
|
1261
|
-
expect(runtime['cargo-test-runtime-core-shard1']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1262
|
-
expect(runtime['cargo-test-runtime-core-shard2']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1263
|
-
expect(runtime['cargo-test-runtime-core-exceptions-shard1']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1264
|
-
expect(runtime['cargo-test-runtime-core-exceptions-shard2']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1265
|
-
expect(runtime['cargo-test-runtime-core-shard1']?.options).toMatchObject({ cwd: '.' });
|
|
1266
|
-
// At the root the helper and the plugin's nextest config are the root's
|
|
1267
|
-
// own `node_modules` link, no `../`.
|
|
1268
|
-
expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toStartWith(
|
|
1269
|
-
'extracted="$(node node_modules/@smoothbricks/nx-plugin/dist/bin/smoo-nx-nextest-extract.js .cache/nextest/archive.tar.zst)" && ',
|
|
1270
|
-
);
|
|
1271
|
-
expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toContain(
|
|
1272
|
-
`--target-dir-remap "$extracted/target" --workspace-remap . -E 'package(runtime-core)`,
|
|
1273
|
-
);
|
|
1274
|
-
expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toEndWith(
|
|
1275
|
-
'--tool-config-file "smoo:$PWD/node_modules/@smoothbricks/nx-plugin/nextest.toml"',
|
|
1276
|
-
);
|
|
1277
|
-
expect(native['cargo-test-native-napi']?.options?.command).toContain('--no-tests=pass');
|
|
1278
|
-
expect(runtime['cargo-test']?.dependsOn).toEqual([
|
|
1279
|
-
'cargo-test-runtime-core-shard1',
|
|
1280
|
-
'cargo-test-runtime-core-shard2',
|
|
1281
|
-
'cargo-test-runtime-core-exceptions-shard1',
|
|
1282
|
-
'cargo-test-runtime-core-exceptions-shard2',
|
|
1283
|
-
]);
|
|
1284
|
-
// A package owning crates validates through the root's one clippy verdict.
|
|
1285
|
-
expect(runtime['cargo-lint']?.dependsOn).toEqual([{ projects: [rootProject], target: 'cargo-lint' }]);
|
|
1286
|
-
expect(runtime.lint?.dependsOn).toEqual(['cargo-lint']);
|
|
1287
|
-
expect(runtime['cargo-lint-runtime-core']).toBeUndefined();
|
|
1288
|
-
expect(runtime.clean).toBeUndefined();
|
|
1289
|
-
|
|
1290
|
-
expect(wasm['cargo-test-runtime-wasm']?.dependsOn).toEqual([rootFetch, rootArchive]);
|
|
1291
|
-
expect(wasm['cargo-wasm']?.inputs).toContain(CARGO_CLOSURE_INPUT);
|
|
1292
|
-
expect(wasm['cargo-wasm']?.inputs).not.toContain('{workspaceRoot}/**/*.rs');
|
|
1293
|
-
expect(wasm['cargo-wasm']?.options).toMatchObject({ cwd: '.' });
|
|
1294
|
-
// Dev by default, in the workspace's own `target/`; only the release
|
|
1295
|
-
// configuration compiles, and binds, the release artifact.
|
|
1296
|
-
expect(wasm['cargo-wasm']?.options?.command).toBe(
|
|
1297
|
-
[
|
|
1298
|
-
'cargo --frozen build --target wasm32-unknown-unknown -p runtime-wasm',
|
|
1299
|
-
'wasm-bindgen --target web --out-dir packages/wasm/dist-wasm/web target/wasm32-unknown-unknown/debug/runtime_wasm.wasm',
|
|
1300
|
-
].join(' && '),
|
|
1301
|
-
);
|
|
1302
|
-
expect(wasm['cargo-wasm']?.options?.commands).toBeUndefined();
|
|
1303
|
-
expect(wasm['cargo-wasm']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
|
|
1304
|
-
command: [
|
|
1305
|
-
'cargo --frozen build --release --target wasm32-unknown-unknown -p runtime-wasm',
|
|
1306
|
-
'wasm-bindgen --target web --out-dir packages/wasm/dist-wasm/web target/wasm32-unknown-unknown/release/runtime_wasm.wasm',
|
|
1307
|
-
].join(' && '),
|
|
1308
|
-
});
|
|
1309
|
-
expect(wasm['cargo-wasm']?.outputs).toEqual(['{projectRoot}/dist-wasm']);
|
|
1310
|
-
expect(wasm['cargo-wasm']?.dependsOn).toEqual([rootFetch, '^build']);
|
|
1311
|
-
expect(wasm.build?.dependsOn).toContainEqual(rootCompile);
|
|
1312
|
-
expect(wasm.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
1313
|
-
|
|
1314
|
-
// The crate whose project also builds the debug cdylib keeps that edge:
|
|
1315
|
-
// its tests load the artifact `napi-debug` writes into `target/debug`.
|
|
1316
|
-
expect(native['cargo-test-native-napi']?.dependsOn).toEqual([rootFetch, rootArchive, 'napi-debug']);
|
|
1317
|
-
// The addon build consumes only its dependencies' outputs; it is not
|
|
1318
|
-
// ordered behind the test compile.
|
|
1319
|
-
expect(native['napi-debug']?.dependsOn).toEqual(['^build']);
|
|
1320
|
-
// The addon depends on the package's napi block and the napi CLI's version,
|
|
1321
|
-
// never on the package version or the whole lockfile: a release bumps both
|
|
1322
|
-
// before it builds, and that must not recompile the native code.
|
|
1323
|
-
const napiInputs = native['napi-debug']?.inputs ?? [];
|
|
1324
|
-
expect(napiInputs).toContainEqual({ externalDependencies: ['@napi-rs/cli'] });
|
|
1325
|
-
expect(
|
|
1326
|
-
napiInputs.some((input) => typeof input === 'object' && 'runtime' in input && input.runtime.includes('.napi')),
|
|
1327
|
-
).toBe(true);
|
|
1328
|
-
for (const [name, target] of Object.entries(native)) {
|
|
1329
|
-
if (!name.startsWith('napi-') || target.cache !== true) continue;
|
|
1330
|
-
expect(target.inputs).toContain(CARGO_CLOSURE_INPUT);
|
|
1331
|
-
expect(target.inputs).not.toContain('{workspaceRoot}/**/*.rs');
|
|
1332
|
-
}
|
|
1333
|
-
const nativeClosure = projects.get('packages/native')?.namedInputs?.[CARGO_CLOSURE_INPUT] ?? [];
|
|
1334
|
-
expect(nativeClosure).toContain(
|
|
1335
|
-
'{workspaceRoot}/packages/native/crates/native-napi/**/{*.rs,Cargo.toml,.cargo/config,.cargo/config.toml}',
|
|
1336
|
-
);
|
|
1337
|
-
expect(nativeClosure.some((input) => typeof input === 'string' && input.includes('packages/runtime'))).toBe(
|
|
1338
|
-
false,
|
|
1339
|
-
);
|
|
1340
|
-
expect(napiInputs).not.toContain('{workspaceRoot}/bun.lock');
|
|
1341
|
-
expect(napiInputs.some((input) => typeof input === 'string' && input.endsWith('/package.json'))).toBe(false);
|
|
1342
|
-
// ... and on the toolchain pin, which it must state itself: `napi build`
|
|
1343
|
-
// compiles with the pinned rustc but never spells `cargo --frozen`, so
|
|
1344
|
-
// the sweep that gives every other cargo target its identity skips it.
|
|
1345
|
-
expect(napiInputs).toContain('{workspaceRoot}/devenv.lock');
|
|
1346
|
-
expect(napiInputs).toContain('{workspaceRoot}/tooling/direnv/devenv.lock');
|
|
1347
|
-
expect(native['napi-debug']?.options).toMatchObject({
|
|
1348
|
-
cwd: '.',
|
|
1349
|
-
command:
|
|
1350
|
-
'packages/native/node_modules/.bin/napi build --platform --no-js --dts native.napi.d.ts --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --package-json-path packages/native/package.json --output-dir packages/native/.cache/native-debug',
|
|
1351
|
-
});
|
|
1352
|
-
const platformBuild = (release: string): string =>
|
|
1353
|
-
`packages/native/node_modules/.bin/napi build${release} --platform --no-js --dts native.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --package-json-path packages/native/package.json --output-dir packages/native/dist/native/darwin-arm64`;
|
|
1354
|
-
expect(native['napi-arm64-macos']?.options).toMatchObject({ cwd: '.', command: platformBuild('') });
|
|
1355
|
-
expect(native['napi-arm64-macos']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
|
|
1356
|
-
command: platformBuild(' --release'),
|
|
1357
|
-
});
|
|
1358
|
-
expect(native.build?.dependsOn).toContainEqual(rootCompile);
|
|
1359
|
-
expect(native.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
1360
|
-
for (const inferred of [root, runtime, wasm, native]) {
|
|
1361
|
-
expectNoSchedulerThrottle(inferred);
|
|
1362
|
-
}
|
|
1363
|
-
} finally {
|
|
1364
|
-
await workspace.cleanup();
|
|
1365
|
-
}
|
|
1366
|
-
});
|
|
1367
|
-
|
|
1368
|
-
it('keeps root packages, nested workspaces and multiple owned crates in their own lint graph', async () => {
|
|
1369
|
-
const workspace = await createWorkspace();
|
|
1370
|
-
const declared: Record<string, TargetConfiguration> = {
|
|
1371
|
-
'cargo-lint': { dependsOn: ['...', 'prepare-check'] },
|
|
1372
|
-
lint: { dependsOn: ['cargo-lint', 'custom-check'] },
|
|
1373
|
-
};
|
|
1374
|
-
try {
|
|
1375
|
-
await workspace.write('package.json', '{"name":"outer-root"}\n');
|
|
1376
|
-
await workspace.write(
|
|
1377
|
-
'Cargo.toml',
|
|
1378
|
-
'[workspace]\nmembers = ["packages/group/crates/*"]\nexclude = ["nested"]\n\n[package]\nname = "host-core"\n',
|
|
1379
|
-
);
|
|
1380
|
-
await workspace.write(
|
|
1381
|
-
'packages/group/package.json',
|
|
1382
|
-
JSON.stringify({ name: 'group', nx: { targets: declared } }),
|
|
1383
|
-
);
|
|
1384
|
-
await workspace.write('packages/group/tsconfig.lib.json', '{}\n');
|
|
1385
|
-
await workspace.write('packages/group/crates/alpha/Cargo.toml', '[package]\nname = "alpha-core"\n');
|
|
1386
|
-
await workspace.write('packages/group/crates/beta/Cargo.toml', '[package]\nname = "beta-wasm"\n');
|
|
1387
|
-
await workspace.write('nested/package.json', '{"name":"inner-root"}\n');
|
|
1388
|
-
await workspace.write(
|
|
1389
|
-
'nested/Cargo.toml',
|
|
1390
|
-
'[workspace]\nmembers = ["modules/leaf"]\n\n[package]\nname = "inner-host"\n',
|
|
1391
|
-
);
|
|
1392
|
-
await workspace.write('nested/modules/leaf/package.json', '{"name":"inner-leaf-project"}\n');
|
|
1393
|
-
await workspace.write('nested/modules/leaf/Cargo.toml', '[package]\nname = "inner-leaf"\n');
|
|
1394
|
-
const inferred = await inferTargets(
|
|
1395
|
-
['package.json', 'packages/group/package.json', 'nested/package.json', 'nested/modules/leaf/package.json'],
|
|
1396
|
-
undefined,
|
|
1397
|
-
workspace.context,
|
|
1398
|
-
);
|
|
1399
|
-
const projects = new Map(inferred.flatMap(([, result]) => Object.entries(result.projects ?? {})));
|
|
1400
|
-
const outer = projects.get('.')?.targets ?? {};
|
|
1401
|
-
const group = projects.get('packages/group')?.targets ?? {};
|
|
1402
|
-
const inner = projects.get('nested')?.targets ?? {};
|
|
1403
|
-
const leaf = projects.get('nested/modules/leaf')?.targets ?? {};
|
|
1404
|
-
// Each cargo workspace root runs one clippy over all its members; the
|
|
1405
|
-
// packages owning crates validate through that verdict.
|
|
1406
|
-
expect(outer['cargo-lint']?.options?.cwd).toBe('.');
|
|
1407
|
-
expect(String(outer['cargo-lint']?.options?.commands?.[1])).toContain('clippy --workspace');
|
|
1408
|
-
// Workspace-anchored, because Nx hashes a `{projectRoot}` glob against
|
|
1409
|
-
// only the files its project owns, and the group project owns alpha and
|
|
1410
|
-
// beta: spelled from the root project, those globs hash nothing and the
|
|
1411
|
-
// archive replays stale binaries against edited crates.
|
|
1412
|
-
for (const name of ['cargo-lint', 'cargo-test-archive']) {
|
|
1413
|
-
expect(outer[name]?.inputs).toEqual(
|
|
1414
|
-
expect.arrayContaining([
|
|
1415
|
-
'{workspaceRoot}/packages/group/crates/alpha/**/*',
|
|
1416
|
-
'{workspaceRoot}/packages/group/crates/beta/**/*',
|
|
1417
|
-
]),
|
|
1418
|
-
);
|
|
1419
|
-
expect(
|
|
1420
|
-
(outer[name]?.inputs ?? []).filter(
|
|
1421
|
-
(input) => typeof input === 'string' && input.startsWith('{projectRoot}/packages/'),
|
|
1422
|
-
),
|
|
1423
|
-
).toEqual([]);
|
|
1424
|
-
}
|
|
1425
|
-
expect(group['cargo-lint']?.dependsOn).toEqual([{ projects: ['outer-root'], target: 'cargo-lint' }]);
|
|
1426
|
-
expect(group.build?.dependsOn).toEqual([
|
|
1427
|
-
'^build',
|
|
1428
|
-
{ projects: ['outer-root'], target: 'cargo-test-compile' },
|
|
1429
|
-
'tsc-js',
|
|
1430
|
-
]);
|
|
1431
|
-
expect(outer['cargo-lint-host-core']).toBeUndefined();
|
|
1432
|
-
expect(inner['cargo-lint']?.options).toMatchObject({ cwd: 'nested' });
|
|
1433
|
-
expect(inner['cargo-lint']?.inputs).toContain('{workspaceRoot}/nested/**/*');
|
|
1434
|
-
expect(inner['cargo-lint']?.inputs).toContain('{workspaceRoot}/nested/modules/leaf/**/*');
|
|
1435
|
-
expect(inner['cargo-lint']?.inputs).not.toContain('{workspaceRoot}/packages/group/crates/alpha/**/*');
|
|
1436
|
-
expect(leaf['cargo-lint']?.dependsOn).toEqual([{ projects: ['inner-root'], target: 'cargo-lint' }]);
|
|
1437
|
-
expect(leaf['cargo-lint-inner-leaf']).toBeUndefined();
|
|
1438
|
-
expect(leaf['cargo-test-inner-leaf']?.options?.cwd).toBe('nested');
|
|
1439
|
-
expect(inner['cargo-test-compile']?.options?.cwd).toBe('nested');
|
|
1440
|
-
expect(leaf['cargo-test-inner-leaf']?.dependsOn).toEqual([
|
|
1441
|
-
{ projects: ['inner-root'], target: 'cargo-fetch' },
|
|
1442
|
-
{ projects: ['inner-root'], target: 'cargo-test-archive' },
|
|
1443
|
-
]);
|
|
1444
|
-
expect(inner['cargo-test-archive']?.options?.cwd).toBe('nested');
|
|
1445
|
-
expect(resolveDeclaredOverInferred(group, declared, 'cargo-lint')).toMatchObject({
|
|
1446
|
-
executor: 'nx:noop',
|
|
1447
|
-
cache: true,
|
|
1448
|
-
outputs: [],
|
|
1449
|
-
dependsOn: [{ projects: ['outer-root'], target: 'cargo-lint' }, 'prepare-check'],
|
|
1450
|
-
});
|
|
1451
|
-
expect(resolveDeclaredOverInferred(group, declared, 'lint')?.dependsOn).toEqual(['cargo-lint', 'custom-check']);
|
|
1452
|
-
} finally {
|
|
1453
|
-
await workspace.cleanup();
|
|
1454
|
-
}
|
|
1455
|
-
});
|
|
1456
|
-
|
|
1457
|
-
it('keys every cached cargo target on the declared toolchain pin', async () => {
|
|
1458
|
-
const workspace = await createWorkspace();
|
|
1459
|
-
try {
|
|
1460
|
-
await writeCargoIdentityFixture(workspace);
|
|
1461
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
1462
|
-
const cached = cachedCargoTargets(targets);
|
|
1463
|
-
|
|
1464
|
-
// Named, so a family that stops being cached — or a new one that starts —
|
|
1465
|
-
// shows up here rather than silently leaving the sweep below empty.
|
|
1466
|
-
expect(cached.map(([name]) => name).sort()).toEqual([
|
|
1467
|
-
'cargo-cross-test-archive-aarch64-apple-darwin',
|
|
1468
|
-
'cargo-lint',
|
|
1469
|
-
'cargo-lint-cross',
|
|
1470
|
-
'cargo-test-archive',
|
|
1471
|
-
'cargo-test-ferris-core',
|
|
1472
|
-
]);
|
|
1473
|
-
// An SDK or toolchain change must invalidate every one of them. The pin
|
|
1474
|
-
// is the only thing in the identity that can see one, and it is declared
|
|
1475
|
-
// at both fleet locations because a fileset matching nothing is free.
|
|
1476
|
-
for (const [name, target] of cached) {
|
|
1477
|
-
const declared = (target.inputs ?? []).filter(
|
|
1478
|
-
(input) => typeof input === 'string' && input.endsWith('devenv.lock'),
|
|
1479
|
-
);
|
|
1480
|
-
expect([name, declared]).toEqual([
|
|
1481
|
-
name,
|
|
1482
|
-
['{workspaceRoot}/devenv.lock', '{workspaceRoot}/tooling/direnv/devenv.lock'],
|
|
1483
|
-
]);
|
|
1484
|
-
}
|
|
1485
|
-
} finally {
|
|
1486
|
-
await workspace.cleanup();
|
|
1487
|
-
}
|
|
1488
|
-
});
|
|
1489
|
-
|
|
1490
|
-
// Without an `externalDependencies` input Nx keys a task whose executor is
|
|
1491
|
-
// not an `@nx/` one on every package in the lockfile, so a lockfile-only
|
|
1492
|
-
// commit re-ran every cargo verdict (measured in a consumer: every cargo-test-*
|
|
1493
|
-
// runner and the archive re-keyed on a one-integrity bun.lock edit). Here
|
|
1494
|
-
// the plugin is this repository's workspace project, which Nx refuses as an
|
|
1495
|
-
// external dependency, so each target names none.
|
|
1496
|
-
it('keys every cached cargo target on the npm packages it runs, not the lockfile', async () => {
|
|
1497
|
-
const workspace = await createWorkspace();
|
|
1498
|
-
try {
|
|
1499
|
-
await writeCargoIdentityFixture(workspace);
|
|
1500
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
1501
|
-
const cached = cachedCargoTargets(targets);
|
|
1502
|
-
expect(cached.length).toBeGreaterThan(0);
|
|
1503
|
-
for (const [name, target] of cached) {
|
|
1504
|
-
const named = (target.inputs ?? []).filter(
|
|
1505
|
-
(input) => typeof input === 'object' && 'externalDependencies' in input,
|
|
1506
|
-
);
|
|
1507
|
-
expect([name, named]).toEqual([name, [{ externalDependencies: [] }]]);
|
|
1508
|
-
}
|
|
1509
|
-
} finally {
|
|
1510
|
-
await workspace.cleanup();
|
|
1511
|
-
}
|
|
1512
|
-
});
|
|
1513
|
-
|
|
1514
|
-
it('names the installed plugin for a cargo target that runs its executor or files, and nothing for cargo alone', () => {
|
|
1515
|
-
const plugin = 'node_modules/.bun/@smoothbricks+nx-plugin@0.4.26/node_modules/@smoothbricks/nx-plugin';
|
|
1516
|
-
const runner = { executor: '@smoothbricks/nx-plugin:bounded-exec' };
|
|
1517
|
-
const archive = `cargo --frozen nextest archive --workspace --tool-config-file "smoo:$PWD/${plugin}/nextest.toml"`;
|
|
1518
|
-
const clippy = CARGO_LINT_CLIPPY_COMMAND;
|
|
1519
|
-
expect(cargoCommandNpmPackages(runner, 'cargo --frozen nextest run', true)).toEqual(['@smoothbricks/nx-plugin']);
|
|
1520
|
-
expect(cargoCommandNpmPackages({ executor: 'nx:run-commands' }, archive, true)).toEqual([
|
|
1521
|
-
'@smoothbricks/nx-plugin',
|
|
1522
|
-
]);
|
|
1523
|
-
expect(cargoCommandNpmPackages({ executor: 'nx:run-commands' }, clippy, true)).toEqual([]);
|
|
1524
|
-
expect(cargoCommandNpmPackages(runner, archive, false)).toEqual([]);
|
|
1525
|
-
});
|
|
1526
|
-
|
|
1527
|
-
// The property that decides whether Rust can ever use a shared cache. A cargo
|
|
1528
|
-
// target's identity used to include a dump of the ambient cargo environment,
|
|
1529
|
-
// whose values are absolute `/nix/store/…` and per-checkout devenv state
|
|
1530
|
-
// paths: no two machines agreed, and the same target hashed differently in a
|
|
1531
|
-
// bare shell and inside a devenv profile, which made the pre-push
|
|
1532
|
-
// cross-compile probe unsatisfiable by construction.
|
|
1533
|
-
//
|
|
1534
|
-
// The runtime value AND its command declaration must be portable: Nx also
|
|
1535
|
-
// hashes the owning project's target configuration.
|
|
1536
|
-
it('hashes no machine-local value into a cached cargo target', async () => {
|
|
1537
|
-
const workspace = await createWorkspace();
|
|
1538
|
-
try {
|
|
1539
|
-
await writeCargoIdentityFixture(workspace);
|
|
1540
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
1541
|
-
// Installed the way a consumer links it, so the inputs find the wrapper they name. After
|
|
1542
|
-
// inference, whose fixture walk would follow the link.
|
|
1543
|
-
await mkdir(join(workspace.context.workspaceRoot, 'node_modules/@smoothbricks'), { recursive: true });
|
|
1544
|
-
await symlink(
|
|
1545
|
-
fileURLToPath(new URL('..', import.meta.url)),
|
|
1546
|
-
join(workspace.context.workspaceRoot, 'node_modules/@smoothbricks/nx-plugin'),
|
|
1547
|
-
);
|
|
1548
|
-
const offenders: string[] = [];
|
|
1549
|
-
for (const [name, target] of cachedCargoTargets(targets)) {
|
|
1550
|
-
for (const input of target.inputs ?? []) {
|
|
1551
|
-
if (typeof input === 'string') {
|
|
1552
|
-
if (!WORKSPACE_ANCHORED_INPUT.test(input)) offenders.push(`${name}: fileset ${input}`);
|
|
1553
|
-
continue;
|
|
1554
|
-
}
|
|
1555
|
-
if ('env' in input) offenders.push(`${name}: environment input ${String(input.env)}`);
|
|
1556
|
-
if (!('runtime' in input)) continue;
|
|
1557
|
-
if (input.runtime.includes(fileURLToPath(new URL('..', import.meta.url)))) {
|
|
1558
|
-
offenders.push(`${name}: runtime command names the plugin checkout`);
|
|
1559
|
-
}
|
|
1560
|
-
const value = await runtimeInputValue(input.runtime, workspace.context.workspaceRoot);
|
|
1561
|
-
const rooted = PATH_OUTSIDE_WORKSPACE.exec(value);
|
|
1562
|
-
if (rooted) offenders.push(`${name}: runtime input yields ${rooted[0].trim()} — from ${input.runtime}`);
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
expect(offenders).toEqual([]);
|
|
1566
|
-
} finally {
|
|
1567
|
-
await workspace.cleanup();
|
|
1568
|
-
}
|
|
1569
|
-
});
|
|
1570
|
-
|
|
1571
|
-
// A consumer links the plugin from a checkout of its own, outside the
|
|
1572
|
-
// workspace, and its forks sit at different depths. Nx hashes a project's
|
|
1573
|
-
// configuration into every task of that project and of its dependents, so
|
|
1574
|
-
// the configuration must not know how deep the workspace is: measured, a
|
|
1575
|
-
// `../` count in the tool config path re-keyed 118 tasks of a fork of a warm
|
|
1576
|
-
// main.
|
|
1577
|
-
it('infers byte-identical cargo targets for a workspace at any depth', async () => {
|
|
1578
|
-
const parent = await realpath(await mkdtemp(join(tmpdir(), 'smoothbricks-nx-plugin-depth-')));
|
|
1579
|
-
const plugin = fileURLToPath(new URL('..', import.meta.url));
|
|
1580
|
-
const pluginNextestConfig = await readFile(join(plugin, 'nextest.toml'), 'utf8');
|
|
1581
|
-
try {
|
|
1582
|
-
const inferred: string[] = [];
|
|
1583
|
-
for (const dir of [parent, join(parent, 'a/b/c')]) {
|
|
1584
|
-
await mkdir(dir, { recursive: true });
|
|
1585
|
-
const workspace = await createWorkspace(dir);
|
|
1586
|
-
const root = workspace.context.workspaceRoot;
|
|
1587
|
-
await writeCargoIdentityFixture(workspace);
|
|
1588
|
-
const project = await inferProject(workspace, 'packages/ferris/package.json');
|
|
1589
|
-
// Installed the way a consumer links it: a checkout outside the
|
|
1590
|
-
// workspace. After inference, whose fixture walk would follow it.
|
|
1591
|
-
await mkdir(join(root, 'node_modules/@smoothbricks'), { recursive: true });
|
|
1592
|
-
await symlink(plugin, join(root, 'node_modules/@smoothbricks/nx-plugin'));
|
|
1593
|
-
// Stable is not enough: from where each command runs, the spelling
|
|
1594
|
-
// must name the config the plugin ships.
|
|
1595
|
-
const configured: string[] = [];
|
|
1596
|
-
for (const [name, target] of cachedCargoTargets(project?.targets ?? {})) {
|
|
1597
|
-
const named = /--tool-config-file "smoo:\$PWD\/([^"]+)"/.exec(String(target.options?.command));
|
|
1598
|
-
if (!named?.[1]) continue;
|
|
1599
|
-
configured.push(name);
|
|
1600
|
-
const config = await readFile(join(root, String(target.options?.cwd), named[1]), 'utf8');
|
|
1601
|
-
expect([name, config]).toEqual([name, pluginNextestConfig]);
|
|
1602
|
-
}
|
|
1603
|
-
expect(configured.sort()).toEqual([
|
|
1604
|
-
'cargo-cross-test-archive-aarch64-apple-darwin',
|
|
1605
|
-
'cargo-test-archive',
|
|
1606
|
-
'cargo-test-ferris-core',
|
|
1607
|
-
]);
|
|
1608
|
-
inferred.push(JSON.stringify(project, null, 2));
|
|
1609
|
-
}
|
|
1610
|
-
expect(inferred[1]).toBe(inferred[0]);
|
|
1611
|
-
} finally {
|
|
1612
|
-
await rm(parent, { recursive: true, force: true });
|
|
1613
|
-
}
|
|
1614
|
-
});
|
|
1615
|
-
|
|
1616
|
-
it('scopes each per-crate cargo-test command to exactly one package', async () => {
|
|
1617
|
-
const workspace = await createWorkspace();
|
|
1618
|
-
try {
|
|
1619
|
-
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
1620
|
-
await workspace.write(
|
|
1621
|
-
'packages/ferris/Cargo.toml',
|
|
1622
|
-
'[workspace]\nmembers = ["crates/ferris-core", "crates/ferris-wasm"]\n',
|
|
1623
|
-
);
|
|
1624
|
-
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
1625
|
-
await workspace.write('packages/ferris/crates/ferris-wasm/Cargo.toml', '[package]\nname = "ferris-wasm"\n');
|
|
1626
|
-
|
|
1627
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
1628
|
-
|
|
1629
|
-
// Scoped by filterset over one archived workspace build: exactly one
|
|
1630
|
-
// crate runs, and no `-p` re-resolves its features.
|
|
1631
|
-
expect(cargoPackageSelection(String(targets['cargo-test-ferris-core']?.options?.command ?? ''))).toEqual({
|
|
1632
|
-
prebuiltRun: true,
|
|
1633
|
-
packageFlags: [],
|
|
1634
|
-
filtered: ['ferris-core'],
|
|
1635
|
-
});
|
|
1636
|
-
expect(cargoPackageSelection(String(targets['cargo-test-ferris-wasm']?.options?.command ?? ''))).toEqual({
|
|
1637
|
-
prebuiltRun: true,
|
|
1638
|
-
packageFlags: [],
|
|
1639
|
-
filtered: ['ferris-wasm'],
|
|
1640
|
-
});
|
|
1641
|
-
expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
1642
|
-
expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
1643
|
-
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-test-ferris-wasm']);
|
|
1644
|
-
} finally {
|
|
1645
|
-
await workspace.cleanup();
|
|
1646
|
-
}
|
|
1647
|
-
});
|
|
1648
|
-
|
|
1649
|
-
it('extracts the test archive once for all per-crate runners, and again only when its bytes change', async () => {
|
|
1650
|
-
const workspace = await createWorkspace();
|
|
1651
|
-
const root = workspace.context.workspaceRoot;
|
|
1652
|
-
const crates = ['ferris-a', 'ferris-b', 'ferris-c'];
|
|
1653
|
-
try {
|
|
1654
|
-
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
1655
|
-
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = ["crates/*"]\n');
|
|
1656
|
-
for (const crate of crates) {
|
|
1657
|
-
await workspace.write(`packages/ferris/crates/${crate}/Cargo.toml`, `[package]\nname = "${crate}"\n`);
|
|
1658
|
-
}
|
|
1659
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
1660
|
-
// Installed the way a consumer has it, so each command finds the helper it names.
|
|
1661
|
-
await mkdir(join(root, 'node_modules/@smoothbricks'), { recursive: true });
|
|
1662
|
-
await symlink(fileURLToPath(new URL('..', import.meta.url)), join(root, 'node_modules/@smoothbricks/nx-plugin'));
|
|
1663
|
-
// A cargo that does what nextest does with an archive, and says so: an
|
|
1664
|
-
// `--archive-file` unpacks it (into `--extract-to`, or a private temp
|
|
1665
|
-
// dir when a run is given the archive itself), and a run reports which
|
|
1666
|
-
// archive's binaries it executed. `metadata` names the workspace's
|
|
1667
|
-
// target directory, where the extraction root lives.
|
|
1668
|
-
const log = join(root, 'nextest.log');
|
|
1669
|
-
await workspace.write(
|
|
1670
|
-
'bin/cargo',
|
|
1671
|
-
[
|
|
1672
|
-
'#!/bin/sh',
|
|
1673
|
-
'archive= dest= binaries=',
|
|
1674
|
-
'while [ $# -gt 0 ]; do',
|
|
1675
|
-
' case "$1" in',
|
|
1676
|
-
' metadata) printf \'{"target_directory":"%s/target"}\\n\' "$PWD"; exit 0 ;;',
|
|
1677
|
-
' --archive-file) archive=$2; shift ;;',
|
|
1678
|
-
' --extract-to) dest=$2; shift ;;',
|
|
1679
|
-
' --binaries-metadata) binaries=$2; shift ;;',
|
|
1680
|
-
' esac',
|
|
1681
|
-
' shift',
|
|
1682
|
-
'done',
|
|
1683
|
-
'if [ -n "$archive" ]; then',
|
|
1684
|
-
' echo "extract $(cat "$archive")" >> "$FAKE_NEXTEST_LOG"',
|
|
1685
|
-
' if [ -z "$dest" ]; then echo "run $(cat "$archive")" >> "$FAKE_NEXTEST_LOG"; exit 0; fi',
|
|
1686
|
-
' mkdir -p "$dest/target/nextest"',
|
|
1687
|
-
' cat "$archive" > "$dest/target/nextest/binaries-metadata.json"',
|
|
1688
|
-
' cat "$archive" > "$dest/target/nextest/cargo-metadata.json"',
|
|
1689
|
-
' exit 0',
|
|
1690
|
-
'fi',
|
|
1691
|
-
'echo "run $(cat "$binaries")" >> "$FAKE_NEXTEST_LOG"',
|
|
1692
|
-
'',
|
|
1693
|
-
].join('\n'),
|
|
1694
|
-
);
|
|
1695
|
-
await chmod(join(root, 'bin/cargo'), 0o755);
|
|
1696
|
-
// Every runner at once, through `sh -c` exactly as bounded-exec spawns it.
|
|
1697
|
-
const runAll = () =>
|
|
1698
|
-
Promise.all(
|
|
1699
|
-
crates.map(async (crate) => {
|
|
1700
|
-
const options = targets[`cargo-test-${crate}`]?.options;
|
|
1701
|
-
const child = Bun.spawn(['sh', '-c', String(options?.command)], {
|
|
1702
|
-
cwd: join(root, String(options?.cwd)),
|
|
1703
|
-
env: { ...process.env, PATH: `${join(root, 'bin')}:${process.env.PATH}`, FAKE_NEXTEST_LOG: log },
|
|
1704
|
-
stdout: 'pipe',
|
|
1705
|
-
stderr: 'pipe',
|
|
1706
|
-
});
|
|
1707
|
-
const [exitCode, stderr] = await Promise.all([child.exited, new Response(child.stderr).text()]);
|
|
1708
|
-
return { crate, exitCode, stderr };
|
|
1709
|
-
}),
|
|
1710
|
-
);
|
|
1711
|
-
|
|
1712
|
-
await workspace.write('packages/ferris/.cache/nextest/archive.tar.zst', 'first archive');
|
|
1713
|
-
for (const run of await runAll()) {
|
|
1714
|
-
expect(run).toMatchObject({ exitCode: 0 });
|
|
1715
|
-
}
|
|
1716
|
-
expect((await readFile(log, 'utf8')).trim().split('\n').sort()).toEqual([
|
|
1717
|
-
'extract first archive',
|
|
1718
|
-
'run first archive',
|
|
1719
|
-
'run first archive',
|
|
1720
|
-
'run first archive',
|
|
1721
|
-
]);
|
|
1722
|
-
|
|
1723
|
-
// A rebuilt archive is new bytes at the same path: the runners must not
|
|
1724
|
-
// execute what the old one unpacked, and the old unpacking is garbage.
|
|
1725
|
-
await workspace.write('packages/ferris/.cache/nextest/archive.tar.zst', 'second archive');
|
|
1726
|
-
for (const run of await runAll()) {
|
|
1727
|
-
expect(run).toMatchObject({ exitCode: 0 });
|
|
1728
|
-
}
|
|
1729
|
-
expect((await readFile(log, 'utf8')).trim().split('\n').sort()).toEqual([
|
|
1730
|
-
'extract first archive',
|
|
1731
|
-
'extract second archive',
|
|
1732
|
-
'run first archive',
|
|
1733
|
-
'run first archive',
|
|
1734
|
-
'run first archive',
|
|
1735
|
-
'run second archive',
|
|
1736
|
-
'run second archive',
|
|
1737
|
-
'run second archive',
|
|
1738
|
-
]);
|
|
1739
|
-
// The old unpacking is gone from Cargo's build tree, and the archive's
|
|
1740
|
-
// directory holds only the archive, the declared Nx output.
|
|
1741
|
-
const extracted = join(root, 'packages/ferris/target', NEXTEST_EXTRACTION_DIRECTORY);
|
|
1742
|
-
const unpacked = (await readdir(extracted, { recursive: true })).filter((path) =>
|
|
1743
|
-
path.endsWith('binaries-metadata.json'),
|
|
1744
|
-
);
|
|
1745
|
-
expect(await Promise.all(unpacked.map((path) => readFile(join(extracted, path), 'utf8')))).toEqual([
|
|
1746
|
-
'second archive',
|
|
1747
|
-
]);
|
|
1748
|
-
expect(await readdir(join(root, 'packages/ferris/.cache/nextest'))).toEqual(['archive.tar.zst']);
|
|
1749
|
-
} finally {
|
|
1750
|
-
await workspace.cleanup();
|
|
1751
|
-
}
|
|
1752
|
-
});
|
|
1753
|
-
|
|
1754
|
-
it('infers a cached Cargo Wasm build directly from crate metadata', async () => {
|
|
1755
|
-
const workspace = await createWorkspace();
|
|
1756
|
-
try {
|
|
1757
|
-
await workspace.write('packages/git-do/package.json', '{"name":"git-do"}\n');
|
|
1758
|
-
await workspace.write(
|
|
1759
|
-
'packages/git-do/crates/git-do/Cargo.toml',
|
|
1760
|
-
[
|
|
1761
|
-
'[package]',
|
|
1762
|
-
'name = "git-do"',
|
|
1763
|
-
'',
|
|
1764
|
-
'[lib]',
|
|
1765
|
-
'name = "gitoxide_engine"',
|
|
1766
|
-
'crate-type = ["cdylib", "rlib"]',
|
|
1767
|
-
'',
|
|
1768
|
-
'[package.metadata.smoothbricks.wasm-bindgen]',
|
|
1769
|
-
'targets = ["nodejs", "web"]',
|
|
1770
|
-
'out-dir = "generated/wasm"',
|
|
1771
|
-
'',
|
|
1772
|
-
].join('\n'),
|
|
1773
|
-
);
|
|
1774
|
-
await workspace.write('packages/git-do/tsconfig.lib.json', '{"compilerOptions":{"outDir":"dist"}}\n');
|
|
1775
|
-
|
|
1776
|
-
const targets = await inferProjectTargets(workspace, 'packages/git-do/package.json');
|
|
1777
|
-
|
|
1778
|
-
// A release bumps package.json and the lockfile before it builds; neither
|
|
1779
|
-
// is part of a wasm artifact, so neither may be an input.
|
|
1780
|
-
expect(targets['cargo-wasm']?.inputs).not.toContain('{projectRoot}/package.json');
|
|
1781
|
-
expect(targets['cargo-wasm']?.inputs).not.toContain('{workspaceRoot}/bun.lock');
|
|
1782
|
-
expect(targets['cargo-wasm']).toMatchObject({
|
|
1783
|
-
executor: 'nx:run-commands',
|
|
1784
|
-
cache: true,
|
|
1785
|
-
dependsOn: ['cargo-fetch', '^build'],
|
|
1786
|
-
inputs: expect.arrayContaining(['{projectRoot}/**/*.rs', '{projectRoot}/**/Cargo.toml']),
|
|
1787
|
-
outputs: ['{projectRoot}/generated/wasm'],
|
|
1788
|
-
options: {
|
|
1789
|
-
command: [
|
|
1790
|
-
'cargo --frozen build --target wasm32-unknown-unknown --manifest-path crates/git-do/Cargo.toml',
|
|
1791
|
-
'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/wasm32-unknown-unknown/debug/gitoxide_engine.wasm',
|
|
1792
|
-
'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/wasm32-unknown-unknown/debug/gitoxide_engine.wasm',
|
|
1793
|
-
].join(' && '),
|
|
1794
|
-
cwd: 'packages/git-do',
|
|
1795
|
-
},
|
|
1796
|
-
});
|
|
1797
|
-
// No workspace claims the crate, so cargo's default target dir is the one
|
|
1798
|
-
// beside its own manifest, and the release configuration reads the
|
|
1799
|
-
// release artifact from it.
|
|
1800
|
-
expect(targets['cargo-wasm']?.options?.commands).toBeUndefined();
|
|
1801
|
-
expect(targets['cargo-wasm']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
|
|
1802
|
-
command: [
|
|
1803
|
-
'cargo --frozen build --release --target wasm32-unknown-unknown --manifest-path crates/git-do/Cargo.toml',
|
|
1804
|
-
'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
|
|
1805
|
-
'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
|
|
1806
|
-
].join(' && '),
|
|
1807
|
-
});
|
|
1808
|
-
// A wasm-bindgen crate in a nested Cargo workspace still needs its locked
|
|
1809
|
-
// graph downloaded, and the project root is not a member of it, so the
|
|
1810
|
-
// fetch names the crate manifest instead of relying on cwd.
|
|
1811
|
-
expect(targets['cargo-fetch']?.options).toEqual({
|
|
1812
|
-
commands: ['cargo fetch --locked --manifest-path crates/git-do/Cargo.toml'],
|
|
1813
|
-
cwd: 'packages/git-do',
|
|
1814
|
-
});
|
|
1815
|
-
expect(targets['tsc-js']?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
|
|
1816
|
-
expect(targets.typecheck?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
|
|
1817
|
-
expect(targets.build?.dependsOn).toEqual(['^build', 'cargo-wasm', 'tsc-js']);
|
|
1818
|
-
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
1819
|
-
// A nested crate manifest is enough for output inference, but not for
|
|
1820
|
-
// workspace-wide cargo-test/lint policy.
|
|
1821
|
-
expect(targets['cargo-test']).toBeUndefined();
|
|
1822
|
-
expect(targets['cargo-lint']).toBeUndefined();
|
|
1823
|
-
expectNoSchedulerThrottle(targets);
|
|
1824
|
-
} finally {
|
|
1825
|
-
await workspace.cleanup();
|
|
1826
|
-
}
|
|
1827
|
-
});
|
|
1828
|
-
|
|
1829
|
-
it('infers disjoint host and release targets from canonical N-API metadata', async () => {
|
|
1830
|
-
const workspace = await createWorkspace();
|
|
1831
|
-
try {
|
|
1832
|
-
await workspace.write(
|
|
1833
|
-
'packages/cowshed/package.json',
|
|
1834
|
-
JSON.stringify({
|
|
1835
|
-
name: 'cowshed',
|
|
1836
|
-
scripts: { test: 'nx run cowshed:test --outputStyle=stream' },
|
|
1837
|
-
nx: {
|
|
1838
|
-
targets: {
|
|
1839
|
-
'cli-arm64-macos': { executor: 'nx:run-commands', options: { command: 'true' } },
|
|
1840
|
-
'cli-x64-linux': { executor: 'nx:run-commands', options: { command: 'true' } },
|
|
1841
|
-
},
|
|
1842
|
-
},
|
|
1843
|
-
napi: {
|
|
1844
|
-
binaryName: 'cowshed',
|
|
1845
|
-
targets: [
|
|
1846
|
-
'aarch64-apple-darwin',
|
|
1847
|
-
'x86_64-apple-darwin',
|
|
1848
|
-
'aarch64-unknown-linux-gnu',
|
|
1849
|
-
'x86_64-unknown-linux-gnu',
|
|
1850
|
-
],
|
|
1851
|
-
},
|
|
1852
|
-
}),
|
|
1853
|
-
);
|
|
1854
|
-
await workspace.write('packages/cowshed/Cargo.toml', '[workspace]\nmembers = ["crates/cowshed-napi"]\n');
|
|
1855
|
-
await workspace.write(
|
|
1856
|
-
'packages/cowshed/crates/cowshed-napi/Cargo.toml',
|
|
1857
|
-
'[package]\nname = "cowshed-napi"\n\n[lib]\ncrate-type = ["cdylib"]\n',
|
|
1858
|
-
);
|
|
1859
|
-
await workspace.write(
|
|
1860
|
-
'packages/cowshed/tsconfig.lib.json',
|
|
1861
|
-
'{"compilerOptions":{"outDir":"dist/ts","tsBuildInfoFile":"dist/ts/tsconfig.lib.tsbuildinfo"}}\n',
|
|
1862
|
-
);
|
|
1863
|
-
await workspace.write('packages/cowshed/src/native.test.ts', 'export {};\n');
|
|
1864
|
-
|
|
1865
|
-
const targets = await inferProjectTargets(workspace, 'packages/cowshed/package.json');
|
|
1866
|
-
|
|
1867
|
-
expect(targets['cargo-wasm']).toBeUndefined();
|
|
1868
|
-
expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/ts']);
|
|
1869
|
-
// This fixture declares all four supported triples, so on EVERY supported
|
|
1870
|
-
// runner the host's own triple is present and native: the host provider is
|
|
1871
|
-
// that platform target and `cargo-napi` is never inferred. Tying the native
|
|
1872
|
-
// regime to `-macos` asserted a macOS-only model and failed on Linux with
|
|
1873
|
-
// zero host providers found. The dedicated `cargo-napi` regime is covered
|
|
1874
|
-
// below against a platform no declared triple can serve, which reaches it
|
|
1875
|
-
// on every runner instead of only on Linux.
|
|
1876
|
-
const hostOs = process.platform === 'darwin' ? 'macos' : process.platform === 'linux' ? 'linux' : null;
|
|
1877
|
-
const hostArch = process.arch === 'arm64' ? 'arm64' : process.arch === 'x64' ? 'x64' : null;
|
|
1878
|
-
const hostSuffix = hostOs !== null && hostArch !== null ? `-${hostArch}-${hostOs}` : null;
|
|
1879
|
-
expect(hostSuffix).not.toBeNull();
|
|
1880
|
-
expect(targets[`napi${hostSuffix}`]).toBeDefined();
|
|
1881
|
-
expect(targets['cargo-napi']).toBeUndefined();
|
|
1882
|
-
|
|
1883
|
-
// A platform outside NAPI_TARGET_CONVENTIONS leaves no native host target,
|
|
1884
|
-
// which is precisely the condition that infers the dedicated host build.
|
|
1885
|
-
const unservedHostTargets = await inferProjectTargets(
|
|
1886
|
-
workspace,
|
|
1887
|
-
'packages/cowshed/package.json',
|
|
1888
|
-
createNodesV2ForPlatform('win32', 'x64'),
|
|
1889
|
-
);
|
|
1890
|
-
expect(unservedHostTargets['cargo-napi']).toMatchObject({
|
|
1891
|
-
executor: 'nx:run-commands',
|
|
1892
|
-
cache: true,
|
|
1893
|
-
// The dedicated host build consumes only its dependencies' outputs; it is
|
|
1894
|
-
// not ordered behind the test compile.
|
|
1895
|
-
dependsOn: ['^build'],
|
|
1896
|
-
outputs: ['{projectRoot}/dist/native/host'],
|
|
1897
|
-
options: {
|
|
1898
|
-
cwd: 'packages/cowshed',
|
|
1899
|
-
command:
|
|
1900
|
-
'napi build --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir dist/native/host',
|
|
1901
|
-
},
|
|
1902
|
-
configurations: {
|
|
1903
|
-
[RELEASE_CONFIGURATION]: {
|
|
1904
|
-
command:
|
|
1905
|
-
'napi build --release --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir dist/native/host',
|
|
1906
|
-
},
|
|
1907
|
-
},
|
|
1908
|
-
});
|
|
1909
|
-
expect(unservedHostTargets.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'cargo-napi', 'tsc-js']);
|
|
1910
|
-
expect(targets['napi-arm64-macos']?.outputs).toEqual(['{projectRoot}/dist/native/darwin-arm64']);
|
|
1911
|
-
// Every local build compiles dev; only the release configuration ships.
|
|
1912
|
-
const darwinArm64Build = (release: string): string =>
|
|
1913
|
-
`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 --package-json-path package.json --output-dir dist/native/darwin-arm64`;
|
|
1914
|
-
expect(targets['napi-arm64-macos']?.options).toMatchObject({ command: darwinArm64Build('') });
|
|
1915
|
-
expect(targets['napi-arm64-macos']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
|
|
1916
|
-
command: darwinArm64Build(' --release'),
|
|
1917
|
-
});
|
|
1918
|
-
expect(targets['napi-arm64-macos']?.options?.env).toBeUndefined();
|
|
1919
|
-
// No cargo-test-compile edge here, on ANY host: the platform build consumes
|
|
1920
|
-
// nothing from it, and a platform target's dependency closure may only reach
|
|
1921
|
-
// its own family (`validatePlatformTargetDependencies`).
|
|
1922
|
-
expect(targets['napi-arm64-macos']?.dependsOn).toBeUndefined();
|
|
1923
|
-
// Every host infers the SAME Linux addon target: devenv's zig through the
|
|
1924
|
-
// cargo-zigbuild executor, glibc pinned by the triple suffix. There is no
|
|
1925
|
-
// native-versus-cross branch to diverge on, so forcing a Linux host and a
|
|
1926
|
-
// macOS host must yield byte-identical Linux targets, and neither may
|
|
1927
|
-
// carry a compiler environment or a toolchain prerequisite.
|
|
1928
|
-
const linuxX64Targets = await inferProjectTargets(
|
|
1929
|
-
workspace,
|
|
1930
|
-
'packages/cowshed/package.json',
|
|
1931
|
-
createNodesV2ForPlatform('linux', 'x64'),
|
|
1932
|
-
);
|
|
1933
|
-
const darwinArm64Targets = await inferProjectTargets(
|
|
1934
|
-
workspace,
|
|
1935
|
-
'packages/cowshed/package.json',
|
|
1936
|
-
createNodesV2ForPlatform('darwin', 'arm64'),
|
|
1937
|
-
);
|
|
1938
|
-
expect(darwinArm64Targets['napi-x64-linux']).toMatchObject({
|
|
1939
|
-
executor: '@smoothbricks/nx-plugin:cargo-zigbuild',
|
|
1940
|
-
cache: true,
|
|
1941
|
-
outputs: ['{projectRoot}/dist/native/linux-x64-gnu'],
|
|
1942
|
-
options: {
|
|
1943
|
-
target: 'x86_64-unknown-linux-gnu.2.17',
|
|
1944
|
-
manifestPath: 'packages/cowshed/crates/cowshed-napi/Cargo.toml',
|
|
1945
|
-
package: 'cowshed-napi',
|
|
1946
|
-
output: '{projectRoot}/dist/native/linux-x64-gnu/cowshed.linux-x64-gnu.node',
|
|
1947
|
-
},
|
|
1948
|
-
configurations: { [RELEASE_CONFIGURATION]: { release: true } },
|
|
1949
|
-
});
|
|
1950
|
-
expect(darwinArm64Targets['napi-arm64-linux']?.options).toMatchObject({
|
|
1951
|
-
target: 'aarch64-unknown-linux-gnu.2.17',
|
|
1952
|
-
output: '{projectRoot}/dist/native/linux-arm64-gnu/cowshed.linux-arm64-gnu.node',
|
|
1953
|
-
});
|
|
1954
|
-
for (const suffix of ['arm64-linux', 'x64-linux']) {
|
|
1955
|
-
expect(linuxX64Targets[`napi-${suffix}`]).toEqual(darwinArm64Targets[`napi-${suffix}`]);
|
|
1956
|
-
expect(darwinArm64Targets[`napi-${suffix}`]?.dependsOn).toBeUndefined();
|
|
1957
|
-
}
|
|
1958
|
-
for (const inferred of [linuxX64Targets, darwinArm64Targets]) {
|
|
1959
|
-
expect(Object.keys(inferred).filter((name) => name.startsWith('napi-toolchain-'))).toEqual([]);
|
|
1960
|
-
expect(inferred['napi-debug']?.options?.env).toBeUndefined();
|
|
1961
|
-
for (const suffix of ['arm64-macos', 'x64-macos']) {
|
|
1962
|
-
expect(inferred[`napi-${suffix}`]?.options?.command).toContain('napi build');
|
|
1963
|
-
expect(inferred[`napi-${suffix}`]?.options?.env).toBeUndefined();
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
// The aggregate build pulls in exactly the inferring host's
|
|
1967
|
-
// platform-suffixed targets (publish still owns foreign platforms), and
|
|
1968
|
-
// the only cargo-test work it owns is compiling the executables — every
|
|
1969
|
-
// RUNNER is reached through `test`. Both hosts are asserted here so the
|
|
1970
|
-
// expectation does not depend on which machine runs the suite: the
|
|
1971
|
-
// previous form read `process.platform`, and the macOS answer was the only
|
|
1972
|
-
// one anyone checked.
|
|
1973
|
-
for (const [inferred, hostSuffix] of [
|
|
1974
|
-
[linuxX64Targets, '-x64-linux'],
|
|
1975
|
-
[darwinArm64Targets, '-arm64-macos'],
|
|
1976
|
-
] as const) {
|
|
1977
|
-
const hostNapiTargets = [
|
|
1978
|
-
'cli-arm64-macos',
|
|
1979
|
-
'cli-x64-linux',
|
|
1980
|
-
'napi-arm64-macos',
|
|
1981
|
-
'napi-x64-macos',
|
|
1982
|
-
'napi-arm64-linux',
|
|
1983
|
-
'napi-x64-linux',
|
|
1984
|
-
]
|
|
1985
|
-
.filter((name) => name.endsWith(hostSuffix))
|
|
1986
|
-
.sort();
|
|
1987
|
-
expect(hostNapiTargets.length).toBeGreaterThan(0);
|
|
1988
|
-
expect(inferred.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'tsc-js', ...hostNapiTargets]);
|
|
1989
|
-
// Crate `cowshed-napi` names its bounded runner `cargo-test-cowshed-napi`;
|
|
1990
|
-
// the retired `*-napi` output-family glob matched it on suffix alone and
|
|
1991
|
-
// put the whole cargo test suite inside `nx run-many -t build`.
|
|
1992
|
-
expect(inferred['cargo-test-cowshed-napi']).toBeDefined();
|
|
1993
|
-
for (const dependency of inferred.build?.dependsOn ?? []) {
|
|
1994
|
-
expect(String(dependency).startsWith('cargo-test-')).toBe(dependency === 'cargo-test-compile');
|
|
1995
|
-
}
|
|
1996
|
-
for (const dependency of inferred.build?.dependsOn ?? []) {
|
|
1997
|
-
if (typeof dependency === 'string' && /-(?:arm64|x64)-(?:macos|linux)$/.test(dependency)) {
|
|
1998
|
-
expect(dependency.endsWith(hostSuffix)).toBe(true);
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
2003
|
-
// The test suite runs against the dev-profile addon, never a release
|
|
2004
|
-
// platform build: napi-debug shares target/debug with cargo-test, keeps
|
|
2005
|
-
// the release binaries off the test critical path, and lives outside
|
|
2006
|
-
// dist/ so the wholesale-packaged dist/ tree can never ship it.
|
|
2007
|
-
expect(targets['napi-debug']).toMatchObject({
|
|
2008
|
-
executor: 'nx:run-commands',
|
|
2009
|
-
cache: true,
|
|
2010
|
-
dependsOn: ['^build'],
|
|
2011
|
-
outputs: ['{projectRoot}/.cache/native-debug'],
|
|
2012
|
-
options: {
|
|
2013
|
-
cwd: 'packages/cowshed',
|
|
2014
|
-
command:
|
|
2015
|
-
'napi build --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir .cache/native-debug',
|
|
2016
|
-
},
|
|
2017
|
-
});
|
|
2018
|
-
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-cowshed-napi']);
|
|
2019
|
-
// cargo-fetch survives the napi-debug edge: the per-crate runner is itself
|
|
2020
|
-
// a frozen cargo command, so its precondition is its own edge. It reads
|
|
2021
|
-
// the workspace archive and still waits for the debug cdylib its own
|
|
2022
|
-
// project builds, because its tests load that artifact from `target/`.
|
|
2023
|
-
expect(targets['cargo-test-cowshed-napi']?.dependsOn).toEqual([
|
|
2024
|
-
'cargo-fetch',
|
|
2025
|
-
'cargo-test-archive',
|
|
2026
|
-
'napi-debug',
|
|
2027
|
-
]);
|
|
2028
|
-
expect(targets['cargo-test-cowshed-napi']?.options?.command).toMatch(
|
|
2029
|
-
/^extracted="\$\(node \.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/dist\/bin\/smoo-nx-nextest-extract\.js \.cache\/nextest\/archive\.tar\.zst\)" && cargo --frozen nextest run --binaries-metadata "\$extracted\/target\/nextest\/binaries-metadata\.json" --cargo-metadata "\$extracted\/target\/nextest\/cargo-metadata\.json" --target-dir-remap "\$extracted\/target" --workspace-remap \. -E 'package\(cowshed-napi\)' --no-fail-fast --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
2030
|
-
);
|
|
2031
|
-
expect(targets['napi-test']).toMatchObject({
|
|
2032
|
-
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
2033
|
-
cache: true,
|
|
2034
|
-
dependsOn: ['cargo-test', 'napi-debug', 'tsc-js', '^build'],
|
|
2035
|
-
options: {
|
|
2036
|
-
command: 'bun test --config=../bunfig.toml --timeout=0 native.test.ts',
|
|
2037
|
-
cwd: 'packages/cowshed/src',
|
|
2038
|
-
env: { NAPI_DEBUG_ADDON: '1' },
|
|
2039
|
-
idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
|
|
2040
|
-
killAfterMs: 10000,
|
|
2041
|
-
},
|
|
2042
|
-
});
|
|
2043
|
-
expectNoSchedulerThrottle(targets);
|
|
2044
|
-
await workspace.write('packages/cowshed/bunfig.napi-test.toml', '[test]\n');
|
|
2045
|
-
const targetsWithDedicatedBunfig = await inferProjectTargets(workspace, 'packages/cowshed/package.json');
|
|
2046
|
-
expect(targetsWithDedicatedBunfig['napi-test']?.options?.command).toBe(
|
|
2047
|
-
'bun test --config=../bunfig.napi-test.toml --timeout=0 native.test.ts',
|
|
2048
|
-
);
|
|
2049
|
-
} finally {
|
|
2050
|
-
await workspace.cleanup();
|
|
2051
|
-
}
|
|
2052
|
-
});
|
|
2053
|
-
|
|
2054
|
-
it('keeps an explicit package-local cargo-wasm target singular and feeding the aggregate build', async () => {
|
|
2055
|
-
const workspace = await createWorkspace();
|
|
2056
|
-
try {
|
|
2057
|
-
await workspace.write(
|
|
2058
|
-
'packages/columine/package.json',
|
|
2059
|
-
JSON.stringify({
|
|
2060
|
-
name: 'columine',
|
|
2061
|
-
nx: {
|
|
2062
|
-
targets: {
|
|
2063
|
-
'cargo-wasm': { executor: 'nx:run-commands', outputs: ['{projectRoot}/dist/**/*.wasm'] },
|
|
2064
|
-
},
|
|
2065
|
-
},
|
|
2066
|
-
}),
|
|
2067
|
-
);
|
|
2068
|
-
await workspace.write(
|
|
2069
|
-
'packages/columine/Cargo.toml',
|
|
2070
|
-
'[workspace]\nmembers = ["crates/columine-wasm"]\n\n[profile.wasm-release]\ninherits = "release"\n',
|
|
2071
|
-
);
|
|
2072
|
-
await workspace.write(
|
|
2073
|
-
'packages/columine/crates/columine-wasm/Cargo.toml',
|
|
2074
|
-
'[package]\nname = "columine-wasm"\n\n[lib]\ncrate-type = ["cdylib", "rlib"]\n\n[package.metadata.smoothbricks.wasm-bindgen]\ntargets = ["web"]\n',
|
|
2075
|
-
);
|
|
2076
|
-
|
|
2077
|
-
const targets = await inferProjectTargets(workspace, 'packages/columine/package.json');
|
|
2078
|
-
|
|
2079
|
-
// The declared target stays the only cargo-wasm: inference never emits a
|
|
2080
|
-
// duplicate for Nx to merge, even with a cdylib *-wasm member crate present.
|
|
2081
|
-
expect(targets['cargo-wasm']).toBeUndefined();
|
|
2082
|
-
// Its declared *-wasm output-family name feeds the aggregate build and
|
|
2083
|
-
// clean by concrete name, and the cargo workspace's test-executable
|
|
2084
|
-
// compilation comes with it.
|
|
2085
|
-
expect(targets.build?.executor).toBe('nx:noop');
|
|
2086
|
-
expect(targets.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'cargo-wasm']);
|
|
2087
|
-
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
2088
|
-
} finally {
|
|
2089
|
-
await workspace.cleanup();
|
|
2090
|
-
}
|
|
2091
|
-
});
|
|
2092
|
-
|
|
2093
|
-
it('binds the wasm a package workspace member writes into that workspace target dir', async () => {
|
|
2094
|
-
const workspace = await createWorkspace();
|
|
2095
|
-
try {
|
|
2096
|
-
await workspace.write('packages/columine/package.json', '{"name":"columine"}\n');
|
|
2097
|
-
await workspace.write('packages/columine/Cargo.toml', '[workspace]\nmembers = ["crates/columine-wasm"]\n');
|
|
2098
|
-
await workspace.write(
|
|
2099
|
-
'packages/columine/crates/columine-wasm/Cargo.toml',
|
|
2100
|
-
'[package]\nname = "columine-wasm"\n\n[lib]\ncrate-type = ["cdylib", "rlib"]\n\n[package.metadata.smoothbricks.wasm-bindgen]\ntargets = ["web"]\n',
|
|
2101
|
-
);
|
|
2102
|
-
|
|
2103
|
-
const targets = await inferProjectTargets(workspace, 'packages/columine/package.json');
|
|
2104
|
-
|
|
2105
|
-
// Cargo writes a member's artifacts under its workspace root, not beside
|
|
2106
|
-
// the member's manifest, so the bindgen input is read from there.
|
|
2107
|
-
expect(targets['cargo-wasm']?.options?.command).toBe(
|
|
2108
|
-
[
|
|
2109
|
-
'cargo --frozen build --target wasm32-unknown-unknown --manifest-path crates/columine-wasm/Cargo.toml',
|
|
2110
|
-
'wasm-bindgen --target web --out-dir dist-wasm/web target/wasm32-unknown-unknown/debug/columine_wasm.wasm',
|
|
2111
|
-
].join(' && '),
|
|
2112
|
-
);
|
|
2113
|
-
} finally {
|
|
2114
|
-
await workspace.cleanup();
|
|
2115
|
-
}
|
|
2116
|
-
});
|
|
2117
|
-
|
|
2118
|
-
it('partitions ordinary and exceptional tests into disjoint hash shards of the same declared count', async () => {
|
|
2119
|
-
const workspace = await createWorkspace();
|
|
2120
|
-
try {
|
|
2121
|
-
await workspace.write('packages/rusty/package.json', '{"name":"rusty"}\n');
|
|
2122
|
-
await workspace.write('packages/rusty/Cargo.toml', '[workspace]\nmembers = ["crates/big", "crates/small"]\n');
|
|
2123
|
-
await workspace.write(
|
|
2124
|
-
'packages/rusty/crates/big/Cargo.toml',
|
|
2125
|
-
'[package]\nname = "big"\n\n[package.metadata.smoothbricks.test]\nshards = 3\n',
|
|
2126
|
-
);
|
|
2127
|
-
await workspace.write('packages/rusty/crates/small/Cargo.toml', '[package]\nname = "small"\n');
|
|
2128
|
-
|
|
2129
|
-
const targets = await inferProjectTargets(workspace, 'packages/rusty/package.json');
|
|
2130
|
-
|
|
2131
|
-
// An unsharded crate keeps the bare name and takes no --partition, so
|
|
2132
|
-
// declaring nothing is exactly the old single-target behaviour.
|
|
2133
|
-
expect(targets['cargo-test-small']?.options?.command).toMatch(
|
|
2134
|
-
/--workspace-remap \. -E 'package\(small\)' --no-fail-fast --no-tests=pass --user-config-file none/,
|
|
2135
|
-
);
|
|
2136
|
-
// The shards partition the crate MINUS the classes nextest.toml singles
|
|
2137
|
-
// out, i of N. Those are lifted out because a test carrying a raised
|
|
2138
|
-
// slow-timeout costs what the suite does not — the compile-fail test
|
|
2139
|
-
// rustc's a fixture for 25.6s on a cold target dir against 1.8s warm.
|
|
2140
|
-
const exceptional = exceptionalTestFilter(fileURLToPath(new URL('../nextest.toml', import.meta.url)));
|
|
2141
|
-
if (exceptional === null) {
|
|
2142
|
-
throw new Error('nextest.toml declares no overrides; this test asserts the pin that protects them');
|
|
2143
|
-
}
|
|
2144
|
-
for (const index of [1, 2, 3]) {
|
|
2145
|
-
expect(targets[`cargo-test-big-shard${index}`]?.options?.command).toContain(
|
|
2146
|
-
`-E 'package(big) and not (${exceptional})' --partition hash:${index}/3 --no-fail-fast --no-tests=pass`,
|
|
2147
|
-
);
|
|
2148
|
-
expect(targets[`cargo-test-big-shard${index}`]?.options?.idleTimeoutMs).toBe(BOUNDED_TEST_IDLE_TIMEOUT_MS);
|
|
2149
|
-
expect(targets[`cargo-test-big-shard${index}`]?.options).not.toHaveProperty('timeoutMs');
|
|
2150
|
-
}
|
|
2151
|
-
// Exceptional partitions are the exact complement, hashed by the same
|
|
2152
|
-
// declared count; each keeps the full bounded window.
|
|
2153
|
-
for (const index of [1, 2, 3]) {
|
|
2154
|
-
const name = `cargo-test-big-exceptions-shard${index}`;
|
|
2155
|
-
expect(targets[name]?.options?.command).toContain(
|
|
2156
|
-
`-E 'package(big) and (${exceptional})' --partition hash:${index}/3 --no-fail-fast --no-tests=pass`,
|
|
2157
|
-
);
|
|
2158
|
-
expect(targets[name]?.options?.idleTimeoutMs).toBe(BOUNDED_TEST_IDLE_TIMEOUT_MS);
|
|
2159
|
-
expect(packageNameFromCargoTestTarget(name)).toBe('big');
|
|
2160
|
-
}
|
|
2161
|
-
expect(targets['cargo-test-big-exceptions']).toBeUndefined();
|
|
2162
|
-
// An unsharded crate needs no pin: its whole suite is already one run.
|
|
2163
|
-
expect(targets['cargo-test-small-exceptions']).toBeUndefined();
|
|
2164
|
-
expect(targets['cargo-test-big']).toBeUndefined();
|
|
2165
|
-
// Every piece reaches the aggregate, and they all hang off the one
|
|
2166
|
-
// archive: a run extracts binaries to its own temp directory and writes
|
|
2167
|
-
// nothing to cargo's target/, so no piece waits on another.
|
|
2168
|
-
expect(targets['cargo-test']?.dependsOn).toEqual([
|
|
2169
|
-
'cargo-test-big-shard1',
|
|
2170
|
-
'cargo-test-big-shard2',
|
|
2171
|
-
'cargo-test-big-shard3',
|
|
2172
|
-
'cargo-test-big-exceptions-shard1',
|
|
2173
|
-
'cargo-test-big-exceptions-shard2',
|
|
2174
|
-
'cargo-test-big-exceptions-shard3',
|
|
2175
|
-
'cargo-test-small',
|
|
2176
|
-
]);
|
|
2177
|
-
for (const name of [
|
|
2178
|
-
'cargo-test-big-shard1',
|
|
2179
|
-
'cargo-test-big-shard2',
|
|
2180
|
-
'cargo-test-big-shard3',
|
|
2181
|
-
'cargo-test-big-exceptions-shard1',
|
|
2182
|
-
'cargo-test-big-exceptions-shard2',
|
|
2183
|
-
'cargo-test-big-exceptions-shard3',
|
|
2184
|
-
'cargo-test-small',
|
|
2185
|
-
]) {
|
|
2186
|
-
expect(targets[name]?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
2187
|
-
}
|
|
2188
|
-
// Pieces of one crate share its inputs: they are one suite, split only to
|
|
2189
|
-
// fit the bound, so any change to the crate invalidates all of them.
|
|
2190
|
-
expect(targets['cargo-test-big-shard2']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
|
|
2191
|
-
expect(targets['cargo-test-big-exceptions-shard1']?.inputs).toEqual(targets['cargo-test-big-shard1']?.inputs);
|
|
2192
|
-
// Exceptional pieces fan out like the ordinary ones: nothing is exclusive.
|
|
2193
|
-
expectNoSchedulerThrottle(targets);
|
|
2194
|
-
} finally {
|
|
2195
|
-
await workspace.cleanup();
|
|
2196
|
-
}
|
|
2197
|
-
});
|
|
2198
|
-
|
|
2199
|
-
it('runs the serial test group once, unpartitioned, and excludes its tests from every crate piece on macOS', async () => {
|
|
2200
|
-
const workspace = await createWorkspace();
|
|
2201
|
-
try {
|
|
2202
|
-
await workspace.write('packages/rusty/package.json', '{"name":"rusty"}\n');
|
|
2203
|
-
await workspace.write('packages/rusty/Cargo.toml', '[workspace]\nmembers = ["crates/big", "crates/small"]\n');
|
|
2204
|
-
await workspace.write(
|
|
2205
|
-
'packages/rusty/crates/big/Cargo.toml',
|
|
2206
|
-
'[package]\nname = "big"\n\n[package.metadata.smoothbricks.test]\nshards = 3\n',
|
|
2207
|
-
);
|
|
2208
|
-
await workspace.write('packages/rusty/crates/small/Cargo.toml', '[package]\nname = "small"\n');
|
|
2209
|
-
await workspace.write(
|
|
2210
|
-
'packages/rusty/.config/nextest.toml',
|
|
2211
|
-
[
|
|
2212
|
-
'[test-groups.real-apfs]',
|
|
2213
|
-
'max-threads = 1',
|
|
2214
|
-
'',
|
|
2215
|
-
'[[profile.default.overrides]]',
|
|
2216
|
-
"filter = 'test(/real_apfs_/)'",
|
|
2217
|
-
`platform = 'cfg(target_os="macos")'`,
|
|
2218
|
-
"test-group = 'real-apfs'",
|
|
2219
|
-
'',
|
|
2220
|
-
].join('\n'),
|
|
2221
|
-
);
|
|
2222
|
-
|
|
2223
|
-
const macos = await inferProjectTargets(
|
|
2224
|
-
workspace,
|
|
2225
|
-
'packages/rusty/package.json',
|
|
2226
|
-
createNodesV2ForPlatform('darwin', 'arm64'),
|
|
2227
|
-
);
|
|
2228
|
-
const serial = '(test(/real_apfs_/))';
|
|
2229
|
-
const group = macos['cargo-test-group-real-apfs'];
|
|
2230
|
-
// One runner for the workspace, owned by the cargo root beside the archive it executes: a progress bound and no
|
|
2231
|
-
// ceiling like every test target, one CPU token, no partition and no thread flag. A filter that selects
|
|
2232
|
-
// nothing fails the run.
|
|
2233
|
-
expect(group?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
2234
|
-
expect(group?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
2235
|
-
expect(String(group?.options?.command)).toContain('nextest run ');
|
|
2236
|
-
expect(String(group?.options?.command)).toContain(
|
|
2237
|
-
`-E '${serial}' --no-fail-fast --no-tests=fail --user-config-file none`,
|
|
2238
|
-
);
|
|
2239
|
-
expect(group?.options).not.toHaveProperty('timeoutMs');
|
|
2240
|
-
expect(group?.options?.idleTimeoutMs).toBe(BOUNDED_TEST_IDLE_TIMEOUT_MS);
|
|
2241
|
-
expect(group?.options?.killAfterMs).toBe(BOUNDED_TEST_KILL_AFTER_MS);
|
|
2242
|
-
expect(group?.options?.parallelism).toBe(1);
|
|
2243
|
-
expect(group?.inputs).toContain('{workspaceRoot}/packages/rusty/.config/nextest.toml');
|
|
2244
|
-
expect(JSON.stringify(group?.inputs)).toContain('nextest-code-bound.ts');
|
|
2245
|
-
expect(JSON.stringify(macos['cargo-test-small']?.inputs)).not.toContain('nextest-code-bound.ts');
|
|
2246
|
-
expect(String(group?.options?.command)).not.toMatch(/--partition|test-threads|max-fail/);
|
|
2247
|
-
|
|
2248
|
-
// Every crate piece excludes the group's tests, so each test is selected by exactly one target.
|
|
2249
|
-
const exceptional = exceptionalTestFilter(fileURLToPath(new URL('../nextest.toml', import.meta.url)));
|
|
2250
|
-
if (exceptional === null) {
|
|
2251
|
-
throw new Error('nextest.toml declares no overrides; this test asserts the pin that protects them');
|
|
2252
|
-
}
|
|
2253
|
-
expect(macos['cargo-test-small']?.options?.command).toContain(
|
|
2254
|
-
`-E 'package(small) and not ((test(/real_apfs_/)))' --no-fail-fast --no-tests=pass`,
|
|
2255
|
-
);
|
|
2256
|
-
for (const index of [1, 2, 3]) {
|
|
2257
|
-
expect(macos[`cargo-test-big-shard${index}`]?.options?.command).toContain(
|
|
2258
|
-
`-E 'package(big) and not (${exceptional}) and not ((test(/real_apfs_/)))' --partition hash:${index}/3 --no-fail-fast --no-tests=pass`,
|
|
2259
|
-
);
|
|
2260
|
-
expect(macos[`cargo-test-big-exceptions-shard${index}`]?.options?.command).toContain(
|
|
2261
|
-
`-E 'package(big) and (${exceptional}) and not ((test(/real_apfs_/)))' --partition hash:${index}/3 --no-fail-fast --no-tests=pass`,
|
|
2262
|
-
);
|
|
2263
|
-
}
|
|
2264
|
-
// `cargo-test` and `test` are the ordinary suite alone: neither infers an edge to the group.
|
|
2265
|
-
expect(macos['cargo-test']?.dependsOn).not.toContain('cargo-test-group-real-apfs');
|
|
2266
|
-
expect(macos.test?.dependsOn).toEqual(['cargo-test']);
|
|
2267
|
-
|
|
2268
|
-
// Off macOS nextest applies the group nowhere, so it is not inferred and no piece excludes its tests.
|
|
2269
|
-
const linux = await inferProjectTargets(
|
|
2270
|
-
workspace,
|
|
2271
|
-
'packages/rusty/package.json',
|
|
2272
|
-
createNodesV2ForPlatform('linux', 'x64'),
|
|
2273
|
-
);
|
|
2274
|
-
expect(linux['cargo-test-group-real-apfs']).toBeUndefined();
|
|
2275
|
-
expect(linux['cargo-test-small']?.options?.command).toContain(
|
|
2276
|
-
`-E 'package(small)' --no-fail-fast --no-tests=pass`,
|
|
2277
|
-
);
|
|
2278
|
-
expect(linux['cargo-test']?.dependsOn).not.toContain('cargo-test-group-real-apfs');
|
|
2279
|
-
expect(linux.test?.dependsOn).toEqual(['cargo-test']);
|
|
2280
|
-
} finally {
|
|
2281
|
-
await workspace.cleanup();
|
|
2282
|
-
}
|
|
2283
|
-
});
|
|
2284
|
-
|
|
2285
|
-
it("scopes each serial group's runner inputs to its packages and their closure, and keeps an unscoped group workspace-wide", async () => {
|
|
2286
|
-
const workspace = await createWorkspace();
|
|
2287
|
-
try {
|
|
2288
|
-
await writeApfsSplitFixture(workspace, [
|
|
2289
|
-
...APFS_SPLIT_GROUPS,
|
|
2290
|
-
'[test-groups.wide]',
|
|
2291
|
-
'max-threads = 1',
|
|
2292
|
-
'',
|
|
2293
|
-
...serialOverride('test(/wide_/)', 'wide'),
|
|
2294
|
-
]);
|
|
2295
|
-
const root = (await inferApfsSplit(workspace)).get('.') ?? {};
|
|
2296
|
-
const device = root['cargo-test-group-real-apfs'];
|
|
2297
|
-
const host = root['cargo-test-group-real-apfs-host'];
|
|
2298
|
-
const wide = root['cargo-test-group-wide'];
|
|
2299
|
-
|
|
2300
|
-
// A group scoped to packages hashes those crates and every crate they link, and no other.
|
|
2301
|
-
expect(hashedCrates(device)).toEqual(['cowshed-apfs', 'cowshed-apfs-tests', 'cowshed-os']);
|
|
2302
|
-
expect(hashedCrates(host)).toEqual(['cowshed-apfs', 'cowshed-cli', 'cowshed-core', 'cowshed-os']);
|
|
2303
|
-
// A filter scoped to no package keeps every member's tree, as the archive hashes them.
|
|
2304
|
-
expect(hashedCrates(wide)).toEqual([
|
|
2305
|
-
'cowshed-apfs',
|
|
2306
|
-
'cowshed-apfs-tests',
|
|
2307
|
-
'cowshed-cli',
|
|
2308
|
-
'cowshed-core',
|
|
2309
|
-
'cowshed-os',
|
|
2310
|
-
'lmao-core',
|
|
2311
|
-
]);
|
|
2312
|
-
|
|
2313
|
-
// The proof as the three cases it makes. An unrelated crate reruns neither scoped group. A scenario
|
|
2314
|
-
// edit reruns the device group alone: the scenarios are a crate of their own that no host crate
|
|
2315
|
-
// depends on. A change to the production substrate, or to what it links, reruns both, because the
|
|
2316
|
-
// host crates link it too. Nothing here excludes a tests tree, and the test support every real-image
|
|
2317
|
-
// binary compiles in stays hashed for both groups.
|
|
2318
|
-
const hashedBy = (path: string) => ({
|
|
2319
|
-
device: hashes(device, path),
|
|
2320
|
-
host: hashes(host, path),
|
|
2321
|
-
wide: hashes(wide, path),
|
|
2322
|
-
});
|
|
2323
|
-
expect(hashedBy('packages/lmao/crates/lmao-core/src/lib.rs')).toEqual({ device: false, host: false, wide: true });
|
|
2324
|
-
expect(hashedBy('packages/cowshed/crates/cowshed-apfs-tests/src/tests.rs')).toEqual({
|
|
2325
|
-
device: true,
|
|
2326
|
-
host: false,
|
|
2327
|
-
wide: true,
|
|
2328
|
-
});
|
|
2329
|
-
expect(hashedBy('packages/cowshed/crates/cowshed-core/src/lib.rs')).toEqual({
|
|
2330
|
-
device: false,
|
|
2331
|
-
host: true,
|
|
2332
|
-
wide: true,
|
|
2333
|
-
});
|
|
2334
|
-
expect(hashedBy('packages/cowshed/crates/cowshed-cli/src/lib.rs')).toEqual({
|
|
2335
|
-
device: false,
|
|
2336
|
-
host: true,
|
|
2337
|
-
wide: true,
|
|
2338
|
-
});
|
|
2339
|
-
for (const shared of [
|
|
2340
|
-
'packages/cowshed/crates/cowshed-apfs/src/lib.rs',
|
|
2341
|
-
'packages/cowshed/crates/cowshed-apfs/tests/support/blank_image.rs',
|
|
2342
|
-
'packages/cowshed/crates/cowshed-os/src/lib.rs',
|
|
2343
|
-
]) {
|
|
2344
|
-
expect(hashedBy(shared), shared).toEqual({ device: true, host: true, wide: true });
|
|
2345
|
-
}
|
|
2346
|
-
for (const group of [device, host]) {
|
|
2347
|
-
const exclusions = (group?.inputs ?? []).filter(
|
|
2348
|
-
(input): input is string => typeof input === 'string' && input.startsWith('!'),
|
|
2349
|
-
);
|
|
2350
|
-
expect(exclusions.filter((input) => /\btests?\b/.test(input))).toEqual([]);
|
|
2351
|
-
}
|
|
2352
|
-
|
|
2353
|
-
// Every scoped group still hashes every member manifest, the repository's nextest config and the
|
|
2354
|
-
// run-wrapper its tests are bounded by: those decide a verdict whichever crates it selects.
|
|
2355
|
-
for (const group of [device, host, wide]) {
|
|
2356
|
-
expect(group?.inputs).toContain('{workspaceRoot}/packages/lmao/crates/lmao-core/Cargo.toml');
|
|
2357
|
-
expect(group?.inputs).toContain('{workspaceRoot}/.config/nextest.toml');
|
|
2358
|
-
expect(JSON.stringify(group?.inputs)).toContain('nextest-code-bound.ts');
|
|
2359
|
-
}
|
|
2360
|
-
} finally {
|
|
2361
|
-
await workspace.cleanup();
|
|
2362
|
-
}
|
|
2363
|
-
});
|
|
2364
|
-
|
|
2365
|
-
it('refuses a serial group scoped to a package that is not a member of the Cargo workspace', async () => {
|
|
2366
|
-
const workspace = await createWorkspace();
|
|
2367
|
-
try {
|
|
2368
|
-
await writeApfsSplitFixture(workspace, [
|
|
2369
|
-
'[test-groups.real-apfs]',
|
|
2370
|
-
'max-threads = 1',
|
|
2371
|
-
'',
|
|
2372
|
-
...serialOverride('package(cowshed-missing) and test(/real_apfs_/)', 'real-apfs'),
|
|
2373
|
-
]);
|
|
2374
|
-
// Nx wraps a createNodes throw in AggregateCreateNodesError, so the reason is in the nested error.
|
|
2375
|
-
const failure = await inferApfsSplit(workspace).then(
|
|
2376
|
-
() => undefined,
|
|
2377
|
-
(error: unknown) => error,
|
|
2378
|
-
);
|
|
2379
|
-
if (!(failure instanceof AggregateCreateNodesError)) {
|
|
2380
|
-
throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
|
|
2381
|
-
}
|
|
2382
|
-
expect(failure.errors[0]?.[1]?.message).toMatch(
|
|
2383
|
-
/test-group "real-apfs" selects package\(cowshed-missing\), which is not a member of the Cargo workspace/,
|
|
2384
|
-
);
|
|
2385
|
-
} finally {
|
|
2386
|
-
await workspace.cleanup();
|
|
2387
|
-
}
|
|
2388
|
-
});
|
|
2389
|
-
|
|
2390
|
-
it('keeps cargo-test and test to the ordinary suite, so no gate of the root or a member reaches a serial group', async () => {
|
|
2391
|
-
const workspace = await createWorkspace();
|
|
2392
|
-
try {
|
|
2393
|
-
await writeApfsSplitFixture(workspace, APFS_SPLIT_GROUPS);
|
|
2394
|
-
const macos = await inferApfsSplit(workspace);
|
|
2395
|
-
const root = macos.get('.') ?? {};
|
|
2396
|
-
const cowshed = macos.get('packages/cowshed') ?? {};
|
|
2397
|
-
const lmao = macos.get('packages/lmao') ?? {};
|
|
2398
|
-
|
|
2399
|
-
// `cargo-test` is the ordinary suite alone, whichever project owns the aggregate.
|
|
2400
|
-
expect(root['cargo-test']?.dependsOn).toEqual([
|
|
2401
|
-
{ projects: ['cowshed'], target: 'cargo-test-cowshed-apfs' },
|
|
2402
|
-
{ projects: ['cowshed'], target: 'cargo-test-cowshed-apfs-tests' },
|
|
2403
|
-
{ projects: ['cowshed'], target: 'cargo-test-cowshed-cli' },
|
|
2404
|
-
{ projects: ['cowshed'], target: 'cargo-test-cowshed-core' },
|
|
2405
|
-
{ projects: ['cowshed'], target: 'cargo-test-cowshed-os' },
|
|
2406
|
-
{ projects: ['lmao'], target: 'cargo-test-lmao-core' },
|
|
2407
|
-
]);
|
|
2408
|
-
expect(cowshed['cargo-test']?.dependsOn).toEqual([
|
|
2409
|
-
'cargo-test-cowshed-apfs',
|
|
2410
|
-
'cargo-test-cowshed-apfs-tests',
|
|
2411
|
-
'cargo-test-cowshed-cli',
|
|
2412
|
-
'cargo-test-cowshed-core',
|
|
2413
|
-
'cargo-test-cowshed-os',
|
|
2414
|
-
]);
|
|
2415
|
-
expect(lmao['cargo-test']?.dependsOn).toEqual(['cargo-test-lmao-core']);
|
|
2416
|
-
|
|
2417
|
-
// Ordinary test inference excludes serial groups at both the root and every member. Explicit repository
|
|
2418
|
-
// host aggregates, not inference, own those edges.
|
|
2419
|
-
for (const targets of [root, cowshed, lmao]) {
|
|
2420
|
-
expect(targets.test?.dependsOn).toEqual(['cargo-test']);
|
|
2421
|
-
}
|
|
2422
|
-
|
|
2423
|
-
// Inference orders nothing between the groups: that edge is the repository's explicit config.
|
|
2424
|
-
for (const name of ['cargo-test-group-real-apfs', 'cargo-test-group-real-apfs-host']) {
|
|
2425
|
-
expect(root[name]?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
|
|
2426
|
-
}
|
|
2427
|
-
|
|
2428
|
-
// Every crate piece, scoped to a package the groups hold or not, excludes both groups' tests.
|
|
2429
|
-
const exclusion =
|
|
2430
|
-
'not ((package(cowshed-apfs-tests) and test(/real_apfs_/)) or ' +
|
|
2431
|
-
'(package(cowshed-core) and (test(/real_apfs_/) or binary(apfs_native_macos))) or ' +
|
|
2432
|
-
'(package(cowshed-cli) and test(/real_apfs_/)))';
|
|
2433
|
-
const pieces: ReadonlyArray<readonly [TargetConfiguration | undefined, string]> = [
|
|
2434
|
-
[cowshed['cargo-test-cowshed-apfs'], 'cowshed-apfs'],
|
|
2435
|
-
[cowshed['cargo-test-cowshed-apfs-tests'], 'cowshed-apfs-tests'],
|
|
2436
|
-
[lmao['cargo-test-lmao-core'], 'lmao-core'],
|
|
2437
|
-
];
|
|
2438
|
-
for (const [piece, crate] of pieces) {
|
|
2439
|
-
expect(piece?.options?.command, crate).toContain(
|
|
2440
|
-
`-E 'package(${crate}) and ${exclusion}' --no-fail-fast --no-tests=pass`,
|
|
2441
|
-
);
|
|
2442
|
-
}
|
|
2443
|
-
|
|
2444
|
-
// Off macOS the groups are not inferred at all, and the gate is the same ordinary suite.
|
|
2445
|
-
const linux = await inferApfsSplit(workspace, createNodesV2ForPlatform('linux', 'x64'));
|
|
2446
|
-
expect(linux.get('.')?.test?.dependsOn).toEqual(['cargo-test']);
|
|
2447
|
-
expect(linux.get('packages/cowshed')?.test?.dependsOn).toEqual(['cargo-test']);
|
|
2448
|
-
expect(linux.get('.')?.['cargo-test-group-real-apfs-host']).toBeUndefined();
|
|
2449
|
-
} finally {
|
|
2450
|
-
await workspace.cleanup();
|
|
2451
|
-
}
|
|
2452
|
-
});
|
|
2453
|
-
|
|
2454
|
-
it('runs the host group after the device group through the explicit targetDefaults edge, and no test gate runs either', async () => {
|
|
2455
|
-
const workspace = await createWorkspace();
|
|
2456
|
-
try {
|
|
2457
|
-
await writeApfsSplitFixture(workspace, APFS_SPLIT_GROUPS);
|
|
2458
|
-
const macos = await inferApfsSplit(workspace);
|
|
2459
|
-
const rootProject = '@fixture/codebase';
|
|
2460
|
-
const rootTargets = macos.get('.') ?? {};
|
|
2461
|
-
|
|
2462
|
-
// The edge as the repository's nx.json states it. Nx expands `...` to the inferred list, so the
|
|
2463
|
-
// archive and the locked fetch stay ahead of the host group beside the device group.
|
|
2464
|
-
const nxJson = {
|
|
2465
|
-
targetDefaults: { 'cargo-test-group-real-apfs-host': { dependsOn: ['...', 'cargo-test-group-real-apfs'] } },
|
|
2466
|
-
};
|
|
2467
|
-
let host = rootTargets['cargo-test-group-real-apfs-host'] ?? {};
|
|
2468
|
-
for (const [, , result] of createTargetDefaultsResults(
|
|
2469
|
-
{ '.': { root: '.', targets: rootTargets } },
|
|
2470
|
-
{},
|
|
2471
|
-
nxJson,
|
|
2472
|
-
)) {
|
|
2473
|
-
const target = result.projects?.['.']?.targets?.['cargo-test-group-real-apfs-host'];
|
|
2474
|
-
if (target) host = mergeTargetConfigurations(target, host);
|
|
2475
|
-
}
|
|
2476
|
-
expect(host.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive', 'cargo-test-group-real-apfs']);
|
|
2477
|
-
|
|
2478
|
-
const nodes: Record<string, ProjectGraphProjectNode> = {
|
|
2479
|
-
[rootProject]: {
|
|
2480
|
-
name: rootProject,
|
|
2481
|
-
type: 'app',
|
|
2482
|
-
data: { root: '.', targets: { ...rootTargets, 'cargo-test-group-real-apfs-host': host } },
|
|
2483
|
-
},
|
|
2484
|
-
cowshed: {
|
|
2485
|
-
name: 'cowshed',
|
|
2486
|
-
type: 'lib',
|
|
2487
|
-
data: { root: 'packages/cowshed', targets: macos.get('packages/cowshed') ?? {} },
|
|
2488
|
-
},
|
|
2489
|
-
lmao: {
|
|
2490
|
-
name: 'lmao',
|
|
2491
|
-
type: 'lib',
|
|
2492
|
-
data: { root: 'packages/lmao', targets: macos.get('packages/lmao') ?? {} },
|
|
2493
|
-
},
|
|
2494
|
-
};
|
|
2495
|
-
const graph: ProjectGraph = { nodes, dependencies: { [rootProject]: [], cowshed: [], lmao: [] } };
|
|
2496
|
-
const task = (project: string, target: string): string => `${project}:${target}`;
|
|
2497
|
-
// Every task `from` waits on, directly or through the tasks it waits on.
|
|
2498
|
-
const reached = (dependencies: Record<string, string[]>, from: string): string[] => {
|
|
2499
|
-
const seen = new Set<string>();
|
|
2500
|
-
const pending = [from];
|
|
2501
|
-
while (pending.length > 0) {
|
|
2502
|
-
const next = pending.pop();
|
|
2503
|
-
if (next === undefined || seen.has(next)) continue;
|
|
2504
|
-
seen.add(next);
|
|
2505
|
-
pending.push(...(dependencies[next] ?? []));
|
|
2506
|
-
}
|
|
2507
|
-
return [...seen];
|
|
2508
|
-
};
|
|
2509
|
-
const groupsReached = (dependencies: Record<string, string[]>, from: string): string[] =>
|
|
2510
|
-
reached(dependencies, from).filter((id) => id.includes(':cargo-test-group-'));
|
|
2511
|
-
const device = task(rootProject, 'cargo-test-group-real-apfs');
|
|
2512
|
-
const hosted = task(rootProject, 'cargo-test-group-real-apfs-host');
|
|
2513
|
-
|
|
2514
|
-
// The task graph `nx run-many -t test` runs reaches neither group, from the root or from a member.
|
|
2515
|
-
for (const project of [rootProject, 'cowshed']) {
|
|
2516
|
-
const gate = createTaskGraph(graph, {}, [project], ['test'], undefined, {});
|
|
2517
|
-
expect(groupsReached(gate.dependencies, task(project, 'test'))).toEqual([]);
|
|
2518
|
-
}
|
|
2519
|
-
|
|
2520
|
-
// When a run selects both groups, the host starts only once the device group is done, so two real-image
|
|
2521
|
-
// runners never overlap, and the device group waits on no other group.
|
|
2522
|
-
const named = createTaskGraph(
|
|
2523
|
-
graph,
|
|
2524
|
-
{},
|
|
2525
|
-
[rootProject],
|
|
2526
|
-
['test', 'cargo-test-group-real-apfs', 'cargo-test-group-real-apfs-host'],
|
|
2527
|
-
undefined,
|
|
2528
|
-
{},
|
|
2529
|
-
);
|
|
2530
|
-
expect(named.dependencies[hosted]).toContain(device);
|
|
2531
|
-
expect(groupsReached(named.dependencies, device)).toEqual([device]);
|
|
2532
|
-
expect(groupsReached(named.dependencies, task(rootProject, 'test'))).toEqual([]);
|
|
2533
|
-
} finally {
|
|
2534
|
-
await workspace.cleanup();
|
|
2535
|
-
}
|
|
2536
|
-
});
|
|
2537
|
-
|
|
2538
|
-
it('rejects a shard count that cannot describe a partition', async () => {
|
|
2539
|
-
const workspace = await createWorkspace();
|
|
2540
|
-
try {
|
|
2541
|
-
await workspace.write('packages/rusty/package.json', '{"name":"rusty"}\n');
|
|
2542
|
-
await workspace.write('packages/rusty/Cargo.toml', '[workspace]\nmembers = ["crates/big"]\n');
|
|
2543
|
-
await workspace.write(
|
|
2544
|
-
'packages/rusty/crates/big/Cargo.toml',
|
|
2545
|
-
'[package]\nname = "big"\n\n[package.metadata.smoothbricks.test]\nshards = 0\n',
|
|
2546
|
-
);
|
|
2547
|
-
|
|
2548
|
-
// Nx wraps a createNodes throw in AggregateCreateNodesError, so the
|
|
2549
|
-
// reason a maintainer needs is in the nested error, not the top message.
|
|
2550
|
-
const failure = await inferProjectTargets(workspace, 'packages/rusty/package.json').then(
|
|
2551
|
-
() => undefined,
|
|
2552
|
-
(error: unknown) => error,
|
|
2553
|
-
);
|
|
2554
|
-
if (!(failure instanceof AggregateCreateNodesError)) {
|
|
2555
|
-
throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
|
|
2556
|
-
}
|
|
2557
|
-
expect(failure.errors[0]?.[1]?.message).toMatch(/smoothbricks\.test\.shards must be an integer >= 1, got 0/);
|
|
2558
|
-
} finally {
|
|
2559
|
-
await workspace.cleanup();
|
|
2560
|
-
}
|
|
2561
|
-
});
|
|
2562
|
-
|
|
2563
|
-
it('lets explicit nx.targets suppress output and aggregate inference, and skips non-workspace Cargo.toml', async () => {
|
|
2564
|
-
const workspace = await createWorkspace();
|
|
2565
|
-
try {
|
|
2566
|
-
await workspace.write(
|
|
2567
|
-
'packages/custom/package.json',
|
|
2568
|
-
'{"name":"custom","nx":{"targets":{"cargo-wasm":{"options":{"command":"custom"}},"test":{}}}}\n',
|
|
2569
|
-
);
|
|
2570
|
-
await workspace.write('packages/custom/Cargo.toml', '[workspace]\nmembers = ["crates/x-wasm"]\n');
|
|
2571
|
-
await workspace.write(
|
|
2572
|
-
'packages/custom/crates/x-wasm/Cargo.toml',
|
|
2573
|
-
'[package]\nname = "x-wasm"\n\n[lib]\ncrate-type = ["cdylib"]\n',
|
|
2574
|
-
);
|
|
2575
|
-
|
|
2576
|
-
const targets = await inferProjectTargets(workspace, 'packages/custom/package.json');
|
|
2577
|
-
expect(targets['cargo-wasm']).toBeUndefined();
|
|
2578
|
-
expect(targets.test).toEqual({ dependsOn: ['^build', 'build'] });
|
|
2579
|
-
expect(targets['cargo-test']).toBeDefined();
|
|
2580
|
-
|
|
2581
|
-
// A member crate's own Cargo.toml (no [workspace]) infers nothing.
|
|
2582
|
-
await workspace.write('packages/member/package.json', '{"name":"member"}\n');
|
|
2583
|
-
await workspace.write('packages/member/Cargo.toml', '[package]\nname = "member"\n');
|
|
2584
|
-
const memberTargets = await inferProjectTargets(workspace, 'packages/member/package.json');
|
|
2585
|
-
expect(memberTargets).toEqual({});
|
|
2586
|
-
} finally {
|
|
2587
|
-
await workspace.cleanup();
|
|
2588
|
-
}
|
|
2589
|
-
});
|
|
2590
|
-
|
|
2591
|
-
it('gives a declared TypeScript test the ^build/build dependsOn base targetDefaults must not supply', async () => {
|
|
2592
|
-
const workspace = await createWorkspace();
|
|
2593
|
-
try {
|
|
2594
|
-
await workspace.write(
|
|
2595
|
-
'packages/money/package.json',
|
|
2596
|
-
JSON.stringify({
|
|
2597
|
-
name: 'money',
|
|
2598
|
-
nx: {
|
|
2599
|
-
targets: {
|
|
2600
|
-
test: {
|
|
2601
|
-
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
2602
|
-
options: { command: 'bun test', cwd: '{projectRoot}' },
|
|
2603
|
-
},
|
|
2604
|
-
},
|
|
2605
|
-
},
|
|
2606
|
-
}),
|
|
2607
|
-
);
|
|
2608
|
-
await workspace.write('packages/money/tsconfig.lib.json', '{}\n');
|
|
2609
|
-
|
|
2610
|
-
const targets = await inferProjectTargets(workspace, 'packages/money/package.json');
|
|
2611
|
-
expect(targets.test).toEqual({ dependsOn: ['^build', 'build'] });
|
|
2612
|
-
expect(targets['cargo-test']).toBeUndefined();
|
|
2613
|
-
} finally {
|
|
2614
|
-
await workspace.cleanup();
|
|
2615
|
-
}
|
|
2616
|
-
});
|
|
2617
|
-
|
|
2618
|
-
it('keeps inferring a cargo target the package partially declares', async () => {
|
|
2619
|
-
const workspace = await createWorkspace();
|
|
2620
|
-
const declared: Record<string, TargetConfiguration> = {
|
|
2621
|
-
// One added edge per target. Everything that makes each target do its job
|
|
2622
|
-
// — executor, options, inputs, cache — must survive the declaration
|
|
2623
|
-
// instead of being replaced wholesale by it.
|
|
2624
|
-
'cargo-test': { dependsOn: ['cargo-test-ferris-core', 'cargo-wasm'] },
|
|
2625
|
-
'cargo-test-compile': { dependsOn: ['cargo-wasm'] },
|
|
2626
|
-
'cargo-lint': { inputs: ['{projectRoot}/clippy.toml'] },
|
|
2627
|
-
mutation: { options: { command: 'cargo mutants --in-diff' } },
|
|
2628
|
-
bench: { cache: true },
|
|
2629
|
-
};
|
|
2630
|
-
try {
|
|
2631
|
-
await workspace.write(
|
|
2632
|
-
'packages/ferris/package.json',
|
|
2633
|
-
JSON.stringify({ name: 'ferris', nx: { targets: declared } }),
|
|
2634
|
-
);
|
|
2635
|
-
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = ["crates/ferris-core"]\n');
|
|
2636
|
-
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
2637
|
-
|
|
2638
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
2639
|
-
|
|
2640
|
-
// The aggregate stays a no-op that reaches bounded crate runners. A
|
|
2641
|
-
// partial declaration must keep that inferred base, not erase the chain.
|
|
2642
|
-
expect(targets['cargo-test']?.executor).toBe('nx:noop');
|
|
2643
|
-
expect(targets['cargo-test-ferris-core']?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
2644
|
-
expect(targets['cargo-test-compile']?.executor).toBe('nx:run-commands');
|
|
2645
|
-
expect(targets['cargo-lint']?.options).toMatchObject({
|
|
2646
|
-
commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
|
|
2647
|
-
});
|
|
2648
|
-
|
|
2649
|
-
const cargoTest = resolveDeclaredOverInferred(targets, declared, 'cargo-test');
|
|
2650
|
-
expect(cargoTest?.executor).toBe('nx:noop');
|
|
2651
|
-
expect(cargoTest?.cache).toBe(true);
|
|
2652
|
-
expect(cargoTest?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-wasm']);
|
|
2653
|
-
expect(cargoTest?.options).toBeUndefined();
|
|
2654
|
-
expect(targets['cargo-test-ferris-core']?.options?.command).toContain("-E 'package(ferris-core)'");
|
|
2655
|
-
expect(targets['cargo-test-ferris-core']?.options?.idleTimeoutMs).toBe(BOUNDED_TEST_IDLE_TIMEOUT_MS);
|
|
2656
|
-
|
|
2657
|
-
const cargoTestCompile = resolveDeclaredOverInferred(targets, declared, 'cargo-test-compile');
|
|
2658
|
-
expect(cargoTestCompile?.executor).toBe('nx:run-commands');
|
|
2659
|
-
// A replacing array drops every inferred edge, cargo-fetch included: the
|
|
2660
|
-
// package now owns ordering the locked fetch ahead of its frozen compile.
|
|
2661
|
-
expect(cargoTestCompile?.dependsOn).toEqual(['cargo-wasm']);
|
|
2662
|
-
expect(targets['cargo-test-compile']?.dependsOn).toEqual(['cargo-fetch']);
|
|
2663
|
-
expect(cargoTestCompile?.options).toMatchObject({
|
|
2664
|
-
command: 'cargo --frozen test --workspace --no-run',
|
|
2665
|
-
});
|
|
2666
|
-
|
|
2667
|
-
// A declared array replaces the inferred one; the command it guards stays.
|
|
2668
|
-
const cargoLint = resolveDeclaredOverInferred(targets, declared, 'cargo-lint');
|
|
2669
|
-
expect(cargoLint?.inputs).toEqual(['{projectRoot}/clippy.toml']);
|
|
2670
|
-
expect(cargoLint?.options).toMatchObject({
|
|
2671
|
-
commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
|
|
2672
|
-
});
|
|
2673
|
-
|
|
2674
|
-
// `options` merges key by key, so a declared command overrides only itself.
|
|
2675
|
-
const mutation = resolveDeclaredOverInferred(targets, declared, 'mutation');
|
|
2676
|
-
expect(mutation?.options).toEqual({
|
|
2677
|
-
command: 'cargo mutants --in-diff',
|
|
2678
|
-
cwd: 'packages/ferris',
|
|
2679
|
-
timeoutMs: 6 * 60 * 60 * 1000,
|
|
2680
|
-
});
|
|
2681
|
-
expect(mutation?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
2682
|
-
expect(mutation?.cache).toBe(false);
|
|
2683
|
-
|
|
2684
|
-
const bench = resolveDeclaredOverInferred(targets, declared, 'bench');
|
|
2685
|
-
expect(bench?.cache).toBe(true);
|
|
2686
|
-
expect(bench?.options).toMatchObject({ command: 'cargo --frozen bench --workspace' });
|
|
2687
|
-
} finally {
|
|
2688
|
-
await workspace.cleanup();
|
|
2689
|
-
}
|
|
2690
|
-
});
|
|
2691
|
-
|
|
2692
|
-
it('lets a declared dependsOn spread expand the inferred cargo chain', async () => {
|
|
2693
|
-
const workspace = await createWorkspace();
|
|
2694
|
-
// Additive intent has Nx's own spelling: `'...'` expands the inferred list
|
|
2695
|
-
// at the token, so an added edge keeps the inferred cargo edges.
|
|
2696
|
-
const declared: Record<string, TargetConfiguration> = {
|
|
2697
|
-
'cargo-test': { dependsOn: ['...', 'cargo-wasm'] },
|
|
2698
|
-
};
|
|
2699
|
-
try {
|
|
2700
|
-
await workspace.write(
|
|
2701
|
-
'packages/ferris/package.json',
|
|
2702
|
-
JSON.stringify({ name: 'ferris', nx: { targets: declared } }),
|
|
2703
|
-
);
|
|
2704
|
-
await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = ["crates/ferris-core"]\n');
|
|
2705
|
-
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
2706
|
-
|
|
2707
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
2708
|
-
|
|
2709
|
-
// The spread expands exactly once, against the single inferred base this
|
|
2710
|
-
// plugin emits — re-implementing the overlay here would double it.
|
|
2711
|
-
const cargoTest = resolveDeclaredOverInferred(targets, declared, 'cargo-test');
|
|
2712
|
-
expect(cargoTest?.dependsOn).toEqual(['cargo-test-ferris-core', 'cargo-wasm']);
|
|
2713
|
-
expect(cargoTest?.executor).toBe('nx:noop');
|
|
2714
|
-
} finally {
|
|
2715
|
-
await workspace.cleanup();
|
|
2716
|
-
}
|
|
2717
|
-
});
|
|
2718
|
-
|
|
2719
|
-
it('gives a private wrangler project a deploy that runs the stage CLI, uncached, behind its build half', async () => {
|
|
2720
|
-
const workspace = await createWorkspace();
|
|
2721
|
-
try {
|
|
2722
|
-
await workspace.write('packages/site/package.json', '{"name":"site","private":true}\n');
|
|
2723
|
-
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
2724
|
-
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
2725
|
-
|
|
2726
|
-
// One target taking a stage, never a configuration per stage: pull-request stages are
|
|
2727
|
-
// `prN` for unbounded N, so `--configuration` could not name the stage that matters most.
|
|
2728
|
-
expect(targets.deploy?.options).toEqual({
|
|
2729
|
-
command: 'smoo wrangler deploy-stage --stage {args.stage}',
|
|
2730
|
-
cwd: 'packages/site',
|
|
2731
|
-
});
|
|
2732
|
-
// A cache hit on deploy would mean "we once uploaded this hash", which a rollback falsifies
|
|
2733
|
-
// silently; the step has to run and read live state instead.
|
|
2734
|
-
expect(targets.deploy?.cache).toBe(false);
|
|
2735
|
-
expect(targets.deploy?.outputs).toEqual([]);
|
|
2736
|
-
// No build half of any kind here, so no edge is claimed: wrangler bundles its own
|
|
2737
|
-
// TypeScript, so a worker with neither `build` nor `deploy-build` is legitimate.
|
|
2738
|
-
expect(targets.deploy?.dependsOn).toBeUndefined();
|
|
2739
|
-
} finally {
|
|
2740
|
-
await workspace.cleanup();
|
|
2741
|
-
}
|
|
2742
|
-
});
|
|
2743
|
-
|
|
2744
|
-
it('infers no deploy for a PUBLISHED package whose wrangler manifest documents a binding', async () => {
|
|
2745
|
-
const workspace = await createWorkspace();
|
|
2746
|
-
try {
|
|
2747
|
-
// The shape that regressed a consumer: a library published to npm that ships a wrangler
|
|
2748
|
-
// manifest so consumers can declare the Durable Object binding it implements. Structurally
|
|
2749
|
-
// identical to a worker's, so only the manifest's own `private` flag tells them apart.
|
|
2750
|
-
await workspace.write(
|
|
2751
|
-
'packages/acme-cloudflare/package.json',
|
|
2752
|
-
'{"name":"@acme/cloudflare","nx":{"tags":["npm:private"]}}\n',
|
|
2753
|
-
);
|
|
2754
|
-
await workspace.write(
|
|
2755
|
-
'packages/acme-cloudflare/wrangler.toml',
|
|
2756
|
-
'# Wrangler configuration for @acme/cloudflare Durable Object\nname = "acme-cloudflare"\nmain = "src/index.ts"\ncompatibility_date = "2025-01-01"\n',
|
|
2757
|
-
);
|
|
2758
|
-
const targets = await inferProjectTargets(workspace, 'packages/acme-cloudflare/package.json');
|
|
2759
|
-
|
|
2760
|
-
expect(Object.keys(targets)).not.toContain('deploy');
|
|
2761
|
-
} finally {
|
|
2762
|
-
await workspace.cleanup();
|
|
2763
|
-
}
|
|
2764
|
-
});
|
|
2765
|
-
|
|
2766
|
-
it('points an inferred deploy at the declared deploy-build, and caches that half', async () => {
|
|
2767
|
-
const workspace = await createWorkspace();
|
|
2768
|
-
const declared = {
|
|
2769
|
-
'deploy-build': { executor: 'nx:run-commands', options: { command: 'bun tooling/build-site.ts' } },
|
|
2770
|
-
};
|
|
2771
|
-
try {
|
|
2772
|
-
await workspace.write(
|
|
2773
|
-
'packages/site/package.json',
|
|
2774
|
-
JSON.stringify({ name: 'site', private: true, nx: { targets: declared } }),
|
|
2775
|
-
);
|
|
2776
|
-
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
2777
|
-
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
2778
|
-
|
|
2779
|
-
expect(targets.deploy?.dependsOn).toEqual(['deploy-build']);
|
|
2780
|
-
// Only the project knows what building it means, so the plugin supplies the policy for
|
|
2781
|
-
// that half and nothing else.
|
|
2782
|
-
expect(resolveDeclaredOverInferred(targets, declared, 'deploy-build')?.cache).toBe(true);
|
|
2783
|
-
expect(resolveDeclaredOverInferred(targets, declared, 'deploy-build')?.options).toEqual({
|
|
2784
|
-
command: 'bun tooling/build-site.ts',
|
|
2785
|
-
});
|
|
2786
|
-
} finally {
|
|
2787
|
-
await workspace.cleanup();
|
|
2788
|
-
}
|
|
2789
|
-
});
|
|
2790
|
-
|
|
2791
|
-
it('falls back to the aggregate build when a wrangler project emits one', async () => {
|
|
2792
|
-
const workspace = await createWorkspace();
|
|
2793
|
-
try {
|
|
2794
|
-
await workspace.write('packages/site/package.json', '{"name":"site","private":true}\n');
|
|
2795
|
-
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
2796
|
-
// tsconfig.lib.json is what puts an emitting target, and so the `build` aggregate, on a project.
|
|
2797
|
-
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
2798
|
-
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
2799
|
-
|
|
2800
|
-
expect(targets.build).toBeDefined();
|
|
2801
|
-
expect(targets.deploy?.dependsOn).toEqual(['build']);
|
|
2802
|
-
} finally {
|
|
2803
|
-
await workspace.cleanup();
|
|
2804
|
-
}
|
|
2805
|
-
});
|
|
2806
|
-
|
|
2807
|
-
it('lets a dependsOn-only declaration add a cross-project edge without restating the command', async () => {
|
|
2808
|
-
const workspace = await createWorkspace();
|
|
2809
|
-
// The whole point of inferring: ordering is expressed in Nx's own vocabulary, and the
|
|
2810
|
-
// consumer never retypes the command, cwd, cache or outputs to get it.
|
|
2811
|
-
const declared: Record<string, TargetConfiguration> = {
|
|
2812
|
-
deploy: { dependsOn: ['...', { projects: ['backend'], target: 'deploy', params: 'forward' }] },
|
|
2813
|
-
};
|
|
2814
|
-
try {
|
|
2815
|
-
await workspace.write(
|
|
2816
|
-
'packages/site/package.json',
|
|
2817
|
-
JSON.stringify({ name: 'site', private: true, nx: { targets: declared } }),
|
|
2818
|
-
);
|
|
2819
|
-
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
2820
|
-
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
2821
|
-
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
2822
|
-
|
|
2823
|
-
const deploy = resolveDeclaredOverInferred(targets, declared, 'deploy');
|
|
2824
|
-
// `...` expands to the inferred list at its position, so the inferred build edge survives
|
|
2825
|
-
// beside the declared one.
|
|
2826
|
-
expect(deploy?.dependsOn).toEqual(['build', { projects: ['backend'], target: 'deploy', params: 'forward' }]);
|
|
2827
|
-
expect(deploy?.options).toEqual({
|
|
2828
|
-
command: 'smoo wrangler deploy-stage --stage {args.stage}',
|
|
2829
|
-
cwd: 'packages/site',
|
|
2830
|
-
});
|
|
2831
|
-
expect(deploy?.cache).toBe(false);
|
|
2832
|
-
expect(deploy?.outputs).toEqual([]);
|
|
2833
|
-
} finally {
|
|
2834
|
-
await workspace.cleanup();
|
|
2835
|
-
}
|
|
2836
|
-
});
|
|
2837
|
-
|
|
2838
|
-
it('infers no deploy for a project with no wrangler manifest', async () => {
|
|
2839
|
-
const workspace = await createWorkspace();
|
|
2840
|
-
try {
|
|
2841
|
-
await workspace.write('packages/lib/package.json', '{"name":"plain-lib"}\n');
|
|
2842
|
-
const targets = await inferProjectTargets(workspace, 'packages/lib/package.json');
|
|
2843
|
-
|
|
2844
|
-
expect(Object.keys(targets)).not.toContain('deploy');
|
|
2845
|
-
expect(Object.keys(targets)).not.toContain('deploy-build');
|
|
2846
|
-
} finally {
|
|
2847
|
-
await workspace.cleanup();
|
|
2848
|
-
}
|
|
2849
|
-
});
|
|
2850
|
-
|
|
2851
|
-
it('orders a three-project chain of INFERRED deploys through one run-many', async () => {
|
|
2852
|
-
const workspace = await createWorkspace();
|
|
2853
|
-
// c is deepest: a's deploy calls into b's, b's calls into c's. No project declares a deploy
|
|
2854
|
-
// target — each only has a wrangler manifest and, where it needs ordering, the edge. Nothing
|
|
2855
|
-
// here says "round one" or "round two", and no project knows the depth.
|
|
2856
|
-
const chain: Record<string, string[]> = { a: ['b:deploy'], b: ['c:deploy'], c: [] };
|
|
2857
|
-
try {
|
|
2858
|
-
const nodes: Record<string, ProjectGraphProjectNode> = {};
|
|
2859
|
-
for (const [name, edges] of Object.entries(chain)) {
|
|
2860
|
-
const declared: Record<string, TargetConfiguration> =
|
|
2861
|
-
edges.length > 0 ? { deploy: { dependsOn: ['...', ...edges] } } : {};
|
|
2862
|
-
await workspace.write(`packages/${name}/wrangler.toml`, `name = "${name}"\n`);
|
|
2863
|
-
await workspace.write(
|
|
2864
|
-
`packages/${name}/package.json`,
|
|
2865
|
-
JSON.stringify({ name, private: true, nx: { targets: declared } }),
|
|
2866
|
-
);
|
|
2867
|
-
const targets = await inferProjectTargets(workspace, `packages/${name}/package.json`);
|
|
2868
|
-
const deploy = resolveDeclaredOverInferred(targets, declared, 'deploy');
|
|
2869
|
-
// The edge rides on the inferred target: its executor and command still carry the run.
|
|
2870
|
-
expect(deploy?.executor).toBe('nx:run-commands');
|
|
2871
|
-
expect(deploy?.options?.command).toBe('smoo wrangler deploy-stage --stage {args.stage}');
|
|
2872
|
-
if (deploy === undefined) throw new Error(`${name} infers no deploy`);
|
|
2873
|
-
nodes[name] = { name, type: 'app', data: { root: `packages/${name}`, targets: { ...targets, deploy } } };
|
|
2874
|
-
}
|
|
2875
|
-
const graph: ProjectGraph = { nodes, dependencies: { a: [], b: [], c: [] } };
|
|
2876
|
-
|
|
2877
|
-
// The task graph `nx run-many -t deploy --projects=a,b,c` runs: Nx starts a task only once
|
|
2878
|
-
// every task it depends on has finished, so this is the order.
|
|
2879
|
-
const tasks = createTaskGraph(graph, {}, ['a', 'b', 'c'], ['deploy'], undefined, { stage: 'staging' });
|
|
2880
|
-
expect(tasks.dependencies).toEqual({ 'a:deploy': ['b:deploy'], 'b:deploy': ['c:deploy'], 'c:deploy': [] });
|
|
2881
|
-
expect(tasks.roots).toEqual(['c:deploy']);
|
|
2882
|
-
} finally {
|
|
2883
|
-
await workspace.cleanup();
|
|
2884
|
-
}
|
|
2885
|
-
});
|
|
2886
|
-
|
|
2887
|
-
it('archives a declared foreign triple beside the host archive, and runs it without building', async () => {
|
|
2888
|
-
const workspace = await createWorkspace();
|
|
2889
|
-
try {
|
|
2890
|
-
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
2891
|
-
await workspace.write(
|
|
2892
|
-
'packages/ferris/Cargo.toml',
|
|
2893
|
-
'[workspace]\nmembers = ["crates/ferris-core"]\n\n' +
|
|
2894
|
-
'[workspace.metadata.smoothbricks.test]\n' +
|
|
2895
|
-
'cross-targets = [{ target = "aarch64-apple-darwin", cargo = "scripts/cargo-for-nextest.sh" }]\n',
|
|
2896
|
-
);
|
|
2897
|
-
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
2898
|
-
await workspace.write('packages/ferris/scripts/cargo-for-nextest.sh', '#!/bin/sh\nexec cargo "$@"\n');
|
|
2899
|
-
|
|
2900
|
-
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
2901
|
-
const archive = targets['cargo-cross-test-archive-aarch64-apple-darwin'];
|
|
2902
|
-
const run = targets['cargo-cross-test-aarch64-apple-darwin'];
|
|
2903
|
-
|
|
2904
|
-
// A distinct archive file, declared as this target's output: the host
|
|
2905
|
-
// archive must survive a cross build and each must be cached as itself.
|
|
2906
|
-
expect(archive?.outputs).toEqual(['{projectRoot}/.cache/nextest/archive-aarch64-apple-darwin.tar.zst']);
|
|
2907
|
-
expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/.cache/nextest/archive.tar.zst']);
|
|
2908
|
-
expect(archive?.cache).toBe(true);
|
|
2909
|
-
// Everything the host archive hashes, plus the declared driver: the
|
|
2910
|
-
// script that decides how the foreign link happens is an input of the
|
|
2911
|
-
// bytes it produces.
|
|
2912
|
-
for (const input of targets['cargo-test-archive']?.inputs ?? []) {
|
|
2913
|
-
expect(archive?.inputs).toContainEqual(input);
|
|
2914
|
-
}
|
|
2915
|
-
expect(archive?.inputs).toContain('{projectRoot}/scripts/cargo-for-nextest.sh');
|
|
2916
|
-
expect(archive?.options?.env).toEqual({ CARGO: 'scripts/cargo-for-nextest.sh' });
|
|
2917
|
-
// The runner needs no driver: it never invokes cargo at all.
|
|
2918
|
-
expect(run?.options?.env).toBeUndefined();
|
|
2919
|
-
expect(archive?.options?.commands).toBeUndefined();
|
|
2920
|
-
// `cargo-nextest`, not `cargo nextest`: cargo overwrites CARGO for its
|
|
2921
|
-
// subcommands, and CARGO is the only seam a cross cargo driver has.
|
|
2922
|
-
expect(String(archive?.options?.command)).toMatch(
|
|
2923
|
-
/^mkdir -p \.cache\/nextest && cargo-nextest nextest archive --workspace --target aarch64-apple-darwin --frozen --archive-file \.cache\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
2924
|
-
);
|
|
2925
|
-
expect(archive?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
|
|
2926
|
-
expect(run?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
|
|
2927
|
-
// The archive BUILDS, so it needs the locked registry graph; the runner
|
|
2928
|
-
// never touches cargo, so it needs nothing and depends on nothing.
|
|
2929
|
-
expect(archive?.dependsOn).toEqual(['cargo-fetch']);
|
|
2930
|
-
expect(run?.dependsOn).toEqual([]);
|
|
2931
|
-
expect(String(run?.options?.command)).toMatch(
|
|
2932
|
-
/^cargo-nextest nextest run --archive-file \.cache\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --workspace-remap \. --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
2933
|
-
);
|
|
2934
|
-
expect(run?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
2935
|
-
// Not a crate: the per-crate coverage policy reads `cargo-test-<name>`,
|
|
2936
|
-
// so a triple must not land in that namespace, and neither target may
|
|
2937
|
-
// join the test aggregate a host machine runs.
|
|
2938
|
-
expect(packageNameFromCargoTestTarget('cargo-cross-test-archive-aarch64-apple-darwin')).toBeNull();
|
|
2939
|
-
expect(packageNameFromCargoTestTarget('cargo-cross-test-aarch64-apple-darwin')).toBeNull();
|
|
2940
|
-
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core']);
|
|
2941
|
-
expect(targets.build?.dependsOn ?? []).not.toContain('cargo-cross-test-archive-aarch64-apple-darwin');
|
|
2942
|
-
expectNoSchedulerThrottle(targets);
|
|
2943
|
-
} finally {
|
|
2944
|
-
await workspace.cleanup();
|
|
2945
|
-
}
|
|
2946
|
-
});
|
|
2947
|
-
|
|
2948
|
-
it('refuses a cross-targets declaration that cannot name a target or a file', async () => {
|
|
2949
|
-
const workspace = await createWorkspace();
|
|
2950
|
-
try {
|
|
2951
|
-
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
2952
|
-
await workspace.write(
|
|
2953
|
-
'packages/ferris/Cargo.toml',
|
|
2954
|
-
'[workspace]\nmembers = ["crates/ferris-core"]\n\n' +
|
|
2955
|
-
'[workspace.metadata.smoothbricks.test]\ncross-targets = ["aarch64 apple darwin; rm -rf /"]\n',
|
|
2956
|
-
);
|
|
2957
|
-
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
2958
|
-
|
|
2959
|
-
const failure = await inferProjectTargets(workspace, 'packages/ferris/package.json').then(
|
|
2960
|
-
() => undefined,
|
|
2961
|
-
(error: unknown) => error,
|
|
2962
|
-
);
|
|
2963
|
-
if (!(failure instanceof AggregateCreateNodesError)) {
|
|
2964
|
-
throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
|
|
2965
|
-
}
|
|
2966
|
-
expect(failure.errors[0]?.[1]?.message).toMatch(/cross-targets entries must be target triples like/);
|
|
2967
|
-
} finally {
|
|
2968
|
-
await workspace.cleanup();
|
|
2969
|
-
}
|
|
2970
|
-
});
|
|
2971
|
-
//#endregion
|
|
2972
|
-
});
|
|
2973
|
-
|
|
2974
|
-
/**
|
|
2975
|
-
* Target-inference fixtures declare real Cargo workspaces. Supply their empty
|
|
2976
|
-
* Rust library and initial lock before inference, rather than relying on a
|
|
2977
|
-
* rejected Cargo query. Explicit sources and locks, including planted failures,
|
|
2978
|
-
* remain untouched.
|
|
2979
|
-
*/
|
|
2980
|
-
async function prepareCargoFixture(root: string): Promise<void> {
|
|
2981
|
-
const manifests = (await readdir(root, { recursive: true }))
|
|
2982
|
-
.filter((path) => path === 'Cargo.toml' || path.endsWith('/Cargo.toml'))
|
|
2983
|
-
.filter((path) => !path.split('/').some((part) => ['node_modules', 'target', '.nx'].includes(part)));
|
|
2984
|
-
const workspaces: string[] = [];
|
|
2985
|
-
for (const manifest of manifests) {
|
|
2986
|
-
const path = join(root, manifest);
|
|
2987
|
-
const contents = await readFile(path, 'utf8');
|
|
2988
|
-
if (/^\[package\]\s*$/m.test(contents)) {
|
|
2989
|
-
const source = join(dirname(path), 'src/lib.rs');
|
|
2990
|
-
if (!(await Bun.file(source).exists())) {
|
|
2991
|
-
await mkdir(dirname(source), { recursive: true });
|
|
2992
|
-
await writeFile(source, '// Empty Cargo fixture library.\n');
|
|
2993
|
-
}
|
|
2994
|
-
}
|
|
2995
|
-
if (/^\[workspace\]\s*$/m.test(contents)) workspaces.push(path);
|
|
2996
|
-
}
|
|
2997
|
-
for (const manifest of workspaces) {
|
|
2998
|
-
if (await Bun.file(join(dirname(manifest), 'Cargo.lock')).exists()) continue;
|
|
2999
|
-
const child = Bun.spawn(['cargo', 'generate-lockfile', '--offline', '--manifest-path', manifest], {
|
|
3000
|
-
env: process.env,
|
|
3001
|
-
cwd: root,
|
|
3002
|
-
stdout: 'pipe',
|
|
3003
|
-
stderr: 'pipe',
|
|
3004
|
-
});
|
|
3005
|
-
const [code, stdout, stderr] = await Promise.all([
|
|
3006
|
-
child.exited,
|
|
3007
|
-
new Response(child.stdout).text(),
|
|
3008
|
-
new Response(child.stderr).text(),
|
|
3009
|
-
]);
|
|
3010
|
-
if (code !== 0) throw new Error(`Cargo fixture ${manifest} could not lock:\n${stdout}${stderr}`);
|
|
3011
|
-
}
|
|
3012
|
-
}
|
|
3013
|
-
|
|
3014
|
-
async function createWorkspace(parent = tmpdir()): Promise<WorkspaceFixture> {
|
|
3015
|
-
// Canonical, because macOS puts the temp directory behind a /private symlink
|
|
3016
|
-
// and a daemon never sees an edit made under a root named through one.
|
|
3017
|
-
const root = await realpath(await mkdtemp(join(parent, 'smoothbricks-nx-plugin-')));
|
|
3018
|
-
|
|
3019
|
-
return {
|
|
3020
|
-
context: {
|
|
3021
|
-
workspaceRoot: root,
|
|
3022
|
-
nxJsonConfiguration: {},
|
|
3023
|
-
},
|
|
3024
|
-
async write(filePath: string, contents: string): Promise<void> {
|
|
3025
|
-
const absolutePath = join(root, filePath);
|
|
3026
|
-
await mkdir(dirname(absolutePath), { recursive: true });
|
|
3027
|
-
await writeFile(absolutePath, contents);
|
|
3028
|
-
},
|
|
3029
|
-
async cleanup(): Promise<void> {
|
|
3030
|
-
await rm(root, { recursive: true, force: true });
|
|
3031
|
-
},
|
|
3032
|
-
};
|
|
3033
|
-
}
|
|
3034
|
-
|
|
3035
|
-
interface WorkspaceFixture {
|
|
3036
|
-
context: CreateNodesContextV2;
|
|
3037
|
-
write(filePath: string, contents: string): Promise<void>;
|
|
3038
|
-
cleanup(): Promise<void>;
|
|
3039
|
-
}
|
|
3040
|
-
|
|
3041
|
-
/**
|
|
3042
|
-
* What inference told the operator while it ran. The plugin degrades out loud
|
|
3043
|
-
* — a hash it cannot make complete is a cache verdict nobody can invalidate —
|
|
3044
|
-
* so the stream is part of its behavior, not decoration.
|
|
3045
|
-
*/
|
|
3046
|
-
async function withCapturedStderr<T>(run: () => Promise<T>): Promise<{ result: T; stderr: string }> {
|
|
3047
|
-
const original = process.stderr.write.bind(process.stderr);
|
|
3048
|
-
let stderr = '';
|
|
3049
|
-
process.stderr.write = (chunk: string | Uint8Array) => {
|
|
3050
|
-
stderr += typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk);
|
|
3051
|
-
return true;
|
|
3052
|
-
};
|
|
3053
|
-
try {
|
|
3054
|
-
return { result: await run(), stderr };
|
|
3055
|
-
} finally {
|
|
3056
|
-
process.stderr.write = original;
|
|
3057
|
-
}
|
|
3058
|
-
}
|
|
3059
|
-
|
|
3060
|
-
/**
|
|
3061
|
-
* A fileset Nx resolves against the workspace, or a named input nx.json
|
|
3062
|
-
* declares. Anything else is a path this machine happens to have.
|
|
3063
|
-
*/
|
|
3064
|
-
const WORKSPACE_ANCHORED_INPUT = /^!?(?:\{(?:projectRoot|workspaceRoot)\}\/|\^?[A-Za-z][\w-]*$)/;
|
|
3065
|
-
|
|
3066
|
-
/** A path rooted outside the workspace, wherever it appears in a hashed value. */
|
|
3067
|
-
const PATH_OUTSIDE_WORKSPACE = /(?:^|[^\w.\-~])(\/[\w.-]+\/[\w.-]+)/;
|
|
3068
|
-
|
|
3069
|
-
/**
|
|
3070
|
-
* One Cargo workspace producing every cached cargo target family inference can
|
|
3071
|
-
* make: the host archive, a per-crate run, both lint verdicts, and — through
|
|
3072
|
-
* the `cross-targets` declaration — the foreign-triple archive, which states
|
|
3073
|
-
* its own inputs instead of receiving them from the `cargo --frozen` sweep.
|
|
3074
|
-
*/
|
|
3075
|
-
async function writeCargoIdentityFixture(workspace: WorkspaceFixture): Promise<void> {
|
|
3076
|
-
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
3077
|
-
await workspace.write(
|
|
3078
|
-
'packages/ferris/Cargo.toml',
|
|
3079
|
-
'[workspace]\nmembers = ["crates/ferris-core"]\n\n' +
|
|
3080
|
-
'[workspace.metadata.smoothbricks.test]\n' +
|
|
3081
|
-
'cross-targets = [{ target = "aarch64-apple-darwin", cargo = "scripts/cargo-for-nextest.sh" }]\n',
|
|
3082
|
-
);
|
|
3083
|
-
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
3084
|
-
await workspace.write('packages/ferris/scripts/cargo-for-nextest.sh', '#!/bin/sh\nexec cargo "$@"\n');
|
|
3085
|
-
}
|
|
3086
|
-
|
|
3087
|
-
/**
|
|
3088
|
-
* The targets a cache verdict can be wrong about: cached, and running cargo.
|
|
3089
|
-
* Derived rather than listed, so a new cargo family joins these assertions the
|
|
3090
|
-
* day it is inferred instead of the day someone remembers to add it.
|
|
3091
|
-
*/
|
|
3092
|
-
function cachedCargoTargets(targets: Record<string, TargetConfiguration>): [string, TargetConfiguration][] {
|
|
3093
|
-
return Object.entries(targets).filter(([, target]) => {
|
|
3094
|
-
const command: unknown = target.options?.command;
|
|
3095
|
-
const commands: unknown = target.options?.commands;
|
|
3096
|
-
const text = [
|
|
3097
|
-
typeof command === 'string' ? command : '',
|
|
3098
|
-
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
3099
|
-
].join('\n');
|
|
3100
|
-
return target.cache === true && /\bcargo/.test(text);
|
|
3101
|
-
});
|
|
3102
|
-
}
|
|
3103
|
-
|
|
3104
|
-
async function inferProject(
|
|
3105
|
-
workspace: WorkspaceFixture,
|
|
3106
|
-
packageJsonPath: string,
|
|
3107
|
-
createNodes: CreateNodesV2 = createNodesV2,
|
|
3108
|
-
) {
|
|
3109
|
-
const [, infer] = createNodes;
|
|
3110
|
-
await prepareCargoFixture(workspace.context.workspaceRoot);
|
|
3111
|
-
// Each inference indexes the tree as it is now, as a fresh Nx process would: the
|
|
3112
|
-
// in-process workspace context otherwise keeps the files of the first inference.
|
|
3113
|
-
resetWorkspaceContext();
|
|
3114
|
-
const result = await infer([packageJsonPath], undefined, workspace.context);
|
|
3115
|
-
return result[0]?.[1].projects?.[dirname(packageJsonPath)];
|
|
3116
|
-
}
|
|
3117
|
-
|
|
3118
|
-
/**
|
|
3119
|
-
* Inference against a chosen nx.json. The versionless manifest inputs reach as
|
|
3120
|
-
* far as the workspace's own `namedInputs` allow, so the workspace
|
|
3121
|
-
* configuration is an input to inference and not a constant of the fixture.
|
|
3122
|
-
*/
|
|
3123
|
-
async function inferProjectWithNxJson(
|
|
3124
|
-
workspace: WorkspaceFixture,
|
|
3125
|
-
packageJsonPath: string,
|
|
3126
|
-
nxJsonConfiguration: CreateNodesContextV2['nxJsonConfiguration'],
|
|
3127
|
-
) {
|
|
3128
|
-
const [, infer] = createNodesV2;
|
|
3129
|
-
await prepareCargoFixture(workspace.context.workspaceRoot);
|
|
3130
|
-
resetWorkspaceContext();
|
|
3131
|
-
const result = await infer([packageJsonPath], undefined, {
|
|
3132
|
-
workspaceRoot: workspace.context.workspaceRoot,
|
|
3133
|
-
nxJsonConfiguration,
|
|
3134
|
-
});
|
|
3135
|
-
return result[0]?.[1].projects?.[dirname(packageJsonPath)];
|
|
3136
|
-
}
|
|
3137
|
-
|
|
3138
|
-
async function inferProjectTargets(
|
|
3139
|
-
workspace: WorkspaceFixture,
|
|
3140
|
-
packageJsonPath: string,
|
|
3141
|
-
createNodes?: CreateNodesV2,
|
|
3142
|
-
): Promise<Record<string, TargetConfiguration>> {
|
|
3143
|
-
return (await inferProject(workspace, packageJsonPath, createNodes))?.targets ?? {};
|
|
3144
|
-
}
|
|
3145
|
-
|
|
3146
|
-
/**
|
|
3147
|
-
* The configuration Nx resolves for a target this plugin infers and the package
|
|
3148
|
-
* also declares. Nx merges a package-local `nx.targets` entry over an inference
|
|
3149
|
-
* plugin's target one layer later — the precedence order is specified plugins →
|
|
3150
|
-
* target defaults → default plugins, and the package.json reader is a default
|
|
3151
|
-
* plugin — so composing with the same merge function the graph uses makes these
|
|
3152
|
-
* assertions the resolved configuration rather than a guess about it.
|
|
3153
|
-
*/
|
|
3154
|
-
function resolveDeclaredOverInferred(
|
|
3155
|
-
targets: Record<string, TargetConfiguration>,
|
|
3156
|
-
declared: Record<string, TargetConfiguration>,
|
|
3157
|
-
name: string,
|
|
3158
|
-
): TargetConfiguration | undefined {
|
|
3159
|
-
const inferred = targets[name];
|
|
3160
|
-
return inferred && mergeTargetConfigurations(declared[name] ?? {}, inferred);
|
|
3161
|
-
}
|
|
3162
|
-
|
|
3163
|
-
/**
|
|
3164
|
-
* How a cargo test command is scoped to one crate, split into the three facts
|
|
3165
|
-
* that can independently go wrong.
|
|
3166
|
-
*
|
|
3167
|
-
* `--binaries-metadata` must be present: the runner executes binaries one
|
|
3168
|
-
* workspace `cargo nextest archive --workspace` already built, so a per-crate
|
|
3169
|
-
* run cannot compile anything. Narrowing comes from the nextest filterset,
|
|
3170
|
-
* which selects what RUNS. `--package` narrows too, but it re-resolves that
|
|
3171
|
-
* crate's features, which is a build — 57.9s of a 120s bounded budget on a
|
|
3172
|
-
* hosted 3-core macOS runner when the runners still built — so its presence is
|
|
3173
|
-
* a regression even though it selects the same tests. nextest rejects it
|
|
3174
|
-
* outright beside a reused build, and this assertion says so before cargo does.
|
|
3175
|
-
*/
|
|
3176
|
-
function cargoPackageSelection(command: string): {
|
|
3177
|
-
prebuiltRun: boolean;
|
|
3178
|
-
packageFlags: string[];
|
|
3179
|
-
filtered: string[];
|
|
3180
|
-
} {
|
|
3181
|
-
const tokens = command.split(/\s+/);
|
|
3182
|
-
const packageFlags: string[] = [];
|
|
3183
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
3184
|
-
if (tokens[i] === '--package' || tokens[i] === '-p') {
|
|
3185
|
-
const name = tokens[i + 1];
|
|
3186
|
-
if (name !== undefined && name.length > 0) {
|
|
3187
|
-
packageFlags.push(name);
|
|
3188
|
-
}
|
|
3189
|
-
}
|
|
3190
|
-
}
|
|
3191
|
-
return {
|
|
3192
|
-
prebuiltRun: tokens.includes('--binaries-metadata'),
|
|
3193
|
-
packageFlags,
|
|
3194
|
-
filtered: [...command.matchAll(/\bpackage\(([^)]+)\)/g)].flatMap((match) =>
|
|
3195
|
-
match[1] === undefined ? [] : [match[1]],
|
|
3196
|
-
),
|
|
3197
|
-
};
|
|
3198
|
-
}
|
|
3199
|
-
|
|
3200
|
-
/**
|
|
3201
|
-
* Inference never throttles the scheduler: no target is exclusive and no
|
|
3202
|
-
* run-commands target is run one command at a time. A pair that really is
|
|
3203
|
-
* producer and consumer is one `&&` command; everything else is left to Nx and
|
|
3204
|
-
* to the locks Cargo owns.
|
|
3205
|
-
*/
|
|
3206
|
-
function expectNoSchedulerThrottle(targets: Record<string, TargetConfiguration>): void {
|
|
3207
|
-
for (const [name, target] of Object.entries(targets)) {
|
|
3208
|
-
expect(target.parallelism, `${name} parallelism`).toBeUndefined();
|
|
3209
|
-
expect(target.options?.parallel, `${name} options.parallel`).toBeUndefined();
|
|
3210
|
-
}
|
|
3211
|
-
}
|
|
3212
|
-
|
|
3213
|
-
/** A default-profile override that puts the tests `filter` selects in `group`, on the platform serial groups run on. */
|
|
3214
|
-
function serialOverride(filter: string, group: string): string[] {
|
|
3215
|
-
return [
|
|
3216
|
-
'[[profile.default.overrides]]',
|
|
3217
|
-
`filter = '${filter}'`,
|
|
3218
|
-
`platform = 'cfg(target_os="macos")'`,
|
|
3219
|
-
`test-group = '${group}'`,
|
|
3220
|
-
'',
|
|
3221
|
-
];
|
|
3222
|
-
}
|
|
3223
|
-
|
|
3224
|
-
/** The real-image split in miniature: a device group over one crate, a host group over the two crates above it. */
|
|
3225
|
-
const APFS_SPLIT_GROUPS: readonly string[] = [
|
|
3226
|
-
'[test-groups.real-apfs]',
|
|
3227
|
-
'max-threads = 1',
|
|
3228
|
-
'',
|
|
3229
|
-
'[test-groups.real-apfs-host]',
|
|
3230
|
-
'max-threads = 1',
|
|
3231
|
-
'',
|
|
3232
|
-
...serialOverride('package(cowshed-apfs-tests) and test(/real_apfs_/)', 'real-apfs'),
|
|
3233
|
-
...serialOverride('package(cowshed-core) and (test(/real_apfs_/) or binary(apfs_native_macos))', 'real-apfs-host'),
|
|
3234
|
-
...serialOverride('package(cowshed-cli) and test(/real_apfs_/)', 'real-apfs-host'),
|
|
3235
|
-
];
|
|
3236
|
-
|
|
3237
|
-
/**
|
|
3238
|
-
* A repository-root Cargo workspace with two projects: `cowshed` holds the production device layer (`cowshed-apfs`,
|
|
3239
|
-
* which links `cowshed-os` and carries the test support the crates above it compile in), the real-image scenarios in a
|
|
3240
|
-
* crate of their own (`cowshed-apfs-tests`, which nothing depends on) and the host crates, and `lmao` holds a crate no
|
|
3241
|
-
* group can reach. `nextest` is the repository's `.config/nextest.toml`.
|
|
3242
|
-
*/
|
|
3243
|
-
async function writeApfsSplitFixture(workspace: WorkspaceFixture, nextest: readonly string[]): Promise<void> {
|
|
3244
|
-
const crate = (
|
|
3245
|
-
project: string,
|
|
3246
|
-
name: string,
|
|
3247
|
-
dependencies: readonly string[] = [],
|
|
3248
|
-
section: 'dependencies' | 'dev-dependencies' = 'dependencies',
|
|
3249
|
-
): Promise<void> =>
|
|
3250
|
-
workspace.write(
|
|
3251
|
-
`packages/${project}/crates/${name}/Cargo.toml`,
|
|
3252
|
-
[
|
|
3253
|
-
'[package]',
|
|
3254
|
-
`name = "${name}"`,
|
|
3255
|
-
...(dependencies.length === 0
|
|
3256
|
-
? []
|
|
3257
|
-
: ['', `[${section}]`, ...dependencies.map((dependency) => `${dependency} = { path = "../${dependency}" }`)]),
|
|
3258
|
-
'',
|
|
3259
|
-
].join('\n'),
|
|
3260
|
-
);
|
|
3261
|
-
await workspace.write('package.json', '{"name":"@fixture/codebase"}\n');
|
|
3262
|
-
await workspace.write('packages/cowshed/package.json', '{"name":"@fixture/cowshed","nx":{"name":"cowshed"}}\n');
|
|
3263
|
-
await workspace.write('packages/lmao/package.json', '{"name":"@fixture/lmao","nx":{"name":"lmao"}}\n');
|
|
3264
|
-
await workspace.write('Cargo.toml', '[workspace]\nmembers = ["packages/*/crates/*"]\n');
|
|
3265
|
-
await crate('cowshed', 'cowshed-os');
|
|
3266
|
-
await crate('cowshed', 'cowshed-apfs', ['cowshed-os']);
|
|
3267
|
-
await crate('cowshed', 'cowshed-apfs-tests', ['cowshed-apfs', 'cowshed-os'], 'dev-dependencies');
|
|
3268
|
-
await crate('cowshed', 'cowshed-core', ['cowshed-apfs', 'cowshed-os']);
|
|
3269
|
-
await crate('cowshed', 'cowshed-cli', ['cowshed-core']);
|
|
3270
|
-
await crate('lmao', 'lmao-core');
|
|
3271
|
-
await workspace.write(
|
|
3272
|
-
'packages/cowshed/crates/cowshed-apfs/tests/support/blank_image.rs',
|
|
3273
|
-
'// shared test support\n',
|
|
3274
|
-
);
|
|
3275
|
-
await workspace.write('.config/nextest.toml', nextest.join('\n'));
|
|
3276
|
-
}
|
|
3277
|
-
|
|
3278
|
-
/** Inference over the split fixture's three projects in the one call Nx makes: project root to inferred targets. */
|
|
3279
|
-
async function inferApfsSplit(
|
|
3280
|
-
workspace: WorkspaceFixture,
|
|
3281
|
-
createNodes: CreateNodesV2 = createNodesV2ForPlatform('darwin', 'arm64'),
|
|
3282
|
-
): Promise<Map<string, Record<string, TargetConfiguration>>> {
|
|
3283
|
-
const [, infer] = createNodes;
|
|
3284
|
-
await prepareCargoFixture(workspace.context.workspaceRoot);
|
|
3285
|
-
resetWorkspaceContext();
|
|
3286
|
-
const inferred = await infer(
|
|
3287
|
-
['package.json', 'packages/cowshed/package.json', 'packages/lmao/package.json'],
|
|
3288
|
-
undefined,
|
|
3289
|
-
workspace.context,
|
|
3290
|
-
);
|
|
3291
|
-
return new Map(
|
|
3292
|
-
inferred.flatMap(([, result]) =>
|
|
3293
|
-
Object.entries(result.projects ?? {}).map(([root, project]): [string, Record<string, TargetConfiguration>] => [
|
|
3294
|
-
root,
|
|
3295
|
-
project.targets ?? {},
|
|
3296
|
-
]),
|
|
3297
|
-
),
|
|
3298
|
-
);
|
|
3299
|
-
}
|
|
3300
|
-
|
|
3301
|
-
/** The crates whose whole tree a target hashes: one `{workspaceRoot}/…/crates/<crate>/**\/*` fileset each. */
|
|
3302
|
-
function hashedCrates(target: TargetConfiguration | undefined): string[] {
|
|
3303
|
-
const crates = (target?.inputs ?? []).flatMap((input) =>
|
|
3304
|
-
typeof input === 'string'
|
|
3305
|
-
? (/^\{workspaceRoot\}\/packages\/[^/]+\/crates\/([^/]+)\/\*\*\/\*$/.exec(input)?.[1] ?? [])
|
|
3306
|
-
: [],
|
|
3307
|
-
);
|
|
3308
|
-
return [...new Set(crates)].sort((left, right) => left.localeCompare(right));
|
|
3309
|
-
}
|
|
3310
|
-
|
|
3311
|
-
/** Whether Nx would hash `path` (workspace-relative) under the `{workspaceRoot}` filesets of `target`'s inputs. */
|
|
3312
|
-
function hashes(target: TargetConfiguration | undefined, path: string): boolean {
|
|
3313
|
-
const filesets = (target?.inputs ?? []).flatMap((input) =>
|
|
3314
|
-
typeof input === 'string' && input.includes('{workspaceRoot}') ? [input] : [],
|
|
3315
|
-
);
|
|
3316
|
-
const matches = (fileset: string): boolean => new Bun.Glob(fileset.replace('{workspaceRoot}/', '')).match(path);
|
|
3317
|
-
return (
|
|
3318
|
-
filesets.some((input) => !input.startsWith('!') && matches(input)) &&
|
|
3319
|
-
!filesets.some((input) => input.startsWith('!') && matches(input.slice(1)))
|
|
3320
|
-
);
|
|
3321
|
-
}
|