@smoothbricks/nx-plugin 0.5.6 → 0.6.0

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.
Files changed (440) hide show
  1. package/README.md +1095 -360
  2. package/dist/.build-inputs.json +138 -0
  3. package/dist/bin/smoo-nx-cargo-toolchain.d.ts +3 -0
  4. package/dist/bin/smoo-nx-cargo-toolchain.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-cargo-toolchain.js +8 -0
  6. package/dist/bin/smoo-nx-forbidden-spellings.d.ts +3 -0
  7. package/dist/bin/smoo-nx-forbidden-spellings.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-forbidden-spellings.js +32 -0
  9. package/dist/bin/smoo-nx-nextest-timings.d.ts +3 -0
  10. package/dist/bin/smoo-nx-nextest-timings.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-nextest-timings.js +28 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +14 -15
  15. package/dist/build-state-output-policy.d.ts +95 -1
  16. package/dist/build-state-output-policy.d.ts.map +1 -1
  17. package/dist/build-state-output-policy.js +368 -30
  18. package/dist/bun-lock-scope.d.ts +44 -0
  19. package/dist/bun-lock-scope.d.ts.map +1 -0
  20. package/dist/bun-lock-scope.js +97 -0
  21. package/dist/cargo-build-script-env.d.ts +49 -0
  22. package/dist/cargo-build-script-env.d.ts.map +1 -0
  23. package/dist/cargo-build-script-env.js +324 -0
  24. package/dist/cargo-closure-input.d.ts +31 -4
  25. package/dist/cargo-closure-input.d.ts.map +1 -1
  26. package/dist/cargo-closure-input.js +66 -6
  27. package/dist/cargo-retention-hook.d.ts +17 -0
  28. package/dist/cargo-retention-hook.d.ts.map +1 -0
  29. package/dist/cargo-retention-hook.js +85 -0
  30. package/dist/cargo-source-hash.d.ts +25 -7
  31. package/dist/cargo-source-hash.d.ts.map +1 -1
  32. package/dist/cargo-source-hash.js +108 -43
  33. package/dist/cargo-toolchain-paths.d.ts +40 -0
  34. package/dist/cargo-toolchain-paths.d.ts.map +1 -0
  35. package/dist/cargo-toolchain-paths.js +84 -0
  36. package/dist/cargo-toolchain-policy.d.ts +25 -8
  37. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  38. package/dist/cargo-toolchain-policy.js +39 -5
  39. package/dist/cargo-workspace.d.ts +10 -4
  40. package/dist/cargo-workspace.d.ts.map +1 -1
  41. package/dist/cargo-workspace.js +65 -95
  42. package/dist/cross-check-policy.d.ts +9 -9
  43. package/dist/cross-check-policy.d.ts.map +1 -1
  44. package/dist/cross-check-policy.js +11 -11
  45. package/dist/disk-command-policy.d.ts.map +1 -1
  46. package/dist/disk-command-policy.js +1 -0
  47. package/dist/ensure-built-receipt.d.ts +13 -5
  48. package/dist/ensure-built-receipt.d.ts.map +1 -1
  49. package/dist/ensure-built-receipt.js +126 -47
  50. package/dist/ensure-built-witness.d.ts +27 -8
  51. package/dist/ensure-built-witness.d.ts.map +1 -1
  52. package/dist/ensure-built-witness.js +45 -15
  53. package/dist/ensure-built.d.ts.map +1 -1
  54. package/dist/ensure-built.js +9 -1
  55. package/dist/eslint-config-closure.d.ts +7 -0
  56. package/dist/eslint-config-closure.d.ts.map +1 -0
  57. package/dist/eslint-config-closure.js +346 -0
  58. package/dist/executors/all-verdicts/executor.d.ts +35 -0
  59. package/dist/executors/all-verdicts/executor.d.ts.map +1 -0
  60. package/dist/executors/all-verdicts/executor.js +133 -0
  61. package/dist/executors/all-verdicts/schema.d.ts +10 -0
  62. package/dist/executors/all-verdicts/schema.d.ts.map +1 -0
  63. package/dist/executors/all-verdicts/schema.js +2 -0
  64. package/dist/executors/bounded-exec/bounds.d.ts +56 -0
  65. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -0
  66. package/dist/executors/bounded-exec/bounds.js +43 -0
  67. package/dist/executors/bounded-exec/cpu-pool.d.ts +33 -36
  68. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  69. package/dist/executors/bounded-exec/cpu-pool.js +54 -119
  70. package/dist/executors/bounded-exec/executor.d.ts +19 -12
  71. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  72. package/dist/executors/bounded-exec/executor.js +371 -239
  73. package/dist/executors/bounded-exec/gateway-lease.d.ts +22 -19
  74. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  75. package/dist/executors/bounded-exec/gateway-lease.js +81 -28
  76. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +18 -1
  77. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  78. package/dist/executors/bounded-exec/hang-diagnostics.js +148 -30
  79. package/dist/executors/bounded-exec/lease-wait.d.ts +43 -0
  80. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -0
  81. package/dist/executors/bounded-exec/lease-wait.js +68 -0
  82. package/dist/executors/bounded-exec/lock-wait.d.ts +51 -0
  83. package/dist/executors/bounded-exec/lock-wait.d.ts.map +1 -0
  84. package/dist/executors/bounded-exec/lock-wait.js +108 -0
  85. package/dist/executors/bounded-exec/owned-subtree.d.ts +84 -0
  86. package/dist/executors/bounded-exec/owned-subtree.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/owned-subtree.js +178 -0
  88. package/dist/executors/bounded-exec/progress.d.ts +4 -1
  89. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  90. package/dist/executors/bounded-exec/progress.js +5 -2
  91. package/dist/executors/bounded-exec/ram-attach.d.ts +19 -0
  92. package/dist/executors/bounded-exec/ram-attach.d.ts.map +1 -0
  93. package/dist/executors/bounded-exec/ram-attach.js +207 -0
  94. package/dist/executors/bounded-exec/ram-detach.d.ts +25 -0
  95. package/dist/executors/bounded-exec/ram-detach.d.ts.map +1 -0
  96. package/dist/executors/bounded-exec/ram-detach.js +207 -0
  97. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +76 -0
  98. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -1
  99. package/dist/executors/bounded-exec/ram-temp-fixtures.js +296 -0
  100. package/dist/executors/bounded-exec/ram-temp.d.ts +388 -88
  101. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  102. package/dist/executors/bounded-exec/ram-temp.js +1213 -399
  103. package/dist/executors/bounded-exec/run-cpu-pool.d.ts +4 -4
  104. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  105. package/dist/executors/bounded-exec/run-cpu-pool.js +20 -30
  106. package/dist/executors/bounded-exec/runner-hook.js +14 -5
  107. package/dist/executors/bounded-exec/runner-lifecycle.d.ts +14 -1
  108. package/dist/executors/bounded-exec/runner-lifecycle.d.ts.map +1 -1
  109. package/dist/executors/bounded-exec/runner-lifecycle.js +27 -6
  110. package/dist/executors/bounded-exec/{cpu-tokens.d.ts → runner-sizing.d.ts} +14 -42
  111. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -0
  112. package/dist/executors/bounded-exec/{cpu-tokens.js → runner-sizing.js} +5 -35
  113. package/dist/executors/bounded-exec/runtime-pin.d.ts +73 -0
  114. package/dist/executors/bounded-exec/runtime-pin.d.ts.map +1 -0
  115. package/dist/executors/bounded-exec/runtime-pin.js +167 -0
  116. package/dist/executors/bounded-exec/schema.d.ts +18 -1
  117. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  118. package/dist/executors/bounded-exec/verdict.d.ts +40 -11
  119. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  120. package/dist/executors/bounded-exec/verdict.js +88 -19
  121. package/dist/executors/cargo-zigbuild/executor.d.ts +21 -0
  122. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  123. package/dist/executors/cargo-zigbuild/executor.js +67 -12
  124. package/dist/executors/clean-outputs/executor.js +1 -0
  125. package/dist/executors/scriptc-native/executor.d.ts +79 -0
  126. package/dist/executors/scriptc-native/executor.d.ts.map +1 -0
  127. package/dist/executors/scriptc-native/executor.js +367 -0
  128. package/dist/executors/scriptc-native/ffi-paths.d.ts +9 -0
  129. package/dist/executors/scriptc-native/ffi-paths.d.ts.map +1 -0
  130. package/dist/executors/scriptc-native/ffi-paths.js +25 -0
  131. package/dist/executors/scriptc-native/schema.d.ts +34 -0
  132. package/dist/executors/scriptc-native/schema.d.ts.map +1 -0
  133. package/dist/executors/scriptc-native/schema.js +1 -0
  134. package/dist/executors/typescript-emit/executor.d.ts +3 -1
  135. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  136. package/dist/executors/typescript-emit/executor.js +164 -33
  137. package/dist/forbidden-spelling-policy.d.ts +56 -0
  138. package/dist/forbidden-spelling-policy.d.ts.map +1 -0
  139. package/dist/forbidden-spelling-policy.js +176 -0
  140. package/dist/generators/create-package/generator.d.ts.map +1 -1
  141. package/dist/generators/create-package/generator.js +3 -4
  142. package/dist/graph-input-contract.d.ts +14 -0
  143. package/dist/graph-input-contract.d.ts.map +1 -1
  144. package/dist/graph-input-contract.js +67 -2
  145. package/dist/index.d.ts +23 -6
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +676 -215
  148. package/dist/managed-assets.d.ts +2 -0
  149. package/dist/managed-assets.d.ts.map +1 -1
  150. package/dist/managed-files/files.d.ts +3 -3
  151. package/dist/managed-files/files.d.ts.map +1 -1
  152. package/dist/managed-files/files.js +28 -3
  153. package/dist/managed-files/managed-format.d.ts.map +1 -1
  154. package/dist/managed-files/managed-format.js +1 -0
  155. package/dist/nextest-code-bound.js +1 -0
  156. package/dist/nextest-timings.d.ts +35 -0
  157. package/dist/nextest-timings.d.ts.map +1 -0
  158. package/dist/nextest-timings.js +168 -0
  159. package/dist/owned-installation.d.ts +6 -5
  160. package/dist/owned-installation.d.ts.map +1 -1
  161. package/dist/owned-installation.js +150 -26
  162. package/dist/package-target-policy.d.ts.map +1 -1
  163. package/dist/package-target-policy.js +2 -3
  164. package/dist/process-children.d.ts +7 -0
  165. package/dist/process-children.d.ts.map +1 -0
  166. package/dist/process-children.darwin.d.ts +7 -0
  167. package/dist/process-children.darwin.d.ts.map +1 -0
  168. package/dist/process-children.darwin.js +13 -0
  169. package/dist/process-children.js +14 -0
  170. package/dist/process-children.linux.d.ts +8 -0
  171. package/dist/process-children.linux.d.ts.map +1 -0
  172. package/dist/process-children.linux.js +25 -0
  173. package/dist/process-group.d.ts +108 -0
  174. package/dist/process-group.d.ts.map +1 -0
  175. package/dist/process-group.js +171 -0
  176. package/dist/process-listing.d.ts +7 -0
  177. package/dist/process-listing.d.ts.map +1 -0
  178. package/dist/process-listing.js +51 -0
  179. package/dist/producer-receipts.d.ts +8 -2
  180. package/dist/producer-receipts.d.ts.map +1 -1
  181. package/dist/producer-receipts.js +75 -48
  182. package/dist/task-graph-policy.d.ts +21 -0
  183. package/dist/task-graph-policy.d.ts.map +1 -0
  184. package/dist/task-graph-policy.js +91 -0
  185. package/dist/test-timings.js +4 -4
  186. package/dist/test-walk-policy.d.ts +14 -5
  187. package/dist/test-walk-policy.d.ts.map +1 -1
  188. package/dist/test-walk-policy.js +8 -2
  189. package/dist/testing.d.ts +73 -28
  190. package/dist/testing.d.ts.map +1 -1
  191. package/dist/testing.js +217 -223
  192. package/dist/tool-bins.d.ts +33 -0
  193. package/dist/tool-bins.d.ts.map +1 -0
  194. package/dist/tool-bins.js +72 -0
  195. package/dist/typecheck-test-policy.d.ts.map +1 -1
  196. package/dist/typecheck-test-policy.js +3 -4
  197. package/dist/wait-why-policy.d.ts +28 -0
  198. package/dist/wait-why-policy.d.ts.map +1 -0
  199. package/dist/wait-why-policy.js +223 -0
  200. package/dist/workspace-config-policy.d.ts +14 -8
  201. package/dist/workspace-config-policy.d.ts.map +1 -1
  202. package/dist/workspace-config-policy.js +60 -16
  203. package/dist/workspace-manifest.d.ts +41 -6
  204. package/dist/workspace-manifest.d.ts.map +1 -1
  205. package/dist/workspace-manifest.js +57 -0
  206. package/executors.json +21 -1
  207. package/loader.js +2 -0
  208. package/managed/raw/envrc +11 -0
  209. package/managed/raw/patches/nx@23.2.1.patch +2840 -199
  210. package/managed/raw/patches/ttsc@0.34.1.patch +119 -0
  211. package/managed/raw/tooling/direnv/cargo-fetch-bound.ts +245 -0
  212. package/managed/raw/tooling/direnv/cargo-fetch-run.ts +299 -0
  213. package/managed/raw/tooling/direnv/compiler-variables.sh +42 -0
  214. package/managed/raw/tooling/direnv/developer-links.ts +464 -25
  215. package/managed/raw/tooling/direnv/devenv.smoo.nix +78 -38
  216. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -12
  217. package/managed/raw/tooling/direnv/installed-bun-links.ts +308 -0
  218. package/managed/raw/tooling/direnv/linked-snapshots.ts +62 -3
  219. package/managed/raw/tooling/direnv/nx-socket-dir.sh +56 -17
  220. package/managed/raw/tooling/direnv/repo-path +68 -6
  221. package/managed/raw/tooling/direnv/secret-references.ts +13 -4
  222. package/managed/raw/tooling/direnv/setup-environment.ts +128 -537
  223. package/managed/raw/tooling/direnv/toolchain-stamp.ts +4 -2
  224. package/managed/raw/tooling/direnv/ttsc-env.sh +9 -0
  225. package/managed/raw/tooling/direnv/uv-relocation.ts +227 -0
  226. package/managed/raw/tooling/git-hooks/commit-msg.sh +2 -1
  227. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -1
  228. package/managed/raw/tooling/git-hooks/pre-push.sh +2 -1
  229. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +85 -7
  230. package/managed/templates/github/actions/save-nix-devenv/action.yml +12 -2
  231. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  232. package/package.json +77 -13
  233. package/src/bin/smoo-nx-cargo-toolchain.ts +11 -0
  234. package/src/bin/smoo-nx-forbidden-spellings.ts +33 -0
  235. package/src/bin/smoo-nx-nextest-timings.ts +31 -0
  236. package/src/bounded-test-policy.ts +12 -14
  237. package/src/build-state-output-policy.ts +458 -34
  238. package/src/bun-lock-scope.ts +108 -0
  239. package/src/cargo-build-script-env.ts +265 -0
  240. package/src/cargo-closure-input.ts +74 -7
  241. package/src/cargo-retention-hook.ts +94 -0
  242. package/src/cargo-source-hash.ts +138 -41
  243. package/src/cargo-toolchain-paths.ts +95 -0
  244. package/src/cargo-toolchain-policy.ts +49 -5
  245. package/src/cargo-workspace.ts +72 -123
  246. package/src/cross-check-policy.ts +12 -10
  247. package/src/disk-command-policy.ts +1 -0
  248. package/src/ensure-built-receipt.ts +132 -39
  249. package/src/ensure-built-witness.ts +62 -10
  250. package/src/ensure-built.ts +11 -1
  251. package/src/eslint-config-closure.ts +357 -0
  252. package/src/executors/all-verdicts/executor.ts +164 -0
  253. package/src/executors/all-verdicts/schema.json +22 -0
  254. package/src/executors/all-verdicts/schema.ts +10 -0
  255. package/src/executors/bounded-exec/bounds.ts +76 -0
  256. package/src/executors/bounded-exec/cpu-pool.ts +51 -117
  257. package/src/executors/bounded-exec/executor.ts +423 -259
  258. package/src/executors/bounded-exec/gateway-lease.ts +82 -33
  259. package/src/executors/bounded-exec/hang-diagnostics.ts +173 -31
  260. package/src/executors/bounded-exec/lease-wait.ts +89 -0
  261. package/src/executors/bounded-exec/lock-wait.ts +141 -0
  262. package/src/executors/bounded-exec/owned-subtree.ts +235 -0
  263. package/src/executors/bounded-exec/progress.ts +9 -3
  264. package/src/executors/bounded-exec/ram-attach.ts +238 -0
  265. package/src/executors/bounded-exec/ram-detach.ts +226 -0
  266. package/src/executors/bounded-exec/ram-temp-fixtures.ts +358 -0
  267. package/src/executors/bounded-exec/ram-temp-registry.txt +440 -0
  268. package/src/executors/bounded-exec/ram-temp.ts +1497 -460
  269. package/src/executors/bounded-exec/run-cpu-pool.ts +22 -30
  270. package/src/executors/bounded-exec/runner-hook.ts +14 -6
  271. package/src/executors/bounded-exec/runner-lifecycle.ts +31 -8
  272. package/src/executors/bounded-exec/{cpu-tokens.ts → runner-sizing.ts} +13 -59
  273. package/src/executors/bounded-exec/runtime-pin.ts +232 -0
  274. package/src/executors/bounded-exec/schema.json +11 -2
  275. package/src/executors/bounded-exec/schema.ts +19 -1
  276. package/src/executors/bounded-exec/verdict.ts +137 -34
  277. package/src/executors/cargo-zigbuild/executor.ts +82 -8
  278. package/src/executors/clean-outputs/executor.ts +1 -0
  279. package/src/executors/scriptc-native/executor.ts +394 -0
  280. package/src/executors/scriptc-native/ffi-paths.ts +29 -0
  281. package/src/executors/scriptc-native/schema.json +60 -0
  282. package/src/executors/scriptc-native/schema.ts +34 -0
  283. package/src/executors/typescript-emit/executor.ts +205 -38
  284. package/src/forbidden-spelling-policy.ts +226 -0
  285. package/src/generators/create-package/generator.ts +7 -7
  286. package/src/graph-input-contract.ts +61 -2
  287. package/src/index.ts +792 -225
  288. package/src/managed-assets.ts +3 -0
  289. package/src/managed-files/files.ts +28 -3
  290. package/src/managed-files/managed-format.ts +1 -0
  291. package/src/nextest-code-bound.ts +1 -0
  292. package/src/nextest-timings.ts +106 -0
  293. package/src/owned-installation.ts +150 -23
  294. package/src/package-target-policy.ts +2 -3
  295. package/src/process-children.darwin.ts +14 -0
  296. package/src/process-children.linux.ts +33 -0
  297. package/src/process-children.ts +22 -0
  298. package/src/process-group.ts +209 -0
  299. package/src/process-listing.ts +54 -0
  300. package/src/producer-receipts.ts +68 -45
  301. package/src/task-graph-policy.ts +98 -0
  302. package/src/test-walk-policy.ts +23 -8
  303. package/src/testing.ts +240 -232
  304. package/src/tool-bins.ts +108 -0
  305. package/src/typecheck-test-policy.ts +2 -3
  306. package/src/wait-why-policy.ts +226 -0
  307. package/src/workspace-config-policy.ts +63 -15
  308. package/src/workspace-manifest.ts +89 -6
  309. package/test-timings.json +123 -98
  310. package/dist/bin/smoo-nx-failures.d.ts +0 -3
  311. package/dist/bin/smoo-nx-failures.d.ts.map +0 -1
  312. package/dist/bin/smoo-nx-failures.js +0 -3
  313. package/dist/bin/smoo-nx-nextest-extract.d.ts +0 -3
  314. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +0 -1
  315. package/dist/bin/smoo-nx-nextest-extract.js +0 -42
  316. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +0 -1
  317. package/dist/failure-summary.d.ts +0 -5
  318. package/dist/failure-summary.d.ts.map +0 -1
  319. package/dist/failure-summary.js +0 -118
  320. package/dist/nextest-extraction.d.ts +0 -117
  321. package/dist/nextest-extraction.d.ts.map +0 -1
  322. package/dist/nextest-extraction.js +0 -303
  323. package/managed/raw/patches/ttsc@0.30.4.patch +0 -2255
  324. package/src/__tests__/cargo-closure-filesets.ts +0 -94
  325. package/src/__tests__/cargo-closure-fixture.ts +0 -113
  326. package/src/__tests__/counted-cargo-process.ts +0 -286
  327. package/src/__tests__/counted-cargo.ts +0 -713
  328. package/src/__tests__/directory-change.ts +0 -27
  329. package/src/__tests__/fixture-cargo-home.ts +0 -36
  330. package/src/__tests__/fixture-nx-env.ts +0 -193
  331. package/src/__tests__/owned-installation.ts +0 -13
  332. package/src/__tests__/past-tick.ts +0 -12
  333. package/src/__tests__/progress-clock.ts +0 -43
  334. package/src/__tests__/runtime-input.ts +0 -23
  335. package/src/bin/smoo-nx-bound-failures.test.ts +0 -127
  336. package/src/bin/smoo-nx-failures.ts +0 -4
  337. package/src/bin/smoo-nx-nextest-extract.ts +0 -44
  338. package/src/bounded-test-policy.test.ts +0 -1029
  339. package/src/build-state-output-policy.test.ts +0 -115
  340. package/src/bun-bootstrap.test.ts +0 -102
  341. package/src/bun-file-packages.test.ts +0 -47
  342. package/src/cargo-closure-filesets.test.ts +0 -63
  343. package/src/cargo-closure-input.property.test.ts +0 -50
  344. package/src/cargo-closure-input.test.ts +0 -506
  345. package/src/cargo-closure-key.test.ts +0 -240
  346. package/src/cargo-resolve-cache.test.ts +0 -1181
  347. package/src/cargo-source-hash.test.ts +0 -707
  348. package/src/cargo-workspace.test.ts +0 -615
  349. package/src/cross-check-policy.test.ts +0 -316
  350. package/src/disk-command-policy.test.ts +0 -61
  351. package/src/ensure-built-receipt.test.ts +0 -279
  352. package/src/ensure-built-witness.test.ts +0 -688
  353. package/src/ensure-built.test.ts +0 -1462
  354. package/src/executors/bounded-exec/cargo-progress-host.test.ts +0 -332
  355. package/src/executors/bounded-exec/cpu-pool.test.ts +0 -684
  356. package/src/executors/bounded-exec/cpu-tokens.test.ts +0 -519
  357. package/src/executors/bounded-exec/disk-lease.test.ts +0 -219
  358. package/src/executors/bounded-exec/executor-host.test.ts +0 -800
  359. package/src/executors/bounded-exec/executor.test.ts +0 -1819
  360. package/src/executors/bounded-exec/go-progress-host.test.ts +0 -171
  361. package/src/executors/bounded-exec/hang-diagnostics.test.ts +0 -291
  362. package/src/executors/bounded-exec/progress.test.ts +0 -139
  363. package/src/executors/bounded-exec/ram-temp-held.test.ts +0 -264
  364. package/src/executors/bounded-exec/ram-temp-host.test.ts +0 -635
  365. package/src/executors/bounded-exec/ram-temp.test.ts +0 -750
  366. package/src/executors/bounded-exec/run-cpu-pool.test.ts +0 -79
  367. package/src/executors/bounded-exec/runner-hook.test.ts +0 -193
  368. package/src/executors/bounded-exec/runner-lifecycle.test.ts +0 -82
  369. package/src/executors/bounded-exec/verdict.test.ts +0 -545
  370. package/src/executors/cargo-zigbuild/executor.test.ts +0 -129
  371. package/src/executors/clean-outputs/executor.test.ts +0 -20
  372. package/src/executors/typescript-emit/executor.test.ts +0 -83
  373. package/src/failure-summary.ts +0 -119
  374. package/src/generators/bounded-test-targets/generator.test.ts +0 -138
  375. package/src/generators/bun-test-tracing/generator.test.ts +0 -250
  376. package/src/generators/create-package/generator.test.ts +0 -190
  377. package/src/generators/make-public/generator.test.ts +0 -137
  378. package/src/graph-input-contract.test.ts +0 -379
  379. package/src/host-controller-wiring.test.ts +0 -31
  380. package/src/index.test.ts +0 -3319
  381. package/src/linked-snapshots.nx.test.ts +0 -254
  382. package/src/managed-files/forgejo-artifact.test.ts +0 -395
  383. package/src/managed-files/generator.test.ts +0 -243
  384. package/src/managed-files/github-host-cache-isolation.test.ts +0 -86
  385. package/src/managed-files/json-edit.test.ts +0 -216
  386. package/src/managed-files/managed-content.test.ts +0 -166
  387. package/src/managed-files/managed-format-json.test.ts +0 -308
  388. package/src/managed-files/repo-path.test.ts +0 -172
  389. package/src/managed-files/setup-devenv-free-disk.test.ts +0 -95
  390. package/src/managed-files/trace-db-artifact.test.ts +0 -7
  391. package/src/managed-files/tree-permissions.test.ts +0 -109
  392. package/src/managed-files/tree.test.ts +0 -123
  393. package/src/manifest-hash.test.ts +0 -219
  394. package/src/nextest-code-bound.test.ts +0 -161
  395. package/src/nextest-extraction.test.ts +0 -216
  396. package/src/nextest-extraction.ts +0 -371
  397. package/src/nextest-partitions.test.ts +0 -501
  398. package/src/nx-cache-bound.test.ts +0 -109
  399. package/src/nx-cache-restore-mtime.test.ts +0 -170
  400. package/src/nx-daemon-claim.test.ts +0 -279
  401. package/src/nx-daemon-idle-cpu.test.ts +0 -80
  402. package/src/nx-daemon-idle-policy.test.ts +0 -111
  403. package/src/nx-daemon-ignore-files.test.ts +0 -210
  404. package/src/nx-daemon-root-normalization.test.ts +0 -105
  405. package/src/nx-daemon-start-never.test.ts +0 -292
  406. package/src/nx-daemon-validity.test.ts +0 -1055
  407. package/src/nx-dot-input-policy.test.ts +0 -353
  408. package/src/nx-failure-life-cycles.test.ts +0 -207
  409. package/src/nx-files-archive-racy.test.ts +0 -97
  410. package/src/nx-foreign-workspace-env.test.ts +0 -329
  411. package/src/nx-incomplete-run-summary.test.ts +0 -70
  412. package/src/nx-plugin-load-errors.test.ts +0 -120
  413. package/src/nx-project-graph-errors.test.ts +0 -70
  414. package/src/nx-project-resolution-cache.test.ts +0 -176
  415. package/src/nx-raw-inputs.test.ts +0 -166
  416. package/src/nx-resident-graph-workers.test.ts +0 -112
  417. package/src/nx-run-information.test.ts +0 -118
  418. package/src/nx-skipped-task-exit.test.ts +0 -180
  419. package/src/nx-state-location.test.ts +0 -63
  420. package/src/nx-store-resolution.test.ts +0 -81
  421. package/src/nx-task-graph-cycles.test.ts +0 -148
  422. package/src/nx-task-output-lease.test.ts +0 -550
  423. package/src/nx-use-local.test.ts +0 -105
  424. package/src/owned-installation.test.ts +0 -105
  425. package/src/package-target-policy.test.ts +0 -1014
  426. package/src/producer-receipts.test.ts +0 -285
  427. package/src/release-config-policy.test.ts +0 -311
  428. package/src/runtime-input.test.ts +0 -393
  429. package/src/serial-group-wiring.test.ts +0 -326
  430. package/src/task-history-namespace.test.ts +0 -181
  431. package/src/task-results.test.ts +0 -228
  432. package/src/test-clock-policy.test.ts +0 -338
  433. package/src/test-program.test.ts +0 -303
  434. package/src/test-timings.test.ts +0 -240
  435. package/src/test-walk-policy.test.ts +0 -620
  436. package/src/testing.test.ts +0 -509
  437. package/src/typecheck-test-policy.test.ts +0 -1468
  438. package/src/typescript-resolution.test.ts +0 -76
  439. package/src/version-actions.test.ts +0 -80
  440. package/src/workspace-config-policy.test.ts +0 -737
