@intentius/chant 0.124.39 → 0.124.41

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 (337) hide show
  1. package/dist/__fixtures__/oidc-emulator.d.ts +49 -0
  2. package/dist/__fixtures__/oidc-emulator.d.ts.map +1 -0
  3. package/dist/__fixtures__/oidc-emulator.js +89 -0
  4. package/dist/ci-handover.d.ts +117 -0
  5. package/dist/ci-handover.d.ts.map +1 -0
  6. package/dist/ci-handover.js +217 -0
  7. package/dist/ci-identity.d.ts +190 -0
  8. package/dist/ci-identity.d.ts.map +1 -0
  9. package/dist/ci-identity.js +219 -0
  10. package/dist/cli/component-endpoint.d.ts +20 -0
  11. package/dist/cli/component-endpoint.d.ts.map +1 -0
  12. package/dist/cli/component-endpoint.js +36 -0
  13. package/dist/cli/handlers/approve.d.ts +2 -1
  14. package/dist/cli/handlers/approve.d.ts.map +1 -1
  15. package/dist/cli/handlers/approve.js +20 -6
  16. package/dist/cli/handlers/build.d.ts.map +1 -1
  17. package/dist/cli/handlers/build.js +15 -1
  18. package/dist/cli/handlers/fan-out.d.ts.map +1 -1
  19. package/dist/cli/handlers/fan-out.js +26 -4
  20. package/dist/cli/handlers/gate-resume.d.ts +3 -0
  21. package/dist/cli/handlers/gate-resume.d.ts.map +1 -1
  22. package/dist/cli/handlers/gate-resume.js +15 -2
  23. package/dist/cli/handlers/lock.d.ts +8 -0
  24. package/dist/cli/handlers/lock.d.ts.map +1 -0
  25. package/dist/cli/handlers/lock.js +197 -0
  26. package/dist/cli/handlers/pr-env.d.ts +34 -0
  27. package/dist/cli/handlers/pr-env.d.ts.map +1 -0
  28. package/dist/cli/handlers/pr-env.js +436 -0
  29. package/dist/cli/handlers/pr.d.ts +74 -0
  30. package/dist/cli/handlers/pr.d.ts.map +1 -1
  31. package/dist/cli/handlers/pr.js +514 -58
  32. package/dist/cli/handlers/promote.d.ts.map +1 -1
  33. package/dist/cli/handlers/promote.js +16 -2
  34. package/dist/cli/handlers/query.d.ts +6 -0
  35. package/dist/cli/handlers/query.d.ts.map +1 -0
  36. package/dist/cli/handlers/query.js +80 -0
  37. package/dist/cli/handlers/run.d.ts +4 -1
  38. package/dist/cli/handlers/run.d.ts.map +1 -1
  39. package/dist/cli/handlers/run.js +17 -6
  40. package/dist/cli/main.d.ts.map +1 -1
  41. package/dist/cli/main.js +41 -2
  42. package/dist/cli/parse-args.d.ts.map +1 -1
  43. package/dist/cli/parse-args.js +31 -2
  44. package/dist/cli/registry.d.ts +12 -2
  45. package/dist/cli/registry.d.ts.map +1 -1
  46. package/dist/components/auto-release.d.ts +35 -3
  47. package/dist/components/auto-release.d.ts.map +1 -1
  48. package/dist/components/auto-release.js +29 -2
  49. package/dist/components/cli-support.d.ts +2 -0
  50. package/dist/components/cli-support.d.ts.map +1 -1
  51. package/dist/components/cli-support.js +2 -0
  52. package/dist/components/deploy-units.d.ts.map +1 -1
  53. package/dist/components/deploy-units.js +5 -0
  54. package/dist/components/fan-out-run.d.ts +28 -0
  55. package/dist/components/fan-out-run.d.ts.map +1 -1
  56. package/dist/components/fan-out-run.js +27 -3
  57. package/dist/components/pr-environment.d.ts +298 -0
  58. package/dist/components/pr-environment.d.ts.map +1 -0
  59. package/dist/components/pr-environment.js +406 -0
  60. package/dist/components/pr-hooks.d.ts +66 -0
  61. package/dist/components/pr-hooks.d.ts.map +1 -0
  62. package/dist/components/pr-hooks.js +119 -0
  63. package/dist/components/pr-pipeline.d.ts +72 -2
  64. package/dist/components/pr-pipeline.d.ts.map +1 -1
  65. package/dist/components/pr-pipeline.js +96 -5
  66. package/dist/components/pr-policy.d.ts +109 -0
  67. package/dist/components/pr-policy.d.ts.map +1 -0
  68. package/dist/components/pr-policy.js +150 -0
  69. package/dist/components/pr-run.d.ts.map +1 -1
  70. package/dist/components/pr-run.js +5 -3
  71. package/dist/components/promote.d.ts.map +1 -1
  72. package/dist/components/promote.js +39 -16
  73. package/dist/gate-decision.d.ts +15 -2
  74. package/dist/gate-decision.d.ts.map +1 -1
  75. package/dist/gate-decision.js +17 -2
  76. package/dist/gate-policy.d.ts +140 -0
  77. package/dist/gate-policy.d.ts.map +1 -0
  78. package/dist/gate-policy.js +242 -0
  79. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
  80. package/dist/lifecycle/__fixtures__/publish-fakes.js +6 -1
  81. package/dist/lifecycle/gate-checkpoint.d.ts +1 -1
  82. package/dist/lifecycle/gate-checkpoint.js +1 -1
  83. package/dist/{workspace/trust → lifecycle}/gate-seal.d.ts +1 -1
  84. package/dist/lifecycle/gate-seal.d.ts.map +1 -0
  85. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  86. package/dist/lifecycle/publish-declaration.js +4 -3
  87. package/dist/lifecycle/publish-npm.d.ts +2 -2
  88. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  89. package/dist/lifecycle/publish-npm.js +31 -8
  90. package/dist/lifecycle/query.d.ts +68 -0
  91. package/dist/lifecycle/query.d.ts.map +1 -0
  92. package/dist/lifecycle/query.js +246 -0
  93. package/dist/lifecycle/release-ledger.d.ts +31 -0
  94. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  95. package/dist/lifecycle/release-ledger.js +19 -1
  96. package/dist/lifecycle/run-ledger.d.ts +13 -0
  97. package/dist/lifecycle/run-ledger.d.ts.map +1 -1
  98. package/dist/lifecycle/run-ledger.js +16 -0
  99. package/dist/lifecycle/status.d.ts +5 -1
  100. package/dist/lifecycle/status.d.ts.map +1 -1
  101. package/dist/lifecycle/status.js +10 -5
  102. package/dist/lifecycle/target-lock.d.ts +97 -0
  103. package/dist/lifecycle/target-lock.d.ts.map +1 -0
  104. package/dist/lifecycle/target-lock.js +286 -0
  105. package/dist/live-endpoint.d.ts +18 -0
  106. package/dist/live-endpoint.d.ts.map +1 -1
  107. package/dist/live-endpoint.js +27 -0
  108. package/dist/op/activities/activity-contracts.d.ts +30 -0
  109. package/dist/op/activities/activity-contracts.d.ts.map +1 -1
  110. package/dist/op/activities/activity-contracts.js +26 -0
  111. package/dist/op/activities/index.d.ts +2 -0
  112. package/dist/op/activities/index.d.ts.map +1 -1
  113. package/dist/op/activities/index.js +4 -0
  114. package/dist/op/activities/review-agent.d.ts +137 -0
  115. package/dist/op/activities/review-agent.d.ts.map +1 -0
  116. package/dist/op/activities/review-agent.js +266 -0
  117. package/dist/op/builders.d.ts +9 -0
  118. package/dist/op/builders.d.ts.map +1 -1
  119. package/dist/op/builders.js +11 -0
  120. package/dist/op/cron.d.ts +8 -0
  121. package/dist/op/cron.d.ts.map +1 -1
  122. package/dist/op/cron.js +51 -0
  123. package/dist/op/gate-approval.d.ts +20 -13
  124. package/dist/op/gate-approval.d.ts.map +1 -1
  125. package/dist/op/gate-approval.js +13 -18
  126. package/dist/op/gate-quorum.d.ts +131 -0
  127. package/dist/op/gate-quorum.d.ts.map +1 -0
  128. package/dist/op/gate-quorum.js +183 -0
  129. package/dist/op/gate-resume.d.ts +4 -2
  130. package/dist/op/gate-resume.d.ts.map +1 -1
  131. package/dist/op/gate-resume.js +5 -4
  132. package/dist/op/gate-review.js +1 -1
  133. package/dist/op/gate.d.ts +32 -4
  134. package/dist/op/gate.d.ts.map +1 -1
  135. package/dist/op/gate.js +40 -24
  136. package/dist/op/index.d.ts +6 -4
  137. package/dist/op/index.d.ts.map +1 -1
  138. package/dist/op/index.js +4 -3
  139. package/dist/op/local-executor.d.ts.map +1 -1
  140. package/dist/op/local-executor.js +9 -3
  141. package/dist/op/op-waves-run.d.ts +62 -1
  142. package/dist/op/op-waves-run.d.ts.map +1 -1
  143. package/dist/op/op-waves-run.js +190 -11
  144. package/dist/op/op-waves.d.ts +55 -3
  145. package/dist/op/op-waves.d.ts.map +1 -1
  146. package/dist/op/op-waves.js +63 -8
  147. package/dist/op/schedule-overdue.d.ts +57 -0
  148. package/dist/op/schedule-overdue.d.ts.map +1 -0
  149. package/dist/op/schedule-overdue.js +138 -0
  150. package/dist/override-gate.d.ts +2 -2
  151. package/dist/override-gate.d.ts.map +1 -1
  152. package/dist/override-gate.js +1 -1
  153. package/dist/pr-forge.d.ts +36 -0
  154. package/dist/pr-forge.d.ts.map +1 -1
  155. package/dist/pr-forge.js +82 -0
  156. package/dist/pr-loop.d.ts +90 -1
  157. package/dist/pr-loop.d.ts.map +1 -1
  158. package/dist/pr-loop.js +77 -3
  159. package/dist/pr-post.d.ts +72 -0
  160. package/dist/pr-post.d.ts.map +1 -0
  161. package/dist/pr-post.js +134 -0
  162. package/dist/wave-blocked.d.ts +79 -0
  163. package/dist/wave-blocked.d.ts.map +1 -0
  164. package/dist/wave-blocked.js +245 -0
  165. package/dist/wave-engine.d.ts +6 -0
  166. package/dist/wave-engine.d.ts.map +1 -1
  167. package/dist/wave-engine.js +2 -0
  168. package/dist/wave-runtime.mjs +239 -239
  169. package/dist/workspace/__fixtures__/two-member-workspace.d.ts +1 -0
  170. package/dist/workspace/__fixtures__/two-member-workspace.d.ts.map +1 -1
  171. package/dist/workspace/__fixtures__/two-member-workspace.js +1 -1
  172. package/dist/workspace/ci-branches.d.ts +51 -0
  173. package/dist/workspace/ci-branches.d.ts.map +1 -0
  174. package/dist/workspace/ci-branches.js +69 -0
  175. package/dist/workspace/ci-cloud-identity.d.ts +11 -0
  176. package/dist/workspace/ci-cloud-identity.d.ts.map +1 -0
  177. package/dist/workspace/ci-cloud-identity.js +24 -0
  178. package/dist/workspace/ci-locks.d.ts +12 -0
  179. package/dist/workspace/ci-locks.d.ts.map +1 -0
  180. package/dist/workspace/ci-locks.js +6 -0
  181. package/dist/workspace/ci-run.d.ts +24 -1
  182. package/dist/workspace/ci-run.d.ts.map +1 -1
  183. package/dist/workspace/ci-run.js +85 -6
  184. package/dist/workspace/declaration.d.ts +63 -0
  185. package/dist/workspace/declaration.d.ts.map +1 -1
  186. package/dist/workspace/declaration.js +72 -1
  187. package/dist/workspace/declaration.schema.json +147 -0
  188. package/dist/workspace/identity-gate-rule.d.ts +1 -1
  189. package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
  190. package/dist/workspace/identity-gate-rule.js +1 -1
  191. package/dist/workspace/identity.d.ts +1 -1
  192. package/dist/workspace/identity.d.ts.map +1 -1
  193. package/dist/workspace/lineage-upgrade.d.ts.map +1 -1
  194. package/dist/workspace/lineage-upgrade.js +8 -5
  195. package/dist/workspace/member-pipeline.d.ts +6 -0
  196. package/dist/workspace/member-pipeline.d.ts.map +1 -1
  197. package/dist/workspace/member-pipeline.js +23 -0
  198. package/dist/workspace/pr-report.schema.json +73 -2
  199. package/dist/workspace/security.d.ts.map +1 -1
  200. package/dist/workspace/security.js +4 -0
  201. package/dist/workspace/status-gates.d.ts +3 -2
  202. package/dist/workspace/status-gates.d.ts.map +1 -1
  203. package/dist/workspace/status-gates.js +8 -7
  204. package/dist/workspace/status.d.ts +3 -1
  205. package/dist/workspace/status.d.ts.map +1 -1
  206. package/dist/workspace/status.js +7 -3
  207. package/dist/workspace/status.schema.json +1 -0
  208. package/dist/workspace/trust/seal.d.ts +2 -2
  209. package/dist/workspace/trust/seal.d.ts.map +1 -1
  210. package/dist/workspace/trust/seal.js +2 -2
  211. package/package.json +1 -1
  212. package/src/__fixtures__/oidc-emulator.ts +118 -0
  213. package/src/ci-handover.test.ts +209 -0
  214. package/src/ci-handover.ts +237 -0
  215. package/src/ci-identity.test.ts +201 -0
  216. package/src/ci-identity.ts +310 -0
  217. package/src/cli/component-endpoint.ts +43 -0
  218. package/src/cli/handlers/approve.ts +18 -5
  219. package/src/cli/handlers/build.ts +15 -1
  220. package/src/cli/handlers/fan-out.test.ts +10 -0
  221. package/src/cli/handlers/fan-out.ts +29 -4
  222. package/src/cli/handlers/gate-resume.ts +16 -2
  223. package/src/cli/handlers/lock.test.ts +98 -0
  224. package/src/cli/handlers/lock.ts +202 -0
  225. package/src/cli/handlers/operator.test.ts +3 -1
  226. package/src/cli/handlers/pr-endpoint.test.ts +169 -0
  227. package/src/cli/handlers/pr-env.ts +462 -0
  228. package/src/cli/handlers/pr-waves-blocked.test.ts +247 -0
  229. package/src/cli/handlers/pr.test.ts +184 -0
  230. package/src/cli/handlers/pr.ts +508 -64
  231. package/src/cli/handlers/promote.ts +25 -2
  232. package/src/cli/handlers/query.ts +78 -0
  233. package/src/cli/handlers/run.test.ts +2 -1
  234. package/src/cli/handlers/run.ts +16 -5
  235. package/src/cli/main.ts +41 -2
  236. package/src/cli/parse-args.ts +23 -2
  237. package/src/cli/registry.ts +12 -2
  238. package/src/components/auto-release-infra.test.ts +131 -0
  239. package/src/components/auto-release.test.ts +40 -1
  240. package/src/components/auto-release.ts +50 -4
  241. package/src/components/cli-support.ts +4 -0
  242. package/src/components/deploy-units.ts +5 -0
  243. package/src/components/fan-out-run.ts +39 -2
  244. package/src/components/fan-out-waves.test.ts +45 -1
  245. package/src/components/pr-environment.test.ts +249 -0
  246. package/src/components/pr-environment.ts +538 -0
  247. package/src/components/pr-hooks.test.ts +118 -0
  248. package/src/components/pr-hooks.ts +157 -0
  249. package/src/components/pr-pipeline.ts +130 -5
  250. package/src/components/pr-policy.test.ts +145 -0
  251. package/src/components/pr-policy.ts +211 -0
  252. package/src/components/pr-run.ts +5 -2
  253. package/src/components/promote.test.ts +39 -0
  254. package/src/components/promote.ts +38 -14
  255. package/src/gate-decision-bundle.test.ts +4 -3
  256. package/src/gate-decision.ts +39 -2
  257. package/src/gate-policy-bundle.test.ts +28 -0
  258. package/src/gate-policy.test.ts +162 -0
  259. package/src/gate-policy.ts +298 -0
  260. package/src/lifecycle/__fixtures__/publish-fakes.ts +6 -1
  261. package/src/lifecycle/gate-checkpoint.ts +1 -1
  262. package/src/{workspace/trust → lifecycle}/gate-seal.ts +1 -1
  263. package/src/lifecycle/publish-declaration.ts +4 -3
  264. package/src/lifecycle/publish-npm.ts +33 -8
  265. package/src/lifecycle/publish-targets.test.ts +36 -3
  266. package/src/lifecycle/query.test.ts +91 -0
  267. package/src/lifecycle/query.ts +315 -0
  268. package/src/lifecycle/release-ledger.ts +42 -1
  269. package/src/lifecycle/run-ledger.ts +18 -0
  270. package/src/lifecycle/status.test.ts +19 -0
  271. package/src/lifecycle/status.ts +14 -6
  272. package/src/lifecycle/target-lock.test.ts +195 -0
  273. package/src/lifecycle/target-lock.ts +347 -0
  274. package/src/live-endpoint.ts +31 -0
  275. package/src/op/activities/activity-contracts.ts +31 -0
  276. package/src/op/activities/index.ts +6 -0
  277. package/src/op/activities/review-agent.test.ts +240 -0
  278. package/src/op/activities/review-agent.ts +355 -0
  279. package/src/op/builders.ts +13 -0
  280. package/src/op/cron.ts +44 -0
  281. package/src/op/gate-alias.test.ts +2 -2
  282. package/src/op/gate-approval.test.ts +30 -9
  283. package/src/op/gate-approval.ts +23 -26
  284. package/src/op/gate-quorum.test.ts +139 -0
  285. package/src/op/gate-quorum.ts +248 -0
  286. package/src/op/gate-resume.ts +6 -3
  287. package/src/op/gate-review.ts +1 -1
  288. package/src/op/gate.ts +64 -23
  289. package/src/op/index.ts +13 -1
  290. package/src/op/local-executor.ts +9 -2
  291. package/src/op/op-waves-hook-targets.test.ts +126 -0
  292. package/src/op/op-waves-policy-hold.test.ts +66 -0
  293. package/src/op/op-waves-quorum.test.ts +101 -0
  294. package/src/op/op-waves-run.ts +233 -11
  295. package/src/op/op-waves.ts +83 -10
  296. package/src/op/schedule-overdue.test.ts +220 -0
  297. package/src/op/schedule-overdue.ts +161 -0
  298. package/src/override-gate-bundle.test.ts +1 -1
  299. package/src/override-gate.ts +2 -2
  300. package/src/pr-forge-bundle.test.ts +2 -2
  301. package/src/pr-forge.test.ts +33 -0
  302. package/src/pr-forge.ts +114 -0
  303. package/src/pr-loop-bundle.test.ts +2 -2
  304. package/src/pr-loop.test.ts +58 -0
  305. package/src/pr-loop.ts +146 -4
  306. package/src/pr-post.test.ts +141 -0
  307. package/src/pr-post.ts +159 -0
  308. package/src/wave-blocked-bundle.test.ts +25 -0
  309. package/src/wave-blocked.test.ts +146 -0
  310. package/src/wave-blocked.ts +271 -0
  311. package/src/wave-engine.ts +8 -0
  312. package/src/workspace/__fixtures__/two-member-workspace.ts +2 -2
  313. package/src/workspace/ci-branches.test.ts +62 -0
  314. package/src/workspace/ci-branches.ts +79 -0
  315. package/src/workspace/ci-cloud-identity.test.ts +53 -0
  316. package/src/workspace/ci-cloud-identity.ts +23 -0
  317. package/src/workspace/ci-locks.ts +16 -0
  318. package/src/workspace/ci-run-index.test.ts +2 -1
  319. package/src/workspace/ci-run.test.ts +133 -8
  320. package/src/workspace/ci-run.ts +92 -7
  321. package/src/workspace/declaration.schema.json +147 -0
  322. package/src/workspace/declaration.test.ts +76 -0
  323. package/src/workspace/declaration.ts +134 -2
  324. package/src/workspace/identity-gate-rule.ts +1 -1
  325. package/src/workspace/identity.ts +1 -1
  326. package/src/workspace/lineage-upgrade.ts +11 -8
  327. package/src/workspace/member-pipeline.test.ts +29 -0
  328. package/src/workspace/member-pipeline.ts +30 -0
  329. package/src/workspace/pr-report.schema.json +73 -2
  330. package/src/workspace/security.ts +4 -0
  331. package/src/workspace/status-gates.ts +9 -6
  332. package/src/workspace/status.schema.json +1 -0
  333. package/src/workspace/status.ts +11 -4
  334. package/src/workspace/trust/gate-seal.test.ts +1 -1
  335. package/src/workspace/trust/seal.ts +2 -2
  336. package/dist/workspace/trust/gate-seal.d.ts.map +0 -1
  337. /package/dist/{workspace/trust → lifecycle}/gate-seal.js +0 -0
