@intentius/chant 0.124.55 → 0.124.57

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 (419) hide show
  1. package/dist/ci-agent.d.ts.map +1 -1
  2. package/dist/ci-agent.js +1 -2
  3. package/dist/ci-audit/attribution.d.ts +111 -0
  4. package/dist/ci-audit/attribution.d.ts.map +1 -0
  5. package/dist/ci-audit/attribution.js +194 -0
  6. package/dist/ci-audit/audit-log.d.ts +144 -0
  7. package/dist/ci-audit/audit-log.d.ts.map +1 -0
  8. package/dist/ci-audit/audit-log.js +149 -0
  9. package/dist/ci-audit/index.d.ts +12 -0
  10. package/dist/ci-audit/index.d.ts.map +1 -0
  11. package/dist/ci-audit/index.js +11 -0
  12. package/dist/ci-audit/unrecorded.d.ts +74 -0
  13. package/dist/ci-audit/unrecorded.d.ts.map +1 -0
  14. package/dist/ci-audit/unrecorded.js +95 -0
  15. package/dist/ci-audit.d.ts +3 -0
  16. package/dist/ci-audit.d.ts.map +1 -0
  17. package/dist/ci-audit.js +2 -0
  18. package/dist/ci-control.d.ts.map +1 -1
  19. package/dist/ci-control.js +3 -4
  20. package/dist/ci-estate.d.ts +24 -0
  21. package/dist/ci-estate.d.ts.map +1 -1
  22. package/dist/ci-estate.js +1 -2
  23. package/dist/ci-identity.d.ts.map +1 -1
  24. package/dist/ci-identity.js +2 -3
  25. package/dist/ci-job-guard.d.ts +139 -0
  26. package/dist/ci-job-guard.d.ts.map +1 -0
  27. package/dist/ci-job-guard.js +287 -0
  28. package/dist/ci-jobs.d.ts +7 -0
  29. package/dist/ci-jobs.d.ts.map +1 -1
  30. package/dist/ci-jobs.js +7 -0
  31. package/dist/ci-product-words.d.ts +7 -1
  32. package/dist/ci-product-words.d.ts.map +1 -1
  33. package/dist/ci-product-words.js +38 -4
  34. package/dist/ci-product.d.ts +35 -0
  35. package/dist/ci-product.d.ts.map +1 -1
  36. package/dist/ci-product.js +38 -4
  37. package/dist/ci-respond-run.d.ts +73 -0
  38. package/dist/ci-respond-run.d.ts.map +1 -0
  39. package/dist/ci-respond-run.js +247 -0
  40. package/dist/ci-respond.d.ts +189 -0
  41. package/dist/ci-respond.d.ts.map +1 -0
  42. package/dist/ci-respond.js +285 -0
  43. package/dist/cli/handlers/audit-log.d.ts +12 -0
  44. package/dist/cli/handlers/audit-log.d.ts.map +1 -0
  45. package/dist/cli/handlers/audit-log.js +81 -0
  46. package/dist/cli/handlers/build.d.ts +7 -0
  47. package/dist/cli/handlers/build.d.ts.map +1 -1
  48. package/dist/cli/handlers/build.js +81 -0
  49. package/dist/cli/handlers/ci-check-job.d.ts +11 -0
  50. package/dist/cli/handlers/ci-check-job.d.ts.map +1 -0
  51. package/dist/cli/handlers/ci-check-job.js +27 -0
  52. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  53. package/dist/cli/handlers/ci-check.js +38 -9
  54. package/dist/cli/handlers/e2e-safe-run.d.ts +12 -0
  55. package/dist/cli/handlers/e2e-safe-run.d.ts.map +1 -0
  56. package/dist/cli/handlers/e2e-safe-run.js +23 -0
  57. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  58. package/dist/cli/handlers/lifecycle.js +14 -0
  59. package/dist/cli/handlers/pr.d.ts +5 -0
  60. package/dist/cli/handlers/pr.d.ts.map +1 -1
  61. package/dist/cli/handlers/pr.js +346 -36
  62. package/dist/cli/handlers/run-wave.js +89 -1
  63. package/dist/cli/main.d.ts.map +1 -1
  64. package/dist/cli/main.js +56 -2
  65. package/dist/cli/parse-args.d.ts.map +1 -1
  66. package/dist/cli/parse-args.js +107 -0
  67. package/dist/cli/registry.d.ts +38 -0
  68. package/dist/cli/registry.d.ts.map +1 -1
  69. package/dist/components/adoption.d.ts.map +1 -1
  70. package/dist/components/adoption.js +1 -2
  71. package/dist/components/auto-release.d.ts +5 -2
  72. package/dist/components/auto-release.d.ts.map +1 -1
  73. package/dist/components/auto-release.js +9 -4
  74. package/dist/components/capability.d.ts +47 -0
  75. package/dist/components/capability.d.ts.map +1 -1
  76. package/dist/components/capability.js +25 -0
  77. package/dist/components/check-hooks.d.ts +4 -1
  78. package/dist/components/check-hooks.d.ts.map +1 -1
  79. package/dist/components/check-steps.d.ts +74 -0
  80. package/dist/components/check-steps.d.ts.map +1 -0
  81. package/dist/components/check-steps.js +102 -0
  82. package/dist/components/ci-services.d.ts.map +1 -1
  83. package/dist/components/ci-services.js +1 -2
  84. package/dist/components/deploy-units.d.ts +12 -0
  85. package/dist/components/deploy-units.d.ts.map +1 -1
  86. package/dist/components/deploy-units.js +20 -1
  87. package/dist/components/driver.d.ts +12 -0
  88. package/dist/components/driver.d.ts.map +1 -1
  89. package/dist/components/driver.js +35 -1
  90. package/dist/components/groups.d.ts.map +1 -1
  91. package/dist/components/groups.js +4 -3
  92. package/dist/components/pr-env-ledger.d.ts.map +1 -1
  93. package/dist/components/pr-env-ledger.js +1 -2
  94. package/dist/components/pr-environment.d.ts +1 -1
  95. package/dist/components/pr-environment.d.ts.map +1 -1
  96. package/dist/components/pr-environment.js +1 -1
  97. package/dist/components/pr-pipeline.d.ts +137 -5
  98. package/dist/components/pr-pipeline.d.ts.map +1 -1
  99. package/dist/components/pr-pipeline.js +164 -20
  100. package/dist/components/pr-run.d.ts +8 -0
  101. package/dist/components/pr-run.d.ts.map +1 -1
  102. package/dist/components/pr-run.js +9 -4
  103. package/dist/components/product-pipeline.d.ts +35 -2
  104. package/dist/components/product-pipeline.d.ts.map +1 -1
  105. package/dist/components/product-pipeline.js +24 -5
  106. package/dist/components/row-lease.d.ts +22 -1
  107. package/dist/components/row-lease.d.ts.map +1 -1
  108. package/dist/components/row-lease.js +32 -6
  109. package/dist/components/wave-plan.d.ts +8 -0
  110. package/dist/components/wave-plan.d.ts.map +1 -1
  111. package/dist/components/wave-plan.js +18 -2
  112. package/dist/e2e-harness/bucket.d.ts +21 -0
  113. package/dist/e2e-harness/bucket.d.ts.map +1 -0
  114. package/dist/e2e-harness/bucket.js +61 -0
  115. package/dist/e2e-harness/claim.d.ts +70 -0
  116. package/dist/e2e-harness/claim.d.ts.map +1 -0
  117. package/dist/e2e-harness/claim.js +98 -0
  118. package/dist/e2e-harness/driver.d.ts +64 -0
  119. package/dist/e2e-harness/driver.d.ts.map +1 -0
  120. package/dist/e2e-harness/driver.js +243 -0
  121. package/dist/e2e-harness/forgejo.d.ts +77 -0
  122. package/dist/e2e-harness/forgejo.d.ts.map +1 -0
  123. package/dist/e2e-harness/forgejo.js +205 -0
  124. package/dist/e2e-harness/git.d.ts +32 -0
  125. package/dist/e2e-harness/git.d.ts.map +1 -0
  126. package/dist/e2e-harness/git.js +67 -0
  127. package/dist/e2e-harness/index.d.ts +22 -0
  128. package/dist/e2e-harness/index.d.ts.map +1 -0
  129. package/dist/e2e-harness/index.js +47 -0
  130. package/dist/e2e-harness/jobs.d.ts +8 -0
  131. package/dist/e2e-harness/jobs.d.ts.map +1 -0
  132. package/dist/e2e-harness/jobs.js +34 -0
  133. package/dist/e2e-harness/pins.d.ts +45 -0
  134. package/dist/e2e-harness/pins.d.ts.map +1 -0
  135. package/dist/e2e-harness/pins.js +44 -0
  136. package/dist/e2e-harness/ports.d.ts +113 -0
  137. package/dist/e2e-harness/ports.d.ts.map +1 -0
  138. package/dist/e2e-harness/ports.js +4 -0
  139. package/dist/e2e-harness/reports.d.ts +45 -0
  140. package/dist/e2e-harness/reports.d.ts.map +1 -0
  141. package/dist/e2e-harness/reports.js +57 -0
  142. package/dist/e2e-harness/safe-run-cli.d.ts +17 -0
  143. package/dist/e2e-harness/safe-run-cli.d.ts.map +1 -0
  144. package/dist/e2e-harness/safe-run-cli.js +43 -0
  145. package/dist/e2e-harness/safe-run.d.ts +61 -0
  146. package/dist/e2e-harness/safe-run.d.ts.map +1 -0
  147. package/dist/e2e-harness/safe-run.js +172 -0
  148. package/dist/e2e-harness/scenario.d.ts +11 -0
  149. package/dist/e2e-harness/scenario.d.ts.map +1 -0
  150. package/dist/e2e-harness/scenario.js +89 -0
  151. package/dist/e2e-harness/schemas/demo-cycle.schema.json +282 -0
  152. package/dist/e2e-harness/schemas/demo-step.schema.json +245 -0
  153. package/dist/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
  154. package/dist/e2e-harness/schemas/e2e-claims.schema.json +18 -0
  155. package/dist/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
  156. package/dist/e2e-harness/schemas/index.d.ts +191 -0
  157. package/dist/e2e-harness/schemas/index.d.ts.map +1 -0
  158. package/dist/e2e-harness/schemas/index.js +62 -0
  159. package/dist/e2e-harness/stack.d.ts +124 -0
  160. package/dist/e2e-harness/stack.d.ts.map +1 -0
  161. package/dist/e2e-harness/stack.js +207 -0
  162. package/dist/e2e-harness/steps.d.ts +11 -0
  163. package/dist/e2e-harness/steps.d.ts.map +1 -0
  164. package/dist/e2e-harness/steps.js +22 -0
  165. package/dist/e2e-harness.d.ts +3 -0
  166. package/dist/e2e-harness.d.ts.map +1 -0
  167. package/dist/e2e-harness.js +2 -0
  168. package/dist/exit-codes.d.ts +7 -1
  169. package/dist/exit-codes.d.ts.map +1 -1
  170. package/dist/exit-codes.js +7 -1
  171. package/dist/lexicon.d.ts +55 -0
  172. package/dist/lexicon.d.ts.map +1 -1
  173. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  174. package/dist/lifecycle/gate-ledger.js +2 -3
  175. package/dist/lifecycle/gated-request.d.ts.map +1 -1
  176. package/dist/lifecycle/gated-request.js +1 -2
  177. package/dist/lifecycle/git.d.ts +39 -3
  178. package/dist/lifecycle/git.d.ts.map +1 -1
  179. package/dist/lifecycle/git.js +223 -15
  180. package/dist/lifecycle/lock-rows.d.ts +23 -0
  181. package/dist/lifecycle/lock-rows.d.ts.map +1 -1
  182. package/dist/lifecycle/lock-rows.js +47 -8
  183. package/dist/lifecycle/query.d.ts.map +1 -1
  184. package/dist/lifecycle/query.js +4 -5
  185. package/dist/lifecycle/release-catalog.d.ts.map +1 -1
  186. package/dist/lifecycle/release-catalog.js +1 -1
  187. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  188. package/dist/lifecycle/release-ledger.js +1 -2
  189. package/dist/lifecycle/release-status.d.ts +20 -0
  190. package/dist/lifecycle/release-status.d.ts.map +1 -1
  191. package/dist/lifecycle/release-status.js +1 -22
  192. package/dist/lifecycle/resource-lock.d.ts +70 -0
  193. package/dist/lifecycle/resource-lock.d.ts.map +1 -1
  194. package/dist/lifecycle/resource-lock.js +241 -5
  195. package/dist/lifecycle/wave-plans.d.ts +23 -7
  196. package/dist/lifecycle/wave-plans.d.ts.map +1 -1
  197. package/dist/lifecycle/wave-plans.js +9 -2
  198. package/dist/op/approval-status.d.ts +103 -0
  199. package/dist/op/approval-status.d.ts.map +1 -0
  200. package/dist/op/approval-status.js +197 -0
  201. package/dist/op/gate.js +21 -4
  202. package/dist/op/index.d.ts +1 -1
  203. package/dist/op/index.d.ts.map +1 -1
  204. package/dist/op/index.js +1 -1
  205. package/dist/op/op-waves-capability-spec.d.ts +8 -0
  206. package/dist/op/op-waves-capability-spec.d.ts.map +1 -1
  207. package/dist/op/op-waves-capability-spec.js +21 -0
  208. package/dist/op/op-waves-release-port.js +1 -1
  209. package/dist/op/op-waves-release.d.ts +2 -1
  210. package/dist/op/op-waves-release.d.ts.map +1 -1
  211. package/dist/op/op-waves-release.js +1 -2
  212. package/dist/op/op-waves-run.d.ts +15 -2
  213. package/dist/op/op-waves-run.d.ts.map +1 -1
  214. package/dist/op/op-waves-run.js +195 -31
  215. package/dist/op/op-waves-stand-down.d.ts.map +1 -1
  216. package/dist/op/op-waves-stand-down.js +1 -2
  217. package/dist/op/op-waves.d.ts +53 -0
  218. package/dist/op/op-waves.d.ts.map +1 -1
  219. package/dist/op/op-waves.js +62 -6
  220. package/dist/op/runtime.d.ts +4 -0
  221. package/dist/op/runtime.d.ts.map +1 -1
  222. package/dist/op/runtime.js +2 -3
  223. package/dist/otlp.d.ts.map +1 -1
  224. package/dist/otlp.js +1 -2
  225. package/dist/parallelism.d.ts +17 -0
  226. package/dist/parallelism.d.ts.map +1 -0
  227. package/dist/parallelism.js +33 -0
  228. package/dist/policy-source.d.ts.map +1 -1
  229. package/dist/policy-source.js +1 -2
  230. package/dist/pr-forge.d.ts.map +1 -1
  231. package/dist/pr-forge.js +56 -39
  232. package/dist/pr-loop.d.ts +9 -0
  233. package/dist/pr-loop.d.ts.map +1 -1
  234. package/dist/pr-loop.js +22 -4
  235. package/dist/pr-merge.d.ts +64 -0
  236. package/dist/pr-merge.d.ts.map +1 -0
  237. package/dist/pr-merge.js +78 -0
  238. package/dist/pr-post.d.ts +70 -1
  239. package/dist/pr-post.d.ts.map +1 -1
  240. package/dist/pr-post.js +116 -5
  241. package/dist/pr-report-url.d.ts.map +1 -1
  242. package/dist/pr-report-url.js +1 -2
  243. package/dist/release-floors.d.ts +1 -1
  244. package/dist/release-floors.js +1 -1
  245. package/dist/run-event.d.ts.map +1 -1
  246. package/dist/run-event.js +1 -2
  247. package/dist/scheduled-op-cloud.d.ts +32 -0
  248. package/dist/scheduled-op-cloud.d.ts.map +1 -0
  249. package/dist/scheduled-op-cloud.js +69 -0
  250. package/dist/wave-runtime.mjs +351 -328
  251. package/dist/workspace/ci-lock-grain.d.ts +5 -0
  252. package/dist/workspace/ci-lock-grain.d.ts.map +1 -1
  253. package/dist/workspace/ci-lock-grain.js +1 -7
  254. package/dist/workspace/ci-run.d.ts.map +1 -1
  255. package/dist/workspace/ci-run.js +5 -1
  256. package/dist/workspace/pr-report.schema.json +5 -0
  257. package/package.json +1 -1
  258. package/src/ci-agent.ts +1 -2
  259. package/src/ci-audit/__fixtures__/cloudtrail-lookup-bucket.json +37 -0
  260. package/src/ci-audit/__fixtures__/cloudtrail-writes-window.json +59 -0
  261. package/src/ci-audit/attribution.ts +260 -0
  262. package/src/ci-audit/audit-log.ts +220 -0
  263. package/src/ci-audit/ci-audit.test.ts +175 -0
  264. package/src/ci-audit/index.ts +14 -0
  265. package/src/ci-audit/unrecorded.ts +140 -0
  266. package/src/ci-audit.ts +2 -0
  267. package/src/ci-control.ts +3 -4
  268. package/src/ci-estate.ts +1 -2
  269. package/src/ci-identity-database.test.ts +2 -3
  270. package/src/ci-identity-targets.test.ts +1 -3
  271. package/src/ci-identity.ts +2 -3
  272. package/src/ci-job-guard.test.ts +154 -0
  273. package/src/ci-job-guard.ts +319 -0
  274. package/src/ci-jobs.ts +8 -0
  275. package/src/ci-product-comment-targets.test.ts +45 -0
  276. package/src/ci-product-words.ts +35 -6
  277. package/src/ci-product.ts +55 -4
  278. package/src/ci-respond-run.ts +291 -0
  279. package/src/ci-respond.test.ts +264 -0
  280. package/src/ci-respond.ts +412 -0
  281. package/src/cli/handlers/audit-log.ts +74 -0
  282. package/src/cli/handlers/build-pr-loop-flags.test.ts +98 -0
  283. package/src/cli/handlers/build.ts +69 -0
  284. package/src/cli/handlers/ci-check-job.test.ts +114 -0
  285. package/src/cli/handlers/ci-check-job.ts +33 -0
  286. package/src/cli/handlers/ci-check.ts +38 -8
  287. package/src/cli/handlers/e2e-safe-run.ts +27 -0
  288. package/src/cli/handlers/lifecycle.ts +13 -0
  289. package/src/cli/handlers/pr-before-merge.test.ts +1 -1
  290. package/src/cli/handlers/pr-deploy-inputs.test.ts +1 -1
  291. package/src/cli/handlers/pr-endpoint.test.ts +1 -1
  292. package/src/cli/handlers/pr-green.test.ts +1 -1
  293. package/src/cli/handlers/pr-plan-comment-targets.test.ts +166 -0
  294. package/src/cli/handlers/pr-plan-flags.test.ts +161 -0
  295. package/src/cli/handlers/pr-plan-targets.test.ts +1 -1
  296. package/src/cli/handlers/pr-record.test.ts +34 -2
  297. package/src/cli/handlers/pr-waves-blocked.test.ts +1 -1
  298. package/src/cli/handlers/pr-waves.test.ts +1 -1
  299. package/src/cli/handlers/pr.test.ts +1 -1
  300. package/src/cli/handlers/pr.ts +311 -32
  301. package/src/cli/handlers/run-wave.ts +79 -1
  302. package/src/cli/main.test.ts +1 -1
  303. package/src/cli/main.ts +56 -2
  304. package/src/cli/parse-args.ts +77 -0
  305. package/src/cli/registry.ts +38 -0
  306. package/src/components/adoption.ts +1 -2
  307. package/src/components/auto-release.test.ts +4 -2
  308. package/src/components/auto-release.ts +9 -5
  309. package/src/components/capability.ts +60 -0
  310. package/src/components/check-hooks.ts +4 -1
  311. package/src/components/check-steps.test.ts +70 -0
  312. package/src/components/check-steps.ts +158 -0
  313. package/src/components/ci-services.ts +1 -2
  314. package/src/components/deploy-units.test.ts +18 -1
  315. package/src/components/deploy-units.ts +26 -1
  316. package/src/components/driver.ts +35 -1
  317. package/src/components/groups.ts +4 -2
  318. package/src/components/plan-flags.test.ts +46 -0
  319. package/src/components/pr-comment-preview-targets.test.ts +34 -0
  320. package/src/components/pr-env-ledger.ts +1 -2
  321. package/src/components/pr-env-run-bundle.test.ts +0 -20
  322. package/src/components/pr-environment.ts +1 -1
  323. package/src/components/pr-pipeline-runners.test.ts +80 -0
  324. package/src/components/pr-pipeline.ts +244 -20
  325. package/src/components/pr-run.ts +17 -6
  326. package/src/components/pr-stale-job.test.ts +34 -0
  327. package/src/components/product-pipeline.ts +50 -8
  328. package/src/components/row-lease.test.ts +61 -1
  329. package/src/components/row-lease.ts +48 -7
  330. package/src/components/wave-plan.ts +18 -2
  331. package/src/e2e-harness/__project__/chant.config.ts +4 -0
  332. package/src/e2e-harness/__project__/src/compose.ts +33 -0
  333. package/src/e2e-harness/bucket.ts +69 -0
  334. package/src/e2e-harness/claim.test.ts +150 -0
  335. package/src/e2e-harness/claim.ts +140 -0
  336. package/src/e2e-harness/driver.test.ts +304 -0
  337. package/src/e2e-harness/driver.ts +294 -0
  338. package/src/e2e-harness/forgejo.ts +267 -0
  339. package/src/e2e-harness/git.ts +96 -0
  340. package/src/e2e-harness/index.ts +49 -0
  341. package/src/e2e-harness/jobs.ts +35 -0
  342. package/src/e2e-harness/pins.ts +52 -0
  343. package/src/e2e-harness/ports.ts +130 -0
  344. package/src/e2e-harness/reports.ts +79 -0
  345. package/src/e2e-harness/safe-run-cli.test.ts +102 -0
  346. package/src/e2e-harness/safe-run-cli.ts +54 -0
  347. package/src/e2e-harness/safe-run.ts +198 -0
  348. package/src/e2e-harness/scenario.ts +89 -0
  349. package/src/e2e-harness/schemas/README.md +62 -0
  350. package/src/e2e-harness/schemas/demo-cycle.schema.json +282 -0
  351. package/src/e2e-harness/schemas/demo-step.schema.json +245 -0
  352. package/src/e2e-harness/schemas/e2e-claim-row.schema.json +33 -0
  353. package/src/e2e-harness/schemas/e2e-claims.schema.json +18 -0
  354. package/src/e2e-harness/schemas/e2e-scenario.schema.json +150 -0
  355. package/src/e2e-harness/schemas/index.ts +220 -0
  356. package/src/e2e-harness/schemas.test.ts +145 -0
  357. package/src/e2e-harness/stack.test.ts +124 -0
  358. package/src/e2e-harness/stack.ts +306 -0
  359. package/src/e2e-harness/steps.ts +30 -0
  360. package/src/e2e-harness.ts +2 -0
  361. package/src/exit-codes.test.ts +3 -2
  362. package/src/exit-codes.ts +7 -1
  363. package/src/gate-decision-bundle.test.ts +0 -2
  364. package/src/lexicon.ts +57 -0
  365. package/src/lifecycle/control-entries-ledger.test.ts +2 -3
  366. package/src/lifecycle/gate-ledger.ts +2 -3
  367. package/src/lifecycle/gated-request.ts +1 -2
  368. package/src/lifecycle/git.test.ts +155 -0
  369. package/src/lifecycle/git.ts +213 -17
  370. package/src/lifecycle/lock-rows.test.ts +6 -1
  371. package/src/lifecycle/lock-rows.ts +58 -7
  372. package/src/lifecycle/query.ts +4 -5
  373. package/src/lifecycle/release-catalog.test.ts +3 -4
  374. package/src/lifecycle/release-catalog.ts +1 -1
  375. package/src/lifecycle/release-ledger.ts +1 -2
  376. package/src/lifecycle/release-status.test.ts +3 -4
  377. package/src/lifecycle/release-status.ts +1 -2
  378. package/src/lifecycle/resource-lock-wait.test.ts +292 -0
  379. package/src/lifecycle/resource-lock.ts +261 -7
  380. package/src/lifecycle/wave-plans.ts +33 -5
  381. package/src/op/approval-status.test.ts +134 -0
  382. package/src/op/approval-status.ts +235 -0
  383. package/src/op/gate-review.test.ts +2 -1
  384. package/src/op/gate.test.ts +7 -5
  385. package/src/op/gate.ts +20 -4
  386. package/src/op/index.ts +2 -0
  387. package/src/op/op-waves-after-plan.test.ts +11 -0
  388. package/src/op/op-waves-capability-spec.ts +20 -0
  389. package/src/op/op-waves-ledger-lock.test.ts +208 -0
  390. package/src/op/op-waves-parallelism.test.ts +89 -0
  391. package/src/op/op-waves-pull-request.test.ts +78 -1
  392. package/src/op/op-waves-release-port.ts +1 -1
  393. package/src/op/op-waves-release.ts +2 -3
  394. package/src/op/op-waves-run.ts +196 -31
  395. package/src/op/op-waves-stand-down.ts +1 -2
  396. package/src/op/op-waves.ts +81 -6
  397. package/src/op/runtime.ts +6 -3
  398. package/src/otlp.ts +1 -2
  399. package/src/parallelism.test.ts +38 -0
  400. package/src/parallelism.ts +33 -0
  401. package/src/policy-source.ts +1 -2
  402. package/src/pr-forge-bundle.test.ts +1 -1
  403. package/src/pr-forge.ts +54 -35
  404. package/src/pr-loop-bundle.test.ts +0 -2
  405. package/src/pr-loop-narrowed.test.ts +63 -0
  406. package/src/pr-loop.ts +30 -4
  407. package/src/pr-merge.test.ts +100 -0
  408. package/src/pr-merge.ts +105 -0
  409. package/src/pr-post-stale.test.ts +163 -0
  410. package/src/pr-post.ts +159 -5
  411. package/src/pr-report-url.ts +1 -2
  412. package/src/product-subpaths-plain-node.e2e.test.ts +1 -0
  413. package/src/release-floors.ts +1 -1
  414. package/src/run-event.ts +1 -2
  415. package/src/scheduled-op-cloud.ts +68 -0
  416. package/src/stage-hooks-bundle.test.ts +0 -2
  417. package/src/workspace/ci-lock-grain.ts +1 -2
  418. package/src/workspace/ci-run.ts +5 -1
  419. package/src/workspace/pr-report.schema.json +5 -0