@@ -1,1055 +0,0 @@
1
- import { expect, it } from 'bun:test';
2
- import { type ChildProcess, spawn, spawnSync } from 'node:child_process';
3
- import { watch as fsWatch } from 'node:fs';
4
- import { mkdir, readdir, readFile, rename, rm, symlink, unlink, writeFile } from 'node:fs/promises';
5
- import { createRequire } from 'node:module';
6
- import { createConnection, createServer } from 'node:net';
7
- import { dirname, join } from 'node:path';
8
- import { createInterface } from 'node:readline';
9
- import { setTimeout as sleep } from 'node:timers/promises';
10
- import { sendMessage } from 'nx/src/daemon/socket-utils.js';
11
- import { consumeMessagesFromSocket, parseMessage } from 'nx/src/utils/consume-messages-from-socket.js';
12
- import typia from 'typia';
13
- import { guardEvent } from './__tests__/counted-cargo.js';
14
- import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
15
- import { awaitExit, isRunning, type ProcessEntry, processTable, terminate, withDescendants } from './testing.js';
16
-
17
- /**
18
- * Guards the event-driven validity hunk of `patches/nx@23.2.1.patch` (upstream nrwl/nx#37113, fixing nrwl/nx#37112).
19
- * The installed daemon judged its root lockfiles and installed nx version on a 20 ms timer. These regressions preserve
20
- * the existing socket and process ownership guards while moving lockfile checks to applied watcher events, request
21
- * boundaries, and a 5 s safety poll for events the watcher ignores or drops.
22
- *
23
- * Each test runs a real daemon in a fixture workspace and asserts only what a client, a watcher, or the filesystem can
24
- * observe. Restarts are awaited on the record directory, and readiness on an actual PING answer, not a filesystem event.
25
- * The one real-clock observation window is the idle walk in the last test.
26
- */
27
-
28
- const repositoryRoot = join(import.meta.dir, '../../..');
29
- const nxEntry = join(repositoryRoot, 'node_modules', '.bin', 'nx');
30
- const requireNx = createRequire(join(repositoryRoot, 'package.json'));
31
- const daemonClient = requireNx.resolve('nx/src/daemon/client/client');
32
- const daemonStart = requireNx.resolve('nx/src/daemon/server/start.js');
33
- const daemonServer = join(dirname(daemonStart), 'server.js');
34
-
35
- /** The root lockfiles the daemon validates. */
36
- const LOCKFILES = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock'] as const;
37
- /** The fixture's workspace directory under its root, so installed-package copies sit outside the workspace. */
38
- const FIXTURE_WORKSPACE = 'workspace';
39
- /** The idle observation window, longer than the 5 s safety poll so one poll would fall inside it. */
40
- const OBSERVATION_MS = 6_000;
41
-
42
- interface DaemonRecord {
43
- readonly processId: number;
44
- readonly socketPath: string;
45
- }
46
-
47
- interface Daemon {
48
- readonly record: DaemonRecord;
49
- readonly entry: ProcessEntry;
50
- }
51
-
52
- interface Manifest {
53
- readonly version: string;
54
- readonly [field: string]: unknown;
55
- }
56
-
57
- interface DaemonRequest {
58
- readonly type: 'PING' | 'REQUEST_PROJECT_GRAPH';
59
- readonly workspaceRoot: string;
60
- }
61
-
62
- /** A served answer, or the reason the daemon did not answer on this connection. */
63
- type Answer =
64
- | { readonly answered: true; readonly message: unknown }
65
- | { readonly answered: false; readonly reason: string };
66
-
67
- interface RawClient {
68
- request(message: DaemonRequest, what: string): Promise<Answer>;
69
- close(): void;
70
- }
71
-
72
- interface Listener {
73
- readonly pid: number;
74
- stop(): Promise<void>;
75
- }
76
-
77
- interface Replacement {
78
- readonly workspace: string;
79
- /** The pid the record must stop naming; absent when no daemon has published a record yet. */
80
- readonly previous?: number;
81
- /** Runs once the directory watch is open. */
82
- readonly action?: () => Promise<void>;
83
- readonly what: string;
84
- }
85
-
86
- /** One line per event the watch client saw: its kind, then the tab-separated details. */
87
- interface WatchEvent {
88
- readonly kind: string;
89
- readonly details: readonly string[];
90
- }
91
-
92
- const CLIENT = `
93
- const { writeSync } = require('node:fs');
94
- const { daemonClient } = require(process.env.NX_DAEMON_CLIENT);
95
- const say = (...fields) => writeSync(1, fields.join('\\t') + '\\n');
96
- daemonClient
97
- .registerFileWatcher({ watchProjects: 'all', includeGlobalWorkspaceFiles: true }, (error, data) => {
98
- if (error === 'reconnecting' || error === 'closed') {
99
- say(error);
100
- process.exit(0);
101
- }
102
- if (error !== null) {
103
- say('error', String(error));
104
- process.exit(1);
105
- }
106
- say('changed', ...data.changedFiles.map(({ path }) => path));
107
- })
108
- .then(() => say('ready'), (error) => {
109
- say('error', String(error));
110
- process.exit(1);
111
- });
112
- `;
113
-
114
- /**
115
- * A process that stands in as a successor: it listens on the socket path it is given, and reports so on stdout. The
116
- * listening server keeps the process alive.
117
- */
118
- const LISTENER = [
119
- "const { createServer } = require('node:net');",
120
- "createServer(() => {}).listen(process.argv[1], () => process.stdout.write('listening\\n'));",
121
- ].join('\n');
122
-
123
- /**
124
- * Preloaded into the daemon. It records each call that reads a lockfile by name, the record file, or a socket, through
125
- * the fs functions the old 20 ms loop used. It writes with `writeSync` on a descriptor opened before it wraps anything.
126
- */
127
- const PROBE = `
128
- const fs = require('node:fs');
129
- const path = require('node:path');
130
- const locks = ${JSON.stringify(Object.fromEntries(LOCKFILES.map((name) => [name, true])))};
131
- const sink = fs.openSync(process.env.NX_VALIDITY_LOG, 'a');
132
- const write = (line) => fs.writeSync(sink, line + '\\n');
133
- const classify = (file) => {
134
- if (typeof file !== 'string') return undefined;
135
- const name = path.basename(file);
136
- if (locks[name] === true) return 'lock';
137
- if (name === 'server-process.json') return 'record';
138
- if (name.endsWith('.sock')) return 'socket';
139
- return undefined;
140
- };
141
- write('attached');
142
- for (const name of ['existsSync', 'statSync', 'lstatSync', 'readFileSync', 'openSync']) {
143
- const original = fs[name];
144
- fs[name] = function (file, ...rest) {
145
- const kind = classify(file);
146
- if (kind !== undefined) write(kind + ' ' + name + ' ' + file);
147
- return original.call(fs, file, ...rest);
148
- };
149
- }
150
- `;
151
-
152
- function recordPath(workspace: string): string {
153
- return join(workspace, '.nx', 'workspace-data', 'd', 'server-process.json');
154
- }
155
-
156
- /** A missing path (ENOENT) or a socket nothing listens on (ECONNREFUSED): the record or the daemon is absent. */
157
- function isAbsent(error: unknown): boolean {
158
- if (typeof error !== 'object' || error === null || !('code' in error)) return false;
159
- return error.code === 'ENOENT' || error.code === 'ECONNREFUSED';
160
- }
161
-
162
- function gone(reason: string): Answer {
163
- return { answered: false, reason };
164
- }
165
-
166
- function ping(workspace: string): DaemonRequest {
167
- return { type: 'PING', workspaceRoot: workspace };
168
- }
169
-
170
- async function daemonRecord(workspace: string): Promise<DaemonRecord | null> {
171
- let text: string;
172
- try {
173
- text = await readFile(recordPath(workspace), 'utf8');
174
- } catch (error) {
175
- if (isAbsent(error)) return null;
176
- throw error;
177
- }
178
- return typia.json.assertParse<DaemonRecord>(text);
179
- }
180
-
181
- async function recordedPid(workspace: string): Promise<number> {
182
- const record = await daemonRecord(workspace);
183
- if (record === null) throw new Error(`no daemon record at ${recordPath(workspace)}`);
184
- return record.processId;
185
- }
186
-
187
- async function installedManifest(): Promise<Manifest> {
188
- return typia.json.assertParse<Manifest>(
189
- await readFile(join(repositoryRoot, 'node_modules', 'nx', 'package.json'), 'utf8'),
190
- );
191
- }
192
-
193
- function nx(workspace: string, env: Record<string, string>, ...args: string[]): string {
194
- const result = spawnSync('bun', [nxEntry, ...args], { cwd: workspace, env, encoding: 'utf8' });
195
- expect(result.status, `nx ${args.join(' ')} failed:\n${result.stdout}\n${result.stderr}`).toBe(0);
196
- return result.stdout;
197
- }
198
-
199
- /** A fixture-owned `node_modules`: every entry links to the repository's, except `nx`, which links to `nxPackage`. */
200
- async function linkedModules(workspace: string, nxPackage: string): Promise<void> {
201
- const modules = join(workspace, 'node_modules');
202
- await mkdir(modules);
203
- for (const entry of await readdir(join(repositoryRoot, 'node_modules'))) {
204
- if (entry !== 'nx') await symlink(join(repositoryRoot, 'node_modules', entry), join(modules, entry), 'dir');
205
- }
206
- await symlink(nxPackage, join(modules, 'nx'), 'dir');
207
- }
208
-
209
- /** A fixture-owned copy of the installed `nx` package, with `version` in its manifest and the repository's `dist`. */
210
- async function nxPackageCopy(directory: string, version: string): Promise<void> {
211
- await mkdir(directory);
212
- const manifest = await installedManifest();
213
- await writeFile(join(directory, 'package.json'), JSON.stringify({ ...manifest, version }));
214
- await symlink(join(repositoryRoot, 'node_modules', 'nx', 'dist'), join(directory, 'dist'), 'dir');
215
- }
216
-
217
- /** A project in the workspace; `node_modules` is the repository's, or a fixture-owned copy when `nxPackage` is given. */
218
- async function fixtureWorkspace(workspace: string, nxPackage?: string): Promise<void> {
219
- if (nxPackage === undefined) {
220
- await symlink(join(repositoryRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
221
- } else {
222
- await linkedModules(workspace, nxPackage);
223
- }
224
- await writeFile(join(workspace, 'nx.json'), '{}\n');
225
- await writeFile(join(workspace, 'package.json'), '{"name":"fixture","private":true}\n');
226
- await mkdir(join(workspace, 'p'));
227
- await writeFile(join(workspace, 'p', 'project.json'), '{"name":"p"}\n');
228
- }
229
-
230
- async function processEntry(pid: number): Promise<ProcessEntry> {
231
- const entry = (await processTable()).find((candidate) => candidate.pid === pid);
232
- if (entry === undefined) throw new Error(`process ${pid} is not in the process table`);
233
- return entry;
234
- }
235
-
236
- async function stopChild(child: ChildProcess): Promise<void> {
237
- if (child.exitCode !== null || child.signalCode !== null) return;
238
- const exited = Promise.withResolvers<void>();
239
- child.once('exit', () => exited.resolve());
240
- if (child.pid !== undefined) terminate(child.pid);
241
- await exited.promise;
242
- }
243
-
244
- /** A raw IPC connection that stays open, so one client can send across a lockfile change. */
245
- function openClient(socketPath: string): Promise<RawClient> {
246
- const socket = createConnection(socketPath);
247
- const opened = Promise.withResolvers<RawClient>();
248
- let waiting: ((answer: Answer) => void) | undefined;
249
- const settle = (answer: Answer): void => {
250
- const resolve = waiting;
251
- waiting = undefined;
252
- resolve?.(answer);
253
- };
254
- socket.on(
255
- 'data',
256
- consumeMessagesFromSocket(
257
- (message) => settle({ answered: true, message: parseMessage(message) }),
258
- (error) => settle(gone(String(error))),
259
- ),
260
- );
261
- socket.once('error', (error) => settle(gone(error.message)));
262
- socket.once('close', () => settle(gone('the daemon closed the connection')));
263
- socket.once('connect', () =>
264
- opened.resolve({
265
- request(message, what) {
266
- if (socket.destroyed) return Promise.resolve(gone('the connection was already closed'));
267
- const answer = Promise.withResolvers<Answer>();
268
- waiting = answer.resolve;
269
- sendMessage(socket, message, 'json');
270
- return guardEvent(answer.promise, what, () => `socket ${socketPath}`);
271
- },
272
- close() {
273
- socket.destroy();
274
- },
275
- }),
276
- );
277
- socket.once('error', opened.reject);
278
- return opened.promise;
279
- }
280
-
281
- /** One PING or request on a fresh connection. A daemon that is gone answers `gone`. */
282
- async function requestOnce(socketPath: string, request: DaemonRequest, what: string): Promise<Answer> {
283
- let client: RawClient;
284
- try {
285
- client = await openClient(socketPath);
286
- } catch (error) {
287
- if (isAbsent(error)) return gone(`nothing listens on ${socketPath}: ${String(error)}`);
288
- throw error;
289
- }
290
- try {
291
- return await client.request(request, what);
292
- } finally {
293
- client.close();
294
- }
295
- }
296
-
297
- /** Whether a process accepts connections on `socketPath`. */
298
- async function acceptsConnections(socketPath: string): Promise<boolean> {
299
- try {
300
- (await openClient(socketPath)).close();
301
- return true;
302
- } catch (error) {
303
- if (isAbsent(error)) return false;
304
- throw error;
305
- }
306
- }
307
-
308
- /** A served answer is one that is not an error. A stale daemon must answer with an error, or not at all. */
309
- function assertNotServed(answer: Answer, what: string): void {
310
- if (!answer.answered) return;
311
- if (typeof answer.message === 'object' && answer.message !== null && 'error' in answer.message) return;
312
- throw new Error(`${what} was served by a daemon that should have stopped: ${JSON.stringify(answer.message)}`);
313
- }
314
-
315
- /**
316
- * Runs `action` once a watch on `directory` is open, then resolves with the first non-null `check`. Each pass runs
317
- * `check` before it waits, so a change at any point, including while `action` runs, is seen.
318
- */
319
- async function watchUntil<T>(
320
- directory: string,
321
- what: string,
322
- check: () => Promise<T | null>,
323
- action?: () => Promise<void>,
324
- ): Promise<T> {
325
- await mkdir(directory, { recursive: true });
326
- let notify: (() => void) | undefined;
327
- const watcher = fsWatch(directory, () => notify?.());
328
- try {
329
- await action?.();
330
- for (;;) {
331
- const changed = Promise.withResolvers<void>();
332
- notify = () => changed.resolve();
333
- const found = await check();
334
- if (found !== null) return found;
335
- await guardEvent(changed.promise, what, () => `no change in ${directory}`);
336
- }
337
- } finally {
338
- watcher.close();
339
- }
340
- }
341
-
342
- /** Capture the expected holder and the current record before fixture retirement removes the evidence. */
343
- async function daemonDiagnostics(workspace: string, expectedPid: number): Promise<string> {
344
- const [record, table] = await Promise.all([daemonRecord(workspace), processTable()]);
345
- const expected = table.find(({ pid }) => pid === expectedPid);
346
- const processes = withDescendants(table, record === null ? [expectedPid] : [expectedPid, record.processId]);
347
- const logPath = join(dirname(recordPath(workspace)), 'daemon.log');
348
- let log: string;
349
- try {
350
- log = await readFile(logPath, 'utf8');
351
- } catch (error) {
352
- log = `unavailable: ${error instanceof Error ? error.message : String(error)}`;
353
- }
354
- return [
355
- `workspace ${workspace}; expected daemon pid ${expectedPid}: ${
356
- expected === undefined ? 'absent from process table' : `state=${expected.stat} command=${expected.command}`
357
- }`,
358
- `current daemon record ${JSON.stringify(record)}`,
359
- `daemon processes ${JSON.stringify(processes)}`,
360
- `daemon log tail ${logPath}:\n${log.split('\n').slice(-60).join('\n')}`,
361
- ].join('\n');
362
- }
363
-
364
- /**
365
- * The record and socket path can exist before a daemon can answer. Binding, listening and closing a connection need not
366
- * emit another directory event, so readiness probes the protocol itself; only a true PING advances the fixture.
367
- */
368
- async function untilServing(record: DaemonRecord, workspace: string): Promise<void> {
369
- const { socketPath } = record;
370
- const waiting = new AbortController();
371
- const serving = async (): Promise<void> => {
372
- while (!waiting.signal.aborted) {
373
- const answer = await requestOnce(socketPath, ping(workspace), 'the readiness PING');
374
- if (answer.answered) {
375
- if (answer.message === true) return;
376
- throw new Error(`the daemon on ${socketPath} answered PING with ${JSON.stringify(answer.message)}, not true`);
377
- }
378
- await sleep(50, undefined, { signal: waiting.signal });
379
- }
380
- };
381
- try {
382
- await guardEvent(serving(), `the daemon on ${socketPath} to answer PING`, () =>
383
- daemonDiagnostics(workspace, record.processId),
384
- );
385
- } finally {
386
- waiting.abort();
387
- }
388
- }
389
-
390
- async function readyDaemon(workspace: string, record: DaemonRecord): Promise<Daemon> {
391
- await untilServing(record, workspace);
392
- return { record, entry: await processEntry(record.processId) };
393
- }
394
-
395
- async function startDaemon(workspace: string, env: Record<string, string>): Promise<Daemon> {
396
- nx(workspace, env, 'daemon', '--start');
397
- const record = await daemonRecord(workspace);
398
- if (record === null) throw new Error('nx daemon --start left no daemon record');
399
- return readyDaemon(workspace, record);
400
- }
401
-
402
- /**
403
- * Runs `action`, then resolves with the record that names a process other than `previous`. The record directory is
404
- * watched before `action` runs, so a record written at any point is seen.
405
- */
406
- function replacementAfter({ workspace, previous, action, what }: Replacement): Promise<DaemonRecord> {
407
- return watchUntil(
408
- dirname(recordPath(workspace)),
409
- what,
410
- async () => {
411
- const record = await daemonRecord(workspace);
412
- return record !== null && record.processId !== previous ? record : null;
413
- },
414
- action,
415
- );
416
- }
417
-
418
- /** Runs `action` under a daemon that must judge the change in place, then awaits the old daemon's exit and the new one. */
419
- async function restarted(
420
- workspace: string,
421
- daemon: Daemon,
422
- what: string,
423
- action: () => Promise<void>,
424
- ): Promise<Daemon> {
425
- const record = await replacementAfter({
426
- workspace,
427
- previous: daemon.record.processId,
428
- action,
429
- what: `the daemon to restart after ${what}`,
430
- });
431
- await awaitExit([daemon.entry], `daemon ${daemon.record.processId} replaced after ${what}`);
432
- return readyDaemon(workspace, record);
433
- }
434
-
435
- /**
436
- * A file-watcher client of the workspace's daemon, read one event at a time. The fixture environment turns NX_DAEMON
437
- * off, so this client turns it back on: its watcher must reach the daemon under test, not an in-process Nx.
438
- */
439
- function watchClient(workspace: string, env: Record<string, string>) {
440
- const child = spawn('node', ['-e', CLIENT], {
441
- cwd: workspace,
442
- env: { ...env, NX_DAEMON: 'true', NX_DAEMON_CLIENT: daemonClient },
443
- stdio: ['ignore', 'pipe', 'pipe'],
444
- });
445
- let stderr = '';
446
- child.stderr.setEncoding('utf8').on('data', (text: string) => {
447
- stderr += text;
448
- });
449
- const seen: WatchEvent[] = [];
450
- const lines = createInterface({ input: child.stdout })[Symbol.asyncIterator]();
451
- const exited = Promise.withResolvers<number | null>();
452
- child.once('exit', (code) => exited.resolve(code));
453
- return {
454
- seen,
455
- async next(what: string): Promise<WatchEvent> {
456
- const line = await guardEvent(lines.next(), what, () => `events so far ${JSON.stringify(seen)}\n${stderr}`);
457
- if (line.done) throw new Error(`the watch client ended before ${what}: ${JSON.stringify(seen)}\n${stderr}`);
458
- const [kind = '', ...details] = line.value.split('\t');
459
- const event = { kind, details };
460
- seen.push(event);
461
- return event;
462
- },
463
- async end(): Promise<void> {
464
- if (child.pid !== undefined && child.exitCode === null && child.signalCode === null) terminate(child.pid);
465
- await exited.promise;
466
- },
467
- };
468
- }
469
-
470
- /**
471
- * Runs `change` under a file-watcher client of the daemon, then writes a marker the watcher must report. Watch events
472
- * arrive in order, so once the marker is reported the change was judged too. The daemon must still be the same process.
473
- */
474
- async function quietAfter(
475
- workspace: string,
476
- env: Record<string, string>,
477
- daemon: Daemon,
478
- what: string,
479
- marker: string,
480
- change: () => Promise<void>,
481
- ): Promise<void> {
482
- const client = watchClient(workspace, env);
483
- try {
484
- expect(await client.next(`the file watcher registering before ${what}`)).toEqual({ kind: 'ready', details: [] });
485
- await change();
486
- await writeFile(join(workspace, 'p', marker), 'marker\n');
487
- for (;;) {
488
- const event = await client.next(`the file watcher reporting ${marker} after ${what}`);
489
- expect(
490
- event.kind,
491
- `${what} made the daemon stop instead of judging the change in place: ${JSON.stringify(client.seen)}`,
492
- ).toBe('changed');
493
- if (event.details.includes(`p/${marker}`)) break;
494
- }
495
- } finally {
496
- await client.end();
497
- }
498
- expect(await recordedPid(workspace), `${what} replaced the daemon`).toBe(daemon.record.processId);
499
- expect(isRunning(daemon.record.processId), `${what} stopped the daemon`).toBe(true);
500
- }
501
-
502
- /** A process that listens on `socketPath`, started after the path is free. */
503
- async function listeningChild(socketPath: string): Promise<Listener> {
504
- const child = spawn('node', ['-e', LISTENER, socketPath], { stdio: ['ignore', 'pipe', 'pipe'] });
505
- const pid = child.pid;
506
- if (pid === undefined) throw new Error(`could not start the listener for ${socketPath}`);
507
- let stderr = '';
508
- child.stderr.setEncoding('utf8').on('data', (text: string) => {
509
- stderr += text;
510
- });
511
- const lines = createInterface({ input: child.stdout })[Symbol.asyncIterator]();
512
- const first = await guardEvent(lines.next(), `the listener on ${socketPath} to start`, () => `stderr:\n${stderr}`);
513
- if (first.done || first.value !== 'listening') {
514
- throw new Error(`the listener on ${socketPath} did not report listening: ${JSON.stringify(first)}\n${stderr}`);
515
- }
516
- return { pid, stop: () => stopChild(child) };
517
- }
518
-
519
- /** Binds `socketPath` from this process, so the replacement exists before a daemon's exit could remove it. */
520
- async function listenInProcess(socketPath: string): Promise<() => Promise<void>> {
521
- const server = createServer(() => {});
522
- const listening = Promise.withResolvers<void>();
523
- server.once('error', listening.reject);
524
- server.listen(socketPath, () => listening.resolve());
525
- await guardEvent(listening.promise, `this process to listen on ${socketPath}`, () => 'no listen callback');
526
- return () => {
527
- const closed = Promise.withResolvers<void>();
528
- server.close(() => closed.resolve());
529
- return closed.promise;
530
- };
531
- }
532
-
533
- it('has no 20 ms outdated-check loop or lockfile hashing left in the installed daemon', async () => {
534
- const source = await readFile(daemonServer, 'utf8');
535
- for (const removed of [
536
- 'lockFileHashChanged',
537
- 'daemonIsOutdated',
538
- 'existingLockHash',
539
- 'outdated check interval (20ms)',
540
- ]) {
541
- expect(source.includes(removed), `${daemonServer} still contains ${removed}`).toBe(false);
542
- }
543
- });
544
-
545
- it('awaits an answerable daemon after a closed PING without another socket-directory event', async () => {
546
- await withNxFixture('nx-daemon-validity-readiness-', async ({ socketDirectory, workspace }) => {
547
- await fixtureWorkspace(workspace);
548
- await mkdir(socketDirectory, { recursive: true });
549
- const socketPath = join(socketDirectory, 'readiness.sock');
550
- let requests = 0;
551
- const server = createServer((socket) => {
552
- socket.once('data', () => {
553
- requests += 1;
554
- if (requests === 1) socket.end();
555
- else sendMessage(socket, true, 'json');
556
- });
557
- });
558
- const listening = Promise.withResolvers<void>();
559
- server.once('error', listening.reject);
560
- server.listen(socketPath, () => listening.resolve());
561
- await listening.promise;
562
- try {
563
- await untilServing({ processId: process.pid, socketPath }, workspace);
564
- expect(requests).toBe(2);
565
- } finally {
566
- const closed = Promise.withResolvers<void>();
567
- server.close(() => closed.resolve());
568
- await closed.promise;
569
- }
570
- });
571
- });
572
-
573
- /** Valid lockfiles keep the real graph usable while the watcher judges byte changes. */
574
- async function lockContents(
575
- lockfile: (typeof LOCKFILES)[number],
576
- root: string,
577
- ): Promise<readonly [Buffer, Buffer, Buffer]> {
578
- let text: string;
579
- switch (lockfile) {
580
- case 'package-lock.json':
581
- text = '{"name":"fixture","lockfileVersion":3,"requires":true,"packages":{"":{"name":"fixture"}}}\n';
582
- break;
583
- case 'yarn.lock':
584
- text = '# yarn lockfile v1\n';
585
- break;
586
- case 'pnpm-lock.yaml':
587
- text = "lockfileVersion: '9.0'\nimporters:\n .: {}\npackages: {}\nsnapshots: {}\n";
588
- break;
589
- case 'bun.lock':
590
- text = '{"lockfileVersion":1,"workspaces":{"":{"name":"fixture"}},"packages":{}}\n';
591
- break;
592
- case 'bun.lockb': {
593
- // Generate the legacy binary with Bun, outside the watched workspace.
594
- const generator = join(root, 'lock-generator');
595
- await mkdir(generator);
596
- await writeFile(join(generator, 'bunfig.toml'), '[install]\nsaveTextLockfile = false\n');
597
- const generated: Buffer[] = [];
598
- for (const version of ['1.0.0', '1.0.1', '1.0.2']) {
599
- const dependency = join(root, `lock-dependency-${version}`);
600
- await mkdir(dependency);
601
- await writeFile(
602
- join(generator, 'package.json'),
603
- JSON.stringify({
604
- name: 'fixture',
605
- dependencies: { 'lock-dependency': `file:../lock-dependency-${version}` },
606
- }),
607
- );
608
- await writeFile(join(dependency, 'package.json'), JSON.stringify({ name: 'lock-dependency', version }));
609
- await rm(join(generator, 'bun.lockb'), { force: true });
610
- const result = spawnSync('bun', ['install', '--lockfile-only', '--ignore-scripts', '--offline'], {
611
- cwd: generator,
612
- encoding: 'utf8',
613
- });
614
- expect(result.status, result.stdout + result.stderr).toBe(0);
615
- generated.push(await readFile(join(generator, 'bun.lockb')));
616
- }
617
- const [one, two, three] = generated;
618
- if (one === undefined || two === undefined || three === undefined)
619
- throw new Error('Bun generated fewer than three lockfiles');
620
- expect(one.equals(two)).toBe(false);
621
- expect(two.equals(three)).toBe(false);
622
- return [one, two, three];
623
- }
624
- }
625
- return [Buffer.from(text), Buffer.from(`${text}\n`), Buffer.from(`${text}\n\n`)];
626
- }
627
-
628
- for (const lockfile of LOCKFILES) {
629
- it(`restarts the daemon on ${lockfile} create, change, replace, and delete, and only then`, async () => {
630
- await withNxFixture(
631
- 'nx-daemon-validity-lock-',
632
- async ({ root, socketDirectory, workspace }) => {
633
- if (lockfile === 'pnpm-lock.yaml') {
634
- // pnpm's parser requires its hoisting metadata, even with no packages.
635
- // Keep the installation directory fixture-owned, never write through the repository link.
636
- await fixtureWorkspace(workspace, join(repositoryRoot, 'node_modules/nx'));
637
- await writeFile(join(workspace, 'node_modules/.modules.yaml'), 'hoistedDependencies: {}\n');
638
- } else {
639
- await fixtureWorkspace(workspace);
640
- }
641
- const env = fixtureNxEnv(workspace, socketDirectory);
642
- const lock = join(workspace, lockfile);
643
- const [one, two, three] = await lockContents(lockfile, root);
644
- let daemon = await startDaemon(workspace, env);
645
- daemon = await restarted(workspace, daemon, `creating ${lockfile}`, () => writeFile(lock, one));
646
- daemon = await restarted(workspace, daemon, `changing ${lockfile}`, () => writeFile(lock, two));
647
- daemon = await restarted(workspace, daemon, `replacing ${lockfile} by rename`, async () => {
648
- await writeFile(`${lock}.next`, three);
649
- await rename(`${lock}.next`, lock);
650
- });
651
- await quietAfter(workspace, env, daemon, `a same-bytes rewrite of ${lockfile}`, 'same-bytes.txt', () =>
652
- writeFile(lock, three),
653
- );
654
- await quietAfter(workspace, env, daemon, `a nested ${lockfile} in p`, 'nested.txt', () =>
655
- writeFile(join(workspace, 'p', lockfile), one),
656
- );
657
- await restarted(workspace, daemon, `deleting ${lockfile}`, () => rm(lock));
658
- },
659
- FIXTURE_WORKSPACE,
660
- );
661
- });
662
- }
663
-
664
- it('does not serve a request sent on a connection opened before a lockfile change', async () => {
665
- await withNxFixture(
666
- 'nx-daemon-validity-held-',
667
- async ({ socketDirectory, workspace }) => {
668
- await fixtureWorkspace(workspace);
669
- const lock = join(workspace, 'yarn.lock');
670
- await writeFile(lock, 'lock one\n');
671
- const env = fixtureNxEnv(workspace, socketDirectory);
672
- const daemon = await startDaemon(workspace, env);
673
- const held = await openClient(daemon.record.socketPath);
674
- try {
675
- expect(await held.request(ping(workspace), 'the first PING on the held connection')).toEqual({
676
- answered: true,
677
- message: true,
678
- });
679
- await writeFile(lock, 'lock two\n');
680
- assertNotServed(
681
- await held.request(
682
- { type: 'REQUEST_PROJECT_GRAPH', workspaceRoot: workspace },
683
- 'the graph request sent right after the lockfile change',
684
- ),
685
- 'a graph request on a connection opened before the lockfile change',
686
- );
687
- } finally {
688
- held.close();
689
- }
690
- await awaitExit([daemon.entry], `daemon ${daemon.record.processId} after the held lockfile change`);
691
- await replacementAfter({
692
- workspace,
693
- previous: daemon.record.processId,
694
- what: 'the daemon to restart after the held lockfile change',
695
- });
696
- },
697
- FIXTURE_WORKSPACE,
698
- );
699
- });
700
-
701
- it('stops a kept daemon on a lockfile change instead of spawning a successor its keeper does not own', async () => {
702
- await withNxFixture(
703
- 'nx-daemon-validity-kept-',
704
- async ({ socketDirectory, workspace }) => {
705
- await fixtureWorkspace(workspace);
706
- const lock = join(workspace, 'yarn.lock');
707
- await writeFile(lock, 'lock one\n');
708
- const env = fixtureNxEnv(workspace, socketDirectory);
709
- // As cowshed's keeper job starts it: the daemon's own entry in the foreground, kept.
710
- const kept = spawn('node', [daemonStart, '--kept'], { cwd: workspace, env, stdio: ['ignore', 'pipe', 'pipe'] });
711
- let log = '';
712
- kept.stdout.setEncoding('utf8').on('data', (text: string) => {
713
- log += text;
714
- });
715
- kept.stderr.setEncoding('utf8').on('data', (text: string) => {
716
- log += text;
717
- });
718
- const exited = Promise.withResolvers<number | null>();
719
- kept.once('exit', (code) => exited.resolve(code));
720
- try {
721
- const record = await watchUntil(
722
- dirname(recordPath(workspace)),
723
- 'the kept daemon to write its record',
724
- async () => {
725
- const current = await daemonRecord(workspace);
726
- return current !== null && current.processId === kept.pid ? current : null;
727
- },
728
- async () => {},
729
- );
730
- const daemon = await readyDaemon(workspace, record);
731
- await writeFile(lock, 'lock two\n');
732
- assertNotServed(
733
- await requestOnce(daemon.record.socketPath, ping(workspace), 'a PING sent after the lockfile changed'),
734
- 'a PING sent to the kept daemon after the lockfile changed',
735
- );
736
- await guardEvent(exited.promise, 'the kept daemon to exit after the lockfile changed', () => log);
737
- // The decision is in the daemon's own log, written before it exits: it stopped, and started nothing.
738
- expect(log, 'the kept daemon did not say it left its successor to its keeper').toContain(
739
- 'Stopping: the process that started this daemon (--kept) starts its successor',
740
- );
741
- expect(log, 'the kept daemon spawned a successor of its own').not.toContain('Restarting daemon');
742
- expect(log, 'the kept daemon spawned a successor of its own').not.toContain('Started new daemon process');
743
- } finally {
744
- if (kept.exitCode === null && kept.signalCode === null && kept.pid !== undefined) terminate(kept.pid);
745
- await exited.promise;
746
- }
747
- },
748
- FIXTURE_WORKSPACE,
749
- );
750
- });
751
-
752
- it('stops a daemon at the next request after an ignored lockfile changes, then its successor within its safety poll with no request', async () => {
753
- await withNxFixture(
754
- 'nx-daemon-validity-ignored-',
755
- async ({ socketDirectory, workspace }) => {
756
- await fixtureWorkspace(workspace);
757
- await writeFile(join(workspace, '.gitignore'), 'yarn.lock\n');
758
- const lock = join(workspace, 'yarn.lock');
759
- await writeFile(lock, 'lock one\n');
760
- const env = fixtureNxEnv(workspace, socketDirectory);
761
- const daemon = await startDaemon(workspace, env);
762
- // The watcher never reports an ignored lockfile; the next request is what judges this change.
763
- await writeFile(lock, 'lock two\n');
764
- assertNotServed(
765
- await requestOnce(daemon.record.socketPath, ping(workspace), 'a PING sent after the ignored lockfile changed'),
766
- 'a PING sent after the ignored lockfile changed',
767
- );
768
- await awaitExit(
769
- [daemon.entry],
770
- `daemon ${daemon.record.processId} after the ignored lockfile changed and a PING followed`,
771
- );
772
- const record = await replacementAfter({
773
- workspace,
774
- previous: daemon.record.processId,
775
- what: 'the daemon to restart after the ignored lockfile changed and a PING followed',
776
- });
777
- // The successor booted with 'lock two' on disk, so that is its baseline; a daemon answers a PING only when its
778
- // check finds the lock unchanged, and nothing requests this one afterwards.
779
- const successor = await readyDaemon(workspace, record);
780
- expect(
781
- await recordedPid(workspace),
782
- 'the successor was replaced before the lockfile changed again, so no replacement could show the safety poll',
783
- ).toBe(successor.record.processId);
784
- // Nothing requests the successor after this write and its watcher ignores the file, so only the 5 s safety
785
- // poll can judge 'lock three'.
786
- await replacementAfter({
787
- workspace,
788
- previous: successor.record.processId,
789
- action: () => writeFile(lock, 'lock three\n'),
790
- what: 'a replacement of the successor within the 5 s safety poll after an ignored lockfile change',
791
- });
792
- await awaitExit(
793
- [successor.entry],
794
- `successor ${successor.record.processId} after the ignored lockfile changed with no request`,
795
- );
796
- },
797
- FIXTURE_WORKSPACE,
798
- );
799
- });
800
-
801
- it('stops a daemon, refusing its next request, once the installed nx version changes in place', async () => {
802
- await withNxFixture(
803
- 'nx-daemon-validity-version-',
804
- async ({ root, socketDirectory, workspace }) => {
805
- const installed = join(root, 'installed-nx');
806
- const manifest = await installedManifest();
807
- await nxPackageCopy(installed, manifest.version);
808
- await fixtureWorkspace(workspace, installed);
809
- const env = fixtureNxEnv(workspace, socketDirectory);
810
- const daemon = await startDaemon(workspace, env);
811
- await writeFile(
812
- join(installed, 'package.json'),
813
- JSON.stringify({ ...manifest, version: `${manifest.version}-validity` }),
814
- );
815
- assertNotServed(
816
- await requestOnce(
817
- daemon.record.socketPath,
818
- ping(workspace),
819
- 'a PING sent after the installed nx version changed',
820
- ),
821
- 'a PING sent after the installed nx version changed',
822
- );
823
- await awaitExit([daemon.entry], `daemon ${daemon.record.processId} after the installed nx version changed`);
824
- },
825
- FIXTURE_WORKSPACE,
826
- );
827
- });
828
-
829
- it('stops a daemon once the workspace nx link points at a different version', async () => {
830
- await withNxFixture(
831
- 'nx-daemon-validity-link-',
832
- async ({ root, socketDirectory, workspace }) => {
833
- const first = join(root, 'installed-nx');
834
- const second = join(root, 'replacement-nx');
835
- const manifest = await installedManifest();
836
- await nxPackageCopy(first, manifest.version);
837
- await nxPackageCopy(second, `${manifest.version}-validity`);
838
- await fixtureWorkspace(workspace, first);
839
- const env = fixtureNxEnv(workspace, socketDirectory);
840
- const daemon = await startDaemon(workspace, env);
841
- const link = join(workspace, 'node_modules', 'nx');
842
- await unlink(link);
843
- await symlink(second, link, 'dir');
844
- assertNotServed(
845
- await requestOnce(daemon.record.socketPath, ping(workspace), 'a PING sent after the nx link changed'),
846
- 'a PING sent after the nx link changed',
847
- );
848
- await awaitExit([daemon.entry], `daemon ${daemon.record.processId} after the nx link changed`);
849
- },
850
- FIXTURE_WORKSPACE,
851
- );
852
- });
853
-
854
- it('restarts a daemon once a plugin linked from outside the workspace changes its bytes, in place or by a moved link, and only then', async () => {
855
- await withNxFixture(
856
- 'nx-daemon-validity-plugin-',
857
- async ({ root, socketDirectory, workspace }) => {
858
- const inference = (version: string) =>
859
- `// inference ${version}\nmodule.exports = { name: 'linked-plugin', createNodesV2: ['**/never.json', () => []] };\n`;
860
- // A developer link: the plugin is a package of another checkout, which has its own lockfile.
861
- const checkout = async (name: string) => {
862
- const plugin = join(root, name, 'plugin');
863
- await mkdir(join(plugin, 'dist'), { recursive: true });
864
- await writeFile(join(root, name, 'bun.lock'), 'checkout lock one\n');
865
- await writeFile(
866
- join(plugin, 'package.json'),
867
- JSON.stringify({ name: 'linked-plugin', version: '1.0.0', main: 'dist/index.js', files: ['dist'] }),
868
- );
869
- await writeFile(join(plugin, 'dist', 'index.js'), inference('one'));
870
- return { plugin, entry: join(plugin, 'dist', 'index.js'), lock: join(root, name, 'bun.lock') };
871
- };
872
- const first = await checkout('checkout-a');
873
- const copy = await checkout('checkout-b');
874
- const link = join(workspace, 'node_modules', 'linked-plugin');
875
- const relink = async (target: string) => {
876
- await unlink(link);
877
- await symlink(target, link, 'dir');
878
- };
879
- await fixtureWorkspace(workspace, join(repositoryRoot, 'node_modules', 'nx'));
880
- await symlink(first.plugin, link, 'dir');
881
- await writeFile(join(workspace, 'nx.json'), JSON.stringify({ plugins: ['linked-plugin'] }));
882
- const env = fixtureNxEnv(workspace, socketDirectory);
883
- // Nothing in the workspace changes, so no watcher event reaches the daemon: each request judges the link.
884
- const serves = async (daemon: Daemon, what: string) => {
885
- expect(
886
- await requestOnce(daemon.record.socketPath, ping(workspace), `a PING after ${what}`),
887
- `${what} was refused`,
888
- ).toEqual({ answered: true, message: true });
889
- expect(await recordedPid(workspace), `${what} replaced the daemon`).toBe(daemon.record.processId);
890
- };
891
- const replaced = async (daemon: Daemon, what: string) => {
892
- assertNotServed(
893
- await requestOnce(daemon.record.socketPath, ping(workspace), `a PING sent after ${what}`),
894
- `a PING sent after ${what}`,
895
- );
896
- await awaitExit([daemon.entry], `daemon ${daemon.record.processId} after ${what}`);
897
- return readyDaemon(
898
- workspace,
899
- await replacementAfter({ workspace, previous: daemon.record.processId, what: `a successor after ${what}` }),
900
- );
901
- };
902
- let daemon = await startDaemon(workspace, env);
903
- await writeFile(first.entry, inference('one'));
904
- await serves(daemon, 'a same-bytes rewrite of the linked plugin');
905
- await relink(copy.plugin);
906
- await serves(daemon, 'the link moving to a copy with the same bytes');
907
- await writeFile(copy.entry, inference('two'));
908
- daemon = await replaced(daemon, 'the linked plugin changing in place');
909
- await relink(first.plugin);
910
- daemon = await replaced(daemon, 'the link moving to a plugin with other bytes');
911
- // The checkout's lockfile selects the plugin's dependencies, so its change restarts the daemon as well.
912
- await writeFile(first.lock, 'checkout lock two\n');
913
- await replaced(daemon, "the linked plugin checkout's lockfile changing");
914
- },
915
- FIXTURE_WORKSPACE,
916
- );
917
- });
918
-
919
- it('leaves a successor record and socket in place when another process takes the record', async () => {
920
- await withNxFixture(
921
- 'nx-daemon-validity-successor-',
922
- async ({ socketDirectory, workspace }) => {
923
- await fixtureWorkspace(workspace);
924
- const env = fixtureNxEnv(workspace, socketDirectory);
925
- const old = await startDaemon(workspace, env);
926
- const successorSocket = join(socketDirectory, 'successor.sock');
927
- const successor = await listeningChild(successorSocket);
928
- try {
929
- const record = {
930
- processId: successor.pid,
931
- socketPath: successorSocket,
932
- nxVersion: (await installedManifest()).version,
933
- workspaceRoot: workspace,
934
- };
935
- await writeFile(recordPath(workspace), `${JSON.stringify(record)}\n`);
936
- await awaitExit([old.entry], `daemon ${old.record.processId} whose record now names ${successor.pid}`);
937
- expect(await daemonRecord(workspace), 'the record after the displaced daemon exited').toMatchObject({
938
- processId: successor.pid,
939
- socketPath: successorSocket,
940
- });
941
- expect(
942
- await acceptsConnections(successorSocket),
943
- 'the successor socket after the displaced daemon exited',
944
- ).toBe(true);
945
- } finally {
946
- await successor.stop();
947
- }
948
- },
949
- FIXTURE_WORKSPACE,
950
- );
951
- });
952
-
953
- it("leaves a replacement socket in place when the daemon's own socket path is replaced", async () => {
954
- await withNxFixture(
955
- 'nx-daemon-validity-socket-',
956
- async ({ socketDirectory, workspace }) => {
957
- await fixtureWorkspace(workspace);
958
- const env = fixtureNxEnv(workspace, socketDirectory);
959
- const daemon = await startDaemon(workspace, env);
960
- await unlink(daemon.record.socketPath);
961
- const closeReplacement = await listenInProcess(daemon.record.socketPath);
962
- try {
963
- await awaitExit([daemon.entry], `daemon ${daemon.record.processId} whose socket path was replaced`);
964
- expect(
965
- await acceptsConnections(daemon.record.socketPath),
966
- 'the replacement socket after the daemon exited',
967
- ).toBe(true);
968
- } finally {
969
- await closeReplacement();
970
- }
971
- },
972
- FIXTURE_WORKSPACE,
973
- );
974
- });
975
-
976
- it('stops a daemon whose own socket path is removed with nothing taking its place', async () => {
977
- await withNxFixture(
978
- 'nx-daemon-validity-unlinked-',
979
- async ({ socketDirectory, workspace }) => {
980
- await fixtureWorkspace(workspace);
981
- const env = fixtureNxEnv(workspace, socketDirectory);
982
- const daemon = await startDaemon(workspace, env);
983
- await unlink(daemon.record.socketPath);
984
- await awaitExit([daemon.entry], `daemon ${daemon.record.processId} after its socket path was removed`);
985
- expect(await acceptsConnections(daemon.record.socketPath), 'the socket path after the daemon exited').toBe(false);
986
- },
987
- FIXTURE_WORKSPACE,
988
- );
989
- });
990
-
991
- it('stops a daemon whose workspace files are all deleted before it reads the emptied workspace', async () => {
992
- await withNxFixture(
993
- 'nx-daemon-validity-emptied-',
994
- async ({ socketDirectory, workspace }) => {
995
- await fixtureWorkspace(workspace);
996
- const env = fixtureNxEnv(workspace, socketDirectory);
997
- const daemon = await startDaemon(workspace, env);
998
- expect(JSON.parse(nx(workspace, { ...env, NX_DAEMON: 'true' }, 'show', 'projects', '--json'))).toEqual(['p']);
999
- // Every tracked file goes, as when a checkout is removed or unmounted under its daemon; the daemon's own record
1000
- // under .nx stays, so only the workspace check can stop it. Reading the emptied file map instead would block
1001
- // the daemon's only thread for good, where no SIGTERM handler runs.
1002
- await rm(join(workspace, 'p'), { recursive: true });
1003
- await unlink(join(workspace, 'package.json'));
1004
- await unlink(join(workspace, 'nx.json'));
1005
- await awaitExit([daemon.entry], `daemon ${daemon.record.processId} after every workspace file was deleted`);
1006
- const log = await readFile(join(workspace, '.nx', 'workspace-data', 'd', 'daemon.log'), 'utf8');
1007
- expect(log).toMatch(/Server stopped because: "its workspace \S+ has no nx\.json any more"/);
1008
- },
1009
- FIXTURE_WORKSPACE,
1010
- );
1011
- });
1012
-
1013
- it('keeps an idle daemon off the lockfiles, record, and socket between its safety polls', async () => {
1014
- await withNxFixture(
1015
- 'nx-daemon-validity-idle-',
1016
- async ({ root, socketDirectory, workspace }) => {
1017
- await fixtureWorkspace(workspace);
1018
- const log = join(root, 'validity-probe.log');
1019
- const probe = join(root, 'validity-probe.cjs');
1020
- await writeFile(probe, PROBE);
1021
- const env = { ...fixtureNxEnv(workspace, socketDirectory), NX_VALIDITY_LOG: log };
1022
- const daemonProcess = spawn(process.execPath, ['--preload', probe, daemonStart], {
1023
- cwd: workspace,
1024
- env,
1025
- stdio: ['ignore', 'ignore', 'ignore'],
1026
- });
1027
- try {
1028
- const record = await replacementAfter({ workspace, what: 'the directly started daemon to publish its record' });
1029
- const daemon = await readyDaemon(workspace, record);
1030
- const before = (await readFile(log, 'utf8')).split('\n').filter((line) => line !== '');
1031
- // The one real-clock wait. The daemon is a separate OS process whose idle behaviour exists only in wall-clock
1032
- // time, so no injected or fake clock can reach it; the window has to be measured against the real clock.
1033
- const observation = Promise.withResolvers<void>();
1034
- setTimeout(observation.resolve, OBSERVATION_MS);
1035
- await observation.promise;
1036
- const observed = (await readFile(log, 'utf8'))
1037
- .split('\n')
1038
- .filter((line) => line !== '')
1039
- .slice(before.length);
1040
- expect(
1041
- before.length,
1042
- 'the probe recorded no daemon startup reads, so its instrumentation is dead',
1043
- ).toBeGreaterThan(1);
1044
- expect(
1045
- observed.length,
1046
- `an idle daemon made ${observed.length} lockfile, record, or socket calls in ${OBSERVATION_MS} ms:\n${observed.join('\n')}`,
1047
- ).toBeLessThan(100);
1048
- expect(isRunning(daemon.record.processId), 'the idle daemon stopped').toBe(true);
1049
- } finally {
1050
- await stopChild(daemonProcess);
1051
- }
1052
- },
1053
- FIXTURE_WORKSPACE,
1054
- );
1055
- });