@intentius/chant 0.124.87 → 0.124.88

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 (342) hide show
  1. package/dist/action-pins.d.ts +1 -0
  2. package/dist/action-pins.d.ts.map +1 -1
  3. package/dist/action-pins.js +2 -0
  4. package/dist/actor.d.ts +12 -0
  5. package/dist/actor.d.ts.map +1 -0
  6. package/dist/actor.js +18 -0
  7. package/dist/bundle-check.d.ts +20 -5
  8. package/dist/bundle-check.d.ts.map +1 -1
  9. package/dist/bundle-check.js +20 -5
  10. package/dist/chant-install.d.ts +98 -0
  11. package/dist/chant-install.d.ts.map +1 -1
  12. package/dist/chant-install.js +204 -2
  13. package/dist/ci-commit.d.ts +1 -1
  14. package/dist/ci-commit.d.ts.map +1 -1
  15. package/dist/ci-commit.js +1 -2
  16. package/dist/ci-control.d.ts +1 -1
  17. package/dist/ci-control.d.ts.map +1 -1
  18. package/dist/ci-control.js +1 -1
  19. package/dist/ci-evidence-claims.d.ts +59 -0
  20. package/dist/ci-evidence-claims.d.ts.map +1 -0
  21. package/dist/ci-evidence-claims.js +87 -0
  22. package/dist/ci-evidence-from-job.d.ts +103 -0
  23. package/dist/ci-evidence-from-job.d.ts.map +1 -0
  24. package/dist/ci-evidence-from-job.js +162 -0
  25. package/dist/ci-evidence-jobs.d.ts +39 -4
  26. package/dist/ci-evidence-jobs.d.ts.map +1 -1
  27. package/dist/ci-evidence-jobs.js +38 -4
  28. package/dist/ci-handover.d.ts +12 -0
  29. package/dist/ci-handover.d.ts.map +1 -1
  30. package/dist/ci-handover.js +15 -3
  31. package/dist/ci-identity.d.ts +32 -6
  32. package/dist/ci-identity.d.ts.map +1 -1
  33. package/dist/ci-identity.js +40 -8
  34. package/dist/ci-image.d.ts +47 -9
  35. package/dist/ci-image.d.ts.map +1 -1
  36. package/dist/ci-image.js +45 -18
  37. package/dist/ci-jobs.d.ts +1 -1
  38. package/dist/ci-jobs.d.ts.map +1 -1
  39. package/dist/ci-jobs.js +7 -2
  40. package/dist/ci-login.d.ts +75 -13
  41. package/dist/ci-login.d.ts.map +1 -1
  42. package/dist/ci-login.js +89 -37
  43. package/dist/ci-product-words.d.ts +20 -1
  44. package/dist/ci-product-words.d.ts.map +1 -1
  45. package/dist/ci-product-words.js +27 -1
  46. package/dist/ci-product.d.ts +21 -2
  47. package/dist/ci-product.d.ts.map +1 -1
  48. package/dist/ci-product.js +21 -2
  49. package/dist/cli/handlers/approve-confirm.d.ts +14 -0
  50. package/dist/cli/handlers/approve-confirm.d.ts.map +1 -1
  51. package/dist/cli/handlers/approve-confirm.js +46 -0
  52. package/dist/cli/handlers/build.d.ts +1 -1
  53. package/dist/cli/handlers/build.d.ts.map +1 -1
  54. package/dist/cli/handlers/build.js +22 -1
  55. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  56. package/dist/cli/handlers/ci-check.js +21 -1
  57. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  58. package/dist/cli/handlers/ci-evidence.js +227 -18
  59. package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -1
  60. package/dist/cli/handlers/ci-forge-check.js +34 -17
  61. package/dist/cli/handlers/generated-check.d.ts +3 -0
  62. package/dist/cli/handlers/generated-check.d.ts.map +1 -0
  63. package/dist/cli/handlers/generated-check.js +41 -0
  64. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  65. package/dist/cli/handlers/lifecycle.js +3 -0
  66. package/dist/cli/handlers/local-chant.d.ts +13 -0
  67. package/dist/cli/handlers/local-chant.d.ts.map +1 -1
  68. package/dist/cli/handlers/local-chant.js +42 -1
  69. package/dist/cli/handlers/pr.d.ts.map +1 -1
  70. package/dist/cli/handlers/pr.js +42 -5
  71. package/dist/cli/handlers/run-wave.js +8 -0
  72. package/dist/cli/main.d.ts.map +1 -1
  73. package/dist/cli/main.js +38 -4
  74. package/dist/cli/parse-args.d.ts.map +1 -1
  75. package/dist/cli/parse-args.js +66 -0
  76. package/dist/cli/registry.d.ts +24 -0
  77. package/dist/cli/registry.d.ts.map +1 -1
  78. package/dist/components/check-hooks.d.ts +10 -0
  79. package/dist/components/check-hooks.d.ts.map +1 -1
  80. package/dist/components/check-hooks.js +18 -0
  81. package/dist/components/pr-checks.d.ts +105 -0
  82. package/dist/components/pr-checks.d.ts.map +1 -0
  83. package/dist/components/pr-checks.js +119 -0
  84. package/dist/components/pr-pipeline.d.ts +34 -0
  85. package/dist/components/pr-pipeline.d.ts.map +1 -1
  86. package/dist/components/pr-pipeline.js +14 -1
  87. package/dist/components/product-pipeline.d.ts +16 -1
  88. package/dist/components/product-pipeline.d.ts.map +1 -1
  89. package/dist/components/product-pipeline.js +17 -2
  90. package/dist/components/product-plan.d.ts +257 -4
  91. package/dist/components/product-plan.d.ts.map +1 -1
  92. package/dist/components/product-plan.js +241 -11
  93. package/dist/config.d.ts +10 -6
  94. package/dist/config.d.ts.map +1 -1
  95. package/dist/config.js +11 -6
  96. package/dist/control/consumers.d.ts +6 -0
  97. package/dist/control/consumers.d.ts.map +1 -1
  98. package/dist/control/consumers.js +6 -0
  99. package/dist/dead-guards.d.ts.map +1 -1
  100. package/dist/dead-guards.js +9 -6
  101. package/dist/discovery/files.d.ts +1 -1
  102. package/dist/discovery/files.js +1 -1
  103. package/dist/drift-issue.d.ts +20 -3
  104. package/dist/drift-issue.d.ts.map +1 -1
  105. package/dist/drift-issue.js +16 -0
  106. package/dist/drift-record.d.ts +45 -5
  107. package/dist/drift-record.d.ts.map +1 -1
  108. package/dist/drift-record.js +27 -6
  109. package/dist/floor-table.d.ts +6 -6
  110. package/dist/floor-table.d.ts.map +1 -1
  111. package/dist/floor-table.data.d.ts.map +1 -1
  112. package/dist/floor-table.data.js +58 -21
  113. package/dist/floor-table.js +10 -7
  114. package/dist/forge-check/contract.d.ts +8 -0
  115. package/dist/forge-check/contract.d.ts.map +1 -1
  116. package/dist/forge-check/contract.js +4 -1
  117. package/dist/forge-check/index.d.ts +2 -0
  118. package/dist/forge-check/index.d.ts.map +1 -1
  119. package/dist/forge-check/index.js +2 -0
  120. package/dist/forge-flags.d.ts +10 -0
  121. package/dist/forge-flags.d.ts.map +1 -1
  122. package/dist/forge-flags.js +31 -0
  123. package/dist/forge-remote.d.ts +47 -0
  124. package/dist/forge-remote.d.ts.map +1 -0
  125. package/dist/forge-remote.js +69 -0
  126. package/dist/generated-check.d.ts +74 -0
  127. package/dist/generated-check.d.ts.map +1 -0
  128. package/dist/generated-check.js +216 -0
  129. package/dist/lexicon.d.ts +16 -0
  130. package/dist/lexicon.d.ts.map +1 -1
  131. package/dist/lifecycle/publish-npm.d.ts +15 -0
  132. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  133. package/dist/lifecycle/publish-npm.js +49 -3
  134. package/dist/lifecycle/release-images.d.ts +22 -1
  135. package/dist/lifecycle/release-images.d.ts.map +1 -1
  136. package/dist/lifecycle/release-images.js +27 -3
  137. package/dist/lifecycle/release-ledger.d.ts +4 -3
  138. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  139. package/dist/lifecycle/release-ledger.js +3 -2
  140. package/dist/local-chant.d.ts +57 -3
  141. package/dist/local-chant.d.ts.map +1 -1
  142. package/dist/local-chant.js +122 -13
  143. package/dist/op/op-waves-evidence-jobs.d.ts +92 -0
  144. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -0
  145. package/dist/op/op-waves-evidence-jobs.js +112 -0
  146. package/dist/op/op-waves-evidence.d.ts +12 -1
  147. package/dist/op/op-waves-evidence.d.ts.map +1 -1
  148. package/dist/op/op-waves-evidence.js +23 -2
  149. package/dist/op/op-waves-run.d.ts +12 -1
  150. package/dist/op/op-waves-run.d.ts.map +1 -1
  151. package/dist/op/op-waves-run.js +54 -3
  152. package/dist/op/op-waves.d.ts +8 -0
  153. package/dist/op/op-waves.d.ts.map +1 -1
  154. package/dist/op/op-waves.js +10 -0
  155. package/dist/op/schedule-overdue.d.ts +39 -2
  156. package/dist/op/schedule-overdue.d.ts.map +1 -1
  157. package/dist/op/schedule-overdue.js +89 -7
  158. package/dist/pr-forge-reads.d.ts +21 -1
  159. package/dist/pr-forge-reads.d.ts.map +1 -1
  160. package/dist/pr-forge-reads.js +19 -1
  161. package/dist/pr-forge.d.ts +7 -1
  162. package/dist/pr-forge.d.ts.map +1 -1
  163. package/dist/pr-forge.js +7 -2
  164. package/dist/pr-plan-note.d.ts +24 -0
  165. package/dist/pr-plan-note.d.ts.map +1 -1
  166. package/dist/pr-plan-note.js +11 -1
  167. package/dist/pr-plan-record.d.ts +47 -0
  168. package/dist/pr-plan-record.d.ts.map +1 -0
  169. package/dist/pr-plan-record.js +89 -0
  170. package/dist/pr-post.d.ts +40 -0
  171. package/dist/pr-post.d.ts.map +1 -1
  172. package/dist/pr-post.js +79 -6
  173. package/dist/pr-requires.d.ts +8 -0
  174. package/dist/pr-requires.d.ts.map +1 -1
  175. package/dist/pr-requires.js +3 -1
  176. package/dist/ref-gate-init.d.ts +76 -0
  177. package/dist/ref-gate-init.d.ts.map +1 -0
  178. package/dist/ref-gate-init.js +144 -0
  179. package/dist/ref-gate-rules.d.ts +19 -0
  180. package/dist/ref-gate-rules.d.ts.map +1 -0
  181. package/dist/ref-gate-rules.js +17 -0
  182. package/dist/release-floors.d.ts +64 -16
  183. package/dist/release-floors.d.ts.map +1 -1
  184. package/dist/release-floors.js +65 -17
  185. package/dist/state-migration.d.ts +24 -1
  186. package/dist/state-migration.d.ts.map +1 -1
  187. package/dist/state-migration.js +39 -3
  188. package/dist/state-unlock.d.ts +32 -1
  189. package/dist/state-unlock.d.ts.map +1 -1
  190. package/dist/state-unlock.js +31 -0
  191. package/dist/wave-runtime.mjs +292 -285
  192. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  193. package/dist/workspace/ci-green-cli.js +13 -7
  194. package/dist/workspace/drift-cli.d.ts +1 -1
  195. package/dist/workspace/drift-cli.d.ts.map +1 -1
  196. package/dist/workspace/drift-cli.js +5 -12
  197. package/dist/workspace/forge-work.d.ts +3 -2
  198. package/dist/workspace/forge-work.d.ts.map +1 -1
  199. package/dist/workspace/forge-work.js +7 -17
  200. package/dist/workspace/lexicon-outputs.js +2 -2
  201. package/dist/workspace/release-workflow.d.ts +26 -3
  202. package/dist/workspace/release-workflow.d.ts.map +1 -1
  203. package/dist/workspace/release-workflow.js +48 -6
  204. package/dist/workspace/trust/check-evidence-report.d.ts +18 -0
  205. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  206. package/dist/workspace/trust/check-evidence-report.js +13 -0
  207. package/dist/workspace/trust/check-evidence.d.ts +13 -1
  208. package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
  209. package/dist/workspace/trust/check-evidence.js +8 -3
  210. package/dist/workspace/trust/evidence.d.ts +5 -0
  211. package/dist/workspace/trust/evidence.d.ts.map +1 -1
  212. package/dist/workspace/trust/evidence.js +5 -0
  213. package/dist/workspace/trust/open-evidence.d.ts +67 -0
  214. package/dist/workspace/trust/open-evidence.d.ts.map +1 -0
  215. package/dist/workspace/trust/open-evidence.js +92 -0
  216. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
  217. package/dist/workspace/trust/ref-gate-cli.js +65 -3
  218. package/dist/workspace/trust/ref-gate.d.ts +61 -2
  219. package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
  220. package/dist/workspace/trust/ref-gate.js +72 -7
  221. package/package.json +1 -1
  222. package/src/action-pins.ts +2 -0
  223. package/src/actor.test.ts +12 -0
  224. package/src/actor.ts +19 -0
  225. package/src/bundle-check.test.ts +22 -0
  226. package/src/bundle-check.ts +33 -5
  227. package/src/chant-install.test.ts +109 -1
  228. package/src/chant-install.ts +243 -2
  229. package/src/ci-commit.test.ts +51 -5
  230. package/src/ci-commit.ts +1 -2
  231. package/src/ci-control.ts +1 -0
  232. package/src/ci-evidence-claims.ts +102 -0
  233. package/src/ci-evidence-from-job.test.ts +147 -0
  234. package/src/ci-evidence-from-job.ts +195 -0
  235. package/src/ci-evidence-jobs.ts +41 -4
  236. package/src/ci-handover.ts +16 -3
  237. package/src/ci-identity.test.ts +3 -3
  238. package/src/ci-identity.ts +51 -11
  239. package/src/ci-image.test.ts +60 -10
  240. package/src/ci-image.ts +78 -19
  241. package/src/ci-jobs.ts +7 -2
  242. package/src/ci-login.test.ts +131 -3
  243. package/src/ci-login.token-drop.test.ts +204 -0
  244. package/src/ci-login.ts +137 -39
  245. package/src/ci-product-words.ts +30 -0
  246. package/src/ci-product.ts +26 -1
  247. package/src/cli/commands/__fixtures__/source-dir-root/migrations/0001-init/backfill.ts +3 -0
  248. package/src/cli/handlers/approve-confirm.test.ts +35 -0
  249. package/src/cli/handlers/approve-confirm.ts +44 -0
  250. package/src/cli/handlers/build-source-dir.test.ts +4 -0
  251. package/src/cli/handlers/build.ts +20 -2
  252. package/src/cli/handlers/ci-check.ts +19 -1
  253. package/src/cli/handlers/ci-evidence-open.test.ts +164 -0
  254. package/src/cli/handlers/ci-evidence.ts +210 -16
  255. package/src/cli/handlers/ci-forge-check.ts +22 -9
  256. package/src/cli/handlers/generated-check.ts +39 -0
  257. package/src/cli/handlers/lifecycle.test.ts +20 -0
  258. package/src/cli/handlers/lifecycle.ts +4 -0
  259. package/src/cli/handlers/local-chant.ts +39 -1
  260. package/src/cli/handlers/pr.ts +43 -5
  261. package/src/cli/handlers/run-wave.ts +7 -0
  262. package/src/cli/main.ts +38 -4
  263. package/src/cli/parse-args.ts +46 -0
  264. package/src/cli/registry.ts +24 -0
  265. package/src/components/check-hooks.ts +22 -0
  266. package/src/components/check-report-summary.test.ts +78 -0
  267. package/src/components/pr-checks.ts +159 -0
  268. package/src/components/pr-pipeline.ts +41 -1
  269. package/src/components/product-pipeline.ts +25 -3
  270. package/src/components/product-plan.test.ts +102 -1
  271. package/src/components/product-plan.ts +416 -15
  272. package/src/config.ts +13 -8
  273. package/src/control/consumers.ts +7 -0
  274. package/src/dead-guards.test.ts +27 -5
  275. package/src/dead-guards.ts +9 -6
  276. package/src/discovery/files.ts +1 -1
  277. package/src/drift-issue.test.ts +29 -1
  278. package/src/drift-issue.ts +28 -3
  279. package/src/drift-record.test.ts +25 -0
  280. package/src/drift-record.ts +55 -6
  281. package/src/floor-table.data.ts +58 -21
  282. package/src/floor-table.ts +12 -9
  283. package/src/forge-check/contract.ts +11 -1
  284. package/src/forge-check/forge-check.test.ts +8 -0
  285. package/src/forge-check/index.ts +2 -0
  286. package/src/forge-flags.test.ts +25 -1
  287. package/src/forge-flags.ts +34 -0
  288. package/src/forge-remote.test.ts +37 -0
  289. package/src/forge-remote.ts +79 -0
  290. package/src/generated-check.e2e.test.ts +98 -0
  291. package/src/generated-check.test.ts +104 -0
  292. package/src/generated-check.ts +269 -0
  293. package/src/lexicon.ts +17 -0
  294. package/src/lifecycle/publish-npm.ts +56 -3
  295. package/src/lifecycle/release-catalog.test.ts +2 -2
  296. package/src/lifecycle/release-images-dockerfile.test.ts +20 -0
  297. package/src/lifecycle/release-images.test.ts +44 -0
  298. package/src/lifecycle/release-images.ts +39 -3
  299. package/src/lifecycle/release-ledger.ts +4 -3
  300. package/src/local-chant.e2e.test.ts +81 -6
  301. package/src/local-chant.test.ts +22 -3
  302. package/src/local-chant.ts +130 -13
  303. package/src/op/op-waves-evidence-jobs.ts +134 -0
  304. package/src/op/op-waves-evidence.test.ts +36 -3
  305. package/src/op/op-waves-evidence.ts +23 -3
  306. package/src/op/op-waves-run.ts +57 -2
  307. package/src/op/op-waves.ts +11 -0
  308. package/src/op/schedule-overdue.test.ts +83 -1
  309. package/src/op/schedule-overdue.ts +107 -9
  310. package/src/pr-forge-reads-compare.test.ts +2 -1
  311. package/src/pr-forge-reads.ts +37 -1
  312. package/src/pr-forge.ts +14 -3
  313. package/src/pr-plan-note.ts +32 -3
  314. package/src/pr-plan-record.test.ts +75 -0
  315. package/src/pr-plan-record.ts +101 -0
  316. package/src/pr-post-plan-note.test.ts +60 -0
  317. package/src/pr-post.test.ts +30 -0
  318. package/src/pr-post.ts +110 -6
  319. package/src/pr-requires.test.ts +20 -0
  320. package/src/pr-requires.ts +10 -1
  321. package/src/ref-gate-init.ts +189 -0
  322. package/src/ref-gate-rules.ts +26 -0
  323. package/src/release-floors.ts +86 -17
  324. package/src/state-migration-record.test.ts +90 -0
  325. package/src/state-migration.test.ts +1 -1
  326. package/src/state-migration.ts +52 -3
  327. package/src/state-unlock.test.ts +33 -1
  328. package/src/state-unlock.ts +49 -1
  329. package/src/workspace/ci-green-cli.ts +12 -6
  330. package/src/workspace/drift-cli.ts +6 -18
  331. package/src/workspace/forge-work.ts +7 -14
  332. package/src/workspace/lexicon-outputs.ts +2 -2
  333. package/src/workspace/release-workflow.test.ts +70 -0
  334. package/src/workspace/release-workflow.ts +56 -8
  335. package/src/workspace/trust/check-evidence-report.ts +24 -0
  336. package/src/workspace/trust/check-evidence.ts +17 -5
  337. package/src/workspace/trust/evidence.ts +5 -0
  338. package/src/workspace/trust/open-evidence.ts +129 -0
  339. package/src/workspace/trust/ref-gate-cli.ts +59 -3
  340. package/src/workspace/trust/ref-gate-pieces.test.ts +175 -0
  341. package/src/workspace/trust/ref-gate.e2e.test.ts +17 -0
  342. package/src/workspace/trust/ref-gate.ts +87 -6
