@smoothbricks/nx-plugin 0.4.25 → 0.4.27
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 +1078 -98
- package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-bound-failures.js +31 -0
- package/dist/bin/smoo-nx-cargo-hash.js +28 -3
- package/dist/bin/smoo-nx-exec.js +16 -85
- package/dist/bin/smoo-nx-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-failures.js +3 -0
- package/dist/bin/smoo-nx-nextest-extract.js +3 -2
- package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-walks.js +34 -0
- package/dist/bounded-test-policy.d.ts +7 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +101 -40
- package/dist/build-state-output-policy.d.ts +25 -0
- package/dist/build-state-output-policy.d.ts.map +1 -0
- package/dist/build-state-output-policy.js +64 -0
- package/dist/cargo-closure-input.d.ts +16 -17
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +37 -44
- package/dist/cargo-dev-profile.d.ts +37 -0
- package/dist/cargo-dev-profile.d.ts.map +1 -0
- package/dist/cargo-dev-profile.js +108 -0
- package/dist/cargo-source-hash.d.ts +50 -8
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +691 -71
- package/dist/cargo-toolchain-policy.d.ts +4 -0
- package/dist/cargo-toolchain-policy.d.ts.map +1 -1
- package/dist/cargo-toolchain-policy.js +5 -0
- package/dist/cargo-workspace.d.ts +108 -12
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +299 -18
- package/dist/cross-check-policy.d.ts +21 -3
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +24 -6
- package/dist/disk-command-policy.d.ts +7 -0
- package/dist/disk-command-policy.d.ts.map +1 -0
- package/dist/disk-command-policy.js +98 -0
- package/dist/ensure-built-receipt.d.ts +25 -0
- package/dist/ensure-built-receipt.d.ts.map +1 -0
- package/dist/ensure-built-receipt.js +261 -0
- package/dist/ensure-built-witness.d.ts +57 -0
- package/dist/ensure-built-witness.d.ts.map +1 -0
- package/dist/ensure-built-witness.js +412 -0
- package/dist/ensure-built.d.ts +213 -12
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +624 -177
- package/dist/eslint-file-set.d.ts +7 -0
- package/dist/eslint-file-set.d.ts.map +1 -0
- package/dist/eslint-file-set.js +12 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool.js +379 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/disk-lease.js +91 -0
- package/dist/executors/bounded-exec/executor.d.ts +45 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +447 -52
- package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/gateway-lease.js +143 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
- package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
- package/dist/executors/bounded-exec/progress.d.ts +35 -0
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
- package/dist/executors/bounded-exec/progress.js +79 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp.js +1528 -0
- package/dist/executors/bounded-exec/schema.d.ts +29 -11
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.d.ts +162 -0
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
- package/dist/executors/bounded-exec/verdict.js +318 -0
- package/dist/executors/shard-timings/executor.d.ts +14 -0
- package/dist/executors/shard-timings/executor.d.ts.map +1 -0
- package/dist/executors/shard-timings/executor.js +25 -0
- package/dist/executors/shard-timings/schema.d.ts +4 -0
- package/dist/executors/shard-timings/schema.d.ts.map +1 -0
- package/dist/executors/shard-timings/schema.js +1 -0
- package/dist/failure-summary.d.ts +5 -0
- package/dist/failure-summary.d.ts.map +1 -0
- package/dist/failure-summary.js +118 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +6 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +435 -230
- package/dist/managed-assets.d.ts +6 -0
- package/dist/managed-assets.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.d.ts +13 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +44 -13
- package/dist/managed-files/files.d.ts +7 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +62 -8
- package/dist/managed-files/json-edit.d.ts +21 -0
- package/dist/managed-files/json-edit.d.ts.map +1 -0
- package/dist/managed-files/json-edit.js +295 -0
- package/dist/managed-files/managed-format.d.ts +33 -1
- package/dist/managed-files/managed-format.d.ts.map +1 -1
- package/dist/managed-files/managed-format.js +82 -2
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +231 -48
- package/dist/managed-files/tree.d.ts +5 -0
- package/dist/managed-files/tree.d.ts.map +1 -1
- package/dist/managed-files/tree.js +5 -3
- package/dist/manifest-hash.js +3 -2
- package/dist/nextest-code-bound.d.ts +62 -0
- package/dist/nextest-code-bound.d.ts.map +1 -0
- package/dist/nextest-code-bound.js +154 -0
- package/dist/nextest-extraction.d.ts +24 -8
- package/dist/nextest-extraction.d.ts.map +1 -1
- package/dist/nextest-extraction.js +42 -7
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +3 -5
- package/dist/release-config-policy.d.ts.map +1 -1
- package/dist/release-config-policy.js +3 -5
- package/dist/runtime-input.d.ts +14 -0
- package/dist/runtime-input.d.ts.map +1 -0
- package/dist/runtime-input.js +15 -0
- package/dist/rust-tokens.d.ts +11 -0
- package/dist/rust-tokens.d.ts.map +1 -0
- package/dist/rust-tokens.js +81 -0
- package/dist/task-results.d.ts +6 -0
- package/dist/task-results.d.ts.map +1 -0
- package/dist/task-results.js +61 -0
- package/dist/test-program.d.ts +54 -0
- package/dist/test-program.d.ts.map +1 -0
- package/dist/test-program.js +292 -0
- package/dist/test-timings.d.ts +71 -0
- package/dist/test-timings.d.ts.map +1 -0
- package/dist/test-timings.js +393 -0
- package/dist/test-walk-policy.d.ts +103 -0
- package/dist/test-walk-policy.d.ts.map +1 -0
- package/dist/test-walk-policy.js +657 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +824 -0
- package/dist/type-guards.d.ts +3 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +4 -0
- package/dist/typecheck-test-policy.d.ts +8 -5
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +113 -100
- package/dist/workspace-config-policy.d.ts +8 -0
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +175 -63
- package/dist/workspace-index.d.ts +12 -0
- package/dist/workspace-index.d.ts.map +1 -0
- package/dist/workspace-index.js +17 -0
- package/dist/workspace-manifest.d.ts +37 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/executors.json +5 -0
- package/loader.js +13 -11
- package/managed/raw/envrc +33 -62
- package/managed/raw/git-format-staged.yml +30 -35
- package/managed/raw/patches/nx@23.2.1.patch +3484 -0
- package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
- package/managed/raw/tooling/direnv/developer-links.ts +607 -17
- package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -92
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
- package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
- package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
- package/managed/raw/tooling/direnv/repo-path +14 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +1009 -118
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
- package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
- package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
- package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
- package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
- package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
- package/managed/templates/github/actions/cache-nx/action.yml +1 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
- package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
- package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
- package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
- package/managed/templates/github/workflows/managed-files.yml +1 -2
- package/nextest.toml +8 -75
- package/package.json +75 -13
- package/runtime-input.sh +81 -0
- package/src/__tests__/counted-cargo-process.ts +286 -0
- package/src/__tests__/counted-cargo.ts +730 -0
- package/src/__tests__/fixture-cargo-home.ts +36 -0
- package/src/__tests__/fixture-nx-env.ts +157 -2
- package/src/__tests__/progress-clock.ts +43 -0
- package/src/__tests__/runtime-input.ts +23 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
- package/src/bin/smoo-nx-bound-failures.ts +33 -0
- package/src/bin/smoo-nx-cargo-hash.ts +28 -3
- package/src/bin/smoo-nx-exec.ts +17 -86
- package/src/bin/smoo-nx-failures.ts +4 -0
- package/src/bin/smoo-nx-nextest-extract.ts +3 -2
- package/src/bin/smoo-nx-test-walks.ts +42 -0
- package/src/bounded-test-policy.test.ts +268 -22
- package/src/bounded-test-policy.ts +114 -42
- package/src/build-state-output-policy.test.ts +115 -0
- package/src/build-state-output-policy.ts +90 -0
- package/src/bun-bootstrap.test.ts +57 -3
- package/src/bun-file-packages.test.ts +47 -0
- package/src/cargo-closure-input.test.ts +432 -62
- package/src/cargo-closure-input.ts +51 -57
- package/src/cargo-dev-profile.ts +137 -0
- package/src/cargo-resolve-cache.test.ts +1044 -0
- package/src/cargo-source-hash.test.ts +203 -93
- package/src/cargo-source-hash.ts +762 -75
- package/src/cargo-toolchain-policy.ts +6 -0
- package/src/cargo-workspace.test.ts +320 -0
- package/src/cargo-workspace.ts +344 -18
- package/src/cross-check-policy.test.ts +59 -1
- package/src/cross-check-policy.ts +25 -6
- package/src/disk-command-policy.test.ts +61 -0
- package/src/disk-command-policy.ts +107 -0
- package/src/ensure-built-receipt.test.ts +184 -0
- package/src/ensure-built-receipt.ts +263 -0
- package/src/ensure-built-witness.test.ts +344 -0
- package/src/ensure-built-witness.ts +252 -0
- package/src/ensure-built.test.ts +1043 -483
- package/src/ensure-built.ts +870 -197
- package/src/eslint-file-set.ts +9 -0
- package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
- package/src/executors/bounded-exec/cpu-pool.ts +417 -0
- package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
- package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
- package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
- package/src/executors/bounded-exec/disk-lease.ts +139 -0
- package/src/executors/bounded-exec/executor-host.test.ts +778 -0
- package/src/executors/bounded-exec/executor.test.ts +1116 -63
- package/src/executors/bounded-exec/executor.ts +565 -67
- package/src/executors/bounded-exec/gateway-lease.ts +176 -0
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
- package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
- package/src/executors/bounded-exec/progress.test.ts +79 -0
- package/src/executors/bounded-exec/progress.ts +118 -0
- package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
- package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
- package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
- package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
- package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
- package/src/executors/bounded-exec/ram-temp.ts +1918 -0
- package/src/executors/bounded-exec/schema.json +11 -5
- package/src/executors/bounded-exec/schema.ts +27 -11
- package/src/executors/bounded-exec/verdict.test.ts +440 -0
- package/src/executors/bounded-exec/verdict.ts +433 -0
- package/src/executors/shard-timings/executor.ts +36 -0
- package/src/executors/shard-timings/schema.json +21 -0
- package/src/executors/shard-timings/schema.ts +4 -0
- package/src/failure-summary.ts +119 -0
- package/src/generators/bounded-test-targets/generator.test.ts +4 -4
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/create-package/generator.test.ts +6 -0
- package/src/generators/create-package/generator.ts +6 -2
- package/src/host-controller-wiring.test.ts +31 -0
- package/src/index.test.ts +1070 -360
- package/src/index.ts +524 -255
- package/src/linked-snapshots.nx.test.ts +172 -0
- package/src/managed-assets.ts +12 -0
- package/src/managed-files/ci-workflow.ts +54 -13
- package/src/managed-files/files.ts +65 -9
- package/src/managed-files/forgejo-artifact.test.ts +395 -0
- package/src/managed-files/generator.test.ts +60 -1
- package/src/managed-files/json-edit.test.ts +216 -0
- package/src/managed-files/json-edit.ts +290 -0
- package/src/managed-files/managed-format-json.test.ts +308 -0
- package/src/managed-files/managed-format.ts +90 -2
- package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
- package/src/managed-files/publish-workflow.ts +285 -67
- package/src/managed-files/repo-path.test.ts +129 -0
- package/src/managed-files/trace-db-artifact.test.ts +7 -0
- package/src/managed-files/tree.ts +11 -3
- package/src/manifest-hash.ts +3 -2
- package/src/nextest-code-bound.test.ts +155 -0
- package/src/nextest-code-bound.ts +195 -0
- package/src/nextest-extraction.test.ts +37 -5
- package/src/nextest-extraction.ts +51 -9
- package/src/nextest-partitions.test.ts +495 -0
- package/src/nx-cache-bound.test.ts +109 -0
- package/src/nx-cache-restore-mtime.test.ts +170 -0
- package/src/nx-daemon-claim.test.ts +277 -0
- package/src/nx-daemon-idle-cpu.test.ts +81 -0
- package/src/nx-daemon-idle-policy.test.ts +51 -0
- package/src/nx-daemon-ignore-files.test.ts +210 -0
- package/src/nx-daemon-root-normalization.test.ts +105 -0
- package/src/nx-daemon-validity.test.ts +925 -0
- package/src/nx-dot-input-policy.test.ts +353 -0
- package/src/nx-failure-life-cycles.test.ts +207 -0
- package/src/nx-files-archive-racy.test.ts +97 -0
- package/src/nx-foreign-workspace-env.test.ts +329 -0
- package/src/nx-incomplete-run-summary.test.ts +70 -0
- package/src/nx-plugin-load-errors.test.ts +120 -0
- package/src/nx-project-resolution-cache.test.ts +176 -0
- package/src/nx-raw-inputs.test.ts +166 -0
- package/src/nx-resident-graph-workers.test.ts +112 -0
- package/src/nx-run-information.test.ts +118 -0
- package/src/nx-skipped-task-exit.test.ts +180 -0
- package/src/nx-state-location.test.ts +63 -0
- package/src/nx-store-resolution.test.ts +99 -0
- package/src/nx-task-graph-cycles.test.ts +148 -0
- package/src/nx-task-output-lease.test.ts +414 -0
- package/src/nx-use-local.test.ts +103 -0
- package/src/package-target-policy.ts +3 -6
- package/src/release-config-policy.ts +3 -6
- package/src/runtime-input.test.ts +215 -0
- package/src/runtime-input.ts +17 -0
- package/src/rust-tokens.ts +78 -0
- package/src/serial-group-wiring.test.ts +326 -0
- package/src/task-history-namespace.test.ts +181 -0
- package/src/task-results.test.ts +226 -0
- package/src/task-results.ts +75 -0
- package/src/test-program.test.ts +303 -0
- package/src/test-program.ts +341 -0
- package/src/test-timings.test.ts +240 -0
- package/src/test-timings.ts +311 -0
- package/src/test-walk-policy.test.ts +585 -0
- package/src/test-walk-policy.ts +731 -0
- package/src/testing.test.ts +509 -0
- package/src/testing.ts +922 -0
- package/src/type-guards.ts +4 -0
- package/src/typecheck-test-policy.test.ts +496 -11
- package/src/typecheck-test-policy.ts +137 -103
- package/src/workspace-config-policy.test.ts +212 -13
- package/src/workspace-config-policy.ts +101 -73
- package/src/workspace-index.ts +18 -0
- package/src/workspace-manifest.ts +41 -1
- package/test-timings.json +85 -28
- package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -615
- package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
- package/src/__tests__/in-process-nx-index.ts +0 -9
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { expandWildcardTargetConfiguration } from 'nx/src/tasks-runner/utils.js';
|
|
4
|
+
import {
|
|
5
|
+
CARGO_TEST_ARCHIVE_TARGET,
|
|
6
|
+
CARGO_TEST_COMPILE_TARGET,
|
|
7
|
+
CARGO_TEST_TARGET,
|
|
8
|
+
listCargoWorkspacePackages,
|
|
9
|
+
packageNameFromCargoTestTarget,
|
|
10
|
+
} from './cargo-workspace.js';
|
|
11
|
+
import { writeJsonFile } from './managed-files/managed-format.js';
|
|
4
12
|
import type { PackageTargetPolicyOptions, ResolvedProjectTargets } from './package-target-policy.js';
|
|
13
|
+
import { isTestRunnerTargetName } from './workspace-config-policy.js';
|
|
5
14
|
|
|
6
15
|
export const BOUNDED_TEST_EXECUTOR = '@smoothbricks/nx-plugin:bounded-exec';
|
|
7
|
-
|
|
16
|
+
/**
|
|
17
|
+
* A test target's one bound: the `idleTimeoutMs` with which no test may go unfinished, the hang backstop of
|
|
18
|
+
* specs/cowshed/08_testing.md. It is no wall-clock ceiling: a suite that keeps finishing tests runs as long as it
|
|
19
|
+
* needs. It is the longest any single test may run, so it stays above every slow-timeout class in the plugin's
|
|
20
|
+
* nextest.toml and every bun `--timeout`.
|
|
21
|
+
*/
|
|
22
|
+
export const BOUNDED_TEST_IDLE_TIMEOUT_MS = 180_000;
|
|
8
23
|
export const BOUNDED_TEST_KILL_AFTER_MS = 10_000;
|
|
9
24
|
// Per-test timeout passed to `bun test --timeout=<ms>`. Bun's default is
|
|
10
25
|
// 5000ms which is too tight for git-fixture tests on slower CI runners
|
|
@@ -58,7 +73,7 @@ export function applyBoundedTestTargetPolicy(
|
|
|
58
73
|
nextTestTarget.options = {
|
|
59
74
|
command,
|
|
60
75
|
cwd: '{projectRoot}',
|
|
61
|
-
|
|
76
|
+
idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
|
|
62
77
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
63
78
|
};
|
|
64
79
|
|
|
@@ -93,9 +108,9 @@ export function applyWorkspaceBoundedTestTargetPolicy(root: string, options: Pac
|
|
|
93
108
|
if (JSON.stringify(packageJson) === beforePackageJson && JSON.stringify(projectJson) === beforeProjectJson) {
|
|
94
109
|
continue;
|
|
95
110
|
}
|
|
96
|
-
|
|
111
|
+
writeJsonFile(packageJsonPath, packageJson);
|
|
97
112
|
if (projectJson) {
|
|
98
|
-
|
|
113
|
+
writeJsonFile(projectJsonPath, projectJson);
|
|
99
114
|
}
|
|
100
115
|
changed = true;
|
|
101
116
|
}
|
|
@@ -215,6 +230,7 @@ export function checkWorkspaceCargoTestReachabilityPolicy(
|
|
|
215
230
|
* to catch.
|
|
216
231
|
*/
|
|
217
232
|
function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string): boolean {
|
|
233
|
+
const targetNames = [...project.targets];
|
|
218
234
|
const visiting = new Set<string>();
|
|
219
235
|
const visit = (targetName: string): boolean => {
|
|
220
236
|
if (visiting.has(targetName) || !project.targets.has(targetName)) {
|
|
@@ -230,7 +246,7 @@ function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string
|
|
|
230
246
|
const reached =
|
|
231
247
|
runs ||
|
|
232
248
|
(project.targetDependencies?.get(targetName) ?? []).some((dependency) =>
|
|
233
|
-
matchingResolvedTargets(dependency, project.targets).some(visit),
|
|
249
|
+
matchingResolvedTargets(dependency, project.targets, targetNames).some(visit),
|
|
234
250
|
);
|
|
235
251
|
visiting.delete(targetName);
|
|
236
252
|
return reached;
|
|
@@ -244,6 +260,7 @@ function resolvedTargetRunsTests(project: ResolvedProjectTargets, target: string
|
|
|
244
260
|
* inference uses; the child list is the graph, not a hand-written crate list.
|
|
245
261
|
*/
|
|
246
262
|
function cargoTestPackageChildren(project: ResolvedProjectTargets): string[] {
|
|
263
|
+
const targetNames = [...project.targets];
|
|
247
264
|
const packages = new Set<string>();
|
|
248
265
|
const visiting = new Set<string>();
|
|
249
266
|
const visit = (targetName: string): void => {
|
|
@@ -256,7 +273,7 @@ function cargoTestPackageChildren(project: ResolvedProjectTargets): string[] {
|
|
|
256
273
|
packages.add(pkg);
|
|
257
274
|
}
|
|
258
275
|
for (const dependency of project.targetDependencies?.get(targetName) ?? []) {
|
|
259
|
-
for (const matched of matchingResolvedTargets(dependency, project.targets)) {
|
|
276
|
+
for (const matched of matchingResolvedTargets(dependency, project.targets, targetNames)) {
|
|
260
277
|
visit(matched);
|
|
261
278
|
}
|
|
262
279
|
}
|
|
@@ -306,11 +323,12 @@ function commandOf(project: ResolvedProjectTargets, targetName: string): string
|
|
|
306
323
|
if (options === undefined || options === null) {
|
|
307
324
|
return undefined;
|
|
308
325
|
}
|
|
309
|
-
const command =
|
|
326
|
+
const command = options.command;
|
|
310
327
|
return typeof command === 'string' ? command : undefined;
|
|
311
328
|
}
|
|
312
329
|
|
|
313
330
|
function resolvedTargetReaches(project: ResolvedProjectTargets, from: string, goal: string): boolean {
|
|
331
|
+
const targetNames = [...project.targets];
|
|
314
332
|
const visiting = new Set<string>();
|
|
315
333
|
const visit = (targetName: string): boolean => {
|
|
316
334
|
if (targetName === goal) {
|
|
@@ -321,7 +339,7 @@ function resolvedTargetReaches(project: ResolvedProjectTargets, from: string, go
|
|
|
321
339
|
}
|
|
322
340
|
visiting.add(targetName);
|
|
323
341
|
const reached = (project.targetDependencies?.get(targetName) ?? []).some((dependency) =>
|
|
324
|
-
matchingResolvedTargets(dependency, project.targets).some(visit),
|
|
342
|
+
matchingResolvedTargets(dependency, project.targets, targetNames).some(visit),
|
|
325
343
|
);
|
|
326
344
|
visiting.delete(targetName);
|
|
327
345
|
return reached;
|
|
@@ -360,8 +378,10 @@ export function checkBoundedTestTargetPolicy(
|
|
|
360
378
|
* bounded `bun test` command. A `commands` array (a multi-runner gate) would
|
|
361
379
|
* be flattened to the default command — deleting the very checks the target
|
|
362
380
|
* exists to run — and a non-bun runner (cargo, go) would inherit wall-clock
|
|
363
|
-
* bounds scaled for bun suites.
|
|
364
|
-
* to
|
|
381
|
+
* bounds scaled for bun suites. A no-op aggregate already delegates execution
|
|
382
|
+
* to its legs; adding a runner would execute the suite a second time. Those
|
|
383
|
+
* targets are left in place for the check to report, so restructuring them
|
|
384
|
+
* stays a human decision.
|
|
365
385
|
*/
|
|
366
386
|
function boundableTestTarget(
|
|
367
387
|
packageJson: BoundedTestPolicyPackageJson,
|
|
@@ -371,8 +391,8 @@ function boundableTestTarget(
|
|
|
371
391
|
if (!isRecord(target)) {
|
|
372
392
|
return true;
|
|
373
393
|
}
|
|
374
|
-
if (isNoopAggregateTarget(target)) {
|
|
375
|
-
return
|
|
394
|
+
if (target.executor === 'nx:noop' || isNoopAggregateTarget(target)) {
|
|
395
|
+
return false;
|
|
376
396
|
}
|
|
377
397
|
const targetOptions = isRecord(target.options) ? target.options : undefined;
|
|
378
398
|
if (targetOptions && Array.isArray(targetOptions.commands)) {
|
|
@@ -389,7 +409,7 @@ function isNoopAggregateTarget(target: Record<string, unknown>): boolean {
|
|
|
389
409
|
if (typeof target.command === 'string' || (isRecord(target.options) && typeof target.options.command === 'string')) {
|
|
390
410
|
return false;
|
|
391
411
|
}
|
|
392
|
-
return Array.isArray(target.dependsOn)
|
|
412
|
+
return Array.isArray(target.dependsOn);
|
|
393
413
|
}
|
|
394
414
|
|
|
395
415
|
function isPositiveSafeInteger(value: unknown): value is number {
|
|
@@ -405,18 +425,55 @@ function isBoundedExecutionTarget(executor: unknown, rawOptions: unknown, allowe
|
|
|
405
425
|
typeof command === 'string' &&
|
|
406
426
|
command.length > 0 &&
|
|
407
427
|
isPackageTestScriptRunnerCommand(command) === false &&
|
|
408
|
-
|
|
428
|
+
// A test leg is bounded by progress alone: a wall-clock ceiling fails a suite that is only slow.
|
|
429
|
+
rawOptions.timeoutMs === undefined &&
|
|
430
|
+
isPositiveSafeInteger(rawOptions.idleTimeoutMs) &&
|
|
431
|
+
bunTestTimeoutIsBounded(command, rawOptions.idleTimeoutMs) &&
|
|
409
432
|
typeof rawOptions.cwd === 'string' &&
|
|
410
|
-
|
|
411
|
-
|
|
433
|
+
// `bun test` walks its working directory looking for test files, so it must start where that walk is cheap: the
|
|
434
|
+
// project root or its `src/`. Any other command names what it runs and has no walk to bound. A cargo workspace's
|
|
435
|
+
// per-crate nextest legs run from the workspace root, which no member project owns, and a gate may run a script
|
|
436
|
+
// that lives in another project; both are bounded by their progress bound alone.
|
|
437
|
+
(!BUN_TEST_PREFIX.test(command) || allowedCwds.has(rawOptions.cwd)) &&
|
|
412
438
|
isPositiveSafeInteger(rawOptions.killAfterMs)
|
|
413
439
|
);
|
|
414
440
|
}
|
|
415
441
|
|
|
442
|
+
/** A bun leg's per-test `--timeout` must fire before the leg's progress bound would. */
|
|
443
|
+
function bunTestTimeoutIsBounded(command: string, idleTimeoutMs: number): boolean {
|
|
444
|
+
if (!BUN_TEST_PREFIX.test(command)) {
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
let found = false;
|
|
448
|
+
for (const match of command.matchAll(/(?:^|\s)--timeout(?==|\s|$)(?:=(\S*)|\s+(\S+))?/g)) {
|
|
449
|
+
const value = match[1] ?? match[2];
|
|
450
|
+
const perTestTimeoutMs = Number(value);
|
|
451
|
+
if (
|
|
452
|
+
value === undefined ||
|
|
453
|
+
!/^\d+$/.test(value) ||
|
|
454
|
+
!isPositiveSafeInteger(perTestTimeoutMs) ||
|
|
455
|
+
perTestTimeoutMs > idleTimeoutMs
|
|
456
|
+
) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
found = true;
|
|
460
|
+
}
|
|
461
|
+
return found;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function isTestLegTargetName(name: string): boolean {
|
|
465
|
+
return (
|
|
466
|
+
name !== CARGO_TEST_COMPILE_TARGET &&
|
|
467
|
+
name !== CARGO_TEST_ARCHIVE_TARGET &&
|
|
468
|
+
(isTestRunnerTargetName(name) || name.endsWith('-test'))
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
416
472
|
function resolvedAggregateTestIsBounded(project: ResolvedProjectTargets | undefined): boolean {
|
|
417
473
|
if (!project?.targetDependencies || !project.targetExecutors || !project.targetOptions) {
|
|
418
474
|
return false;
|
|
419
475
|
}
|
|
476
|
+
const targetNames = [...project.targets];
|
|
420
477
|
const visiting = new Set<string>();
|
|
421
478
|
const verified = new Map<string, boolean>();
|
|
422
479
|
const allowedCwds = new Set(
|
|
@@ -433,18 +490,36 @@ function resolvedAggregateTestIsBounded(project: ResolvedProjectTargets | undefi
|
|
|
433
490
|
}
|
|
434
491
|
visiting.add(targetName);
|
|
435
492
|
const executor = project.targetExecutors?.get(targetName);
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
493
|
+
const executes = executor !== undefined && executor !== 'nx:noop';
|
|
494
|
+
let valid = !executes || isBoundedExecutionTarget(executor, project.targetOptions?.get(targetName), allowedCwds);
|
|
495
|
+
let hasTestLeg = executes;
|
|
496
|
+
if (valid) {
|
|
497
|
+
for (const dependency of project.targetDependencies?.get(targetName) ?? []) {
|
|
498
|
+
if (dependency.startsWith('^')) {
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const matches = matchingResolvedTargets(dependency, project.targets, targetNames);
|
|
502
|
+
if (matches.length === 0 && isTestLegTargetName(dependency)) {
|
|
503
|
+
valid = false;
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
for (const matched of matches) {
|
|
507
|
+
// Nx omits a task's dependency on itself, including a glob that selects it.
|
|
508
|
+
if (matched === targetName || !isTestLegTargetName(matched)) {
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
hasTestLeg = true;
|
|
512
|
+
if (!visit(matched)) {
|
|
513
|
+
valid = false;
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (!valid) {
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
447
521
|
}
|
|
522
|
+
valid = valid && hasTestLeg;
|
|
448
523
|
visiting.delete(targetName);
|
|
449
524
|
verified.set(targetName, valid);
|
|
450
525
|
return valid;
|
|
@@ -453,15 +528,20 @@ function resolvedAggregateTestIsBounded(project: ResolvedProjectTargets | undefi
|
|
|
453
528
|
return visit('test');
|
|
454
529
|
}
|
|
455
530
|
|
|
456
|
-
function matchingResolvedTargets(dependency: string, targets: ReadonlySet<string
|
|
531
|
+
function matchingResolvedTargets(dependency: string, targets: ReadonlySet<string>, targetNames: string[]): string[] {
|
|
457
532
|
if (dependency.startsWith('^')) {
|
|
458
533
|
return [];
|
|
459
534
|
}
|
|
460
|
-
if (
|
|
461
|
-
return
|
|
535
|
+
if (targets.has(dependency)) {
|
|
536
|
+
return [dependency];
|
|
462
537
|
}
|
|
463
|
-
const
|
|
464
|
-
|
|
538
|
+
const matches: string[] = [];
|
|
539
|
+
for (const { target } of expandWildcardTargetConfiguration({ target: dependency, projects: [] }, targetNames)) {
|
|
540
|
+
if (targets.has(target)) {
|
|
541
|
+
matches.push(target);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return matches;
|
|
465
545
|
}
|
|
466
546
|
|
|
467
547
|
function resolvedProjectFor(
|
|
@@ -602,10 +682,6 @@ function readPackageJson(path: string): BoundedTestPolicyPackageJson {
|
|
|
602
682
|
};
|
|
603
683
|
}
|
|
604
684
|
|
|
605
|
-
function writePackageJson(path: string, packageJson: BoundedTestPolicyPackageJson): void {
|
|
606
|
-
writeFileSync(path, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
607
|
-
}
|
|
608
|
-
|
|
609
685
|
function readProjectJson(path: string): BoundedTestPolicyProjectJson {
|
|
610
686
|
const parsed = readJsonObject(path);
|
|
611
687
|
return {
|
|
@@ -634,10 +710,6 @@ function readTargets(value: unknown): Record<string, Record<string, unknown>> |
|
|
|
634
710
|
return targets;
|
|
635
711
|
}
|
|
636
712
|
|
|
637
|
-
function writeProjectJson(path: string, projectJson: BoundedTestPolicyProjectJson): void {
|
|
638
|
-
writeFileSync(path, `${JSON.stringify(projectJson, null, 2)}\n`);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
713
|
function hasTestEntrypoint(
|
|
642
714
|
packageJson: BoundedTestPolicyPackageJson,
|
|
643
715
|
projectJson: BoundedTestPolicyProjectJson | undefined,
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
3
|
+
import type { TargetConfiguration } from 'nx/src/devkit-exports.js';
|
|
4
|
+
import { BuildStateOutputError, refuseOutputsUnderBuildState } from './build-state-output-policy.js';
|
|
5
|
+
|
|
6
|
+
const workspaceRoot = '/checkout';
|
|
7
|
+
const buildStatePaths = [
|
|
8
|
+
{ checkout: 'target', volume: 'target' },
|
|
9
|
+
{ checkout: '.nx/cache', volume: 'nx/cache' },
|
|
10
|
+
{ checkout: '.nx/workspace-data', volume: 'nx/workspace-data' },
|
|
11
|
+
{ checkout: 'packages/nested/out/cargo', volume: 'cargo/nested' },
|
|
12
|
+
{ checkout: '.codegraph', volume: 'codegraph' },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
function graph(target: TargetConfiguration, root = 'packages/example'): ProjectGraph {
|
|
16
|
+
return {
|
|
17
|
+
nodes: { example: { name: 'example', type: 'lib', data: { root, targets: { archive: target } } } },
|
|
18
|
+
dependencies: { example: [] },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function validate(outputs: string[]): void {
|
|
23
|
+
refuseOutputsUnderBuildState(graph({ outputs }), buildStatePaths, workspaceRoot);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('build-state Nx output policy', () => {
|
|
27
|
+
it('refuses an output at or under every contributed build-state path', () => {
|
|
28
|
+
for (const { checkout } of buildStatePaths) {
|
|
29
|
+
for (const output of [checkout, `${checkout}/artifact`, `${checkout}/**/*`]) {
|
|
30
|
+
expect(() => validate([`{workspaceRoot}/${output}`])).toThrow(BuildStateOutputError);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('refuses ancestors whose restore can remove fixed build-state links', () => {
|
|
36
|
+
for (const output of ['{workspaceRoot}', '{workspaceRoot}/.nx', '{workspaceRoot}/packages/nested/out']) {
|
|
37
|
+
expect(() => validate([output])).toThrow(BuildStateOutputError);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('refuses glob prefixes that can cover build state, including an unbounded glob', () => {
|
|
42
|
+
for (const output of ['{workspaceRoot}/**/*', '{workspaceRoot}/packages/*/out', '{workspaceRoot}/target-*']) {
|
|
43
|
+
expect(() => validate([output])).toThrow(BuildStateOutputError);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('resolves absolute outputs against the supplied workspace root', () => {
|
|
48
|
+
for (const output of ['/checkout/target/archive', '/checkout/packages/nested', '/checkout/**/archive', '/']) {
|
|
49
|
+
expect(() => validate([output])).toThrow(BuildStateOutputError);
|
|
50
|
+
}
|
|
51
|
+
expect(() => validate(['/elsewhere/target/archive'])).not.toThrow();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('allows disjoint source-tree archive and compiler outputs without prefix false positives', () => {
|
|
55
|
+
expect(() =>
|
|
56
|
+
validate([
|
|
57
|
+
'{workspaceRoot}/.cache/nextest/archive.tar.zst',
|
|
58
|
+
'{projectRoot}/dist/**/*',
|
|
59
|
+
'{workspaceRoot}/targeted/artifact',
|
|
60
|
+
'{workspaceRoot}/packages/nested/out/cargo-docs',
|
|
61
|
+
'{workspaceRoot}/.nx-other/**/*',
|
|
62
|
+
]),
|
|
63
|
+
).not.toThrow();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('uses stock Nx interpolation for project, options and every configuration', () => {
|
|
67
|
+
const resolved = graph({
|
|
68
|
+
outputs: ['{options.outputPath}'],
|
|
69
|
+
options: { outputPath: 'dist/example' },
|
|
70
|
+
configurations: {
|
|
71
|
+
unsafe: { outputPath: 'packages/nested/out/cargo/archive' },
|
|
72
|
+
safe: { outputPath: 'dist/safe' },
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
try {
|
|
76
|
+
refuseOutputsUnderBuildState(resolved, buildStatePaths, workspaceRoot);
|
|
77
|
+
throw new Error('unsafe configured output was accepted');
|
|
78
|
+
} catch (error) {
|
|
79
|
+
expect(error).toBeInstanceOf(BuildStateOutputError);
|
|
80
|
+
if (!(error instanceof BuildStateOutputError)) throw error;
|
|
81
|
+
expect(error.findings).toEqual([
|
|
82
|
+
{
|
|
83
|
+
project: 'example',
|
|
84
|
+
target: 'archive',
|
|
85
|
+
configuration: 'unsafe',
|
|
86
|
+
output: 'packages/nested/out/cargo/archive',
|
|
87
|
+
buildStatePath: 'packages/nested/out/cargo',
|
|
88
|
+
},
|
|
89
|
+
]);
|
|
90
|
+
expect(error.message).toContain('example:archive:unsafe');
|
|
91
|
+
}
|
|
92
|
+
expect(() =>
|
|
93
|
+
refuseOutputsUnderBuildState(
|
|
94
|
+
graph({ outputs: ['{projectRoot}/artifact'] }, 'target'),
|
|
95
|
+
buildStatePaths,
|
|
96
|
+
workspaceRoot,
|
|
97
|
+
),
|
|
98
|
+
).toThrow(BuildStateOutputError);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('checks stock Nx outputPath fallback and the resolved graph override rather than plugin declarations', () => {
|
|
102
|
+
expect(() =>
|
|
103
|
+
refuseOutputsUnderBuildState(
|
|
104
|
+
graph({ options: { outputPath: 'target/archive' } }),
|
|
105
|
+
buildStatePaths,
|
|
106
|
+
workspaceRoot,
|
|
107
|
+
),
|
|
108
|
+
).toThrow(BuildStateOutputError);
|
|
109
|
+
const resolved = graph({ outputs: ['{workspaceRoot}/.cache/nextest/archive.tar.zst'] });
|
|
110
|
+
const project = resolved.nodes.example;
|
|
111
|
+
if (!project) throw new Error('fixture project missing');
|
|
112
|
+
project.data.targets = { archive: { outputs: ['{workspaceRoot}/target/overridden'] } };
|
|
113
|
+
expect(() => refuseOutputsUnderBuildState(resolved, buildStatePaths, workspaceRoot)).toThrow(BuildStateOutputError);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
2
|
+
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
3
|
+
import { getOutputsForTargetAndConfiguration, interpolate } from 'nx/src/tasks-runner/utils';
|
|
4
|
+
|
|
5
|
+
/** The read-only path records returned by `cowshed build-state --json`. */
|
|
6
|
+
export interface BuildStatePath {
|
|
7
|
+
readonly checkout: string;
|
|
8
|
+
readonly volume: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface BuildStateOutputFinding {
|
|
12
|
+
readonly project: string;
|
|
13
|
+
readonly target: string;
|
|
14
|
+
readonly configuration: string | undefined;
|
|
15
|
+
readonly output: string;
|
|
16
|
+
readonly buildStatePath: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class BuildStateOutputError extends Error {
|
|
20
|
+
constructor(readonly findings: readonly BuildStateOutputFinding[]) {
|
|
21
|
+
super(
|
|
22
|
+
`Nx outputs must not cover cowshed build-state paths:\n${findings
|
|
23
|
+
.map(
|
|
24
|
+
({ project, target, configuration, output, buildStatePath }) =>
|
|
25
|
+
` ${project}:${target}${configuration ? `:${configuration}` : ''}: ${JSON.stringify(output)} covers ${JSON.stringify(buildStatePath)}`,
|
|
26
|
+
)
|
|
27
|
+
.join('\n')}`,
|
|
28
|
+
);
|
|
29
|
+
this.name = 'BuildStateOutputError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function contains(parent: string, child: string): boolean {
|
|
34
|
+
return parent === child || child.startsWith(parent.endsWith('/') ? parent : `${parent}/`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The non-glob directory prefix, conservatively including every possible glob match. */
|
|
38
|
+
function staticPrefix(output: string): string {
|
|
39
|
+
const parts = output.replaceAll('\\', '/').split('/');
|
|
40
|
+
const firstGlob = parts.findIndex((part) => /[*?[\]{}()!]/.test(part));
|
|
41
|
+
return firstGlob < 0 ? parts.join('/') : parts.slice(0, firstGlob).join('/') || '.';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Enforce spec 16 at the consuming repository's Nx lint boundary, using its already resolved
|
|
46
|
+
* graph (including project overrides). Never construct a graph during cowshed job admission.
|
|
47
|
+
* An Nx restore may remove an output before restoring it, so ancestors and overlapping glob
|
|
48
|
+
* prefixes are unsafe too: they can replace the fixed links even without naming a tool's files.
|
|
49
|
+
*/
|
|
50
|
+
export function refuseOutputsUnderBuildState(
|
|
51
|
+
graph: ProjectGraph,
|
|
52
|
+
buildStatePaths: readonly BuildStatePath[],
|
|
53
|
+
workspaceRoot: string,
|
|
54
|
+
): void {
|
|
55
|
+
const root = workspaceRoot.replaceAll('\\', '/');
|
|
56
|
+
if (!posix.isAbsolute(root)) throw new Error('build-state output validation requires an absolute workspace root');
|
|
57
|
+
const paths = buildStatePaths.map(({ checkout }) => ({ checkout, absolute: posix.resolve(root, checkout) }));
|
|
58
|
+
const findings: BuildStateOutputFinding[] = [];
|
|
59
|
+
for (const [project, node] of Object.entries(graph.nodes)) {
|
|
60
|
+
for (const [target, options] of Object.entries(node.data.targets ?? {})) {
|
|
61
|
+
const configurations: (string | undefined)[] = [undefined, ...Object.keys(options.configurations ?? {})];
|
|
62
|
+
for (const configuration of configurations) {
|
|
63
|
+
// Nx's task helper rejects root globs and absolute declarations before expanding
|
|
64
|
+
// them. This lint must name the overlapping build path even for those declarations.
|
|
65
|
+
const outputs = options.outputs
|
|
66
|
+
? options.outputs
|
|
67
|
+
.map((output) =>
|
|
68
|
+
interpolate(output, {
|
|
69
|
+
workspaceRoot: root,
|
|
70
|
+
projectRoot: node.data.root,
|
|
71
|
+
projectName: node.name,
|
|
72
|
+
project: { ...node.data, name: node.name },
|
|
73
|
+
options: { ...options.options, ...(configuration ? options.configurations?.[configuration] : {}) },
|
|
74
|
+
}),
|
|
75
|
+
)
|
|
76
|
+
.filter((output) => output && !/{(projectRoot|workspaceRoot|(options.*))}/.test(output))
|
|
77
|
+
: getOutputsForTargetAndConfiguration({ project, target, configuration }, {}, node);
|
|
78
|
+
for (const output of outputs) {
|
|
79
|
+
const prefix = posix.resolve(root, staticPrefix(output));
|
|
80
|
+
for (const path of paths) {
|
|
81
|
+
if (contains(prefix, path.absolute) || contains(path.absolute, prefix)) {
|
|
82
|
+
findings.push({ project, target, configuration, output, buildStatePath: path.checkout });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (findings.length) throw new BuildStateOutputError(findings);
|
|
90
|
+
}
|
|
@@ -1,10 +1,58 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { copyFile, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
2
6
|
|
|
3
7
|
describe('Bun bootstrap imports', () => {
|
|
4
8
|
it('imports the main plugin entry point', async () => {
|
|
5
|
-
|
|
9
|
+
// Module loading is the boundary under test; the public entry must select the transformed product.
|
|
10
|
+
const plugin = await import('@smoothbricks/nx-plugin');
|
|
6
11
|
expect(plugin.createNodesV2).toBeDefined();
|
|
7
12
|
expect(Array.isArray(plugin.createNodesV2)).toBe(true);
|
|
13
|
+
expect(typeof plugin.preTasksExecution).toBe('function');
|
|
14
|
+
expect(typeof plugin.postTasksExecution).toBe('function');
|
|
15
|
+
expect(typeof plugin.default.preTasksExecution).toBe('function');
|
|
16
|
+
expect(typeof plugin.default.postTasksExecution).toBe('function');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('refuses a cold missing bootstrap product instead of returning an empty graph', async () => {
|
|
20
|
+
const root = await mkdtemp(join(tmpdir(), 'nx-plugin-bootstrap-'));
|
|
21
|
+
try {
|
|
22
|
+
await writeFile(join(root, 'package.json'), '{"type":"module"}\n');
|
|
23
|
+
await copyFile(join(import.meta.dir, '../loader.js'), join(root, 'loader.js'));
|
|
24
|
+
const script = `await import(${JSON.stringify(join(root, 'loader.js'))})`;
|
|
25
|
+
const child = spawnSync(process.execPath, ['--no-install', '-e', script], { cwd: root, encoding: 'utf8' });
|
|
26
|
+
expect(child.status).not.toBe(0);
|
|
27
|
+
expect(child.stderr).toContain('The Nx plugin bootstrap product is missing:');
|
|
28
|
+
expect(child.stderr).toContain('ttsc -p packages/nx-plugin/tsconfig.lib.json --emit');
|
|
29
|
+
} finally {
|
|
30
|
+
await rm(root, { recursive: true, force: true });
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('loads the public policy caller closure without a transform preload', () => {
|
|
35
|
+
const script = [
|
|
36
|
+
'const { fileURLToPath } = await import("node:url");',
|
|
37
|
+
'const { handleImport } = await import("nx/src/utils/handle-import.js");',
|
|
38
|
+
'const root = await handleImport(fileURLToPath(import.meta.resolve("@smoothbricks/nx-plugin")));',
|
|
39
|
+
'if (!Array.isArray(root.createNodesV2)) throw new Error("the compiled plugin entry is incomplete");',
|
|
40
|
+
'const policy = await import("@smoothbricks/nx-plugin/workspace-config-policy");',
|
|
41
|
+
'const bounded = await import("@smoothbricks/nx-plugin/bounded-test-policy");',
|
|
42
|
+
'const targets = await import("@smoothbricks/nx-plugin/package-target-policy");',
|
|
43
|
+
'const eslint = await import("@smoothbricks/nx-plugin/eslint-file-set");',
|
|
44
|
+
'if (!policy.checkWorkspaceConfig({plugins:[{plugin:42}]}).some(issue => issue.message.startsWith("plugins is malformed:"))) throw new Error("the public policy did not validate");',
|
|
45
|
+
'if (typeof bounded.applyBoundedTestTargetPolicy !== "function" || typeof targets.applyPackageTargetPolicy !== "function") throw new Error("the compiled caller closure is incomplete");',
|
|
46
|
+
'if (!eslint.isEslintFileSet({command:"eslint src/fixture.ts",files:["src/fixture.ts"]}) || eslint.isEslintFileSet({command:42,files:[]})) throw new Error("the compiled ESLint file-set owner did not validate");',
|
|
47
|
+
].join('\n');
|
|
48
|
+
for (const conditions of [[], ['--conditions=development']]) {
|
|
49
|
+
const child = spawnSync(
|
|
50
|
+
process.execPath,
|
|
51
|
+
['--config=/dev/null', '--no-env-file', '--no-install', ...conditions, '-e', script],
|
|
52
|
+
{ cwd: join(import.meta.dir, '../../cli'), encoding: 'utf8' },
|
|
53
|
+
);
|
|
54
|
+
expect(child.status, child.stdout + child.stderr).toBe(0);
|
|
55
|
+
}
|
|
8
56
|
});
|
|
9
57
|
|
|
10
58
|
it('imports bounded-test-policy', async () => {
|
|
@@ -17,16 +65,22 @@ describe('Bun bootstrap imports', () => {
|
|
|
17
65
|
expect(typeof policy.resolveTestCommand).toBe('function');
|
|
18
66
|
expect(typeof policy.ensureBunTestTimeoutFlag).toBe('function');
|
|
19
67
|
expect(typeof policy.BOUNDED_TEST_EXECUTOR).toBe('string');
|
|
20
|
-
expect(typeof policy.
|
|
68
|
+
expect(typeof policy.BOUNDED_TEST_IDLE_TIMEOUT_MS).toBe('number');
|
|
21
69
|
expect(typeof policy.BOUNDED_TEST_KILL_AFTER_MS).toBe('number');
|
|
22
70
|
expect(typeof policy.BOUNDED_TEST_PER_TEST_TIMEOUT_MS).toBe('number');
|
|
23
71
|
});
|
|
24
72
|
|
|
25
73
|
it('imports workspace-config-policy', async () => {
|
|
26
|
-
|
|
74
|
+
// Module loading is the boundary under test; no test preload may mask a raw public policy entry.
|
|
75
|
+
const policy = await import('@smoothbricks/nx-plugin/workspace-config-policy');
|
|
27
76
|
expect(typeof policy.checkWorkspaceConfigPolicy).toBe('function');
|
|
28
77
|
expect(typeof policy.applyWorkspaceConfigPolicy).toBe('function');
|
|
29
78
|
expect(Array.isArray(policy.BUILD_OUTPUT_DEPENDENCIES)).toBe(true);
|
|
79
|
+
expect(
|
|
80
|
+
policy
|
|
81
|
+
.checkWorkspaceConfig({ plugins: [{ plugin: 42 }] })
|
|
82
|
+
.some((issue) => issue.message.startsWith('plugins is malformed:')),
|
|
83
|
+
).toBe(true);
|
|
30
84
|
});
|
|
31
85
|
|
|
32
86
|
it('imports release-config-policy', async () => {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { DependencyType } from 'nx/src/config/project-graph';
|
|
4
|
+
import { getBunTextLockfileDependencies, getBunTextLockfileNodes } from 'nx/src/plugins/js/lock-file/bun-parser';
|
|
5
|
+
import type { CreateDependenciesContext } from 'nx/src/project-graph/plugins';
|
|
6
|
+
|
|
7
|
+
// A local file package is not an Nx workspace merely because Bun copied it.
|
|
8
|
+
// Keep the real parser and native hasher: these assertions fail on stock Nx 23.2.1.
|
|
9
|
+
test('Bun file packages retain their external node and consumer edge without externalizing actual workspaces', () => {
|
|
10
|
+
const lock = JSON.stringify({
|
|
11
|
+
lockfileVersion: 3,
|
|
12
|
+
workspaces: {
|
|
13
|
+
'': {
|
|
14
|
+
name: 'file-package-host',
|
|
15
|
+
dependencies: {
|
|
16
|
+
consumer: '1.0.0',
|
|
17
|
+
'@fixture/sdk': 'file:./.managed/sdk',
|
|
18
|
+
'@fixture/worker': 'file:./packages/worker',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
'packages/worker': { name: '@fixture/worker', version: '1.0.0' },
|
|
22
|
+
},
|
|
23
|
+
packages: {
|
|
24
|
+
consumer: ['consumer@1.0.0', '', { dependencies: { '@fixture/sdk': 'file:.managed/sdk' } }, 'sha512-consumer'],
|
|
25
|
+
'@fixture/sdk': ['@fixture/sdk@file:.managed/sdk', {}],
|
|
26
|
+
'@fixture/worker': ['@fixture/worker@file:./packages/worker', {}],
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const hash = createHash('sha256').update(lock).digest('hex');
|
|
30
|
+
const nodes = getBunTextLockfileNodes(lock, hash);
|
|
31
|
+
expect(nodes['npm:@fixture/sdk@file:.managed/sdk']?.data.packageName).toBe('@fixture/sdk');
|
|
32
|
+
expect(nodes['npm:@fixture/sdk@file:.managed/sdk']?.data.version).toBe('file:.managed/sdk');
|
|
33
|
+
expect(Object.values(nodes).some((node) => node.data.packageName === '@fixture/worker')).toBe(false);
|
|
34
|
+
const context: CreateDependenciesContext = {
|
|
35
|
+
externalNodes: nodes,
|
|
36
|
+
projects: { worker: { root: 'packages/worker', name: 'worker' } },
|
|
37
|
+
nxJsonConfiguration: {},
|
|
38
|
+
fileMap: { projectFileMap: {}, nonProjectFiles: [] },
|
|
39
|
+
filesToProcess: { projectFileMap: {}, nonProjectFiles: [] },
|
|
40
|
+
workspaceRoot: process.cwd(),
|
|
41
|
+
};
|
|
42
|
+
expect(getBunTextLockfileDependencies(lock, hash, context)).toContainEqual({
|
|
43
|
+
source: 'npm:consumer@1.0.0',
|
|
44
|
+
target: 'npm:@fixture/sdk@file:.managed/sdk',
|
|
45
|
+
type: DependencyType.static,
|
|
46
|
+
});
|
|
47
|
+
});
|