@@ -0,0 +1,235 @@
1
+ /**
2
+ * The approval status before merge (#4630): `<product>/approval` on an open
3
+ * pull request's head says whether the waves its merge will run wait for an
4
+ * approval. It covers the waves whose approval at base is `pr-review` and,
5
+ * under the 2026-10-28 ruling, the waves whose approval is `pull-request`.
6
+ *
7
+ * - `pending` while a wave whose gate the plan will hold has no approval
8
+ * that would pass it: under `pr-review` an approving review of that head,
9
+ * by a writer other than its author; under `pull-request` the pull
10
+ * request's own approval (below).
11
+ * - `success` once every such wave has one, or when no wave's gate holds
12
+ * the plan.
13
+ *
14
+ * Which waves the gate holds is read the way the wave job reads it after the
15
+ * merge: each wave's approval mode and policy from the spec at the pull
16
+ * request's base (`readOpWavePolicy`), applied to the facts the head's plans
17
+ * record (`chant run wave --record-plans`, `../lifecycle/wave-plans.ts`):
18
+ * whether a run changes anything and whether a plan is destructive. A head
19
+ * whose plans are not recorded yet is pending, since nothing says its waves
20
+ * pass.
21
+ *
22
+ * The pull request's own approval, for a `pull-request` wave: an approval at
23
+ * the pull request's gate (`approvals.pullRequest.gate` at base) whose
24
+ * change set covers the wave's change set at the head, as the merged wave
25
+ * checks it (`planCoveredBy`). The approval is read on the pull request's
26
+ * op (`pr-<n>`), where the product's approve line records it, and on the
27
+ * spec's op, which the merged wave reads. The head's change set is the one
28
+ * `--record-plans` stored for the wave; a record without one is pending.
29
+ *
30
+ * The status job reads only: the pull request, its reviews and
31
+ * `chant/lifecycle`. It writes the one commit status. On GitHub and Forgejo
32
+ * it runs after the record-plans job and on every review; on GitLab, whose
33
+ * approvals start no pipeline, a scheduled pipeline of the target branch
34
+ * posts it for every open merge request (`--open`). An approval recorded on
35
+ * the ledger starts no run on any forge: the next push, review or `--open`
36
+ * run posts it. The status advises: the gate after the merge decides, from
37
+ * the ledger and the merged review.
38
+ */
39
+
40
+ import { activeProductWords, productStatusContext, type CiProductWords } from "../ci-product-words";
41
+ import type { ChangeSetDocument } from "../change-set";
42
+ import type { GateResolutionRecord } from "../lifecycle/gate-ledger";
43
+ import type { HeadPlans } from "../lifecycle/wave-plans";
44
+ import type { PrApproverFilter, PrForge } from "../pr-forge";
45
+ import type { OpWaveGatePolicy, OpWavesSpec } from "./op-waves";
46
+ import type { OpWaveShowAtBase } from "./op-waves-run";
47
+
48
+ /** What the status says. */
49
+ export interface ApprovalStatus {
50
+ state: "pending" | "success";
51
+ description: string;
52
+ /** The waves whose gate the plan will hold, by number. */
53
+ waits: number[];
54
+ /** Who approved the head, when someone did. */
55
+ approvers: string[];
56
+ }
57
+
58
+ export interface ApprovalStatusInput {
59
+ spec: OpWavesSpec;
60
+ /** The spec's path, which the policy is read from at `base`. */
61
+ specFile: string;
62
+ forge: Pick<PrForge, "prApproved" | "kind">;
63
+ pr: number;
64
+ /** The pull request's head commit. */
65
+ head: string;
66
+ /** The pull request's base commit, which the policy is read at. */
67
+ base: string;
68
+ cwd?: string;
69
+ /** The head's recorded plans. Default: `chant/lifecycle` at `cwd`. */
70
+ readPlans?: (name: string, head: string) => Promise<HeadPlans | null>;
71
+ /** How the spec is read at base. Default `git show`. */
72
+ show?: OpWaveShowAtBase;
73
+ /** Who may approve, as the forge's requires check takes it. */
74
+ approvers?: PrApproverFilter;
75
+ /** The resolutions on one op's gate ledger, for a `pull-request` wave. Default: `chant/lifecycle` at `cwd`. */
76
+ readResolutions?: (op: string) => Promise<GateResolutionRecord[]>;
77
+ /** A stored change set by digest, for a `pull-request` wave. Default: `_change-sets/` on `chant/lifecycle` at `cwd`. */
78
+ changeSets?: (digest: string) => Promise<ChangeSetDocument | undefined>;
79
+ }
80
+
81
+ /** Whether `policy` holds a wave with these facts. A record with no facts reads as changing, so it holds under `always`. */
82
+ export function headWaveHolds(policy: OpWaveGatePolicy, facts: { changes?: boolean; destructive?: boolean }): boolean {
83
+ if (policy === "never") return false;
84
+ if (facts.changes === false) return false;
85
+ if (policy === "on-destructive") return facts.destructive === true;
86
+ return true;
87
+ }
88
+
89
+ const short = (sha: string): string => sha.slice(0, 8);
90
+ const cut = (text: string): string => (text.length > 135 ? `${text.slice(0, 132)}...` : text);
91
+
92
+ /** The status for one pull request's head. Throws only when the spec cannot be read at base. */
93
+ export async function approvalStatusOf(input: ApprovalStatusInput): Promise<ApprovalStatus> {
94
+ const cwd = input.cwd ?? process.cwd();
95
+ const { readOpWavePolicy } = await import("./op-waves-run");
96
+ const rulesOf = (name: string) => readOpWavePolicy(input.specFile, name, input.base, cwd, ...(input.show ? [input.show] : []));
97
+ const asked = input.spec.waves
98
+ .map((w, i) => ({ k: i + 1, wave: w, rules: rulesOf(w.name) }))
99
+ .filter(({ rules }) => rules.approval === "pr-review" || rules.approval === "pull-request");
100
+ if (asked.length === 0) return { state: "success", description: "no wave takes its approval from the pull request", waits: [], approvers: [] };
101
+ const plans = await (input.readPlans ?? ((name, head) => ledgerHeadPlans(name, head, cwd)))(input.spec.name, input.head);
102
+ if (!plans) {
103
+ return { state: "pending", description: cut(`the plans of ${short(input.head)} are not recorded yet, so every wave may wait`), waits: asked.map((r) => r.k), approvers: [] };
104
+ }
105
+ const factsOf = (k: number) => plans.waves.find((w) => w.wave === k);
106
+ const holding = asked.filter(({ k, rules }) => headWaveHolds(rules.policy, factsOf(k) ?? {}));
107
+ const waits = holding.map((r) => r.k);
108
+ if (waits.length === 0) return { state: "success", description: cut(`no wave waits for an approval at ${short(input.head)}`), waits, approvers: [] };
109
+
110
+ const unmet: string[] = [];
111
+ const approvers = new Set<string>();
112
+ // pr-review: one approving review of the head answers every such wave.
113
+ const byReview = holding.filter((r) => r.rules.approval === "pr-review").map((r) => r.k);
114
+ if (byReview.length > 0) {
115
+ const which = wavesLabel(byReview);
116
+ if (!input.forge.prApproved) unmet.push(`${which}: ${input.forge.kind} cannot say who approved the head`);
117
+ else {
118
+ const approved = await input.forge.prApproved(input.pr, input.head, input.approvers);
119
+ if (approved.passed && approved.approvers.length > 0) for (const a of approved.approvers) approvers.add(a);
120
+ else unmet.push(`${which}: ${approved.reason}`);
121
+ }
122
+ }
123
+ // pull-request: the pull request's own approval, whose change set must cover each wave's.
124
+ const byPullRequest = holding.filter((r) => r.rules.approval === "pull-request");
125
+ if (byPullRequest.length > 0) {
126
+ const read = pullRequestApprovalReader(input, cwd);
127
+ for (const { k, rules } of byPullRequest) {
128
+ const got = await read(rules.pullRequestGate, factsOf(k)?.changeSet);
129
+ if (got.approvedBy) approvers.add(got.approvedBy);
130
+ else unmet.push(`wave ${k}: ${got.reason}`);
131
+ }
132
+ }
133
+ const which = wavesLabel(waits);
134
+ if (unmet.length > 0) return { state: "pending", description: cut(`${which} wait: ${unmet.join("; ")}`), waits, approvers: [] };
135
+ const by = [...approvers];
136
+ return { state: "success", description: cut(`${which} approved at ${short(input.head)} by ${by.join(", ")}`), waits, approvers: by };
137
+ }
138
+
139
+ const wavesLabel = (ks: readonly number[]): string => `wave${ks.length === 1 ? "" : "s"} ${ks.join(", ")}`;
140
+
141
+ /**
142
+ * How a `pull-request` wave's approval is found before merge: the newest
143
+ * approval at the pull request's gate, on the pull request's op or the
144
+ * spec's, whose change set covers the wave's change set at the head.
145
+ */
146
+ function pullRequestApprovalReader(input: ApprovalStatusInput, cwd: string) {
147
+ const resolutionsOf = input.readResolutions ?? ((op: string) => ledgerResolutions(op, cwd));
148
+ const changeSetOf = input.changeSets ?? ((digest: string) => ledgerChangeSet(digest, cwd));
149
+ let all: Promise<GateResolutionRecord[]> | undefined;
150
+ const resolutions = () =>
151
+ (all ??= (async () => {
152
+ // The pull request's op, as `prOp` (../pr-loop.ts) names it, and the spec's.
153
+ const ops = [...new Set([`pr-${input.pr}`, input.spec.name])];
154
+ return (await Promise.all(ops.map((op) => resolutionsOf(op)))).flat();
155
+ })());
156
+ return async (gate: string | undefined, digest: string | undefined): Promise<{ approvedBy?: string; reason: string }> => {
157
+ if (!gate) return { reason: "the spec at base names no approvals.pullRequest.gate" };
158
+ if (!digest) return { reason: `the plans of ${short(input.head)} carry no change set to check the pull request's approval against` };
159
+ const fresh = await changeSetOf(digest).catch(() => undefined);
160
+ if (!fresh) return { reason: `the change set ${digest} of ${short(input.head)} is not stored` };
161
+ const approvals = (await resolutions()).filter((r) => r.gate === gate && (r.changeSet ?? r.planDigest)).sort((a, b) => (a.timestamp < b.timestamp ? 1 : -1));
162
+ if (approvals.length === 0) return { reason: `the pull request's gate ${gate} has no approval` };
163
+ const { planCoveredBy } = await import("../components/pr-run");
164
+ let reason = `no approval at ${gate} covers its plans`;
165
+ for (const r of approvals) {
166
+ const approvedDigest = (r.changeSet ?? r.planDigest)!;
167
+ const approved = approvedDigest === fresh.digest ? fresh : await changeSetOf(approvedDigest).catch(() => undefined);
168
+ if (!approved) {
169
+ reason = `the change set ${approvedDigest} the approval at ${gate} names is not stored`;
170
+ continue;
171
+ }
172
+ const why = fresh.members.map((m) => planCoveredBy(approved, fresh, m.member)).find((w) => w !== undefined);
173
+ if (why === undefined) return { approvedBy: r.resolvedBy, reason: "" };
174
+ reason = why;
175
+ }
176
+ return { reason };
177
+ };
178
+ }
179
+
180
+ /** Post the status on the head. Returns what was posted. */
181
+ export async function postApprovalStatus(
182
+ input: ApprovalStatusInput & { forge: Pick<PrForge, "prApproved" | "kind" | "setStatus" | "runUrl"> },
183
+ words: CiProductWords = activeProductWords(),
184
+ ): Promise<ApprovalStatus> {
185
+ const status = await approvalStatusOf(input);
186
+ await input.forge.setStatus(input.head, {
187
+ context: productStatusContext(words, "approval"),
188
+ state: status.state,
189
+ description: status.description,
190
+ ...(input.forge.runUrl ? { url: input.forge.runUrl } : {}),
191
+ });
192
+ return status;
193
+ }
194
+
195
+ /**
196
+ * Post the status on every open pull request into `branch` (#4630), for
197
+ * GitLab's scheduled pipeline: the forge names each head and base. One
198
+ * that fails is a warning, and the rest are posted.
199
+ */
200
+ export async function postOpenApprovalStatuses(
201
+ input: Omit<ApprovalStatusInput, "pr" | "head" | "base"> & { forge: Pick<PrForge, "prApproved" | "kind" | "setStatus" | "runUrl" | "openPullRequests">; branch: string },
202
+ words: CiProductWords = activeProductWords(),
203
+ ): Promise<{ posted: Array<{ pr: number; status: ApprovalStatus }>; warnings: string[] }> {
204
+ if (!input.forge.openPullRequests) throw new Error(`${input.forge.kind} cannot list its open pull requests, so --open is not for it`);
205
+ const posted: Array<{ pr: number; status: ApprovalStatus }> = [];
206
+ const warnings: string[] = [];
207
+ for (const open of await input.forge.openPullRequests(input.branch)) {
208
+ if (open.fork) continue;
209
+ try {
210
+ const status = await postApprovalStatus({ ...input, pr: open.number, head: open.headSha, base: open.baseSha ?? input.branch }, words);
211
+ posted.push({ pr: open.number, status });
212
+ } catch (err) {
213
+ warnings.push(`!${open.number}: ${err instanceof Error ? err.message : String(err)}`);
214
+ }
215
+ }
216
+ return { posted, warnings };
217
+ }
218
+
219
+ async function ledgerHeadPlans(name: string, head: string, cwd: string): Promise<HeadPlans | null> {
220
+ const { gitLedgerReadPort, requireLifecycleLedger } = await import("../lifecycle/git");
221
+ const { readHeadPlans } = await import("../lifecycle/wave-plans");
222
+ await requireLifecycleLedger({ cwd });
223
+ return readHeadPlans(gitLedgerReadPort({ cwd }), name, head);
224
+ }
225
+
226
+ async function ledgerResolutions(op: string, cwd: string): Promise<GateResolutionRecord[]> {
227
+ const { readGateLedger } = await import("../lifecycle/gate-ledger");
228
+ return (await readGateLedger(op, { cwd })).resolutions;
229
+ }
230
+
231
+ async function ledgerChangeSet(digest: string, cwd: string): Promise<ChangeSetDocument | undefined> {
232
+ const { readStoredChangeSet } = await import("../lifecycle/change-set-store");
233
+ const got = await readStoredChangeSet(digest, { cwd });
234
+ return got.status === "found" ? got.document : undefined;
235
+ }
@@ -177,7 +177,8 @@ describe("a pr-review wave (#3684)", () => {
177
177
  const h = harness(digest("a"));
178
178
  let written: unknown;
179
179
  const recorded = await recordOpWaveHeadPlans({ spec: spec("pr-review"), cwd: h.cwd, exec: h.exec, head: HEAD, now: "t", write: async (p) => void (written = p) });
180
- expect(recorded.waves).toEqual([{ wave: 1, name: "prod", digest: set(digest("a")) }]);
180
+ // #4630: the record keeps whether the wave changes anything and whether it is destructive.
181
+ expect(recorded.waves).toEqual([{ wave: 1, name: "prod", digest: set(digest("a")), changes: true, destructive: false }]);
181
182
  expect(written).toEqual(recorded);
182
183
  });
