@intentius/chant 0.124.88 → 0.124.90

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 (377) hide show
  1. package/dist/actor.d.ts +36 -1
  2. package/dist/actor.d.ts.map +1 -1
  3. package/dist/actor.js +39 -1
  4. package/dist/chant-install.d.ts.map +1 -1
  5. package/dist/chant-install.js +1 -2
  6. package/dist/ci-base.d.ts +30 -0
  7. package/dist/ci-base.d.ts.map +1 -0
  8. package/dist/ci-base.js +33 -0
  9. package/dist/ci-comment-commands.d.ts +193 -0
  10. package/dist/ci-comment-commands.d.ts.map +1 -0
  11. package/dist/ci-comment-commands.js +353 -0
  12. package/dist/ci-comment-replies.d.ts +40 -0
  13. package/dist/ci-comment-replies.d.ts.map +1 -0
  14. package/dist/ci-comment-replies.js +59 -0
  15. package/dist/ci-evidence-from-job.d.ts +25 -0
  16. package/dist/ci-evidence-from-job.d.ts.map +1 -1
  17. package/dist/ci-evidence-from-job.js +43 -2
  18. package/dist/ci-evidence-jobs.d.ts +30 -1
  19. package/dist/ci-evidence-jobs.d.ts.map +1 -1
  20. package/dist/ci-evidence-jobs.js +46 -3
  21. package/dist/ci-image.d.ts +21 -4
  22. package/dist/ci-image.d.ts.map +1 -1
  23. package/dist/ci-image.js +62 -10
  24. package/dist/ci-job-guard.d.ts +42 -45
  25. package/dist/ci-job-guard.d.ts.map +1 -1
  26. package/dist/ci-job-guard.js +206 -3
  27. package/dist/ci-note-commands.d.ts +104 -4
  28. package/dist/ci-note-commands.d.ts.map +1 -1
  29. package/dist/ci-note-commands.js +131 -38
  30. package/dist/ci-product-words.d.ts +42 -0
  31. package/dist/ci-product-words.d.ts.map +1 -1
  32. package/dist/ci-product-words.js +25 -0
  33. package/dist/ci-product.d.ts +72 -1
  34. package/dist/ci-product.d.ts.map +1 -1
  35. package/dist/ci-product.js +73 -6
  36. package/dist/cli/commands/build.d.ts.map +1 -1
  37. package/dist/cli/commands/build.js +29 -2
  38. package/dist/cli/handlers/approve.d.ts.map +1 -1
  39. package/dist/cli/handlers/approve.js +2 -1
  40. package/dist/cli/handlers/ci-check.d.ts +1 -1
  41. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  42. package/dist/cli/handlers/ci-check.js +17 -7
  43. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  44. package/dist/cli/handlers/ci-evidence.js +33 -7
  45. package/dist/cli/handlers/components.d.ts.map +1 -1
  46. package/dist/cli/handlers/components.js +3 -1
  47. package/dist/cli/handlers/generated-check.d.ts +8 -0
  48. package/dist/cli/handlers/generated-check.d.ts.map +1 -1
  49. package/dist/cli/handlers/generated-check.js +31 -1
  50. package/dist/cli/handlers/lock.d.ts.map +1 -1
  51. package/dist/cli/handlers/lock.js +121 -4
  52. package/dist/cli/handlers/pr-comment.d.ts +33 -0
  53. package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
  54. package/dist/cli/handlers/pr-comment.js +201 -0
  55. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  56. package/dist/cli/handlers/pr-env.js +6 -3
  57. package/dist/cli/handlers/pr-notes.d.ts.map +1 -1
  58. package/dist/cli/handlers/pr-notes.js +23 -1
  59. package/dist/cli/handlers/pr.d.ts +23 -1
  60. package/dist/cli/handlers/pr.d.ts.map +1 -1
  61. package/dist/cli/handlers/pr.js +71 -23
  62. package/dist/cli/handlers/promote.d.ts.map +1 -1
  63. package/dist/cli/handlers/promote.js +2 -1
  64. package/dist/cli/handlers/release.d.ts.map +1 -1
  65. package/dist/cli/handlers/release.js +11 -2
  66. package/dist/cli/handlers/run-wave.d.ts.map +1 -1
  67. package/dist/cli/handlers/run-wave.js +180 -4
  68. package/dist/cli/handlers/run.d.ts.map +1 -1
  69. package/dist/cli/handlers/run.js +2 -1
  70. package/dist/cli/main.d.ts.map +1 -1
  71. package/dist/cli/main.js +41 -2
  72. package/dist/cli/parse-args.d.ts.map +1 -1
  73. package/dist/cli/parse-args.js +31 -0
  74. package/dist/cli/registry.d.ts +19 -1
  75. package/dist/cli/registry.d.ts.map +1 -1
  76. package/dist/components/auto-release.d.ts.map +1 -1
  77. package/dist/components/auto-release.js +2 -1
  78. package/dist/components/pr-checks.d.ts +97 -6
  79. package/dist/components/pr-checks.d.ts.map +1 -1
  80. package/dist/components/pr-checks.js +107 -13
  81. package/dist/components/pr-pipeline.d.ts +19 -14
  82. package/dist/components/pr-pipeline.d.ts.map +1 -1
  83. package/dist/components/pr-pipeline.js +7 -13
  84. package/dist/components/product-pipeline.d.ts +96 -3
  85. package/dist/components/product-pipeline.d.ts.map +1 -1
  86. package/dist/components/product-pipeline.js +120 -14
  87. package/dist/components/product-plan.d.ts +203 -6
  88. package/dist/components/product-plan.d.ts.map +1 -1
  89. package/dist/components/product-plan.js +250 -43
  90. package/dist/drift-record.d.ts +7 -0
  91. package/dist/drift-record.d.ts.map +1 -1
  92. package/dist/drift-record.js +19 -0
  93. package/dist/floor-table.data.d.ts.map +1 -1
  94. package/dist/floor-table.data.js +63 -31
  95. package/dist/forge-check/contract.d.ts +11 -1
  96. package/dist/forge-check/contract.d.ts.map +1 -1
  97. package/dist/forge-check/contract.js +4 -1
  98. package/dist/forge-check/index.d.ts +2 -0
  99. package/dist/forge-check/index.d.ts.map +1 -1
  100. package/dist/forge-check/index.js +2 -0
  101. package/dist/gate-resume-run.d.ts +9 -1
  102. package/dist/gate-resume-run.d.ts.map +1 -1
  103. package/dist/gate-resume-run.js +26 -3
  104. package/dist/generated-check.d.ts +18 -4
  105. package/dist/generated-check.d.ts.map +1 -1
  106. package/dist/generated-check.js +37 -5
  107. package/dist/image-pins.d.ts +26 -0
  108. package/dist/image-pins.d.ts.map +1 -0
  109. package/dist/image-pins.js +19 -0
  110. package/dist/lexicon.d.ts +93 -4
  111. package/dist/lexicon.d.ts.map +1 -1
  112. package/dist/lifecycle/gate-applied.d.ts +9 -0
  113. package/dist/lifecycle/gate-applied.d.ts.map +1 -1
  114. package/dist/lifecycle/git.d.ts +11 -0
  115. package/dist/lifecycle/git.d.ts.map +1 -1
  116. package/dist/lifecycle/git.js +30 -3
  117. package/dist/lifecycle/publish-npm.d.ts +11 -0
  118. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  119. package/dist/lifecycle/publish-npm.js +27 -1
  120. package/dist/lifecycle/reach-locks.d.ts +131 -0
  121. package/dist/lifecycle/reach-locks.d.ts.map +1 -0
  122. package/dist/lifecycle/reach-locks.js +118 -0
  123. package/dist/lifecycle/release-cut.d.ts +3 -1
  124. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  125. package/dist/lifecycle/release-cut.js +15 -0
  126. package/dist/lifecycle/release-images.d.ts.map +1 -1
  127. package/dist/lifecycle/release-images.js +1 -2
  128. package/dist/notify-product.d.ts +12 -3
  129. package/dist/notify-product.d.ts.map +1 -1
  130. package/dist/notify-product.js +10 -6
  131. package/dist/op/activities/source-release.d.ts.map +1 -1
  132. package/dist/op/activities/source-release.js +2 -1
  133. package/dist/op/activities/source-rollback.d.ts.map +1 -1
  134. package/dist/op/activities/source-rollback.js +2 -1
  135. package/dist/op/apply-status.d.ts +84 -0
  136. package/dist/op/apply-status.d.ts.map +1 -0
  137. package/dist/op/apply-status.js +106 -0
  138. package/dist/op/before-merge-decide.d.ts +102 -0
  139. package/dist/op/before-merge-decide.d.ts.map +1 -0
  140. package/dist/op/before-merge-decide.js +142 -0
  141. package/dist/op/before-merge-done.d.ts +56 -0
  142. package/dist/op/before-merge-done.d.ts.map +1 -0
  143. package/dist/op/before-merge-done.js +69 -0
  144. package/dist/op/before-merge-store.d.ts +20 -0
  145. package/dist/op/before-merge-store.d.ts.map +1 -0
  146. package/dist/op/before-merge-store.js +48 -0
  147. package/dist/op/before-merge.d.ts +150 -0
  148. package/dist/op/before-merge.d.ts.map +1 -0
  149. package/dist/op/before-merge.js +207 -0
  150. package/dist/op/follow-on-run.d.ts +117 -0
  151. package/dist/op/follow-on-run.d.ts.map +1 -0
  152. package/dist/op/follow-on-run.js +154 -0
  153. package/dist/op/follow-on-store.d.ts +17 -0
  154. package/dist/op/follow-on-store.d.ts.map +1 -0
  155. package/dist/op/follow-on-store.js +54 -0
  156. package/dist/op/gate.d.ts +6 -0
  157. package/dist/op/gate.d.ts.map +1 -1
  158. package/dist/op/gate.js +10 -1
  159. package/dist/op/index.d.ts +5 -1
  160. package/dist/op/index.d.ts.map +1 -1
  161. package/dist/op/index.js +2 -0
  162. package/dist/op/op-waves-after-plan.d.ts +13 -0
  163. package/dist/op/op-waves-after-plan.d.ts.map +1 -1
  164. package/dist/op/op-waves-evidence-jobs.d.ts +10 -2
  165. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
  166. package/dist/op/op-waves-evidence-jobs.js +19 -5
  167. package/dist/op/op-waves-follow-on.d.ts +162 -0
  168. package/dist/op/op-waves-follow-on.d.ts.map +1 -0
  169. package/dist/op/op-waves-follow-on.js +355 -0
  170. package/dist/op/op-waves-render-spec.d.ts +100 -0
  171. package/dist/op/op-waves-render-spec.d.ts.map +1 -0
  172. package/dist/op/op-waves-render-spec.js +162 -0
  173. package/dist/op/op-waves-run.d.ts +148 -6
  174. package/dist/op/op-waves-run.d.ts.map +1 -1
  175. package/dist/op/op-waves-run.js +873 -100
  176. package/dist/op/op-waves-split.d.ts +122 -0
  177. package/dist/op/op-waves-split.d.ts.map +1 -0
  178. package/dist/op/op-waves-split.js +166 -0
  179. package/dist/op/op-waves.d.ts +24 -0
  180. package/dist/op/op-waves.d.ts.map +1 -1
  181. package/dist/op/op-waves.js +18 -1
  182. package/dist/op/schedule-overdue.d.ts +15 -1
  183. package/dist/op/schedule-overdue.d.ts.map +1 -1
  184. package/dist/op/schedule-overdue.js +77 -5
  185. package/dist/op/stage-hooks.d.ts +36 -1
  186. package/dist/op/stage-hooks.d.ts.map +1 -1
  187. package/dist/op/stage-hooks.js +17 -3
  188. package/dist/op/wave-stop.d.ts +67 -0
  189. package/dist/op/wave-stop.d.ts.map +1 -0
  190. package/dist/op/wave-stop.js +129 -0
  191. package/dist/planned-files.d.ts +76 -0
  192. package/dist/planned-files.d.ts.map +1 -0
  193. package/dist/planned-files.js +108 -0
  194. package/dist/pr-forge-job.d.ts +22 -0
  195. package/dist/pr-forge-job.d.ts.map +1 -0
  196. package/dist/pr-forge-job.js +46 -0
  197. package/dist/pr-loop.d.ts +3 -6
  198. package/dist/pr-loop.d.ts.map +1 -1
  199. package/dist/pr-loop.js +4 -81
  200. package/dist/pr-plan-note.d.ts +97 -0
  201. package/dist/pr-plan-note.d.ts.map +1 -1
  202. package/dist/pr-plan-note.js +94 -1
  203. package/dist/pr-post.d.ts +28 -3
  204. package/dist/pr-post.d.ts.map +1 -1
  205. package/dist/pr-post.js +146 -13
  206. package/dist/pr-status.d.ts +16 -0
  207. package/dist/pr-status.d.ts.map +1 -0
  208. package/dist/pr-status.js +90 -0
  209. package/dist/ref-gate-init.d.ts +16 -2
  210. package/dist/ref-gate-init.d.ts.map +1 -1
  211. package/dist/ref-gate-init.js +24 -13
  212. package/dist/release-floors.d.ts +39 -1
  213. package/dist/release-floors.d.ts.map +1 -1
  214. package/dist/release-floors.js +63 -25
  215. package/dist/render-module.d.ts +15 -0
  216. package/dist/render-module.d.ts.map +1 -0
  217. package/dist/render-module.js +73 -0
  218. package/dist/state-migration.d.ts.map +1 -1
  219. package/dist/state-migration.js +1 -2
  220. package/dist/wave-blocked.d.ts +7 -1
  221. package/dist/wave-blocked.d.ts.map +1 -1
  222. package/dist/wave-blocked.js +7 -2
  223. package/dist/wave-runtime.mjs +366 -350
  224. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  225. package/dist/workspace/ci-green-cli.js +3 -2
  226. package/dist/workspace/release-train.d.ts.map +1 -1
  227. package/dist/workspace/release-train.js +2 -1
  228. package/dist/workspace/release-workflow.d.ts +4 -3
  229. package/dist/workspace/release-workflow.d.ts.map +1 -1
  230. package/dist/workspace/release-workflow.js +10 -7
  231. package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
  232. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  233. package/dist/workspace/trust/check-evidence-report.js +15 -8
  234. package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
  235. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
  236. package/dist/workspace/trust/ref-gate-cli.js +30 -10
  237. package/dist/workspace/workspace-run.d.ts.map +1 -1
  238. package/dist/workspace/workspace-run.js +2 -1
  239. package/package.json +1 -1
  240. package/src/actor.test.ts +68 -2
  241. package/src/actor.ts +61 -1
  242. package/src/chant-install.test.ts +2 -3
  243. package/src/chant-install.ts +1 -2
  244. package/src/ci-base.test.ts +41 -0
  245. package/src/ci-base.ts +43 -0
  246. package/src/ci-comment-commands.test.ts +439 -0
  247. package/src/ci-comment-commands.ts +428 -0
  248. package/src/ci-comment-replies.ts +78 -0
  249. package/src/ci-commit.test.ts +2 -3
  250. package/src/ci-evidence-from-job.test.ts +18 -0
  251. package/src/ci-evidence-from-job.ts +58 -2
  252. package/src/ci-evidence-jobs.ts +50 -5
  253. package/src/ci-image.test.ts +130 -10
  254. package/src/ci-image.ts +85 -12
  255. package/src/ci-job-guard.before-merge.test.ts +148 -0
  256. package/src/ci-job-guard.follow-on-record.test.ts +137 -0
  257. package/src/ci-job-guard.follow-on.test.ts +144 -0
  258. package/src/ci-job-guard.ts +221 -3
  259. package/src/ci-note-commands.test.ts +76 -1
  260. package/src/ci-note-commands.ts +198 -46
  261. package/src/ci-product-words.ts +59 -0
  262. package/src/ci-product.ts +90 -6
  263. package/src/cli/commands/build.test.ts +41 -0
  264. package/src/cli/commands/build.ts +27 -2
  265. package/src/cli/handlers/approve.ts +2 -1
  266. package/src/cli/handlers/ci-check.ts +19 -7
  267. package/src/cli/handlers/ci-evidence.ts +29 -8
  268. package/src/cli/handlers/components.ts +3 -1
  269. package/src/cli/handlers/generated-check.ts +31 -1
  270. package/src/cli/handlers/lock-reach.test.ts +103 -0
  271. package/src/cli/handlers/lock.ts +100 -4
  272. package/src/cli/handlers/pr-comment.ts +187 -0
  273. package/src/cli/handlers/pr-env.ts +6 -3
  274. package/src/cli/handlers/pr-notes.ts +30 -6
  275. package/src/cli/handlers/pr-record.test.ts +1 -1
  276. package/src/cli/handlers/pr.ts +64 -21
  277. package/src/cli/handlers/promote.ts +2 -1
  278. package/src/cli/handlers/release.e2e.test.ts +35 -0
  279. package/src/cli/handlers/release.ts +14 -2
  280. package/src/cli/handlers/run-wave.ts +170 -4
  281. package/src/cli/handlers/run.ts +2 -1
  282. package/src/cli/main.ts +41 -2
  283. package/src/cli/parse-args.ts +23 -0
  284. package/src/cli/registry.ts +19 -1
  285. package/src/components/auto-release.ts +2 -1
  286. package/src/components/pr-checks.ts +165 -17
  287. package/src/components/pr-pipeline.ts +22 -18
  288. package/src/components/product-pipeline.apply-status.test.ts +50 -0
  289. package/src/components/product-pipeline.ts +204 -17
  290. package/src/components/product-plan.test.ts +60 -4
  291. package/src/components/product-plan.ts +367 -50
  292. package/src/drift-record.test.ts +20 -0
  293. package/src/drift-record.ts +16 -0
  294. package/src/floor-table.data.ts +63 -31
  295. package/src/forge-check/contract.ts +12 -1
  296. package/src/forge-check/forge-check.test.ts +17 -0
  297. package/src/forge-check/index.ts +2 -0
  298. package/src/gate-resume-run.ts +27 -3
  299. package/src/generated-check.e2e.test.ts +21 -1
  300. package/src/generated-check.test.ts +66 -0
  301. package/src/generated-check.ts +51 -10
  302. package/src/image-pins.ts +31 -0
  303. package/src/lexicon.ts +89 -1
  304. package/src/lifecycle/gate-applied.ts +7 -0
  305. package/src/lifecycle/git.test.ts +48 -0
  306. package/src/lifecycle/git.ts +27 -4
  307. package/src/lifecycle/publish-npm.ts +31 -1
  308. package/src/lifecycle/reach-locks.test.ts +87 -0
  309. package/src/lifecycle/reach-locks.ts +169 -0
  310. package/src/lifecycle/release-cut.ts +17 -1
  311. package/src/lifecycle/release-images.test.ts +56 -0
  312. package/src/lifecycle/release-images.ts +1 -2
  313. package/src/notify-product.ts +19 -8
  314. package/src/op/activities/source-release.ts +2 -1
  315. package/src/op/activities/source-rollback.ts +2 -1
  316. package/src/op/apply-status.test.ts +83 -0
  317. package/src/op/apply-status.ts +132 -0
  318. package/src/op/before-merge-decide.ts +190 -0
  319. package/src/op/before-merge-done.ts +99 -0
  320. package/src/op/before-merge-store.ts +44 -0
  321. package/src/op/before-merge.test.ts +201 -0
  322. package/src/op/before-merge.ts +266 -0
  323. package/src/op/follow-on-run.ts +206 -0
  324. package/src/op/follow-on-store.ts +54 -0
  325. package/src/op/gate-resume.test.ts +27 -0
  326. package/src/op/gate.ts +16 -1
  327. package/src/op/index.ts +15 -0
  328. package/src/op/op-waves-after-plan.ts +13 -0
  329. package/src/op/op-waves-evidence-jobs.ts +21 -7
  330. package/src/op/op-waves-follow-on-record.test.ts +152 -0
  331. package/src/op/op-waves-follow-on.test.ts +247 -0
  332. package/src/op/op-waves-follow-on.ts +385 -0
  333. package/src/op/op-waves-notify-words.test.ts +18 -0
  334. package/src/op/op-waves-render-spec.test.ts +159 -0
  335. package/src/op/op-waves-render-spec.ts +171 -0
  336. package/src/op/op-waves-run.ts +973 -94
  337. package/src/op/op-waves-split-product.test.ts +288 -0
  338. package/src/op/op-waves-split-step.test.ts +298 -0
  339. package/src/op/op-waves-split.test.ts +196 -0
  340. package/src/op/op-waves-split.ts +189 -0
  341. package/src/op/op-waves.ts +31 -3
  342. package/src/op/schedule-overdue.test.ts +72 -1
  343. package/src/op/schedule-overdue.ts +84 -6
  344. package/src/op/stage-hooks.ts +52 -4
  345. package/src/op/wave-stop.test.ts +72 -0
  346. package/src/op/wave-stop.ts +139 -0
  347. package/src/planned-files.test.ts +80 -0
  348. package/src/planned-files.ts +134 -0
  349. package/src/pr-forge-job.test.ts +53 -0
  350. package/src/pr-forge-job.ts +46 -0
  351. package/src/pr-loop-narrowed.test.ts +2 -1
  352. package/src/pr-loop-words.test.ts +2 -1
  353. package/src/pr-loop.test.ts +1 -2
  354. package/src/pr-loop.ts +4 -80
  355. package/src/pr-plan-note.ts +155 -3
  356. package/src/pr-post-replan.test.ts +144 -0
  357. package/src/pr-post-subject.test.ts +230 -0
  358. package/src/pr-post.test.ts +2 -1
  359. package/src/pr-post.ts +151 -15
  360. package/src/pr-status.ts +91 -0
  361. package/src/ref-gate-init.ts +30 -11
  362. package/src/release-floors.ts +81 -25
  363. package/src/render-module.ts +73 -0
  364. package/src/state-migration-record.test.ts +2 -3
  365. package/src/state-migration.ts +1 -2
  366. package/src/wave-blocked.ts +9 -4
  367. package/src/workspace/ci-green-cli.ts +3 -2
  368. package/src/workspace/ci-green-workflow.test.ts +32 -1
  369. package/src/workspace/release-train.ts +2 -1
  370. package/src/workspace/release-workflow.test.ts +36 -5
  371. package/src/workspace/release-workflow.ts +10 -7
  372. package/src/workspace/trust/check-evidence-report.ts +15 -8
  373. package/src/workspace/trust/check-evidence.test.ts +5 -0
  374. package/src/workspace/trust/ref-gate-cli.ts +30 -8
  375. package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
  376. package/src/workspace/trust/ref-gate.test.ts +10 -0
  377. package/src/workspace/workspace-run.ts +2 -1
