@intentius/chant 0.124.76 → 0.124.78

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 (212) hide show
  1. package/dist/__fixtures__/agent-guard/plywood.d.ts +8 -0
  2. package/dist/__fixtures__/agent-guard/plywood.d.ts.map +1 -0
  3. package/dist/__fixtures__/agent-guard/plywood.js +19 -0
  4. package/dist/__fixtures__/agent-guard/terragucci.d.ts +8 -0
  5. package/dist/__fixtures__/agent-guard/terragucci.d.ts.map +1 -0
  6. package/dist/__fixtures__/agent-guard/terragucci.js +30 -0
  7. package/dist/__fixtures__/gated-ledger.d.ts +10 -0
  8. package/dist/__fixtures__/gated-ledger.d.ts.map +1 -0
  9. package/dist/__fixtures__/gated-ledger.js +51 -0
  10. package/dist/__fixtures__/notify-messages/events.d.ts +9 -0
  11. package/dist/__fixtures__/notify-messages/events.d.ts.map +1 -0
  12. package/dist/__fixtures__/notify-messages/events.js +21 -0
  13. package/dist/__fixtures__/product-words.d.ts +14 -0
  14. package/dist/__fixtures__/product-words.d.ts.map +1 -1
  15. package/dist/__fixtures__/product-words.js +11 -0
  16. package/dist/__fixtures__/terragucci-notify.d.ts +66 -0
  17. package/dist/__fixtures__/terragucci-notify.d.ts.map +1 -0
  18. package/dist/__fixtures__/terragucci-notify.js +133 -0
  19. package/dist/action-pins.d.ts +8 -0
  20. package/dist/action-pins.d.ts.map +1 -1
  21. package/dist/action-pins.js +9 -0
  22. package/dist/agent-guard.d.ts +143 -0
  23. package/dist/agent-guard.d.ts.map +1 -0
  24. package/dist/agent-guard.js +455 -0
  25. package/dist/ci-commit.d.ts +120 -5
  26. package/dist/ci-commit.d.ts.map +1 -1
  27. package/dist/ci-commit.js +214 -23
  28. package/dist/ci-own-jobs.d.ts +81 -0
  29. package/dist/ci-own-jobs.d.ts.map +1 -0
  30. package/dist/ci-own-jobs.js +233 -0
  31. package/dist/ci-product-words.d.ts +18 -4
  32. package/dist/ci-product-words.d.ts.map +1 -1
  33. package/dist/ci-product-words.js +26 -6
  34. package/dist/ci-product.d.ts +40 -1
  35. package/dist/ci-product.d.ts.map +1 -1
  36. package/dist/ci-product.js +40 -1
  37. package/dist/cli/handlers/approve.d.ts +5 -1
  38. package/dist/cli/handlers/approve.d.ts.map +1 -1
  39. package/dist/cli/handlers/approve.js +17 -11
  40. package/dist/cli/handlers/build.d.ts +1 -1
  41. package/dist/cli/handlers/build.d.ts.map +1 -1
  42. package/dist/cli/handlers/build.js +88 -2
  43. package/dist/cli/handlers/commit.d.ts.map +1 -1
  44. package/dist/cli/handlers/commit.js +3 -1
  45. package/dist/cli/handlers/notify-relay.d.ts +18 -1
  46. package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
  47. package/dist/cli/handlers/notify-relay.js +90 -14
  48. package/dist/cli/handlers/pr.d.ts.map +1 -1
  49. package/dist/cli/handlers/pr.js +3 -1
  50. package/dist/cli/handlers/release.d.ts +5 -1
  51. package/dist/cli/handlers/release.d.ts.map +1 -1
  52. package/dist/cli/handlers/release.js +21 -9
  53. package/dist/cli/handlers/run-generate.d.ts.map +1 -1
  54. package/dist/cli/handlers/run-generate.js +2 -1
  55. package/dist/cli/main.d.ts.map +1 -1
  56. package/dist/cli/main.js +21 -1
  57. package/dist/cli/parse-args.d.ts.map +1 -1
  58. package/dist/cli/parse-args.js +60 -4
  59. package/dist/cli/registry.d.ts +16 -0
  60. package/dist/cli/registry.d.ts.map +1 -1
  61. package/dist/components/pr-env-components.d.ts +65 -0
  62. package/dist/components/pr-env-components.d.ts.map +1 -0
  63. package/dist/components/pr-env-components.js +162 -0
  64. package/dist/components/pr-policy.d.ts +15 -0
  65. package/dist/components/pr-policy.d.ts.map +1 -1
  66. package/dist/components/pr-policy.js +24 -1
  67. package/dist/components/release-compile.d.ts +15 -3
  68. package/dist/components/release-compile.d.ts.map +1 -1
  69. package/dist/components/release-compile.js +66 -15
  70. package/dist/config.d.ts +14 -8
  71. package/dist/config.d.ts.map +1 -1
  72. package/dist/config.js +16 -1
  73. package/dist/gate-policy.d.ts +14 -1
  74. package/dist/gate-policy.d.ts.map +1 -1
  75. package/dist/gate-policy.js +16 -6
  76. package/dist/lexicon.d.ts +25 -1
  77. package/dist/lexicon.d.ts.map +1 -1
  78. package/dist/lexicon.js +10 -0
  79. package/dist/lifecycle/gated-op.d.ts +95 -0
  80. package/dist/lifecycle/gated-op.d.ts.map +1 -0
  81. package/dist/lifecycle/gated-op.js +96 -0
  82. package/dist/lifecycle/git.d.ts.map +1 -1
  83. package/dist/lifecycle/git.js +83 -2
  84. package/dist/lifecycle/release-images.d.ts +77 -3
  85. package/dist/lifecycle/release-images.d.ts.map +1 -1
  86. package/dist/lifecycle/release-images.js +132 -6
  87. package/dist/notify-product.d.ts +11 -2
  88. package/dist/notify-product.d.ts.map +1 -1
  89. package/dist/notify-product.js +16 -4
  90. package/dist/notify-relay-repo.d.ts +131 -0
  91. package/dist/notify-relay-repo.d.ts.map +1 -0
  92. package/dist/notify-relay-repo.js +202 -0
  93. package/dist/notify-relay.d.ts +25 -1
  94. package/dist/notify-relay.d.ts.map +1 -1
  95. package/dist/notify-relay.js +27 -2
  96. package/dist/notify.d.ts +36 -4
  97. package/dist/notify.d.ts.map +1 -1
  98. package/dist/notify.js +31 -21
  99. package/dist/notify.schema.json +1 -0
  100. package/dist/op/activities/review-product.d.ts +111 -0
  101. package/dist/op/activities/review-product.d.ts.map +1 -0
  102. package/dist/op/activities/review-product.js +116 -0
  103. package/dist/op/op-waves-capability.js +2 -2
  104. package/dist/policy-engine.d.ts +95 -0
  105. package/dist/policy-engine.d.ts.map +1 -0
  106. package/dist/policy-engine.js +157 -0
  107. package/dist/pr-forge-reads.d.ts +124 -0
  108. package/dist/pr-forge-reads.d.ts.map +1 -0
  109. package/dist/pr-forge-reads.js +322 -0
  110. package/dist/pr-forge.d.ts +14 -0
  111. package/dist/pr-forge.d.ts.map +1 -1
  112. package/dist/pr-forge.js +21 -13
  113. package/dist/pr-plan-note.d.ts +293 -0
  114. package/dist/pr-plan-note.d.ts.map +1 -0
  115. package/dist/pr-plan-note.js +362 -0
  116. package/dist/release-floors.d.ts +9 -1
  117. package/dist/release-floors.d.ts.map +1 -1
  118. package/dist/release-floors.js +9 -1
  119. package/dist/state-export.d.ts +126 -0
  120. package/dist/state-export.d.ts.map +1 -0
  121. package/dist/state-export.js +156 -0
  122. package/dist/state-migration.d.ts +148 -0
  123. package/dist/state-migration.d.ts.map +1 -0
  124. package/dist/state-migration.js +146 -0
  125. package/dist/state-unlock.d.ts +167 -0
  126. package/dist/state-unlock.d.ts.map +1 -0
  127. package/dist/state-unlock.js +196 -0
  128. package/dist/wave-runtime.mjs +332 -332
  129. package/dist/workspace/declaration.schema.json +1 -1
  130. package/dist/workspace/release-workflow.d.ts +10 -0
  131. package/dist/workspace/release-workflow.d.ts.map +1 -1
  132. package/dist/workspace/release-workflow.js +10 -4
  133. package/package.json +1 -1
  134. package/src/__fixtures__/agent-guard/plywood.ts +27 -0
  135. package/src/__fixtures__/agent-guard/terragucci.ts +39 -0
  136. package/src/__fixtures__/gated-ledger.ts +58 -0
  137. package/src/__fixtures__/notify-messages/events.ts +23 -0
  138. package/src/__fixtures__/notify-messages/messages.json +50 -0
  139. package/src/__fixtures__/pr-loop/terragucci-plan.note.golden.md +53 -0
  140. package/src/__fixtures__/pr-loop/terragucci-plan.note.json +83 -0
  141. package/src/__fixtures__/product-words.ts +12 -0
  142. package/src/__fixtures__/review-agent/terragucci-review.json +94 -0
  143. package/src/__fixtures__/terragucci-notify.ts +170 -0
  144. package/src/action-pins.test.ts +12 -1
  145. package/src/action-pins.ts +11 -0
  146. package/src/agent-guard.test.ts +319 -0
  147. package/src/agent-guard.ts +547 -0
  148. package/src/ci-commit.test.ts +213 -2
  149. package/src/ci-commit.ts +258 -27
  150. package/src/ci-own-jobs.test.ts +108 -0
  151. package/src/ci-own-jobs.ts +252 -0
  152. package/src/ci-product-words.ts +35 -7
  153. package/src/ci-product.ts +81 -1
  154. package/src/cli/handlers/approve-cwd.test.ts +112 -0
  155. package/src/cli/handlers/approve.ts +22 -11
  156. package/src/cli/handlers/build-own-jobs.test.ts +80 -0
  157. package/src/cli/handlers/build-pr-loop-control.test.ts +87 -0
  158. package/src/cli/handlers/build-run-group.test.ts +59 -0
  159. package/src/cli/handlers/build.ts +83 -3
  160. package/src/cli/handlers/commit.ts +3 -0
  161. package/src/cli/handlers/notify-relay.ts +99 -17
  162. package/src/cli/handlers/pr.ts +3 -1
  163. package/src/cli/handlers/release.ts +20 -10
  164. package/src/cli/handlers/run-generate.ts +2 -1
  165. package/src/cli/main.ts +21 -1
  166. package/src/cli/parse-args.ts +45 -3
  167. package/src/cli/registry.ts +16 -0
  168. package/src/components/pr-env-components.test.ts +137 -0
  169. package/src/components/pr-env-components.ts +213 -0
  170. package/src/components/pr-policy.test.ts +41 -1
  171. package/src/components/pr-policy.ts +25 -1
  172. package/src/components/release-compile.test.ts +47 -0
  173. package/src/components/release-compile.ts +70 -13
  174. package/src/config.ts +23 -3
  175. package/src/gate-policy-bundle.test.ts +14 -0
  176. package/src/gate-policy.test.ts +7 -0
  177. package/src/gate-policy.ts +22 -7
  178. package/src/lexicon.ts +28 -1
  179. package/src/lifecycle/gated-op.ts +158 -0
  180. package/src/lifecycle/git.test.ts +92 -0
  181. package/src/lifecycle/git.ts +71 -2
  182. package/src/lifecycle/release-images-dockerfile.test.ts +221 -0
  183. package/src/lifecycle/release-images.ts +167 -8
  184. package/src/notify-message-words.test.ts +186 -0
  185. package/src/notify-product.ts +17 -4
  186. package/src/notify-relay-repo.test.ts +284 -0
  187. package/src/notify-relay-repo.ts +234 -0
  188. package/src/notify-relay.test.ts +12 -0
  189. package/src/notify-relay.ts +29 -3
  190. package/src/notify.schema.json +1 -0
  191. package/src/notify.ts +59 -19
  192. package/src/op/activities/review-product.test.ts +116 -0
  193. package/src/op/activities/review-product.ts +200 -0
  194. package/src/op/op-waves-capability.ts +2 -2
  195. package/src/op/schedule-overdue.test.ts +26 -0
  196. package/src/policy-engine.test.ts +162 -0
  197. package/src/policy-engine.ts +200 -0
  198. package/src/pr-forge-reads.test.ts +285 -0
  199. package/src/pr-forge-reads.ts +424 -0
  200. package/src/pr-forge.ts +30 -16
  201. package/src/pr-plan-note.test.ts +105 -0
  202. package/src/pr-plan-note.ts +521 -0
  203. package/src/release-floors.ts +13 -1
  204. package/src/state-export.test.ts +124 -0
  205. package/src/state-export.ts +227 -0
  206. package/src/state-migration.test.ts +133 -0
  207. package/src/state-migration.ts +236 -0
  208. package/src/state-unlock.test.ts +165 -0
  209. package/src/state-unlock.ts +293 -0
  210. package/src/workspace/declaration.schema.json +1 -1
  211. package/src/workspace/release-workflow.test.ts +34 -0
  212. package/src/workspace/release-workflow.ts +19 -4