183
184
  });
@@ -571,12 +571,14 @@ describe("op/gate — a rejected ledger push is reported, not swallowed (#2310)"
571
571
  timestamp: "2026-09-09T05:10:00.000Z",
572
572
  expiresAt: "2026-09-10T05:10:00.000Z",
573
573
  });
574
- expect(third.pushed).toBe(false);
575
- expect(third.pushWarning).toBeTruthy();
576
- expect(third.pushWarning).toMatch(/chant\/lifecycle remote branch has moved|stale|rejected|non-fast-forward/i);
577
- // The append itself still landed locally — a correct local answer, per
578
- // the #2309 author's reasoning; only the report was missing.
574
+ // plywood#22 finding 9: the refused push replays the third fact on the
575
+ // remote's tip and pushes again, so it lands beside the other writer's.
576
+ expect(third.pushed).toBe(true);
577
+ expect(third.pushWarning).toBeUndefined();
579
578
  expect(third.record.gate).toBe("approve-third-gate");
579
+ const onRemote = git(["log", "-p", "chant/lifecycle"], remote).stdout;
580
+ expect(onRemote).toContain("approve-other-gate");
581
+ expect(onRemote).toContain("approve-third-gate");
580
582
  });
581
583
 
582
584
  test("evaluateGate carries the rejection onto the gate check it returns, recorded but not pushed", async () => {
package/src/op/gate.ts CHANGED
@@ -59,7 +59,7 @@ import {
59
59
  quorumNeed, quorumRuleProgress, quorumRules, ruleNeedsProof, samePrincipal, trustQuorumJudge, UNPROVEN_JUDGE,
60
60
  type GateQuorumJudge, type GateQuorumRuleProgress, type GateQuorumSpec,
61
61
  } from "./gate-quorum";
62
- import { pushLifecycleReport, readBlobBySha, readBlobFromPath, readPathSha, requireLifecycleLedger, writeBlobToPath, RefCASConflictError } from "../lifecycle/git";
62
+ import { LifecyclePushLostError, pushLifecycleRebasing, readBlobBySha, readBlobFromPath, readPathSha, requireLifecycleLedger, writeBlobToPath, RefCASConflictError } from "../lifecycle/git";
63
63
  import { parseDuration } from "./duration";
64
64
  import { ciRunIdFromEnv, resolveGateRunLocator } from "./gate-run-locator";
65
65
  import { resolveCommitSha } from "../lifecycle/commit-sha";
@@ -202,11 +202,11 @@ export function gitGateLedgerPort(opts?: { cwd?: string }): GateLedgerPort {
202
202
  },
203
203
  async appendResolution(input) {
204
204
  const { record } = await appendGateResolution(input, opts);
205
- return { record, ...(await pushLifecycleReport(opts)) };
205
+ return { record, ...(await pushGateLine(opts)) };
206
206
  },
207
207
  async appendPending(input) {
208
208
  const { record } = await appendPendingGate(input, opts);
209
- return { record, ...(await pushLifecycleReport(opts)) };
209
+ return { record, ...(await pushGateLine(opts)) };
210
210
  },
211
211
  async writeCheckpoint(checkpoint) {
212
212
  await writeGateCheckpoint(checkpoint, opts);
@@ -255,7 +255,7 @@ export function gitGateLedgerPort(opts?: { cwd?: string }): GateLedgerPort {
255
255
  ...opts,
256
256
  expectPriorPathSha: prior,
257
257
  });
258
- return pushLifecycleReport(opts);
258
+ return pushGateLine(opts);
259
259
  } catch (err) {
260
260
  if (!(err instanceof RefCASConflictError)) throw err;
261
261
  lastErr = err;
@@ -1120,3 +1120,19 @@ export async function gateIsSealed(gate: string, cwd: string = process.cwd()): P
1120
1120
  return false;
1121
1121
  }
1122
1122
  }