@@ -0,0 +1,98 @@
1
+ /**
2
+ * #4293: `chant lock` and `chant unlock` take, list and release target locks
3
+ * on `chant/lifecycle`, and exit 3 when another pull request holds a target.
4
+ */
5
+ import { execFileSync } from "node:child_process";
6
+ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
7
+ import { tmpdir } from "node:os";
8
+ import { join } from "node:path";
9
+ import { afterAll, afterEach, beforeEach, describe, expect, test, vi } from "vitest";
10
+ import { commandRegistry, parseArgs } from "../main";
11
+ import { resolveCommand } from "../registry";
12
+
13
+ const dirs: string[] = [];
14
+ const home = process.cwd();
15
+ afterAll(() => {
16
+ process.chdir(home);
17
+ for (const d of dirs) rmSync(d, { recursive: true, force: true });
18
+ });
19
+
20
+ function git(cwd: string, ...args: string[]): string {
21
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
22
+ }
23
+
24
+ function initRepo(): string {
25
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), "chant-lock-cli-")));
26
+ dirs.push(dir);
27
+ git(dir, "init", "-q", "-b", "main");
28
+ git(dir, "config", "user.email", "test@chant.dev");
29
+ git(dir, "config", "user.name", "Test");
30
+ git(dir, "config", "commit.gpgsign", "false");
31
+ writeFileSync(join(dir, "README.md"), "# t\n");
32
+ git(dir, "add", "README.md");
33
+ git(dir, "commit", "-q", "-m", "init");
34
+ return dir;
35
+ }
36
+
37
+ async function run(argv: string[]): Promise<{ code: number; out: string; err: string }> {
38
+ let out = "";
39
+ let err = "";
40
+ vi.spyOn(console, "log").mockImplementation((s) => void (out += String(s) + "\n"));
41
+ vi.spyOn(console, "error").mockImplementation((s) => void (err += String(s) + "\n"));
42
+ const args = parseArgs(argv);
43
+ const match = resolveCommand(args, commandRegistry);
44
+ expect(match?.def.name).toBe(argv[0]);
45
+ const code = await match!.def.handler({ args, plugins: [], serializers: [] });
46
+ vi.restoreAllMocks();
47
+ return { code: code ?? 0, out, err };
48
+ }
49
+
50
+ let repo: string;
51
+ beforeEach(() => {
52
+ repo = initRepo();
53
+ process.chdir(repo);
54
+ });
55
+ afterEach(() => {
56
+ process.chdir(home);
57
+ vi.restoreAllMocks();
58
+ });
59
+
60
+ describe("chant lock and chant unlock", () => {
61
+ test("lock takes named targets, a second pull request exits 3 naming the holder, unlock frees them", async () => {
62
+ const taken = await run(["lock", "web", "api", "--pr", "1", "--by", "alice", "--json"]);
63
+ expect(taken.code).toBe(0);
64
+ expect(JSON.parse(taken.out)).toMatchObject({ gate: "pr-apply", pr: 1, ok: true, stage: "lock", taken: ["api", "web"] });
65
+
66
+ const held = await run(["lock", "web", "--pr", "2", "--by", "bob"]);
67
+ expect(held.code).toBe(3);
68
+ expect(held.err).toContain("web is locked by pull request 1 (locked with chant lock by alice), so pull request 2 is not locked");
69
+
70
+ const listed = await run(["lock", "--list", "--json"]);
71
+ expect(Object.keys(JSON.parse(listed.out).locks)).toEqual(["api", "web"]);
72
+
73
+ const released = await run(["unlock", "--pr", "1", "--json"]);
74
+ expect(JSON.parse(released.out)).toMatchObject({ released: ["api", "web"] });
75
+ expect((await run(["lock", "web", "--pr", "2", "--by", "bob"])).code).toBe(0);
76
+ });
77
+
78
+ test("--from-report locks the components a pr-plan.json selected, as plan locks, and refuses another pull request's report", async () => {
79
+ const report = join(repo, "pr-plan.json");
80
+ writeFileSync(report, JSON.stringify({ pr: 4, head: "b".repeat(40), selection: { waves: [["db"], ["api", "web"]] } }));
81
+ const taken = await run(["lock", "--from-report", report, "--pr", "4", "--stage", "plan", "--json"]);
82
+ expect(JSON.parse(taken.out)).toMatchObject({ ok: true, stage: "plan", taken: ["api", "db", "web"] });
83
+ const file = JSON.parse(git(repo, "show", "chant/lifecycle:_locks/pr-apply.json"));
84
+ expect(file.locks.db).toMatchObject({ pr: 4, stage: "plan", head: "b".repeat(40) });
85
+
86
+ const wrong = await run(["lock", "--from-report", report, "--pr", "5"]);
87
+ expect(wrong.code).toBe(1);
88
+ expect(wrong.err).toContain("is the report of pull request 4, not 5");
89
+ });
90
+
91
+ test("refuses without --pr or targets, an unknown stage, and a gate that is not a file name", async () => {
92
+ expect((await run(["lock", "web"])).err).toContain("--pr <n>");
93
+ expect((await run(["lock", "--pr", "1"])).err).toContain("needs the targets");
94
+ expect((await run(["lock", "web", "--pr", "1", "--stage", "merge"])).err).toContain("--stage merge is not one of plan, apply, lock");
95
+ expect((await run(["lock", "web", "--pr", "1", "--gate", "../x"])).code).toBe(1);
96
+ expect((await run(["unlock"])).err).toContain("--pr <n>");
97
+ });
98
+ });
@@ -0,0 +1,202 @@
1
+ /**
2
+ * `chant lock` and `chant unlock` (#4293): take, list and release the target
3
+ * locks a pull request holds (../../lifecycle/target-lock.ts).
4
+ *
5
+ * ```
6
+ * chant lock <target>... --pr <n> [--stage plan|apply|lock] [--head <sha>] [--by <who>] [--gate <name>] [--forge <kind>] [--json]
7
+ * chant lock --from-report <pr-plan.json> --pr <n> [--stage plan] [--forge <kind>] [--json]
8
+ * chant lock --list [--gate <name>] [--json]
9
+ * chant unlock --pr <n> [<target>...] [--gate <name>] [--json]
10
+ * ```
11
+ *
12
+ * The targets are names: the components `chant components pr-plan` selects,
13
+ * which are what `pr-apply` checks under `ci.locks`, or any other name a
14
+ * pipeline locks by. `--from-report` reads them from a pull-request report
15
+ * (`selection.waves`), so a lock job that runs the target branch's code can
16
+ * lock what the plan job, which ran the pull request's code, selected.
17
+ *
18
+ * `--forge` reads which holders are still open, so a lock whose pull
19
+ * request merged or closed is taken over, and, with `--head`, posts the
20
+ * `chant/lock` status on that commit. Without it every lock counts as held.
21
+ *
22
+ * Exit 0 when the locks are taken or released, 3 when another open pull
23
+ * request holds a target (nothing is locked), 1 on an error.
24
+ */
25
+ import { readFileSync } from "node:fs";
26
+ import { resolve } from "node:path";
27
+ import type { CommandContext } from "../registry";
28
+ import { formatError, formatInfo, formatSuccess, formatWarning } from "../format";
29
+ import { FORGE_KINDS, forgeFromEnv, type ForgeKind, type PrForge } from "../../pr-forge";
30
+ import { PR_APPLY_GATE } from "../../pr-loop";
31
+ import {
32
+ describeHeldTargetLocks,
33
+ readTargetLocks,
34
+ releaseTargetLocks,
35
+ takeTargetLocks,
36
+ targetLockGateProblem,
37
+ targetLockPathAt,
38
+ TARGET_LOCK_STAGES,
39
+ type TargetLockStage,
40
+ } from "../../lifecycle/target-lock";
41
+
42
+ /** The exit for a target another open pull request holds: 3, as a run stopped at a gate exits (`GATED_EXIT_CODE` in ./run.ts). */
43
+ const HELD_EXIT_CODE = 3;
44
+
45
+ /** The status `chant lock --head <sha> --forge <kind>` posts. */
46
+ export const LOCK_STATUS_CONTEXT = "chant/lock";
47
+
48
+ const fail = (message: string, hint?: string): number => {
49
+ console.error(formatError({ message, ...(hint ? { hint } : {}) }));
50
+ return 1;
51
+ };
52
+
53
+ /** The targets named after the command word. */
54
+ function targetsOf(ctx: CommandContext): string[] {
55
+ return (ctx.args.positionals ?? []).filter((t) => t !== "");
56
+ }
57
+
58
+ function gateOf(ctx: CommandContext): string | { error: string } {
59
+ const gate = ctx.args.gate ?? PR_APPLY_GATE;
60
+ const problem = targetLockGateProblem(gate);
61
+ return problem ? { error: problem } : gate;
62
+ }
63
+
64
+ function forgeOf(ctx: CommandContext): PrForge | undefined | { error: string } {
65
+ const kind = ctx.args.forge;
66
+ if (kind === undefined) return undefined;
67
+ if (!(FORGE_KINDS as readonly string[]).includes(kind)) return { error: `--forge ${kind} is not one of ${FORGE_KINDS.join(", ")}` };
68
+ try {
69
+ return forgeFromEnv(kind as ForgeKind);
70
+ } catch (err) {
71
+ return { error: err instanceof Error ? err.message : String(err) };
72
+ }
73
+ }
74
+
75
+ const prName = (forge: PrForge | undefined) => (n: number) => (forge?.kind === "gitlab" ? `merge request !${n}` : `pull request ${n}`);
76
+
77
+ /** The components a `pr-plan.json` selected, and the head it planned, checked against `--pr`. */
78
+ function fromReport(file: string, pr: number): { targets: string[]; head?: string } | { error: string } {
79
+ let doc: { pr?: unknown; head?: unknown; selection?: { waves?: unknown } };
80
+ try {
81
+ doc = JSON.parse(readFileSync(resolve(file), "utf8"));
82
+ } catch (err) {
83
+ return { error: `--from-report: could not read "${file}": ${err instanceof Error ? err.message : String(err)}` };
84
+ }
85
+ if (doc.pr !== pr) return { error: `--from-report: "${file}" is the report of ${doc.pr === null || doc.pr === undefined ? "no pull request" : `pull request ${String(doc.pr)}`}, not ${pr}` };
86
+ const waves = doc.selection?.waves;
87
+ if (!Array.isArray(waves) || !waves.every((w) => Array.isArray(w) && w.every((n) => typeof n === "string"))) {
88
+ return { error: `--from-report: "${file}" has no selection.waves; pass a pr-plan.json that chant components pr-plan wrote` };
89
+ }
90
+ return { targets: (waves as string[][]).flat(), ...(typeof doc.head === "string" ? { head: doc.head } : {}) };
91
+ }
92
+
93
+ async function postStatus(forge: PrForge | undefined, head: string | undefined, state: "success" | "failure", description: string): Promise<void> {
94
+ if (!forge || !head) return;
95
+ try {
96
+ await forge.setStatus(head, { context: LOCK_STATUS_CONTEXT, state, description: description.length > 140 ? `${description.slice(0, 137)}...` : description, ...(forge.runUrl ? { url: forge.runUrl } : {}) });
97
+ } catch (err) {
98
+ console.error(formatWarning({ message: `could not post ${LOCK_STATUS_CONTEXT} on ${head}: ${err instanceof Error ? err.message : String(err)}` }));
99
+ }
100
+ }
101
+
102
+ /** chant lock */
103
+ export async function runLock(ctx: CommandContext): Promise<number> {
104
+ const { args } = ctx;
105
+ const gate = gateOf(ctx);
106
+ if (typeof gate !== "string") return fail(gate.error);
107
+
108
+ if (args.list) {
109
+ if (targetsOf(ctx).length > 0 || args.pr !== undefined) return fail("--list prints every lock; drop the targets and --pr");
110
+ let file;
111
+ try {
112
+ file = await readTargetLocks(gate);
113
+ } catch (err) {
114
+ return fail(err instanceof Error ? err.message : String(err));
115
+ }
116
+ const rows = Object.entries(file.locks).sort(([a], [b]) => a.localeCompare(b));
117
+ if (args.json) {
118
+ console.log(JSON.stringify({ gate, path: await targetLockPathAt(gate), locks: Object.fromEntries(rows) }, null, 2));
119
+ return 0;
120
+ }
121
+ if (rows.length === 0) console.error(formatInfo(`no target locks on ${gate}`));
122
+ for (const [target, l] of rows) console.log(`${target}\tpull request ${l.pr}\t${l.stage}\t${l.by}\t${l.at}`);
123
+ return 0;
124
+ }
125
+
126
+ if (args.pr === undefined) return fail("chant lock needs the pull or merge request that holds the locks: --pr <n>", "chant lock --list prints the locks held now.");
127
+ const stage = (args.lockStage ?? "lock") as TargetLockStage;
128
+ if (!(TARGET_LOCK_STAGES as readonly string[]).includes(stage)) return fail(`--stage ${args.lockStage} is not one of ${TARGET_LOCK_STAGES.join(", ")}`);
129
+
130
+ let targets = targetsOf(ctx);
131
+ let head = args.head;
132
+ if (args.fromReport) {
133
+ if (targets.length > 0) return fail("--from-report reads the targets from the report; drop the names");
134
+ const read = fromReport(args.fromReport, args.pr);
135
+ if ("error" in read) return fail(read.error);
136
+ targets = read.targets;
137
+ head ??= read.head;
138
+ } else if (targets.length === 0 && stage !== "plan") {
139
+ return fail("chant lock needs the targets to lock: chant lock <target>... --pr <n>", "Or --from-report <pr-plan.json> to lock what a plan selected.");
140
+ }
141
+
142
+ const forge = forgeOf(ctx);
143
+ if (forge && "error" in forge) return fail(forge.error);
144
+ const isOpen = forge?.pullRequestOpen?.bind(forge);
145
+ const by = args.by ?? process.env.GITHUB_ACTOR ?? process.env.GITLAB_USER_LOGIN ?? process.env.USER ?? "unknown";
146
+ const name = prName(forge);
147
+
148
+ let result;
149
+ try {
150
+ result = await takeTargetLocks(
151
+ gate,
152
+ targets,
153
+ { pr: args.pr, by, at: new Date().toISOString(), stage, ...(head ? { head } : {}) },
154
+ { ...(isOpen ? { isOpen } : {}), releaseStalePlan: stage === "plan" },
155
+ );
156
+ } catch (err) {
157
+ return fail(`could not take the locks of ${gate}: ${err instanceof Error ? err.message : String(err)}`);
158
+ }
159
+
160
+ if (!result.ok) {
161
+ const holders = [...new Set(result.held.map((h) => h.pr))].sort((a, b) => a - b);
162
+ const text = `${describeHeldTargetLocks(result.held, name)}, so ${name(args.pr)} is not locked`;
163
+ await postStatus(forge, head, "failure", `locked by ${holders.map(name).join(", ")}: ${result.held.map((h) => h.target).join(", ")}`);
164
+ if (args.json) console.log(JSON.stringify({ gate, pr: args.pr, ok: false, held: result.held }, null, 2));
165
+ console.error(formatError({ message: text, hint: `Lock again once ${holders.length === 1 ? "it merges or closes" : "they merge or close"}, or after chant unlock --pr ${holders[0]}.${isOpen ? "" : " Without --forge every lock counts as held."}` }));
166
+ return HELD_EXIT_CODE;
167
+ }
168
+
169
+ const holds = result.taken.length > 0 ? `holds ${result.taken.join(", ")}` : "reaches no target";
170
+ await postStatus(forge, head, "success", holds);
171
+ if (args.json) {
172
+ console.log(JSON.stringify({ gate, pr: args.pr, ok: true, stage, taken: result.taken, released: result.released, expired: result.expired, pushed: result.pushed }, null, 2));
173
+ return 0;
174
+ }
175
+ console.error(formatSuccess(`${name(args.pr)} ${holds} on ${gate}`));
176
+ if (result.released.length > 0) console.error(formatInfo(`released ${result.released.join(", ")}, which it no longer reaches`));
177
+ if (result.expired.length > 0) console.error(formatInfo(`took over ${result.expired.join(", ")} from pull requests that merged or closed`));
178
+ if (!result.pushed && (result.taken.length > 0 || result.released.length > 0)) console.error(formatInfo("chant/lifecycle was not pushed: this repository has no remote, or recording is off"));
179
+ return 0;
180
+ }
181
+
182
+ /** chant unlock */
183
+ export async function runUnlock(ctx: CommandContext): Promise<number> {
184
+ const { args } = ctx;
185
+ const gate = gateOf(ctx);
186
+ if (typeof gate !== "string") return fail(gate.error);
187
+ if (args.pr === undefined) return fail("chant unlock needs the pull or merge request whose locks it releases: --pr <n>");
188
+ const targets = targetsOf(ctx);
189
+ let result;
190
+ try {
191
+ result = await releaseTargetLocks(gate, args.pr, targets.length > 0 ? { targets } : {});
192
+ } catch (err) {
193
+ return fail(`could not release the locks of ${gate}: ${err instanceof Error ? err.message : String(err)}`);
194
+ }
195
+ if (args.json) {
196
+ console.log(JSON.stringify({ gate, pr: args.pr, released: result.released, pushed: result.pushed }, null, 2));
197
+ return 0;
198
+ }
199
+ if (result.released.length === 0) console.error(formatInfo(`pull request ${args.pr} holds no lock${targets.length > 0 ? ` on ${targets.join(", ")}` : ""} on ${gate}`));
200
+ else console.error(formatSuccess(`released the locks pull request ${args.pr} held on ${result.released.join(", ")}`));
201
+ return 0;
202
+ }
@@ -1278,7 +1278,9 @@ describe("runApprove — a gate with an approval policy (#2508)", () => {
1278
1278
  }));
