@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
@@ -0,0 +1,170 @@
1
+ /**
2
+ * terragucci's own Slack and Teams bodies, copied unchanged from
3
+ * packages/terragucci/src/notify.ts at terragucci commit c87473035270
4
+ * (origin/main, 2026-11-08), for #4818. chant's messages under terragucci's
5
+ * words must come out byte for byte as these do; once terragucci renders
6
+ * through chant's, it deletes the originals.
7
+ *
8
+ * Written here: the imports, `NOTIFY_SOURCE`, the notice types without the
9
+ * fields the renderers do not read, and `export` on `summary`. Every function
10
+ * body is terragucci's.
11
+ */
12
+ import { slackRelayActions, teamsRelayReply, type RelayButtons } from "../notify";
13
+
14
+ const NOTIFY_SOURCE = "terragucci";
15
+ export const REPLAN_ACTION = "terragucci-replan";
16
+ type WaveEvent = "waiting" | "refused" | "failed";
17
+
18
+ export interface WaveNotice {
19
+ event: WaveEvent;
20
+ wave: number;
21
+ project: string;
22
+ roots: string[];
23
+ approve: string;
24
+ digest?: string;
25
+ review?: { pr: number; url: string };
26
+ outcome?: string;
27
+ run?: string;
28
+ report?: string;
29
+ relay?: string;
30
+ }
31
+
32
+ export interface DriftNotice {
33
+ project: string;
34
+ roots: string[];
35
+ failed: string[];
36
+ run?: string;
37
+ report?: string;
38
+ replan?: string;
39
+ }
40
+
41
+ const HEADLINE: Record<WaveEvent, string> = {
42
+ waiting: "waits for an approval",
43
+ refused: "was refused: its plans changed after approval, so nothing in it was applied",
44
+ failed: "failed",
45
+ };
46
+
47
+ /** What happened to the wave: the first line, after `terragucci: `. */
48
+ export const summary = (n: WaveNotice): string => `wave ${n.wave} of ${n.project} ${HEADLINE[n.event]}`;
49
+
50
+ /** The first line of every message. */
51
+ export function headline(n: WaveNotice): string {
52
+ return `${NOTIFY_SOURCE}: ${summary(n)}`;
53
+ }
54
+
55
+ const rootsText = (n: WaveNotice): string => (n.roots.length > 0 ? n.roots.join(", ") : "see the run");
56
+
57
+ /** A Slack button. `url` makes it a link that opens a page. */
58
+ function slackButton(text: string, action: string, o: { value?: string; url?: string; style?: "primary" | "danger" }): Record<string, unknown> {
59
+ return { type: "button", action_id: action, text: { type: "plain_text", text }, ...(o.value ? { value: o.value } : {}), ...(o.url ? { url: o.url } : {}), ...(o.style ? { style: o.style } : {}) };
60
+ }
61
+
62
+ /**
63
+ * A Slack incoming webhook's body: one mrkdwn text. With the relay's signed
64
+ * button value (`relay`, which chant's sendNotify passes for a waiting wave
65
+ * when the relay key is set), the text as a block and chant's Approve and
66
+ * Decline buttons.
67
+ */
68
+ export function slackMessage(n: WaveNotice, relay?: RelayButtons): { text: string; blocks?: Record<string, unknown>[] } {
69
+ const text = slackText(n);
70
+ if (!n.relay || !relay || n.event !== "waiting") return { text };
71
+ return { text, blocks: [{ type: "section", text: { type: "mrkdwn", text } }, slackRelayActions(relay)] };
72
+ }
73
+
74
+ function slackText(n: WaveNotice): string {
75
+ return [
76
+ `*${headline(n)}*`,
77
+ ...(n.review ? [`Review and approve: <${n.review.url}|pull request ${n.review.pr}>, then run the wave again`] : []),
78
+ `Roots: ${rootsText(n)}`,
79
+ ...(n.digest ? [`Digest: \`${n.digest}\``] : []),
80
+ `${n.review ? "Or approve" : "Approve"}: \`${n.approve}\``,
81
+ ...(n.outcome ? [`Outcome: ${n.outcome}`] : []),
82
+ ...(n.run ? [`Run: <${n.run}>`] : []),
83
+ ...(n.report ? [`Report: <${n.report}>`] : []),
84
+ ].join("\n");
85
+ }
86
+
87
+ /** The Teams reply that approves or declines a waiting wave through the relay's outgoing webhook: a mention of the relay, then chant's reply. */
88
+ export const teamsReply = (n: Pick<WaveNotice, "relay">, relay: RelayButtons, action: "approve" | "decline"): string => `@${n.relay} ${teamsRelayReply(relay, action)}`;
89
+
90
+ /** A Teams incoming webhook's body (a Workflows webhook): one Adaptive Card. Its actions open the pull request's review page, under pr-review, and the run. */
91
+ export function teamsMessage(n: WaveNotice, relay?: RelayButtons): Record<string, unknown> {
92
+ const facts = [
93
+ { title: "Wave", value: String(n.wave) },
94
+ ...(n.review ? [{ title: "Review and approve", value: `pull request ${n.review.pr}, then run the wave again: ${n.review.url}` }] : []),
95
+ { title: "Roots", value: rootsText(n) },
96
+ ...(n.digest ? [{ title: "Digest", value: n.digest }] : []),
97
+ { title: n.review ? "Or approve" : "Approve", value: n.approve },
98
+ ...(n.outcome ? [{ title: "Outcome", value: n.outcome }] : []),
99
+ ...(n.run ? [{ title: "Run", value: n.run }] : []),
100
+ ];
101
+ return {
102
+ type: "message",
103
+ attachments: [
104
+ {
105
+ contentType: "application/vnd.microsoft.card.adaptive",
106
+ contentUrl: null,
107
+ content: {
108
+ $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
109
+ type: "AdaptiveCard",
110
+ version: "1.4",
111
+ body: [
112
+ { type: "TextBlock", text: headline(n), weight: "Bolder", wrap: true },
113
+ { type: "FactSet", facts },
114
+ // Teams has no button that reaches a relay without a registered bot, so the card gives the reply its outgoing webhook reads.
115
+ ...(n.relay && relay && n.event === "waiting"
116
+ ? [{ type: "TextBlock", wrap: true, text: `Approve here: reply ${teamsReply(n, relay, "approve")}. Decline: reply ${teamsReply(n, relay, "decline")}.` }]
117
+ : []),
118
+ ],
119
+ ...(n.review || n.run ? { actions: [...(n.review ? [{ type: "Action.OpenUrl", title: "Review and approve", url: n.review.url }] : []), ...(n.run ? [{ type: "Action.OpenUrl", title: "Open the run", url: n.run }] : [])] } : {}),
120
+ },
121
+ },
122
+ ],
123
+ };
124
+ }
125
+
126
+ export const driftHeadline = (n: DriftNotice): string =>
127
+ `terragucci: drift in ${n.project}: ${n.roots.length > 0 ? `${n.roots.length} root${n.roots.length === 1 ? "" : "s"} changed outside Terraform` : "no drift found"}${n.failed.length > 0 ? `, ${n.failed.length} could not be refreshed` : ""}`;
128
+
129
+ /** The drift notice for Slack: the text, and a Re-plan button that opens the page where the check runs again. */
130
+ export function slackDrift(n: DriftNotice): { text: string; blocks?: Record<string, unknown>[] } {
131
+ const text = [
132
+ `*${driftHeadline(n)}*`,
133
+ ...(n.roots.length > 0 ? [`Drifted: ${n.roots.join(", ")}`] : []),
134
+ ...(n.failed.length > 0 ? [`Not refreshed: ${n.failed.join(", ")}`] : []),
135
+ ...(n.run ? [`Run: <${n.run}>`] : []),
136
+ ...(n.report ? [`Report: <${n.report}>`] : []),
137
+ ].join("\n");
138
+ if (!n.replan) return { text };
139
+ return { text, blocks: [{ type: "section", text: { type: "mrkdwn", text } }, { type: "actions", block_id: "terragucci-drift", elements: [slackButton("Re-plan", REPLAN_ACTION, { url: n.replan })] }] };
140
+ }
141
+
142
+ /** The drift notice for Teams: an Adaptive Card whose Re-plan button opens the page where the check runs again. */
143
+ export function teamsDrift(n: DriftNotice): Record<string, unknown> {
144
+ const facts = [
145
+ ...(n.roots.length > 0 ? [{ title: "Drifted", value: n.roots.join(", ") }] : []),
146
+ ...(n.failed.length > 0 ? [{ title: "Not refreshed", value: n.failed.join(", ") }] : []),
147
+ ...(n.run ? [{ title: "Run", value: n.run }] : []),
148
+ ];
149
+ const actions = [...(n.replan ? [{ type: "Action.OpenUrl", title: "Re-plan", url: n.replan }] : []), ...(n.run ? [{ type: "Action.OpenUrl", title: "Open the run", url: n.run }] : [])];
150
+ return {
151
+ type: "message",
152
+ attachments: [
153
+ {
154
+ contentType: "application/vnd.microsoft.card.adaptive",
155
+ contentUrl: null,
156
+ content: {
157
+ $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
158
+ type: "AdaptiveCard",
159
+ version: "1.4",
160
+ body: [
161
+ { type: "TextBlock", text: driftHeadline(n), weight: "Bolder", wrap: true },
162
+ { type: "FactSet", facts },
163
+ ],
164
+ ...(actions.length > 0 ? { actions } : {}),
165
+ },
166
+ },
167
+ ],
168
+ };
169
+ }
170
+
@@ -1,7 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { readdirSync, readFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
- import { ACTION_PINS, pinAtMajor, pinMajor, tagComments, unpinnedActions, usesRef } from "./action-pins";
4
+ import { ACTION_PINS, CACHE4_PIN_FLOOR, pinAtMajor, pinMajor, tagComments, unpinnedActions, usesRef } from "./action-pins";
5
+ import { NEXT_RELEASE } from "./release-floors";
5
6
 
6
7
  describe("the action pin table", () => {
7
8
  it("holds a full commit SHA and a release of the row's major for every action", () => {
@@ -37,6 +38,16 @@ describe("the action pin table", () => {
37
38
  expect(pinAtMajor("0".repeat(40), "v3")).toBeUndefined();
38
39
  expect(pinMajor(ACTION_PINS.downloadArtifact4.sha)).toBe(4);
39
40
  });
41
+
42
+ it("pins actions/cache itself at v4, the commit its restore and save rows pin (#4816)", () => {
43
+ expect(ACTION_PINS.cache4).toEqual({ slug: "actions/cache", major: "v4", sha: "0057852bfaa89a56745cba8c7296529d2fc39830", tag: "v4.3.0" });
44
+ expect(usesRef(ACTION_PINS.cache4)).toBe("actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830");
45
+ expect(pinAtMajor(ACTION_PINS.cache6.sha, "v4")).toBe(ACTION_PINS.cache4);
46
+ // The restore row shares the commit; moving it keeps its own subpath.
47
+ expect(pinAtMajor(ACTION_PINS.cacheRestore4.sha, "v4")).toBe(ACTION_PINS.cacheRestore4);
48
+ expect(tagComments(` uses: ${usesRef(ACTION_PINS.cache4)}`)).toBe(` uses: ${usesRef(ACTION_PINS.cache4)} # v4.3.0`);
49
+ expect(CACHE4_PIN_FLOOR).toBe(NEXT_RELEASE);
50
+ });
40
51
  });
41
52
 
42
53
  // #4410: the places that are not generators pin too.
@@ -9,11 +9,21 @@
9
9
  * forgejo lexicon moves `upload-artifact` and `download-artifact` to v3, whose
10
10
  * rows are here too: v4 and later refuse to run on a Forgejo runner (#4008).
11
11
  *
12
+ * actions/cache has a v4 row beside v6 (#4816): terragucci's Terragrunt cache
13
+ * step uses the action itself at the commit the restore and save rows pin.
14
+ * It follows them in the table, so `pinAtMajor` on that shared commit still
15
+ * starts from the restore row.
16
+ *
12
17
  * Refresh a row by resolving the major tag to its commit:
13
18
  *
14
19
  * gh api repos/actions/checkout/commits/v6 --jq .sha
15
20
  */
16
21
 
22
+ import { NEXT_RELEASE } from "./release-floors";
23
+
24
+ /** The first chant whose table has the `cache4` row (#4816). */
25
+ export const CACHE4_PIN_FLOOR = NEXT_RELEASE;
26
+
17
27
  export interface ActionPin {
18
28
  /** The action, with its subpath: `actions/cache/restore`. */
19
29
  readonly slug: string;
@@ -47,6 +57,7 @@ export const ACTION_PINS = {
47
57
  createGithubAppToken2: pin("actions/create-github-app-token", "v2", "fee1f7d63c2ff003460e3d139729b119787bc349", "v2.2.2"),
48
58
  cacheRestore4: pin("actions/cache/restore", "v4", "0057852bfaa89a56745cba8c7296529d2fc39830", "v4.3.0"),
49
59
  cacheSave4: pin("actions/cache/save", "v4", "0057852bfaa89a56745cba8c7296529d2fc39830", "v4.3.0"),
60
+ cache4: pin("actions/cache", "v4", "0057852bfaa89a56745cba8c7296529d2fc39830", "v4.3.0"),
50
61
  uploadArtifact4: pin("actions/upload-artifact", "v4", "ea165f8d65b6e75b540449e92b4886f43607fa02", "v4.6.2"),
51
62
  uploadArtifact3: pin("actions/upload-artifact", "v3", "ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5", "v3.2.1"),
52
63
  downloadArtifact4: pin("actions/download-artifact", "v4", "d3f86a106a0bac45b974a628896c90dbdf5c8093", "v4.3.0"),
@@ -0,0 +1,319 @@
1
+ /**
2
+ * The agent guard (#4770), proven against both products' words and rules:
3
+ * terragucci's tests (its test/guard.test.ts) and plywood's ("the agent
4
+ * guard" in its test/agents.test.ts), ported to the shared code, and the
5
+ * cases where the two disagreed, settled on the stricter answer.
6
+ */
7
+ import { spawnSync } from "node:child_process";
8
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+ import { describe, expect, it, onTestFinished } from "vitest";
12
+ import { AGENT_GUARD_FLOOR, agentGuard, CLAUDE_SETTINGS_LOCAL, CLAUDE_SETTINGS_SHARED, installAgentGuard, withAgentGuardHook } from "./agent-guard";
13
+ import { PLYWOOD_GUARD } from "./__fixtures__/agent-guard/plywood";
14
+ import { TERRAGUCCI_GUARD } from "./__fixtures__/agent-guard/terragucci";
15
+
16
+ const tmp = (): string => mkdtempSync(join(tmpdir(), "chant-guard-"));
17
+ const git = (repo: string, ...args: string[]): string => {
18
+ const r = spawnSync("git", ["-C", repo, ...args], { encoding: "utf-8" });
19
+ if (r.status !== 0) throw new Error(r.stderr);
20
+ return r.stdout;
21
+ };
22
+
23
+ /** Stand-ins for the real binaries, logging their calls. */
24
+ function fakeBinaries(names: string[]): { dir: string; log: string } {
25
+ const dir = tmp();
26
+ const log = join(dir, "calls.log");
27
+ for (const b of names) {
28
+ writeFileSync(join(dir, b), `#!/bin/sh\necho "${b} $*" >> ${JSON.stringify(log)}\nexit 0\n`);
29
+ chmodSync(join(dir, b), 0o755);
30
+ }
31
+ return { dir, log };
32
+ }
33
+
34
+ function runner(bin: string, real: { dir: string; log: string }, env: NodeJS.ProcessEnv = process.env) {
35
+ return (name: string, args: string[], cwd: string) => {
36
+ const r = spawnSync(join(bin, name), args, { cwd, encoding: "utf-8", env: { ...env, PATH: `${bin}:${real.dir}:${process.env.PATH ?? ""}` } });
37
+ return { status: r.status, stderr: r.stderr, ran: existsSync(real.log) ? readFileSync(real.log, "utf-8") : "" };
38
+ };
39
+ }
40
+
41
+ function hookOf(script: string) {
42
+ return (command: string, cwd: string, env: NodeJS.ProcessEnv = process.env) => {
43
+ const r = spawnSync(process.execPath, [script, "hook"], { input: JSON.stringify({ tool_name: "Bash", tool_input: { command }, cwd }), encoding: "utf-8", env });
44
+ return { status: r.status, stderr: r.stderr };
45
+ };
46
+ }
47
+
48
+ const ROOTS = ["envs/dev/app", "envs/prod/app"];
49
+
50
+ /** terragucci's fixture: a repo with two pipeline roots and a directory that is not one, the guard written locally. */
51
+ function terragucci() {
52
+ const repo = tmp();
53
+ for (const d of [...ROOTS, "modules/net"]) mkdirSync(join(repo, d), { recursive: true });
54
+ writeFileSync(join(repo, "README.md"), "x\n");
55
+ git(repo, "init", "-q", "-b", "main");
56
+ const real = fakeBinaries(Object.keys(TERRAGUCCI_GUARD.rules.engines));
57
+ const g = installAgentGuard({ ...TERRAGUCCI_GUARD, repo, install: "local", roots: ROOTS });
58
+ return { repo, g, run: runner(g.bin, real), hook: hookOf(g.script) };
59
+ }
60
+
61
+ describe("AGENT_GUARD_FLOOR", () => {
62
+ it("names the next release", () => expect(AGENT_GUARD_FLOOR).toBe("0.124.77"));
63
+ });
64
+
65
+ describe("terragucci's guard: the wrappers", () => {
66
+ it("writes the wrappers and the script under the git directory, out of commits", () => {
67
+ const { repo, g } = terragucci();
68
+ const gitDir = git(repo, "rev-parse", "--absolute-git-dir").trim();
69
+ expect(g.script).toBe(join(gitDir, "terragucci", "guard", "guard.mjs"));
70
+ for (const b of ["tofu", "terraform", "terragrunt", "choudoufu"]) expect(existsSync(join(g.bin, b))).toBe(true);
71
+ expect(g.path).toBe(`export PATH="${g.bin}:$PATH"`);
72
+ expect(git(repo, "status", "--porcelain", "--untracked-files=all")).not.toMatch(/terragucci\/guard|settings\.local\.json/);
73
+ });
74
+
75
+ it("refuses apply, destroy and -auto-approve in a pipeline root, naming propose, and runs nothing", () => {
76
+ const { repo, run } = terragucci();
77
+ const root = join(repo, "envs/prod/app");
78
+ for (const args of [["apply"], ["destroy"], ["apply", "-auto-approve"], ["plan", "-auto-approve"], ["import", "aws_s3_bucket.b", "b"], ["state", "rm", "aws_s3_bucket.b"], ["state", "mv", "a", "b"], ["state", "push", "x.tfstate"]]) {
79
+ const r = run("tofu", args, root);
80
+ expect(r.status, args.join(" ")).toBe(3);
81
+ expect(r.stderr).toContain("terragucci guard: tofu");
82
+ expect(r.stderr).toContain("in envs/prod/app, a root of this repo's pipeline");
83
+ expect(r.stderr).toContain("the propose tool of terragucci mcp --propose");
84
+ }
85
+ expect(run("terraform", ["-chdir=envs/dev/app", "apply"], repo).status).not.toBe(0);
86
+ expect(run("tofu", ["-chdir", "envs/dev/app", "destroy"], repo).status).not.toBe(0);
87
+ expect(run("tofu", ["apply"], root).ran).toBe("");
88
+ });
89
+
90
+ it("passes init, validate, fmt, plan and state reads through to the real binary in a root", () => {
91
+ const { repo, run } = terragucci();
92
+ const root = join(repo, "envs/prod/app");
93
+ for (const args of [["init"], ["validate"], ["fmt", "-check"], ["plan", "-out=tfplan"], ["state", "list"], ["show", "-json"]]) expect(run("tofu", args, root).status, args.join(" ")).toBe(0);
94
+ expect(run("tofu", ["version"], root).ran).toBe(["tofu init", "tofu validate", "tofu fmt -check", "tofu plan -out=tfplan", "tofu state list", "tofu show -json", "tofu version", ""].join("\n"));
95
+ });
96
+
97
+ it("passes every command through outside the pipeline's roots", () => {
98
+ const { repo, run } = terragucci();
99
+ for (const cwd of [repo, join(repo, "modules/net"), tmp()]) {
100
+ expect(run("tofu", ["apply", "-auto-approve"], cwd).status, cwd).toBe(0);
101
+ expect(run("terraform", ["destroy"], cwd).status, cwd).toBe(0);
102
+ }
103
+ expect(run("tofu", ["version"], repo).ran.split("\n").filter(Boolean)).toHaveLength(7);
104
+ });
105
+
106
+ it("refuses terragrunt's --all and run-all apply from a directory that holds a root, and its plan", () => {
107
+ const { repo, run } = terragucci();
108
+ expect(run("terragrunt", ["run", "--all", "apply"], join(repo, "envs")).status).not.toBe(0);
109
+ expect(run("terragrunt", ["run-all", "destroy"], repo).status).not.toBe(0);
110
+ expect(run("terragrunt", ["apply"], join(repo, "envs/dev/app")).status).not.toBe(0);
111
+ expect(run("terragrunt", ["run", "--all", "plan"], join(repo, "envs")).status).toBe(0);
112
+ // Without --all, terragrunt applies the directory it runs in, which is no root here.
113
+ expect(run("terragrunt", ["apply"], join(repo, "envs")).status).toBe(0);
114
+ });
115
+ });
116
+
117
+ describe("terragucci's guard: the hook", () => {
118
+ it("writes a PreToolUse hook into Claude Code's local settings, kept out of commits, and keeps what else the file holds", () => {
119
+ const saved = { GIT_CONFIG_GLOBAL: process.env.GIT_CONFIG_GLOBAL, XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME };
120
+ process.env.GIT_CONFIG_GLOBAL = "/dev/null";
121
+ process.env.XDG_CONFIG_HOME = tmp();
122
+ onTestFinished(() => {
123
+ for (const [k, v] of Object.entries(saved)) if (v === undefined) delete process.env[k];
124
+ else process.env[k] = v;
125
+ });
126
+ const { repo, g } = terragucci();
127
+ const settings = JSON.parse(readFileSync(join(repo, CLAUDE_SETTINGS_LOCAL), "utf-8"));
128
+ expect(settings.hooks.PreToolUse).toEqual([{ matcher: "Bash", hooks: [{ type: "command", command: `"${process.execPath}" "${g.script}" hook` }] }]);
129
+ expect(readFileSync(join(repo, ".git/info/exclude"), "utf-8")).toContain(`/${CLAUDE_SETTINGS_LOCAL}`);
130
+ writeFileSync(join(repo, CLAUDE_SETTINGS_LOCAL), JSON.stringify({ ...settings, permissions: { allow: ["Bash(ls)"] } }));
131
+ installAgentGuard({ ...TERRAGUCCI_GUARD, repo, install: "local", roots: ROOTS });
132
+ const again = JSON.parse(readFileSync(join(repo, CLAUDE_SETTINGS_LOCAL), "utf-8"));
133
+ expect(again.permissions).toEqual({ allow: ["Bash(ls)"] });
134
+ expect(again.hooks.PreToolUse).toHaveLength(1);
135
+ expect(readFileSync(join(repo, ".git/info/exclude"), "utf-8").split(`/${CLAUDE_SETTINGS_LOCAL}`)).toHaveLength(2);
136
+ });
137
+
138
+ it("blocks the same commands in the agent's Bash tool with exit 2, following cd and sh -c", () => {
139
+ const { repo, hook } = terragucci();
140
+ for (const [command, cwd] of [
141
+ ["cd envs/prod/app && tofu apply", repo],
142
+ ["tofu -chdir=envs/dev/app destroy", repo],
143
+ ["AWS_PROFILE=prod terraform apply -auto-approve", join(repo, "envs/prod/app")],
144
+ ["bash -c 'cd envs/dev/app; tofu apply'", repo],
145
+ ["/usr/local/bin/tofu state rm aws_s3_bucket.b", join(repo, "envs/dev/app")],
146
+ ["npx terragucci approve wave-1 --plan sha256:abc", repo],
147
+ ["npx -y @intentius/terragucci override envs/prod/app --rule r --reason x", repo],
148
+ ["npx @intentius/terragucci@0.4.35 pr-merge --pr 7 --sha abc", repo],
149
+ ["terragucci stage tf-apply --wave 1 --layers envs/prod/app", repo],
150
+ ["npx terragucci rollout net --mode apply", repo],
151
+ ] as const) {
152
+ const r = hook(command, cwd);
153
+ expect(r.status, command).toBe(2);
154
+ expect(r.stderr).toContain("propose");
155
+ }
156
+ });
157
+
158
+ it("lets plans, reads and everything outside the repo's roots through", () => {
159
+ const { repo, g, hook } = terragucci();
160
+ for (const [command, cwd] of [
161
+ ["cd envs/prod/app && tofu init && tofu plan -out=p", repo],
162
+ ["tofu apply", repo],
163
+ ["tofu apply -auto-approve", tmp()],
164
+ ["git commit -m 'apply the fix'", repo],
165
+ ["echo apply", join(repo, "envs/prod/app")],
166
+ ["npx terragucci plan --json", repo],
167
+ ["npx terragucci approve wave-1", tmp()],
168
+ ] as const) expect(hook(command, cwd).status, command).toBe(0);
169
+ expect(spawnSync(process.execPath, [g.script, "hook"], { input: "not json", encoding: "utf-8" }).status).toBe(0);
170
+ });
171
+
172
+ it("refuses to rewrite a settings file that is not JSON, or not an object", () => {
173
+ expect(() => withAgentGuardHook("{ nope", "x", CLAUDE_SETTINGS_LOCAL)).toThrow(/is not JSON/);
174
+ expect(() => withAgentGuardHook("[]", "x", CLAUDE_SETTINGS_LOCAL)).toThrow(/not a JSON object/);
175
+ class ConfigError extends Error {}
176
+ expect(() => withAgentGuardHook("{ nope", "x", CLAUDE_SETTINGS_LOCAL, [], (m) => new ConfigError(m))).toThrow(ConfigError);
177
+ expect(JSON.parse(withAgentGuardHook(undefined, "x", CLAUDE_SETTINGS_LOCAL)).hooks.PreToolUse[0].hooks[0].command).toBe("x");
178
+ });
179
+
180
+ it("says it needs a git checkout for a local install", () => {
181
+ expect(() => installAgentGuard({ ...TERRAGUCCI_GUARD, repo: tmp(), install: "local", roots: [] })).toThrow(/terragucci guard runs in a git checkout/);
182
+ });
183
+ });
184
+
185
+ describe("plywood's guard", () => {
186
+ const refused = ["pulumi up", "pulumi up --yes --stack dev", "cd shop && pulumi -C infra up", "npx plunge up", "FOO=1 pulumi destroy -y", "/usr/local/bin/pulumi update", "env -i pulumi up"];
187
+ const allowed = ["pulumi preview", "pulumi stack ls", "plunge drift --resource urn:x", "git commit -m 'pulumi up later'", "plywood preview", "echo pulumi"];
188
+
189
+ /** plywood's fixture: the guard written into a project's `.claude/`, refused anywhere. */
190
+ function plywood() {
191
+ const repo = tmp();
192
+ mkdirSync(join(repo, ".claude"));
193
+ writeFileSync(join(repo, CLAUDE_SETTINGS_SHARED), JSON.stringify({ permissions: { allow: ["Bash(ls)"] } }));
194
+ const g = installAgentGuard({ ...PLYWOOD_GUARD, repo, install: "project" });
195
+ return { repo, g, hook: hookOf(g.script) };
196
+ }
197
+
198
+ it("refuses an update or destroy, and lets every read through", () => {
199
+ const guard = agentGuard(PLYWOOD_GUARD, { repo: tmp() });
200
+ for (const line of refused) expect(guard.checkCommand(line, guard.repo), line).toBeDefined();
201
+ for (const line of allowed) expect(guard.checkCommand(line, guard.repo), line).toBeUndefined();
202
+ expect(guard.checkCommand("pulumi up", guard.repo)).toMatchObject({ bin: "pulumi", command: "up", message: "plywood guard: an agent session does not run 'pulumi up'. Open a pull request; plywood previews it, and the update runs after a person approves the digest." });
203
+ });
204
+
205
+ it("gives the same answers in the hook it writes, from any directory", () => {
206
+ const { repo, hook } = plywood();
207
+ for (const line of [...refused, ...allowed]) for (const cwd of [repo, tmp()]) expect(hook(line, cwd).status === 2, `${line} in ${cwd}`).toBe(refused.includes(line));
208
+ });
209
+
210
+ it("blocks pulumi up in a fixture Claude Code session (exit 2), with the hook as plywood's settings name it", () => {
211
+ const { repo, g } = plywood();
212
+ const settings = JSON.parse(readFileSync(join(repo, CLAUDE_SETTINGS_SHARED), "utf-8"));
213
+ const command = settings.hooks.PreToolUse[0].hooks[0].command as string;
214
+ expect(command).toBe('node "$CLAUDE_PROJECT_DIR/.claude/hooks/plywood-guard.mjs" hook');
215
+ expect(g.written).toEqual([".claude/hooks/plywood-guard.mjs", ".plywood/agent-bin/pulumi", ".plywood/agent-bin/plunge", ".claude/settings.json"]);
216
+ const call = (c: string) => spawnSync("sh", ["-c", command], { input: JSON.stringify({ tool_name: "Bash", tool_input: { command: c } }), encoding: "utf-8", env: { ...process.env, CLAUDE_PROJECT_DIR: repo } });
217
+ const blocked = call("pulumi up --yes");
218
+ expect(blocked.status).toBe(2);
219
+ expect(blocked.stderr).toContain("pull request");
220
+ expect(call("pulumi preview").status).toBe(0);
221
+ });
222
+
223
+ it("installs the hook once into .claude/settings.json and keeps the rest", () => {
224
+ const { repo } = plywood();
225
+ installAgentGuard({ ...PLYWOOD_GUARD, repo, install: "project" });
226
+ const settings = JSON.parse(readFileSync(join(repo, CLAUDE_SETTINGS_SHARED), "utf-8"));
227
+ expect(settings.permissions).toEqual({ allow: ["Bash(ls)"] });
228
+ expect(settings.hooks.PreToolUse).toHaveLength(1);
229
+ expect(JSON.parse(withAgentGuardHook(JSON.stringify(settings), settings.hooks.PreToolUse[0].hooks[0].command, CLAUDE_SETTINGS_SHARED))).toEqual(settings);
230
+ });
231
+
232
+ it("replaces the hook an earlier plywood guard install wrote", () => {
233
+ const old = { hooks: { PreToolUse: [{ matcher: "Bash", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.claude/hooks/plywood-guard.mjs"' }] }] } };
234
+ const next = JSON.parse(withAgentGuardHook(JSON.stringify(old), 'node "$CLAUDE_PROJECT_DIR/.claude/hooks/plywood-guard.mjs" hook', CLAUDE_SETTINGS_SHARED, ["plywood-guard.mjs"]));
235
+ expect(next.hooks.PreToolUse).toEqual([{ matcher: "Bash", hooks: [{ type: "command", command: 'node "$CLAUDE_PROJECT_DIR/.claude/hooks/plywood-guard.mjs" hook' }] }]);
236
+ });
237
+
238
+ it("writes wrappers that refuse with plywood's exit code, without PLYWOOD_AGENT_GUARD set, and run the real pulumi for the rest", () => {
239
+ const { repo, g } = plywood();
240
+ const real = fakeBinaries(["pulumi", "plunge"]);
241
+ const env = { ...process.env };
242
+ delete env.PLYWOOD_AGENT_GUARD;
243
+ delete env.CLAUDECODE;
244
+ const run = runner(g.bin, real, env);
245
+ const up = run("pulumi", ["--stack", "dev", "up", "--yes"], repo);
246
+ expect(up.status).toBe(1);
247
+ expect(up.stderr).toContain("plywood guard: an agent session does not run 'pulumi up'");
248
+ expect(run("plunge", ["destroy"], tmp()).status).toBe(1);
249
+ expect(run("pulumi", ["preview"], repo).status).toBe(0);
250
+ expect(run("pulumi", ["stack", "ls"], repo).ran).toBe("pulumi preview\npulumi stack ls\n");
251
+ });
252
+ });
253
+
254
+ describe("the script", () => {
255
+ it("runs when chant runs from source under tsx, whose keepNames wraps the rule's functions in __name", () => {
256
+ const repo = tmp();
257
+ const code = `import { installAgentGuard } from ${JSON.stringify(join(__dirname, "agent-guard.ts"))}; import { PLYWOOD_GUARD } from ${JSON.stringify(join(__dirname, "__fixtures__/agent-guard/plywood.ts"))}; installAgentGuard({ ...PLYWOOD_GUARD, repo: ${JSON.stringify(repo)}, install: "project" });`;
258
+ const w = spawnSync(process.execPath, ["--import", "tsx", "--input-type=module", "-e", code], { encoding: "utf-8" });
259
+ expect(w.status, w.stderr).toBe(0);
260
+ const script = join(repo, ".claude/hooks/plywood-guard.mjs");
261
+ expect(readFileSync(script, "utf-8")).toContain("__name(");
262
+ expect(hookOf(script)("pulumi up", repo).status).toBe(2);
263
+ expect(hookOf(script)("pulumi preview", repo).status).toBe(0);
264
+ });
265
+ });
266
+
267
+ describe("where the two guards disagreed: the stricter answer", () => {
268
+ const ply = () => agentGuard(PLYWOOD_GUARD, { repo: tmp() });
269
+ const tg = () => {
270
+ const repo = tmp();
271
+ for (const d of ROOTS) mkdirSync(join(repo, d), { recursive: true });
272
+ return { repo, guard: agentGuard(TERRAGUCCI_GUARD, { repo, roots: ROOTS }) };
273
+ };
274
+
275
+ it("follows sh -c, bash -lc and eval, which plywood's guard let through", () => {
276
+ const g = ply();
277
+ for (const line of ["bash -c 'pulumi up'", "sh -c \"cd x && pulumi destroy\"", "bash -lc 'pulumi up'", "eval pulumi up", "eval 'pulumi up --yes'"]) expect(g.checkCommand(line, g.repo), line).toBeDefined();
278
+ });
279
+
280
+ it("skips a launcher's flags, which terragucci's guard read as the command", () => {
281
+ const { repo, guard } = tg();
282
+ for (const line of ["env -i tofu apply", "env -u AWS_PROFILE tofu apply", "sudo -u ops tofu destroy", "nice -n 5 terraform apply", "xargs tofu apply", "command -p tofu apply"]) expect(guard.checkCommand(line, join(repo, "envs/dev/app")), line).toBeDefined();
283
+ });
284
+
285
+ it("finds the command after npx's flags, which plywood's guard did not", () => {
286
+ const g = ply();
287
+ for (const line of ["npx -y plunge up", "npx --yes pulumi destroy", "npx -p @pulumi/cli pulumi up", "bunx plunge up"]) expect(g.checkCommand(line, g.repo), line).toBeDefined();
288
+ });
289
+
290
+ it("skips a flag's value before the subcommand, which terragucci's guard read as the subcommand", () => {
291
+ const g = ply();
292
+ expect(g.checkCommand("pulumi --stack dev up", g.repo)).toBeDefined();
293
+ expect(g.checkCommand("pulumi -C infra destroy", g.repo)).toBeDefined();
294
+ });
295
+
296
+ it("refuses the product's own applying commands, which plywood's guard let through", () => {
297
+ const g = ply();
298
+ for (const line of ["plywood up", "npx @intentius/plywood approve up --plan sha256:x", "plywood override dev --rule r --reason x", "plywood resume --wave 1", "plywood drift --respond up", "plywood cancel dev"]) expect(g.checkCommand(line, g.repo), line).toBeDefined();
299
+ for (const line of ["plywood preview", "plywood drift --respond issue", "plywood guard check pulumi up", "plywood audit"]) expect(g.checkCommand(line, g.repo), line).toBeUndefined();
300
+ });
301
+
302
+ it("reads a quoted separator as text, not a second command", () => {
303
+ const g = ply();
304
+ expect(g.checkCommand('echo "done; pulumi up later"', g.repo)).toBeUndefined();
305
+ expect(g.checkCommand("echo ok; pulumi up", g.repo)).toBeDefined();
306
+ expect(g.checkCommand("echo $(pulumi up)", g.repo)).toBeDefined();
307
+ expect(g.checkCommand("echo `pulumi destroy`", g.repo)).toBeDefined();
308
+ });
309
+
310
+ it("keeps roots a product rule: refused anywhere without them, only in a root with them, nowhere with none", () => {
311
+ const { repo, guard } = tg();
312
+ expect(guard.checkCommand("tofu apply", repo)).toBeUndefined();
313
+ expect(guard.checkCommand("tofu apply", join(repo, "envs/dev/app"))).toMatchObject({ where: "envs/dev/app" });
314
+ const anywhere = agentGuard(TERRAGUCCI_GUARD, { repo });
315
+ expect(anywhere.checkCommand("tofu apply", tmp())).toMatchObject({ what: "tofu apply" });
316
+ expect(anywhere.checkCommand("tofu apply", tmp())!.message).not.toContain(" in ");
317
+ expect(agentGuard(TERRAGUCCI_GUARD, { repo, roots: [] }).checkCommand("tofu apply", join(repo, "envs/dev/app"))).toBeUndefined();
318
+ });
319
+ });