@smoothbricks/nx-plugin 0.4.26 → 0.4.28
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 +994 -117
- 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 +15 -73
- 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 +3 -2
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +16 -15
- 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 +43 -6
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +309 -73
- 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 +101 -5
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +291 -10
- 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 +207 -12
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +576 -202
- 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 +370 -138
- 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.d.ts.map +1 -1
- package/dist/manifest-hash.js +2 -5
- 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 -0
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/executors.json +5 -0
- package/loader.js +13 -11
- package/managed/raw/envrc +33 -67
- 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 +569 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
- 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 +1146 -159
- 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 -41
- package/package.json +74 -12
- package/runtime-input.sh +81 -0
- package/src/__tests__/counted-cargo.ts +33 -14
- package/src/__tests__/fixture-nx-env.ts +111 -46
- 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 +16 -74
- 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 -21
- 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 +138 -66
- package/src/cargo-closure-input.ts +17 -15
- package/src/cargo-dev-profile.ts +137 -0
- package/src/cargo-resolve-cache.test.ts +70 -1
- package/src/cargo-source-hash.test.ts +193 -97
- package/src/cargo-source-hash.ts +345 -68
- package/src/cargo-toolchain-policy.ts +6 -0
- package/src/cargo-workspace.test.ts +320 -0
- package/src/cargo-workspace.ts +336 -10
- 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 +1036 -578
- package/src/ensure-built.ts +820 -224
- 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 +909 -295
- package/src/index.ts +441 -143
- package/src/linked-snapshots.nx.test.ts +172 -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 +2 -6
- 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 +427 -82
- package/src/nx-cache-bound.test.ts +5 -10
- 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 +7 -16
- 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 +26 -25
- 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 +87 -89
- 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 -0
- package/test-timings.json +85 -30
- package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
- package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { existsSync, lstatSync } from 'node:fs';
|
|
3
|
+
import { mkdir, mkdtemp, readdir, readFile, readlink, realpath, rm, symlink, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { createConnection, createServer } from 'node:net';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { fixtureNxEnv, nxFixtureRoot, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
8
|
+
import {
|
|
9
|
+
awaitExit,
|
|
10
|
+
fixtureSocketDirectory,
|
|
11
|
+
isRunning,
|
|
12
|
+
NX_LONGEST_SOCKET_NAME,
|
|
13
|
+
nxDaemonProcesses,
|
|
14
|
+
ownedFixtureRoot,
|
|
15
|
+
ownedWorkspaceSocketDirectory,
|
|
16
|
+
type ProcessEntry,
|
|
17
|
+
pidsWorkingIn,
|
|
18
|
+
processTable,
|
|
19
|
+
publishFixtureSocketDirectory,
|
|
20
|
+
retireFixtureSocketDirectory,
|
|
21
|
+
socketNamespace,
|
|
22
|
+
stopNxDaemon,
|
|
23
|
+
terminate,
|
|
24
|
+
withDescendants,
|
|
25
|
+
} from './testing.js';
|
|
26
|
+
|
|
27
|
+
const repositoryRoot = join(import.meta.dir, '../../..');
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Make `workspace` an Nx workspace and start its daemon. The daemon and every
|
|
31
|
+
* process it started, once `nx daemon --start` has returned with it up.
|
|
32
|
+
*/
|
|
33
|
+
async function startDaemon(
|
|
34
|
+
workspace: string,
|
|
35
|
+
socketDirectory: string,
|
|
36
|
+
environment: Record<string, string> = {},
|
|
37
|
+
): Promise<ProcessEntry[]> {
|
|
38
|
+
await mkdir(workspace, { recursive: true });
|
|
39
|
+
await writeFile(join(workspace, 'package.json'), '{"name":"daemon-fixture","private":true}\n');
|
|
40
|
+
await writeFile(join(workspace, '.gitignore'), 'node_modules\n.nx\n');
|
|
41
|
+
await writeFile(join(workspace, 'nx.json'), '{}\n');
|
|
42
|
+
await symlink(join(repositoryRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
43
|
+
expect(Bun.spawnSync(['git', 'init', '--quiet', workspace]).exitCode).toBe(0);
|
|
44
|
+
const child = Bun.spawn(['bun', join(repositoryRoot, 'node_modules/.bin/nx'), 'daemon', '--start'], {
|
|
45
|
+
cwd: workspace,
|
|
46
|
+
env: { ...fixtureNxEnv(workspace, socketDirectory), NX_DAEMON: 'true', ...environment },
|
|
47
|
+
stdout: 'pipe',
|
|
48
|
+
stderr: 'pipe',
|
|
49
|
+
});
|
|
50
|
+
const [code, stdout, stderr] = await Promise.all([
|
|
51
|
+
child.exited,
|
|
52
|
+
new Response(child.stdout).text(),
|
|
53
|
+
new Response(child.stderr).text(),
|
|
54
|
+
]);
|
|
55
|
+
expect(code, stdout + stderr).toBe(0);
|
|
56
|
+
const daemon = await nxDaemonProcesses(workspace);
|
|
57
|
+
expect(daemon, stdout + stderr).not.toEqual([]);
|
|
58
|
+
return daemon;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Which of `processes` still run, zombies (already exited) aside. */
|
|
62
|
+
async function stillRunning(processes: readonly ProcessEntry[]): Promise<string[]> {
|
|
63
|
+
const live = (await processTable()).filter((entry) => !entry.stat.startsWith('Z')).map((entry) => entry.pid);
|
|
64
|
+
return processes.filter((entry) => live.includes(entry.pid)).map((entry) => `${entry.pid} ${entry.command}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
it('lists a process once when it descends from another of the pids it is asked about', () => {
|
|
68
|
+
const table: ProcessEntry[] = [
|
|
69
|
+
{ pid: 1, ppid: 0, stat: 'Ss', command: 'launchd' },
|
|
70
|
+
{ pid: 10, ppid: 1, stat: 'Ss', command: 'sh -c sleep 600 & wait' },
|
|
71
|
+
{ pid: 11, ppid: 10, stat: 'S', command: 'sleep 600' },
|
|
72
|
+
{ pid: 12, ppid: 11, stat: 'S', command: 'sleep 1' },
|
|
73
|
+
{ pid: 20, ppid: 1, stat: 'S', command: 'bystander' },
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
expect(
|
|
77
|
+
withDescendants(table, [11, 10])
|
|
78
|
+
.map((entry) => entry.pid)
|
|
79
|
+
.sort((a, b) => a - b),
|
|
80
|
+
).toEqual([10, 11, 12]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('finds its Darwin working-directory holder without system sbin on PATH', async () => {
|
|
84
|
+
if (process.platform !== 'darwin') return;
|
|
85
|
+
const root = await realpath(await mkdtemp(join(tmpdir(), 'cwd-restricted-path-')));
|
|
86
|
+
try {
|
|
87
|
+
const child = Bun.spawn(
|
|
88
|
+
[
|
|
89
|
+
process.execPath,
|
|
90
|
+
'-e',
|
|
91
|
+
`import { pidsWorkingIn } from ${JSON.stringify(join(import.meta.dir, 'testing.ts'))};
|
|
92
|
+
console.log(JSON.stringify(await pidsWorkingIn(process.cwd())));`,
|
|
93
|
+
],
|
|
94
|
+
{ cwd: root, env: { ...process.env, PATH: '/usr/bin:/bin' }, stdout: 'pipe', stderr: 'pipe' },
|
|
95
|
+
);
|
|
96
|
+
const [code, stdout, stderr] = await Promise.all([
|
|
97
|
+
child.exited,
|
|
98
|
+
new Response(child.stdout).text(),
|
|
99
|
+
new Response(child.stderr).text(),
|
|
100
|
+
]);
|
|
101
|
+
expect(code, stderr).toBe(0);
|
|
102
|
+
expect(JSON.parse(stdout)).toContain(child.pid);
|
|
103
|
+
} finally {
|
|
104
|
+
await rm(root, { recursive: true });
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('stops the Nx daemon of a fixture whose body throws, and deletes its socket alias and root', async () => {
|
|
109
|
+
let root = '';
|
|
110
|
+
let alias = '';
|
|
111
|
+
let daemon: ProcessEntry[] = [];
|
|
112
|
+
const thrown = withNxFixture('throwing-body-', async (fixture) => {
|
|
113
|
+
root = fixture.root;
|
|
114
|
+
alias = dirname(fixture.socketDirectory);
|
|
115
|
+
expect(lstatSync(alias).isSymbolicLink()).toBe(true);
|
|
116
|
+
daemon = await startDaemon(fixture.workspace, fixture.socketDirectory);
|
|
117
|
+
throw new Error('the fixture body failed on purpose');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
await expect(thrown).rejects.toThrow('the fixture body failed on purpose');
|
|
121
|
+
expect(daemon).not.toEqual([]);
|
|
122
|
+
expect(await stillRunning(daemon)).toEqual([]);
|
|
123
|
+
expect(await pidsWorkingIn(root)).toEqual([]);
|
|
124
|
+
expect(existsSync(root)).toBe(false);
|
|
125
|
+
expect(lstatSync(alias, { throwIfNoEntry: false })).toBeUndefined();
|
|
126
|
+
}, 120_000);
|
|
127
|
+
|
|
128
|
+
it('ends owned Nx processes before daemon publication and after daemon exit', async () => {
|
|
129
|
+
let root = '';
|
|
130
|
+
await withNxFixture('daemon-orphan-', async (fixture) => {
|
|
131
|
+
root = fixture.root;
|
|
132
|
+
const { workspace } = fixture;
|
|
133
|
+
const record = join(workspace, '.nx', 'workspace-data', 'd', 'server-process.json');
|
|
134
|
+
for (const recorded of [false, true]) {
|
|
135
|
+
const phase = recorded ? 'recorded' : 'unrecorded';
|
|
136
|
+
const pidFile = join(workspace, `${phase}-orphan.pid`);
|
|
137
|
+
const workerFile = join(workspace, `${phase}-worker.pid`);
|
|
138
|
+
// The daemon's last act starts an orphan, so each cleanup path must rescan its owned cwd.
|
|
139
|
+
const daemon = Bun.spawn(
|
|
140
|
+
[
|
|
141
|
+
'sh',
|
|
142
|
+
'-c',
|
|
143
|
+
`trap 'sleep 60 & echo $! > "$1"; exit 0' TERM; sleep 3600 & echo $! > "$2"; echo ready; wait`,
|
|
144
|
+
'sh',
|
|
145
|
+
pidFile,
|
|
146
|
+
workerFile,
|
|
147
|
+
],
|
|
148
|
+
{ cwd: workspace, stdout: 'pipe', stderr: 'ignore' },
|
|
149
|
+
);
|
|
150
|
+
try {
|
|
151
|
+
const reader = daemon.stdout.getReader();
|
|
152
|
+
const decoder = new TextDecoder();
|
|
153
|
+
let output = '';
|
|
154
|
+
while (!output.includes('ready\n')) {
|
|
155
|
+
const next = await reader.read();
|
|
156
|
+
if (next.done) {
|
|
157
|
+
throw new Error(`stand-in daemon exited before it was ready: ${output}`);
|
|
158
|
+
}
|
|
159
|
+
output += decoder.decode(next.value);
|
|
160
|
+
}
|
|
161
|
+
reader.releaseLock();
|
|
162
|
+
if (recorded) {
|
|
163
|
+
await mkdir(dirname(record), { recursive: true });
|
|
164
|
+
await writeFile(record, JSON.stringify({ processId: daemon.pid }));
|
|
165
|
+
} else {
|
|
166
|
+
expect(existsSync(record)).toBe(false);
|
|
167
|
+
}
|
|
168
|
+
let stopCalls = 0;
|
|
169
|
+
await stopNxDaemon(workspace, async () => {
|
|
170
|
+
stopCalls += 1;
|
|
171
|
+
terminate(daemon.pid);
|
|
172
|
+
await daemon.exited;
|
|
173
|
+
});
|
|
174
|
+
expect(stopCalls).toBe(recorded ? 1 : 0);
|
|
175
|
+
expect(await pidsWorkingIn(workspace)).toEqual([]);
|
|
176
|
+
const orphan = Number(await readFile(pidFile, 'utf8'));
|
|
177
|
+
expect(orphan).toBeGreaterThan(0);
|
|
178
|
+
// A zombie has exited already; a signal probe would still count it as running.
|
|
179
|
+
expect((await processTable()).filter((entry) => entry.pid === orphan && !entry.stat.startsWith('Z'))).toEqual(
|
|
180
|
+
[],
|
|
181
|
+
);
|
|
182
|
+
} finally {
|
|
183
|
+
// Assert before retiring this probe, but release every real child on a failed oracle too.
|
|
184
|
+
terminate(daemon.pid);
|
|
185
|
+
await daemon.exited;
|
|
186
|
+
const owned = [];
|
|
187
|
+
for (const file of [workerFile, pidFile]) {
|
|
188
|
+
const pid = existsSync(file) ? Number(await readFile(file, 'utf8')) : 0;
|
|
189
|
+
if (pid > 0) {
|
|
190
|
+
owned.push(pid);
|
|
191
|
+
terminate(pid);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
await awaitExit(withDescendants(await processTable(), owned), `orphan probe of ${workspace}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
expect(await pidsWorkingIn(root)).toEqual([]);
|
|
199
|
+
}, 120_000);
|
|
200
|
+
|
|
201
|
+
it('binds and connects through its short alias without granting the long fixture root a socket namespace', async () => {
|
|
202
|
+
let alias = '';
|
|
203
|
+
await withNxFixture('short-socket-boundary-'.padEnd(100, 'x'), async ({ workspace, socketDirectory }) => {
|
|
204
|
+
alias = dirname(socketDirectory);
|
|
205
|
+
const socket = join(socketDirectory, NX_LONGEST_SOCKET_NAME);
|
|
206
|
+
// The physical leaf is too long for Nx to bind, so only the alias can make this pass.
|
|
207
|
+
expect(Buffer.byteLength(join(workspace, '.nx', 'sockets', 'nx', NX_LONGEST_SOCKET_NAME))).toBeGreaterThan(95);
|
|
208
|
+
expect(Buffer.byteLength(socket)).toBeLessThanOrEqual(95);
|
|
209
|
+
expect(lstatSync(alias).isSymbolicLink()).toBe(true);
|
|
210
|
+
expect(dirname(alias)).toBe(socketNamespace().directory);
|
|
211
|
+
await mkdir(socketDirectory);
|
|
212
|
+
expect(await realpath(socketDirectory)).toBe(join(workspace, '.nx', 'sockets', 'nx'));
|
|
213
|
+
const server = createServer((client) => client.end('owned-socket-ok'));
|
|
214
|
+
try {
|
|
215
|
+
await new Promise<void>((resolve, reject) => {
|
|
216
|
+
server.once('error', reject);
|
|
217
|
+
server.listen(socket, resolve);
|
|
218
|
+
});
|
|
219
|
+
const received = await new Promise<string>((resolve, reject) => {
|
|
220
|
+
const client = createConnection(socket);
|
|
221
|
+
let text = '';
|
|
222
|
+
client.on('data', (bytes) => {
|
|
223
|
+
text += bytes.toString();
|
|
224
|
+
});
|
|
225
|
+
client.once('error', reject);
|
|
226
|
+
client.once('end', () => resolve(text));
|
|
227
|
+
});
|
|
228
|
+
expect(received).toBe('owned-socket-ok');
|
|
229
|
+
} finally {
|
|
230
|
+
if (server.listening) {
|
|
231
|
+
await new Promise<void>((resolve, reject) => {
|
|
232
|
+
server.close((error) => (error === undefined ? resolve() : reject(error)));
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
// The fixture's retirement unlinked its alias.
|
|
238
|
+
expect(lstatSync(alias, { throwIfNoEntry: false })).toBeUndefined();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('publishes no alias for a workspace outside its own fixture run, or one named through a link', async () => {
|
|
242
|
+
const unowned = await realpath(await mkdtemp(join(tmpdir(), 'socket-unowned-')));
|
|
243
|
+
const root = await nxFixtureRoot('socket-linked-');
|
|
244
|
+
const linked = join(root, 'linked');
|
|
245
|
+
try {
|
|
246
|
+
await mkdir(join(root, 'real'));
|
|
247
|
+
await symlink(join(root, 'real'), linked, 'dir');
|
|
248
|
+
for (const workspace of [unowned, linked]) {
|
|
249
|
+
await expect(publishFixtureSocketDirectory(workspace)).rejects.toThrow(
|
|
250
|
+
'not a physical workspace in a fixture run this process owns',
|
|
251
|
+
);
|
|
252
|
+
expect(existsSync(join(workspace, '.nx'))).toBe(false);
|
|
253
|
+
expect(lstatSync(dirname(fixtureSocketDirectory(workspace)), { throwIfNoEntry: false })).toBeUndefined();
|
|
254
|
+
}
|
|
255
|
+
} finally {
|
|
256
|
+
await rm(unowned, { recursive: true });
|
|
257
|
+
await rm(root, { recursive: true });
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('refuses a symlinked socket-state ancestor before writing outside the fixture', async () => {
|
|
262
|
+
const root = await nxFixtureRoot('socket-escape-boundary-');
|
|
263
|
+
const foreign = await mkdtemp(join(tmpdir(), 'socket-foreign-boundary-'));
|
|
264
|
+
try {
|
|
265
|
+
await symlink(foreign, join(root, '.nx'), 'dir');
|
|
266
|
+
await expect(publishFixtureSocketDirectory(root)).rejects.toThrow(
|
|
267
|
+
'is not a real directory in its physical workspace',
|
|
268
|
+
);
|
|
269
|
+
expect(existsSync(join(foreign, 'sockets'))).toBe(false);
|
|
270
|
+
expect(lstatSync(dirname(fixtureSocketDirectory(root)), { throwIfNoEntry: false })).toBeUndefined();
|
|
271
|
+
} finally {
|
|
272
|
+
await rm(root, { recursive: true });
|
|
273
|
+
await rm(foreign, { recursive: true });
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('neither uses nor removes a retargeted alias or a colliding directory at its alias name', async () => {
|
|
278
|
+
const root = await nxFixtureRoot('socket-collision-');
|
|
279
|
+
const foreign = await realpath(await mkdtemp(join(tmpdir(), 'socket-collision-foreign-')));
|
|
280
|
+
const alias = dirname(fixtureSocketDirectory(root));
|
|
281
|
+
try {
|
|
282
|
+
await symlink(foreign, alias, 'dir');
|
|
283
|
+
await expect(publishFixtureSocketDirectory(root)).rejects.toThrow('does not name its owned target');
|
|
284
|
+
await expect(retireFixtureSocketDirectory(root)).rejects.toThrow('does not name its owned target');
|
|
285
|
+
await expect(ownedWorkspaceSocketDirectory(root, 'a')).rejects.toThrow('does not name its owned target');
|
|
286
|
+
expect(await readlink(alias)).toBe(foreign);
|
|
287
|
+
expect(await readdir(foreign)).toEqual([]);
|
|
288
|
+
await rm(alias);
|
|
289
|
+
|
|
290
|
+
await mkdir(alias);
|
|
291
|
+
await writeFile(join(alias, 'kept'), 'kept\n');
|
|
292
|
+
await expect(publishFixtureSocketDirectory(root)).rejects.toThrow('does not name its owned target');
|
|
293
|
+
await expect(retireFixtureSocketDirectory(root)).rejects.toThrow('does not name its owned target');
|
|
294
|
+
expect(lstatSync(alias).isDirectory()).toBe(true);
|
|
295
|
+
expect(await readFile(join(alias, 'kept'), 'utf8')).toBe('kept\n');
|
|
296
|
+
} finally {
|
|
297
|
+
await rm(alias, { recursive: true, force: true });
|
|
298
|
+
await rm(root, { recursive: true });
|
|
299
|
+
await rm(foreign, { recursive: true });
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('refuses a socket namespace too long for Nx before publishing anything', async () => {
|
|
304
|
+
const root = await nxFixtureRoot('socket-length-');
|
|
305
|
+
const namespace = join(root, 'namespace-'.padEnd(80, 'x'));
|
|
306
|
+
await mkdir(namespace);
|
|
307
|
+
const outer = Object.fromEntries(
|
|
308
|
+
['NX_SOCKET_DIR', 'COWSHED_RUNTIME_LINK', 'TMPDIR'].map((name) => [name, process.env[name]]),
|
|
309
|
+
);
|
|
310
|
+
// Only the temp directory is left to fall back to, and it is too long.
|
|
311
|
+
delete process.env.NX_SOCKET_DIR;
|
|
312
|
+
delete process.env.COWSHED_RUNTIME_LINK;
|
|
313
|
+
process.env.TMPDIR = namespace;
|
|
314
|
+
try {
|
|
315
|
+
expect(socketNamespace().directory).toBe(namespace);
|
|
316
|
+
await expect(publishFixtureSocketDirectory(root)).rejects.toThrow('over the 95 a Unix socket may have');
|
|
317
|
+
expect(existsSync(join(root, '.nx'))).toBe(false);
|
|
318
|
+
expect(await readdir(namespace)).toEqual([]);
|
|
319
|
+
} finally {
|
|
320
|
+
for (const [name, value] of Object.entries(outer)) {
|
|
321
|
+
if (value === undefined) delete process.env[name];
|
|
322
|
+
else process.env[name] = value;
|
|
323
|
+
}
|
|
324
|
+
await rm(root, { recursive: true });
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('starts and connects to a fixture daemon through owned short aliases with a long private TMPDIR', async () => {
|
|
329
|
+
await withNxFixture('long-tmp-socket-', async ({ workspace, socketDirectory }) => {
|
|
330
|
+
const privateTemp = join(workspace, 'private-temp-'.padEnd(110, 'x'));
|
|
331
|
+
await mkdir(privateTemp);
|
|
332
|
+
expect(Buffer.byteLength(join(privateTemp, NX_LONGEST_SOCKET_NAME))).toBeGreaterThan(95);
|
|
333
|
+
const daemon = await startDaemon(workspace, socketDirectory, { TMPDIR: privateTemp });
|
|
334
|
+
const alias = dirname(socketDirectory);
|
|
335
|
+
expect(lstatSync(alias).isSymbolicLink()).toBe(true);
|
|
336
|
+
expect(lstatSync(socketDirectory).isDirectory()).toBe(true);
|
|
337
|
+
expect(lstatSync(socketDirectory).isSymbolicLink()).toBe(false);
|
|
338
|
+
expect(await realpath(socketDirectory)).toBe(join(workspace, '.nx', 'sockets', 'nx'));
|
|
339
|
+
expect(Buffer.byteLength(join(socketDirectory, NX_LONGEST_SOCKET_NAME))).toBeLessThanOrEqual(95);
|
|
340
|
+
const slot = await ownedWorkspaceSocketDirectory(workspace, 'a');
|
|
341
|
+
expect(slot).toBe(join(alias, 'a'));
|
|
342
|
+
expect(await realpath(slot)).toBe(join(workspace, '.nx', 'sockets', 'a'));
|
|
343
|
+
expect(lstatSync(slot).isSymbolicLink()).toBe(false);
|
|
344
|
+
expect(Buffer.byteLength(join(slot, NX_LONGEST_SOCKET_NAME))).toBeLessThanOrEqual(95);
|
|
345
|
+
await expect(ownedWorkspaceSocketDirectory(workspace, 'a')).rejects.toThrow('EEXIST');
|
|
346
|
+
await rm(slot, { recursive: true });
|
|
347
|
+
const client = Bun.spawn(['bun', join(repositoryRoot, 'node_modules/.bin/nx'), 'show', 'projects', '--json'], {
|
|
348
|
+
cwd: workspace,
|
|
349
|
+
env: { ...fixtureNxEnv(workspace, socketDirectory), NX_DAEMON: 'true', TMPDIR: privateTemp },
|
|
350
|
+
stdout: 'pipe',
|
|
351
|
+
stderr: 'pipe',
|
|
352
|
+
});
|
|
353
|
+
const [code, stdout, stderr] = await Promise.all([
|
|
354
|
+
client.exited,
|
|
355
|
+
new Response(client.stdout).text(),
|
|
356
|
+
new Response(client.stderr).text(),
|
|
357
|
+
]);
|
|
358
|
+
expect(code, stdout + stderr).toBe(0);
|
|
359
|
+
expect(JSON.parse(stdout)).toEqual([]);
|
|
360
|
+
const record = JSON.parse(
|
|
361
|
+
await readFile(join(workspace, '.nx', 'workspace-data', 'd', 'server-process.json'), 'utf8'),
|
|
362
|
+
);
|
|
363
|
+
expect(daemon.some(({ pid }) => pid === record.processId)).toBe(true);
|
|
364
|
+
expect(await stillRunning(daemon)).not.toEqual([]);
|
|
365
|
+
});
|
|
366
|
+
}, 120_000);
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* The alias a killed fixture leaves: what {@link publishFixtureSocketDirectory} makes, planted for a workspace in
|
|
370
|
+
* another process's run, which this process may not publish for. `workspace` itself is not made.
|
|
371
|
+
*/
|
|
372
|
+
async function plantSocketAlias(workspace: string): Promise<string> {
|
|
373
|
+
const directory = fixtureSocketDirectory(workspace);
|
|
374
|
+
await symlink(join(workspace, '.nx', 'sockets'), dirname(directory), 'dir');
|
|
375
|
+
return directory;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
it("reclaims a dead run's Nx daemon, helper processes and socket aliases, and nothing of a live run", async () => {
|
|
379
|
+
// A suite of its own, so this process's first fixture of it is the one that sweeps.
|
|
380
|
+
const suite = `sweep-regression-${process.pid}`;
|
|
381
|
+
const suiteDirectory = join(await realpath(tmpdir()), 'smoothbricks-fixtures', suite);
|
|
382
|
+
// A pid that names no process: one this test started and saw exit.
|
|
383
|
+
const exited = Bun.spawn(['true']);
|
|
384
|
+
await exited.exited;
|
|
385
|
+
const deadRun = join(suiteDirectory, `run-${exited.pid}`);
|
|
386
|
+
// A run whose owner is alive: the process that started this test.
|
|
387
|
+
const liveRun = join(suiteDirectory, `run-${process.ppid}`);
|
|
388
|
+
const abandoned = join(deadRun, 'abandoned-fixture');
|
|
389
|
+
const kept = join(liveRun, 'live-fixture');
|
|
390
|
+
// A fixture of the dead run whose workspace is already gone: only its alias is left.
|
|
391
|
+
const vanished = join(deadRun, 'vanished-fixture');
|
|
392
|
+
await mkdir(join(kept, '.nx', 'sockets'), { recursive: true });
|
|
393
|
+
await mkdir(join(abandoned, '.nx', 'sockets'), { recursive: true });
|
|
394
|
+
const abandonedDirectory = await plantSocketAlias(abandoned);
|
|
395
|
+
const abandonedAlias = dirname(abandonedDirectory);
|
|
396
|
+
const keptAlias = dirname(await plantSocketAlias(kept));
|
|
397
|
+
const vanishedAlias = dirname(await plantSocketAlias(vanished));
|
|
398
|
+
// When the sweep signals the dead run's processes, it has not yet touched the run's aliases.
|
|
399
|
+
const aliasAtSignal = join(suiteDirectory, 'alias-at-signal');
|
|
400
|
+
const witness = Bun.spawn(
|
|
401
|
+
[
|
|
402
|
+
'sh',
|
|
403
|
+
'-c',
|
|
404
|
+
`trap 'if [ -L "$0" ]; then echo present; else echo gone; fi > "$1"; exit 0' TERM; while :; do sleep 1; done`,
|
|
405
|
+
abandonedAlias,
|
|
406
|
+
aliasAtSignal,
|
|
407
|
+
],
|
|
408
|
+
{ cwd: abandoned },
|
|
409
|
+
);
|
|
410
|
+
let daemon: ProcessEntry[] = [];
|
|
411
|
+
const helper = Bun.spawn(['sleep', '600'], { cwd: abandoned });
|
|
412
|
+
const bystander = Bun.spawn(['sleep', '600'], { cwd: kept });
|
|
413
|
+
try {
|
|
414
|
+
// A real daemon, as a killed test leaves it, beside a stand-in for the
|
|
415
|
+
// helper processes (watchers, clients) that work in the same root.
|
|
416
|
+
daemon = await startDaemon(abandoned, abandonedDirectory);
|
|
417
|
+
|
|
418
|
+
const fresh = await ownedFixtureRoot(tmpdir(), suite, 'fresh-');
|
|
419
|
+
|
|
420
|
+
expect(await stillRunning(daemon)).toEqual([]);
|
|
421
|
+
expect(await helper.exited).not.toBe(0);
|
|
422
|
+
expect(helper.signalCode).toBe('SIGTERM');
|
|
423
|
+
expect(await witness.exited).toBe(0);
|
|
424
|
+
expect(await readFile(aliasAtSignal, 'utf8')).toBe('present\n');
|
|
425
|
+
expect(existsSync(deadRun)).toBe(false);
|
|
426
|
+
expect(lstatSync(abandonedAlias, { throwIfNoEntry: false })).toBeUndefined();
|
|
427
|
+
expect(lstatSync(vanishedAlias, { throwIfNoEntry: false })).toBeUndefined();
|
|
428
|
+
expect(bystander.exitCode).toBeNull();
|
|
429
|
+
expect(bystander.signalCode).toBeNull();
|
|
430
|
+
expect(existsSync(kept)).toBe(true);
|
|
431
|
+
expect(lstatSync(keptAlias).isSymbolicLink()).toBe(true);
|
|
432
|
+
expect(await realpath(keptAlias)).toBe(join(await realpath(kept), '.nx', 'sockets'));
|
|
433
|
+
expect(fresh.startsWith(join(suiteDirectory, `run-${process.pid}`, 'fresh-'))).toBe(true);
|
|
434
|
+
} finally {
|
|
435
|
+
for (const entry of [...daemon, { pid: helper.pid }, { pid: bystander.pid }, { pid: witness.pid }]) {
|
|
436
|
+
terminate(entry.pid);
|
|
437
|
+
}
|
|
438
|
+
await Promise.all([helper.exited, bystander.exited, witness.exited]);
|
|
439
|
+
for (const workspace of [abandoned, kept, vanished]) {
|
|
440
|
+
await retireFixtureSocketDirectory(workspace);
|
|
441
|
+
}
|
|
442
|
+
await rm(suiteDirectory, { recursive: true, force: true });
|
|
443
|
+
}
|
|
444
|
+
}, 120_000);
|
|
445
|
+
|
|
446
|
+
it('stops what works in every run it owns when the process is signalled, then dies of the signal', async () => {
|
|
447
|
+
const suite = `signal-regression-${process.pid}`;
|
|
448
|
+
const suiteDirectory = join(await realpath(tmpdir()), 'smoothbricks-fixtures', suite);
|
|
449
|
+
// A second parent for the same suite: the owner holds a run in each, and one signal has to reclaim both.
|
|
450
|
+
const otherParent = await mkdtemp(join(await realpath(tmpdir()), 'signal-regression-parent-'));
|
|
451
|
+
const otherSuiteDirectory = join(otherParent, 'smoothbricks-fixtures', suite);
|
|
452
|
+
const script = join(suiteDirectory, 'owner.ts');
|
|
453
|
+
await mkdir(suiteDirectory, { recursive: true });
|
|
454
|
+
// A detached stand-in for a fixture daemon in each run: its own session, so only the
|
|
455
|
+
// owner's handler, not a process-group signal, can stop it. The interval
|
|
456
|
+
// keeps the owner alive until it is signalled.
|
|
457
|
+
await writeFile(
|
|
458
|
+
script,
|
|
459
|
+
`import { spawn } from 'node:child_process';
|
|
460
|
+
import { tmpdir } from 'node:os';
|
|
461
|
+
import { ownedFixtureRoot } from ${JSON.stringify(join(import.meta.dir, 'testing.ts'))};
|
|
462
|
+
const helpers = [];
|
|
463
|
+
for (const parent of [tmpdir(), ${JSON.stringify(otherParent)}]) {
|
|
464
|
+
const root = await ownedFixtureRoot(parent, ${JSON.stringify(suite)}, 'signalled-');
|
|
465
|
+
const helper = spawn('sleep', ['600'], { cwd: root, detached: true, stdio: 'ignore' });
|
|
466
|
+
helper.unref();
|
|
467
|
+
helpers.push(helper.pid);
|
|
468
|
+
}
|
|
469
|
+
console.log('READY ' + helpers.join(' '));
|
|
470
|
+
setInterval(() => {}, 1 << 30);
|
|
471
|
+
`,
|
|
472
|
+
);
|
|
473
|
+
const owner = Bun.spawn([process.execPath, script], { stdout: 'pipe', stderr: 'pipe' });
|
|
474
|
+
let helpers: number[] = [];
|
|
475
|
+
try {
|
|
476
|
+
const reader = owner.stdout.getReader();
|
|
477
|
+
const decoder = new TextDecoder();
|
|
478
|
+
let printed = '';
|
|
479
|
+
while (helpers.length === 0) {
|
|
480
|
+
const chunk = await reader.read();
|
|
481
|
+
if (chunk.done) throw new Error(`the owner exited before it was ready: ${printed}`);
|
|
482
|
+
printed += decoder.decode(chunk.value, { stream: true });
|
|
483
|
+
helpers = /^READY (\d+) (\d+)$/m.exec(printed)?.slice(1).map(Number) ?? [];
|
|
484
|
+
}
|
|
485
|
+
for (const helper of helpers) {
|
|
486
|
+
expect(isRunning(helper)).toBe(true);
|
|
487
|
+
}
|
|
488
|
+
// One run for each parent, though both name one suite.
|
|
489
|
+
const runs = [suiteDirectory, otherSuiteDirectory].map((directory) => join(directory, `run-${owner.pid}`));
|
|
490
|
+
for (const run of runs) {
|
|
491
|
+
expect(existsSync(run), run).toBe(true);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
owner.kill('SIGTERM');
|
|
495
|
+
await owner.exited;
|
|
496
|
+
|
|
497
|
+
expect(owner.signalCode, await new Response(owner.stderr).text()).toBe('SIGTERM');
|
|
498
|
+
expect(await stillRunning(helpers.map((pid) => ({ pid, ppid: 0, stat: '', command: 'sleep 600' })))).toEqual([]);
|
|
499
|
+
for (const run of runs) {
|
|
500
|
+
expect(existsSync(run), run).toBe(false);
|
|
501
|
+
}
|
|
502
|
+
} finally {
|
|
503
|
+
for (const helper of helpers) terminate(helper);
|
|
504
|
+
owner.kill('SIGKILL');
|
|
505
|
+
await owner.exited;
|
|
506
|
+
await rm(suiteDirectory, { recursive: true, force: true });
|
|
507
|
+
await rm(otherParent, { recursive: true, force: true });
|
|
508
|
+
}
|
|
509
|
+
}, 120_000);
|