@@ -4,11 +4,30 @@
4
4
  * runs with, and plywood's resolve fallback for a repository with no chant.
5
5
  */
6
6
 
7
+ import { spawnSync } from "node:child_process";
7
8
  import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
8
9
  import { tmpdir } from "node:os";
9
10
  import { delimiter, join } from "node:path";
11
+ import { pathToFileURL } from "node:url";
10
12
  import { afterAll, describe, expect, test } from "vitest";
11
- import { bundledChant, CHANT_SPECIFIER, chantArgv, chantCommand, chantEnv, chantResolveFallback, installedChant } from "./chant-install";
13
+ import {
14
+ bareResolveFallback,
15
+ bundledChant,
16
+ CHANT_RUN_FLOOR,
17
+ CHANT_SPECIFIER,
18
+ chantArgv,
19
+ chantCommand,
20
+ chantEnv,
21
+ chantResolveFallback,
22
+ fallbackImportArgs,
23
+ fallbackParent,
24
+ hasNodeModulesAbove,
25
+ installedChant,
26
+ isBareSpecifier,
27
+ lastJsonLine,
28
+ runChant,
29
+ } from "./chant-install";
30
+ import { NEXT_RELEASE } from "./release-floors";
12
31
 
13
32
  const scratch = mkdtempSync(join(tmpdir(), "chant-install-"));
