@intentius/chant 0.124.88 → 0.124.89

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 (303) 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 +177 -0
  10. package/dist/ci-comment-commands.d.ts.map +1 -0
  11. package/dist/ci-comment-commands.js +325 -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-note-commands.d.ts +63 -3
  25. package/dist/ci-note-commands.d.ts.map +1 -1
  26. package/dist/ci-note-commands.js +69 -35
  27. package/dist/ci-product-words.d.ts +42 -0
  28. package/dist/ci-product-words.d.ts.map +1 -1
  29. package/dist/ci-product-words.js +25 -0
  30. package/dist/ci-product.d.ts +31 -0
  31. package/dist/ci-product.d.ts.map +1 -1
  32. package/dist/ci-product.js +34 -4
  33. package/dist/cli/commands/build.d.ts.map +1 -1
  34. package/dist/cli/commands/build.js +29 -2
  35. package/dist/cli/handlers/approve.d.ts.map +1 -1
  36. package/dist/cli/handlers/approve.js +2 -1
  37. package/dist/cli/handlers/ci-check.d.ts +1 -1
  38. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  39. package/dist/cli/handlers/ci-check.js +17 -7
  40. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  41. package/dist/cli/handlers/ci-evidence.js +33 -7
  42. package/dist/cli/handlers/components.d.ts.map +1 -1
  43. package/dist/cli/handlers/components.js +3 -1
  44. package/dist/cli/handlers/generated-check.d.ts +8 -0
  45. package/dist/cli/handlers/generated-check.d.ts.map +1 -1
  46. package/dist/cli/handlers/generated-check.js +31 -1
  47. package/dist/cli/handlers/lock.d.ts.map +1 -1
  48. package/dist/cli/handlers/lock.js +121 -4
  49. package/dist/cli/handlers/pr-comment.d.ts +21 -0
  50. package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
  51. package/dist/cli/handlers/pr-comment.js +112 -0
  52. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  53. package/dist/cli/handlers/pr-env.js +6 -3
  54. package/dist/cli/handlers/pr.d.ts +23 -1
  55. package/dist/cli/handlers/pr.d.ts.map +1 -1
  56. package/dist/cli/handlers/pr.js +55 -9
  57. package/dist/cli/handlers/promote.d.ts.map +1 -1
  58. package/dist/cli/handlers/promote.js +2 -1
  59. package/dist/cli/handlers/release.d.ts.map +1 -1
  60. package/dist/cli/handlers/release.js +11 -2
  61. package/dist/cli/handlers/run-wave.d.ts.map +1 -1
  62. package/dist/cli/handlers/run-wave.js +28 -2
  63. package/dist/cli/handlers/run.d.ts.map +1 -1
  64. package/dist/cli/handlers/run.js +2 -1
  65. package/dist/cli/main.d.ts.map +1 -1
  66. package/dist/cli/main.js +24 -2
  67. package/dist/cli/parse-args.d.ts.map +1 -1
  68. package/dist/cli/parse-args.js +16 -0
  69. package/dist/cli/registry.d.ts +11 -0
  70. package/dist/cli/registry.d.ts.map +1 -1
  71. package/dist/components/auto-release.d.ts.map +1 -1
  72. package/dist/components/auto-release.js +2 -1
  73. package/dist/components/pr-checks.d.ts +70 -6
  74. package/dist/components/pr-checks.d.ts.map +1 -1
  75. package/dist/components/pr-checks.js +74 -13
  76. package/dist/components/pr-pipeline.d.ts +16 -12
  77. package/dist/components/pr-pipeline.d.ts.map +1 -1
  78. package/dist/components/pr-pipeline.js +3 -11
  79. package/dist/components/product-pipeline.d.ts +42 -1
  80. package/dist/components/product-pipeline.d.ts.map +1 -1
  81. package/dist/components/product-pipeline.js +64 -12
  82. package/dist/components/product-plan.d.ts +190 -5
  83. package/dist/components/product-plan.d.ts.map +1 -1
  84. package/dist/components/product-plan.js +220 -39
  85. package/dist/drift-record.d.ts +7 -0
  86. package/dist/drift-record.d.ts.map +1 -1
  87. package/dist/drift-record.js +19 -0
  88. package/dist/floor-table.data.d.ts.map +1 -1
  89. package/dist/floor-table.data.js +54 -31
  90. package/dist/forge-check/contract.d.ts +11 -1
  91. package/dist/forge-check/contract.d.ts.map +1 -1
  92. package/dist/forge-check/contract.js +4 -1
  93. package/dist/forge-check/index.d.ts +2 -0
  94. package/dist/forge-check/index.d.ts.map +1 -1
  95. package/dist/forge-check/index.js +2 -0
  96. package/dist/gate-resume-run.d.ts +9 -1
  97. package/dist/gate-resume-run.d.ts.map +1 -1
  98. package/dist/gate-resume-run.js +26 -3
  99. package/dist/generated-check.d.ts +18 -4
  100. package/dist/generated-check.d.ts.map +1 -1
  101. package/dist/generated-check.js +37 -5
  102. package/dist/image-pins.d.ts +26 -0
  103. package/dist/image-pins.d.ts.map +1 -0
  104. package/dist/image-pins.js +19 -0
  105. package/dist/lexicon.d.ts +11 -0
  106. package/dist/lexicon.d.ts.map +1 -1
  107. package/dist/lifecycle/git.d.ts +11 -0
  108. package/dist/lifecycle/git.d.ts.map +1 -1
  109. package/dist/lifecycle/git.js +30 -3
  110. package/dist/lifecycle/publish-npm.d.ts +11 -0
  111. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  112. package/dist/lifecycle/publish-npm.js +27 -1
  113. package/dist/lifecycle/reach-locks.d.ts +131 -0
  114. package/dist/lifecycle/reach-locks.d.ts.map +1 -0
  115. package/dist/lifecycle/reach-locks.js +118 -0
  116. package/dist/lifecycle/release-cut.d.ts +3 -1
  117. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  118. package/dist/lifecycle/release-cut.js +15 -0
  119. package/dist/lifecycle/release-images.d.ts.map +1 -1
  120. package/dist/lifecycle/release-images.js +1 -2
  121. package/dist/notify-product.d.ts +12 -3
  122. package/dist/notify-product.d.ts.map +1 -1
  123. package/dist/notify-product.js +10 -6
  124. package/dist/op/activities/source-release.d.ts.map +1 -1
  125. package/dist/op/activities/source-release.js +2 -1
  126. package/dist/op/activities/source-rollback.d.ts.map +1 -1
  127. package/dist/op/activities/source-rollback.js +2 -1
  128. package/dist/op/index.d.ts +2 -0
  129. package/dist/op/index.d.ts.map +1 -1
  130. package/dist/op/index.js +1 -0
  131. package/dist/op/op-waves-evidence-jobs.d.ts +6 -1
  132. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
  133. package/dist/op/op-waves-evidence-jobs.js +9 -3
  134. package/dist/op/op-waves-render-spec.d.ts +100 -0
  135. package/dist/op/op-waves-render-spec.d.ts.map +1 -0
  136. package/dist/op/op-waves-render-spec.js +162 -0
  137. package/dist/op/op-waves-run.d.ts +2 -0
  138. package/dist/op/op-waves-run.d.ts.map +1 -1
  139. package/dist/op/op-waves-run.js +2 -1
  140. package/dist/op/op-waves.d.ts +4 -0
  141. package/dist/op/op-waves.d.ts.map +1 -1
  142. package/dist/op/op-waves.js +4 -1
  143. package/dist/op/schedule-overdue.d.ts.map +1 -1
  144. package/dist/op/schedule-overdue.js +59 -3
  145. package/dist/op/wave-stop.d.ts +64 -0
  146. package/dist/op/wave-stop.d.ts.map +1 -0
  147. package/dist/op/wave-stop.js +127 -0
  148. package/dist/planned-files.d.ts +76 -0
  149. package/dist/planned-files.d.ts.map +1 -0
  150. package/dist/planned-files.js +108 -0
  151. package/dist/pr-forge-job.d.ts +22 -0
  152. package/dist/pr-forge-job.d.ts.map +1 -0
  153. package/dist/pr-forge-job.js +46 -0
  154. package/dist/pr-loop.d.ts +3 -6
  155. package/dist/pr-loop.d.ts.map +1 -1
  156. package/dist/pr-loop.js +4 -81
  157. package/dist/pr-plan-note.d.ts +97 -0
  158. package/dist/pr-plan-note.d.ts.map +1 -1
  159. package/dist/pr-plan-note.js +94 -1
  160. package/dist/pr-post.d.ts +28 -3
  161. package/dist/pr-post.d.ts.map +1 -1
  162. package/dist/pr-post.js +145 -13
  163. package/dist/pr-status.d.ts +16 -0
  164. package/dist/pr-status.d.ts.map +1 -0
  165. package/dist/pr-status.js +90 -0
  166. package/dist/ref-gate-init.d.ts +16 -2
  167. package/dist/ref-gate-init.d.ts.map +1 -1
  168. package/dist/ref-gate-init.js +24 -13
  169. package/dist/release-floors.d.ts +37 -1
  170. package/dist/release-floors.d.ts.map +1 -1
  171. package/dist/release-floors.js +61 -25
  172. package/dist/render-module.d.ts +15 -0
  173. package/dist/render-module.d.ts.map +1 -0
  174. package/dist/render-module.js +73 -0
  175. package/dist/state-migration.d.ts.map +1 -1
  176. package/dist/state-migration.js +1 -2
  177. package/dist/wave-runtime.mjs +304 -301
  178. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  179. package/dist/workspace/ci-green-cli.js +3 -2
  180. package/dist/workspace/release-train.d.ts.map +1 -1
  181. package/dist/workspace/release-train.js +2 -1
  182. package/dist/workspace/release-workflow.d.ts +4 -3
  183. package/dist/workspace/release-workflow.d.ts.map +1 -1
  184. package/dist/workspace/release-workflow.js +10 -7
  185. package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
  186. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  187. package/dist/workspace/trust/check-evidence-report.js +15 -8
  188. package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
  189. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
  190. package/dist/workspace/trust/ref-gate-cli.js +30 -10
  191. package/dist/workspace/workspace-run.d.ts.map +1 -1
  192. package/dist/workspace/workspace-run.js +2 -1
  193. package/package.json +1 -1
  194. package/src/actor.test.ts +68 -2
  195. package/src/actor.ts +61 -1
  196. package/src/chant-install.test.ts +2 -3
  197. package/src/chant-install.ts +1 -2
  198. package/src/ci-base.test.ts +41 -0
  199. package/src/ci-base.ts +43 -0
  200. package/src/ci-comment-commands.test.ts +376 -0
  201. package/src/ci-comment-commands.ts +389 -0
  202. package/src/ci-comment-replies.ts +78 -0
  203. package/src/ci-commit.test.ts +2 -3
  204. package/src/ci-evidence-from-job.test.ts +18 -0
  205. package/src/ci-evidence-from-job.ts +58 -2
  206. package/src/ci-evidence-jobs.ts +50 -5
  207. package/src/ci-image.test.ts +130 -9
  208. package/src/ci-image.ts +85 -12
  209. package/src/ci-note-commands.ts +104 -41
  210. package/src/ci-product-words.ts +59 -0
  211. package/src/ci-product.ts +40 -4
  212. package/src/cli/commands/build.test.ts +41 -0
  213. package/src/cli/commands/build.ts +27 -2
  214. package/src/cli/handlers/approve.ts +2 -1
  215. package/src/cli/handlers/ci-check.ts +19 -7
  216. package/src/cli/handlers/ci-evidence.ts +29 -8
  217. package/src/cli/handlers/components.ts +3 -1
  218. package/src/cli/handlers/generated-check.ts +31 -1
  219. package/src/cli/handlers/lock-reach.test.ts +103 -0
  220. package/src/cli/handlers/lock.ts +100 -4
  221. package/src/cli/handlers/pr-comment.ts +104 -0
  222. package/src/cli/handlers/pr-env.ts +6 -3
  223. package/src/cli/handlers/pr-record.test.ts +1 -1
  224. package/src/cli/handlers/pr.ts +50 -10
  225. package/src/cli/handlers/promote.ts +2 -1
  226. package/src/cli/handlers/release.e2e.test.ts +35 -0
  227. package/src/cli/handlers/release.ts +14 -2
  228. package/src/cli/handlers/run-wave.ts +28 -2
  229. package/src/cli/handlers/run.ts +2 -1
  230. package/src/cli/main.ts +24 -2
  231. package/src/cli/parse-args.ts +12 -0
  232. package/src/cli/registry.ts +11 -0
  233. package/src/components/auto-release.ts +2 -1
  234. package/src/components/pr-checks.ts +112 -17
  235. package/src/components/pr-pipeline.ts +17 -15
  236. package/src/components/product-pipeline.ts +93 -11
  237. package/src/components/product-plan.test.ts +40 -2
  238. package/src/components/product-plan.ts +331 -45
  239. package/src/drift-record.test.ts +20 -0
  240. package/src/drift-record.ts +16 -0
  241. package/src/floor-table.data.ts +54 -31
  242. package/src/forge-check/contract.ts +12 -1
  243. package/src/forge-check/forge-check.test.ts +17 -0
  244. package/src/forge-check/index.ts +2 -0
  245. package/src/gate-resume-run.ts +27 -3
  246. package/src/generated-check.e2e.test.ts +21 -1
  247. package/src/generated-check.test.ts +66 -0
  248. package/src/generated-check.ts +51 -10
  249. package/src/image-pins.ts +31 -0
  250. package/src/lexicon.ts +11 -0
  251. package/src/lifecycle/git.test.ts +48 -0
  252. package/src/lifecycle/git.ts +27 -4
  253. package/src/lifecycle/publish-npm.ts +31 -1
  254. package/src/lifecycle/reach-locks.test.ts +87 -0
  255. package/src/lifecycle/reach-locks.ts +169 -0
  256. package/src/lifecycle/release-cut.ts +17 -1
  257. package/src/lifecycle/release-images.test.ts +56 -0
  258. package/src/lifecycle/release-images.ts +1 -2
  259. package/src/notify-product.ts +19 -8
  260. package/src/op/activities/source-release.ts +2 -1
  261. package/src/op/activities/source-rollback.ts +2 -1
  262. package/src/op/gate-resume.test.ts +27 -0
  263. package/src/op/index.ts +10 -0
  264. package/src/op/op-waves-evidence-jobs.ts +10 -4
  265. package/src/op/op-waves-notify-words.test.ts +18 -0
  266. package/src/op/op-waves-render-spec.test.ts +160 -0
  267. package/src/op/op-waves-render-spec.ts +171 -0
  268. package/src/op/op-waves-run.ts +2 -1
  269. package/src/op/op-waves.ts +5 -2
  270. package/src/op/schedule-overdue.test.ts +43 -0
  271. package/src/op/schedule-overdue.ts +57 -3
  272. package/src/op/wave-stop.test.ts +72 -0
  273. package/src/op/wave-stop.ts +137 -0
  274. package/src/planned-files.test.ts +80 -0
  275. package/src/planned-files.ts +134 -0
  276. package/src/pr-forge-job.test.ts +53 -0
  277. package/src/pr-forge-job.ts +46 -0
  278. package/src/pr-loop-narrowed.test.ts +2 -1
  279. package/src/pr-loop-words.test.ts +2 -1
  280. package/src/pr-loop.test.ts +1 -2
  281. package/src/pr-loop.ts +4 -80
  282. package/src/pr-plan-note.ts +155 -3
  283. package/src/pr-post-replan.test.ts +144 -0
  284. package/src/pr-post-subject.test.ts +230 -0
  285. package/src/pr-post.test.ts +2 -1
  286. package/src/pr-post.ts +150 -15
  287. package/src/pr-status.ts +91 -0
  288. package/src/ref-gate-init.ts +30 -11
  289. package/src/release-floors.ts +78 -25
  290. package/src/render-module.ts +73 -0
  291. package/src/state-migration-record.test.ts +2 -3
  292. package/src/state-migration.ts +1 -2
  293. package/src/workspace/ci-green-cli.ts +3 -2
  294. package/src/workspace/ci-green-workflow.test.ts +32 -1
  295. package/src/workspace/release-train.ts +2 -1
  296. package/src/workspace/release-workflow.test.ts +36 -5
  297. package/src/workspace/release-workflow.ts +10 -7
  298. package/src/workspace/trust/check-evidence-report.ts +15 -8
  299. package/src/workspace/trust/check-evidence.test.ts +5 -0
  300. package/src/workspace/trust/ref-gate-cli.ts +30 -8
  301. package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
  302. package/src/workspace/trust/ref-gate.test.ts +10 -0
  303. package/src/workspace/workspace-run.ts +2 -1