@@ -21,12 +21,22 @@ import {
21
21
  prepareCommitRun,
22
22
  resolveCommitSpec,
23
23
  runCommit,
24
+ COMMIT_PR_ENV,
25
+ CI_COMMIT_ARG_FLOOR,
26
+ CI_COMMIT_HARNESS_BREAK_FLOOR,
27
+ COMMIT_HARNESS_BREAK_ENV,
28
+ COMMIT_HARNESS_FORGE,
29
+ commitHarnessBreaks,
30
+ commitArgv,
31
+ GITLAB_COMMIT_ARG_VAR,
32
+ type CommitRefusalReply,
24
33
  type CommitRunCommand,
25
34
  type CommitSettings,
26
35
  type OpCommitSpec,
27
36
  } from "./ci-commit";
28
37
  import { assertProductWords, parseProductComment } from "./ci-product-words";
29
38
  import { PLYWOOD } from "./__fixtures__/product-words";
39
+ import { NEXT_RELEASE } from "./release-floors";
30
40
  import type { OpRunRecord, OpRunRecordInput } from "./op/runtime";
31
41
  import type { PullRequestHead } from "./pr-forge";
32
42
 
@@ -112,7 +122,7 @@ function world(): World {
112
122
  return w;
113
123
  }
114
124
 