14
33
  afterAll(() => rmSync(scratch, { recursive: true, force: true }));
@@ -110,3 +129,92 @@ describe("chantResolveFallback", () => {
110
129
  expect(() => hook("@intentius/chant", { parentURL: from }, fail(missing))).toThrow("not found");
111
130
  });
112
131
  });
132
+
133
+ /** #4889: a file with no node_modules above it, outside every checkout and install. */
134
+ describe("the resolve fallback for any bare specifier (#4889)", () => {
135
+ const worktree = join(import.meta.dirname, "..", "..", "..");
136
+ const parent = pathToFileURL(join(worktree, "chant-resolve-fallback.js")).href;
137
+ const missing = Object.assign(new Error("not found"), { code: "ERR_MODULE_NOT_FOUND" });
138
+ const bare = join(scratch, "worktree");
139
+ mkdirSync(join(bare, "src"), { recursive: true });
140
+ const importer = pathToFileURL(join(bare, "src", "chant.config.ts")).href;
141
+
142
+ test("a bare specifier is a package name, nothing else", () => {
143
+ for (const s of ["semver", "@intentius/sql-yodeler", "@intentius/chant/op"]) expect(isBareSpecifier(s), s).toBe(true);
144
+ for (const s of ["./a.js", "../a.js", "/abs/a.js", "file:///a.js", "node:fs", "data:text/javascript,", "#internal"]) expect(isBareSpecifier(s), s).toBe(false);
145
+ });
146
+
147
+ test("the scratch worktree has no node_modules above it, and this file does", () => {
148
+ expect(hasNodeModulesAbove(importer)).toBe(false);
149
+ expect(hasNodeModulesAbove(pathToFileURL(import.meta.filename).href)).toBe(true);
150
+ expect(hasNodeModulesAbove("node:fs")).toBe(true);
151
+ });
152
+
153
+ test("fallbackParent is a file beside the node_modules holding chant, or chant's own file in a checkout", () => {
154
+ expect(fallbackParent("file:///opt/yodel/node_modules/@intentius/chant/dist/chant-install.js")).toBe("file:///opt/yodel/chant-resolve-fallback.js");
155
+ expect(fallbackParent("file:///src/chant/packages/core/src/chant-install.ts")).toBe("file:///src/chant/packages/core/src/chant-install.ts");
156
+ });
157
+
158
+ test("retries a bare import of a file with no install from the product's, and leaves the rest as Node reports them", () => {
159
+ const hook = bareResolveFallback(parent);
160
+ const seen: unknown[] = [];
161
+ const next = (specifier: string, context?: Record<string, unknown>) => {
162
+ seen.push(context?.parentURL);
163
+ if (context?.parentURL !== parent) throw missing;
164
+ return { url: `file:///product/node_modules/${specifier}/index.js` };
165
+ };
166
+ expect(hook("@intentius/sql-yodeler", { parentURL: importer }, next).url).toBe("file:///product/node_modules/@intentius/sql-yodeler/index.js");
167
+ expect(seen).toEqual([importer, parent]);
168
+ const fail = (e: Error) => () => {
169
+ throw e;
170
+ };
171
+ expect(() => hook("./local.js", { parentURL: importer }, fail(missing))).toThrow("not found");
172
+ expect(() => hook("left-pad", { parentURL: pathToFileURL(import.meta.filename).href }, fail(missing))).toThrow("not found");
173
+ expect(() => hook("left-pad", { parentURL: importer }, fail(new Error("syntax")))).toThrow("syntax");
174
+ });
175
+
176
+ test("fallbackImportArgs lets a child import a package from the product's install", () => {
177
+ const file = join(bare, "src", "uses-semver.mjs");
178
+ writeFileSync(file, 'import semver from "semver";\nconsole.log(semver.valid("1.2.3"));\n');
179
+ const without = spawnSync(process.execPath, [file], { encoding: "utf8" });
180
+ expect(without.status).not.toBe(0);
181
+ expect(without.stderr).toMatch(/Cannot find package 'semver'/);
182
+ const withIt = spawnSync(process.execPath, [...fallbackImportArgs(parent), file], { encoding: "utf8" });
183
+ expect(withIt.stderr).toBe("");
184
+ expect(withIt.stdout.trim()).toBe("1.2.3");
185
+ });
186
+ });
187
+
188
+ describe("runChant (#4889)", () => {
189
+ test("lastJsonLine is the last line that is a JSON object, or a pretty-printed document", () => {
190
+ expect(lastJsonLine('fold: 1 file folded\n{"a":1}\n{not json\n')).toEqual({ a: 1 });
191
+ expect(lastJsonLine('{"a":1}\nlog\n{"b":2}\n')).toEqual({ b: 2 });
192
+ expect(lastJsonLine('{\n "a": 2\n}\n')).toEqual({ a: 2 });
193
+ expect(lastJsonLine("no json here")).toBeUndefined();
194
+ });
195
+
196
+ test("runs the install's bin with this node, the fallback's --import and chant's bin first on PATH, and reads its --json document", async () => {
197
+ const root = pkg(join(scratch, "run", "node_modules", "@intentius", "chant"), { name: "@intentius/chant", version: "9.9.9", bin: { chant: "./bin/chant" } }, "bin/chant");
198
+ writeFileSync(
199
+ join(root, "bin", "chant"),
200
+ 'console.error("chant: working");\nconsole.log("a log line");\nconsole.log(JSON.stringify({ args: process.argv.slice(2), imports: process.execArgv.filter((a) => a.startsWith("data:")).length, path: process.env.PATH.split(require("path").delimiter)[0], color: process.env.NO_COLOR ?? null }));\nprocess.exit(3);\n',
201
+ );
202
+ const install = installedChant([join(scratch, "run")])!;
203
+ const chunks: string[] = [];
204
+ const ran = await runChant(["build", "--json"], { install, cwd: scratch, resolveFallback: true, noColor: true, onStderr: (t) => chunks.push(t) });
205
+ expect(ran.code).toBe(3);
206
+ expect(ran.stdout).toMatch(/^a log line\n/);
207
+ expect(ran.json).toEqual({ args: ["build", "--json"], imports: 1, path: install.binDir, color: "1" });
208
+ expect(chunks.join("")).toBe("chant: working\n");
209
+ });
210
+
211
+ test("a named chant runs as it is, and a child that cannot start rejects", async () => {
212
+ const ran = await runChant(["-e", "console.log(JSON.stringify({ ok: true }))"], { chant: process.execPath });
213
+ expect(ran).toMatchObject({ code: 0, json: { ok: true } });
214
+ await expect(runChant([], { chant: join(scratch, "no-such-chant") })).rejects.toThrow(/ENOENT/);
215
+ });
216
+
217
+ test("CHANT_RUN_FLOOR is the next release", () => {
218
+ expect(CHANT_RUN_FLOOR).toBe(NEXT_RELEASE);
219
+ });
220
+ });
@@ -18,12 +18,25 @@
18
18
  * {@link chantArgv} runs the package's `bin/chant` with the node running