1123
+
1124
+ /**
1125
+ * Push the gate line just written (plywood#22 finding 9): a push another
1126
+ * writer beat replays this checkout's commits on the remote's tip and pushes
1127
+ * again (`pushLifecycleRebasing`). One that never lands is reported as not
1128
+ * pushed, with `LifecyclePushLostError`'s message, so the spend line's
1129
+ * caller fails the wave as it does for any push that did not land.
1130
+ */
1131
+ async function pushGateLine(opts?: { cwd?: string }): Promise<{ pushed: boolean; pushWarning?: string }> {
1132
+ try {
1133
+ return await pushLifecycleRebasing(opts);
1134
+ } catch (err) {
1135
+ if (err instanceof LifecyclePushLostError) return { pushed: false, pushWarning: `LifecyclePushLostError: ${err.message}` };
1136
+ throw err;
1137
+ }
1138
+ }
package/src/op/index.ts CHANGED
@@ -78,7 +78,9 @@ export {
78
78
  runStageHooksAsync,
79
79
  spawnExecAsync,
80
80
  opWaveNeedsApproval,
81
+ opWavePlanPath,
81
82
  opWavePlansPath,
83
+ OP_WAVE_PLAN_PATH_FLOOR,
82
84
  opWaveRunsPath,
83
85
  opWaveSetDigest,
84
86
  parseOpWavesSpec,
@@ -274,3 +274,14 @@ describe("after-plan hooks in the job's process (#4614)", () => {
274
274
  expect(activeProductWaveHook()).toBeUndefined();
275
275
  });
276
276
  });