@@ -26,9 +26,15 @@
26
26
  * {@link committedPathOf}): under a check, `chant ci workflow` and `chant
27
27
  * release workflow` write every file into the render tree, the trigger edits
28
28
  * to other workflows included, and name the committed path in their header,
29
- * so the render matches the file that was written without `--output`.
29
+ * so the render matches the file that was written without `--output`. #4950:
30
+ * with no `--output` they write into the render tree too.
30
31
  *
31
- * This module imports only Node's own modules.
32
+ * A render can also be a module and its export (#4950, `./render-module`):
33
+ * the check imports the module and writes the `{ path: text }` files the
34
+ * export returns below the render tree, with no command or bundler.
35
+ *
36
+ * This module imports only Node's own modules; a module render loads
37
+ * `./render-module` when it runs.
32
38
  */
33
39
  import { spawn } from "node:child_process";
34
40
  import { existsSync, mkdtempSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
@@ -40,7 +46,11 @@ export const GENERATED_OUT_ENV = "CHANT_GENERATED_OUT";
40
46
  /** The product root the check renders for: the committed paths are relative to it. */
41
47
  export const GENERATED_ROOT_ENV = "CHANT_GENERATED_ROOT";
42
48
 
43
- /** One render: a command that writes some of the product's generated files. */
49
+ /**
50
+ * One render: a command that writes some of the product's generated files,
51
+ * or (#4950) a module whose export returns them. Each render has `run`, or
52
+ * `module` and `export`.
53
+ */
44
54
  export interface GeneratedRender {
45
55
  /** A short name, in the output: `ci`, `images`. */
46
56
  name: string;
@@ -49,12 +59,22 @@ export interface GeneratedRender {
49
59
  * quoted for the shell; the command writes each file at its committed path
50
60
  * below it (`npx chant build ci -o {out}/.github/workflows/ci.yml`).
51
61
  */
52
- run: string;
62
+ run?: string;
63
+ /**
64
+ * #4950: a TypeScript or JavaScript module, relative to the product root,
65
+ * whose {@link export} is a `{ path: text }` object, or a function that
66
+ * returns one. chant imports it and writes each file at its path below the
67
+ * render tree, as `chant dev render <module> <export>` writes it in place.
68
+ */
69
+ module?: string;
70
+ /** The export of {@link module} that renders the files: `dockerfiles`. */
71
+ export?: string;
53
72
  /**
54
73
  * The committed files it renders, relative to the product root. A `*` in a
55
74
  * path's last segment matches within it (`images/Dockerfile.*`), and then
56
- * every match on either side must have its twin. A render with no files
57
- * passes when its command exits 0 (a script with a check of its own).
75
+ * every match on either side must have its twin. A command render with no
76
+ * files passes when its command exits 0 (a script with a check of its
77
+ * own); a module render with no files compares every file it renders.
58
78
  */
59
79
  files?: string[];
60
80
  }
@@ -97,7 +117,13 @@ export function readGeneratedCheckConfig(productDir: string): GeneratedCheckConf
97
117
  if (!c || typeof c !== "object" || !Array.isArray(c.renders)) throw new Error(`${f}: chantGenerated needs a renders list`);
98
118
  const names = new Set<string>();
99
119
  for (const [i, r] of c.renders.entries()) {
100
- if (!r || typeof r.name !== "string" || !r.name || typeof r.run !== "string" || !r.run) throw new Error(`${f}: chantGenerated.renders[${i}] needs a name and a run command`);
120
+ if (!r || typeof r.name !== "string" || !r.name) throw new Error(`${f}: chantGenerated.renders[${i}] needs a name and a run command`);
121
+ const isRun = r.run !== undefined;
122
+ const isModule = r.module !== undefined || r.export !== undefined;
123
+ if (isRun === isModule) throw new Error(`${f}: chantGenerated.renders[${i}] needs a run command, or a module and its export`);
124
+ if (isRun && (typeof r.run !== "string" || !r.run)) throw new Error(`${f}: chantGenerated.renders[${i}] needs a name and a run command`);
125
+ if (isModule && (typeof r.module !== "string" || !r.module || typeof r.export !== "string" || !r.export)) throw new Error(`${f}: chantGenerated.renders[${i}] needs a module and the name of its export`);
126
+ if (isModule && (r.module!.startsWith("/") || r.module!.split("/").includes(".."))) throw new Error(`${f}: chantGenerated.renders[${i}].module must be a path inside the product`);
101
127
  if (names.has(r.name)) throw new Error(`${f}: chantGenerated.renders names '${r.name}' twice`);
102
128
  names.add(r.name);
103
129
  if (r.files !== undefined && (!Array.isArray(r.files) || r.files.some((p) => typeof p !== "string" || p.startsWith("/") || p.split("/").includes("..")))) {
@@ -222,7 +248,21 @@ export async function checkGenerated(productDir: string, config: GeneratedCheckC
222
248
  const env = { ...process.env, [GENERATED_OUT_ENV]: out, [GENERATED_ROOT_ENV]: root };
223
249
  const ran = await Promise.all(
224
250
  renders.map(async (r) => {
225
- const command = r.run.split("{out}").join(shellQuote(out));
251
+ if (r.module !== undefined) {
252
+ // #4950: a module render runs here, in chant's process, with the
253
+ // TypeScript loader and chant served as itself. Exit 1 and the error
254
+ // stand in for a command's exit code and output.
255
+ const command = `chant dev render ${shellQuote(r.module)} ${shellQuote(r.export!)}`;
256
+ try {
257
+ const { renderModuleFiles, writeRenderedFiles } = await import("./render-module");
258
+ const rendered = await renderModuleFiles(r.module, r.export!, root);
259
+ writeRenderedFiles(out, rendered);
260
+ return { r, command, exitCode: 0, output: "", rendered: Object.keys(rendered) };
261
+ } catch (err) {
262
+ return { r, command, exitCode: 1, output: err instanceof Error ? err.message : String(err) };
263
+ }
264
+ }
265
+ const command = r.run!.split("{out}").join(shellQuote(out));
226
266
  return { r, command, ...(await runRender(command, root, env)) };
227
267
  }),
228
268
  );
@@ -230,14 +270,15 @@ export async function checkGenerated(productDir: string, config: GeneratedCheckC
230
270
  const results: GeneratedRenderResult[] = [];
231
271
  const matched: string[] = [];
232
272
  const hint = config.regenerate ? ` Run '${config.regenerate}' and commit the result.` : "";
233
- for (const { r, command, exitCode, output } of ran) {
273
+ for (const { r, command, exitCode, output, rendered } of ran as ((typeof ran)[number] & { rendered?: string[] })[]) {
234
274
  const files: string[] = [];
235
275
  results.push({ name: r.name, command, exitCode, output, files });
236
276
  if (exitCode !== 0) {
237
277
  problems.push(`render '${r.name}' exited ${exitCode}: ${command}${output.trim() ? `\n${output.trimEnd().split("\n").map((l) => ` ${l}`).join("\n")}` : ""}`);
238
278
  continue;
239
279
  }
240
- for (const path of r.files ?? []) {
280
+ // A module render with no files compares every file it rendered.
281
+ for (const path of r.files ?? rendered ?? []) {
241
282
  const committed = expand(root, path);
242
283
  const rendered = expand(out, path);
243
284
  if (!path.includes("*") && rendered.length === 0) {
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The container images the workflows chant generates run, each pinned by the
3
+ * digest of its image index (#4941), as {@link ../action-pins.ts} pins the
4
+ * actions by commit. A tag can move; a digest cannot. A generator takes its
5
+ * image reference from here, so an update is one change to this table. Each
6
+ * row names the tag it followed when it was resolved, which the reference
7
+ * keeps beside the digest so a reader sees the release.
8
+ *
9
+ * Refresh a row by resolving its tag to the index digest:
10
+ *
11
+ * docker buildx imagetools inspect tonistiigi/binfmt:qemu-v10.2.3 --format '{{.Manifest.Digest}}'
12
+ */
13
+
14
+ export interface ImagePin {
15
+ /** The repository, as `docker run` names it: `tonistiigi/binfmt`. */
16
+ readonly repository: string;
17
+ /** The tag the row followed when it was resolved. */
18
+ readonly tag: string;
19
+ /** The image index digest, `sha256:<hex>`. */
20
+ readonly digest: string;
21
+ }
22
+
23
+ const pin = (repository: string, tag: string, digest: string): ImagePin => ({ repository, tag, digest });
24
+
25
+ export const IMAGE_PINS = {
26
+ // #4941: the GitLab release workflow's QEMU binfmt setup (#4876); `latest` pointed at this index on 2026-11-10.
27
+ binfmt: pin("tonistiigi/binfmt", "qemu-v10.2.3", "sha256:400a4873b838d1b89194d982c45e5fb3cda4593fbfd7e08a02e76b03b21166f0"),
28
+ } as const satisfies Record<string, ImagePin>;
29
+
30
+ /** The reference a pin is run by: `<repository>:<tag>@<digest>`. Docker pulls by the digest and ignores the tag. */
31
+ export const imageRef = (p: ImagePin): string => `${p.repository}:${p.tag}@${p.digest}`;
package/src/lexicon.ts CHANGED
@@ -1174,6 +1174,63 @@ export interface OpWavesPipelineOptions
1174
1174
  * wave is planned. Absent: the jobs render as without it.
1175
1175
  */
1176
1176
  evidence?: import("./ci-evidence-jobs").PipelineEvidence;
1177
+ /**
1178
+ * A spec the job renders at run time (#4982,
1179
+ * `@intentius/chant/op/op-waves-render-spec`): every wave, deciding and
1180
+ * share job and the policy step runs `chant run wave --render-spec`, with
1181
+ * `CHANT_WAVES_SPEC_COMMAND` set to `command`, which prints the spec at
1182
+ * the commit in `CHANT_WAVES_SPEC_AT`. The spec handed to the generator
1183
+ * is the pipeline's shape (its waves, shares, job groups, `cloud`,
1184
+ * runners, environments and `holds.policy`); the rendered one sets the
1185
+ * rules. Absent: the jobs read the committed spec as before.
1186
+ */
1187
+ renderSpec?: import("./op/op-waves-render-spec").OpWavesRenderSpec;
1188
+ /**
1189
+ * The before-merge mode (#4984, `@intentius/chant/op/before-merge`): the
1190
+ * workflow also runs for an open pull request's head that the comment job
1191
+ * (GitHub, Forgejo) or the note poll (GitLab) decided and recorded on
1192
+ * `chant/lifecycle`. GitHub and Forgejo dispatch it on the default branch
1193
+ * with the inputs `pr`, `head` and `digest`; GitLab starts a pipeline of
1194
+ * the default branch with `CHANT_BEFORE_MERGE_PR`, `_HEAD` and `_DIGEST`.
1195
+ * Each wave job's guard admits that head alone, the job checks it out
1196
+ * after the default branch's checkout, and its command reads the gates
1197
+ * and the spec at the default branch's commit. After the last wave the
1198
+ * `before-merge-done` job merges the pull request (`merge: "auto"`) and
1199
+ * releases its locks, or says it is ready. Absent: the jobs run on a push
1200
+ * alone, as before.
1201
+ *
1202
+ * #4987: with it, every wave (on a push too) is four jobs
1203
+ * (`@intentius/chant/op/op-waves-split`): a plan job and an applying job
1204
+ * that run the change's code with no write token and no credentials in
1205
+ * the checkout, keeping the wave's runners, trades and environment, and a
1206
+ * gate job and a record job at the default branch's code that write
1207
+ * `chant/lifecycle`. The evidence job signs the plan job's checks. A
1208
+ * `rest` wave is refused. #4992: a `step` spec splits (the gate job
1209
+ * leases its rows, the record job lets go of them), a hold on another
1210
+ * gate is recorded by the gate or record job, Forgejo's plan and applying
1211
+ * jobs hand their files on as job outputs, and the wave's environment is
1212
+ * on the applying job alone (`planEnvironment` for the plan job).
1213
+ */
1214
+ beforeMerge?: import("./op/before-merge").OpWavesBeforeMerge;
1215
+ /**
1216
+ * The apply statuses (#4987, `@intentius/chant/op/apply-status`): after
1217
+ * each wave a job `apply-status-<n>` at the default branch's commit reads
1218
+ * the outcome files and posts `context` on the commit the waves applied
1219
+ * (the push's, or a before-merge run's decided head): pending after each
1220
+ * wave, success after the last, failed when a run failed. It runs none of
1221
+ * the change's code. On GitLab it posts with `CHANT_FORGE_TOKEN` (the job
1222
+ * token cannot post a status). Absent: no job posts one.
1223
+ */
1224
+ applyStatus?: import("./op/apply-status").OpWavesApplyStatus;
1225
+ /**
1226
+ * The stale marking (#4987, #4628): the command and values of the job
1227
+ * `stale-notes`, which runs beside wave 1 on a push (never in a
1228
+ * before-merge run) and marks stale each open pull request's plan note
1229
+ * posted against another commit of the branch. A product plan's
1230
+ * pipeline gives it from `productPipelineJobs`, one `--member` per plan
1231
+ * target. On GitLab it posts with `CHANT_FORGE_TOKEN`.
1232
+ */
1233
+ staleNotes?: { command: string; env: Record<string, string> };
1177
1234
  }
1178
1235
 
1179
1236
  /** A run step a product adds to a generated job (#4791): its name, and its shell lines in order. */
@@ -1191,6 +1248,14 @@ export interface OpWaveJobInputs {
1191
1248
  * `cloud`, they run after the token request is unset, as every later step.
1192
1249
  */
1193
1250
  before?: OpWaveRunStep[];
1251
+ /**
1252
+ * Shell lines run in the command's own step, just before the command
1253
+ * (#4984), such as terragucci's Terragrunt prelude: cache exports and
1254
+ * the apply roles' variables, which a step of their own would lose on
1255
+ * GitHub and Forgejo, where each step is a shell of its own. GitLab: the
1256
+ * lines before the command in the job's script.
1257
+ */
1258
+ prelude?: string[];
1194
1259
  /**
1195
1260
  * A step run after the job whatever its exit, since a wave that waits at
1196
1261
  * its gate exits 3. GitHub and Forgejo: a step with `if: always()` after
@@ -1203,8 +1268,31 @@ export interface OpWaveJobInputs {
1203
1268
  * and Forgejo: an upload step named `step` after the report. GitLab: the
1204
1269
  * path joins the job's `artifacts:`, which keep the outcome files too,
1205
1270
  * under `name`.
1271
+ *
1272
+ * #4994: `path` may be a list, so one artifact keeps every directory the
1273
+ * product used to upload in steps of its own (a report and an agent's
1274
+ * input). With `beforeMerge`, a Forgejo plan or applying job hands each
1275
+ * path on as its job outputs (#4992), and its gate or record job keeps
1276
+ * them as this artifact, so the product needs no upload step of its own.
1206
1277
  */
1207
- artifact?: { step: string; name: string; path: string };
1278
+ artifact?: OpWaveJobArtifact;
1279
+ /**
1280
+ * With `beforeMerge` (#4994): what the wave's gate job adds, which runs the
1281
+ * after-gate hooks (a product's report of the decision) at the default
1282
+ * branch's code with the token. `report` runs after the job's command
1283
+ * whatever its exit, as above; `artifact` keeps what the report and the
1284
+ * hooks wrote, `{job}` being the gate job's name. Absent: the gate job
1285
+ * renders as before.
1286
+ */
1287
+ gate?: { report?: OpWaveRunStep; artifact?: OpWaveJobArtifact };
1288
+ }
1289
+
1290
+ /** A product's artifact of a wave job (#4791, {@link OpWaveJobInputs.artifact}). */
1291
+ export interface OpWaveJobArtifact {
1292
+ step: string;
1293
+ name: string;
1294
+ /** One path, or several (#4994). */
1295
+ path: string | string[];
1208
1296
  }
1209
1297
 
1210
1298
  /** What a product adds to the plans job, `record-plans` (#4791, {@link OpWavesPipelineOptions.recordPlans}). */
@@ -46,6 +46,13 @@ export interface AppliedGateRecord {
46
46
  * once it is gone, and the wave applies the rest under the same approval.
47
47
  */
48
48
  resume?: GateRunLocator;
49
+ /**
50
+ * Spent by a split wave's gate job for a held hook that runs again in the
51
+ * plan job of a later run of the same commit (#4994): `head` is that
52
+ * commit. Until a finished line names this line, such a plan job runs the
53
+ * hook again under it; any other job reads it as spent.
54
+ */
55
+ rerun?: { head: string };
49
56
  }
50
57
 
51
58
  /**
@@ -634,6 +634,54 @@ describe("lifecycle/git", () => {
634
634
  }
635
635
  });
636
636
 
637
+ /** An update hook that refuses the first push with GitHub's words from plywood's 0.3.9 cut, and takes the rest (#4965). */
638
+ const refuseOnce = (remotePath: string) =>
639
+ writeFileSync(
640
+ join(remotePath, "hooks", "update"),
641
+ `#!/bin/sh\nif [ ! -f '${remotePath}/refused' ]; then touch '${remotePath}/refused'; echo 'fatal error in commit_refs_rules' >&2; exit 1; fi\nexit 0\n`,
642
+ { mode: 0o755 },
643
+ );
644
+
645
+ test("#4965: a push the remote refuses once is pushed again and lands", async () => {
646
+ const { b, remotePath, done } = await twoWriters();
647
+ try {
648
+ refuseOnce(remotePath);
649
+ await writeBlobToPath("prod", "release.json", '{"cut":1}', "Release cut", { cwd: b });
650
+ expect(await pushLifecycleRebasing({ cwd: b, requireLanded: true, waitMs: 0 })).toEqual({ pushed: true });
651
+ expect(git(["rev-parse", "refs/heads/chant/lifecycle"], remotePath).stdout.trim()).toBe(git(["rev-parse", "refs/heads/chant/lifecycle"], b).stdout.trim());
652
+ } finally {
653
+ await done();
654
+ }
655
+ });
656
+
657
+ test("#4965: the first push of the branch, refused once, is pushed again and lands", async () => {
658
+ const { clonePath, remotePath, cleanup } = await setupClonePair();
659
+ try {
660
+ refuseOnce(remotePath);
661
+ await writeBlobToPath("prod", "release.json", '{"cut":1}', "Release cut", { cwd: clonePath });
662
+ expect(await pushLifecycleRebasing({ cwd: clonePath, requireLanded: true, waitMs: 0 })).toEqual({ pushed: true });
663
+ expect(git(["show", "chant/lifecycle:prod/release.json"], remotePath).stdout).toBe('{"cut":1}');
664
+ } finally {
665
+ await cleanup();
666
+ }
667
+ });
668
+
669
+ test("#4965: with requireLanded, a push that fails for another reason is tried again and then throws", async () => {
670
+ const { clonePath, cleanup } = await setupClonePair();
671
+ try {
672
+ await writeBlobToPath("prod", "release.json", '{"cut":1}', "Release cut", { cwd: clonePath });
673
+ git(["remote", "set-url", "origin", join(tmpdir(), `chant-no-such-remote-${Date.now()}`)], clonePath);
674
+ // Without it the failure is a warning, as before.
675
+ expect((await pushLifecycleRebasing({ cwd: clonePath })).pushed).toBe(false);
676
+ const err = await pushLifecycleRebasing({ cwd: clonePath, requireLanded: true, waitMs: 0 }).catch((e: unknown) => e);
677
+ expect(err).toBeInstanceOf(LifecyclePushLostError);
678
+ expect((err as LifecyclePushLostError).tries).toBe(LIFECYCLE_PUSH_TRIES);
679
+ expect((err as Error).message).toContain("the push of chant/lifecycle to \"origin\" failed");
680
+ } finally {
681
+ await cleanup();
682
+ }
683
+ });
684
+
637
685
  test("plywood#22 finding 9: two writers that append lines to one ledger file both land, in push order", async () => {
638
686
  const { a, b, remotePath, done } = await twoWriters();
639
687
  try {
@@ -976,6 +976,9 @@ function pushReportOf(result: LifecyclePushStatus): { pushed: boolean; pushWarni
976
976
  /** How many pushes {@link pushLifecycleRebasing} makes, as the snapshot store's `publishRef` does. */
977
977
  export const LIFECYCLE_PUSH_TRIES = 3;
978
978
 
979
+ /** With `requireLanded`, how long {@link pushLifecycleRebasing} waits after a failed push, times the try's number (#4965). */
980
+ export const LIFECYCLE_PUSH_WAIT_MS = 2_000;
981
+
979
982
  /**
980
983
  * Thrown by {@link pushLifecycleRebasing} when the ledger branch did not reach
981
984
  * the remote: another writer pushed before each of its tries, or this
@@ -1013,6 +1016,8 @@ async function rebaseLifecycleOnRemote(remote: string, cwd?: string): Promise<{
1013
1016
  const firstLine = (s: string | undefined) => (s ?? "").trim().split("\n")[0] ?? "";
1014
1017
  try {
1015
1018
  const fetched = await run(["fetch", "--no-tags", "--force", remote, `refs/heads/${STATE_BRANCH}:${REBASE_REF}`]);
1019
+ // #4965: the remote refused the branch's first push (a hook, a rule) and still has none: nothing to replay onto.
1020
+ if (fetched.exitCode !== 0 && /couldn't find remote ref/i.test(fetched.stderr ?? "")) return { rebased: 0 };
1016
1021
  if (fetched.exitCode !== 0) return { error: `the fetch of the remote's tip failed (git said: ${firstLine(fetched.stderr)})` };
1017
1022
  const remoteTip = (await run(["rev-parse", "--verify", REBASE_REF])).stdout.trim();
1018
1023
  const local = await getStateBranchTip(cwd);
@@ -1206,22 +1211,40 @@ async function replayAppends(parent: string, commit: string, onto: string, cwd?:
1206
1211
  * remote, recording off and a push git refused for another reason (no
1207
1212
  * network, no credentials) are returned as {@link pushLifecycleReport}
1208
1213
  * returns them.
1214
+ *
1215
+ * `requireLanded` (#4965) is for a writer that must not go on without its
1216
+ * record on the remote, such as `chant release cut` before the workflow pushes
1217
+ * the release tag: a push git refused for another reason is tried again too,
1218
+ * `waitMs` times the try's number after it (default
1219
+ * {@link LIFECYCLE_PUSH_WAIT_MS}), and the last refusal throws
1220
+ * {@link LifecyclePushLostError}. No remote and recording off still return.
1209
1221
  */
1210
- export async function pushLifecycleRebasing(opts?: { cwd?: string; tries?: number }): Promise<{ pushed: boolean; pushWarning?: string }> {
1222
+ export async function pushLifecycleRebasing(opts?: { cwd?: string; tries?: number; requireLanded?: boolean; waitMs?: number }): Promise<{ pushed: boolean; pushWarning?: string }> {
1211
1223
  const tries = Math.max(1, opts?.tries ?? LIFECYCLE_PUSH_TRIES);
1212
1224
  const cwd = opts?.cwd;
1225
+ const waitMs = opts?.waitMs ?? LIFECYCLE_PUSH_WAIT_MS;
1213
1226
  for (let attempt = 1; ; attempt++) {
1214
1227
  let result: LifecyclePushStatus;
1215
1228
  try {
1216
1229
  result = await pushLifecycleStatus({ cwd });
1217
1230
  } catch (err) {
1218
- return { pushed: false, pushWarning: err instanceof Error ? err.message : String(err) };
1231
+ const message = err instanceof Error ? err.message : String(err);
1232
+ if (!opts?.requireLanded) return { pushed: false, pushWarning: message };
1233
+ result = { status: "failed", remote: "(unknown)", stderr: message };
1234
+ }
1235
+ if (result.status === "failed" && opts?.requireLanded) {
1236
+ if (attempt >= tries) throw new LifecyclePushLostError(result.remote, attempt, describeLifecyclePush(result) ?? "the push did not land");
1237
+ if (waitMs > 0) await new Promise((r) => setTimeout(r, waitMs * attempt));
1238
+ continue;
1219
1239
  }
1220
1240
  if (result.status !== "stale") return pushReportOf(result);
1221
1241
  if (attempt >= tries) {
1222
- const said = result.stderr.trim().split("\n")[0];
1223
- throw new LifecyclePushLostError(result.remote, attempt, `another writer pushed before each try${said ? ` (git said: ${said})` : ""}`);
1242
+ // #4965: "[remote rejected]" is the remote's own refusal (a hook, a rule), which no other writer explains.
1243
+ const said = result.stderr.trim().split("\n").find((l) => /remote rejected/.test(l))?.trim() ?? result.stderr.trim().split("\n")[0];
1244
+ const why = /remote rejected/.test(result.stderr) ? "the remote refused each try" : "another writer pushed before each try";
1245
+ throw new LifecyclePushLostError(result.remote, attempt, `${why}${said ? ` (git said: ${said})` : ""}`);
1224
1246
  }
1247
+ if (opts?.requireLanded && waitMs > 0) await new Promise((r) => setTimeout(r, waitMs * attempt));
1225
1248
  const rebased = await rebaseLifecycleOnRemote(result.remote, cwd);
1226
1249
  if ("error" in rebased) throw new LifecyclePushLostError(result.remote, attempt, rebased.error);
1227
1250
  }
@@ -53,7 +53,7 @@
53
53
  */
54
54
 
55
55
  import { execFileSync, spawn } from "node:child_process";
56
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
56
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
57
57
  import { tmpdir } from "node:os";
58
58
  import { join, relative, resolve, sep } from "node:path";
59
59
  import { packageSbom } from "./publish-attachments";
@@ -241,6 +241,36 @@ export function checkPackageImages(release: PublishContext["release"], cwd: stri
241
241
  }
242
242
  }
243
243
 
244
+ /**
245
+ * #4941: {@link checkPackageImages} for every npm target `release.publish`
246
+ * declares, run by the cut once the images are built and before anything is
247
+ * recorded, so a package that would carry an archive stops the cut instead of
248
+ * the publish job after the label is spent. A package that is not a
249
+ * directory with a package.json yet is left for the publish's plan to refuse.
250
+ */
251
+ export function checkDeclaredPackageImages(
252
+ decls: ReadonlyArray<{ type: string; packages?: readonly string[] }>,
253
+ release: PublishContext["release"],
254
+ cwd: string,
255
+ bin = "npm",
256
+ env: NodeJS.ProcessEnv = process.env,
257
+ ): void {
258
+ for (const decl of decls) {
259
+ if (decl.type !== "npm") continue;
260
+ const pkgs = (decl.packages ?? []).flatMap((path) => {
261
+ const abs = resolve(cwd, path);
262
+ if (!existsSync(abs) || !isDir(abs)) return [];
263
+ try {
264
+ const name = (JSON.parse(readFileSync(join(abs, "package.json"), "utf-8")) as { name?: unknown }).name;
265
+ return [{ path, abs, name: typeof name === "string" ? name : path }];
266
+ } catch {
267
+ return [];
268
+ }
269
+ });
270
+ checkPackageImages(release, cwd, pkgs, bin, env);
271
+ }
272
+ }
273
+
244
274
  export function npmTarget(decl: NpmPublishDeclaration, deps: PublishDeps): PublishTarget {
245
275
  const bin = deps.npm ?? "npm";
246
276
  const sleep = deps.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
@@ -0,0 +1,87 @@
1
+ /**
2
+ * #4979: `chant lock --reach`, the targets a change reaches by the pipeline's
3
+ * reach line, after the pull request's head is fetched and checked, and
4
+ * GitLab's `--open` over every open merge request.
5
+ */
6
+ import { describe, expect, test } from "vitest";
7
+ import { pullRequestHeadRef, REACH_HEAD_REF, reachedTargets, reachOpen, type ReachRun } from "./reach-locks";
8
+
9
+ const HEAD = "c".repeat(40);
10
+ const BASE = "b".repeat(40);
11
+
12
+ /** A run that answers git and the reach line as given, and keeps what it was asked. */
13
+ function runs(o: { fetch?: number; head?: string; out?: string; status?: number; stderr?: string } = {}) {
14
+ const calls: Array<{ argv: string[]; env?: Record<string, string | undefined> }> = [];
15
+ const run: ReachRun = (argv, opts) => {
16
+ calls.push({ argv, ...(opts.env ? { env: opts.env } : {}) });
17
+ if (argv[1] === "fetch") return { status: o.fetch ?? 0, stdout: "", stderr: o.fetch ? "fatal: couldn't find remote ref" : "" };
18
+ if (argv[1] === "rev-parse") return { status: 0, stdout: `${o.head ?? HEAD}\n`, stderr: "" };
19
+ return { status: o.status ?? 0, stdout: o.out ?? "", stderr: o.stderr ?? "" };
20
+ };
21
+ return { run, calls };
22
+ }
23
+
24
+ describe("reachedTargets (#4979)", () => {
25
+ test("fetches the head, runs the line with BASE_SHA, HEAD_SHA and PR_NUMBER, and locks each name once, sorted", () => {
26
+ const r = runs({ out: "envs/prod/app\n\nenvs/dev/network\n envs/prod/app \n" });
27
+ expect(reachedTargets({ forge: "github", pr: 7, head: HEAD, base: BASE, line: "terragucci reached", env: { PATH: "/bin" }, run: r.run })).toEqual({ targets: ["envs/dev/network", "envs/prod/app"] });
28
+ expect(r.calls[0]!.argv).toEqual(["git", "fetch", "-q", "--no-tags", "origin", `+refs/pull/7/head:${REACH_HEAD_REF}`]);
29
+ expect(r.calls[2]!.argv).toEqual(["sh", "-c", "terragucci reached"]);
30
+ expect(r.calls[2]!.env).toEqual({ PATH: "/bin", BASE_SHA: BASE, HEAD_SHA: HEAD, PR_NUMBER: "7" });
31
+ });
32
+
33
+ test("GitLab's head is the merge request's ref", () => {
34
+ expect(pullRequestHeadRef("gitlab", 3)).toBe("refs/merge-requests/3/head");
35
+ expect(pullRequestHeadRef("forgejo", 3)).toBe("refs/pull/3/head");
36
+ });
37
+
38
+ test("a head that moved is left to its own run, and nothing is read", () => {
39
+ const r = runs({ head: "d".repeat(40) });
40
+ expect(reachedTargets({ forge: "github", pr: 7, head: HEAD, base: BASE, line: "x", run: r.run })).toEqual({ moved: "pull request 7 moved to dddddddddddd after cccccccccccc, so the run of that push locks it" });
41
+ expect(r.calls.map((c) => c.argv[0])).toEqual(["git", "git"]);
42
+ });
43
+
44
+ test("a fetch, a line that fails, or a name with a control character says why", () => {
45
+ expect(reachedTargets({ forge: "gitlab", pr: 7, head: HEAD, base: BASE, line: "x", run: runs({ fetch: 128 }).run })).toEqual({ error: "could not fetch merge request !7's head (fatal: couldn't find remote ref)" });
46
+ expect(reachedTargets({ forge: "github", pr: 7, head: HEAD, base: BASE, line: "x", run: runs({ status: 2, stderr: "no layers" }).run })).toEqual({ error: "the reach line exited 2: no layers" });
47
+ expect(reachedTargets({ forge: "github", pr: 7, head: HEAD, base: BASE, line: "x", run: runs({ out: "a\u001b[31mb\n" }).run })).toMatchObject({ error: expect.stringMatching(/is not a target name/) });
48
+ expect(reachedTargets({ forge: "github", pr: 7, head: "main", base: BASE, line: "x", run: runs().run })).toEqual({ error: '--head "main" is not a commit sha' });
49
+ expect(reachedTargets({ forge: "github", pr: 7, head: HEAD, base: BASE, line: " ", run: runs().run })).toEqual({ error: "the reach line in CHANT_LOCK_REACH is empty" });
50
+ });
51
+
52
+ test("a change that reaches nothing locks nothing", () => {
53
+ expect(reachedTargets({ forge: "github", pr: 7, head: HEAD, base: BASE, line: "x", run: runs({ out: "" }).run })).toEqual({ targets: [] });
54
+ });
55
+ });
56
+
57
+ describe("reachOpen, GitLab's lock job (#4979)", () => {
58
+ test("locks each open merge request from the project into the branch, skips a fork, and releases a closed holder's locks", async () => {
59
+ const took: Array<[number, string, string[]]> = [];
60
+ const released: number[] = [];
61
+ const got = await reachOpen({
62
+ forge: "gitlab",
63
+ base: BASE,
64
+ line: "x",
65
+ branch: "main",
66
+ run: runs({ out: "envs/dev\n" }).run,
67
+ open: [
68
+ { number: 1, headSha: HEAD, base: "main", fork: false },
69
+ { number: 2, headSha: HEAD, base: "main", fork: true },
70
+ { number: 3, headSha: HEAD, base: "release", fork: false },
71
+ { number: 4, headSha: HEAD, base: "main", fork: false },
72
+ ],
73
+ take: async (pr, head, targets) => {
74
+ took.push([pr, head, targets]);
75
+ return pr === 4 ? { ok: false, held: "envs/dev is locked by merge request !1, so merge request !4 is not locked" } : { ok: true, released: [] };
76
+ },
77
+ holders: async () => [1, 5, 6],
78
+ isOpen: async (pr) => pr === 6,
79
+ release: async (pr) => (released.push(pr), ["envs/old"]),
80
+ });
81
+ expect(took).toEqual([[1, HEAD, ["envs/dev"]], [4, HEAD, ["envs/dev"]]]);
82
+ expect(got.outcomes.map((o) => [o.pr, o.kind])).toEqual([[1, "locked"], [2, "skipped"], [3, "skipped"], [4, "held"]]);
83
+ // !5 is closed; !6 is open into another branch, so it keeps its locks.
84
+ expect(released).toEqual([5]);
85
+ expect(got.released).toEqual([{ pr: 5, targets: ["envs/old"] }]);
86
+ });
87
+ });