1279
1279
  const out = errSpy.mock.calls.map((c) => String(c[0])).join("\n");
1280
1280
  expect(out).toContain("log-only mode, so the decision is recorded and does not change the outcome");
1281
- expect(out).toContain("Quorum: 1 of 2 human approval(s) with role maintainer for this plan (alex)");
1281
+ // #4290: a claimed role is recorded for the policy, and the quorum never counts it.
1282
+ expect(out).toContain("Quorum: 0 of 2 human approval(s) with role maintainer for this plan (none yet)");
1283
+ expect(out).toContain("its roles are read from .chant/trust.json at base");
1282
1284
  errSpy.mockRestore();
1283
1285
  });
1284
1286
 
@@ -0,0 +1,169 @@
1
+ /**
2
+ * `chant components pr-plan` for an environment that declares an endpoint
3
+ * (#4281): every request a capability's plan sends goes to that endpoint and
4
+ * no other host, the way a `--live` read does (`../../live-endpoint.ts`).
5
+ *
6
+ * The capability stands in for azure's `arm-deploy`, gcp's `gcp-apply` and
7
+ * aws's `cfn-deploy`: its plan reads the endpoint from its lexicon's ambient
8
+ * var, else the real cloud's host, and sends a request through `fetch`, which
9
+ * is replaced here and only records. Nothing leaves the process. Git, the
10
+ * change signal, the derivation and the gate ledger are fakes, and the
11
+ * lifecycle branch can't be pushed.
12
+ */
13
+
14
+ import { mkdtemp, rm } from "node:fs/promises";
15
+ import { tmpdir } from "node:os";
16
+ import { join } from "node:path";
17
+ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
18
+ import type { DriverComponent } from "../../components/driver";
19
+ import type { DeployContext } from "../../components/capability";
20
+ import type { EmulatorCapability } from "../../op/emulator-lifecycle";
21
+ import type { ParsedArgs } from "../registry";
22
+
23
+ const HEAD = "a".repeat(40);
24
+ const BASE = "b".repeat(40);
25
+ const EMULATOR = "http://localhost:4566";
26
+ const REAL_CLOUD = "https://management.fakecloud.example";
27
+ const ENDPOINT_VAR = "FAKECLOUD_ENDPOINT_URL";
28
+
29
+ vi.mock("../../components/changed-files", () => ({
30
+ resolveCommit: async () => HEAD,
31
+ resolveMergeBase: async () => BASE,
32
+ }));
33
+
34
+ vi.mock("../../config", async () => {
35
+ const actual = await vi.importActual<typeof import("../../config")>("../../config");
36
+ return {
37
+ ...actual,
38
+ loadChantConfig: async () => ({
39
+ config: { environments: [{ name: "floci", endpoint: EMULATOR }, { name: "prod" }] },
40
+ }),
41
+ };
42
+ });
43
+
44
+ vi.mock("./fan-out", () => ({
45
+ resolveChangedUnits: async () => ({ units: { changed: ["net"], indeterminate: [] } }),
46
+ }));
47
+
48
+ vi.mock("../../lifecycle/gate-change-set", () => ({
49
+ storeGateChangeSet: async () => ({ written: false }),
50
+ readGraphIds: async () => ({ ids: [] }),
51
+ setGraphIdReader: () => {},
52
+ gateGraphReader: () => async () => ({ ids: [] }),
53
+ }));
54
+ vi.mock("../../lifecycle/git", async () => {
55
+ const actual = await vi.importActual<typeof import("../../lifecycle/git")>("../../lifecycle/git");
56
+ return { ...actual, pushLifecycleReport: async () => { throw new Error("pr-endpoint.test must not push chant/lifecycle"); } };
57
+ });
58
+
59
+ vi.mock("./run", () => ({
60
+ GATED_EXIT_CODE: 3,
61
+ autoReleaseRun: (id: string) => ({ runId: id, runOrigin: { forge: "local" } }),
62
+ recordAutoReleasesForRun: async () => [],
63
+ }));
64
+
65
+ vi.mock("../../op/gate", async () => {
66
+ const actual = await vi.importActual<typeof import("../../op/gate")>("../../op/gate");
67
+ return { ...actual, gitGateLedgerPort: () => actual.memoryGateLedgerPort(), gateIsSealed: async () => false };
68
+ });
69
+
70
+ vi.mock("../../components/fan-out-support", async () => {
71
+ const { CapabilityRegistry } = await import("../../components/capability");
72
+ const { planFanOut } = await import("../../components/fan-out");
73
+ const { computePlanDigest } = await import("../../lifecycle/plan-digest");
74
+ const registry = new CapabilityRegistry();
75
+ registry.register({
76
+ kind: "fakecloud-deploy",
77
+ async plan(_ctx: DeployContext, input: { root: string }) {
78
+ // What arm-deploy, gcp-apply and cfn-deploy do: the ambient var, else the real host.
79
+ const base = process.env[ENDPOINT_VAR] ?? REAL_CLOUD;
80
+ await fetch(`${base}/deployments/${input.root}`);
81
+ const planDigest = computePlanDigest("fakecloud-deploy", { root: input.root });
82
+ return {
83
+ member: input.root,
84
+ planDigest,
85
+ artifact: { planDigest },
86
+ changeSet: { member: { member: input.root, lexicon: "fakecloud", planner: "fakecloud", status: "planned", planDigest, holes: [] }, entries: [] },
87
+ };
88
+ },
89
+ async outputs() {
90
+ return {};
91
+ },
92
+ async run() {
93
+ throw new Error("pr-plan must not apply");
94
+ },
95
+ } as never);
96
+ const component = (name: string, dependsOn: string[] = []): DriverComponent => ({
97
+ name,
98
+ dependsOn,
99
+ deploy: [{ phase: "Apply", steps: [{ kind: "fakecloud-deploy", root: name }] }],
100
+ });
101
+ const estate = [component("net"), component("app", ["net"])];
102
+ return {
103
+ fanOutRegistry: async () => registry,
104
+ deriveFanOut: async () => ({
105
+ success: true,
106
+ components: estate,
107
+ plan: planFanOut({ components: estate, changed: ["net"] }),
108
+ signal: { changed: ["net"], indeterminate: [], unclaimed: [] },
109
+ }),
110
+ };
111
+ });
112
+
113
+ /** The lexicon plugin, declaring its endpoint var through its emulator as aws, azure and gcp do. */
114
+ const emulator: EmulatorCapability = {
115
+ spec: { name: "chant-fakecloud", image: "fakecloud:0", containerPort: 4566, healthPath: "/health" },
116
+ env: (endpoint) => ({ [ENDPOINT_VAR]: endpoint, FAKECLOUD_ACCESS_KEY: "test" }),
117
+ };
118
+ const plugins = [{ name: "fakecloud", emulator }];
119
+
120
+ const { runComponentsPrPlan } = await import("./pr");
121
+
122
+ let dir: string;
123
+ let hosts: string[];
124
+
125
+ const ctx = (env: string) =>
126
+ ({
127
+ args: { command: "components", path: "pr-plan", format: "", fix: false, watch: false, verbose: false, help: false, live: false, base: "main", env, output: dir, pr: 7 } as ParsedArgs,
128
+ plugins,
129
+ }) as never;
130
+
131
+ beforeEach(async () => {
132
+ dir = await mkdtemp(join(tmpdir(), "pr-endpoint-"));
133
+ hosts = [];
134
+ delete process.env[ENDPOINT_VAR];
135
+ vi.stubGlobal("fetch", vi.fn(async (url: string | URL) => {
136
+ hosts.push(new URL(String(url)).host);
137
+ return new Response("{}", { status: 200 });
138
+ }));
139
+ vi.spyOn(console, "error").mockImplementation(() => {});
140
+ vi.spyOn(console, "log").mockImplementation(() => {});
141
+ });
142
+
143
+ afterEach(async () => {
144
+ vi.unstubAllGlobals();
145
+ vi.restoreAllMocks();
146
+ delete process.env[ENDPOINT_VAR];
147
+ await rm(dir, { recursive: true, force: true });
148
+ });
149
+
150
+ describe("pr-plan against an environment that declares an endpoint (#4281)", () => {
151
+ test("every plan request goes to the declared endpoint and no other host, and the var is restored after", async () => {
152
+ expect(await runComponentsPrPlan(ctx("floci"))).toBe(0);
153
+ expect(hosts.length).toBe(2);
154
+ expect(new Set(hosts)).toEqual(new Set(["localhost:4566"]));
155
+ expect(process.env[ENDPOINT_VAR]).toBeUndefined();
156
+ });
157
+
158
+ test("an environment with no endpoint is left to the capability's own default", async () => {
159
+ expect(await runComponentsPrPlan(ctx("prod"))).toBe(0);
160
+ expect(new Set(hosts)).toEqual(new Set([new URL(REAL_CLOUD).host]));
161
+ });
162
+
163
+ test("an ambient var already set wins over the declared endpoint", async () => {
164
+ process.env[ENDPOINT_VAR] = "http://127.0.0.1:9999";
165
+ expect(await runComponentsPrPlan(ctx("floci"))).toBe(0);
166
+ expect(new Set(hosts)).toEqual(new Set(["127.0.0.1:9999"]));
167
+ expect(process.env[ENDPOINT_VAR]).toBe("http://127.0.0.1:9999");
168
+ });
169
+ });