@@ -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,17 @@ 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;
1177
1188
  }
1178
1189
 
1179
1190
  /** A run step a product adds to a generated job (#4791): its name, and its shell lines in order. */
@@ -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
+ });
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Locks on what a change reaches (#4979): `chant lock --reach`.
3
+ *
4
+ * A pull request's plan locks (`ci.locks: plan`, #4293) come from what its
5
+ * plan selected, which the plan job, running the change's code, wrote. A
6
+ * product that knows from the change's files alone which of its targets a
7
+ * change reaches, such as terragucci's roots, units and instances, gives a
8
+ * reach line instead: one shell line, written in the pipeline at the target
9
+ * branch's commit, that prints the targets the change from `$BASE_SHA` to
10
+ * `$HEAD_SHA` reaches, one a line. It reads the change as data from git
11
+ * (`git diff`, `git show <sha>:<path>`) and runs none of its code.
12
+ *
13
+ * The lock job runs it in a checkout of the target branch's commit. chant
14
+ * first fetches the pull request's head from the forge (`refs/pull/<n>/head`,
15
+ * GitLab's `refs/merge-requests/<n>/head`) and checks it is still the commit
16
+ * the job was started for: a head that moved is left to the run of the push
17
+ * that moved it. The line's variables are `BASE_SHA`, `HEAD_SHA` and
18
+ * `PR_NUMBER`; it holds the job's environment, and the line is the
19
+ * pipeline's, so none of the change's code runs with the job's token.
20
+ *
21
+ * On GitLab a merge request's pipeline is built from the merge request's own
22
+ * files, so its lock job runs in the target branch's plan notes pipeline and
23
+ * locks every open merge request from the project (`--open`), and releases
24
+ * the locks of a merge request that is no longer open.
25
+ */
26
+
27
+ import { spawnSync } from "node:child_process";
28
+ import type { ForgeKind } from "../pr-forge";
29
+
30
+ /** The variable the reach line is in: the pipeline's, set as the step's variable so no shell quoting carries it (#4979). */
31
+ export const LOCK_REACH_ENV = "CHANT_LOCK_REACH";
32
+
33
+ /** Where chant fetches the pull request's head to before the reach line runs (#4979). */
34
+ export const REACH_HEAD_REF = "refs/remotes/chant/pull-request-head";
35
+
36
+ /** A target name a reach line may print: no control characters, at most 512 characters. */
37
+ const TARGET_LINE = /^[^\u0000-\u001f\u007f]{1,512}$/;
38
+ const SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
39
+
40
+ /** The forge's ref for pull request `pr`'s head. */
41
+ export function pullRequestHeadRef(forge: ForgeKind, pr: number): string {
42
+ return forge === "gitlab" ? `refs/merge-requests/${pr}/head` : `refs/pull/${pr}/head`;
43
+ }
44
+
45
+ /** A process run, as `spawnSync` answers it. */
46
+ export type ReachRun = (argv: string[], o: { cwd?: string; env?: Record<string, string | undefined> }) => { status: number | null; stdout: string; stderr: string };
47
+
48
+ const defaultRun: ReachRun = (argv, o) => {
49
+ const r = spawnSync(argv[0]!, argv.slice(1), { encoding: "utf8", ...(o.cwd ? { cwd: o.cwd } : {}), ...(o.env ? { env: o.env as NodeJS.ProcessEnv } : {}) });
50
+ return { status: r.status, stdout: r.stdout ?? "", stderr: r.error ? r.error.message : (r.stderr ?? "") };
51
+ };
52
+
53
+ /** What {@link reachedTargets} takes. */
54
+ export interface ReachInput {
55
+ forge: ForgeKind;
56
+ pr: number;
57
+ /** The head the job was started for. */
58
+ head: string;
59
+ /** The target branch's commit the change is measured from. */
60
+ base: string;
61
+ /** The reach line. */
62
+ line: string;
63
+ cwd?: string;
64
+ /** The line's environment, to which `BASE_SHA`, `HEAD_SHA` and `PR_NUMBER` are added. Default the process's. */
65
+ env?: Record<string, string | undefined>;
66
+ run?: ReachRun;
67
+ }
68
+
69
+ /** The targets a change reaches, sorted; or that its head moved; or why the line could not say. */
70
+ export type Reached = { targets: string[] } | { moved: string } | { error: string };
71
+
72
+ /**
73
+ * The targets the change of pull request `pr` reaches (#4979): fetch its
74
+ * head, check it is `head`, and run the reach line. Blank lines are left
75
+ * out; a line holding a control character fails the read, so a target name
76
+ * never carries one into the lock file.
77
+ */
78
+ export function reachedTargets(i: ReachInput): Reached {
79
+ const run = i.run ?? defaultRun;
80
+ const name = i.forge === "gitlab" ? `merge request !${i.pr}` : `pull request ${i.pr}`;
81
+ if (!SHA.test(i.head)) return { error: `--head ${JSON.stringify(i.head)} is not a commit sha` };
82
+ if (!SHA.test(i.base)) return { error: `--base ${JSON.stringify(i.base)} is not a commit sha` };
83
+ if (!i.line.trim()) return { error: `the reach line in ${LOCK_REACH_ENV} is empty` };
84
+ const fetched = run(["git", "fetch", "-q", "--no-tags", "origin", `+${pullRequestHeadRef(i.forge, i.pr)}:${REACH_HEAD_REF}`], { ...(i.cwd ? { cwd: i.cwd } : {}) });
85
+ if (fetched.status !== 0) return { error: `could not fetch ${name}'s head (${fetched.stderr.trim() || `git exited ${fetched.status}`})` };
86
+ const now = run(["git", "rev-parse", REACH_HEAD_REF], { ...(i.cwd ? { cwd: i.cwd } : {}) }).stdout.trim();
87
+ if (now !== i.head) return { moved: `${name} moved to ${now.slice(0, 12) || "another commit"} after ${i.head.slice(0, 12)}, so the run of that push locks it` };
88
+ const env = { ...(i.env ?? process.env), BASE_SHA: i.base, HEAD_SHA: i.head, PR_NUMBER: String(i.pr) };
89
+ const out = run(["sh", "-c", i.line], { ...(i.cwd ? { cwd: i.cwd } : {}), env });
90
+ if (out.status !== 0) return { error: `the reach line exited ${out.status ?? "on a signal"}${out.stderr.trim() ? `: ${out.stderr.trim().split("\n").slice(-3).join(" ")}` : ""}` };
91
+ const targets = new Set<string>();
92
+ for (const raw of out.stdout.split("\n")) {
93
+ const t = raw.trim();
94
+ if (t === "") continue;
95
+ if (!TARGET_LINE.test(t)) return { error: `the reach line printed ${JSON.stringify(t.slice(0, 80))}, which is not a target name: one a line, no control characters, at most 512 characters` };
96
+ targets.add(t);
97
+ }
98
+ return { targets: [...targets].sort() };
99
+ }
100
+
101
+ /** One open pull request as {@link reachOpen} locks it. */
102
+ export interface ReachOpenPull {
103
+ number: number;
104
+ headSha: string;
105
+ base: string;
106
+ fork: boolean;
107
+ }
108
+
109
+ /** What one open pull request's lock came to. */
110
+ export type ReachOpenOutcome =
111
+ | { pr: number; kind: "locked"; targets: string[]; released: string[] }
112
+ | { pr: number; kind: "held"; text: string }
113
+ | { pr: number; kind: "skipped"; text: string }
114
+ | { pr: number; kind: "failed"; text: string };
115
+
116
+ /** What {@link reachOpen} takes besides the reach input of each pull request. */
117
+ export interface ReachOpenInput extends Omit<ReachInput, "pr" | "head"> {
118
+ /** The branch the pull requests merge into. */
119
+ branch: string;
120
+ open: readonly ReachOpenPull[];
121
+ /** Take the locks of one pull request; `held` names what another holds. */
122
+ take(pr: number, head: string, targets: string[]): Promise<{ ok: true; released: string[] } | { ok: false; held: string }>;
123
+ /** The pull requests that hold a lock now. */
124
+ holders(): Promise<number[]>;
125
+ /** Whether a holder outside the open list is open still (one that merges into another branch). */
126
+ isOpen(pr: number): Promise<boolean>;
127
+ /** Release every lock of a pull request that is no longer open. */
128
+ release(pr: number): Promise<string[]>;
129
+ }
130
+
131
+ /**
132
+ * `chant lock --reach --open` (#4979), GitLab's lock job in the target
133
+ * branch's plan notes pipeline: lock what each open merge request from the
134
+ * project that merges into `branch` reaches, then release the locks of every
135
+ * holder that is not open any more. A fork's merge request takes no lock.
136
+ */
137
+ export async function reachOpen(i: ReachOpenInput): Promise<{ outcomes: ReachOpenOutcome[]; released: Array<{ pr: number; targets: string[] }> }> {
138
+ const outcomes: ReachOpenOutcome[] = [];
139
+ const open = new Set<number>();
140
+ for (const p of i.open) {
141
+ open.add(p.number);
142
+ if (p.fork) {
143
+ outcomes.push({ pr: p.number, kind: "skipped", text: `!${p.number} comes from a fork, so it takes no lock` });
144
+ continue;
145
+ }
146
+ if (p.base !== i.branch) {
147
+ outcomes.push({ pr: p.number, kind: "skipped", text: `!${p.number} merges into ${p.base}, not ${i.branch}` });
148
+ continue;
149
+ }
150
+ const r = reachedTargets({ ...i, pr: p.number, head: p.headSha });
151
+ if ("error" in r) {
152
+ outcomes.push({ pr: p.number, kind: "failed", text: r.error });
153
+ continue;
154
+ }
155
+ if ("moved" in r) {
156
+ outcomes.push({ pr: p.number, kind: "skipped", text: r.moved });
157
+ continue;
158
+ }
159
+ const took = await i.take(p.number, p.headSha, r.targets);
160
+ outcomes.push(took.ok ? { pr: p.number, kind: "locked", targets: r.targets, released: took.released } : { pr: p.number, kind: "held", text: took.held });
161
+ }
162
+ const released: Array<{ pr: number; targets: string[] }> = [];
163
+ for (const pr of await i.holders()) {
164
+ if (open.has(pr) || (await i.isOpen(pr))) continue;
165
+ const targets = await i.release(pr);
166
+ if (targets.length > 0) released.push({ pr, targets });
167
+ }
168
+ return { outcomes, released };
169
+ }
@@ -120,7 +120,10 @@ export type ReleaseCutCode =
120
120
  | "release-version-invalid"
121
121
  | "release-unsigned"
122
122
  | "release-signer-refused"
123
- | "declaration-invalid";
123
+ | "declaration-invalid"
124
+ /** #4941: the npm target's image check, run by the cut (./publish-npm.ts `checkPackageImages`). */
125
+ | "publish-npm-carries-image"
126
+ | "publish-npm-pack-failed";
124
127
 
125
128
  export class ReleaseCutError extends Error {
126
129
  constructor(
@@ -722,6 +725,19 @@ export async function cutRelease(req: CutRequest): Promise<CutResult> {
722
725
  }
723
726
  const { targets, templates } = targetsOf(compiled);
724
727
  const release = makeRelease({ member: p.member, commit, artifactDigests: artifacts, targets });
728
+ // #4941: an npm package that would carry an image archive stops the cut here, before anything is recorded or
729
+ // tagged, rather than the publish job once the label is spent. The check is the npm target's own plan check.
730
+ if (release.artifactDigests.some((a) => a.kind === "image" && a.path !== "")) {
731
+ const { loadChantConfig } = await import("../config");
732
+ const { checkDeclaredPackageImages } = await import("./publish-npm");
733
+ const { PublishTargetError } = await import("./release-publish");
734
+ try {
735
+ checkDeclaredPackageImages((await loadChantConfig(cwd)).config.release?.publish ?? [], release, cwd);
736
+ } catch (err) {
737
+ if (err instanceof PublishTargetError) throw new ReleaseCutError(err.code as ReleaseCutCode, `no release was cut: ${err.message}`, err.fix);
738
+ throw err;
739
+ }
740
+ }
725
741
  const timestamp = (req.now ?? (() => new Date()))().toISOString();
726
742
  const signed = { releaseDigest: release.releaseDigest, label: req.label, actor: req.actor, timestamp };
727
743
  let signature: string | null = null;
@@ -283,4 +283,60 @@ describe("an npm package that would carry an image archive (#4934)", () => {
283
283
  const { dir, release } = fixture("npm-leaves-image-out", ["dist", "!dist/images/app.tar", "sbom.spdx.json"]);
284
284
  expect((await planOf(dir, release)).map((i) => i.name)).toEqual(["@acme/app@2.0.0"]);
285
285
  });
286
+
287
+ /** #4941: a member whose release.publish has an npm target for the package at its root, cut with an image built into dist/images. */
288
+ const cutCarrying = async (name: string, files: string[]) => {
289
+ const r = new TestRepo(name);
290
+ repos.push(r);
291
+ r.write("chant.config.ts", `export default { environments: ["dev"], release: { publish: [{ type: "npm", packages: ["."] }] } };\n`);
292
+ r.write("package.json", JSON.stringify({ name: "@acme/app", version: "2.0.0", files }, null, 2));
293
+ r.write(".gitignore", "dist/\n");
294
+ const head = r.commit("init");
295
+ r.git(["tag", `ci/green/${head}`]);
296
+ const compiler: TargetCompiler = {
297
+ async compile(env): Promise<CompiledTarget> {
298
+ writeFileSync(join(r.dir, "dist", "index.js"), "export {};\n");
299
+ return { env, params: [], components: [], buildSteps: {}, buildInputs: {}, componentFiles: {}, templates: [{ component: null, path: "dist/out.json", content: "{}\n" }] };
300
+ },
301
+ async buildArtifacts(): Promise<ReleaseArtifact[]> {
302
+ return [];
303
+ },
304
+ };
305
+ const cut = cutRelease({
306
+ cwd: r.dir,
307
+ compiler,
308
+ label: "v2",
309
+ actor: "alice",
310
+ env: {},
311
+ buildImages: () =>
312
+ buildReleaseImages({
313
+ images: [{ name: "app", build: "build", archive: "dist/images/app.tar" }],
314
+ cwd: r.dir,
315
+ sourceDateEpoch: 1762473600,
316
+ label: "v2",
317
+ archiveDigest: ociArchiveDigest,
318
+ run: (_c, o) => {
319
+ writeOciLayout(join(o.cwd, "dist/images/app.tar"), "app layer");
320
+ return 0;
321
+ },
322
+ }),
323
+ });
324
+ return { r, cut };
325
+ };
326
+
327
+ test("#4941: a cut whose npm package would carry the image archive stops before it records anything, so the label is not spent", async () => {
328
+ const { r, cut } = await cutCarrying("cut-carries-image", ["dist"]);
329
+ const err = await cut.catch((e: unknown) => e);
330
+ expect(err).toBeInstanceOf(ReleaseCutError);
331
+ expect((err as ReleaseCutError).code).toBe("publish-npm-carries-image");
332
+ expect((err as ReleaseCutError).message).toMatch(/^no release was cut: @acme\/app \(\.\) would carry dist\/images\/app\.tar\//);
333
+ expect((err as ReleaseCutError).fix).toContain('Add "!dist/images/app.tar" to "files" in package.json');
334
+ expect(() => r.git(["rev-parse", "--verify", "--quiet", "refs/heads/chant/lifecycle"])).toThrow();
335
+ });
336
+
337
+ test("#4941: the same cut with the archive left out of the package records the release", async () => {
338
+ const { cut } = await cutCarrying("cut-leaves-image-out", ["dist", "!dist/images/app.tar"]);
339
+ const { release } = await cut;
340
+ expect(release.artifactDigests.map((a) => a.component)).toEqual(["app"]);
341
+ });
286
342
  });
@@ -38,7 +38,6 @@
38
38
  import { spawnSync } from "node:child_process";
39
39
  import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
40
40
  import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
41
- import { NEXT_RELEASE } from "../release-floors";
42
41
  import type { PublishDeclaration } from "./publish-declaration";
43
42
  import type { Release, ReleaseArtifact } from "./release-store";
44
43
 
@@ -56,7 +55,7 @@ export const RELEASE_IMAGES_FLOOR = "0.124.71";
56
55
  export const RELEASE_IMAGE_DOCKERFILE_FLOOR = "0.124.78";
57
56
 
58
57
  /** The first chant whose Dockerfile entry in `release.images` takes `args`, build arguments beside the two chant passes (#4908). */
59
- export const RELEASE_IMAGE_ARGS_FLOOR = NEXT_RELEASE;
58
+ export const RELEASE_IMAGE_ARGS_FLOOR = "0.124.88";
60
59
 
61
60
  /** One image a release builds in its cut with a command of the product's. */
62
61
  export interface ReleaseImageBuild {
@@ -14,6 +14,7 @@
14
14
 
15
15
  import { CHANT_WORDS, isChantWords, type CiProductNotifyWords, type CiProductWords } from "./ci-product-words";
16
16
  import type { NotifyFields, SendNotifyOptions } from "./notify";
17
+ import { driftIssueRecords, driftRunFingerprint, type DriftRunStack } from "./drift-issue";
17
18
 
18
19
  /**
19
20
  * The first chant whose Slack and Teams messages take a product's words, a
@@ -48,12 +49,19 @@ export function productSendOptions(words: CiProductWords, options: SendNotifyOpt
48
49
 
49
50
  /** What a drift notice concerns. */
50
51
  export interface DriftNotifyInput {
51
- /** The members whose refresh found drift. */
52
- changed: string[];
52
+ /** The members whose refresh found drift. Left out, the {@link stacks} with drift records, in their order. */
53
+ changed?: string[];
53
54
  missing?: string[];
54
55
  /** The members whose refresh failed, so drift there is unknown. */
55
56
  failed?: string[];
57
+ /** The run's fingerprint. Left out, `driftRunFingerprint` of the {@link stacks}. */
56
58
  fingerprint?: string;
59
+ /**
60
+ * Each member's drift records, as the run read them (#4944). The notice
61
+ * then names the members with drift and carries the run's fingerprint, so
62
+ * a product passes what it read instead of computing either.
63
+ */
64
+ stacks?: readonly DriftRunStack[];
57
65
  project?: string;
58
66
  environment?: string;
59
67
  reportUrl?: string;
@@ -62,24 +70,27 @@ export interface DriftNotifyInput {
62
70
  /**
63
71
  * A `drift` event under `words`: `2 stacks drifted: shop-dev, shop-prod` for
64
72
  * plywood, `1 member drifted: net` for chant, with the failed refreshes
65
- * named after them.
73
+ * named after them. Given `stacks`, the drifted members and the
74
+ * fingerprint come from their records (#4944).
66
75
  */
67
76
  export function driftNotifyFields(words: CiProductWords, input: DriftNotifyInput): NotifyFields {
68
77
  const [one, many] = words.noun;
69
- const n = input.changed.length;
78
+ const changed = input.changed ?? (input.stacks ?? []).filter((s) => driftIssueRecords(s.records).length > 0).map((s) => s.stack);
79
+ const fingerprint = input.fingerprint ?? (input.stacks ? driftRunFingerprint(input.stacks) : undefined);
80
+ const n = changed.length;
70
81
  const failed = input.failed ?? [];
71
- const what = n > 0 ? `${n} ${n === 1 ? one : many} drifted: ${input.changed.join(", ")}` : `no ${many} drifted`;
82
+ const what = n > 0 ? `${n} ${n === 1 ? one : many} drifted: ${changed.join(", ")}` : `no ${many} drifted`;
72
83
  const summary = failed.length > 0 ? `${what}; ${failed.length} ${failed.length === 1 ? one : many} could not be refreshed: ${failed.join(", ")}` : what;
73
84
  return {
74
85
  source: productNotifySource(words),
75
86
  event: "drift",
76
87
  summary,
77
- targets: input.changed,
88
+ targets: changed,
78
89
  drift: {
79
- changed: input.changed,
90
+ changed,
80
91
  ...(input.missing?.length ? { missing: input.missing } : {}),
81
92
  ...(failed.length > 0 ? { failed } : {}),
82
- ...(input.fingerprint ? { fingerprint: input.fingerprint } : {}),
93
+ ...(fingerprint ? { fingerprint } : {}),
83
94
  },
84
95
  ...(input.project !== undefined ? { project: input.project } : {}),
85
96
  ...(input.environment !== undefined ? { environment: input.environment } : {}),