115
- async function cycle(w: World, s: CommitSettings, o: { event?: unknown; command?: CommitRunCommand; env?: Record<string, string>; between?: () => void } = {}) {
125
+ async function cycle(w: World, s: CommitSettings, o: { event?: unknown; command?: CommitRunCommand; env?: Record<string, string>; runEnv?: Record<string, string>; refusalReply?: CommitRefusalReply; between?: () => void } = {}) {
116
126
  const d = tmp("dir");
117
127
  const forge = {
118
128
  pullRequestHead: async () => w.heads(),
@@ -129,7 +139,7 @@ async function cycle(w: World, s: CommitSettings, o: { event?: unknown; command?
129
139
  const readRuns = async () => w.records;
130
140
  const pullRequestBase = async () => w.heads().base;
131
141
  const decision = await prepareCommitRun({ settings: s, words, dir: d, env, event, forge, pullRequestBase, readRuns, approval, git: w.r.git, now: NOW });
132
- const ran = await runCommit({ settings: s, dir: d, checkout: w.r.checkout, workDir: join(tmp("work"), "w"), env: { PATH: process.env.PATH }, git: w.r.git, runCommand: o.command ?? formatter() });
142
+ const ran = await runCommit({ settings: s, dir: d, checkout: w.r.checkout, workDir: join(tmp("work"), "w"), env: { PATH: process.env.PATH, ...o.runEnv }, git: w.r.git, runCommand: o.command ?? formatter() });
133
143
  o.between?.();
134
144
  let t = NOW.getTime();
135
145
  const out = await landCommitChange({
@@ -151,6 +161,7 @@ async function cycle(w: World, s: CommitSettings, o: { event?: unknown; command?
151
161
  w.records.push({ version: 1, id: String(w.records.length), ...input } as OpRunRecord);
152
162
  },
153
163
  now: () => new Date((t += 1000)),
164
+ ...(o.refusalReply ? { refusalReply: o.refusalReply } : {}),
154
165
  });
155
166
  // The next cycle sees the branch as it is now.
156
167
  w.r.git(["fetch", "-q", "origin", `+refs/heads/feature:${COMMIT_HEAD_REF}`]);
@@ -434,3 +445,203 @@ describe("mergeBase (#4723)", () => {
434
445
  expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
435
446
  });
436
447
  });
448
+
449
+ describe("the command's variables and its refusal reply (#4724)", () => {
450
+ test("commandEnv round-trips through the job's variables and refuses a forge token or the job's own settings", () => {
451
+ const s = settings({ commandEnv: ["DEV_POSTGRES_READER_USER", "DEV_POSTGRES_READER_USER"] });
452
+ expect(s.commandEnv).toEqual(["DEV_POSTGRES_READER_USER"]);
453
+ expect(commitSettingsFromEnv(commitSettingsEnv(s), "plywood")).toEqual(s);
454
+ expect(settings().commandEnv).toEqual([]);
455
+ expect(() => settings({ commandEnv: ["GITHUB_TOKEN"] })).toThrow(/may not pass GITHUB_TOKEN/);
456
+ expect(() => settings({ commandEnv: ["PUSH_TOKEN"], tokenEnv: "PUSH_TOKEN" })).toThrow(/may not pass PUSH_TOKEN/);
457
+ expect(() => settings({ commandEnv: ["CHANT_COMMIT_NAME"] })).toThrow(/may not pass CHANT_COMMIT_NAME/);
458
+ expect(() => settings({ commandEnv: ["not a var"] })).toThrow(/commandEnv is a list of variable names/);
459
+ });
460
+
461
+ test("the command sees the named variables and the pull request's number, and nothing else of the job", async () => {
462
+ const w = world();
463
+ let seen: Record<string, string> = {};
464
+ const command: CommitRunCommand = async (argv, o) => {
465
+ seen = o.env;
466
+ return formatter()(argv, o);
467
+ };
468
+ await cycle(w, settings({ commandEnv: ["DEV_POSTGRES_READER_USER"] }), { command, runEnv: { DEV_POSTGRES_READER_USER: "reader", DEV_POSTGRES_WRITER_USER: "writer", GITHUB_TOKEN: "t" } });
469
+ expect(seen.DEV_POSTGRES_READER_USER).toBe("reader");
470
+ expect(seen[COMMIT_PR_ENV]).toBe("7");
471
+ expect(seen.DEV_POSTGRES_WRITER_USER).toBeUndefined();
472
+ expect(seen.GITHUB_TOKEN).toBeUndefined();
473
+ });
474
+
475
+ test("a product's reply to a refusal names what the command said, and the run is refused, not failed", async () => {
476
+ const w = world();
477
+ const command: CommitRunCommand = async () => ({ exitCode: 1, timedOut: false, output: "noise\nplywood fmt: refused: main.tf is locked\n" });
478
+ const refusalReply: CommitRefusalReply = ({ rc, output }) => (rc === "1" && output.includes("is locked") ? "`terraform fmt` refused: `main.tf` is locked." : undefined);
479
+ const { out } = await cycle(w, settings(), { command, refusalReply });
480
+ expect(out).toMatchObject({ result: "refused", reason: "the command refused, exiting 1", code: 0 });
481
+ expect(w.replies).toEqual(["plywood: `terraform fmt` refused: `main.tf` is locked. Nothing was pushed."]);
482
+ expect(w.records.at(-1)?.outcomes?.commit).toMatchObject({ result: "refused" });
483
+ });
484
+
485
+ test("a refusal the product does not know keeps chant's own reply", async () => {
486
+ const w = world();
487
+ const command: CommitRunCommand = async () => ({ exitCode: 3, timedOut: false, output: "something else\n" });
488
+ const { out } = await cycle(w, settings(), { command, refusalReply: () => undefined });
489
+ expect(out).toMatchObject({ result: "failed", reason: "the command exited 3" });
490
+ expect(w.replies[0]).toContain("stopped with exit code 3");
491
+ });
492
+ });
493
+
494
+ describe("the comment's argument (#4820)", () => {
495
+ const NAME_PATTERN = "^[a-z0-9]+(?:[-_][a-z0-9]+)*$";
496
+ const named = (extra: Partial<OpCommitSpec> = {}) => settings({ commentArg: { pattern: NAME_PATTERN, position: 1 }, ...extra });
497
+ const seeing = (into: (readonly string[])[]): CommitRunCommand => async (argv, o) => {
498
+ into.push(argv);
499
+ return formatter()(argv, o);
500
+ };
501
+
502
+ test("the parse reads one argument only for a word that declares it, against its pattern and chant's own", () => {
503
+ const args = { fmt: new RegExp(NAME_PATTERN) };
504
+ expect(parseProductComment(words, "/plywood fmt", {}, args)).toEqual({ kind: "commit", word: "fmt" });
505
+ expect(parseProductComment(words, "/plywood fmt add-note", {}, args)).toEqual({ kind: "commit", word: "fmt", arg: "add-note" });
506
+ expect(parseProductComment(words, "/plywood fmt Add-Note", {}, args)).toMatchObject({ kind: "refused", reason: expect.stringMatching(/`\/plywood fmt` takes nothing, or one name after it/) });
507
+ expect(parseProductComment(words, "/plywood fmt a b", {}, args)).toMatchObject({ kind: "refused" });
508
+ expect(parseProductComment(words, "/plywood fmt --force", {}, args)).toMatchObject({ kind: "refused" });
509
+ // chant's own check holds whatever the product's pattern lets through.
510
+ expect(parseProductComment(words, "/plywood fmt ../x", {}, { fmt: /^.*$/ })).toMatchObject({ kind: "refused" });
511
+ expect(parseProductComment(words, "/plywood fmt $(id)", {}, { fmt: /^.*$/ })).toMatchObject({ kind: "refused" });
512
+ expect(parseProductComment(words, "/plywood fmt add-note")).toEqual({ kind: "refused", reason: "`/plywood fmt` takes nothing after it" });
513
+ });
514
+
515
+ test("commentArg round-trips through the job's variables and refuses a loose pattern, a bad position or the check trigger", () => {
516
+ const s = named();
517
+ expect(s.commentArg).toEqual({ pattern: NAME_PATTERN, position: 1 });
518
+ expect(commitSettingsFromEnv(commitSettingsEnv(s), "plywood")).toEqual(s);
519
+ expect(settings().commentArg).toBeUndefined();
520
+ expect(() => named({ commentArg: { pattern: "[a-z]+", position: 1 } })).toThrow(/anchored/);
521
+ expect(() => named({ commentArg: { pattern: "^(?:$", position: 1 } })).toThrow(/pattern/);
522
+ expect(() => named({ commentArg: { pattern: NAME_PATTERN, position: 0 } })).toThrow(/position/);
523
+ expect(() => named({ commentArg: { pattern: NAME_PATTERN, position: 4 } })).toThrow(/position/);
524
+ expect(() => resolveCommitSpec("plywood-fmt", { on: "check", command: ["terraform", "fmt"], allowed: ["main.tf"], commentArg: { pattern: NAME_PATTERN, position: 1 } }, "plywood")).toThrow(/comment trigger/);
525
+ });
526
+
527
+ test("commitArgv puts the argument at its position and refuses one the settings do not take", () => {
528
+ expect(commitArgv(named(), "add-note")).toEqual(["terraform", "add-note", "fmt", "-recursive"]);
529
+ expect(commitArgv(named(), undefined)).toEqual(["terraform", "fmt", "-recursive"]);
530
+ expect(() => commitArgv(settings(), "add-note")).toThrow(/takes no argument/);
531
+ expect(() => commitArgv(named(), "Bad")).toThrow(/not a name/);
532
+ });
533
+
534
+ test("the comment's argument reaches the command's argv, the commit and the reply", async () => {
535
+ const w = world();
536
+ const argvs: (readonly string[])[] = [];
537
+ const { decision, out } = await cycle(w, named(), { event: comment("/plywood fmt add-note"), command: seeing(argvs) });
538
+ expect(decision.arg).toBe("add-note");
539
+ expect(argvs).toEqual([["terraform", "add-note", "fmt", "-recursive"]]);
540
+ expect(out.result).toBe("pushed");
541
+ expect(featureLog(w)).toContain("/plywood fmt add-note asked for by ana");
542
+ expect(featureLog(w)).toContain("Ran terraform add-note fmt -recursive on ");
543
+ expect(w.replies[0]).toContain("from `terraform add-note fmt -recursive`");
544
+ });
545
+
546
+ test("without an argument the argv is the spec's", async () => {
547
+ const w = world();
548
+ const argvs: (readonly string[])[] = [];
549
+ const { decision } = await cycle(w, named(), { command: seeing(argvs) });
550
+ expect(decision.arg).toBeUndefined();
551
+ expect(argvs).toEqual([["terraform", "fmt", "-recursive"]]);
552
+ });
553
+
554
+ test("an argument off the pattern is refused before anything runs", async () => {
555
+ const w = world();
556
+ const argvs: (readonly string[])[] = [];
557
+ const { out } = await cycle(w, named(), { event: comment("/plywood fmt Not_ok!"), command: seeing(argvs) });
558
+ expect(argvs).toEqual([]);
559
+ expect(out.result).toBe("refused");
560
+ expect(out.reason).toMatch(/takes nothing, or one name after it/);
561
+ expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
562
+ });
563
+
564
+ test("GitLab takes the argument from its own pipeline variable", async () => {
565
+ const w = world();
566
+ const argvs: (readonly string[])[] = [];
567
+ const env = { GITLAB_CI: "true", CHANT_COMMIT_PR: "7", CHANT_COMMIT: "fmt", [GITLAB_COMMIT_ARG_VAR]: "add-note", GITLAB_USER_LOGIN: "ana" };
568
+ const { out } = await cycle(w, named(), { event: {}, env, command: seeing(argvs) });
569
+ expect(out.result).toBe("pushed");
570
+ expect(argvs).toEqual([["terraform", "add-note", "fmt", "-recursive"]]);
571
+ const bad = world();
572
+ const { out: refused } = await cycle(bad, named(), { event: {}, env: { ...env, [GITLAB_COMMIT_ARG_VAR]: "a b" }, command: seeing([]) });
573
+ expect(refused.result).toBe("refused");
574
+ });
575
+
576
+ test("the floor is the next release until it ships", () => {
577
+ expect(CI_COMMIT_ARG_FLOOR).toBe(NEXT_RELEASE);
578
+ });
579
+ });
580
+
581
+ describe("the harness's BREAK switch for land (#4836)", () => {
582
+ const harness = (checks: string) => ({ [COMMIT_HARNESS_BREAK_ENV]: checks, BREAK: "1", GITHUB_SERVER_URL: COMMIT_HARNESS_FORGE });
583
+
584
+ test("is read only in a BREAK arm on the harness's Forgejo, and refused anywhere else", () => {
585
+ expect(commitHarnessBreaks({})).toEqual({ checks: [] });
586
+ expect(commitHarnessBreaks(harness("paths"))).toEqual({ checks: ["paths"] });
587
+ expect(commitHarnessBreaks({ ...harness("paths, moved-base"), GITHUB_SERVER_URL: `${COMMIT_HARNESS_FORGE}/` })).toEqual({ checks: ["paths", "moved-base"] });
588
+ expect(commitHarnessBreaks({ ...harness("paths"), BREAK: undefined })).toMatchObject({ refused: expect.stringMatching(/only in a BREAK arm of chant's e2e harness/) });
589
+ expect(commitHarnessBreaks({ ...harness("paths"), GITHUB_SERVER_URL: "https://github.com" })).toMatchObject({ refused: expect.stringMatching(/only in a BREAK arm/) });
590
+ expect(commitHarnessBreaks({ ...harness("paths"), GITHUB_SERVER_URL: undefined })).toMatchObject({ refused: expect.any(String) });
591
+ expect(commitHarnessBreaks({ ...harness("paths"), GITLAB_CI: "true" })).toMatchObject({ refused: expect.any(String) });
592
+ expect(commitHarnessBreaks(harness("guarded"))).toMatchObject({ refused: expect.stringMatching(/paths and moved-base/) });
593
+ expect(commitHarnessBreaks(harness(""))).toEqual({ checks: [] });
594
+ });
595
+
596
+ test("the harness's Forgejo is the one chant's e2e stack runs", async () => {
597
+ const { HARNESS_HOSTS } = await import("./e2e-harness/stack");
598
+ expect(COMMIT_HARNESS_FORGE).toBe(HARNESS_HOSTS.forgejo);
599
+ });
600
+
601
+ test("outside a harness the switch fails the land and pushes nothing", async () => {
602
+ const w = world();
603
+ const { out } = await cycle(w, settings(), { env: { [COMMIT_HARNESS_BREAK_ENV]: "paths" } });
604
+ expect(out).toMatchObject({ result: "failed", code: 1 });
605
+ expect(out.reason).toMatch(new RegExp(COMMIT_HARNESS_BREAK_ENV));
606
+ expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
607
+ expect(w.replies[0]).toMatch(/only in a BREAK arm.*nothing was pushed/);
608
+ });
609
+
610
+ test("paths: a change outside allowed lands, and says the check was off", async () => {
611
+ const w = world();
612
+ const { out } = await cycle(w, settings(), { command: formatter({ "other.tf": "z\n" }), env: harness("paths") });
613
+ expect(out.result).toBe("pushed");
614
+ expect(out.paths).toEqual(["main.tf", "other.tf"]);
615
+ expect(out.reason).toContain("BREAK: the path check was off");
616
+ expect(w.replies[0]).toContain("BREAK: the path check was off");
617
+ });
618
+
619
+ test("paths: a guarded path is still refused", async () => {
620
+ const w = world();
621
+ const { out } = await cycle(w, settings(), { command: formatter({ ".github/workflows/x.yml": "on: push\n" }), env: harness("paths") });
622
+ expect(out.result).toBe("refused");
623
+ expect(out.reason).toBe("the change touches .github/workflows/x.yml");
624
+ expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
625
+ });
626
+
627
+ test("moved-base: a base that moved while the command ran lands the merge of the tip the command ran on", async () => {
628
+ const w = world();
629
+ const ran = onMain(w, { "migrations/002.sql": "x\n" });
630
+ const { out } = await cycle(w, settings({ mergeBase: true }), { env: harness("moved-base"), between: () => void onMain(w, { "migrations/003.sql": "y\n" }, "moved") });
631
+ expect(out.result).toBe("pushed");
632
+ expect(out.reason).toContain("BREAK: the moved-base check was off");
633
+ const parents = sh(["log", "-1", "--format=%P", "refs/heads/feature"], w.r.origin).trim().split(" ");
634
+ expect(parents).toEqual([w.r.head, ran]);
635
+ });
636
+
637
+ test("one check off leaves the other on", async () => {
638
+ const w = world();
639
+ onMain(w, { "migrations/002.sql": "x\n" });
640
+ const { out } = await cycle(w, settings({ mergeBase: true }), { env: harness("paths"), between: () => void onMain(w, { "migrations/003.sql": "y\n" }, "moved") });
641
+ expect(out).toMatchObject({ result: "refused", reason: "the base moved" });
642
+ });
643
+
644
+ test("the floor is the next release until it ships", () => {
645
+ expect(CI_COMMIT_HARNESS_BREAK_FLOOR).toBe(NEXT_RELEASE);
646
+ });
647
+ });