@smoothbricks/nx-plugin 0.5.7 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1097 -360
- package/dist/.build-inputs.json +141 -0
- package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
- package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
- package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
- package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
- package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
- package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
- package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
- package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
- package/dist/bin/smoo-nx-nextest-timings.js +28 -0
- package/dist/bounded-test-policy.d.ts +1 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +14 -15
- package/dist/build-state-output-policy.d.ts +95 -1
- package/dist/build-state-output-policy.d.ts.map +1 -1
- package/dist/build-state-output-policy.js +368 -30
- package/dist/bun-lock-scope.d.ts +44 -0
- package/dist/bun-lock-scope.d.ts.map +1 -0
- package/dist/bun-lock-scope.js +97 -0
- package/dist/cargo-build-script-env.d.ts +49 -0
- package/dist/cargo-build-script-env.d.ts.map +1 -0
- package/dist/cargo-build-script-env.js +324 -0
- package/dist/cargo-closure-input.d.ts +31 -4
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +66 -6
- package/dist/cargo-retention-hook.d.ts +17 -0
- package/dist/cargo-retention-hook.d.ts.map +1 -0
- package/dist/cargo-retention-hook.js +85 -0
- package/dist/cargo-source-hash.d.ts +25 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +108 -43
- package/dist/cargo-toolchain-paths.d.ts +40 -0
- package/dist/cargo-toolchain-paths.d.ts.map +1 -0
- package/dist/cargo-toolchain-paths.js +84 -0
- package/dist/cargo-toolchain-policy.d.ts +25 -8
- package/dist/cargo-toolchain-policy.d.ts.map +1 -1
- package/dist/cargo-toolchain-policy.js +39 -5
- package/dist/cargo-workspace.d.ts +10 -4
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +65 -95
- package/dist/cross-check-policy.d.ts +9 -9
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +11 -11
- package/dist/disk-command-policy.d.ts.map +1 -1
- package/dist/disk-command-policy.js +1 -0
- package/dist/ensure-built-receipt.d.ts +22 -5
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +168 -48
- package/dist/ensure-built-witness.d.ts +27 -8
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +45 -15
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +9 -1
- package/dist/eslint-config-closure.d.ts +7 -0
- package/dist/eslint-config-closure.d.ts.map +1 -0
- package/dist/eslint-config-closure.js +346 -0
- package/dist/executors/bounded-exec/bounds.d.ts +56 -0
- package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
- package/dist/executors/bounded-exec/bounds.js +43 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +28 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.js +20 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +35 -38
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +56 -120
- package/dist/executors/bounded-exec/executor.d.ts +19 -12
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +389 -239
- package/dist/executors/bounded-exec/gateway-lease.d.ts +23 -19
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
- package/dist/executors/bounded-exec/gateway-lease.js +102 -29
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
- package/dist/executors/bounded-exec/lease-wait.d.ts +64 -0
- package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
- package/dist/executors/bounded-exec/lease-wait.js +72 -0
- package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
- package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
- package/dist/executors/bounded-exec/lock-wait.js +108 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts +31 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/mbx-pool.js +24 -0
- package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
- package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
- package/dist/executors/bounded-exec/owned-subtree.js +178 -0
- package/dist/executors/bounded-exec/progress.d.ts +4 -1
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/progress.js +5 -2
- package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
- package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-attach.js +207 -0
- package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
- package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-detach.js +207 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +1213 -399
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts +10 -4
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +122 -35
- package/dist/executors/bounded-exec/runner-hook.js +14 -5
- package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
- package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
- package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
- package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
- package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
- package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
- package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
- package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
- package/dist/executors/bounded-exec/runtime-pin.js +167 -0
- package/dist/executors/bounded-exec/schema.d.ts +18 -1
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.d.ts +48 -11
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +89 -20
- package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
- package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
- package/dist/executors/cargo-zigbuild/executor.js +67 -12
- package/dist/executors/clean-outputs/executor.js +1 -0
- package/dist/executors/scriptc-native/executor.d.ts +79 -0
- package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
- package/dist/executors/scriptc-native/executor.js +367 -0
- package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
- package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
- package/dist/executors/scriptc-native/ffi-paths.js +25 -0
- package/dist/executors/scriptc-native/schema.d.ts +34 -0
- package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
- package/dist/executors/scriptc-native/schema.js +1 -0
- package/dist/executors/typescript-emit/emit-overrides.d.ts +14 -0
- package/dist/executors/typescript-emit/emit-overrides.d.ts.map +1 -0
- package/dist/executors/typescript-emit/emit-overrides.js +24 -0
- package/dist/executors/typescript-emit/executor.d.ts +3 -1
- package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
- package/dist/executors/typescript-emit/executor.js +146 -33
- package/dist/forbidden-spelling-policy.d.ts +56 -0
- package/dist/forbidden-spelling-policy.d.ts.map +1 -0
- package/dist/forbidden-spelling-policy.js +176 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +3 -4
- package/dist/graph-input-contract.d.ts +14 -0
- package/dist/graph-input-contract.d.ts.map +1 -1
- package/dist/graph-input-contract.js +67 -2
- package/dist/index.d.ts +23 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +672 -214
- package/dist/managed-assets.d.ts +2 -0
- package/dist/managed-assets.d.ts.map +1 -1
- package/dist/managed-files/files.d.ts +3 -3
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +28 -3
- package/dist/managed-files/managed-format.d.ts.map +1 -1
- package/dist/managed-files/managed-format.js +1 -0
- package/dist/managed-files/publish-workflow.js +14 -11
- package/dist/nextest-code-bound.js +1 -0
- package/dist/nextest-timings.d.ts +35 -0
- package/dist/nextest-timings.d.ts.map +1 -0
- package/dist/nextest-timings.js +168 -0
- package/dist/owned-installation.d.ts +6 -5
- package/dist/owned-installation.d.ts.map +1 -1
- package/dist/owned-installation.js +150 -26
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +2 -3
- package/dist/process-children.d.ts +7 -0
- package/dist/process-children.d.ts.map +1 -0
- package/dist/process-children.darwin.d.ts +7 -0
- package/dist/process-children.darwin.d.ts.map +1 -0
- package/dist/process-children.darwin.js +13 -0
- package/dist/process-children.js +14 -0
- package/dist/process-children.linux.d.ts +8 -0
- package/dist/process-children.linux.d.ts.map +1 -0
- package/dist/process-children.linux.js +25 -0
- package/dist/process-group.d.ts +108 -0
- package/dist/process-group.d.ts.map +1 -0
- package/dist/process-group.js +171 -0
- package/dist/process-listing.d.ts +7 -0
- package/dist/process-listing.d.ts.map +1 -0
- package/dist/process-listing.js +51 -0
- package/dist/producer-receipts.d.ts +8 -2
- package/dist/producer-receipts.d.ts.map +1 -1
- package/dist/producer-receipts.js +514 -47
- package/dist/task-graph-policy.d.ts +21 -0
- package/dist/task-graph-policy.d.ts.map +1 -0
- package/dist/task-graph-policy.js +91 -0
- package/dist/test-timings.js +4 -4
- package/dist/test-walk-policy.d.ts +14 -5
- package/dist/test-walk-policy.d.ts.map +1 -1
- package/dist/test-walk-policy.js +8 -2
- package/dist/testing.d.ts +73 -28
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +217 -223
- package/dist/tool-bins.d.ts +33 -0
- package/dist/tool-bins.d.ts.map +1 -0
- package/dist/tool-bins.js +72 -0
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +3 -4
- package/dist/wait-why-policy.d.ts +28 -0
- package/dist/wait-why-policy.d.ts.map +1 -0
- package/dist/wait-why-policy.js +223 -0
- package/dist/workspace-config-policy.d.ts +14 -8
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +60 -16
- package/dist/workspace-manifest.d.ts +41 -6
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/dist/workspace-manifest.js +57 -0
- package/executors.json +16 -1
- package/loader.js +2 -0
- package/managed/raw/envrc +11 -0
- package/managed/raw/patches/nx@23.2.1.patch +2840 -199
- package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
- package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
- package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
- package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
- package/managed/raw/tooling/direnv/developer-links.ts +464 -25
- package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
- package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
- package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
- package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
- package/managed/raw/tooling/direnv/repo-path +68 -6
- package/managed/raw/tooling/direnv/secret-references.ts +13 -4
- package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
- package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
- package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
- package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
- package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
- package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
- package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
- package/package.json +95 -14
- package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
- package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
- package/src/bin/smoo-nx-nextest-timings.ts +31 -0
- package/src/bounded-test-policy.ts +12 -14
- package/src/build-state-output-policy.ts +458 -34
- package/src/bun-lock-scope.ts +108 -0
- package/src/cargo-build-script-env.ts +265 -0
- package/src/cargo-closure-input.ts +74 -7
- package/src/cargo-retention-hook.ts +94 -0
- package/src/cargo-source-hash.ts +138 -41
- package/src/cargo-toolchain-paths.ts +95 -0
- package/src/cargo-toolchain-policy.ts +49 -5
- package/src/cargo-workspace.ts +72 -123
- package/src/cross-check-policy.ts +12 -10
- package/src/disk-command-policy.ts +1 -0
- package/src/ensure-built-receipt.ts +173 -39
- package/src/ensure-built-witness.ts +62 -10
- package/src/ensure-built.ts +11 -1
- package/src/eslint-config-closure.ts +357 -0
- package/src/executors/bounded-exec/bounds.ts +76 -0
- package/src/executors/bounded-exec/cpu-pool-thread.ts +43 -0
- package/src/executors/bounded-exec/cpu-pool.ts +55 -120
- package/src/executors/bounded-exec/executor.ts +442 -260
- package/src/executors/bounded-exec/gateway-lease.ts +94 -35
- package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
- package/src/executors/bounded-exec/lease-wait.ts +116 -0
- package/src/executors/bounded-exec/lock-wait.ts +141 -0
- package/src/executors/bounded-exec/mbx-pool.ts +48 -0
- package/src/executors/bounded-exec/owned-subtree.ts +235 -0
- package/src/executors/bounded-exec/progress.ts +9 -3
- package/src/executors/bounded-exec/ram-attach.ts +238 -0
- package/src/executors/bounded-exec/ram-detach.ts +226 -0
- package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
- package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
- package/src/executors/bounded-exec/ram-temp.ts +1497 -460
- package/src/executors/bounded-exec/run-cpu-pool.ts +129 -35
- package/src/executors/bounded-exec/runner-hook.ts +14 -6
- package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
- package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
- package/src/executors/bounded-exec/runtime-pin.ts +232 -0
- package/src/executors/bounded-exec/schema.json +11 -2
- package/src/executors/bounded-exec/schema.ts +19 -1
- package/src/executors/bounded-exec/verdict.ts +145 -35
- package/src/executors/cargo-zigbuild/executor.ts +82 -8
- package/src/executors/clean-outputs/executor.ts +1 -0
- package/src/executors/scriptc-native/executor.ts +394 -0
- package/src/executors/scriptc-native/ffi-paths.ts +29 -0
- package/src/executors/scriptc-native/schema.json +60 -0
- package/src/executors/scriptc-native/schema.ts +34 -0
- package/src/executors/typescript-emit/emit-overrides.ts +24 -0
- package/src/executors/typescript-emit/executor.ts +186 -38
- package/src/forbidden-spelling-policy.ts +226 -0
- package/src/generators/create-package/generator.ts +7 -7
- package/src/graph-input-contract.ts +61 -2
- package/src/index.ts +788 -224
- package/src/managed-assets.ts +3 -0
- package/src/managed-files/files.ts +28 -3
- package/src/managed-files/managed-format.ts +1 -0
- package/src/managed-files/publish-workflow.ts +20 -15
- package/src/nextest-code-bound.ts +1 -0
- package/src/nextest-timings.ts +106 -0
- package/src/owned-installation.ts +150 -23
- package/src/package-target-policy.ts +2 -3
- package/src/process-children.darwin.ts +14 -0
- package/src/process-children.linux.ts +33 -0
- package/src/process-children.ts +22 -0
- package/src/process-group.ts +209 -0
- package/src/process-listing.ts +54 -0
- package/src/producer-receipts.ts +92 -41
- package/src/task-graph-policy.ts +98 -0
- package/src/test-walk-policy.ts +23 -8
- package/src/testing.ts +240 -232
- package/src/tool-bins.ts +108 -0
- package/src/typecheck-test-policy.ts +2 -3
- package/src/wait-why-policy.ts +226 -0
- package/src/workspace-config-policy.ts +63 -15
- package/src/workspace-manifest.ts +89 -6
- package/test-timings.json +124 -99
- package/dist/bin/smoo-nx-failures.d.ts +0 -3
- package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
- package/dist/bin/smoo-nx-failures.js +0 -3
- package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
- package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
- package/dist/bin/smoo-nx-nextest-extract.js +0 -42
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
- package/dist/failure-summary.d.ts +0 -5
- package/dist/failure-summary.d.ts.map +0 -1
- package/dist/failure-summary.js +0 -118
- package/dist/nextest-extraction.d.ts +0 -117
- package/dist/nextest-extraction.d.ts.map +0 -1
- package/dist/nextest-extraction.js +0 -303
- package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
- package/src/__tests__/cargo-closure-filesets.ts +0 -94
- package/src/__tests__/cargo-closure-fixture.ts +0 -113
- package/src/__tests__/counted-cargo-process.ts +0 -286
- package/src/__tests__/counted-cargo.ts +0 -713
- package/src/__tests__/directory-change.ts +0 -27
- package/src/__tests__/fixture-cargo-home.ts +0 -36
- package/src/__tests__/fixture-nx-env.ts +0 -193
- package/src/__tests__/owned-installation.ts +0 -13
- package/src/__tests__/past-tick.ts +0 -12
- package/src/__tests__/progress-clock.ts +0 -43
- package/src/__tests__/runtime-input.ts +0 -23
- package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
- package/src/bin/smoo-nx-failures.ts +0 -4
- package/src/bin/smoo-nx-nextest-extract.ts +0 -44
- package/src/bounded-test-policy.test.ts +0 -1029
- package/src/build-state-output-policy.test.ts +0 -115
- package/src/bun-bootstrap.test.ts +0 -102
- package/src/bun-file-packages.test.ts +0 -47
- package/src/cargo-closure-filesets.test.ts +0 -63
- package/src/cargo-closure-input.property.test.ts +0 -50
- package/src/cargo-closure-input.test.ts +0 -506
- package/src/cargo-closure-key.test.ts +0 -240
- package/src/cargo-resolve-cache.test.ts +0 -1181
- package/src/cargo-source-hash.test.ts +0 -707
- package/src/cargo-workspace.test.ts +0 -615
- package/src/cross-check-policy.test.ts +0 -316
- package/src/disk-command-policy.test.ts +0 -61
- package/src/ensure-built-receipt.test.ts +0 -279
- package/src/ensure-built-witness.test.ts +0 -688
- package/src/ensure-built.test.ts +0 -1462
- package/src/executors/all-verdicts/executor.test.ts +0 -135
- package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
- package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
- package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
- package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
- package/src/executors/bounded-exec/executor-host.test.ts +0 -800
- package/src/executors/bounded-exec/executor.test.ts +0 -1819
- package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
- package/src/executors/bounded-exec/progress.test.ts +0 -139
- package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
- package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
- package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
- package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
- package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
- package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
- package/src/executors/bounded-exec/verdict.test.ts +0 -545
- package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
- package/src/executors/clean-outputs/executor.test.ts +0 -20
- package/src/executors/typescript-emit/executor.test.ts +0 -83
- package/src/failure-summary.ts +0 -119
- package/src/generators/bounded-test-targets/generator.test.ts +0 -138
- package/src/generators/bun-test-tracing/generator.test.ts +0 -250
- package/src/generators/create-package/generator.test.ts +0 -190
- package/src/generators/make-public/generator.test.ts +0 -137
- package/src/graph-input-contract.test.ts +0 -379
- package/src/host-controller-wiring.test.ts +0 -31
- package/src/index.test.ts +0 -3321
- package/src/linked-snapshots.nx.test.ts +0 -254
- package/src/managed-files/forgejo-artifact.test.ts +0 -395
- package/src/managed-files/generator.test.ts +0 -243
- package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
- package/src/managed-files/json-edit.test.ts +0 -216
- package/src/managed-files/managed-content.test.ts +0 -166
- package/src/managed-files/managed-format-json.test.ts +0 -308
- package/src/managed-files/repo-path.test.ts +0 -172
- package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
- package/src/managed-files/trace-db-artifact.test.ts +0 -7
- package/src/managed-files/tree-permissions.test.ts +0 -109
- package/src/managed-files/tree.test.ts +0 -123
- package/src/manifest-hash.test.ts +0 -219
- package/src/nextest-code-bound.test.ts +0 -161
- package/src/nextest-extraction.test.ts +0 -216
- package/src/nextest-extraction.ts +0 -371
- package/src/nextest-partitions.test.ts +0 -501
- package/src/nx-cache-bound.test.ts +0 -109
- package/src/nx-cache-restore-mtime.test.ts +0 -170
- package/src/nx-daemon-claim.test.ts +0 -279
- package/src/nx-daemon-idle-cpu.test.ts +0 -80
- package/src/nx-daemon-idle-policy.test.ts +0 -111
- package/src/nx-daemon-ignore-files.test.ts +0 -210
- package/src/nx-daemon-root-normalization.test.ts +0 -105
- package/src/nx-daemon-start-never.test.ts +0 -292
- package/src/nx-daemon-validity.test.ts +0 -1055
- package/src/nx-dot-input-policy.test.ts +0 -353
- package/src/nx-failure-life-cycles.test.ts +0 -207
- package/src/nx-files-archive-racy.test.ts +0 -97
- package/src/nx-foreign-workspace-env.test.ts +0 -329
- package/src/nx-incomplete-run-summary.test.ts +0 -70
- package/src/nx-plugin-load-errors.test.ts +0 -120
- package/src/nx-project-graph-errors.test.ts +0 -70
- package/src/nx-project-resolution-cache.test.ts +0 -176
- package/src/nx-raw-inputs.test.ts +0 -166
- package/src/nx-resident-graph-workers.test.ts +0 -112
- package/src/nx-run-information.test.ts +0 -118
- package/src/nx-skipped-task-exit.test.ts +0 -180
- package/src/nx-state-location.test.ts +0 -63
- package/src/nx-store-resolution.test.ts +0 -81
- package/src/nx-task-graph-cycles.test.ts +0 -148
- package/src/nx-task-output-lease.test.ts +0 -550
- package/src/nx-use-local.test.ts +0 -105
- package/src/owned-installation.test.ts +0 -105
- package/src/package-target-policy.test.ts +0 -1014
- package/src/producer-receipts.test.ts +0 -285
- package/src/release-config-policy.test.ts +0 -311
- package/src/runtime-input.test.ts +0 -393
- package/src/serial-group-wiring.test.ts +0 -326
- package/src/task-history-namespace.test.ts +0 -181
- package/src/task-results.test.ts +0 -228
- package/src/test-clock-policy.test.ts +0 -338
- package/src/test-program.test.ts +0 -303
- package/src/test-timings.test.ts +0 -240
- package/src/test-walk-policy.test.ts +0 -620
- package/src/testing.test.ts +0 -509
- package/src/typecheck-test-policy.test.ts +0 -1468
- package/src/typescript-resolution.test.ts +0 -76
- package/src/version-actions.test.ts +0 -80
- package/src/workspace-config-policy.test.ts +0 -737
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { connect, type Socket } from 'node:net';
|
|
2
|
+
import { readDetachAnswer } from './ram-detach.js';
|
|
3
|
+
import type { RamDiskLease, RamUnavailable, Result } from './ram-temp.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The client of the cowshed gateway's `ram-lease` (specs/cowshed/05_gateway.md, "RAM disks"). The RAM temp volume's
|
|
7
|
+
* disk lives in the `diskimages-helper` that `hdiutil attach ram://<n>` forks. Forked inside a task's job, the helper is
|
|
8
|
+
* that job's member, and the job's end retires it with the disk under every other job's lease on the volume. The helper
|
|
9
|
+
* belongs to the gateway, which no job contains and which attaches the disk; no job's retirement reaches it.
|
|
10
|
+
*
|
|
11
|
+
* The client writes one line, `{"op":"ram-lease","sectors":<n>}`, and keeps its connection open; the gateway answers
|
|
12
|
+
* one line, `{"ok":true,"ramDisk":{"device":"/dev/diskN","registryEntry":"0x…"}}` or a refusal. The connection is the
|
|
13
|
+
* lease: the gateway holds the disk until the client writes `{"end":"keep"}`, after which the disk is the caller's, or
|
|
14
|
+
* `{"end":"release"}`, which the gateway answers with its detach as `ram-detach` does. A connection that ends first,
|
|
15
|
+
* at the client's deadline or with its process, has the gateway detach the disk. An end the gateway never answers leaves
|
|
16
|
+
* nothing known: the gateway may have handed the disk over or left it to its next startup scan, so the caller detaches it
|
|
17
|
+
* by its entry.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export const RAM_LEASE_OP = 'ram-lease';
|
|
21
|
+
|
|
22
|
+
const WHOLE_DISK = /^\/dev\/disk\d+$/;
|
|
23
|
+
const REGISTRY_ENTRY = /^0x[0-9a-f]+$/;
|
|
24
|
+
/** A release answers what `ram-detach` does, whose native output the gateway bounds; no answer grows past that. */
|
|
25
|
+
const ANSWER_BYTES_MAX = 2 * 64 * 1024 * 6 + 4096;
|
|
26
|
+
|
|
27
|
+
/** What the lease's connection gave next: one answer line, or why it gave none. */
|
|
28
|
+
type Next =
|
|
29
|
+
| { readonly kind: 'line'; readonly line: string }
|
|
30
|
+
| { readonly kind: 'closed' }
|
|
31
|
+
| { readonly kind: 'failed'; readonly error: Error }
|
|
32
|
+
| { readonly kind: 'late' };
|
|
33
|
+
|
|
34
|
+
/** The disk a granted lease holds. */
|
|
35
|
+
interface Granted {
|
|
36
|
+
readonly device: string;
|
|
37
|
+
readonly registryEntry: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Ask the gateway at `socket` for a RAM disk of `sectors` 512-byte sectors; its lease, or why there is none. */
|
|
41
|
+
export async function attachRamDisk(
|
|
42
|
+
socket: string,
|
|
43
|
+
sectors: number,
|
|
44
|
+
deadlineMs: number,
|
|
45
|
+
): Promise<Result<RamDiskLease, string | RamUnavailable>> {
|
|
46
|
+
// eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: a unix-socket connect completes or fails at once, and every answer on it is awaited by next(deadlineMs), whose timer ends the wait
|
|
47
|
+
const connection = connect(socket);
|
|
48
|
+
const next = answers(connection);
|
|
49
|
+
connection.on('connect', () => connection.write(`${JSON.stringify({ op: RAM_LEASE_OP, sectors })}\n`));
|
|
50
|
+
const granted = readGrant(await next(deadlineMs), socket, deadlineMs);
|
|
51
|
+
if (!granted.ok) {
|
|
52
|
+
connection.destroy();
|
|
53
|
+
return granted;
|
|
54
|
+
}
|
|
55
|
+
// The open connection is the lease; it never keeps this process alive on its own.
|
|
56
|
+
connection.unref();
|
|
57
|
+
return { ok: true, value: heldLease(connection, next, granted.value, deadlineMs) };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The connection's answer lines, one per call, each awaited for at most `deadlineMs`. */
|
|
61
|
+
function answers(connection: Socket): (deadlineMs: number) => Promise<Next> {
|
|
62
|
+
let received = '';
|
|
63
|
+
let gone: Next | null = null;
|
|
64
|
+
let waiting: ((next: Next) => void) | null = null;
|
|
65
|
+
const deliver = () => {
|
|
66
|
+
const wake = waiting;
|
|
67
|
+
if (wake === null) return;
|
|
68
|
+
const newline = received.indexOf('\n');
|
|
69
|
+
let next = gone;
|
|
70
|
+
if (newline >= 0) {
|
|
71
|
+
next = { kind: 'line', line: received.slice(0, newline) };
|
|
72
|
+
received = received.slice(newline + 1);
|
|
73
|
+
} else if (gone !== null && received !== '') {
|
|
74
|
+
next = { kind: 'line', line: received };
|
|
75
|
+
received = '';
|
|
76
|
+
}
|
|
77
|
+
if (next === null) return;
|
|
78
|
+
waiting = null;
|
|
79
|
+
wake(next);
|
|
80
|
+
};
|
|
81
|
+
connection.on('data', (chunk: Buffer) => {
|
|
82
|
+
received += chunk.toString('utf8');
|
|
83
|
+
if (received.length <= ANSWER_BYTES_MAX) return deliver();
|
|
84
|
+
received = '';
|
|
85
|
+
connection.destroy(new Error(`the gateway's answer exceeds ${ANSWER_BYTES_MAX} bytes`));
|
|
86
|
+
});
|
|
87
|
+
connection.on('error', (error) => {
|
|
88
|
+
gone ??= { kind: 'failed', error };
|
|
89
|
+
deliver();
|
|
90
|
+
});
|
|
91
|
+
connection.on('close', () => {
|
|
92
|
+
gone ??= { kind: 'closed' };
|
|
93
|
+
deliver();
|
|
94
|
+
});
|
|
95
|
+
return (deadlineMs) =>
|
|
96
|
+
new Promise((resolve) => {
|
|
97
|
+
const timer = setTimeout(() => {
|
|
98
|
+
waiting = null;
|
|
99
|
+
resolve({ kind: 'late' });
|
|
100
|
+
}, deadlineMs);
|
|
101
|
+
waiting = (next) => {
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
resolve(next);
|
|
104
|
+
};
|
|
105
|
+
deliver();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The lease the attach answer grants, or why it grants none. */
|
|
110
|
+
function readGrant(next: Next, socket: string, deadlineMs: number): Result<Granted, string | RamUnavailable> {
|
|
111
|
+
switch (next.kind) {
|
|
112
|
+
case 'late':
|
|
113
|
+
return {
|
|
114
|
+
ok: false,
|
|
115
|
+
error: `the gateway answered no ram-lease within ${deadlineMs} ms; this client closed the lease, so the gateway detaches any disk its attach still makes`,
|
|
116
|
+
};
|
|
117
|
+
case 'failed':
|
|
118
|
+
return {
|
|
119
|
+
ok: false,
|
|
120
|
+
error:
|
|
121
|
+
'code' in next.error && (next.error.code === 'ENOENT' || next.error.code === 'ECONNREFUSED')
|
|
122
|
+
? {
|
|
123
|
+
kind: 'ram-unavailable',
|
|
124
|
+
reason: 'gateway-absent',
|
|
125
|
+
detail: `gateway ${socket} is unavailable: ${next.error.message}`,
|
|
126
|
+
}
|
|
127
|
+
: `gateway ram-lease I/O failed: ${next.error.message}`,
|
|
128
|
+
};
|
|
129
|
+
case 'closed':
|
|
130
|
+
return { ok: false, error: 'the gateway closed ram-lease without an answer' };
|
|
131
|
+
case 'line':
|
|
132
|
+
return readAnswer(next.line);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The fields of one JSON object answer line, or null for anything else. */
|
|
137
|
+
function fieldsOf(line: string): Readonly<Record<string, unknown>> | null {
|
|
138
|
+
let parsed: unknown;
|
|
139
|
+
try {
|
|
140
|
+
parsed = JSON.parse(line);
|
|
141
|
+
} catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)
|
|
145
|
+
? Object.fromEntries(Object.entries(parsed))
|
|
146
|
+
: null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The whole disk and registry entry a `ram-lease` answer names, or why the answer names none. */
|
|
150
|
+
function readAnswer(line: string): Result<Granted, string | RamUnavailable> {
|
|
151
|
+
const fields = fieldsOf(line);
|
|
152
|
+
if (fields === null) {
|
|
153
|
+
return { ok: false, error: `the gateway answered ram-lease with something that is not an answer: ${line}` };
|
|
154
|
+
}
|
|
155
|
+
if (fields.ok !== true) {
|
|
156
|
+
const why = `${String(fields.code ?? 'refused')}: ${String(fields.error ?? '')}`;
|
|
157
|
+
return {
|
|
158
|
+
ok: false,
|
|
159
|
+
error: String(fields.error ?? '').endsWith('unknown gateway control operation')
|
|
160
|
+
? { kind: 'ram-unavailable', reason: 'gateway-unsupported', detail: `gateway predates ram-lease (${why})` }
|
|
161
|
+
: `the gateway refused ram-lease (${why})`,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const ramDisk = fields.ramDisk;
|
|
165
|
+
const device =
|
|
166
|
+
typeof ramDisk === 'object' && ramDisk !== null && 'device' in ramDisk && typeof ramDisk.device === 'string'
|
|
167
|
+
? ramDisk.device
|
|
168
|
+
: null;
|
|
169
|
+
const registryEntry =
|
|
170
|
+
typeof ramDisk === 'object' &&
|
|
171
|
+
ramDisk !== null &&
|
|
172
|
+
'registryEntry' in ramDisk &&
|
|
173
|
+
typeof ramDisk.registryEntry === 'string'
|
|
174
|
+
? ramDisk.registryEntry
|
|
175
|
+
: null;
|
|
176
|
+
return device !== null && WHOLE_DISK.test(device) && registryEntry !== null && REGISTRY_ENTRY.test(registryEntry)
|
|
177
|
+
? { ok: true, value: { device, registryEntry } }
|
|
178
|
+
: { ok: false, error: `the gateway's ram-lease answer names no whole disk and registry entry: ${line}` };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The lease `connection` holds on `disk`; each end is one line, half-closed, whose answer is awaited `deadlineMs`. */
|
|
182
|
+
function heldLease(
|
|
183
|
+
connection: Socket,
|
|
184
|
+
next: (deadlineMs: number) => Promise<Next>,
|
|
185
|
+
disk: Granted,
|
|
186
|
+
deadlineMs: number,
|
|
187
|
+
): RamDiskLease {
|
|
188
|
+
let ended: 'keep' | 'release' | null = null;
|
|
189
|
+
const end = async (how: 'keep' | 'release'): Promise<Result<string, string>> => {
|
|
190
|
+
if (ended !== null) {
|
|
191
|
+
return {
|
|
192
|
+
ok: false,
|
|
193
|
+
error: `the ram-lease of ${disk.device} already ended at its ${ended}; nothing is known of a detach`,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
ended = how;
|
|
197
|
+
connection.end(`${JSON.stringify({ end: how })}\n`);
|
|
198
|
+
const answer = await next(deadlineMs);
|
|
199
|
+
connection.destroy();
|
|
200
|
+
if (answer.kind === 'line') return { ok: true, value: answer.line };
|
|
201
|
+
const why =
|
|
202
|
+
answer.kind === 'late'
|
|
203
|
+
? `none within ${deadlineMs} ms`
|
|
204
|
+
: answer.kind === 'failed'
|
|
205
|
+
? answer.error.message
|
|
206
|
+
: 'it closed the connection';
|
|
207
|
+
return {
|
|
208
|
+
ok: false,
|
|
209
|
+
error: `the gateway answered no ${how} of the ram-lease of ${disk.device} (${why}): ${
|
|
210
|
+
how === 'keep'
|
|
211
|
+
? 'nothing is known: the gateway may have handed the disk over or left it to its next startup scan; detach it by its entry'
|
|
212
|
+
: 'the lease is lost, so nothing is known of a detach'
|
|
213
|
+
}`,
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
return {
|
|
217
|
+
device: disk.device,
|
|
218
|
+
registryEntry: disk.registryEntry,
|
|
219
|
+
async keep() {
|
|
220
|
+
const answer = await end('keep');
|
|
221
|
+
if (!answer.ok) return answer;
|
|
222
|
+
return fieldsOf(answer.value)?.ok === true
|
|
223
|
+
? { ok: true, value: undefined }
|
|
224
|
+
: { ok: false, error: `the gateway refused to keep the ram-lease of ${disk.device}: ${answer.value}` };
|
|
225
|
+
},
|
|
226
|
+
async release() {
|
|
227
|
+
const answer = await end('release');
|
|
228
|
+
if (!answer.ok) return answer;
|
|
229
|
+
const output = readDetachAnswer(answer.value);
|
|
230
|
+
return output === null
|
|
231
|
+
? {
|
|
232
|
+
ok: false,
|
|
233
|
+
error: `the gateway's release of the ram-lease of ${disk.device} proves no detach outcome: ${answer.value}`,
|
|
234
|
+
}
|
|
235
|
+
: { ok: true, value: output };
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { connect } from 'node:net';
|
|
2
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
+
import type { CommandOutput } from './ram-temp.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The silence the client allows the gateway before its first heartbeat line (05_gateway.md, "Deadlines"; Rust
|
|
7
|
+
* `UNPROVEN_SILENCE`): a gateway of an earlier build never heartbeats, and its slow answers still arrive within the
|
|
8
|
+
* minute doctor always gave it.
|
|
9
|
+
*/
|
|
10
|
+
export const UNPROVEN_SILENCE_MS = 60_000;
|
|
11
|
+
|
|
12
|
+
/** The silence allowed once a heartbeat has come: three 5 s heartbeats (Rust `deadline::HEARTBEAT_SILENCE`). */
|
|
13
|
+
export const HEARTBEAT_SILENCE_MS = 15_000;
|
|
14
|
+
|
|
15
|
+
/** A detach answers its native output, which the gateway bounds; no answer grows past that. */
|
|
16
|
+
const ANSWER_BYTES_MAX = 2 * 64 * 1024 * 6 + 4096;
|
|
17
|
+
|
|
18
|
+
/** Monotonic milliseconds and the one silence timer; `after` answers its cancel. A test fires its timer itself. */
|
|
19
|
+
export interface SilenceTimers {
|
|
20
|
+
now(): number;
|
|
21
|
+
after(ms: number, fire: () => void): () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const SYSTEM_TIMERS: SilenceTimers = {
|
|
25
|
+
now: () => performance.now(),
|
|
26
|
+
after(ms, fire) {
|
|
27
|
+
const timer = setTimeout(fire, ms);
|
|
28
|
+
return () => clearTimeout(timer);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** The last thing the client saw the gateway do, which a `SILENT` failure names. */
|
|
33
|
+
type GatewayProgress = { kind: 'nothing' } | { kind: 'sent' } | { kind: 'heartbeat'; seq: number };
|
|
34
|
+
|
|
35
|
+
function describeProgress(progress: GatewayProgress): string {
|
|
36
|
+
switch (progress.kind) {
|
|
37
|
+
case 'nothing':
|
|
38
|
+
return 'nothing';
|
|
39
|
+
case 'sent':
|
|
40
|
+
return 'request sent';
|
|
41
|
+
case 'heartbeat':
|
|
42
|
+
return `heartbeat ${progress.seq}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Typed gateway mutation: no caller-owned native child or arbitrary argv. The request is a one-shot control op, so the
|
|
48
|
+
* answer is read under the gateway's silence rule (05_gateway.md, "Deadlines"), never under a total ceiling: until the
|
|
49
|
+
* first heartbeat line the gateway may be silent for {@link UNPROVEN_SILENCE_MS}, after each one for
|
|
50
|
+
* {@link HEARTBEAT_SILENCE_MS}. A silent gateway ends this caller's wait as `SILENT`, with unknown custody; the gateway's
|
|
51
|
+
* detach keeps running, and its late answer still completes `pending`.
|
|
52
|
+
*/
|
|
53
|
+
export function detachGatewayRamDisk(
|
|
54
|
+
socket: string,
|
|
55
|
+
device: string,
|
|
56
|
+
registryEntry: string,
|
|
57
|
+
timers: SilenceTimers = SYSTEM_TIMERS,
|
|
58
|
+
): Promise<CommandOutput> {
|
|
59
|
+
let resolve!: (output: CommandOutput) => void;
|
|
60
|
+
const answer = new Promise<CommandOutput>((done) => {
|
|
61
|
+
resolve = done;
|
|
62
|
+
});
|
|
63
|
+
let complete!: (output: CommandOutput | null) => void;
|
|
64
|
+
const completion = new Promise<CommandOutput | null>((done) => {
|
|
65
|
+
complete = done;
|
|
66
|
+
});
|
|
67
|
+
const started = timers.now();
|
|
68
|
+
let last: GatewayProgress = { kind: 'nothing' };
|
|
69
|
+
let silenceMs = UNPROVEN_SILENCE_MS;
|
|
70
|
+
let disarm = () => {};
|
|
71
|
+
const decoder = new StringDecoder('utf8');
|
|
72
|
+
let received = '';
|
|
73
|
+
let dispatched = false;
|
|
74
|
+
let bounded = false;
|
|
75
|
+
let finished = false;
|
|
76
|
+
const pending = { pid: null, completion };
|
|
77
|
+
const unknown = (reason: string): CommandOutput => ({ status: 1, stdout: '', stderr: reason, pending });
|
|
78
|
+
// eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: a unix-socket connect completes or fails at once, and the silence timer listen() arms below ends the whole exchange (05_gateway.md, "Deadlines")
|
|
79
|
+
const connection = connect(socket);
|
|
80
|
+
const finish = (output: CommandOutput | null, reason = 'gateway detach terminal status unavailable') => {
|
|
81
|
+
if (finished) return;
|
|
82
|
+
finished = true;
|
|
83
|
+
disarm();
|
|
84
|
+
complete(output);
|
|
85
|
+
if (!bounded) resolve(output ?? unknown(reason));
|
|
86
|
+
connection.destroy();
|
|
87
|
+
};
|
|
88
|
+
const silent = () => {
|
|
89
|
+
bounded = true;
|
|
90
|
+
resolve(
|
|
91
|
+
unknown(
|
|
92
|
+
`SILENT: ram-detach: the gateway at ${socket} wrote no heartbeat or answer for ${silenceMs} ms (waited ${Math.max(0, timers.now() - started)} ms; last progress: ${describeProgress(last)}); the gateway's detach keeps running, not killed`,
|
|
93
|
+
),
|
|
94
|
+
);
|
|
95
|
+
connection.unref();
|
|
96
|
+
};
|
|
97
|
+
/** Allow the gateway `silenceMs` from now; once the caller's wait has ended there is nothing left to bound. */
|
|
98
|
+
const listen = () => {
|
|
99
|
+
if (bounded || finished) return;
|
|
100
|
+
disarm();
|
|
101
|
+
disarm = timers.after(silenceMs, silent);
|
|
102
|
+
};
|
|
103
|
+
listen();
|
|
104
|
+
connection.on('connect', () => {
|
|
105
|
+
dispatched = true;
|
|
106
|
+
connection.end(`${JSON.stringify({ op: 'ram-detach', device, registryEntry })}\n`);
|
|
107
|
+
last = { kind: 'sent' };
|
|
108
|
+
});
|
|
109
|
+
connection.on('data', (chunk: Buffer) => {
|
|
110
|
+
received += decoder.write(chunk);
|
|
111
|
+
for (let newline = received.indexOf('\n'); newline >= 0; newline = received.indexOf('\n')) {
|
|
112
|
+
const line = received.slice(0, newline);
|
|
113
|
+
received = received.slice(newline + 1);
|
|
114
|
+
// The gateway heartbeats an answer that is not ready yet (05_gateway.md, "Deadlines"): never the answer.
|
|
115
|
+
const seq = heartbeatSeq(line);
|
|
116
|
+
if (seq !== null) {
|
|
117
|
+
last = { kind: 'heartbeat', seq };
|
|
118
|
+
silenceMs = HEARTBEAT_SILENCE_MS;
|
|
119
|
+
listen();
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
// A line past the cap is refused before it is read, whatever chunk completed it.
|
|
123
|
+
if (Buffer.byteLength(line) > ANSWER_BYTES_MAX)
|
|
124
|
+
return finish(null, 'gateway detach reply exceeds its bounded output contract');
|
|
125
|
+
const parsed = readDetachAnswer(line);
|
|
126
|
+
if (parsed === null) finish(null, `gateway detach reply proves no terminal outcome: ${line.slice(0, 512)}`);
|
|
127
|
+
else finish(parsed);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
// Native output is bounded by the gateway contract; never buffer an unbounded peer reply.
|
|
131
|
+
if (Buffer.byteLength(received) > ANSWER_BYTES_MAX)
|
|
132
|
+
finish(null, 'gateway detach reply exceeds its bounded output contract');
|
|
133
|
+
});
|
|
134
|
+
connection.on('error', (error) => {
|
|
135
|
+
if (!dispatched) finish({ status: 103, stdout: '', stderr: `gateway detach did not start: ${error.message}` });
|
|
136
|
+
else finish(null, `gateway detach connection ended after dispatch: ${error.message}`);
|
|
137
|
+
});
|
|
138
|
+
connection.on('close', () => finish(null, 'gateway detach closed without an authoritative outcome'));
|
|
139
|
+
return answer;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The heartbeat's `progress` when `line` is exactly a gateway heartbeat, `{"ok":<bool>,"progress":<u64>}` and nothing
|
|
144
|
+
* else (Rust `ProgressLine`, `deny_unknown_fields`); `null` for any other line, which is the answer.
|
|
145
|
+
*/
|
|
146
|
+
function heartbeatSeq(line: string): number | null {
|
|
147
|
+
let parsed: unknown;
|
|
148
|
+
try {
|
|
149
|
+
parsed = JSON.parse(line);
|
|
150
|
+
} catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return null;
|
|
154
|
+
if (Object.keys(parsed).length !== 2 || !('ok' in parsed) || !('progress' in parsed)) return null;
|
|
155
|
+
const { ok, progress } = parsed;
|
|
156
|
+
return typeof ok === 'boolean' && typeof progress === 'number' && Number.isInteger(progress) && progress >= 0
|
|
157
|
+
? progress
|
|
158
|
+
: null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Only the gateway can attest whether its exact native child ran and was reaped. */
|
|
162
|
+
export function readDetachAnswer(line: string): CommandOutput | null {
|
|
163
|
+
let parsed: unknown;
|
|
164
|
+
try {
|
|
165
|
+
parsed = JSON.parse(line);
|
|
166
|
+
} catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
if (typeof parsed !== 'object' || parsed === null || !('ok' in parsed)) return null;
|
|
170
|
+
if (parsed.ok === false && 'code' in parsed && parsed.code === 'invalid-request') {
|
|
171
|
+
return {
|
|
172
|
+
status: 103,
|
|
173
|
+
stdout: '',
|
|
174
|
+
stderr: `gateway detach did not start: ${'error' in parsed ? String(parsed.error) : 'invalid request'}`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (
|
|
178
|
+
parsed.ok !== true ||
|
|
179
|
+
!('ramDetach' in parsed) ||
|
|
180
|
+
typeof parsed.ramDetach !== 'object' ||
|
|
181
|
+
parsed.ramDetach === null
|
|
182
|
+
)
|
|
183
|
+
return null;
|
|
184
|
+
const result = parsed.ramDetach;
|
|
185
|
+
if (!('outcome' in result)) return null;
|
|
186
|
+
if (result.outcome === 'unknown') return null;
|
|
187
|
+
if (result.outcome === 'not-started' && 'reason' in result && typeof result.reason === 'string') {
|
|
188
|
+
return { status: 103, stdout: '', stderr: `gateway detach did not start: ${result.reason}` };
|
|
189
|
+
}
|
|
190
|
+
if (
|
|
191
|
+
result.outcome !== 'terminal' ||
|
|
192
|
+
!('status' in result) ||
|
|
193
|
+
typeof result.status !== 'object' ||
|
|
194
|
+
result.status === null ||
|
|
195
|
+
!('stdout' in result) ||
|
|
196
|
+
typeof result.stdout !== 'string' ||
|
|
197
|
+
!('stderr' in result) ||
|
|
198
|
+
typeof result.stderr !== 'string' ||
|
|
199
|
+
!('stdoutTruncated' in result) ||
|
|
200
|
+
typeof result.stdoutTruncated !== 'boolean' ||
|
|
201
|
+
!('stderrTruncated' in result) ||
|
|
202
|
+
typeof result.stderrTruncated !== 'boolean'
|
|
203
|
+
)
|
|
204
|
+
return null;
|
|
205
|
+
const status = result.status;
|
|
206
|
+
const code =
|
|
207
|
+
'exit' in status && typeof status.exit === 'number' && Number.isSafeInteger(status.exit) && status.exit >= 0
|
|
208
|
+
? status.exit
|
|
209
|
+
: 'signal' in status &&
|
|
210
|
+
typeof status.signal === 'number' &&
|
|
211
|
+
Number.isSafeInteger(status.signal) &&
|
|
212
|
+
status.signal > 0
|
|
213
|
+
? 128 + status.signal
|
|
214
|
+
: null;
|
|
215
|
+
return code === null
|
|
216
|
+
? null
|
|
217
|
+
: {
|
|
218
|
+
status: code,
|
|
219
|
+
stdout: result.stdout,
|
|
220
|
+
stderr:
|
|
221
|
+
result.stderr +
|
|
222
|
+
(result.stdoutTruncated || result.stderrTruncated
|
|
223
|
+
? '\n[gateway detach output truncated at the native inline limit]'
|
|
224
|
+
: ''),
|
|
225
|
+
};
|
|
226
|
+
}
|