19
19
  * now: the bin picks the compiled CLI in an installed package and the source
20
20
  * in a checkout (#3878), so a product never chooses between them.
21
+ *
22
+ * #4889: {@link runChant} spawns that chant and returns its output and its
23
+ * last `--json` document ({@link lastJsonLine}), and
24
+ * {@link installResolveFallback} and {@link fallbackImportArgs} resolve any
25
+ * bare specifier a file with no `node_modules` above it imports, in the
26
+ * product's process and in chant's children, from the product's install
27
+ * (SQL Yodeler's `resolve-fallback.ts` and `process.ts`, terragucci's
28
+ * `runChant` in `resume.ts`).
21
29
  */
22
30
 
31
+ import { spawn } from "node:child_process";
23
32
  import { existsSync, readFileSync } from "node:fs";
24
33
  import * as nodeModule from "node:module";
25
- import { delimiter, dirname, join, resolve } from "node:path";
26
- import { fileURLToPath } from "node:url";
34
+ import { delimiter, dirname, join, resolve, sep } from "node:path";
35
+ import { fileURLToPath, pathToFileURL } from "node:url";
36
+ import { NEXT_RELEASE } from "./release-floors";
37
+
38
+ /** The first chant with `runChant`, `lastJsonLine`, `installResolveFallback` and `fallbackImportArgs` in `@intentius/chant/chant-install` (#4889): a product runs chant and reads its `--json` document, and a file with no `node_modules` above it imports the product's packages, with no code of the product's own. */
39
+ export const CHANT_RUN_FLOOR = NEXT_RELEASE;
27
40
 
28
41
  /** Where a chant package is installed. */
29
42
  export interface ChantInstall {
@@ -177,3 +190,231 @@ export function installChantResolveFallback(from: string = import.meta.url): boo
177
190
  flags[FALLBACK] = true;
178
191
  return true;
179
192
  }
193
+
194
+ // ── #4889: any bare specifier, for a file with no node_modules above it ────
195
+
196
+ /** A bare specifier: a package name, not a relative or absolute path, a URL, a `node:` builtin or a `#` import. */
197
+ export function isBareSpecifier(specifier: string): boolean {
198
+ return !/^(\.{0,2}\/|[a-zA-Z][a-zA-Z0-9+.-]*:)/.test(specifier) && !specifier.startsWith("#");
199
+ }
200
+
201
+ /** Whether the file at `url` has a `node_modules` directory in its own directory or any above it. A URL that is not a file's counts as having one. */
202
+ export function hasNodeModulesAbove(url: unknown): boolean {
203
+ if (typeof url !== "string" || !url.startsWith("file:")) return true;
204
+ for (let dir = dirname(fileURLToPath(url)); ; ) {
205
+ if (existsSync(join(dir, "node_modules"))) return true;
206
+ const up = dirname(dir);
207
+ if (up === dir) return false;
208
+ dir = up;
209
+ }
210
+ }
211
+
212
+ /**
213
+ * The file URL a bare specifier is retried from: a file beside the
214
+ * `node_modules` directory that holds `from` (by default this module, in
215
+ * the chant the product depends on), so the retry finds the product's own
216
+ * packages first; `from` itself when it is in no `node_modules`, as in a
217
+ * chant checkout. SQL Yodeler's `ownModules`.
218
+ */
219
+ export function fallbackParent(from: string = import.meta.url): string {
220
+ const path = from.startsWith("file:") ? fileURLToPath(from) : from;
221
+ const marker = `${sep}node_modules${sep}`;
222
+ const at = path.lastIndexOf(marker);
223
+ if (at < 0) return from.startsWith("file:") ? from : pathToFileURL(from).href;
224
+ return pathToFileURL(join(path.slice(0, at), "chant-resolve-fallback.js")).href;
225
+ }
226
+
227
+ /**
228
+ * A resolve hook (SQL Yodeler's `resolve-fallback.ts`): a bare specifier
229
+ * Node could not find, imported by a file with no `node_modules` in its
230
+ * directory or any above it, resolves from `parent`. chant's commit job
231
+ * runs a product's command in a git worktree outside the checkout the job
232
+ * installed, so a `chant.config.ts` or an Op there imports chant, its
233
+ * lexicons and the product by name and finds none of them. A file that has
234
+ * an install of its own, and any other failure, is left as Node reports it.
235
+ */
236
+ export function bareResolveFallback(parent: string) {
237
+ return (specifier: string, context: Record<string, unknown>, next: NextResolve): ResolveResult => {
238
+ try {
239
+ return next(specifier, context);
240
+ } catch (err) {
241
+ const code = (err as { code?: unknown }).code;
242
+ if (code !== "ERR_MODULE_NOT_FOUND" && code !== "MODULE_NOT_FOUND") throw err;
243
+ if (!isBareSpecifier(specifier) || context.parentURL === parent || hasNodeModulesAbove(context.parentURL)) throw err;
244
+ return next(specifier, { ...context, parentURL: parent });
245
+ }
246
+ };
247
+ }
248
+
249
+ /**
250
+ * {@link bareResolveFallback} as module source for a child's `--import`,
251
+ * with `PARENT` bound: the same checks, written for Node's synchronous
252
+ * `registerHooks` and, on a Node without it, the asynchronous `register`,
253
+ * whose `next` returns a promise.
254
+ */
255
+ function hooksSource(parent: string): string {
256
+ return [
257
+ 'import { existsSync } from "node:fs";',
258
+ 'import { dirname, join } from "node:path";',
259
+ 'import { fileURLToPath } from "node:url";',
260
+ `const PARENT = ${JSON.stringify(parent)};`,
261
+ 'const bare = (s) => !/^(\\.{0,2}\\/|[a-zA-Z][a-zA-Z0-9+.-]*:)/.test(s) && !s.startsWith("#");',
262
+ "function installed(url) {",
263
+ ' if (typeof url !== "string" || !url.startsWith("file:")) return true;',
264
+ " for (let d = dirname(fileURLToPath(url)); ; ) {",
265
+ ' if (existsSync(join(d, "node_modules"))) return true;',
266
+ " const up = dirname(d);",
267
+ " if (up === d) return false;",
268
+ " d = up;",
269
+ " }",
270
+ "}",
271
+ "function retry(specifier, context, next, e) {",
272
+ ' if (!e || (e.code !== "ERR_MODULE_NOT_FOUND" && e.code !== "MODULE_NOT_FOUND") || !bare(specifier) || context.parentURL === PARENT || installed(context.parentURL)) throw e;',
273
+ " return next(specifier, { ...context, parentURL: PARENT });",
274
+ "}",
275
+ "export function resolve(specifier, context, next) {",
276
+ " let r;",
277
+ " try { r = next(specifier, context); } catch (e) { return retry(specifier, context, next, e); }",
278
+ ' return r && typeof r.then === "function" ? r.catch((e) => retry(specifier, context, next, e)) : r;',
279
+ "}",
280
+ ].join("\n");
281
+ }
282
+
283
+ const dataUrl = (source: string): string => `data:text/javascript,${encodeURIComponent(source)}`;
284
+
285
+ const BARE_FALLBACK = Symbol.for("chant.bareResolveFallback");
286
+
287
+ /**
288
+ * Install {@link bareResolveFallback} once in this process, retrying from
289
+ * `parent` (default {@link fallbackParent}). A product's bin calls it before
290
+ * it loads a repository's `chant.config.ts` or Ops. Uses Node's
291
+ * `module.registerHooks` where it has one, else `module.register`. Returns
292
+ * whether it is installed: false on a Node with neither.
293
+ */
294
+ export function installResolveFallback(parent: string = fallbackParent()): boolean {
295
+ const flags = globalThis as { [BARE_FALLBACK]?: boolean };
296
+ if (flags[BARE_FALLBACK]) return true;
297
+ const m = nodeModule as unknown as { registerHooks?: RegisterHooks; register?: (url: string) => unknown };
298
+ if (typeof m.registerHooks === "function") m.registerHooks({ resolve: bareResolveFallback(parent) });
299
+ else if (typeof m.register === "function") m.register(dataUrl(hooksSource(parent)));
300
+ else return false;
301
+ flags[BARE_FALLBACK] = true;
302
+ return true;
303
+ }
304
+
305
+ /**
306
+ * The node arguments that install {@link bareResolveFallback} in a chant
307
+ * child (`chant build`, `chant run`), before its own imports of the
308
+ * repository's files: one `--import` of a `data:` module, so it loads the
309
+ * same from a product's `src/` under tsx and from its bundle. Pass them as
310
+ * {@link chantArgv}'s `nodeArgs`, or {@link runChant}'s `resolveFallback`.
311
+ */
312
+ export function fallbackImportArgs(parent: string = fallbackParent()): string[] {
313
+ const hooks = dataUrl(hooksSource(parent));
314
+ const registrar = [
315
+ 'import * as m from "node:module";',
316
+ `import { resolve } from ${JSON.stringify(hooks)};`,
317
+ `if (typeof m.registerHooks === "function") m.registerHooks({ resolve }); else m.register(${JSON.stringify(hooks)});`,
318
+ ].join("\n");
319
+ return ["--import", dataUrl(registrar)];
320
+ }
321
+
322
+ // ── #4889: running chant and reading its --json document ──────────────────
323
+
324
+ /** What {@link runChant} returns once the child exits. */
325
+ export interface ChantRun {
326
+ /** The exit code; 128 when a signal ended it. */
327
+ code: number;
328
+ stdout: string;
329
+ stderr: string;
330
+ /** {@link lastJsonLine} of `stdout`: the `--json` document, when the command printed one. */
331
+ json?: unknown;
332
+ }
333
+
334
+ export interface RunChantOptions {
335
+ /** The directory chant runs in. Default the current one. */
336
+ cwd?: string;
337
+ /** The environment the child starts from, before {@link chantEnv}. Default `process.env`. */
338
+ env?: NodeJS.ProcessEnv;
339
+ /**
340
+ * A chant executable to run as it is (a product's `--chant` flag): no
341
+ * node in front of it, so `nodeArgs` and `resolveFallback` do not apply.
342
+ */
343
+ chant?: string;
344
+ /** The install to run. Default {@link bundledChant}, else the first of `from` that {@link installedChant} finds, else `chant` on PATH. */
345
+ install?: ChantInstall;
346
+ /** Directories to look for an install from when this module is in none (terragucci looks from the repository). */
347
+ from?: readonly string[];
348
+ /** Node arguments before the bin, such as a product's own `--import`. */
349
+ nodeArgs?: readonly string[];
350
+ /** Install {@link bareResolveFallback} in the child (`true` from {@link fallbackParent}, or a parent URL). */
351
+ resolveFallback?: boolean | string;
352
+ /** `FORCE_COLOR=0` and `NO_COLOR=1`, for output a product reads. */
353
+ noColor?: boolean;
354
+ /** `inherit` writes the child's output to this process's and captures none. Default `pipe`. */
355
+ stdio?: "pipe" | "inherit";
356
+ /** Each chunk as it arrives, for output a person watches. */
357
+ onStdout?: (text: string) => void;
358
+ onStderr?: (text: string) => void;
359
+ }
360
+
361
+ /**
362
+ * Run `chant <args>` and resolve with its exit code, its output and its
363
+ * `--json` document (#4889; SQL Yodeler's `runChant`, terragucci's in
364
+ * `resume.ts`). The chant is the product's own ({@link chantArgv}) with its
365
+ * bin first on PATH ({@link chantEnv}). Never rejects on a non-zero exit;
366
+ * rejects when the child cannot start.
367
+ */
368
+ export function runChant(args: readonly string[], options: RunChantOptions = {}): Promise<ChantRun> {
369
+ const install = options.chant === undefined ? (options.install ?? bundledChant() ?? installedChant(options.from ?? [])) : undefined;
370
+ const fallback = options.resolveFallback === true ? fallbackImportArgs() : typeof options.resolveFallback === "string" ? fallbackImportArgs(options.resolveFallback) : [];
371
+ const [command, ...argv] = install ? chantArgv(args, { install, nodeArgs: [...fallback, ...(options.nodeArgs ?? [])] }) : [options.chant ?? "chant", ...args];
372
+ const env = { ...chantEnv(options.env ?? process.env, install), ...(options.noColor ? { FORCE_COLOR: "0", NO_COLOR: "1" } : {}) };
373
+ const piped = options.stdio !== "inherit";
374
+ return new Promise((done, reject) => {
375
+ const child = spawn(command!, argv, { cwd: options.cwd ?? process.cwd(), env, stdio: ["ignore", piped ? "pipe" : "inherit", piped ? "pipe" : "inherit"] });
376
+ let stdout = "";
377
+ let stderr = "";
378
+ child.stdout?.setEncoding("utf8");
379
+ child.stderr?.setEncoding("utf8");
380
+ child.stdout?.on("data", (chunk: string) => {
381
+ stdout += chunk;
382
+ options.onStdout?.(chunk);
383
+ });
384
+ child.stderr?.on("data", (chunk: string) => {
385
+ stderr += chunk;
386
+ options.onStderr?.(chunk);
387
+ });
388
+ child.on("error", reject);
389
+ child.on("close", (code, signal) => {
390
+ const json = lastJsonLine(stdout);
391
+ done({ code: code ?? (signal ? 128 : 1), stdout, stderr, ...(json !== undefined ? { json } : {}) });
392
+ });
393
+ });
394
+ }
395
+
396
+ /**
397
+ * The last line of `stdout` that parses as a JSON object: chant prints its
398
+ * `--json` document as one line, after any log lines. A pretty-printed
399
+ * document is read from the first `{` to the end. Undefined when there is
400
+ * none.
401
+ */
402
+ export function lastJsonLine(stdout: string): unknown {
403
+ const lines = stdout.split("\n").map((l) => l.trim()).filter((l) => l.startsWith("{"));
404
+ for (const line of lines.reverse()) {
405
+ try {
406
+ return JSON.parse(line) as unknown;
407
+ } catch {
408
+ // A log line that starts with "{"; keep looking.
409
+ }
410
+ }
411
+ const at = stdout.indexOf("{");
412
+ if (at >= 0) {
413
+ try {
414
+ return JSON.parse(stdout.slice(at)) as unknown;
415
+ } catch {
416
+ // Not JSON.
417
+ }
418
+ }
419
+ return undefined;
420
+ }
@@ -35,7 +35,8 @@ import {
35
35
  type CommitSettings,
36
36
  type OpCommitSpec,
37
37
  } from "./ci-commit";
38
- import { assertProductWords, parseProductComment } from "./ci-product-words";
38
+ import { COMMENT_LEAVES_COMMIT_FLOOR } from "./ci-product";
39
+ import { assertProductWords, commitWordOf, parseProductComment } from "./ci-product-words";
39
40
  import { PLYWOOD } from "./__fixtures__/product-words";
40
41
  import { NEXT_RELEASE } from "./release-floors";
41
42
  import type { OpRunRecord, OpRunRecordInput } from "./op/runtime";
@@ -574,7 +575,7 @@ describe("the comment's argument (#4820)", () => {
574
575
  expect(refused.result).toBe("refused");
575
576
  });
576
577
 
577
- test("the floor is the next release until it ships", () => {
578
+ test("the floor is the release that shipped it", () => {
578
579
  expect(CI_COMMIT_ARG_FLOOR).toBe("0.124.78");
579
580
  });
580
581
  });
@@ -617,8 +618,53 @@ describe("a comment refused as it is read gets a reply (#4838)", () => {
617
618
  expect(long.replies[0]).toMatch(new RegExp(`^plywood: \`/plywood fmt x{84}\\.\\.\\.\` was refused`));
618
619
  });
619
620
 
620
- test("the floor is the next release until it ships", () => {
621
- expect(CI_COMMIT_REFUSAL_REPLY_FLOOR).toBe(NEXT_RELEASE);
621
+ test("the floor is the release that shipped it", () => {
622
+ expect(CI_COMMIT_REFUSAL_REPLY_FLOOR).toBe("0.124.86");
623
+ });
624
+ });
625
+
626
+ describe("a comment job leaves the commit job's words to it, so a comment gets one reply (#4890)", () => {
627
+ const named = () => settings({ commentArg: { pattern: "^[a-z0-9]+(?:[-_][a-z0-9]+)*$", position: 1 } });
628
+ /** What a comment job that is not the commit job makes of the comment: a refusal is a reply. */
629
+ const commentJob = (body: string, leaveCommit: boolean) => parseProductComment(words, body, {}, {}, { leaveCommit });
630
+
631
+ test("a malformed comment for a commit word is answered by the commit job alone", async () => {
632
+ for (const [s, body] of [
633
+ [settings(), "/plywood fmt now"],
634
+ [named(), "/plywood fmt Bad"],
635
+ [settings(), "/plywood fmt\nand more"],
636
+ [settings(), "/plywood\tfmt now"],
637
+ ] as const) {
638
+ const w = world();
639
+ await cycle(w, s, { event: comment(body) });
640
+ expect(w.replies, body).toHaveLength(1);
641
+ // Without leaveCommit the comment job refused it too: the second reply #4890 is about.
642
+ expect(commentJob(body, false), body).toMatchObject({ kind: "refused" });
643
+ expect(commentJob(body, true), body).toBeUndefined();
644
+ expect(commitWordOf(words, body), body).toBe("fmt");
645
+ }
646
+ });
647
+
648
+ test("a well-formed commit comment is the commit job's too, and every other comment is still the comment job's", () => {
649
+ expect(commentJob("/plywood fmt", true)).toBeUndefined();
650
+ expect(commentJob("/plywood up now", true)).toMatchObject({ kind: "refused" });
651
+ expect(commentJob("/plywood up", true)).toEqual({ kind: "apply" });
652
+ expect(commentJob("/plywood fmtx", true)).toMatchObject({ kind: "refused", reason: expect.stringMatching(/the commands are/) });
653
+ expect(commentJob("/plywood", true)).toMatchObject({ kind: "refused" });
654
+ expect(commentJob("/plywoodfmt", true)).toBeUndefined();
655
+ expect(commitWordOf(words, "/plywood up")).toBeUndefined();
656
+ expect(commitWordOf(words, "/plywood constructor")).toBeUndefined();
657
+ expect(commitWordOf(words, 7)).toBeUndefined();
658
+ });
659
+
660
+ test("an alias for a commit word is left to the commit job", () => {
661
+ const aliased = assertProductWords({ ...PLYWOOD, commands: { ...PLYWOOD.commands, fmt: "commit" as const }, aliases: [{ from: "pw fmt", command: "commit" as const }] });
662
+ expect(parseProductComment(aliased, "pw fmt")).toEqual({ kind: "commit", word: "fmt" });
663
+ expect(parseProductComment(aliased, "pw fmt", {}, {}, { leaveCommit: true })).toBeUndefined();
664
+ });
665
+
666
+ test("the floor is the next release", () => {
667
+ expect(COMMENT_LEAVES_COMMIT_FLOOR).toBe(NEXT_RELEASE);
622
668
  });
623
669
  });
624
670
 
@@ -685,7 +731,7 @@ describe("the harness's BREAK switch for land (#4836)", () => {
685
731
  expect(out).toMatchObject({ result: "refused", reason: "the base moved" });
686
732
  });
687
733
 
688
- test("the floor is the next release until it ships", () => {
734
+ test("the floor is the release that shipped it", () => {
689
735
  expect(CI_COMMIT_HARNESS_BREAK_FLOOR).toBe("0.124.78");
690
736
  });
691
737
  });
package/src/ci-commit.ts CHANGED
@@ -29,7 +29,6 @@ import { spawn } from "node:child_process";
29
29
  import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
30
30
  import { join } from "node:path";
31
31
  import { CHANT_EXIT } from "./exit-codes";
32
- import { NEXT_RELEASE } from "./release-floors";
33
32
  import { FORGE_TOKEN_VARS } from "./ci-handover";
34
33
  import { agentForbiddenPaths, AgentError, branchOk, errText, LOGIN, readSmall, SHA, type AgentGit } from "./ci-agent";
35
34
  import { COMMIT_COMMENT_ARG, parseProductComment, type CiProductWords } from "./ci-product-words";
@@ -55,7 +54,7 @@ export const CI_COMMIT_ARG_FLOOR = "0.124.78";
55
54
  /** The first chant whose `commit land` reads {@link COMMIT_HARNESS_BREAK_ENV} in a BREAK arm of chant's e2e harness (#4836). */
56
55
  export const CI_COMMIT_HARNESS_BREAK_FLOOR = "0.124.78";
57
56
  /** The first chant whose `commit land` replies to a comment refused as it is read, such as a bad argument or a stray word (#4838). */
58
- export const CI_COMMIT_REFUSAL_REPLY_FLOOR = NEXT_RELEASE;
57
+ export const CI_COMMIT_REFUSAL_REPLY_FLOOR = "0.124.86";
59
58
 
60
59
  /** What starts a commit run: a person's comment, or a check job's finding. */
61
60
  export type CommitTrigger = "comment" | "check";
package/src/ci-control.ts CHANGED
@@ -137,6 +137,7 @@ export {
137
137
  export {
138
138
  CONSUMERS_CONTRACT,
139
139
  CONSUMERS_FILE,
140
+ CONTROL_CONSUMERS_FLOOR,
140
141
  consumersDocument,
141
142
  joinControlConsumers,
142
143
  parseConsumersDocument,
@@ -0,0 +1,102 @@
1
+ /**
2
+ * The claim files a check's step leaves for a signer in another job (#4926),
3
+ * and the variable that names which step or job each check's pass is read
4
+ * from. No import beyond node's, so the wave runner and the generators carry
5
+ * it at no cost.
6
+ *
7
+ * A step that ran a check writes `<dir>/<check>.json` (`:` turned into `-`):
8
+ * the check's name, whether the step saw it pass, and what it said (the
9
+ * claim the statement digests). The step runs the change's code, so the file
10
+ * is data and never enough on its own: `chant ci evidence sign --from-job`
11
+ * signs a check only when the forge reports that step (on GitLab, that job)
12
+ * concluded `success` and the file says the check passed
13
+ * (./ci-evidence-from-job.ts).
14
+ */
15
+
16
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
17
+ import { join } from "node:path";
18
+
19
+ /**
20
+ * The variable a `--from-job` signing step reads its sources from: JSON,
21
+ * each check to the job (default `--from-job`'s) and the step whose
22
+ * conclusion stands for it. A check with no step is read from its job's
23
+ * own status, as on GitLab.
24
+ */
25
+ export const EVIDENCE_SOURCES_ENV = "CHANT_EVIDENCE_SOURCES";
26
+
27
+ /**
28
+ * What a generated wave command step signs itself (#4926), set by the
29
+ * generator beside the wave's evidence job: `plan` signs `plan:<wave>` and
30
+ * leaves `policy:<wave>` to the evidence job, which reads the policy step's
31
+ * result; `job` signs nothing and leaves both. Either way the step writes
32
+ * `plan:<wave>`'s claim file for that job. Unset, the step signs both as it
33
+ * did (#4870). See ./op/op-waves-evidence.ts.
34
+ */
35
+ export const WAVE_EVIDENCE_ENV = "CHANT_WAVE_EVIDENCE";
36
+
37
+ /** Where one check's pass is read from (#4926). */
38
+ export interface EvidenceSourceSpec {
39
+ /** The job's name in the run. Default: `--from-job`'s. */
40
+ job?: string;
41
+ /** The step's name in that job, as the forge lists it. Without it, the job's own result. */
42
+ step?: string;
43
+ }
44
+
45
+ /** What a check's step wrote for its signer. */
46
+ export interface CheckClaimFile {
47
+ check: string;
48
+ passed: boolean;
49
+ /** What the check said, digested into the statement's `claim`. */
50
+ claim?: string;
51
+ }
52
+
53
+ /** The file name a check's claim is kept under: `plan:dev` is `plan-dev.json`. */
54
+ export function checkClaimFileName(check: string): string {
55
+ return `${check.replace(/[^A-Za-z0-9._-]/g, "-")}.json`;
56
+ }
57
+
58
+ /** Write a check's claim file in `dir`. Returns its path. */
59
+ export function writeCheckClaimFile(dir: string, file: CheckClaimFile): string {
60
+ mkdirSync(dir, { recursive: true });
61
+ const path = join(dir, checkClaimFileName(file.check));
62
+ writeFileSync(path, JSON.stringify({ check: file.check, passed: file.passed, ...(file.claim !== undefined ? { claim: file.claim } : {}) }, null, 2) + "\n");
63
+ return path;
64
+ }
65
+
66
+ /** A check's claim file in `dir`, or why there is none that counts. Read as data: a file for another check, or of another shape, does not count. */
67
+ export function readCheckClaimFile(dir: string, check: string): CheckClaimFile | { problem: string } {
68
+ const name = checkClaimFileName(check);
69
+ let doc: unknown;
70
+ try {
71
+ doc = JSON.parse(readFileSync(join(dir, name), "utf-8"));
72
+ } catch {
73
+ return { problem: `the job left no readable ${name}` };
74
+ }
75
+ const d = doc && typeof doc === "object" ? (doc as Record<string, unknown>) : {};
76
+ if (d.check !== check || typeof d.passed !== "boolean" || (d.claim !== undefined && typeof d.claim !== "string")) return { problem: `${name} is not ${check}'s claim file` };
77
+ return { check, passed: d.passed, ...(typeof d.claim === "string" ? { claim: d.claim } : {}) };
78
+ }
79
+
80
+ /** The sources `CHANT_EVIDENCE_SOURCES` names, or why they do not read. A step name alone stands for `{ step }`. */
81
+ export function parseEvidenceSources(raw: string | undefined): { sources: Record<string, EvidenceSourceSpec> } | { problem: string } {
82
+ if (raw === undefined || raw.trim() === "") return { sources: {} };
83
+ let doc: unknown;
84
+ try {
85
+ doc = JSON.parse(raw);
86
+ } catch (err) {
87
+ return { problem: `${EVIDENCE_SOURCES_ENV} is not JSON: ${err instanceof Error ? err.message : String(err)}` };
88
+ }
89
+ if (!doc || typeof doc !== "object" || Array.isArray(doc)) return { problem: `${EVIDENCE_SOURCES_ENV} must map each check to its job and step` };
90
+ const out: Record<string, EvidenceSourceSpec> = {};
91
+ for (const [check, v] of Object.entries(doc as Record<string, unknown>)) {
92
+ if (typeof v === "string" && v !== "") out[check] = { step: v };
93
+ else if (v && typeof v === "object" && !Array.isArray(v)) {
94
+ const o = v as Record<string, unknown>;
95
+ if ((o.job !== undefined && (typeof o.job !== "string" || o.job === "")) || (o.step !== undefined && (typeof o.step !== "string" || o.step === ""))) {
96
+ return { problem: `${EVIDENCE_SOURCES_ENV}: ${check}'s job and step must be names` };
97
+ }
98
+ out[check] = { ...(typeof o.job === "string" ? { job: o.job } : {}), ...(typeof o.step === "string" ? { step: o.step } : {}) };
99
+ } else return { problem: `${EVIDENCE_SOURCES_ENV}: ${check} must name a step, or { job, step }` };
100
+ }
101
+ return { sources: out };
102
+ }