@intentius/chant 0.124.30 → 0.124.32

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 (346) hide show
  1. package/bin/chant +7 -2
  2. package/dist/cli/commands/check-lexicon-plugin.d.ts +7 -4
  3. package/dist/cli/commands/check-lexicon-plugin.d.ts.map +1 -1
  4. package/dist/cli/commands/check-lexicon-plugin.js +10 -7
  5. package/dist/cli/commands/check-lexicon.d.ts.map +1 -1
  6. package/dist/cli/commands/check-lexicon.js +18 -12
  7. package/dist/cli/commands/import.d.ts +10 -0
  8. package/dist/cli/commands/import.d.ts.map +1 -1
  9. package/dist/cli/commands/import.js +37 -0
  10. package/dist/cli/commands/init-lexicon/templates/project.d.ts.map +1 -1
  11. package/dist/cli/commands/init-lexicon/templates/project.js +4 -3
  12. package/dist/cli/commands/onboard.d.ts.map +1 -1
  13. package/dist/cli/commands/onboard.js +8 -4
  14. package/dist/cli/commands/update.d.ts.map +1 -1
  15. package/dist/cli/commands/update.js +2 -1
  16. package/dist/cli/dependencies.d.ts +18 -0
  17. package/dist/cli/dependencies.d.ts.map +1 -0
  18. package/dist/cli/dependencies.js +120 -0
  19. package/dist/cli/handlers/build.d.ts.map +1 -1
  20. package/dist/cli/handlers/build.js +23 -4
  21. package/dist/cli/handlers/fan-out.d.ts.map +1 -1
  22. package/dist/cli/handlers/fan-out.js +12 -4
  23. package/dist/cli/handlers/graph.d.ts.map +1 -1
  24. package/dist/cli/handlers/graph.js +16 -6
  25. package/dist/cli/handlers/lint.d.ts.map +1 -1
  26. package/dist/cli/handlers/lint.js +6 -0
  27. package/dist/cli/handlers/operator.d.ts +2 -2
  28. package/dist/cli/handlers/operator.js +3 -3
  29. package/dist/cli/handlers/pr.d.ts +14 -0
  30. package/dist/cli/handlers/pr.d.ts.map +1 -1
  31. package/dist/cli/handlers/pr.js +488 -32
  32. package/dist/cli/handlers/promote.d.ts.map +1 -1
  33. package/dist/cli/handlers/promote.js +3 -1
  34. package/dist/cli/handlers/run.d.ts +13 -1
  35. package/dist/cli/handlers/run.d.ts.map +1 -1
  36. package/dist/cli/handlers/run.js +38 -15
  37. package/dist/cli/main.d.ts.map +1 -1
  38. package/dist/cli/main.js +74 -12
  39. package/dist/cli/parse-args.d.ts.map +1 -1
  40. package/dist/cli/parse-args.js +65 -0
  41. package/dist/cli/registry.d.ts +29 -2
  42. package/dist/cli/registry.d.ts.map +1 -1
  43. package/dist/cli/registry.js +6 -2
  44. package/dist/codegen/generate-post-synth-barrel.js +2 -2
  45. package/dist/codegen/lexicon-regen.d.ts +4 -0
  46. package/dist/codegen/lexicon-regen.d.ts.map +1 -1
  47. package/dist/codegen/lexicon-regen.js +1 -1
  48. package/dist/codegen/pinned-upgrade.js +2 -2
  49. package/dist/components/capability.d.ts +44 -3
  50. package/dist/components/capability.d.ts.map +1 -1
  51. package/dist/components/capability.js +21 -0
  52. package/dist/components/changed-files.d.ts +7 -1
  53. package/dist/components/changed-files.d.ts.map +1 -1
  54. package/dist/components/changed-files.js +9 -1
  55. package/dist/components/driver.d.ts +38 -0
  56. package/dist/components/driver.d.ts.map +1 -1
  57. package/dist/components/driver.js +47 -6
  58. package/dist/components/fan-out-record.d.ts +6 -1
  59. package/dist/components/fan-out-record.d.ts.map +1 -1
  60. package/dist/components/fan-out-record.js +24 -0
  61. package/dist/components/fan-out-run.d.ts +20 -0
  62. package/dist/components/fan-out-run.d.ts.map +1 -1
  63. package/dist/components/fan-out-run.js +21 -1
  64. package/dist/components/pr-pipeline.d.ts +65 -2
  65. package/dist/components/pr-pipeline.d.ts.map +1 -1
  66. package/dist/components/pr-pipeline.js +107 -15
  67. package/dist/components/pr-run.d.ts +127 -29
  68. package/dist/components/pr-run.d.ts.map +1 -1
  69. package/dist/components/pr-run.js +290 -70
  70. package/dist/components/wave-plan.d.ts +5 -2
  71. package/dist/components/wave-plan.d.ts.map +1 -1
  72. package/dist/components/wave-plan.js +12 -1
  73. package/dist/discovery/fold-import.d.ts.map +1 -1
  74. package/dist/discovery/fold-import.js +16 -6
  75. package/dist/discovery/sandbox/bundle.d.ts.map +1 -1
  76. package/dist/discovery/sandbox/bundle.js +6 -0
  77. package/dist/discovery/specifier-resolve.d.ts.map +1 -1
  78. package/dist/discovery/specifier-resolve.js +8 -2
  79. package/dist/fold/fold.d.ts.map +1 -1
  80. package/dist/fold/fold.js +68 -1
  81. package/dist/fold/subset.d.ts +37 -0
  82. package/dist/fold/subset.d.ts.map +1 -1
  83. package/dist/fold/subset.js +88 -0
  84. package/dist/lexicon-module.d.ts +10 -0
  85. package/dist/lexicon-module.d.ts.map +1 -1
  86. package/dist/lexicon-module.js +53 -8
  87. package/dist/lexicon-plugin-helpers.d.ts.map +1 -1
  88. package/dist/lexicon-plugin-helpers.js +6 -4
  89. package/dist/lexicon.d.ts +2 -0
  90. package/dist/lexicon.d.ts.map +1 -1
  91. package/dist/lifecycle/affected.d.ts.map +1 -1
  92. package/dist/lifecycle/affected.js +7 -1
  93. package/dist/lifecycle/release-ledger.d.ts +21 -0
  94. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  95. package/dist/lifecycle/release-ledger.js +24 -0
  96. package/dist/lifecycle/work-dir.d.ts +45 -0
  97. package/dist/lifecycle/work-dir.d.ts.map +1 -0
  98. package/dist/lifecycle/work-dir.js +78 -0
  99. package/dist/lint/discover.d.ts +17 -9
  100. package/dist/lint/discover.d.ts.map +1 -1
  101. package/dist/lint/discover.js +62 -54
  102. package/dist/module-source.d.ts +57 -0
  103. package/dist/module-source.d.ts.map +1 -0
  104. package/dist/module-source.js +104 -0
  105. package/dist/op/activities/factory.js +1 -1
  106. package/dist/op/discover.d.ts.map +1 -1
  107. package/dist/op/discover.js +13 -3
  108. package/dist/op/gate.d.ts.map +1 -1
  109. package/dist/op/gate.js +3 -0
  110. package/dist/op/local-executor.d.ts +12 -0
  111. package/dist/op/local-executor.d.ts.map +1 -1
  112. package/dist/op/local-executor.js +22 -3
  113. package/dist/op/op-waves-run.d.ts.map +1 -1
  114. package/dist/op/op-waves-run.js +20 -5
  115. package/dist/op/operator.d.ts +2 -2
  116. package/dist/op/operator.js +2 -2
  117. package/dist/op/redact.d.ts +34 -0
  118. package/dist/op/redact.d.ts.map +1 -0
  119. package/dist/op/redact.js +94 -0
  120. package/dist/op/step-console.d.ts +2 -0
  121. package/dist/op/step-console.d.ts.map +1 -1
  122. package/dist/op/step-console.js +5 -2
  123. package/dist/op/steward.d.ts +6 -4
  124. package/dist/op/steward.d.ts.map +1 -1
  125. package/dist/op/steward.js +5 -3
  126. package/dist/op/work-lease-run.d.ts +20 -7
  127. package/dist/op/work-lease-run.d.ts.map +1 -1
  128. package/dist/op/work-lease-run.js +56 -12
  129. package/dist/pr-forge.d.ts +27 -0
  130. package/dist/pr-forge.d.ts.map +1 -1
  131. package/dist/pr-forge.js +51 -6
  132. package/dist/pr-loop.d.ts +141 -4
  133. package/dist/pr-loop.d.ts.map +1 -1
  134. package/dist/pr-loop.js +122 -6
  135. package/dist/pr-report-url.d.ts +10 -2
  136. package/dist/pr-report-url.d.ts.map +1 -1
  137. package/dist/pr-report-url.js +52 -6
  138. package/dist/ts-loader.d.ts +38 -4
  139. package/dist/ts-loader.d.ts.map +1 -1
  140. package/dist/ts-loader.js +190 -16
  141. package/dist/wave-runtime.mjs +208 -208
  142. package/dist/workspace/chant-migrations/fountain-retired-kinds.d.ts +34 -0
  143. package/dist/workspace/chant-migrations/fountain-retired-kinds.d.ts.map +1 -0
  144. package/dist/workspace/chant-migrations/fountain-retired-kinds.js +176 -0
  145. package/dist/workspace/chant-migrations.d.ts.map +1 -1
  146. package/dist/workspace/chant-migrations.js +2 -0
  147. package/dist/workspace/checks/boxes.d.ts +6 -6
  148. package/dist/workspace/checks/boxes.js +9 -9
  149. package/dist/workspace/ci-green-forge.d.ts +6 -4
  150. package/dist/workspace/ci-green-forge.d.ts.map +1 -1
  151. package/dist/workspace/ci-green.d.ts +28 -12
  152. package/dist/workspace/ci-green.d.ts.map +1 -1
  153. package/dist/workspace/ci-green.js +49 -21
  154. package/dist/workspace/ci-list.schema.json +12 -6
  155. package/dist/workspace/ci-report-url.d.ts +18 -0
  156. package/dist/workspace/ci-report-url.d.ts.map +1 -0
  157. package/dist/workspace/ci-report-url.js +33 -0
  158. package/dist/workspace/ci-run-index.d.ts +108 -0
  159. package/dist/workspace/ci-run-index.d.ts.map +1 -0
  160. package/dist/workspace/ci-run-index.js +164 -0
  161. package/dist/workspace/ci-run-index.schema.json +52 -0
  162. package/dist/workspace/ci-run.d.ts +159 -9
  163. package/dist/workspace/ci-run.d.ts.map +1 -1
  164. package/dist/workspace/ci-run.js +419 -50
  165. package/dist/workspace/ci-runner-key.d.ts +133 -0
  166. package/dist/workspace/ci-runner-key.d.ts.map +1 -0
  167. package/dist/workspace/ci-runner-key.js +237 -0
  168. package/dist/workspace/ci-secrets.d.ts +65 -0
  169. package/dist/workspace/ci-secrets.d.ts.map +1 -0
  170. package/dist/workspace/ci-secrets.js +211 -0
  171. package/dist/workspace/ci-serve.d.ts +67 -4
  172. package/dist/workspace/ci-serve.d.ts.map +1 -1
  173. package/dist/workspace/ci-serve.js +240 -35
  174. package/dist/workspace/declaration.d.ts +8 -0
  175. package/dist/workspace/declaration.d.ts.map +1 -1
  176. package/dist/workspace/declaration.js +11 -2
  177. package/dist/workspace/declaration.schema.json +7 -2
  178. package/dist/workspace/export.d.ts +1 -1
  179. package/dist/workspace/export.d.ts.map +1 -1
  180. package/dist/workspace/export.js +7 -3
  181. package/dist/workspace/ls.d.ts +6 -1
  182. package/dist/workspace/ls.d.ts.map +1 -1
  183. package/dist/workspace/ls.js +1 -0
  184. package/dist/workspace/ls.schema.json +7 -1
  185. package/dist/workspace/pin-integrity.d.ts.map +1 -1
  186. package/dist/workspace/pin-integrity.js +3 -2
  187. package/dist/workspace/pr-report.schema.json +74 -7
  188. package/dist/workspace/reason-codes.d.ts +7 -3
  189. package/dist/workspace/reason-codes.d.ts.map +1 -1
  190. package/dist/workspace/reason-codes.js +9 -4
  191. package/dist/workspace/run-event.schema.json +3 -1
  192. package/dist/workspace/status.schema.json +3 -1
  193. package/dist/workspace/trust/trust-write.d.ts +109 -0
  194. package/dist/workspace/trust/trust-write.d.ts.map +1 -0
  195. package/dist/workspace/trust/trust-write.js +320 -0
  196. package/dist/workspace/trust-write.schema.json +265 -0
  197. package/dist/workspace/write-scope.d.ts +9 -0
  198. package/dist/workspace/write-scope.d.ts.map +1 -1
  199. package/dist/workspace/write-scope.js +11 -1
  200. package/package.json +1 -1
  201. package/src/__fixtures__/pr-loop/pr-apply-wave-waiting.note.golden.md +48 -0
  202. package/src/cli/commands/__fixtures__/init-lexicon-output/package.json +3 -3
  203. package/src/cli/commands/audit.test.ts +2 -2
  204. package/src/cli/commands/check-lexicon-plugin.test.ts +9 -0
  205. package/src/cli/commands/check-lexicon-plugin.ts +11 -8
  206. package/src/cli/commands/check-lexicon.test.ts +1 -1
  207. package/src/cli/commands/check-lexicon.ts +16 -11
  208. package/src/cli/commands/import.ts +40 -0
  209. package/src/cli/commands/init-lexicon/templates/project.ts +4 -3
  210. package/src/cli/commands/init-lexicon.test.ts +8 -5
  211. package/src/cli/commands/onboard.test.ts +45 -0
  212. package/src/cli/commands/onboard.ts +8 -4
  213. package/src/cli/commands/update.test.ts +6 -0
  214. package/src/cli/commands/update.ts +4 -1
  215. package/src/cli/compiled-cli.e2e.test.ts +76 -11
  216. package/src/cli/dependencies.e2e.test.ts +101 -0
  217. package/src/cli/dependencies.test.ts +93 -0
  218. package/src/cli/dependencies.ts +122 -0
  219. package/src/cli/handlers/build.test.ts +69 -0
  220. package/src/cli/handlers/build.ts +20 -4
  221. package/src/cli/handlers/fan-out.test.ts +73 -0
  222. package/src/cli/handlers/fan-out.ts +11 -4
  223. package/src/cli/handlers/graph.test.ts +76 -0
  224. package/src/cli/handlers/graph.ts +19 -12
  225. package/src/cli/handlers/lint.test.ts +42 -0
  226. package/src/cli/handlers/lint.ts +6 -0
  227. package/src/cli/handlers/operator.ts +3 -3
  228. package/src/cli/handlers/pr-waves.test.ts +449 -0
  229. package/src/cli/handlers/pr.test.ts +134 -0
  230. package/src/cli/handlers/pr.ts +523 -31
  231. package/src/cli/handlers/promote.test.ts +26 -1
  232. package/src/cli/handlers/promote.ts +3 -2
  233. package/src/cli/handlers/run-components-exit.test.ts +99 -0
  234. package/src/cli/handlers/run-signer.test.ts +79 -0
  235. package/src/cli/handlers/run.ts +34 -16
  236. package/src/cli/main.test.ts +19 -0
  237. package/src/cli/main.ts +73 -12
  238. package/src/cli/parse-args.ts +48 -0
  239. package/src/cli/registry.ts +35 -4
  240. package/src/codegen/generate-post-synth-barrel.ts +2 -2
  241. package/src/codegen/lexicon-regen.ts +1 -1
  242. package/src/codegen/pinned-upgrade.ts +2 -2
  243. package/src/codegen/post-synth-barrel-guards.test.ts +6 -11
  244. package/src/components/capability.ts +51 -3
  245. package/src/components/changed-files.test.ts +16 -1
  246. package/src/components/changed-files.ts +9 -1
  247. package/src/components/driver.test.ts +36 -1
  248. package/src/components/driver.ts +76 -4
  249. package/src/components/fan-out-record.ts +29 -1
  250. package/src/components/fan-out-run.test.ts +35 -0
  251. package/src/components/fan-out-run.ts +40 -1
  252. package/src/components/pr-pipeline.test.ts +100 -0
  253. package/src/components/pr-pipeline.ts +132 -17
  254. package/src/components/pr-run.test.ts +323 -18
  255. package/src/components/pr-run.ts +354 -75
  256. package/src/components/wave-plan.ts +16 -4
  257. package/src/discovery/fold-host-method.test.ts +87 -0
  258. package/src/discovery/fold-import.ts +15 -5
  259. package/src/discovery/fold-package-composite.test.ts +27 -0
  260. package/src/discovery/fold-specifiers.test.ts +8 -0
  261. package/src/discovery/sandbox/bundle.ts +6 -0
  262. package/src/discovery/specifier-resolve.ts +8 -2
  263. package/src/fold/fold.test.ts +72 -0
  264. package/src/fold/fold.ts +71 -0
  265. package/src/fold/subset.test.ts +31 -0
  266. package/src/fold/subset.ts +99 -0
  267. package/src/lexicon-dist.e2e.test.ts +254 -0
  268. package/src/lexicon-module.test.ts +47 -0
  269. package/src/lexicon-module.ts +49 -7
  270. package/src/lexicon-plugin-helpers.ts +6 -4
  271. package/src/lexicon.ts +2 -0
  272. package/src/lifecycle/affected.test.ts +7 -0
  273. package/src/lifecycle/affected.ts +6 -1
  274. package/src/lifecycle/release-ledger.ts +34 -0
  275. package/src/lifecycle/work-dir.test.ts +77 -0
  276. package/src/lifecycle/work-dir.ts +82 -0
  277. package/src/lint/discover.test.ts +46 -2
  278. package/src/lint/discover.ts +55 -49
  279. package/src/module-source.test.ts +85 -0
  280. package/src/module-source.ts +112 -0
  281. package/src/op/activities/factory.ts +1 -1
  282. package/src/op/discover-root.test.ts +31 -2
  283. package/src/op/discover.ts +14 -4
  284. package/src/op/gate.test.ts +30 -0
  285. package/src/op/gate.ts +3 -0
  286. package/src/op/local-executor.ts +31 -3
  287. package/src/op/op-waves-run.ts +20 -5
  288. package/src/op/op-waves.test.ts +49 -0
  289. package/src/op/operator.ts +2 -2
  290. package/src/op/redact.ts +93 -0
  291. package/src/op/step-console.ts +7 -2
  292. package/src/op/steward.ts +6 -4
  293. package/src/op/work-lease-run.test.ts +88 -2
  294. package/src/op/work-lease-run.ts +52 -12
  295. package/src/pr-forge-bundle.test.ts +2 -2
  296. package/src/pr-forge.test.ts +71 -0
  297. package/src/pr-forge.ts +70 -6
  298. package/src/pr-loop-bundle.test.ts +2 -1
  299. package/src/pr-loop.test.ts +117 -1
  300. package/src/pr-loop.ts +252 -10
  301. package/src/pr-report-url.ts +58 -6
  302. package/src/terraform/__fixtures__/advise.test.ts +21 -2
  303. package/src/ts-loader.test.ts +89 -1
  304. package/src/ts-loader.ts +180 -13
  305. package/src/workspace/changes.test.ts +1 -1
  306. package/src/workspace/chant-migrations/fountain-retired-kinds.test.ts +33 -0
  307. package/src/workspace/chant-migrations/fountain-retired-kinds.ts +190 -0
  308. package/src/workspace/chant-migrations.e2e.test.ts +5 -0
  309. package/src/workspace/chant-migrations.ts +2 -0
  310. package/src/workspace/checks/boxes.ts +9 -9
  311. package/src/workspace/ci-green-forge.ts +6 -4
  312. package/src/workspace/ci-green-runs.test.ts +53 -11
  313. package/src/workspace/ci-green.test.ts +1 -1
  314. package/src/workspace/ci-green.ts +50 -22
  315. package/src/workspace/ci-list.schema.json +12 -6
  316. package/src/workspace/ci-report-url.test.ts +220 -0
  317. package/src/workspace/ci-report-url.ts +33 -0
  318. package/src/workspace/ci-run-index.schema.json +52 -0
  319. package/src/workspace/ci-run-index.test.ts +392 -0
  320. package/src/workspace/ci-run-index.ts +206 -0
  321. package/src/workspace/ci-run.test.ts +520 -42
  322. package/src/workspace/ci-run.ts +483 -51
  323. package/src/workspace/ci-runner-key.test.ts +204 -0
  324. package/src/workspace/ci-runner-key.ts +275 -0
  325. package/src/workspace/ci-secrets.test.ts +106 -0
  326. package/src/workspace/ci-secrets.ts +213 -0
  327. package/src/workspace/ci-serve.test.ts +282 -39
  328. package/src/workspace/ci-serve.ts +231 -34
  329. package/src/workspace/declaration.schema.json +7 -2
  330. package/src/workspace/declaration.test.ts +23 -0
  331. package/src/workspace/declaration.ts +19 -3
  332. package/src/workspace/export.ts +6 -3
  333. package/src/workspace/ls.schema.json +7 -1
  334. package/src/workspace/ls.ts +7 -2
  335. package/src/workspace/pin-integrity.test.ts +5 -0
  336. package/src/workspace/pin-integrity.ts +3 -2
  337. package/src/workspace/pr-report.schema.json +74 -7
  338. package/src/workspace/reason-codes.test.ts +2 -0
  339. package/src/workspace/reason-codes.ts +9 -4
  340. package/src/workspace/run-event.schema.json +3 -1
  341. package/src/workspace/status.schema.json +3 -1
  342. package/src/workspace/trust/trust-write.test.ts +179 -0
  343. package/src/workspace/trust/trust-write.ts +377 -0
  344. package/src/workspace/trust-write.schema.json +265 -0
  345. package/src/workspace/write-scope.test.ts +29 -1
  346. package/src/workspace/write-scope.ts +12 -1
