@intentius/chant 0.124.78 → 0.124.80
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.
- package/dist/action-pins.d.ts.map +1 -1
- package/dist/action-pins.js +1 -2
- package/dist/change-set.d.ts +10 -1
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +4 -1
- package/dist/ci-agent.d.ts +16 -2
- package/dist/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +6 -1
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +2 -3
- package/dist/ci-note-commands.d.ts +199 -0
- package/dist/ci-note-commands.d.ts.map +1 -0
- package/dist/ci-note-commands.js +372 -0
- package/dist/ci-product.d.ts +6 -2
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +5 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +7 -1
- package/dist/cli/handlers/pr-notes.d.ts +13 -0
- package/dist/cli/handlers/pr-notes.d.ts.map +1 -0
- package/dist/cli/handlers/pr-notes.js +73 -0
- package/dist/cli/handlers/release.d.ts +8 -0
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +64 -2
- package/dist/cli/handlers/run-wave.js +1 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +17 -1
- package/dist/cli/mcp/product-tools.d.ts +6 -0
- package/dist/cli/mcp/product-tools.d.ts.map +1 -1
- package/dist/cli/mcp/product-tools.js +6 -0
- package/dist/cli/mcp/read-only.d.ts +12 -0
- package/dist/cli/mcp/read-only.d.ts.map +1 -1
- package/dist/cli/mcp/read-only.js +16 -0
- package/dist/cli/mcp/server.d.ts +11 -0
- package/dist/cli/mcp/server.d.ts.map +1 -1
- package/dist/cli/mcp/server.js +26 -5
- package/dist/cli/mcp/types.d.ts +5 -1
- package/dist/cli/mcp/types.d.ts.map +1 -1
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +10 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/capability.d.ts +53 -0
- package/dist/components/capability.d.ts.map +1 -1
- package/dist/components/group-digest.d.ts +17 -0
- package/dist/components/group-digest.d.ts.map +1 -0
- package/dist/components/group-digest.js +18 -0
- package/dist/components/groups.d.ts +2 -11
- package/dist/components/groups.d.ts.map +1 -1
- package/dist/components/groups.js +2 -12
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/pr-pipeline.d.ts +22 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +26 -0
- package/dist/components/product-pipeline.d.ts +12 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +5 -1
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +1 -2
- package/dist/lifecycle/release-cut.d.ts +7 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +1 -0
- package/dist/lifecycle/release-images.d.ts +12 -3
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +6 -7
- package/dist/lifecycle/release-publish.d.ts +8 -1
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/lifecycle/release-publish.js +30 -3
- package/dist/lifecycle/release-version.d.ts +86 -0
- package/dist/lifecycle/release-version.d.ts.map +1 -0
- package/dist/lifecycle/release-version.js +208 -0
- package/dist/mcp/types.d.ts +26 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +1 -2
- package/dist/op/activities/review-product.d.ts.map +1 -1
- package/dist/op/activities/review-product.js +1 -2
- package/dist/op/gate.d.ts +17 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +36 -0
- package/dist/op/index.d.ts +8 -6
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +5 -4
- package/dist/op/op-waves-after-plan.d.ts +109 -1
- package/dist/op/op-waves-after-plan.d.ts.map +1 -1
- package/dist/op/op-waves-after-plan.js +180 -3
- package/dist/op/op-waves-capability-spec.js +1 -2
- package/dist/op/op-waves-capability.d.ts +93 -3
- package/dist/op/op-waves-capability.d.ts.map +1 -1
- package/dist/op/op-waves-capability.js +218 -10
- package/dist/op/op-waves-run-hooks.d.ts +104 -0
- package/dist/op/op-waves-run-hooks.d.ts.map +1 -0
- package/dist/op/op-waves-run-hooks.js +145 -0
- package/dist/op/op-waves-run.d.ts +21 -0
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +307 -21
- package/dist/op/op-waves.d.ts +11 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +7 -1
- package/dist/op/runtime.d.ts +2 -0
- package/dist/op/runtime.d.ts.map +1 -1
- package/dist/pr-forge-reads.d.ts +151 -1
- package/dist/pr-forge-reads.d.ts.map +1 -1
- package/dist/pr-forge-reads.js +265 -1
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +1 -2
- package/dist/release-floors.d.ts +19 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +23 -5
- package/dist/wave-runtime.mjs +312 -312
- package/dist/workspace/change-set.schema.json +7 -0
- package/dist/workspace/release-workflow.d.ts +7 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +11 -1
- package/package.json +1 -1
- package/src/action-pins.test.ts +1 -2
- package/src/action-pins.ts +1 -3
- package/src/change-set.test.ts +20 -0
- package/src/change-set.ts +11 -1
- package/src/ci-agent.test.ts +9 -0
- package/src/ci-agent.ts +15 -2
- package/src/ci-commit.test.ts +2 -3
- package/src/ci-commit.ts +2 -3
- package/src/ci-note-commands.test.ts +377 -0
- package/src/ci-note-commands.ts +479 -0
- package/src/ci-product.ts +6 -2
- package/src/cli/handlers/build.ts +7 -1
- package/src/cli/handlers/pr-notes.ts +70 -0
- package/src/cli/handlers/release.ts +55 -2
- package/src/cli/handlers/run-wave.ts +1 -0
- package/src/cli/main.ts +17 -1
- package/src/cli/mcp/product-tools.test.ts +49 -0
- package/src/cli/mcp/product-tools.ts +7 -0
- package/src/cli/mcp/read-only.ts +19 -0
- package/src/cli/mcp/server.test.ts +30 -0
- package/src/cli/mcp/server.ts +28 -5
- package/src/cli/mcp/types.ts +6 -1
- package/src/cli/parse-args.ts +8 -0
- package/src/cli/registry.ts +4 -0
- package/src/components/capability.ts +52 -0
- package/src/components/group-digest.ts +20 -0
- package/src/components/groups.ts +3 -13
- package/src/components/index.ts +2 -0
- package/src/components/pr-pipeline.ts +35 -0
- package/src/components/product-pipeline.test.ts +14 -0
- package/src/components/product-pipeline.ts +13 -1
- package/src/config.ts +15 -0
- package/src/lexicon.ts +1 -2
- package/src/lifecycle/release-cut.ts +11 -0
- package/src/lifecycle/release-images-dockerfile.test.ts +10 -2
- package/src/lifecycle/release-images.ts +12 -8
- package/src/lifecycle/release-publish.ts +34 -3
- package/src/lifecycle/release-version.test.ts +155 -0
- package/src/lifecycle/release-version.ts +226 -0
- package/src/mcp/types.ts +27 -0
- package/src/notify-message-words.test.ts +1 -2
- package/src/notify-product.ts +1 -2
- package/src/op/activities/review-product.ts +1 -2
- package/src/op/gate.ts +46 -0
- package/src/op/index.ts +10 -4
- package/src/op/op-waves-after-plan-wave.test.ts +225 -0
- package/src/op/op-waves-after-plan.ts +228 -5
- package/src/op/op-waves-capability-spec.ts +1 -1
- package/src/op/op-waves-capability.test.ts +9 -1
- package/src/op/op-waves-capability.ts +246 -13
- package/src/op/op-waves-gate-port.test.ts +232 -0
- package/src/op/op-waves-run-hooks.test.ts +183 -0
- package/src/op/op-waves-run-hooks.ts +194 -0
- package/src/op/op-waves-run.ts +313 -25
- package/src/op/op-waves-step-wave.test.ts +276 -0
- package/src/op/op-waves.ts +15 -2
- package/src/op/runtime.ts +2 -0
- package/src/pr-forge-reads-compare.test.ts +145 -0
- package/src/pr-forge-reads.test.ts +203 -0
- package/src/pr-forge-reads.ts +398 -1
- package/src/pr-plan-note.ts +1 -2
- package/src/release-floors.ts +32 -5
- package/src/workspace/change-set.schema.json +7 -0
- package/src/workspace/release-workflow.test.ts +18 -0
- package/src/workspace/release-workflow.ts +21 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The after-plan hook's wave answer (#4842): what a product adds to the wave
|
|
3
|
+
* as a whole once it read every run's plan. Pending fact fields, digest
|
|
4
|
+
* members that are no run, holds, overriders, and the gate report chant
|
|
5
|
+
* stores beside the pending fact.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, test } from "vitest";
|
|
9
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import type { OpWavesSpec } from "./op-waves";
|
|
13
|
+
import { runOpWave, opWaveSetDigest, type OpWaveShowAtBase } from "./op-waves-run";
|
|
14
|
+
import { memoryGateLedgerPort, opWaveGateReportPath } from "./gate";
|
|
15
|
+
import { CapabilityRegistry, type Capability } from "../components/capability";
|
|
16
|
+
import type { ChangeSetPart } from "../change-set";
|
|
17
|
+
import { opWaveAfterPlanWaveResultProblems, opWaveAfterPlanResultProblems, type OpWaveAfterPlanWave } from "./op-waves-after-plan";
|
|
18
|
+
|
|
19
|
+
const digest = (n: string) => `sha256:${n.repeat(64)}`;
|
|
20
|
+
const NOW = "2026-11-08T00:00:00.000Z";
|
|
21
|
+
|
|
22
|
+
const part = (member: string): ChangeSetPart => ({
|
|
23
|
+
member: { member, lexicon: "terraform", planner: "chant", status: "planned", planDigest: digest("9"), holes: [] },
|
|
24
|
+
entries: [{ member, address: `aws_s3_bucket.${member}`, type: "aws_s3_bucket", action: "create" } as ChangeSetPart["entries"][number]],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function capability(digests: Record<string, string>): { registry: CapabilityRegistry; ran: string[] } {
|
|
28
|
+
const ran: string[] = [];
|
|
29
|
+
const cap: Capability<Record<string, unknown>, unknown> = {
|
|
30
|
+
kind: "fake-apply",
|
|
31
|
+
async plan(_ctx, input) {
|
|
32
|
+
const root = String(input.root);
|
|
33
|
+
return { member: root, planDigest: digests[root]!, artifact: { planFile: `${root}.tfplan` }, changeSet: part(root) };
|
|
34
|
+
},
|
|
35
|
+
async run(_ctx, input) {
|
|
36
|
+
ran.push(String(input.root));
|
|
37
|
+
return {};
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
return { registry: new CapabilityRegistry().register(cap), ran };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const base = (gate: "never" | "always"): OpWavesSpec => ({
|
|
44
|
+
name: "tf-apply",
|
|
45
|
+
op: "tf-apply",
|
|
46
|
+
gateName: "wave-{k}",
|
|
47
|
+
step: { kind: "fake-apply", root: "{target}" },
|
|
48
|
+
waves: [{ name: "wave-1", runs: [{ target: "network" }, { target: "app" }], gate }],
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const digests = { network: digest("1"), app: digest("2") };
|
|
52
|
+
|
|
53
|
+
function harness(spec: OpWavesSpec) {
|
|
54
|
+
const cwd = mkdtempSync(join(tmpdir(), "op-waves-wave-answer-"));
|
|
55
|
+
const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(spec) });
|
|
56
|
+
return { cwd, show, done: () => rmSync(cwd, { recursive: true, force: true }) };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe("the after-plan hook's wave answer (#4842)", () => {
|
|
60
|
+
test("pending fields, digest members and holds: the wave waits whatever its gate, and its digest covers the members", async () => {
|
|
61
|
+
const spec = base("never");
|
|
62
|
+
const h = harness(spec);
|
|
63
|
+
const { registry, ran } = capability(digests);
|
|
64
|
+
const gates = memoryGateLedgerPort();
|
|
65
|
+
const seen: OpWaveAfterPlanWave[] = [];
|
|
66
|
+
const cost = { member: "(monthly cost)", planDigest: digest("7") };
|
|
67
|
+
const result = await runOpWave({
|
|
68
|
+
spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates, capabilities: registry, now: NOW, log: () => {},
|
|
69
|
+
afterPlan: {
|
|
70
|
+
name: "terragucci",
|
|
71
|
+
run: () => {},
|
|
72
|
+
wave: (w) => {
|
|
73
|
+
seen.push(w);
|
|
74
|
+
return { pending: { description: "wave 1 of 1: network, app", commit: "c".repeat(40) }, members: [cost], holds: ["app reads network's vpc_id, unknown when the change was reviewed"] };
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
expect(seen.map((w) => [w.wave, w.job, w.runs.map((r) => r.target)])).toEqual([[1, "wave", ["network", "app"]]]);
|
|
79
|
+
expect(result.exitCode).toBe(3);
|
|
80
|
+
expect(ran).toEqual([]);
|
|
81
|
+
expect(result.decision?.heldBy).toEqual(["app reads network's vpc_id, unknown when the change was reviewed"]);
|
|
82
|
+
expect(result.decision?.extras).toEqual([cost]);
|
|
83
|
+
const members = [{ member: "network", planDigest: digests.network }, { member: "app", planDigest: digests.app }];
|
|
84
|
+
expect(result.decision?.digest).toBe(opWaveSetDigest(spec, members, [cost]));
|
|
85
|
+
expect(gates.appended[0]).toMatchObject({ op: "tf-apply", gate: "wave-1", description: "wave 1 of 1: network, app", commit: "c".repeat(40) });
|
|
86
|
+
h.done();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("the report is stored beside the pending fact it asks approval for, once", async () => {
|
|
90
|
+
const spec = base("always");
|
|
91
|
+
const h = harness(spec);
|
|
92
|
+
const { registry } = capability(digests);
|
|
93
|
+
const gates = memoryGateLedgerPort();
|
|
94
|
+
const go = (report: string) =>
|
|
95
|
+
runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates, capabilities: registry, now: NOW, log: () => {}, afterPlan: { name: "terragucci", run: () => {}, wave: () => ({ report }) } });
|
|
96
|
+
const first = await go('{"roots":["network","app"]}');
|
|
97
|
+
expect(first.exitCode).toBe(3);
|
|
98
|
+
const at = opWaveGateReportPath("tf-apply", "wave-1", first.decision!.digest);
|
|
99
|
+
expect(at).toBe(`_gates/tf-apply/wave-1/${first.decision!.digest.replace(":", "_")}.json`);
|
|
100
|
+
expect(gates.reports.get(at)).toBe('{"roots":["network","app"]}');
|
|
101
|
+
const again = await go('{"roots":["changed"]}');
|
|
102
|
+
expect(again.decision!.digest).toBe(first.decision!.digest);
|
|
103
|
+
expect(gates.reports.get(at)).toBe('{"roots":["network","app"]}');
|
|
104
|
+
h.done();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("a wave that needs no approval stores no report", async () => {
|
|
108
|
+
const spec = base("never");
|
|
109
|
+
const h = harness(spec);
|
|
110
|
+
const { registry, ran } = capability(digests);
|
|
111
|
+
const gates = memoryGateLedgerPort();
|
|
112
|
+
const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates, capabilities: registry, now: NOW, log: () => {}, afterPlan: { name: "terragucci", run: () => {}, wave: () => ({ report: "{}" }) } });
|
|
113
|
+
expect(result.exitCode).toBe(0);
|
|
114
|
+
expect(ran).toEqual(["network", "app"]);
|
|
115
|
+
expect(gates.reports.size).toBe(0);
|
|
116
|
+
h.done();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("after an approval of other plans, the report of the plans now and of the plans approved are written for the respond job", async () => {
|
|
120
|
+
const spec = base("always");
|
|
121
|
+
const h = harness(spec);
|
|
122
|
+
const { registry } = capability(digests);
|
|
123
|
+
const was = digest("9");
|
|
124
|
+
const gates = memoryGateLedgerPort({ resolutions: [{ version: 1, op: "tf-apply", gate: "wave-1", resolvedBy: "alice", timestamp: "2026-11-07T00:00:00Z", planDigest: was }] });
|
|
125
|
+
gates.reports.set(opWaveGateReportPath("tf-apply", "wave-1", was), '{"roots":["network"]}');
|
|
126
|
+
const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates, capabilities: registry, now: NOW, log: () => {}, afterPlan: { name: "terragucci", run: () => {}, wave: () => ({ report: '{"roots":["network","app"]}' }) } });
|
|
127
|
+
expect(result.exitCode).toBe(3);
|
|
128
|
+
expect(result.decision?.mismatch).toMatchObject({ approved: was, resolvedBy: "alice" });
|
|
129
|
+
expect(result.decision?.reports).toEqual({ current: ".chant/op-waves/tf-apply/wave-1/report/current.json", approved: ".chant/op-waves/tf-apply/wave-1/report/approved.json" });
|
|
130
|
+
expect(readFileSync(join(h.cwd, result.decision!.reports!.current), "utf-8")).toBe('{"roots":["network","app"]}');
|
|
131
|
+
expect(readFileSync(join(h.cwd, result.decision!.reports!.approved!), "utf-8")).toBe('{"roots":["network"]}');
|
|
132
|
+
h.done();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("with no report kept for the plans approved, only the report of the plans now is written", async () => {
|
|
136
|
+
const spec = base("always");
|
|
137
|
+
const h = harness(spec);
|
|
138
|
+
const { registry } = capability(digests);
|
|
139
|
+
const gates = memoryGateLedgerPort({ resolutions: [{ version: 1, op: "tf-apply", gate: "wave-1", resolvedBy: "alice", timestamp: "2026-11-07T00:00:00Z", planDigest: digest("9") }] });
|
|
140
|
+
const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates, capabilities: registry, now: NOW, log: () => {}, afterPlan: { name: "terragucci", run: () => {}, wave: () => ({ report: "{}" }) } });
|
|
141
|
+
expect(result.decision?.reports).toEqual({ current: ".chant/op-waves/tf-apply/wave-1/report/current.json" });
|
|
142
|
+
expect(existsSync(join(h.cwd, ".chant/op-waves/tf-apply/wave-1/report/approved.json"))).toBe(false);
|
|
143
|
+
h.done();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("the wave answer's overriders replace the list at base, and a run's own overriders replace them for that run", async () => {
|
|
147
|
+
const { overrideDigest } = await import("../override-gate");
|
|
148
|
+
const spec = base("never");
|
|
149
|
+
const od = overrideDigest("app", digests.app, ["no-public-s3"]);
|
|
150
|
+
const override = { version: 1 as const, op: "policy-override", gate: "app", resolvedBy: "github:carol", timestamp: "2026-11-07T00:00:00Z", planDigest: od, note: "the bucket is the public docs site" };
|
|
151
|
+
const deny = (target: string) => ({ policy: target === "app" ? [{ source: "terragucci", result: "denied" as const, rules: ["no-public-s3"] }] : [] });
|
|
152
|
+
// The wave's list names someone else: carol's override does not count.
|
|
153
|
+
const h = harness(spec);
|
|
154
|
+
const { registry, ran } = capability(digests);
|
|
155
|
+
const refused = await runOpWave({
|
|
156
|
+
spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates: memoryGateLedgerPort({ resolutions: [override] }), capabilities: registry, now: NOW, log: () => {},
|
|
157
|
+
afterPlan: { name: "terragucci", run: (r) => deny(r.target), wave: () => ({ overriders: ["github:dave"], overridersSource: "policy.override in terragucci.yml" }) },
|
|
158
|
+
});
|
|
159
|
+
expect(refused.exitCode).toBe(7);
|
|
160
|
+
expect(refused.decision?.refused).toMatchObject({ runs: ["app"], overridersSource: "policy.override in terragucci.yml" });
|
|
161
|
+
expect(ran).toEqual([]);
|
|
162
|
+
// app's own list names carol: her override lets it through.
|
|
163
|
+
const gates = memoryGateLedgerPort({ resolutions: [override] });
|
|
164
|
+
const passed = await runOpWave({
|
|
165
|
+
spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates, capabilities: registry, now: NOW, log: () => {},
|
|
166
|
+
afterPlan: { name: "terragucci", run: (r) => ({ ...deny(r.target), ...(r.target === "app" ? { overriders: ["github:carol"] } : {}) }), wave: () => ({ overriders: ["github:dave"] }) },
|
|
167
|
+
});
|
|
168
|
+
expect(passed.exitCode).toBe(0);
|
|
169
|
+
expect(passed.decision?.members.find((m) => m.member === "app")).toMatchObject({ override: { by: "github:carol", digest: od } });
|
|
170
|
+
expect(ran).toEqual(["network", "app"]);
|
|
171
|
+
h.done();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("a wave answer that throws fails the wave before the gate under fail, and holds it under approve", async () => {
|
|
175
|
+
const spec = base("never");
|
|
176
|
+
const h = harness(spec);
|
|
177
|
+
const { registry, ran } = capability(digests);
|
|
178
|
+
const failed = await runOpWave({
|
|
179
|
+
spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates: memoryGateLedgerPort(), capabilities: registry, now: NOW, log: () => {},
|
|
180
|
+
afterPlan: { name: "terragucci", run: () => {}, wave: () => { throw new Error("the estimator did not run"); } },
|
|
181
|
+
});
|
|
182
|
+
expect(failed.exitCode).toBe(1);
|
|
183
|
+
expect(failed.decision).toBeUndefined();
|
|
184
|
+
expect(failed.hooks.filter((o) => o.moment === "after-plan").map((o) => [o.target ?? "(wave)", o.outcome])).toEqual([["network", "passed"], ["app", "passed"], ["(wave)", "failed"]]);
|
|
185
|
+
const held = await runOpWave({
|
|
186
|
+
spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates: memoryGateLedgerPort(), capabilities: registry, now: NOW, log: () => {},
|
|
187
|
+
afterPlan: { name: "terragucci", onFailure: "approve", run: () => {}, wave: () => { throw new Error("the estimator did not run"); } },
|
|
188
|
+
});
|
|
189
|
+
expect(held.exitCode).toBe(3);
|
|
190
|
+
expect(held.decision?.heldBy).toEqual(["after-plan hook terragucci (wave 1)"]);
|
|
191
|
+
expect(ran).toEqual([]);
|
|
192
|
+
h.done();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("a hook with no wave answer leaves the wave as it was", async () => {
|
|
196
|
+
const spec = base("never");
|
|
197
|
+
const h = harness(spec);
|
|
198
|
+
const { registry } = capability(digests);
|
|
199
|
+
const gates = memoryGateLedgerPort();
|
|
200
|
+
const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates, capabilities: registry, now: NOW, log: () => {}, afterPlan: { name: "terragucci", run: () => {} } });
|
|
201
|
+
expect(result.exitCode).toBe(0);
|
|
202
|
+
expect(result.decision?.extras).toBeUndefined();
|
|
203
|
+
expect(result.decision?.reports).toBeUndefined();
|
|
204
|
+
h.done();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("the answers are checked", () => {
|
|
208
|
+
expect(opWaveAfterPlanWaveResultProblems({ pending: { op: "x" }, overriders: [1], members: [{ member: "network", planDigest: digest("1") }, { member: "" }], holds: [""], report: 3 }, ["network"])).toEqual([
|
|
209
|
+
"`pending` cannot set op, which chant writes",
|
|
210
|
+
"`overriders` must be a list of principals",
|
|
211
|
+
"member network is also a run's target; a digest member that is no run needs a name of its own",
|
|
212
|
+
"each of `members` needs a member and a planDigest",
|
|
213
|
+
"`holds` must be a list of reasons, each a line saying why the wave waits for a person",
|
|
214
|
+
"`report` must be the report's text",
|
|
215
|
+
]);
|
|
216
|
+
expect(opWaveAfterPlanWaveResultProblems(undefined, [])).toEqual([]);
|
|
217
|
+
expect(opWaveAfterPlanResultProblems({ overriders: "carol" })).toEqual(["`overriders` must be a list of principals"]);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("the floor is 0.124.79", async () => {
|
|
221
|
+
const entry = await import("./index");
|
|
222
|
+
expect(entry.OP_WAVE_AFTER_PLAN_WAVE_FLOOR).toBe("0.124.79");
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
@@ -20,13 +20,70 @@
|
|
|
20
20
|
* The spec's command hooks at `hooks.after.plan` keep running where they
|
|
21
21
|
* ran: after the set digest, before the gate settles. A `perRun` one gets
|
|
22
22
|
* `{planJson}`, `CHANT_PLAN_DIGEST` and `CHANT_PLAN_JSON` the same way.
|
|
23
|
+
*
|
|
24
|
+
* ## The wave answer (#4842)
|
|
25
|
+
*
|
|
26
|
+
* A hook's `wave`, when it has one, is called once per job after its `run`
|
|
27
|
+
* was called for each of its runs, with all of them. It answers for the wave
|
|
28
|
+
* as a whole, as a plans file does for a wave-level plan command:
|
|
29
|
+
*
|
|
30
|
+
* - `pending`: fields for the pending fact (a `description`, the commit it
|
|
31
|
+
* planned), under the plans file's rules (`pendingFields`).
|
|
32
|
+
* - `members`: digest members that are no run, such as the wave's monthly
|
|
33
|
+
* cost from the product's own estimator.
|
|
34
|
+
* - `holds`: reasons the wave waits for a person whatever its gate, one line
|
|
35
|
+
* each, as a held hook's.
|
|
36
|
+
* - `overriders` and `overridersSource`: who may override a denial, in place
|
|
37
|
+
* of the overriders file at base. A run's own answer can name its own
|
|
38
|
+
* `overriders`, which count for that run in place of the wave's.
|
|
39
|
+
* - `report`: the product's report of these plans. When the wave waits,
|
|
40
|
+
* chant stores it beside the pending fact, at
|
|
41
|
+
* `_gates/<op>/<gate>/<digest>.json`, once. When the plans moved after an
|
|
42
|
+
* approval, chant writes it and the report stored for the approved plans
|
|
43
|
+
* to `.chant/op-waves/<name>/wave-<k>/report/` (`current.json`,
|
|
44
|
+
* `approved.json`) and names them on the decision, for the job that
|
|
45
|
+
* explains the refusal.
|
|
46
|
+
*
|
|
47
|
+
* A `wave` that throws follows the hook's `onFailure`, as `run` does.
|
|
23
48
|
*/
|
|
24
49
|
|
|
25
50
|
import { isAbsolute } from "node:path";
|
|
51
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
26
52
|
import type { ChangeSetPart } from "../change-set";
|
|
27
53
|
import type { OpRunPolicyRow } from "./runtime";
|
|
54
|
+
import type { WaveMember } from "../wave-engine";
|
|
28
55
|
import { OP_WAVE_HOOK_FAILURES, opWaveHookRuns, type OpWaveHookFailure } from "./op-waves";
|
|
29
|
-
import type
|
|
56
|
+
import { OP_WAVE_PENDING_RESERVED, type OpWaveHookOutcome } from "./stage-hooks";
|
|
57
|
+
|
|
58
|
+
/** The first chant whose after-plan hooks answer for the wave as a whole (`wave`), take a run's own `overriders`, and whose wave keeps the hook's report beside its pending fact (#4842). */
|
|
59
|
+
export const OP_WAVE_AFTER_PLAN_WAVE_FLOOR = "0.124.79";
|
|
60
|
+
|
|
61
|
+
/** The first chant whose wave answer takes `approvals`, recorded at the wave's gate before chant decides it (terragucci issue 1303). */
|
|
62
|
+
export const OP_WAVE_ANSWER_APPROVALS_FLOOR = NEXT_RELEASE;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* An approval a product settled before the gate (terragucci issue 1303),
|
|
66
|
+
* which chant records at the wave's gate for the digest it decides: a
|
|
67
|
+
* covered round's (the approval of the plans these are covered by), the
|
|
68
|
+
* rest of a stopped apply's (the approval the stopped apply ran under), or
|
|
69
|
+
* a review the product read itself. It counts as any approval does, under
|
|
70
|
+
* the wave's approval mode, `approvals.involved` and `approvals.quorum`.
|
|
71
|
+
*/
|
|
72
|
+
export interface OpWaveAnswerApproval {
|
|
73
|
+
/** Who approved, as the ledger names an approver. */
|
|
74
|
+
resolvedBy: string;
|
|
75
|
+
/** Why this approval stands for these plans, for the ledger and the log. */
|
|
76
|
+
note: string;
|
|
77
|
+
/** Where it was approved, an http or https URL. */
|
|
78
|
+
url?: string;
|
|
79
|
+
/**
|
|
80
|
+
* A review the product read (`approvals.reviewLedger` names the spec's op):
|
|
81
|
+
* written as the product's own review line, `via: "pr-review"` with the
|
|
82
|
+
* pull request, its head and its reviewers, which proves each reviewer
|
|
83
|
+
* under `pr-review`.
|
|
84
|
+
*/
|
|
85
|
+
review?: { pr: number; head: string; reviewers: string[] };
|
|
86
|
+
}
|
|
30
87
|
|
|
31
88
|
/** One planned run, as an after-plan hook in the job's process sees it (#4614). */
|
|
32
89
|
export interface OpWaveAfterPlanRun {
|
|
@@ -64,6 +121,38 @@ export interface OpWaveAfterPlanResult {
|
|
|
64
121
|
policy?: OpRunPolicyRow[];
|
|
65
122
|
/** Files the hook wrote for the run, relative to the job's directory. */
|
|
66
123
|
files?: string[];
|
|
124
|
+
/** Who may override this run's denial (#4842), in place of the wave's overriders. */
|
|
125
|
+
overriders?: string[];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** A job's planned runs, as a hook's wave answer sees them (#4842). */
|
|
129
|
+
export interface OpWaveAfterPlanWave {
|
|
130
|
+
spec: string;
|
|
131
|
+
op: string;
|
|
132
|
+
wave: number;
|
|
133
|
+
waveName: string;
|
|
134
|
+
job: OpWaveAfterPlanRun["job"];
|
|
135
|
+
/** The runs the hook is for, in the wave's order, as its `run` saw each. */
|
|
136
|
+
runs: OpWaveAfterPlanRun[];
|
|
137
|
+
cwd: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** What a hook adds to the wave as a whole (#4842). */
|
|
141
|
+
export interface OpWaveAfterPlanWaveResult {
|
|
142
|
+
/** Fields for the wave's pending fact, as a plans file's `pending`. */
|
|
143
|
+
pending?: Record<string, unknown>;
|
|
144
|
+
/** Digest members that are no run, such as the wave's cost. */
|
|
145
|
+
members?: WaveMember[];
|
|
146
|
+
/** Why the wave waits for a person whatever its gate, a line each. */
|
|
147
|
+
holds?: string[];
|
|
148
|
+
/** Who may override a denial, in place of the overriders file at base. */
|
|
149
|
+
overriders?: string[];
|
|
150
|
+
/** Where those overriders come from, for a refusal: "policy.override in terragucci.yml". */
|
|
151
|
+
overridersSource?: string;
|
|
152
|
+
/** The product's report of these plans: stored beside the pending fact, and written for the respond job after the plans moved. */
|
|
153
|
+
report?: string;
|
|
154
|
+
/** Approvals the product settled before the gate (terragucci issue 1303), recorded at the gate for the wave's digest before it is decided. */
|
|
155
|
+
approvals?: OpWaveAnswerApproval[];
|
|
67
156
|
}
|
|
68
157
|
|
|
69
158
|
/** An after-plan hook in the wave job's process (#4614). */
|
|
@@ -75,6 +164,8 @@ export interface OpWaveAfterPlanHook {
|
|
|
75
164
|
/** The runs it is for, as a command hook's `targets`. Default: every run. */
|
|
76
165
|
targets?: string[];
|
|
77
166
|
run(planned: OpWaveAfterPlanRun): OpWaveAfterPlanResult | void | Promise<OpWaveAfterPlanResult | void>;
|
|
167
|
+
/** Called once per job after `run` for each of its runs (#4842): what the hook adds to the wave. */
|
|
168
|
+
wave?(planned: OpWaveAfterPlanWave): OpWaveAfterPlanWaveResult | void | Promise<OpWaveAfterPlanWaveResult | void>;
|
|
78
169
|
}
|
|
79
170
|
|
|
80
171
|
const ROW_RESULTS: ReadonlyArray<OpRunPolicyRow["result"]> = ["passed", "warned", "denied", "held"];
|
|
@@ -90,6 +181,7 @@ export function opWaveAfterPlanProblems(hooks: unknown): string[] {
|
|
|
90
181
|
if (!hook || typeof hook !== "object") return void problems.push(`${at} must be { name, run, onFailure?, targets? }`);
|
|
91
182
|
if (typeof hook.name !== "string" || hook.name.trim() === "") problems.push(`${at} needs a name`);
|
|
92
183
|
if (typeof hook.run !== "function") problems.push(`${at} needs a run function`);
|
|
184
|
+
if (hook.wave !== undefined && typeof hook.wave !== "function") problems.push(`${at}.wave must be a function`);
|
|
93
185
|
if (hook.onFailure !== undefined && !OP_WAVE_HOOK_FAILURES.includes(hook.onFailure)) problems.push(`${at} has onFailure "${String(hook.onFailure)}"; use ${OP_WAVE_HOOK_FAILURES.join(" or ")}`);
|
|
94
186
|
if (hook.targets !== undefined && (!Array.isArray(hook.targets) || hook.targets.length === 0 || !hook.targets.every((t) => typeof t === "string" && t !== ""))) problems.push(`${at}.targets must be a non-empty list of targets or patterns`);
|
|
95
187
|
});
|
|
@@ -99,8 +191,8 @@ export function opWaveAfterPlanProblems(hooks: unknown): string[] {
|
|
|
99
191
|
/** What is wrong with one answer of a hook, empty when nothing is. */
|
|
100
192
|
export function opWaveAfterPlanResultProblems(value: unknown): string[] {
|
|
101
193
|
if (value === undefined || value === null) return [];
|
|
102
|
-
if (typeof value !== "object" || Array.isArray(value)) return ["the answer must be { policy?, files? }"];
|
|
103
|
-
const r = value as { policy?: unknown; files?: unknown };
|
|
194
|
+
if (typeof value !== "object" || Array.isArray(value)) return ["the answer must be { policy?, files?, overriders? }"];
|
|
195
|
+
const r = value as { policy?: unknown; files?: unknown; overriders?: unknown };
|
|
104
196
|
const problems: string[] = [];
|
|
105
197
|
if (r.policy !== undefined) {
|
|
106
198
|
if (!Array.isArray(r.policy)) problems.push("`policy` must be a list of rows");
|
|
@@ -117,6 +209,70 @@ export function opWaveAfterPlanResultProblems(value: unknown): string[] {
|
|
|
117
209
|
if (r.files !== undefined && (!Array.isArray(r.files) || !r.files.every((f) => typeof f === "string" && f !== "" && !isAbsolute(f) && !f.split("/").includes("..")))) {
|
|
118
210
|
problems.push("`files` must be paths inside the job's directory, relative to it");
|
|
119
211
|
}
|
|
212
|
+
if (r.overriders !== undefined && !principals(r.overriders)) problems.push("`overriders` must be a list of principals");
|
|
213
|
+
return problems;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const principals = (v: unknown): v is string[] => Array.isArray(v) && v.every((p) => typeof p === "string" && p.trim() !== "");
|
|
217
|
+
|
|
218
|
+
/** What is wrong with one wave answer (#4842), empty when nothing is. `targets` are the wave's runs, which no digest member may be named. */
|
|
219
|
+
export function opWaveAfterPlanWaveResultProblems(value: unknown, targets: readonly string[]): string[] {
|
|
220
|
+
if (value === undefined || value === null) return [];
|
|
221
|
+
if (typeof value !== "object" || Array.isArray(value)) return ["the wave answer must be { pending?, members?, holds?, overriders?, overridersSource?, report?, approvals? }"];
|
|
222
|
+
const r = value as Record<string, unknown>;
|
|
223
|
+
const problems: string[] = [];
|
|
224
|
+
if (r.pending !== undefined) {
|
|
225
|
+
const p = r.pending;
|
|
226
|
+
if (p === null || typeof p !== "object" || Array.isArray(p)) problems.push("`pending` must be an object of fields for the pending fact");
|
|
227
|
+
else {
|
|
228
|
+
const reserved = Object.keys(p).filter((key) => (OP_WAVE_PENDING_RESERVED as readonly string[]).includes(key));
|
|
229
|
+
if (reserved.length > 0) problems.push(`\`pending\` cannot set ${reserved.join(", ")}, which chant writes`);
|
|
230
|
+
if ("description" in p && typeof (p as { description?: unknown }).description !== "string") problems.push("`pending.description` must be a string");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (r.overriders !== undefined && !principals(r.overriders)) problems.push("`overriders` must be a list of principals");
|
|
234
|
+
if (r.overridersSource !== undefined && (typeof r.overridersSource !== "string" || r.overridersSource.trim() === "")) problems.push("`overridersSource` must say where the overriders come from");
|
|
235
|
+
if (r.members !== undefined) {
|
|
236
|
+
if (!Array.isArray(r.members)) problems.push("`members` must be a list of { member, planDigest }");
|
|
237
|
+
else {
|
|
238
|
+
const seen = new Set<string>();
|
|
239
|
+
for (const m of r.members as Array<Partial<WaveMember> | null>) {
|
|
240
|
+
if (!m || typeof m.member !== "string" || m.member === "" || typeof m.planDigest !== "string" || m.planDigest === "") {
|
|
241
|
+
problems.push("each of `members` needs a member and a planDigest");
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (targets.includes(m.member)) problems.push(`member ${m.member} is also a run's target; a digest member that is no run needs a name of its own`);
|
|
245
|
+
else if (seen.has(m.member)) problems.push(`\`members\` names ${m.member} twice`);
|
|
246
|
+
seen.add(m.member);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (r.holds !== undefined && !(Array.isArray(r.holds) && r.holds.every((h) => typeof h === "string" && h.trim() !== ""))) problems.push("`holds` must be a list of reasons, each a line saying why the wave waits for a person");
|
|
251
|
+
if (r.report !== undefined && typeof r.report !== "string") problems.push("`report` must be the report's text");
|
|
252
|
+
if (r.approvals !== undefined) {
|
|
253
|
+
if (!Array.isArray(r.approvals)) problems.push("`approvals` must be a list of { resolvedBy, note, url?, review? }");
|
|
254
|
+
else (r.approvals as unknown[]).forEach((x, i) => problems.push(...answerApprovalProblems(x, `approvals[${i}]`)));
|
|
255
|
+
}
|
|
256
|
+
return problems;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** What is wrong with one of a wave answer's `approvals` (terragucci issue 1303). */
|
|
260
|
+
function answerApprovalProblems(value: unknown, at: string): string[] {
|
|
261
|
+
const a = value as Partial<Record<keyof OpWaveAnswerApproval, unknown>> | null;
|
|
262
|
+
if (!a || typeof a !== "object" || Array.isArray(a)) return [`${at} must be { resolvedBy, note, url?, review? }`];
|
|
263
|
+
const problems: string[] = [];
|
|
264
|
+
if (typeof a.resolvedBy !== "string" || a.resolvedBy.trim() === "") problems.push(`${at}.resolvedBy must name the approver`);
|
|
265
|
+
if (typeof a.note !== "string" || a.note.trim() === "") problems.push(`${at}.note must say why the approval stands for these plans`);
|
|
266
|
+
if (a.url !== undefined && (typeof a.url !== "string" || !/^https?:\/\/\S+$/.test(a.url))) problems.push(`${at}.url must be an http or https URL`);
|
|
267
|
+
if (a.review !== undefined) {
|
|
268
|
+
const r = a.review as { pr?: unknown; head?: unknown; reviewers?: unknown } | null;
|
|
269
|
+
if (!r || typeof r !== "object") problems.push(`${at}.review must be { pr, head, reviewers }`);
|
|
270
|
+
else {
|
|
271
|
+
if (typeof r.pr !== "number" || !Number.isInteger(r.pr) || r.pr < 1) problems.push(`${at}.review.pr must be the pull request's number`);
|
|
272
|
+
if (typeof r.head !== "string" || r.head.trim() === "") problems.push(`${at}.review.head must be the commit the review approved`);
|
|
273
|
+
if (!principals(r.reviewers) || r.reviewers.length === 0) problems.push(`${at}.review.reviewers must list the reviewers`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
120
276
|
return problems;
|
|
121
277
|
}
|
|
122
278
|
|
|
@@ -125,6 +281,20 @@ export interface OpWaveAfterPlanRunOutcome {
|
|
|
125
281
|
/** The hooks' rows, in order. */
|
|
126
282
|
policy: OpRunPolicyRow[];
|
|
127
283
|
files: string[];
|
|
284
|
+
/** Who may override its denial (#4842), when a hook named anyone: the last hook's list. */
|
|
285
|
+
overriders?: string[];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** What the hooks' wave answers came to (#4842), each hook's in order. */
|
|
289
|
+
export interface OpWaveAfterPlanWaveOutcome {
|
|
290
|
+
pending?: Record<string, unknown>;
|
|
291
|
+
members: WaveMember[];
|
|
292
|
+
holds: string[];
|
|
293
|
+
overriders?: string[];
|
|
294
|
+
overridersSource?: string;
|
|
295
|
+
report?: string;
|
|
296
|
+
/** Each hook's `approvals`, in order (terragucci issue 1303). */
|
|
297
|
+
approvals: OpWaveAnswerApproval[];
|
|
128
298
|
}
|
|
129
299
|
|
|
130
300
|
/** What the after-plan hooks in the job's process came to (#4614). */
|
|
@@ -136,6 +306,8 @@ export interface OpWaveAfterPlanOutcome {
|
|
|
136
306
|
outcomes: OpWaveHookOutcome[];
|
|
137
307
|
/** Each run's rows and files, by target, for the runs a hook answered. */
|
|
138
308
|
runs: Map<string, OpWaveAfterPlanRunOutcome>;
|
|
309
|
+
/** The wave answers (#4842). */
|
|
310
|
+
wave: OpWaveAfterPlanWaveOutcome;
|
|
139
311
|
}
|
|
140
312
|
|
|
141
313
|
/**
|
|
@@ -149,9 +321,11 @@ export async function runOpWaveAfterPlanHooks(
|
|
|
149
321
|
runs: readonly OpWaveAfterPlanRun[],
|
|
150
322
|
log: (line: string) => void,
|
|
151
323
|
): Promise<OpWaveAfterPlanOutcome> {
|
|
152
|
-
const out: OpWaveAfterPlanOutcome = { holds: [], outcomes: [], runs: new Map() };
|
|
324
|
+
const out: OpWaveAfterPlanOutcome = { holds: [], outcomes: [], runs: new Map(), wave: { members: [], holds: [], approvals: [] } };
|
|
325
|
+
const targets = runs.map((r) => r.target);
|
|
153
326
|
for (const hook of hooks) {
|
|
154
|
-
|
|
327
|
+
const mine = opWaveHookRuns(hook, runs);
|
|
328
|
+
for (const run of mine) {
|
|
155
329
|
const label = `after-plan hook ${hook.name} (${run.target})`;
|
|
156
330
|
let problem: string | undefined;
|
|
157
331
|
let answer: OpWaveAfterPlanResult | void = undefined;
|
|
@@ -171,6 +345,11 @@ export async function runOpWaveAfterPlanHooks(
|
|
|
171
345
|
for (const f of answer.files ?? []) if (!got.files.includes(f)) got.files.push(f);
|
|
172
346
|
out.runs.set(run.target, got);
|
|
173
347
|
}
|
|
348
|
+
if (answer?.overriders) {
|
|
349
|
+
const got = out.runs.get(run.target) ?? { policy: [], files: [] };
|
|
350
|
+
got.overriders = [...new Set(answer.overriders)].sort();
|
|
351
|
+
out.runs.set(run.target, got);
|
|
352
|
+
}
|
|
174
353
|
continue;
|
|
175
354
|
}
|
|
176
355
|
if (hook.onFailure === "approve") {
|
|
@@ -184,10 +363,52 @@ export async function runOpWaveAfterPlanHooks(
|
|
|
184
363
|
log(problem);
|
|
185
364
|
return out;
|
|
186
365
|
}
|
|
366
|
+
if (!hook.wave || mine.length === 0) continue;
|
|
367
|
+
// #4842: the hook's answer for the wave, once its runs were each answered.
|
|
368
|
+
const first = mine[0]!;
|
|
369
|
+
const label = `after-plan hook ${hook.name} (wave ${first.wave})`;
|
|
370
|
+
let problem: string | undefined;
|
|
371
|
+
let answer: OpWaveAfterPlanWaveResult | void = undefined;
|
|
372
|
+
try {
|
|
373
|
+
answer = await hook.wave({ spec: first.spec, op: first.op, wave: first.wave, waveName: first.waveName, job: first.job, runs: [...mine], cwd: first.cwd });
|
|
374
|
+
const wrong = opWaveAfterPlanWaveResultProblems(answer, targets);
|
|
375
|
+
if (wrong.length > 0) problem = `${label} answered with ${wrong.join("; ")}`;
|
|
376
|
+
} catch (err) {
|
|
377
|
+
problem = `${label} failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
378
|
+
}
|
|
379
|
+
const base = { moment: "after-plan" as const, name: hook.name };
|
|
380
|
+
if (problem === undefined) {
|
|
381
|
+
out.outcomes.push({ ...base, exit: 0, outcome: "passed" });
|
|
382
|
+
if (answer) foldWaveAnswer(out.wave, answer);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (hook.onFailure === "approve") {
|
|
386
|
+
out.outcomes.push({ ...base, exit: 1, outcome: "held" });
|
|
387
|
+
out.holds.push(label);
|
|
388
|
+
log(`${problem}, so wave ${first.wave} (${first.waveName}) waits for an approval of its set digest`);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
out.outcomes.push({ ...base, exit: 1, outcome: "failed" });
|
|
392
|
+
out.failed = problem;
|
|
393
|
+
log(problem);
|
|
394
|
+
return out;
|
|
187
395
|
}
|
|
188
396
|
return out;
|
|
189
397
|
}
|
|
190
398
|
|
|
399
|
+
/** Fold one hook's wave answer into what the answers so far came to: fields and lists add up, a later list of overriders or report wins. */
|
|
400
|
+
function foldWaveAnswer(into: OpWaveAfterPlanWaveOutcome, answer: OpWaveAfterPlanWaveResult): void {
|
|
401
|
+
if (answer.pending && Object.keys(answer.pending).length > 0) into.pending = { ...into.pending, ...answer.pending };
|
|
402
|
+
for (const m of answer.members ?? []) if (!into.members.some((x) => x.member === m.member)) into.members.push({ member: m.member, planDigest: m.planDigest });
|
|
403
|
+
for (const h of answer.holds ?? []) if (!into.holds.includes(h)) into.holds.push(h);
|
|
404
|
+
if (answer.overriders) into.overriders = [...new Set(answer.overriders)].sort();
|
|
405
|
+
if (answer.overridersSource) into.overridersSource = answer.overridersSource;
|
|
406
|
+
if (answer.report !== undefined) into.report = answer.report;
|
|
407
|
+
for (const a of answer.approvals ?? []) {
|
|
408
|
+
into.approvals.push({ resolvedBy: a.resolvedBy, note: a.note, ...(a.url ? { url: a.url } : {}), ...(a.review ? { review: { pr: a.review.pr, head: a.review.head, reviewers: [...a.review.reviewers] } } : {}) });
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
191
412
|
/** Fold policy rows into a run's denial and hold: the rules of every `denied` row, and of every `held` row. */
|
|
192
413
|
export function foldPolicyRows(
|
|
193
414
|
rows: readonly OpRunPolicyRow[],
|
|
@@ -216,6 +437,8 @@ export interface ProductWaveHook {
|
|
|
216
437
|
capabilities?: import("../components/capability").CapabilityRegistry;
|
|
217
438
|
/** How the spec's command hooks run, when they call back into the product's process (`RunOpWaveOptions.hookExec`). */
|
|
218
439
|
hookExec?: import("./stage-hooks").OpWaveAsyncExec;
|
|
440
|
+
/** Hooks around each run of a wave with a `step` (#4842, `RunOpWaveOptions.runHooks`). */
|
|
441
|
+
runHooks?: import("./op-waves-run-hooks").OpWaveRunHooks | readonly import("./op-waves-run-hooks").OpWaveRunHooks[];
|
|
219
442
|
}
|
|
220
443
|
|
|
221
444
|
let activeWave: ProductWaveHook | undefined;
|
|
@@ -62,7 +62,7 @@ export function opWaveStepProblems(spec: Pick<OpWavesSpec, "step" | "plan" | "ap
|
|
|
62
62
|
}
|
|
63
63
|
if (spec.hooks?.apply?.runBy === "apply") problems.push("`hooks.apply.runBy: \"apply\"` hands the apply-stage hooks to an apply command, and a `step` has none; leave runBy as chant");
|
|
64
64
|
for (const wave of spec.waves) {
|
|
65
|
-
|
|
65
|
+
// #4842: a step's capability finds a discovering wave's runs (`discoverRuns`), checked when the wave plans.
|
|
66
66
|
if (wave.hooks?.apply?.runBy === "apply") problems.push(`wave "${wave.name}" hands its apply-stage hooks to an apply command, and a \`step\` has none`);
|
|
67
67
|
for (const run of wave.runs ?? []) {
|
|
68
68
|
const input = run.input as unknown;
|
|
@@ -81,7 +81,9 @@ describe("op waves through a capability step (#4545)", () => {
|
|
|
81
81
|
{ root: "app", lockTimeout: "5m", vars: { size: "s" } },
|
|
82
82
|
]);
|
|
83
83
|
// #4613: the plan reads its policy packs at the wave's base.
|
|
84
|
-
|
|
84
|
+
// #4854: and runs in the wave's directory.
|
|
85
|
+
expect(calls.planned[0]!.ctx).toEqual({ env: "dev", component: "network", cwd: h.cwd, policyBase: "b".repeat(40) });
|
|
86
|
+
expect(calls.ran[0]!.ctx.cwd).toBe(h.cwd);
|
|
85
87
|
// The apply gets the plan's artifact under the capability's member.
|
|
86
88
|
expect(calls.ran[0]!.ctx.plans).toEqual({ network: { planFile: "network.tfplan", planJson: "network.tfplan.json" } });
|
|
87
89
|
// The plan file hooks read carries the digest, the artifact and the part.
|
|
@@ -214,4 +216,10 @@ describe("the step and holds settings (#4545)", () => {
|
|
|
214
216
|
expect(partEffects(part("a", "delete"))).toEqual({ empty: false, destructive: true });
|
|
215
217
|
expect(partEffects(undefined)).toEqual({ empty: false, destructive: false });
|
|
216
218
|
});
|
|
219
|
+
|
|
220
|
+
test("a part whose plan changes only outputs is not empty (#4849)", () => {
|
|
221
|
+
const p = part("a", "no-op");
|
|
222
|
+
expect(partEffects({ ...p, member: { ...p.member, outputs: ["url"] } })).toEqual({ empty: false, destructive: false });
|
|
223
|
+
expect(partEffects({ ...p, member: { ...p.member, outputs: [] } })).toEqual({ empty: true, destructive: false });
|
|
224
|
+
});
|
|
217
225
|
});
|