@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
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { channel } from 'node:diagnostics_channel';
|
|
3
|
+
import { mkdir, readdir, readFile, symlink, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import type { Subprocess } from 'bun';
|
|
6
|
+
import { TaskOutputLeases } from 'nx/src/tasks-runner/task-output-lease.js';
|
|
7
|
+
import { guardEvent } from './__tests__/counted-cargo.js';
|
|
8
|
+
import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
9
|
+
import { runtimeInput } from './runtime-input.js';
|
|
10
|
+
import { bindListener } from './testing.js';
|
|
11
|
+
|
|
12
|
+
interface ProbeEvent {
|
|
13
|
+
readonly promise: Promise<URL>;
|
|
14
|
+
resolve(value: URL): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const repoRoot = join(import.meta.dir, '../../..');
|
|
18
|
+
const nx = join(repoRoot, 'node_modules/.bin/nx');
|
|
19
|
+
const binary = Buffer.from([0xff, 0xfe, 0x80, 0, 42]);
|
|
20
|
+
const fileCount = 64;
|
|
21
|
+
|
|
22
|
+
/** The producer pauses with an incomplete live tree; another client's capture must never see it. */
|
|
23
|
+
const producer = String.raw`
|
|
24
|
+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
25
|
+
const label = process.env.OUTPUT_LABEL;
|
|
26
|
+
const event = (phase) => fetch(process.env.LEASE_PROBE + '/' + phase + '?label=' + label);
|
|
27
|
+
rmSync('app/dist', { recursive: true, force: true });
|
|
28
|
+
mkdirSync('app/dist', { recursive: true });
|
|
29
|
+
for (let index = 0; index < 2; index++) writeFileSync('app/dist/' + index + '.js', label);
|
|
30
|
+
await event('partial');
|
|
31
|
+
for (let index = 2; index < 64; index++) writeFileSync('app/dist/' + index + '.js', label);
|
|
32
|
+
writeFileSync('app/dist/binary.dat', Buffer.from([255, 254, 128, 0, 42]));
|
|
33
|
+
await event('built');
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
/** Observe the real capture boundary, without replacing native put/copy or their result. */
|
|
37
|
+
const preload = String.raw`
|
|
38
|
+
const { channel } = require('node:diagnostics_channel');
|
|
39
|
+
const { DbCache } = require('nx/src/tasks-runner/cache');
|
|
40
|
+
const original = DbCache.prototype.put;
|
|
41
|
+
const event = (phase, hash = '') => fetch(process.env.LEASE_PROBE + '/' + phase + '?label=' + process.env.OUTPUT_LABEL + '&hash=' + hash);
|
|
42
|
+
channel('nx:task-output-lease').subscribe((message) => {
|
|
43
|
+
if (message.phase === 'waiting' && message.targets.includes('app:build')) {
|
|
44
|
+
event('waiting').catch((error) => { console.error(error); process.exitCode = 1; });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
DbCache.prototype.put = async function(task, ...args) {
|
|
48
|
+
if (task.target.project === 'app' && task.target.target === 'build') {
|
|
49
|
+
if (process.env.OUTPUT_LABEL === 'A') await event('capture');
|
|
50
|
+
const result = await original.call(this, task, ...args);
|
|
51
|
+
await event('captured', task.hash);
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
return original.call(this, task, ...args);
|
|
55
|
+
};
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
it('leases a target across clients through producer completion, cache capture and restore', async () => {
|
|
59
|
+
await withNxFixture('nx-task-output-lease-', async ({ workspace, socketDirectory }) => {
|
|
60
|
+
const observed = new Map<string, ProbeEvent>();
|
|
61
|
+
const events: string[] = [];
|
|
62
|
+
const signal = (name: string) => {
|
|
63
|
+
let event = observed.get(name);
|
|
64
|
+
if (event === undefined) {
|
|
65
|
+
event = Promise.withResolvers<URL>();
|
|
66
|
+
observed.set(name, event);
|
|
67
|
+
}
|
|
68
|
+
return event;
|
|
69
|
+
};
|
|
70
|
+
const capture = Promise.withResolvers<void>();
|
|
71
|
+
const replacement = Promise.withResolvers<void>();
|
|
72
|
+
const failed = Promise.withResolvers<never>();
|
|
73
|
+
using server = await bindListener((port) =>
|
|
74
|
+
Bun.serve({
|
|
75
|
+
hostname: '127.0.0.1',
|
|
76
|
+
port,
|
|
77
|
+
async fetch(request) {
|
|
78
|
+
const url = new URL(request.url);
|
|
79
|
+
const key = `${url.pathname.slice(1)}:${url.searchParams.get('label')}`;
|
|
80
|
+
events.push(key);
|
|
81
|
+
signal(key).resolve(url);
|
|
82
|
+
if (key === 'capture:A') await capture.promise;
|
|
83
|
+
if (key === 'partial:B') await replacement.promise;
|
|
84
|
+
return new Response('ok');
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
await mkdir(join(workspace, 'app'));
|
|
89
|
+
await symlink(join(repoRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
90
|
+
await writeFile(join(workspace, 'produce.ts'), producer);
|
|
91
|
+
await writeFile(join(workspace, 'probe.cjs'), preload);
|
|
92
|
+
await writeFile(
|
|
93
|
+
join(workspace, 'digest.ts'),
|
|
94
|
+
String.raw`const bytes = await Bun.file('app/dist/binary.dat').bytes(); console.log(new Bun.CryptoHasher('sha256').update(bytes).digest('hex'));`,
|
|
95
|
+
);
|
|
96
|
+
await writeFile(join(workspace, 'nx.json'), JSON.stringify({ cacheDirectory: '.nx/cache' }));
|
|
97
|
+
await writeFile(
|
|
98
|
+
join(workspace, 'app/project.json'),
|
|
99
|
+
JSON.stringify({
|
|
100
|
+
name: 'app',
|
|
101
|
+
targets: {
|
|
102
|
+
build: {
|
|
103
|
+
executor: 'nx:run-commands',
|
|
104
|
+
cache: true,
|
|
105
|
+
inputs: ['{workspaceRoot}/produce.ts', { env: 'OUTPUT_LABEL' }],
|
|
106
|
+
outputs: ['{projectRoot}/dist'],
|
|
107
|
+
options: { command: 'bun produce.ts' },
|
|
108
|
+
},
|
|
109
|
+
hash: {
|
|
110
|
+
executor: 'nx:run-commands',
|
|
111
|
+
cache: true,
|
|
112
|
+
dependsOn: ['build'],
|
|
113
|
+
inputs: [runtimeInput('bun digest.ts')],
|
|
114
|
+
options: { command: "bun -e \"await Bun.write('hashed.ran', 'yes')\"" },
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
const env = fixtureNxEnv(workspace, socketDirectory);
|
|
120
|
+
const children: Subprocess<'ignore', 'pipe', 'pipe'>[] = [];
|
|
121
|
+
const run = (label: string, target = 'app:build') => {
|
|
122
|
+
const child = Bun.spawn(
|
|
123
|
+
['bun', '--preload', join(workspace, 'probe.cjs'), nx, 'run', target, '--outputStyle=static'],
|
|
124
|
+
{
|
|
125
|
+
cwd: workspace,
|
|
126
|
+
env: { ...env, OUTPUT_LABEL: label, LEASE_PROBE: server.url.origin },
|
|
127
|
+
stdin: 'ignore',
|
|
128
|
+
stdout: 'pipe',
|
|
129
|
+
stderr: 'pipe',
|
|
130
|
+
},
|
|
131
|
+
);
|
|
132
|
+
children.push(child);
|
|
133
|
+
return Promise.all([child.exited, new Response(child.stdout).text(), new Response(child.stderr).text()]).then(
|
|
134
|
+
(result) => {
|
|
135
|
+
if (result[0] !== 0)
|
|
136
|
+
failed.reject(new Error(`${label} ${target} exited ${result[0]}\n${result[1]}${result[2]}`));
|
|
137
|
+
return result;
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
const waitFor = (name: string) =>
|
|
142
|
+
guardEvent(Promise.race([signal(name).promise, failed.promise]), name, () => events.join('\n'));
|
|
143
|
+
try {
|
|
144
|
+
const first = run('A');
|
|
145
|
+
await waitFor('capture:A');
|
|
146
|
+
const second = run('B');
|
|
147
|
+
// Before the repair the second producer reaches its partial live tree. With the lease it reports
|
|
148
|
+
// waiting instead. Neither arm depends on a sleep or a guessed scheduler delay.
|
|
149
|
+
await guardEvent(
|
|
150
|
+
Promise.race([signal('waiting:B').promise, signal('partial:B').promise, failed.promise]),
|
|
151
|
+
'the second client to reach the output boundary',
|
|
152
|
+
() => events.join('\n'),
|
|
153
|
+
);
|
|
154
|
+
capture.resolve();
|
|
155
|
+
const capturedA = await waitFor('captured:A');
|
|
156
|
+
await waitFor('partial:B');
|
|
157
|
+
replacement.resolve();
|
|
158
|
+
const capturedB = await waitFor('captured:B');
|
|
159
|
+
for (const result of [await first, await second]) expect(result[0], `${result[1]}${result[2]}`).toBe(0);
|
|
160
|
+
for (const [label, event] of [
|
|
161
|
+
['A', capturedA],
|
|
162
|
+
['B', capturedB],
|
|
163
|
+
] as const) {
|
|
164
|
+
const hash = event.searchParams.get('hash');
|
|
165
|
+
if (hash === null) throw new Error(`no ${label} cache identity: ${event}`);
|
|
166
|
+
const artifact = join(workspace, '.nx/cache', hash, 'app/dist');
|
|
167
|
+
expect((await readdir(artifact)).length, `${label} artifact is incomplete`).toBe(fileCount + 1);
|
|
168
|
+
for (let index = 0; index < fileCount; index++)
|
|
169
|
+
expect(await readFile(join(artifact, `${index}.js`), 'utf8')).toBe(label);
|
|
170
|
+
expect(await readFile(join(artifact, 'binary.dat'))).toEqual(binary);
|
|
171
|
+
}
|
|
172
|
+
// Returning to A must restore its whole artifact, and a runtime input must hash arbitrary file bytes
|
|
173
|
+
// through its byte digest rather than emitting the fail-closed 0xFF stdout used for producer failures.
|
|
174
|
+
const restored = await run('A', 'app:hash');
|
|
175
|
+
expect(restored[0], `${restored[1]}${restored[2]}`).toBe(0);
|
|
176
|
+
expect(await readFile(join(workspace, 'app/dist/0.js'), 'utf8')).toBe('A');
|
|
177
|
+
expect(await readFile(join(workspace, 'app/dist/binary.dat'))).toEqual(binary);
|
|
178
|
+
expect(await readFile(join(workspace, 'hashed.ran'), 'utf8')).toBe('yes');
|
|
179
|
+
expect(events.filter((event) => event === 'built:A')).toHaveLength(1);
|
|
180
|
+
} finally {
|
|
181
|
+
capture.resolve();
|
|
182
|
+
replacement.resolve();
|
|
183
|
+
for (const child of children) {
|
|
184
|
+
if (child.exitCode === null) child.kill('SIGKILL');
|
|
185
|
+
}
|
|
186
|
+
await Promise.all(children.map((child) => child.exited));
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}, 120_000);
|
|
190
|
+
|
|
191
|
+
it('shares ownership across configurations without blocking independent targets, and cancels lock waiters', async () => {
|
|
192
|
+
const owner = new TaskOutputLeases(2, null, 'output');
|
|
193
|
+
const other = new TaskOutputLeases(2, null, 'output');
|
|
194
|
+
const task = {
|
|
195
|
+
id: 'lease:build:first',
|
|
196
|
+
target: { project: `lease-${crypto.randomUUID()}`, target: 'build', configuration: 'first' },
|
|
197
|
+
overrides: {},
|
|
198
|
+
outputs: ['app/dist'],
|
|
199
|
+
cache: true,
|
|
200
|
+
};
|
|
201
|
+
const release = await owner.acquire([task]);
|
|
202
|
+
let releaseOther: (() => Promise<void>) | undefined;
|
|
203
|
+
try {
|
|
204
|
+
const waiting = Promise.withResolvers<void>();
|
|
205
|
+
const onWaiting = () => waiting.resolve();
|
|
206
|
+
const events = channel('nx:task-output-lease');
|
|
207
|
+
events.subscribe(onWaiting);
|
|
208
|
+
let acquired = false;
|
|
209
|
+
const sameTarget = other
|
|
210
|
+
.acquire([{ ...task, target: { ...task.target, configuration: 'second' } }])
|
|
211
|
+
.then((releaseLease) => {
|
|
212
|
+
acquired = true;
|
|
213
|
+
return releaseLease;
|
|
214
|
+
});
|
|
215
|
+
await waiting.promise;
|
|
216
|
+
events.unsubscribe(onWaiting);
|
|
217
|
+
await other.withTasks([{ ...task, target: { ...task.target, target: 'independent' } }], async () => {
|
|
218
|
+
expect(acquired).toBe(false);
|
|
219
|
+
});
|
|
220
|
+
await release();
|
|
221
|
+
releaseOther = await sameTarget;
|
|
222
|
+
await releaseOther();
|
|
223
|
+
await expect(
|
|
224
|
+
other.withTasks([task], async () => {
|
|
225
|
+
throw new Error('producer refused');
|
|
226
|
+
}),
|
|
227
|
+
).rejects.toThrow('producer refused');
|
|
228
|
+
// The failed producer's finally released ownership, so another client can acquire it.
|
|
229
|
+
const heldAgain = await owner.acquire([task]);
|
|
230
|
+
try {
|
|
231
|
+
const refused = other.acquire([task]).then(
|
|
232
|
+
() => null,
|
|
233
|
+
(error: unknown) => error,
|
|
234
|
+
);
|
|
235
|
+
await other.cancelPending();
|
|
236
|
+
const reason = await refused;
|
|
237
|
+
expect(reason).toBeInstanceOf(Error);
|
|
238
|
+
if (!(reason instanceof Error)) throw new Error('the cancelled waiter unexpectedly acquired ownership');
|
|
239
|
+
expect(reason.message).toContain('worker exited');
|
|
240
|
+
} finally {
|
|
241
|
+
await heldAgain();
|
|
242
|
+
}
|
|
243
|
+
} finally {
|
|
244
|
+
await releaseOther?.();
|
|
245
|
+
await release();
|
|
246
|
+
await Promise.all([owner.close(), other.close()]);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('refuses an ancestor-owned target before waiting for its output lease', async () => {
|
|
251
|
+
await withNxFixture('nx-task-output-loop-', async ({ workspace, socketDirectory }) => {
|
|
252
|
+
await mkdir(join(workspace, 'app'));
|
|
253
|
+
await symlink(join(repoRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
254
|
+
await writeFile(join(workspace, 'nx.json'), '{}');
|
|
255
|
+
await writeFile(
|
|
256
|
+
join(workspace, 'app/project.json'),
|
|
257
|
+
JSON.stringify({
|
|
258
|
+
name: 'app',
|
|
259
|
+
targets: {
|
|
260
|
+
loop: {
|
|
261
|
+
executor: 'nx:run-commands',
|
|
262
|
+
cache: false,
|
|
263
|
+
outputs: ['{projectRoot}/dist'],
|
|
264
|
+
options: { command: `bun ${JSON.stringify(nx)} run app:loop --outputStyle=static` },
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
const child = Bun.spawn(['bun', nx, 'run', 'app:loop', '--outputStyle=static'], {
|
|
270
|
+
cwd: workspace,
|
|
271
|
+
env: fixtureNxEnv(workspace, socketDirectory),
|
|
272
|
+
stdin: 'ignore',
|
|
273
|
+
stdout: 'pipe',
|
|
274
|
+
stderr: 'pipe',
|
|
275
|
+
});
|
|
276
|
+
try {
|
|
277
|
+
const [status, stdout, stderr] = await guardEvent(
|
|
278
|
+
Promise.all([child.exited, new Response(child.stdout).text(), new Response(child.stderr).text()]),
|
|
279
|
+
'recursive target refusal before lease acquisition',
|
|
280
|
+
() => `client ${child.pid}, exit ${child.exitCode}`,
|
|
281
|
+
);
|
|
282
|
+
expect(status, `${stdout}${stderr}`).not.toBe(0);
|
|
283
|
+
expect(`${stdout}${stderr}`).toContain('Recursive task output lease');
|
|
284
|
+
expect(`${stdout}${stderr}`).toContain('ancestor client');
|
|
285
|
+
} finally {
|
|
286
|
+
if (child.exitCode === null) child.kill('SIGKILL');
|
|
287
|
+
await child.exited;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}, 60_000);
|
|
291
|
+
|
|
292
|
+
it('shares one continuous producer between simultaneous cold clients without waiting for its lifetime lease', async () => {
|
|
293
|
+
await withNxFixture('nx-task-output-continuous-', async ({ workspace, socketDirectory }) => {
|
|
294
|
+
const entered = new Set<string>();
|
|
295
|
+
const bothEntered = Promise.withResolvers<void>();
|
|
296
|
+
const start = Promise.withResolvers<void>();
|
|
297
|
+
const finish = Promise.withResolvers<void>();
|
|
298
|
+
const started = Promise.withResolvers<URL>();
|
|
299
|
+
const shared = Promise.withResolvers<URL>();
|
|
300
|
+
const events: string[] = [];
|
|
301
|
+
using server = await bindListener((port) =>
|
|
302
|
+
Bun.serve({
|
|
303
|
+
hostname: '127.0.0.1',
|
|
304
|
+
port,
|
|
305
|
+
async fetch(request) {
|
|
306
|
+
const url = new URL(request.url);
|
|
307
|
+
const client = url.searchParams.get('client') ?? '';
|
|
308
|
+
events.push(`${url.pathname}:${client}`);
|
|
309
|
+
if (url.pathname === '/enter') {
|
|
310
|
+
entered.add(client);
|
|
311
|
+
if (entered.size === 2) bothEntered.resolve();
|
|
312
|
+
await start.promise;
|
|
313
|
+
} else if (url.pathname === '/started') {
|
|
314
|
+
started.resolve(url);
|
|
315
|
+
await finish.promise;
|
|
316
|
+
} else if (url.pathname === '/shared') {
|
|
317
|
+
shared.resolve(url);
|
|
318
|
+
}
|
|
319
|
+
return new Response('ok');
|
|
320
|
+
},
|
|
321
|
+
}),
|
|
322
|
+
);
|
|
323
|
+
await mkdir(join(workspace, 'app'));
|
|
324
|
+
await symlink(join(repoRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
325
|
+
await writeFile(join(workspace, 'nx.json'), '{}');
|
|
326
|
+
await writeFile(
|
|
327
|
+
join(workspace, 'app/project.json'),
|
|
328
|
+
JSON.stringify({
|
|
329
|
+
name: 'app',
|
|
330
|
+
targets: {
|
|
331
|
+
serve: {
|
|
332
|
+
executor: 'nx:run-commands',
|
|
333
|
+
continuous: true,
|
|
334
|
+
cache: false,
|
|
335
|
+
outputs: ['{projectRoot}/dist'],
|
|
336
|
+
options: { command: 'bun serve.ts' },
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
}),
|
|
340
|
+
);
|
|
341
|
+
await writeFile(
|
|
342
|
+
join(workspace, 'serve.ts'),
|
|
343
|
+
String.raw`import { mkdirSync, writeFileSync } from 'node:fs';
|
|
344
|
+
mkdirSync('app/dist', {recursive:true});
|
|
345
|
+
writeFileSync('app/dist/pid', String(process.pid));
|
|
346
|
+
await fetch(process.env.LEASE_PROBE + '/started?client=' + process.env.LEASE_CLIENT + '&pid=' + process.pid);`,
|
|
347
|
+
);
|
|
348
|
+
await writeFile(
|
|
349
|
+
join(workspace, 'continuous-probe.cjs'),
|
|
350
|
+
String.raw`const {TaskOrchestrator} = require('nx/src/tasks-runner/task-orchestrator');
|
|
351
|
+
const {SharedRunningTask} = require('nx/src/tasks-runner/running-tasks/shared-running-task');
|
|
352
|
+
const event = (phase) => fetch(process.env.LEASE_PROBE + '/' + phase + '?client=' + process.env.LEASE_CLIENT);
|
|
353
|
+
const originalStart = TaskOrchestrator.prototype.startContinuousTask;
|
|
354
|
+
TaskOrchestrator.prototype.startContinuousTask = async function(...args) {
|
|
355
|
+
await event('enter');
|
|
356
|
+
return originalStart.apply(this, args);
|
|
357
|
+
};
|
|
358
|
+
const originalWait = SharedRunningTask.prototype.waitForTaskToFinish;
|
|
359
|
+
SharedRunningTask.prototype.waitForTaskToFinish = async function(...args) {
|
|
360
|
+
await event('shared');
|
|
361
|
+
return originalWait.apply(this, args);
|
|
362
|
+
};`,
|
|
363
|
+
);
|
|
364
|
+
const children: Subprocess<'ignore', 'pipe', 'pipe'>[] = [];
|
|
365
|
+
const env = fixtureNxEnv(workspace, socketDirectory);
|
|
366
|
+
const run = (client: string) => {
|
|
367
|
+
const child = Bun.spawn(
|
|
368
|
+
['bun', '--preload', join(workspace, 'continuous-probe.cjs'), nx, 'run', 'app:serve', '--outputStyle=static'],
|
|
369
|
+
{
|
|
370
|
+
cwd: workspace,
|
|
371
|
+
env: { ...env, LEASE_PROBE: server.url.origin, LEASE_CLIENT: client },
|
|
372
|
+
stdin: 'ignore',
|
|
373
|
+
stdout: 'pipe',
|
|
374
|
+
stderr: 'pipe',
|
|
375
|
+
},
|
|
376
|
+
);
|
|
377
|
+
children.push(child);
|
|
378
|
+
return Promise.all([child.exited, new Response(child.stdout).text(), new Response(child.stderr).text()]);
|
|
379
|
+
};
|
|
380
|
+
try {
|
|
381
|
+
const first = run('A');
|
|
382
|
+
const second = run('B');
|
|
383
|
+
await guardEvent(bothEntered.promise, 'both cold continuous clients at the startup boundary', () =>
|
|
384
|
+
events.join('\n'),
|
|
385
|
+
);
|
|
386
|
+
start.resolve();
|
|
387
|
+
const [producerEvent, sharedEvent] = await guardEvent(
|
|
388
|
+
Promise.all([started.promise, shared.promise]),
|
|
389
|
+
'one continuous producer and one shared waiter while the producer is alive',
|
|
390
|
+
() => events.join('\n'),
|
|
391
|
+
);
|
|
392
|
+
expect(entered.size).toBe(2);
|
|
393
|
+
expect(producerEvent.searchParams.get('client')).not.toBe(sharedEvent.searchParams.get('client'));
|
|
394
|
+
expect(events.filter((event) => event.startsWith('/started:'))).toHaveLength(1);
|
|
395
|
+
const producerPid = producerEvent.searchParams.get('pid');
|
|
396
|
+
if (producerPid === null) throw new Error(`continuous producer omitted its pid: ${producerEvent}`);
|
|
397
|
+
expect(await readFile(join(workspace, 'app/dist/pid'), 'utf8')).toBe(producerPid);
|
|
398
|
+
finish.resolve();
|
|
399
|
+
const results = await guardEvent(
|
|
400
|
+
Promise.all([first, second]),
|
|
401
|
+
'both continuous clients to finish after their one producer exits',
|
|
402
|
+
() => events.join('\n'),
|
|
403
|
+
);
|
|
404
|
+
for (const [status, stdout, stderr] of results) expect(status, `${stdout}${stderr}`).toBe(0);
|
|
405
|
+
} finally {
|
|
406
|
+
start.resolve();
|
|
407
|
+
finish.resolve();
|
|
408
|
+
for (const child of children) {
|
|
409
|
+
if (child.exitCode === null) child.kill('SIGTERM');
|
|
410
|
+
}
|
|
411
|
+
await Promise.all(children.map((child) => child.exited));
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}, 60_000);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { chmod, mkdir, readFile, symlink, unlink, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { delimiter, join } from 'node:path';
|
|
5
|
+
import { guardEvent } from './__tests__/counted-cargo.js';
|
|
6
|
+
import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Guards the `latest-nx.js` and `bin/nx.js` hunks of `patches/nx@23.2.1.patch`. Stock Nx 23.2.1 answers the Nx
|
|
10
|
+
* Console and AI-agent status every `nx run` asks its daemon for by installing `nx@latest` from the registry into a
|
|
11
|
+
* temporary directory (`npm install`), unless the environment the client sent the daemon says `NX_USE_LOCAL=true`.
|
|
12
|
+
* Agents, cowshed jobs and test fixtures run Nx without that variable, and the daemon took it from whichever client
|
|
13
|
+
* spoke last. The patched daemon resolves its own installed Nx instead, whatever a client sends, and the patched
|
|
14
|
+
* `nx` entry defaults the variable for every command it runs.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const repositoryRoot = join(import.meta.dir, '../../..');
|
|
18
|
+
const PACKAGE_MANAGERS = ['npm', 'npx', 'pnpm', 'yarn'];
|
|
19
|
+
|
|
20
|
+
async function run(
|
|
21
|
+
command: string,
|
|
22
|
+
args: string[],
|
|
23
|
+
cwd: string,
|
|
24
|
+
env: Record<string, string>,
|
|
25
|
+
expectedCode = 0,
|
|
26
|
+
): Promise<string> {
|
|
27
|
+
const child = spawn(command, args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
28
|
+
let output = '';
|
|
29
|
+
child.stdout?.setEncoding('utf8').on('data', (text: string) => {
|
|
30
|
+
output += text;
|
|
31
|
+
});
|
|
32
|
+
child.stderr?.setEncoding('utf8').on('data', (text: string) => {
|
|
33
|
+
output += text;
|
|
34
|
+
});
|
|
35
|
+
const { promise: ended, resolve, reject } = Promise.withResolvers<number | null>();
|
|
36
|
+
child.once('error', reject);
|
|
37
|
+
child.once('close', resolve);
|
|
38
|
+
const code = await guardEvent(ended, `${command} ${args.join(' ')} to close`, () => output);
|
|
39
|
+
expect(code, output).toBe(expectedCode);
|
|
40
|
+
return output;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
it('starts no package manager from a daemon whose clients do not set NX_USE_LOCAL, through nx or the library', async () => {
|
|
44
|
+
await withNxFixture('nx-use-local', async ({ root, workspace, socketDirectory }) => {
|
|
45
|
+
// Every package manager Nx could install `nx@latest` with records that it ran, and fails.
|
|
46
|
+
const fakes = join(root, 'package-managers');
|
|
47
|
+
const marker = join(root, 'package-manager-ran');
|
|
48
|
+
await mkdir(fakes);
|
|
49
|
+
for (const name of PACKAGE_MANAGERS) {
|
|
50
|
+
await writeFile(join(fakes, name), `#!/bin/sh\necho "${name} $*" >> '${marker}'\nexit 1\n`);
|
|
51
|
+
await chmod(join(fakes, name), 0o755);
|
|
52
|
+
}
|
|
53
|
+
await mkdir(join(root, 'home'));
|
|
54
|
+
await mkdir(join(workspace, 'app'));
|
|
55
|
+
await symlink(join(repositoryRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
56
|
+
await writeFile(join(workspace, '.gitignore'), 'node_modules\n.nx\nhome\npackage-managers\npackage-manager-ran\n');
|
|
57
|
+
await writeFile(join(workspace, 'package.json'), JSON.stringify({ name: 'nx-use-local-fixture', private: true }));
|
|
58
|
+
await writeFile(join(workspace, 'nx.json'), '{}\n');
|
|
59
|
+
await writeFile(
|
|
60
|
+
join(workspace, 'app/project.json'),
|
|
61
|
+
JSON.stringify({
|
|
62
|
+
name: 'app',
|
|
63
|
+
targets: { build: { executor: 'nx:run-commands', options: { command: 'true' } } },
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
const { NX_USE_LOCAL: _local, ...withoutLocal } = fixtureNxEnv(workspace, socketDirectory);
|
|
67
|
+
const env = {
|
|
68
|
+
...withoutLocal,
|
|
69
|
+
HOME: join(root, 'home'),
|
|
70
|
+
NX_DAEMON: 'true',
|
|
71
|
+
PATH: `${fakes}${delimiter}${process.env.PATH ?? ''}`,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const controls: string[] = [];
|
|
75
|
+
for (const name of PACKAGE_MANAGERS) {
|
|
76
|
+
await run(name, ['oracle-control'], workspace, env, 1);
|
|
77
|
+
controls.push(`${name} oracle-control`);
|
|
78
|
+
}
|
|
79
|
+
expect(await readFile(marker, 'utf8')).toBe(`${controls.join('\n')}\n`);
|
|
80
|
+
await unlink(marker);
|
|
81
|
+
|
|
82
|
+
// A library client (smoo, cowshed's task hashing, ensureBuilt) without the variable starts the daemon, which
|
|
83
|
+
// computes Nx Console's and the AI agents' status in the environment it started with.
|
|
84
|
+
const library = `
|
|
85
|
+
const client = require.resolve('nx/src/daemon/client/client.js', { paths: [${JSON.stringify(repositoryRoot)}] });
|
|
86
|
+
const { daemonClient } = require(client);
|
|
87
|
+
(async () => {
|
|
88
|
+
await daemonClient.getNxConsoleStatus();
|
|
89
|
+
await daemonClient.getConfigureAiAgentsStatus();
|
|
90
|
+
process.exit(0);
|
|
91
|
+
})().catch((error) => { console.error(error); process.exit(1); });
|
|
92
|
+
`;
|
|
93
|
+
await run('node', ['-e', library], workspace, env);
|
|
94
|
+
// The bare entry, as `node_modules/.bin/nx` runs it, asks the same daemon again at the end of a run.
|
|
95
|
+
await run('node', [join(repositoryRoot, 'node_modules/.bin/nx'), 'run', 'app:build'], workspace, env);
|
|
96
|
+
|
|
97
|
+
const log = await readFile(join(workspace, '.nx/workspace-data/d/daemon.log'), 'utf8');
|
|
98
|
+
// The daemon took the branch that pulled `nx@latest` from the registry; it now resolves the installed Nx.
|
|
99
|
+
expect(log).toContain('[NX-CONSOLE]: Console status check completed');
|
|
100
|
+
expect(log).not.toContain('[LATEST-NX]: Pulling');
|
|
101
|
+
await expect(readFile(marker, 'utf8')).rejects.toMatchObject({ code: 'ENOENT' });
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
4
|
import { getProjects, readJson, type Tree, updateJson } from 'nx/src/devkit-exports.js';
|
|
5
5
|
|
|
6
6
|
import { boundedTestScriptAlias } from './bounded-test-policy.js';
|
|
7
|
+
import { writeJsonFile } from './managed-files/managed-format.js';
|
|
7
8
|
import { isNonSourceDirectory } from './source-directories.js';
|
|
8
9
|
import {
|
|
9
10
|
BUILD_OUTPUT_DEPENDENCIES,
|
|
@@ -87,10 +88,6 @@ function readJsonObject(path: string): Record<string, unknown> | null {
|
|
|
87
88
|
return isRecord(parsed) ? parsed : null;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
function writeJsonObject(path: string, value: Record<string, unknown>): void {
|
|
91
|
-
writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
91
|
function listWorkspacePackageJsonPaths(root: string): string[] {
|
|
95
92
|
const rootPackagePath = join(root, 'package.json');
|
|
96
93
|
if (!existsSync(rootPackagePath)) {
|
|
@@ -1299,7 +1296,7 @@ export function applyPackageTargetPolicy(root: string, options: PackageTargetPol
|
|
|
1299
1296
|
packageChanged;
|
|
1300
1297
|
|
|
1301
1298
|
if (packageChanged) {
|
|
1302
|
-
|
|
1299
|
+
writeJsonFile(packageJsonPath, pkg);
|
|
1303
1300
|
changed = true;
|
|
1304
1301
|
}
|
|
1305
1302
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { existsSync, readFileSync
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import type { Tree } from 'nx/src/devkit-exports.js';
|
|
5
5
|
import { readJson, updateJson } from 'nx/src/devkit-exports.js';
|
|
6
6
|
|
|
7
|
+
import { writeJsonFile } from './managed-files/managed-format.js';
|
|
7
8
|
import type { NxPolicyIssue } from './workspace-config-policy.js';
|
|
8
9
|
|
|
9
10
|
export const SMOO_NX_VERSION_ACTIONS = '@smoothbricks/nx-plugin/version-actions';
|
|
@@ -229,7 +230,7 @@ export function applyReleaseConfigPolicy(root: string): boolean {
|
|
|
229
230
|
}
|
|
230
231
|
const changed = applyReleaseConfig(nxJson);
|
|
231
232
|
if (changed) {
|
|
232
|
-
|
|
233
|
+
writeJsonFile(nxJsonPath, nxJson);
|
|
233
234
|
}
|
|
234
235
|
return changed;
|
|
235
236
|
}
|
|
@@ -246,10 +247,6 @@ function readJsonObject(path: string): Record<string, unknown> | null {
|
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
249
|
|
|
249
|
-
function writeJsonObject(path: string, value: Record<string, unknown>): void {
|
|
250
|
-
writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
250
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
254
251
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
255
252
|
}
|