package/src/pr-loop.ts CHANGED
@@ -28,6 +28,16 @@
28
28
  * and decides the gate against the new digest. The same plan applies; a moved
29
29
  * plan stops with both digests named and nothing applied.
30
30
  *
31
+ * ## A gate per wave on merge
32
+ *
33
+ * With `--wave-gate <gate>` (#4003) the apply runs a wave at a time, and
34
+ * plans each wave after the one before it applied. Wave 1 applies under the
35
+ * pull request's approval. A later wave whose new plan the approved change
36
+ * set covers (`planCoveredBy`) applies under that approval too; one whose
37
+ * plan moved waits at `<gate>-wave-<k>`, under the same op, for an approval
38
+ * of its new plan. The report's `waves` says which wave applied under which
39
+ * approval.
40
+ *
31
41
  * ## Inside a workspace member
32
42
  *
33
43
  * Each workspace member that generates the pipeline (#3465) runs its own
@@ -49,6 +59,15 @@ export const PR_REPORT_CONTRACT = 1;
49
59
  /** The first chant whose report can carry `deployedOutputs` (#4104). */
50
60
  export const PR_REPORT_DEPLOYED_OUTPUTS_FLOOR = "0.124.30";
51
61
 
62
+ /** The first chant whose report can carry `waveGate` and `waves` (#4003). */
63
+ export const PR_REPORT_WAVES_FLOOR = "0.124.32";
64
+ /**
65
+ * The first chant whose report can carry `plannedOutputs`, `rounds`, a
66
+ * member's `unknownInputs`, `buildInputs`, `round` and `held`, and the `waiting` statuses
67
+ * (#3999).
68
+ */
69
+ export const PR_REPORT_PLANNED_OUTPUTS_FLOOR = "0.124.32";
70
+
52
71
  /** The gate a pull request's apply waits on, unless the pipeline names another. */
53
72
  export const PR_APPLY_GATE = "pr-apply";
54
73
 
@@ -60,6 +79,16 @@ export function prOp(pr: number, member?: string): string {
60
79
  return member ? `pr-${pr}-${member}` : `pr-${pr}`;
61
80
  }
62
81
 
82
+ /**
83
+ * The gate a round of an apply waits on (#3999): the pull request's own
84
+ * gate for the first, and `<gate>-round-<n>` for each one planned after an
85
+ * upstream applied. A workspace's `identity.gates` entry for `gate` covers
86
+ * every round.
87
+ */
88
+ export function prRoundGate(gate: string, round: number): string {
89
+ return round <= 1 ? gate : `${gate}-round-${round}`;
90
+ }
91
+
63
92
  /** Whether `op` is a pull request's gate op, with or without a member. Member names follow the declaration's name pattern. */
64
93
  export const PR_GATE_OP = /^pr-\d+(?:-[a-z0-9][a-z0-9-]*)?$/;
65
94
 
@@ -95,7 +124,13 @@ export type PrMemberStatus =
95
124
  /** The apply failed. */
96
125
  | "failed"
97
126
  /** Not applied because a member it depends on failed. */
98
- | "blocked";
127
+ | "blocked"
128
+ /**
129
+ * Apply stage (#3999): held back because its plan read an upstream output
130
+ * that applied as another value, or was known only after apply. It waits
131
+ * on an approval of the plan the apply made for it afterwards (`rounds`).
132
+ */
133
+ | "waiting";
99
134
 
100
135
  export interface PrMember {
101
136
  /** The member's name in the change set: a root, for a terraform-family step. */
@@ -110,9 +145,48 @@ export interface PrMember {
110
145
  /**
111
146
  * Components this one depends on whose outputs changed when they applied
112
147
  * (apply stage). Its applied plan read the values from before, so the next
113
- * run plans it again.
148
+ * run plans it again. Not written since #3999, which holds such a member
149
+ * back and plans it again in the same apply (`held`, `round`).
114
150
  */
115
151
  inputsMoved?: string[];
152
+ /**
153
+ * The upstream outputs its plan read that the change's plans could not
154
+ * say (#3999), as `<component>.<output>`, sorted: known only after that
155
+ * upstream applies. The approval does not cover what this member does
156
+ * with them; the apply plans it again once they are known.
157
+ */
158
+ unknownInputs?: string[];
159
+ /**
160
+ * The published artifact identities its plan read from a build in the
161
+ * same change (#3999), as `<component>.publish.<field>`, sorted: an image
162
+ * digest, say. Known only after the build runs, but never approved again:
163
+ * the build's provenance and attestation bind the digest, so the member
164
+ * applies without a later round.
165
+ */
166
+ buildInputs?: string[];
167
+ /** Apply stage (#3999): the round whose plan it applied or waits on, when not the first. */
168
+ round?: number;
169
+ /** Apply stage (#3999): why the first round's plan did not apply. */
170
+ held?: string;
171
+ }
172
+
173
+ /** A round of plans an apply made after an upstream applied (#3999), the report's `rounds`. */
174
+ export interface PrRound {
175
+ /** 2 for the first plan made after an upstream applied, and on. */
176
+ round: number;
177
+ /** The gate it waits on: {@link prRoundGate}. */
178
+ gate: string;
179
+ /** The change-set digest of what the round planned. What its gate binds. */
180
+ digest: string;
181
+ /** The components planned again, in apply order. */
182
+ components: string[];
183
+ approval: PrApproval;
184
+ /** `waiting`: no approval stands for `digest`. `plan-failed`: a member failed to plan, so the round did not apply. */
185
+ status: "applied" | "failed" | "waiting" | "plan-failed";
186
+ /** With `waiting`: why an approval that stands does not count (`--require-review`). */
187
+ message?: string;
188
+ /** The change-set document the round planned. */
189
+ changeSet: ChangeSetDocument;
116
190
  }
117
191
 
118
192
  /** Where the approval stands for the planned digest. */
@@ -141,8 +215,19 @@ export type PrStatus =
141
215
  | "applied"
142
216
  /** Apply stage: a member failed to apply. Its dependents did not run. */
143
217
  | "failed"
218
+ /**
219
+ * Apply stage with `--wave-gate` and `--wave` (#4003): this wave applied,
220
+ * and a later wave of the change is still to run.
221
+ */
222
+ | "wave-applied"
144
223
  /** Apply stage: nothing applied, see `refusal`. */
145
- | "refused";
224
+ | "refused"
225
+ /**
226
+ * Apply stage (#3999): the approved plans applied, except members held
227
+ * back after an upstream applied. They wait on the approval of the plan
228
+ * the last of `rounds` made.
229
+ */
230
+ | "waiting";
146
231
 
147
232
  /** Why an apply refused. */
148
233
  export type PrRefusal =
@@ -152,8 +237,45 @@ export type PrRefusal =
152
237
  | "plan-changed"
153
238
  /** The approval names someone who has not approved the pull request on the forge. */
154
239
  | "not-a-reviewer"
240
+ /** The approval names the pull request's author, or an author or committer of one of its commits (#4000). */
241
+ | "author-approved"
155
242
  /** No pull request merged this commit, so there is no approval to read. */
156
- | "no-pull-request";
243
+ | "no-pull-request"
244
+ /** `--wave-gate` (#4003): the wave's new plan is not one the pull request approved, and no approval stands for it. */
245
+ | "wave-not-approved"
246
+ /** `--wave-gate`: an approval of the wave's gate stands for another digest, so its plan moved since. */
247
+ | "wave-plan-changed"
248
+ /** `--wave-gate` with `--wave <k>`: an earlier wave has work left, or no record says it applied. */
249
+ | "earlier-wave";
250
+
251
+ /**
252
+ * One wave of an apply with `--wave-gate` (#4003): what it planned, where it
253
+ * got to, and which approval it applied or waits under.
254
+ */
255
+ export interface PrWave {
256
+ /** 1-based, from the derivation (`selection.waves`). */
257
+ wave: number;
258
+ /** The components planned in it on the run that reached it. */
259
+ components: string[];
260
+ /** `applied`; `failed` or `plan-failed`; or `waiting` at its gate. */
261
+ status: "applied" | "failed" | "plan-failed" | "waiting";
262
+ /**
263
+ * `pull-request`: the approved change set covers the wave's plan, so it
264
+ * applies under the pull request's approval. `wave`: its plan moved, so it
265
+ * needs an approval of its own gate.
266
+ */
267
+ approval: "pull-request" | "wave";
268
+ /** The gate it applied or waits under: the pull request's, or `<wave gate>-wave-<k>`. */
269
+ gate: string;
270
+ /** The digest that gate binds: the pull request's change set, or the wave's new plan. */
271
+ digest: string;
272
+ /** Who approved that digest. */
273
+ approvedBy?: string[];
274
+ /** Waiting: an approval of the wave's gate stands for this other digest. */
275
+ approved?: string;
276
+ /** Why the approved change set does not cover the wave's plan, one line per member. */
277
+ moved?: string[];
278
+ }
157
279
 
158
280
  /**
159
281
  * The document `pr-plan` and `pr-apply` write (`pr-report.schema.json`).
@@ -194,7 +316,28 @@ export interface PrReport {
194
316
  * {@link PR_REPORT_DEPLOYED_OUTPUTS_FLOOR}.
195
317
  */
196
318
  deployedOutputs?: Record<string, string[]>;
319
+ /**
320
+ * Per dependency in the change that a member was planned against (#3999),
321
+ * the names of the outputs its plan knows, sorted. An output it reads that
322
+ * is not here is known only after apply (a member's `unknownInputs`).
323
+ * Absent when no member read one. Added within contract 1 by chant
324
+ * {@link PR_REPORT_PLANNED_OUTPUTS_FLOOR}.
325
+ */
326
+ plannedOutputs?: Record<string, string[]>;
327
+ /**
328
+ * Apply stage (#3999): the rounds planned after an upstream applied, in
329
+ * order, each with its own gate and digest. Absent when nothing was held.
330
+ */
331
+ rounds?: PrRound[];
197
332
  approval: PrApproval;
333
+ /**
334
+ * The wave gate's base name with `--wave-gate` (#4003): wave k waits on
335
+ * `<waveGate>-wave-<k>` when its plan moved. Added within contract 1 by
336
+ * chant {@link PR_REPORT_WAVES_FLOOR}.
337
+ */
338
+ waveGate?: string;
339
+ /** With `waveGate`: each wave reached so far, in order. */
340
+ waves?: PrWave[];
198
341
  /** Component names: which changed, which run because they depend on one, and what the change touched that no component deploys. */
199
342
  selection: {
200
343
  changed: string[];
@@ -252,6 +395,7 @@ const STATUS_WORDS: Record<PrMemberStatus, string> = {
252
395
  applied: "applied",
253
396
  failed: "apply failed",
254
397
  blocked: "blocked",
398
+ waiting: "waiting on its new plan",
255
399
  };
256
400
 
257
401
  function headline(report: PrReport): string {
@@ -268,11 +412,55 @@ function headline(report: PrReport): string {
268
412
  return `Applied ${members}.`;
269
413
  case "failed":
270
414
  return `The apply failed: ${report.members.filter((m) => m.status === "failed").length} failed, ${report.members.filter((m) => m.status === "applied").length} applied.`;
271
- case "refused":
272
- return "The apply refused.";
415
+ case "wave-applied": {
416
+ const applied = (report.waves ?? []).filter((w) => w.status === "applied").map((w) => w.wave);
417
+ const total = report.selection.waves.length;
418
+ return `Applied wave ${applied.at(-1) ?? "?"} of ${total}. The next wave runs in its own job.`;
419
+ }
420
+ case "refused": {
421
+ const waiting = report.waves?.find((w) => w.status === "waiting");
422
+ return waiting ? `Wave ${waiting.wave} waits at its gate ${code(waiting.gate)}; nothing in it applied.` : "The apply refused.";
423
+ }
424
+ case "waiting":
425
+ return `Applied ${report.members.filter((m) => m.status === "applied").length} of ${members}; ${report.members.filter((m) => m.status === "waiting").length} wait on an approval of the plan made after their upstream applied.`;
273
426
  }
274
427
  }
275
428
 
429
+ /** Who a wave applied or waits under, as a table cell. */
430
+ function waveApproval(w: PrWave): string {
431
+ const whose = w.approval === "pull-request" ? "the pull request's" : "its own";
432
+ const by = w.approvedBy?.length ? ` by ${w.approvedBy.map(code).join(", ")}` : w.status === "waiting" ? ", not approved yet" : "";
433
+ return `${whose} ${code(w.gate)}${by}`;
434
+ }
435
+
436
+ /**
437
+ * The waves of an apply with `--wave-gate` (#4003): a row per wave reached,
438
+ * saying which approval it applied under, then for a wave that waits the
439
+ * reason its plan moved and the approve command for its new plan.
440
+ */
441
+ function waveLines(report: PrReport, approver: string): string[] {
442
+ const waves = report.waves ?? [];
443
+ if (waves.length === 0) return [];
444
+ const out = ["", "| Wave | Components | Status | Approval |", "|---:|---|---|---|"];
445
+ for (const w of waves) out.push(`| ${w.wave} | ${w.components.map(code).join(", ")} | ${w.status} | ${waveApproval(w)} |`);
446
+ for (const w of waves.filter((x) => x.status === "waiting")) {
447
+ out.push("", `Wave ${w.wave} was planned after the waves before it applied, and the approved plan does not cover it:`, "");
448
+ for (const why of w.moved ?? []) out.push(`- ${why}`);
449
+ if (w.approved) out.push("", `An approval of ${code(w.gate)} stands for ${code(w.approved)}, not for the plan now.`);
450
+ out.push(
451
+ "",
452
+ `Read wave ${w.wave}'s plan, ${code(w.digest)}, and approve it with:`,
453
+ "",
454
+ "```",
455
+ prApproveCommand({ op: report.op, gate: w.gate, digest: w.digest }, approver),
456
+ "```",
457
+ "",
458
+ "Then run the wave's apply job again.",
459
+ );
460
+ }
461
+ return out;
462
+ }
463
+
276
464
  function approvalLines(report: PrReport, approver: string): string[] {
277
465
  const a = report.approval;
278
466
  if (report.status === "nothing") return [];
@@ -332,6 +520,7 @@ export function renderPrNote(report: PrReport, options: { limit?: number; approv
332
520
  out.push("", "A member whose inputs moved applied the plan it was approved with. The next run plans it against the new values.");
333
521
  }
334
522
  }
523
+ out.push(...waveLines(report, options.approver ?? "<you>"));
335
524
  if (report.selection.unclaimed.length > 0) {
336
525
  out.push("", `Changed, and deployed by no component: ${report.selection.unclaimed.map(code).join(", ")}.`);
337
526
  }
@@ -340,9 +529,43 @@ export function renderPrNote(report: PrReport, options: { limit?: number; approv
340
529
  const each = deployed.map(([dep, names]) => `${code(dep)} (${names.length > 0 ? names.map(code).join(", ") : "none yet"})`);
341
530
  out.push("", `Planned against outputs read from the deployed estate: ${each.join("; ")}.`);
342
531
  }
532
+ const planned = Object.entries(report.plannedOutputs ?? {});
533
+ if (planned.length > 0) {
534
+ const each = planned.map(([dep, names]) => `${code(dep)} (${names.length > 0 ? names.map(code).join(", ") : "none known"})`);
535
+ out.push("", `Planned against the outputs this change's plans say its upstreams will have: ${each.join("; ")}.`);
536
+ }
537
+ const unknown = [...new Set(report.members.flatMap((m) => (m.unknownInputs ?? []).map((ref) => `${code(m.component)} reads ${code(ref)}`)))];
538
+ if (unknown.length > 0) {
539
+ out.push(
540
+ "",
541
+ `Known only after apply: ${unknown.join("; ")}. This approval does not cover what those members do with them. ` +
542
+ "The apply plans them again once their upstream applied and asks for an approval of that plan.",
543
+ );
544
+ }
545
+ const fromBuild = [...new Set(report.members.flatMap((m) => (m.buildInputs ?? []).map((ref) => `${code(m.component)} reads ${code(ref)}`)))];
546
+ if (fromBuild.length > 0) {
547
+ out.push(
548
+ "",
549
+ `From this pull request's build: ${fromBuild.join("; ")}. The image digest comes from this pull request's build, whose provenance binds it, ` +
550
+ "so those members apply with it once the build ran, without a second approval.",
551
+ );
552
+ }
553
+ for (const r of report.rounds ?? []) {
554
+ const what = `Round ${r.round} planned ${r.components.map(code).join(", ")} again after their upstream applied, digest ${code(r.digest)}`;
555
+ if (r.status === "waiting") {
556
+ if (r.message) out.push("", `> ${r.message}`);
557
+ out.push("", `${what}. Not approved yet. Approve it, then run the apply again with the same \`--resume\` record:`, "", "```", prApproveCommand({ op: report.op, gate: r.gate, digest: r.digest }, options.approver ?? "<you>"), "```");
558
+ } else {
559
+ out.push("", `${what}: ${r.status === "applied" ? `applied, approved by ${(r.approval.approvedBy ?? []).map(code).join(", ")}` : r.status === "plan-failed" ? "a member failed to plan" : "the apply failed"}.`);
560
+ }
561
+ }
343
562
  if (report.status !== "nothing") {
344
563
  out.push("", `Plan digest: ${code(report.digest)}`, "", ...approvalLines(report, options.approver ?? "<you>"));
345
564
  }
565
+ // #4003: with a gate per wave, a later wave's plan on merge may differ from this one.
566
+ if (report.stage === "plan" && report.status === "planned" && report.waveGate) {
567
+ out.push("", `On merge each wave after the first is planned again once the waves before it apply, and a wave whose plan moved stops at its own gate, ${code(`${report.waveGate}-wave-<k>`)}, for approval.`);
568
+ }
346
569
  const head = out.join("\n") + "\n";
347
570
  if (report.status === "nothing" || report.changeSet.members.length === 0) return head;
348
571
  const room = limit - [...head].length - 1;
@@ -374,19 +597,38 @@ export function prStatusDescription(report: PrReport): string {
374
597
  case "applied":
375
598
  text = `applied ${n} member${n === 1 ? "" : "s"}${digest}`;
376
599
  break;
600
+ case "wave-applied": {
601
+ const last = (report.waves ?? []).filter((w) => w.status === "applied").at(-1);
602
+ text = `applied wave ${last?.wave ?? "?"} of ${report.selection.waves.length}${last ? ` under ${last.approval === "pull-request" ? "the pull request's approval" : `${last.gate}`}` : ""}`;
603
+ break;
604
+ }
377
605
  case "failed":
378
606
  text = `apply failed for ${report.members.filter((m) => m.status === "failed").map((m) => m.member).join(", ")}`;
379
607
  break;
380
- case "refused":
381
- text = `refused: ${report.refusal === "plan-changed" ? "the plan changed after review" : report.refusal === "not-a-reviewer" ? "the approver has not approved the pull request" : report.refusal === "no-pull-request" ? "no pull request merged this commit" : "the plan is not approved"}`;
608
+ case "waiting":
609
+ text = `waiting: ${report.members.filter((m) => m.status === "waiting").map((m) => m.member).join(", ")} planned again after an upstream applied, not approved yet`;
382
610
  break;
611
+ case "refused": {
612
+ const waiting = report.waves?.find((w) => w.status === "waiting");
613
+ if (waiting && (report.refusal === "wave-not-approved" || report.refusal === "wave-plan-changed")) {
614
+ text = `wave ${waiting.wave} waits at ${waiting.gate}: ${report.refusal === "wave-plan-changed" ? "its plan changed after its approval" : "its plan moved, approve it"}`;
615
+ break;
616
+ }
617
+ if (report.refusal === "earlier-wave") {
618
+ text = "refused: an earlier wave has not applied";
619
+ break;
620
+ }
621
+ text = `refused: ${report.refusal === "plan-changed" ? "the plan changed after review" : report.refusal === "not-a-reviewer" ? "the approver has not approved the pull request" : report.refusal === "author-approved" ? "the approver wrote the change" : report.refusal === "no-pull-request" ? "no pull request merged this commit" : "the plan is not approved"}`;
622
+ break;
623
+ }
383
624
  }
384
625
  return text.length > 140 ? text.slice(0, 137) + "..." : text;
385
626
  }
386
627
 
387
628
  /** The commit status state for a report: success, failure, or pending while it waits on approval. */
388
629
  export function prStatusState(report: PrReport): "success" | "failure" | "pending" {
389
- if (report.status === "planned" || report.status === "applied" || report.status === "nothing") return "success";
390
- if (report.status === "refused" && report.refusal === "not-approved") return "pending";
630
+ if (report.status === "planned" || report.status === "applied" || report.status === "wave-applied" || report.status === "nothing") return "success";
631
+ if (report.status === "refused" && (report.refusal === "not-approved" || report.refusal === "wave-not-approved")) return "pending";
632
+ if (report.status === "waiting") return "pending";
391
633
  return "failure";
392
634
  }
@@ -35,7 +35,7 @@
35
35
  */
36
36
 
37
37
  import { spawn } from "node:child_process";
38
- import { mkdirSync, renameSync, writeFileSync } from "node:fs";
38
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
39
39
  import { dirname, isAbsolute, join } from "node:path";
40
40
  import { fileURLToPath } from "node:url";
41
41
 
@@ -44,17 +44,17 @@ export type ReportTarget =
44
44
  | { scheme: "file"; url: string; dir: string }
45
45
  | { scheme: "s3"; url: string; bucket: string; prefix: string };
46
46
 
47
- /** `--report-url` read, or why it can't be. */
48
- export function parseReportUrl(raw: string): ReportTarget | { error: string } {
47
+ /** `--report-url` read, or why it can't be. `name` is what the error calls the value: the flag, or `ci.reportUrl` (#4160). */
48
+ export function parseReportUrl(raw: string, name = "--report-url"): ReportTarget | { error: string } {
49
49
  const url = raw.trim();
50
50
  if (url.startsWith("file://")) {
51
51
  let dir: string;
52
52
  try {
53
53
  dir = fileURLToPath(url);
54
54
  } catch (err) {
55
- return { error: `--report-url ${url}: ${err instanceof Error ? err.message : String(err)}` };
55
+ return { error: `${name} ${url}: ${err instanceof Error ? err.message : String(err)}` };
56
56
  }
57
- if (!isAbsolute(dir)) return { error: `--report-url ${url}: a file URL names an absolute directory` };
57
+ if (!isAbsolute(dir)) return { error: `${name} ${url}: a file URL names an absolute directory` };
58
58
  return { scheme: "file", url: url.replace(/\/+$/, ""), dir };
59
59
  }
60
60
  const s3 = /^s3:\/\/([^/]+)\/?(.*)$/.exec(url);
@@ -62,7 +62,7 @@ export function parseReportUrl(raw: string): ReportTarget | { error: string } {
62
62
  const prefix = s3[2]!.replace(/\/+$/, "");
63
63
  return { scheme: "s3", url: `s3://${s3[1]}${prefix ? `/${prefix}` : ""}`, bucket: s3[1]!, prefix };
64
64
  }
65
- return { error: `--report-url ${url}: takes an s3://<bucket>/<prefix> or file://<directory> URL` };
65
+ return { error: `${name} ${url}: takes an s3://<bucket>/<prefix> or file://<directory> URL` };
66
66
  }
67
67
 
68
68
  /** The key a stage's files are kept under, below the URL: `<pr>/<commit>[/<member>]`. */
@@ -120,6 +120,58 @@ export function reportPut(target: ReportTarget, aws: AwsCli = realAwsCli): Repor
120
120
  };
121
121
  }
122
122
 
123
+ /** Reads one object: `key` below the URL. Resolves null for an object that is not there, and rejects with a line a person can read for any other failure. */
124
+ export type ReportGet = (key: string) => Promise<string | null>;
125
+
126
+ /** Runs the AWS CLI with `args` and resolves its stdout, rejecting with its error line on a non-zero exit. */
127
+ export type AwsRead = (args: string[]) => Promise<string>;
128
+
129
+ /** The AWS CLI on PATH, read for the body `aws s3 cp <s3 url> -` prints. */
130
+ export const realAwsRead: AwsRead = (args) =>
131
+ new Promise((resolveRead, reject) => {
132
+ const child = spawn(AWS_BINARY, args, { stdio: ["ignore", "pipe", "pipe"] });
133
+ const out: Buffer[] = [];
134
+ let stderr = "";
135
+ child.stdout.on("data", (chunk: Buffer) => out.push(chunk));
136
+ child.stderr.on("data", (chunk: Buffer) => {
137
+ if (stderr.length < 4096) stderr += chunk.toString("utf8");
138
+ });
139
+ child.on("error", (err: NodeJS.ErrnoException) =>
140
+ reject(new Error(err.code === "ENOENT" ? "the AWS CLI (aws) is not on PATH; an s3 report URL is read with it" : err.message)),
141
+ );
142
+ child.on("close", (code) => {
143
+ if (code === 0) return resolveRead(Buffer.concat(out).toString("utf8"));
144
+ const line = stderr.trim().split("\n").filter(Boolean).at(-1) ?? "";
145
+ reject(new Error(`aws s3 cp exited ${code}${line ? `: ${line.slice(0, 300)}` : ""}`));
146
+ });
147
+ });
148
+
149
+ /** What the AWS CLI says about an object that does not exist. */
150
+ const S3_ABSENT = /\(404\)|Not Found|NoSuchKey|does not exist/i;
151
+
152
+ /** A get for `target`. `aws` replaces the AWS CLI in a test. */
153
+ export function reportGet(target: ReportTarget, aws: AwsRead = realAwsRead): ReportGet {
154
+ if (target.scheme === "file") {
155
+ return async (key) => {
156
+ try {
157
+ return readFileSync(join(target.dir, ...key.split("/")), "utf-8");
158
+ } catch (err) {
159
+ if ((err as NodeJS.ErrnoException).code === "ENOENT") return null;
160
+ throw err;
161
+ }
162
+ };
163
+ }
164
+ return async (key) => {
165
+ const object = `s3://${target.bucket}/${target.prefix ? `${target.prefix}/` : ""}${key}`;
166
+ try {
167
+ return await aws(["s3", "cp", object, "-", "--only-show-errors"]);
168
+ } catch (err) {
169
+ if (S3_ABSENT.test(messageOf(err))) return null;
170
+ throw err;
171
+ }
172
+ };
173
+ }
174
+
123
175
  /** A stage's upload: its events as they are written, and its files at the end. */
124
176
  export interface PrReportUpload {
125
177
  /** The folder the stage's files go to: `<url>/<key>`. */
@@ -1,5 +1,7 @@
1
1
  import { describe, test, expect } from "vitest";
2
2
  import { join } from "path";
3
+ import { cpSync, mkdtempSync, rmSync } from "fs";
4
+ import { tmpdir } from "os";
3
5
  import {
4
6
  carveAdvise,
5
7
  carveJson,
@@ -50,10 +52,27 @@ describe("carve advise against the sample estate", () => {
50
52
  expect(byAddr["random_pet.suffix"].score).toBe(0);
51
53
  expect(byAddr["random_pet.suffix"].band).toBe("leave in Terraform");
52
54
 
53
- // The report never proposes a mutation.
54
- const text = formatCarveReport(r);
55
+ // The report never proposes a mutation. The estate path is the caller's,
56
+ // so it is masked before the check (#3169).
57
+ const text = formatCarveReport(r).split(r.from!).join("<estate>");
55
58
  expect(text).not.toMatch(/state rm|apply|destroy/i);
56
59
  });
60
+
61
+ test("the no-mutation check holds in a checkout whose path says apply or destroy (#3169)", async () => {
62
+ if (!parserAvailable) return;
63
+ const parent = mkdtempSync(join(tmpdir(), "carve-native-apply-destroy-"));
64
+ try {
65
+ const estate = join(parent, "sample-estate");
66
+ cpSync(ESTATE, estate, { recursive: true });
67
+ const r = await carveAdvise({ from: estate });
68
+ expect(r.ok).toBe(true);
69
+ const text = formatCarveReport(r);
70
+ expect(text).toContain(estate);
71
+ expect(text.split(r.from!).join("<estate>")).not.toMatch(/state rm|apply|destroy/i);
72
+ } finally {
73
+ rmSync(parent, { recursive: true, force: true });
74
+ }
75
+ });
57
76
  });
58
77
 
59
78
  /**
@@ -1,7 +1,9 @@
1
+ import { mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
1
3
  import { join, sep } from "node:path";
2
4
  import { pathToFileURL } from "node:url";
3
5
  import { describe, expect, test } from "vitest";
4
- import { chantSourceDir, ensureTypeScriptLoader } from "./ts-loader";
6
+ import { chantPackageSourceTarget, chantSourceDir, lexiconCompiledTwin, ensureTypeScriptLoader, ensureTypeScriptLoaderFor, typeScriptLoaderPending } from "./ts-loader";
5
7
 
6
8
  describe("ts-loader (#3878)", () => {
7
9
  const pkg = join(sep, "x", "node_modules", "@intentius", "chant");
@@ -20,4 +22,90 @@ describe("ts-loader (#3878)", () => {
20
22
  test("from source, the TypeScript loader is already there and nothing is registered", () => {
21
23
  expect(ensureTypeScriptLoader()).toBe(false);
22
24
  });
25
+
26
+ test("from source, no module asks for the loader (#3981)", () => {
27
+ expect(typeScriptLoaderPending()).toBe(false);
28
+ expect(ensureTypeScriptLoaderFor("/p/src/index.ts")).toBe(false);
29
+ expect(ensureTypeScriptLoaderFor("/p/dist/index.js")).toBe(false);
30
+ });
31
+
32
+ test("compiled, a JavaScript module leaves tsx unregistered (#3981)", () => {
33
+ const STATE = Symbol.for("chant.compiledCli");
34
+ const global = globalThis as { [STATE]?: { tsx: boolean } };
35
+ global[STATE] = { tsx: false };
36
+ try {
37
+ expect(typeScriptLoaderPending()).toBe(true);
38
+ expect(ensureTypeScriptLoaderFor("file:///p/dist/index.js")).toBe(false);
39
+ expect(ensureTypeScriptLoaderFor("/p/dist/meta.json")).toBe(false);
40
+ expect(global[STATE]).toEqual({ tsx: false });
41
+ global[STATE] = { tsx: true };
42
+ expect(typeScriptLoaderPending()).toBe(false);
43
+ expect(ensureTypeScriptLoaderFor("/p/src/index.ts")).toBe(true);
44
+ } finally {
45
+ delete global[STATE];
46
+ }
47
+ });
48
+ });
49
+
50
+ describe("chantPackageSourceTarget (#3981)", () => {
51
+ test("resolves a symlinked lexicon's root and pattern exports to their development source, by real path", () => {
52
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "chant-source-target-")));
53
+ try {
54
+ const lexicon = join(root, "lexicons", "demo");
55
+ mkdirSync(join(lexicon, "src", "generated"), { recursive: true });
56
+ writeFileSync(join(lexicon, "src", "index.ts"), "");
57
+ writeFileSync(join(lexicon, "src", "generated", "index.ts"), "");
58
+ writeFileSync(
59
+ join(lexicon, "package.json"),
60
+ JSON.stringify({
61
+ name: "@intentius/chant-lexicon-demo",
62
+ exports: {
63
+ ".": { development: "./src/index.ts", types: "./dist/index.d.ts", default: "./dist/index.js" },
64
+ "./*": { development: "./src/*.ts", types: "./dist/*.d.ts", default: "./dist/*.js" },
65
+ "./meta": "./dist/meta.json",
66
+ },
67
+ }),
68
+ );
69
+ mkdirSync(join(root, "project", "node_modules", "@intentius"), { recursive: true });
70
+ symlinkSync(lexicon, join(root, "project", "node_modules", "@intentius", "chant-lexicon-demo"), "dir");
71
+ mkdirSync(join(root, "project", "src"));
72
+ const parent = join(root, "project", "src", "infra.ts");
73
+
74
+ expect(chantPackageSourceTarget("@intentius/chant-lexicon-demo", parent)).toBe(join(lexicon, "src", "index.ts"));
75
+ expect(chantPackageSourceTarget("@intentius/chant-lexicon-demo/generated/index", parent)).toBe(join(lexicon, "src", "generated", "index.ts"));
76
+ // No development condition, a missing file, another scope or an absent package: left to Node.
77
+ expect(chantPackageSourceTarget("@intentius/chant-lexicon-demo/meta", parent)).toBeUndefined();
78
+ expect(chantPackageSourceTarget("@intentius/chant-lexicon-demo/missing", parent)).toBeUndefined();
79
+ expect(chantPackageSourceTarget("@other/chant-lexicon-demo", parent)).toBeUndefined();
80
+ expect(chantPackageSourceTarget("@intentius/chant-lexicon-absent", parent)).toBeUndefined();
81
+ } finally {
82
+ rmSync(root, { recursive: true, force: true });
83
+ }
84
+ });
85
+ });
86
+
87
+ describe("lexiconCompiledTwin (#3981)", () => {
88
+ test("points a lexicon's src/*.ts at its dist/*.js when that exists, and nothing else", () => {
89
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "chant-compiled-twin-")));
90
+ try {
91
+ const lexicon = join(root, "node_modules", "@intentius", "chant-lexicon-demo");
92
+ const other = join(root, "node_modules", "other");
93
+ for (const dir of [join(lexicon, "src", "generated"), join(lexicon, "dist", "generated"), join(other, "src"), join(other, "dist")]) {
94
+ mkdirSync(dir, { recursive: true });
95
+ }
96
+ writeFileSync(join(lexicon, "package.json"), JSON.stringify({ name: "@intentius/chant-lexicon-demo" }));
97
+ writeFileSync(join(other, "package.json"), JSON.stringify({ name: "other" }));
98
+ for (const file of ["src/generated/index.ts", "dist/generated/index.js", "src/only-source.ts"]) writeFileSync(join(lexicon, file), "");
99
+ for (const file of ["src/index.ts", "dist/index.js"]) writeFileSync(join(other, file), "");
100
+ const url = (path: string) => pathToFileURL(path).href;
101
+
102
+ expect(lexiconCompiledTwin(url(join(lexicon, "src", "generated", "index.ts")))).toBe(url(join(lexicon, "dist", "generated", "index.js")));
103
+ expect(lexiconCompiledTwin(url(join(lexicon, "src", "only-source.ts")))).toBeUndefined();
104
+ expect(lexiconCompiledTwin(url(join(lexicon, "dist", "generated", "index.js")))).toBeUndefined();
105
+ expect(lexiconCompiledTwin(url(join(other, "src", "index.ts")))).toBeUndefined();
106
+ expect(lexiconCompiledTwin("node:fs")).toBeUndefined();
107
+ } finally {
108
+ rmSync(root, { recursive: true, force: true });
109
+ }
110
+ });
23
111
  });