277
+
278
+ describe("opWavePlanPath", () => {
279
+ test("is exported from the op entry beside opWavePlansPath, and names one target's plan file", async () => {
280
+ const entry = await import("./index");
281
+ expect(entry.opWavePlanPath).toBe(opWavePlanPath);
282
+ expect(entry.OP_WAVE_PLAN_PATH_FLOOR).toBe("0.124.56");
283
+ const spec = { name: "demo" };
284
+ expect(entry.opWavePlanPath(spec, 2, "stacks/a b")).toBe(".chant/op-waves/demo/wave-2/stacks_a_b.plan.json");
285
+ expect(entry.opWavePlanPath(spec, 2, "x")).not.toBe(entry.opWavePlansPath(spec, 2));
286
+ });
287
+ });
@@ -73,6 +73,26 @@ export function opWaveStepProblems(spec: Pick<OpWavesSpec, "step" | "plan" | "ap
73
73
  return problems;
74
74
  }
75
75
 
76
+ /**
77
+ * What is wrong with the spec's and each wave's `parallelism` (#4625), empty
78
+ * when nothing is. Runs applied at once need the capability step, whose
79
+ * apply is one call per run with no gate in it. The whole-number check
80
+ * matches ../parallelism.ts's parallelismProblem, kept here so the spec
81
+ * module (and the bundles that hold it) do not load that file's run loop.
82
+ */
83
+ export function opWaveParallelismProblems(spec: Pick<OpWavesSpec, "parallelism" | "step" | "waves">): string[] {
84
+ const problems: string[] = [];
85
+ for (const [field, value] of [["parallelism", spec.parallelism] as const, ...spec.waves.map((w) => [`wave "${w.name}" parallelism`, w.parallelism] as const)]) {
86
+ if (value === undefined) continue;
87
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
88
+ problems.push(`${field} is ${JSON.stringify(value)}; give a whole number of 1 or more, the most that run at once`);
89
+ } else if (value > 1 && spec.step === undefined) {
90
+ problems.push(`${field} is ${value}, and runs apply at once only through \`step\`; drop it or give step`);
91
+ }
92
+ }
93
+ return problems;
94
+ }
95
+
76
96
  /** What is wrong with a spec's `holds`, empty when nothing is. */
77
97
  export function opWaveHoldsProblems(holds: unknown): string[] {
78
98
  if (holds === undefined) return [];
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Op waves under the ruling for ci-products (2026-10-28), "Ledger lock",
3
+ * and plywood#22 finding 9, on a bare remote with one clone per writer:
4
+ *
5
+ * - a run on the `target` grain whose lexicon names its target's row waits
6
+ * for it on the ledger, then applies; at the deadline it applies nothing,
7
+ * held, exit 5, by name;
8
+ * - a run on the resource grain never waits: a held row is exit 5 at once;
9
+ * - a run whose plan changes nothing takes no row;
10
+ * - the job's run record lands when another writer pushed to the same
11
+ * ledger file first.
12
+ */
13
+ import { afterAll, describe, expect, test } from "vitest";
14
+ import { execFileSync } from "node:child_process";
15
+ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
16
+ import { tmpdir } from "node:os";
17
+ import { join } from "node:path";
18
+ import type { OpWavesSpec } from "./op-waves";
19
+ import { gitOpWaveRunPort, runOpWave, type OpWaveShowAtBase } from "./op-waves-run";
20
+ import { memoryGateLedgerPort } from "./gate";
21
+ import { CapabilityRegistry, type Capability } from "../components/capability";
22
+ import type { ChangeSetPart } from "../change-set";
23
+ import { rootRowKey, type LockGrain } from "../lifecycle/lock-rows";
24
+ import { leaseLockRows, readLockRows } from "../lifecycle/resource-lock";
25
+ import { appendRunRecord, readRunLedger } from "../lifecycle/run-ledger";
26
+ import { pushLifecycle } from "../lifecycle/git";
27
+ import { CHANT_EXIT } from "../exit-codes";
28
+
29
+ const dirs: string[] = [];
30
+ afterAll(() => {
31
+ for (const d of dirs) rmSync(d, { recursive: true, force: true });
32
+ });
33
+
34
+ function tmp(prefix: string): string {
35
+ const d = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
36
+ dirs.push(d);
37
+ return d;
38
+ }
39
+
40
+ function git(cwd: string, ...args: string[]): string {
41
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
42
+ }
43
+
44
+ function writers(n: number): string[] {
45
+ const remote = tmp("op-waves-lock-remote-");
46
+ git(remote, "init", "-q", "--bare", "-b", "main");
47
+ const seed = tmp("op-waves-lock-seed-");
48
+ git(seed, "init", "-q", "-b", "main");
49
+ git(seed, "config", "user.email", "seed@chant.dev");
50
+ git(seed, "config", "user.name", "Seed");
51
+ git(seed, "config", "commit.gpgsign", "false");
52
+ writeFileSync(join(seed, "README.md"), "# t\n");
53
+ git(seed, "add", "README.md");
54
+ git(seed, "commit", "-q", "-m", "init");
55
+ git(seed, "remote", "add", "origin", remote);
56
+ git(seed, "push", "-q", "origin", "main");
57
+ return Array.from({ length: n }, (_, i) => {
58
+ const c = tmp(`op-waves-lock-clone-${i}-`);
59
+ git(c, "clone", "-q", remote, ".");
60
+ git(c, "config", "user.email", `w${i}@chant.dev`);
61
+ git(c, "config", "user.name", `Writer ${i}`);
62
+ git(c, "config", "commit.gpgsign", "false");
63
+ return c;
64
+ });
65
+ }
66
+
67
+ const digest = (n: string) => `sha256:${n.repeat(64)}`;
68
+ const alive = async () => "alive" as const;
69
+
70
+ /** A root capability on `grain`: the target grain names `root <root>`, the resource grain one row per root. */
71
+ function rootCapability(grain: LockGrain, action: "create" | "no-op" = "create"): { registry: CapabilityRegistry; ran: string[] } {
72
+ const ran: string[] = [];
73
+ const part = (member: string): ChangeSetPart => ({
74
+ member: { member, lexicon: "terraform", planner: "chant", status: "planned", planDigest: digest("9"), holes: [] },
75
+ entries: [{ member, address: `aws_s3_bucket.${member}`, type: "aws_s3_bucket", action } as ChangeSetPart["entries"][number]],
76
+ });
77
+ const cap: Capability<Record<string, unknown>, unknown> = {
78
+ kind: "fake-root",
79
+ async plan(_ctx, input) {
80
+ const root = String(input.root);
81
+ return { member: root, planDigest: digest(root === "network" ? "1" : "2"), artifact: { root }, changeSet: part(root) };
82
+ },
83
+ async run(_ctx, input) {
84
+ ran.push(String(input.root));
85
+ return { applied: input.root };
86
+ },
87
+ defaultLockGrain: () => grain,
88
+ targetLockRow: (input) => ({ key: rootRowKey(String(input.root)), target: String(input.root), address: String(input.root) }),
89
+ lockRows: (input) => [{ key: `root ${String(input.root)} aws_s3_bucket.${String(input.root)}`, target: String(input.root), address: `aws_s3_bucket.${String(input.root)}` }],
90
+ };
91
+ return { registry: new CapabilityRegistry().register(cap), ran };
92
+ }
93
+
94
+ const spec: OpWavesSpec = {
95
+ name: "roots",
96
+ op: "tf-apply",
97
+ step: { kind: "fake-root", root: "{target}" },
98
+ waves: [{ name: "dev", runs: [{ target: "network" }], gate: "never" }],
99
+ };
100
+ const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(spec) });
101
+
102
+ describe("op waves and the ledger lock", () => {
103
+ test("a root on the target grain waits for its root row, then applies once the other run lets go", async () => {
104
+ const [other, job] = writers(2) as [string, string];
105
+ const held = await leaseLockRows("pr-apply", [{ key: rootRowKey("network"), target: "network", address: "network" }], { cwd: other, alive, holder: { run: "71", at: new Date().toISOString() } });
106
+ expect(held.ok).toBe(true);
107
+ if (!held.ok) return;
108
+ const { registry, ran } = rootCapability("target");
109
+ const lines: string[] = [];
110
+ // The other run lets go once the job shows in the queue, so the job waits whatever the machine's speed.
111
+ let stop = false;
112
+ const letGo = (async () => {
113
+ while (!stop) {
114
+ const now = await readLockRows("pr-apply", { cwd: other });
115
+ if (Object.keys(now.waiting ?? {}).length > 0) return held.lease.release();
116
+ await new Promise((r) => setTimeout(r, 50));
117
+ }
118
+ return false;
119
+ })();
120
+ try {
121
+ const result = await runOpWave({
122
+ spec,
123
+ specFile: "waves.json",
124
+ wave: 1,
125
+ cwd: job,
126
+ show,
127
+ gates: memoryGateLedgerPort(),
128
+ capabilities: registry,
129
+ lockLiveness: alive,
130
+ lockPollMs: 50,
131
+ lockWaitSeconds: 60,
132
+ log: (l) => lines.push(l),
133
+ });
134
+ expect(result).toMatchObject({ exitCode: 0, applied: ["network"] });
135
+ } finally {
136
+ stop = true;
137
+ }
138
+ expect(await letGo).toBe(true);
139
+ expect(ran).toEqual(["network"]);
140
+ const text = lines.join("\n");
141
+ expect(text).toContain("wave 1 (dev): waits for root network of pr-apply: run 71 is applying network: network");
142
+ expect(text).toMatch(/wave 1 \(dev\): holds 1 row of pr-apply after waiting \d+s while it applies/);
143
+ // The job let go of the row when the wave ended.
144
+ expect((await readLockRows("pr-apply", { cwd: other })).rows).toEqual({});
145
+ });
146
+
147
+ test("a wait that reaches the job's deadline applies nothing, held, exit 5, by name", async () => {
148
+ const [other, job] = writers(2) as [string, string];
149
+ const held = await leaseLockRows("pr-apply", [{ key: rootRowKey("network"), target: "network", address: "network" }], { cwd: other, alive, holder: { run: "72", at: new Date().toISOString() } });
150
+ expect(held.ok).toBe(true);
151
+ const { registry, ran } = rootCapability("target");
152
+ const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: job, show, gates: memoryGateLedgerPort(), capabilities: registry, lockLiveness: alive, lockPollMs: 10, lockWaitSeconds: 0, log: () => {} });
153
+ expect(result.exitCode).toBe(CHANT_EXIT.held);
154
+ expect(result.outcome).toMatchObject({ outcome: "held", holder: { run: "72" } });
155
+ expect(result.outcome!.reason).toMatch(/^LockWaitTimeoutError: waited \d+s for root network of pr-apply/);
156
+ expect(ran).toEqual([]);
157
+ expect((await readLockRows("pr-apply", { cwd: other })).waiting).toBeUndefined();
158
+ });
159
+
160
+ test("a run on the resource grain never waits: a held row is exit 5 at once", async () => {
161
+ const [other, job] = writers(2) as [string, string];
162
+ const key = "root network aws_s3_bucket.network";
163
+ const held = await leaseLockRows("pr-apply", [{ key, target: "network", address: "aws_s3_bucket.network" }], { cwd: other, alive, holder: { run: "73", at: new Date().toISOString() } });
164
+ expect(held.ok).toBe(true);
165
+ const { registry, ran } = rootCapability("resource");
166
+ const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: job, show, gates: memoryGateLedgerPort(), capabilities: registry, lockLiveness: alive, lockPollMs: 10, lockWaitSeconds: 60, log: () => {} });
167
+ expect(result.exitCode).toBe(CHANT_EXIT.held);
168
+ expect(result.outcome!.reason).not.toContain("LockWaitTimeoutError");
169
+ expect(ran).toEqual([]);
170
+ });
171
+
172
+ test("a run whose plan changes nothing takes no row and applies beside the holder", async () => {
173
+ const [other, job] = writers(2) as [string, string];
174
+ const held = await leaseLockRows("pr-apply", [{ key: rootRowKey("network"), target: "network", address: "network" }], { cwd: other, alive, holder: { run: "74", at: new Date().toISOString() } });
175
+ expect(held.ok).toBe(true);
176
+ const { registry } = rootCapability("target", "no-op");
177
+ const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: job, show, gates: memoryGateLedgerPort(), capabilities: registry, lockLiveness: alive, lockPollMs: 10, lockWaitSeconds: 0, log: () => {} });
178
+ expect(result.exitCode).toBe(0);
179
+ });
180
+ });
181
+
182
+ describe("plywood#22 finding 9: the waves run's run record", () => {
183
+ test("lands on the remote when another writer appended to the same run ledger first", async () => {
184
+ const [a, b] = writers(2) as [string, string];
185
+ const record = (ended: string) => ({
186
+ op: "pulumi-up",
187
+ env: "dev",
188
+ started: "2026-10-28T23:39:08.000Z",
189
+ ended,
190
+ status: "ok" as const,
191
+ labels: { Env: "dev" },
192
+ outcomes: {},
193
+ phases: [],
194
+ });
195
+ // B's job wrote nothing yet; A, the other push's job, appends to dev/pulumi-up's ledger and pushes first.
196
+ await appendRunRecord(record("2026-10-28T23:40:03.000Z"), { cwd: a });
197
+ expect(await pushLifecycle({ cwd: a })).toBe(true);
198
+ git(b, "fetch", "-q", "origin", "chant/lifecycle:chant/lifecycle");
199
+ await appendRunRecord(record("2026-10-28T23:40:30.000Z"), { cwd: a });
200
+ expect(await pushLifecycle({ cwd: a })).toBe(true);
201
+ // B appends on the copy it fetched before A's second push, and its push replays on A's tip.
202
+ const port = gitOpWaveRunPort({ cwd: b });
203
+ expect(await port.append(record("2026-10-28T23:41:17.000Z"))).toEqual({});
204
+ git(a, "fetch", "-q", "origin", "chant/lifecycle:chant/lifecycle");
205
+ const { records } = await readRunLedger("dev", "pulumi-up", { cwd: a });
206
+ expect(records.map((r) => r.ended)).toEqual(["2026-10-28T23:40:03.000Z", "2026-10-28T23:40:30.000Z", "2026-10-28T23:41:17.000Z"]);
207
+ });
208
+ });