@intentius/chant 0.124.79 → 0.124.81
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/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/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/main.d.ts.map +1 -1
- package/dist/cli/main.js +10 -1
- package/dist/cli/mcp/product-tools.d.ts.map +1 -1
- package/dist/cli/mcp/product-tools.js +1 -2
- 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 +22 -0
- package/dist/components/capability.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/lifecycle/release-version.d.ts.map +1 -1
- package/dist/lifecycle/release-version.js +1 -2
- package/dist/op/index.d.ts +3 -3
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +2 -2
- package/dist/op/op-waves-after-plan.d.ts +33 -0
- package/dist/op/op-waves-after-plan.d.ts.map +1 -1
- package/dist/op/op-waves-after-plan.js +41 -4
- package/dist/op/op-waves-capability.d.ts +13 -1
- package/dist/op/op-waves-capability.d.ts.map +1 -1
- package/dist/op/op-waves-capability.js +22 -14
- package/dist/op/op-waves-run-hooks.d.ts.map +1 -1
- package/dist/op/op-waves-run-hooks.js +1 -2
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +125 -20
- package/dist/op/op-waves.d.ts +9 -5
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/parallelism.d.ts +9 -0
- package/dist/parallelism.d.ts.map +1 -1
- package/dist/parallelism.js +15 -0
- 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/release-floors.d.ts +15 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +17 -3
- package/dist/wave-runtime.mjs +288 -288
- package/package.json +1 -1
- package/src/ci-note-commands.test.ts +377 -0
- package/src/ci-note-commands.ts +479 -0
- package/src/cli/handlers/build.ts +7 -1
- package/src/cli/handlers/pr-notes.ts +70 -0
- package/src/cli/main.ts +10 -1
- package/src/cli/mcp/product-tools.test.ts +1 -2
- package/src/cli/mcp/product-tools.ts +1 -2
- package/src/cli/parse-args.ts +8 -0
- package/src/cli/registry.ts +4 -0
- package/src/components/capability.ts +22 -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/lifecycle/release-version.ts +1 -2
- package/src/op/index.ts +3 -2
- package/src/op/op-waves-after-plan-wave.test.ts +2 -3
- package/src/op/op-waves-after-plan.ts +61 -4
- package/src/op/op-waves-capability.test.ts +3 -1
- package/src/op/op-waves-capability.ts +27 -18
- package/src/op/op-waves-gate-port.test.ts +231 -0
- package/src/op/op-waves-parallel-plans.test.ts +185 -0
- package/src/op/op-waves-parallelism.test.ts +5 -0
- package/src/op/op-waves-run-hooks.test.ts +2 -3
- package/src/op/op-waves-run-hooks.ts +1 -2
- package/src/op/op-waves-run.ts +123 -23
- package/src/op/op-waves-step-wave.test.ts +3 -4
- package/src/op/op-waves.ts +9 -5
- package/src/parallelism.ts +26 -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/release-floors.ts +24 -3
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pieces of terragucci's gate that move onto chant's (terragucci issue
|
|
3
|
+
* 1303): `approvals.involved` and `approvals.reviewLedger` on a wave that no
|
|
4
|
+
* `approvals.quorum` rule covers, and the after-plan wave answer's
|
|
5
|
+
* `approvals`, which chant records at the gate before it decides it (a
|
|
6
|
+
* covered round, the rest of a stopped apply, a review the product read).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, expect, test } from "vitest";
|
|
10
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import type { OpWavesSpec } from "./op-waves";
|
|
14
|
+
import { runOpWave, type OpWaveShowAtBase } from "./op-waves-run";
|
|
15
|
+
import { memoryGateLedgerPort, type GateLedgerPort } from "./gate";
|
|
16
|
+
import { CapabilityRegistry, type Capability } from "../components/capability";
|
|
17
|
+
import type { ChangeSetPart } from "../change-set";
|
|
18
|
+
import type { GateResolutionRecord } from "../lifecycle/gate-ledger";
|
|
19
|
+
import type { TrustPolicy } from "../workspace/trust/policy";
|
|
20
|
+
import type { MergedReview, ReviewSource } from "./gate-review";
|
|
21
|
+
import { opWaveAfterPlanWaveResultProblems, type OpWaveAfterPlanHook, type OpWaveAnswerApproval } from "./op-waves-after-plan";
|
|
22
|
+
|
|
23
|
+
const digest = (n: string) => `sha256:${n.repeat(64)}`;
|
|
24
|
+
const NOW = "2026-11-08T00:00:00.000Z";
|
|
25
|
+
|
|
26
|
+
const part = (member: string): ChangeSetPart => ({
|
|
27
|
+
member: { member, lexicon: "terraform", planner: "chant", status: "planned", planDigest: digest("9"), holes: [] },
|
|
28
|
+
entries: [{ member, address: `aws_s3_bucket.${member}`, type: "aws_s3_bucket", action: "create" } as ChangeSetPart["entries"][number]],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const registry = (): { registry: CapabilityRegistry; ran: string[] } => {
|
|
32
|
+
const ran: string[] = [];
|
|
33
|
+
const cap: Capability<Record<string, unknown>, unknown> = {
|
|
34
|
+
kind: "fake-apply",
|
|
35
|
+
async plan(_ctx, input) {
|
|
36
|
+
const root = String(input.root);
|
|
37
|
+
return { member: root, planDigest: digest(root === "network" ? "1" : "2"), artifact: { planFile: `${root}.tfplan` }, changeSet: part(root) };
|
|
38
|
+
},
|
|
39
|
+
async run(_ctx, input) {
|
|
40
|
+
ran.push(String(input.root));
|
|
41
|
+
return {};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
return { registry: new CapabilityRegistry().register(cap), ran };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** terragucci's spec on the step: `tf-apply`, gate `wave-1`, no approval rules. */
|
|
48
|
+
const spec = (approvals: OpWavesSpec["approvals"], approval: "ledger" | "pr-review" = "ledger"): OpWavesSpec =>
|
|
49
|
+
({
|
|
50
|
+
name: "tf-apply",
|
|
51
|
+
op: "tf-apply",
|
|
52
|
+
gateName: "wave-{k}",
|
|
53
|
+
step: { kind: "fake-apply", root: "{target}" },
|
|
54
|
+
...(approvals ? { approvals } : {}),
|
|
55
|
+
waves: [{ name: "wave-1", runs: [{ target: "network" }, { target: "app" }], gate: "always", approval }],
|
|
56
|
+
}) as OpWavesSpec;
|
|
57
|
+
|
|
58
|
+
const trust = (): TrustPolicy =>
|
|
59
|
+
({ base: "b".repeat(40), signersPath: ".chant/allowed_signers", active: false, signers: [], excluded: [], roles: {}, adopted: [], runners: [], excludedRunners: [], admitted: {}, problems: [] }) as TrustPolicy;
|
|
60
|
+
|
|
61
|
+
const merged: MergedReview = { pr: 7, head: "r".repeat(40), author: "github:dana", approvers: [], refused: [] };
|
|
62
|
+
const reviews: ReviewSource = { kind: "github", mergedReview: async () => merged };
|
|
63
|
+
|
|
64
|
+
function harness(s: OpWavesSpec) {
|
|
65
|
+
const cwd = mkdtempSync(join(tmpdir(), "op-waves-gate-port-"));
|
|
66
|
+
const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(s) });
|
|
67
|
+
return { cwd, show, done: () => rmSync(cwd, { recursive: true, force: true }) };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A memory port whose `read(op)` returns that op's lines only, as the lifecycle branch's `_gates/<op>.jsonl` does. */
|
|
71
|
+
function ledger(): GateLedgerPort {
|
|
72
|
+
const inner = memoryGateLedgerPort();
|
|
73
|
+
return { ...inner, async read(op) { const r = await inner.read(op); return { ...r, resolutions: r.resolutions.filter((x) => x.op === op), pending: r.pending.filter((x) => x.op === op) }; } };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const run = (h: ReturnType<typeof harness>, s: OpWavesSpec, gates: GateLedgerPort, o: Partial<Parameters<typeof runOpWave>[0]> = {}) => {
|
|
77
|
+
const { registry: capabilities, ran } = registry();
|
|
78
|
+
const logs: string[] = [];
|
|
79
|
+
return runOpWave({
|
|
80
|
+
spec: s, specFile: "waves.json", wave: 1, cwd: h.cwd, show: h.show, gates, capabilities, now: NOW, head: "m".repeat(40), reviews, trust, commits: () => [], log: (l) => logs.push(l), ...o,
|
|
81
|
+
}).then((result) => ({ result, ran, logs }));
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const approve = (gates: GateLedgerPort, by: string, planDigest: string, extra: Partial<GateResolutionRecord> = {}) =>
|
|
85
|
+
gates.appendResolution!({ op: "tf-apply", gate: "wave-1", resolvedBy: by, timestamp: "2026-11-08T01:00:00.000Z", planDigest, approver: { kind: "human" }, ...extra } as never);
|
|
86
|
+
|
|
87
|
+
describe("approvals.involved and approvals.reviewLedger without approval rules (terragucci issue 1303)", () => {
|
|
88
|
+
test("an approval by the agent's account does not count, and one by someone else does", async () => {
|
|
89
|
+
const s = spec({ involved: { agents: ["tg-bot"], exclude: true } });
|
|
90
|
+
const h = harness(s);
|
|
91
|
+
const gates = ledger();
|
|
92
|
+
const waiting = await run(h, s, gates);
|
|
93
|
+
expect(waiting.result.exitCode).toBe(3);
|
|
94
|
+
const set = waiting.result.decision!.digest;
|
|
95
|
+
await approve(gates, "github:tg-bot", set);
|
|
96
|
+
const agent = await run(h, s, gates);
|
|
97
|
+
expect(agent.result.exitCode).toBe(3);
|
|
98
|
+
expect(agent.ran).toEqual([]);
|
|
99
|
+
expect(agent.logs.some((l) => /github:tg-bot is an account an agent acts as, so github:tg-bot's approval does not count/.test(l))).toBe(true);
|
|
100
|
+
// The decision record names who counts as involved, and claims no approval rules.
|
|
101
|
+
expect(agent.result.decision?.involved).toEqual({ agents: ["tg-bot"], exclude: true });
|
|
102
|
+
expect(agent.result.decision?.quorum).toBeUndefined();
|
|
103
|
+
expect(agent.result.decision?.quorumProgress).toBeUndefined();
|
|
104
|
+
await approve(gates, "github:alice", set, { timestamp: "2026-11-08T02:00:00.000Z" });
|
|
105
|
+
const alice = await run(h, s, gates);
|
|
106
|
+
expect(alice.result.exitCode).toBe(0);
|
|
107
|
+
expect(alice.result.decision?.approvedBy).toBe("github:alice");
|
|
108
|
+
expect(alice.ran).toEqual(["network", "app"]);
|
|
109
|
+
h.done();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("the pull request's author's approval does not count", async () => {
|
|
113
|
+
const s = spec({ involved: { exclude: true } });
|
|
114
|
+
const h = harness(s);
|
|
115
|
+
const gates = ledger();
|
|
116
|
+
const set = (await run(h, s, gates)).result.decision!.digest;
|
|
117
|
+
await approve(gates, "github:dana", set);
|
|
118
|
+
const r = await run(h, s, gates);
|
|
119
|
+
expect(r.result.exitCode).toBe(3);
|
|
120
|
+
expect(r.logs.some((l) => /github:dana wrote the change, so github:dana.s approval does not count/.test(l))).toBe(true);
|
|
121
|
+
h.done();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("under pr-review, a review the product recorded on its review ledger approves the wave", async () => {
|
|
125
|
+
const s = spec({ reviewLedger: "tf-reviews", involved: { agents: ["tg-bot"], exclude: true } }, "pr-review");
|
|
126
|
+
const h = harness(s);
|
|
127
|
+
const gates = ledger();
|
|
128
|
+
const set = (await run(h, s, gates)).result.decision!.digest;
|
|
129
|
+
await gates.appendResolution!({ op: "tf-reviews", gate: "wave-1", resolvedBy: "alice,tg-bot", timestamp: "2026-11-08T01:00:00.000Z", planDigest: set, via: "pr-review", pr: 7, head: "r".repeat(40), reviewers: ["alice", "tg-bot"] } as never);
|
|
130
|
+
const r = await run(h, s, gates);
|
|
131
|
+
expect(r.result.exitCode).toBe(0);
|
|
132
|
+
expect(r.result.decision?.approvedBy).toBe("github:alice");
|
|
133
|
+
h.done();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("a spec at base with neither waits for any approval as before, and an agent's approval counts", async () => {
|
|
137
|
+
const s = spec(undefined);
|
|
138
|
+
const h = harness(s);
|
|
139
|
+
const gates = ledger();
|
|
140
|
+
const set = (await run(h, s, gates)).result.decision!.digest;
|
|
141
|
+
await approve(gates, "github:tg-bot", set);
|
|
142
|
+
const r = await run(h, s, gates);
|
|
143
|
+
expect(r.result.exitCode).toBe(0);
|
|
144
|
+
expect(r.result.decision?.approvedBy).toBe("github:tg-bot");
|
|
145
|
+
expect(r.result.decision?.involved).toBeUndefined();
|
|
146
|
+
h.done();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("approvals a product settled before the gate, in the wave answer (terragucci issue 1303)", () => {
|
|
151
|
+
const covered: OpWaveAnswerApproval = { resolvedBy: "github:alice", note: "covered by the approval of sha256:aaaa by github:alice: only network.vpc_id differs" };
|
|
152
|
+
const hook = (approvals: OpWaveAnswerApproval[]): OpWaveAfterPlanHook => ({ name: "terragucci", run: () => {}, wave: () => ({ approvals }) });
|
|
153
|
+
|
|
154
|
+
test("chant records each at the gate for the digest it decides, and the wave applies under it", async () => {
|
|
155
|
+
const s = spec(undefined);
|
|
156
|
+
const h = harness(s);
|
|
157
|
+
const gates = ledger();
|
|
158
|
+
const r = await run(h, s, gates, { afterPlan: hook([covered]) });
|
|
159
|
+
expect(r.result.exitCode).toBe(0);
|
|
160
|
+
expect(r.result.decision?.approvedBy).toBe("github:alice");
|
|
161
|
+
const lines = (await gates.read("tf-apply")).resolutions;
|
|
162
|
+
expect(lines).toHaveLength(1);
|
|
163
|
+
expect(lines[0]).toMatchObject({ op: "tf-apply", gate: "wave-1", resolvedBy: "github:alice", planDigest: r.result.decision!.digest, note: covered.note, timestamp: NOW });
|
|
164
|
+
expect(r.logs).toContain(`wave 1 (wave-1): github:alice's approval recorded for ${r.result.decision!.digest}: ${covered.note}`);
|
|
165
|
+
h.done();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("an approval already recorded for the digest is not written again", async () => {
|
|
169
|
+
const s = spec(undefined);
|
|
170
|
+
const h = harness(s);
|
|
171
|
+
const gates = ledger();
|
|
172
|
+
const set = (await run(h, s, gates)).result.decision!.digest;
|
|
173
|
+
await approve(gates, "github:alice", set, { note: covered.note });
|
|
174
|
+
await run(h, s, gates, { afterPlan: hook([covered]) });
|
|
175
|
+
expect((await gates.read("tf-apply")).resolutions).toHaveLength(1);
|
|
176
|
+
h.done();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("an approval the hook gives by someone involved is recorded and still left out", async () => {
|
|
180
|
+
const s = spec({ involved: { agents: ["tg-bot"], exclude: true } });
|
|
181
|
+
const h = harness(s);
|
|
182
|
+
const gates = ledger();
|
|
183
|
+
const r = await run(h, s, gates, { afterPlan: hook([{ resolvedBy: "github:tg-bot", note: "the rest of the apply of sha256:bbbb, which github:tg-bot approved" }]) });
|
|
184
|
+
expect(r.result.exitCode).toBe(3);
|
|
185
|
+
expect((await gates.read("tf-apply")).resolutions.map((x) => x.resolvedBy)).toEqual(["github:tg-bot"]);
|
|
186
|
+
h.done();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("a review the hook read is written as the product's review line, which a review ledger counts under pr-review", async () => {
|
|
190
|
+
const s = spec({ reviewLedger: "tf-apply" }, "pr-review");
|
|
191
|
+
const h = harness(s);
|
|
192
|
+
const gates = ledger();
|
|
193
|
+
const review: OpWaveAnswerApproval = { resolvedBy: "alice,carol", note: "approved by the review of pull request 7", url: "https://github.com/acme/infra/pull/7", review: { pr: 7, head: "r".repeat(40), reviewers: ["alice", "carol"] } };
|
|
194
|
+
const r = await run(h, s, gates, { afterPlan: hook([review]) });
|
|
195
|
+
expect(r.result.exitCode).toBe(0);
|
|
196
|
+
expect(r.result.decision?.approvedBy).toBe("github:alice, github:carol");
|
|
197
|
+
const line = (await gates.read("tf-apply")).resolutions.find((x) => x.resolvedBy === "alice,carol");
|
|
198
|
+
expect(line).toMatchObject({ via: "pr-review", pr: 7, head: "r".repeat(40), reviewers: ["alice", "carol"], url: review.url });
|
|
199
|
+
h.done();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("a gate that passes without an approval records none", async () => {
|
|
203
|
+
const s = { ...spec(undefined), waves: [{ name: "wave-1", runs: [{ target: "network" }], gate: "never" }] } as OpWavesSpec;
|
|
204
|
+
const h = harness(s);
|
|
205
|
+
const gates = ledger();
|
|
206
|
+
const r = await run(h, s, gates, { afterPlan: hook([covered]) });
|
|
207
|
+
expect(r.result.exitCode).toBe(0);
|
|
208
|
+
expect((await gates.read("tf-apply")).resolutions).toEqual([]);
|
|
209
|
+
h.done();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("the answer's approvals are checked", () => {
|
|
213
|
+
expect(opWaveAfterPlanWaveResultProblems({ approvals: [covered] }, [])).toEqual([]);
|
|
214
|
+
expect(opWaveAfterPlanWaveResultProblems({ approvals: "alice" }, [])).toEqual(["`approvals` must be a list of { resolvedBy, note, url?, review? }"]);
|
|
215
|
+
expect(opWaveAfterPlanWaveResultProblems({ approvals: [{ resolvedBy: " ", note: "" }] }, [])).toEqual([
|
|
216
|
+
"approvals[0].resolvedBy must name the approver",
|
|
217
|
+
"approvals[0].note must say why the approval stands for these plans",
|
|
218
|
+
]);
|
|
219
|
+
expect(opWaveAfterPlanWaveResultProblems({ approvals: [{ ...covered, url: "ftp://x", review: { pr: 0, head: "", reviewers: [] } }] }, [])).toEqual([
|
|
220
|
+
"approvals[0].url must be an http or https URL",
|
|
221
|
+
"approvals[0].review.pr must be the pull request's number",
|
|
222
|
+
"approvals[0].review.head must be the commit the review approved",
|
|
223
|
+
"approvals[0].review.reviewers must list the reviewers",
|
|
224
|
+
]);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("the floor is the release it shipped in", async () => {
|
|
228
|
+
const entry = await import("./index");
|
|
229
|
+
expect(entry.OP_WAVE_ANSWER_APPROVALS_FLOOR).toBe("0.124.80");
|
|
230
|
+
});
|
|
231
|
+
});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A step wave's runs planned `parallelism` at once (#4864), as they apply,
|
|
3
|
+
* with the wave's serial section on each run's context
|
|
4
|
+
* (`DeployContext.serial`). A fake capability with a delay per root records
|
|
5
|
+
* how many plans, applies and serial sections are in flight; the wave's
|
|
6
|
+
* digest, members, plan files, run hooks and after-plan runs must come out
|
|
7
|
+
* as one at a time makes them.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, expect, test } from "vitest";
|
|
11
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { opWavePlanPath, runOpWave, type OpWaveShowAtBase } from "./op-waves-run";
|
|
15
|
+
import type { OpWavesSpec } from "./op-waves";
|
|
16
|
+
import type { OpWaveRunHooks } from "./op-waves-run-hooks";
|
|
17
|
+
import type { OpWaveAfterPlanHook } from "./op-waves-after-plan";
|
|
18
|
+
import { memoryGateLedgerPort } from "./gate";
|
|
19
|
+
import { CapabilityRegistry, type Capability, type CapabilityPlan, type DeployContext } from "../components/capability";
|
|
20
|
+
import { keyedSerial } from "../parallelism";
|
|
21
|
+
|
|
22
|
+
const ROOTS = ["a", "b", "c", "d"];
|
|
23
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
24
|
+
|
|
25
|
+
/** A gauge of how many of something are in flight, and the most there ever were. */
|
|
26
|
+
function gauge() {
|
|
27
|
+
const g = { now: 0, most: 0 };
|
|
28
|
+
return {
|
|
29
|
+
g,
|
|
30
|
+
async in<T>(fn: () => Promise<T>): Promise<T> {
|
|
31
|
+
g.now++;
|
|
32
|
+
g.most = Math.max(g.most, g.now);
|
|
33
|
+
try {
|
|
34
|
+
return await fn();
|
|
35
|
+
} finally {
|
|
36
|
+
g.now--;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A capability whose plan takes an "init" through `ctx.serial` under one key,
|
|
44
|
+
* then plans; the first root plans slowest, so plans at once finish in the
|
|
45
|
+
* other order. `fail` roots throw from their plan after `failAfterMs`.
|
|
46
|
+
*/
|
|
47
|
+
function capability(opts: { fail?: Record<string, number> } = {}) {
|
|
48
|
+
const plans = gauge();
|
|
49
|
+
const inits = gauge();
|
|
50
|
+
const applies = gauge();
|
|
51
|
+
const seen = { serial: [] as boolean[], planned: [] as string[] };
|
|
52
|
+
const delay = (root: string) => (ROOTS.length - ROOTS.indexOf(root)) * 15;
|
|
53
|
+
const cap: Capability<Record<string, unknown>, unknown> = {
|
|
54
|
+
kind: "fake-apply",
|
|
55
|
+
async plan(ctx: DeployContext, input) {
|
|
56
|
+
const root = String(input.root);
|
|
57
|
+
seen.serial.push(typeof ctx.serial === "function");
|
|
58
|
+
const init = () => inits.in(() => sleep(10));
|
|
59
|
+
await (ctx.serial ? ctx.serial("plugin-cache", init) : init());
|
|
60
|
+
return plans.in(async (): Promise<CapabilityPlan> => {
|
|
61
|
+
const failAfter = opts.fail?.[root];
|
|
62
|
+
if (failAfter !== undefined) {
|
|
63
|
+
await sleep(failAfter);
|
|
64
|
+
throw new Error(`${root} broke`);
|
|
65
|
+
}
|
|
66
|
+
await sleep(delay(root));
|
|
67
|
+
seen.planned.push(root);
|
|
68
|
+
const planDigest = `sha256:${String(ROOTS.indexOf(root) + 1).repeat(64)}`;
|
|
69
|
+
return { member: root, planDigest, artifact: { root }, changeSet: { member: { member: root, lexicon: "terraform", planner: "chant", status: "planned", planDigest, holes: [] }, entries: [{ member: root, lexicon: "terraform", planner: "chant", address: `x.${root}`, type: "x", action: "create", attributes: [] }] } };
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
async run(ctx: DeployContext, input) {
|
|
73
|
+
const root = String(input.root);
|
|
74
|
+
const init = () => inits.in(() => sleep(5));
|
|
75
|
+
await (ctx.serial ? ctx.serial("plugin-cache", init) : init());
|
|
76
|
+
return applies.in(async () => {
|
|
77
|
+
await sleep(delay(root));
|
|
78
|
+
return { applied: root };
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
return { registry: new CapabilityRegistry().register(cap), plans: plans.g, inits: inits.g, applies: applies.g, seen };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const spec = (parallelism: number | undefined): OpWavesSpec => ({
|
|
86
|
+
name: "roots",
|
|
87
|
+
op: "tf-apply",
|
|
88
|
+
...(parallelism !== undefined ? { parallelism } : {}),
|
|
89
|
+
step: { kind: "fake-apply", root: "{target}" },
|
|
90
|
+
waves: [{ name: "dev", runs: ROOTS.map((target) => ({ target })), gate: "never" }],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
async function wave(s: OpWavesSpec, registry: CapabilityRegistry, o: { runHooks?: OpWaveRunHooks; afterPlan?: OpWaveAfterPlanHook } = {}) {
|
|
94
|
+
const cwd = mkdtempSync(join(tmpdir(), "op-waves-par-plans-"));
|
|
95
|
+
const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(s) });
|
|
96
|
+
const log: string[] = [];
|
|
97
|
+
try {
|
|
98
|
+
const result = await runOpWave({ spec: s, specFile: "waves.json", wave: 1, cwd, show, gates: memoryGateLedgerPort(), capabilities: registry, log: (l) => log.push(l), ...o });
|
|
99
|
+
const files = ROOTS.map((r) => {
|
|
100
|
+
const f = join(cwd, opWavePlanPath(s, 1, r));
|
|
101
|
+
return existsSync(f) ? readFileSync(f, "utf-8") : undefined;
|
|
102
|
+
});
|
|
103
|
+
return { result, files, log };
|
|
104
|
+
} finally {
|
|
105
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
describe("a step wave's runs planned at once (#4864)", () => {
|
|
110
|
+
test("up to parallelism plans run at once, and the serial section keeps the inits to one at a time", async () => {
|
|
111
|
+
const c = capability();
|
|
112
|
+
const { result } = await wave(spec(3), c.registry);
|
|
113
|
+
expect(result).toMatchObject({ exitCode: 0, applied: ROOTS });
|
|
114
|
+
expect(c.plans.most).toBe(3);
|
|
115
|
+
expect(c.applies.most).toBe(3);
|
|
116
|
+
expect(c.inits.most).toBe(1);
|
|
117
|
+
expect(c.seen.serial).toEqual([true, true, true, true]);
|
|
118
|
+
// The first root plans slowest, so it is not the first to finish.
|
|
119
|
+
expect(c.seen.planned[0]).not.toBe("a");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("the digest, members, plan files, run hooks and after-plan runs come out as one at a time makes them", async () => {
|
|
123
|
+
const take = async (parallelism: number | undefined) => {
|
|
124
|
+
const c = capability();
|
|
125
|
+
const before: string[] = [];
|
|
126
|
+
const after: string[] = [];
|
|
127
|
+
const runHooks: OpWaveRunHooks = { name: "product", beforePlan: (r) => void before.push(r.target) };
|
|
128
|
+
const afterPlan: OpWaveAfterPlanHook = { name: "report", run: (p) => void after.push(`${p.target} ${p.planDigest}`) };
|
|
129
|
+
const got = await wave(spec(parallelism), c.registry, { runHooks, afterPlan });
|
|
130
|
+
return { c, got, before, after };
|
|
131
|
+
};
|
|
132
|
+
const one = await take(undefined);
|
|
133
|
+
const many = await take(4);
|
|
134
|
+
expect(one.c.plans.most).toBe(1);
|
|
135
|
+
expect(many.c.plans.most).toBe(4);
|
|
136
|
+
expect(many.got.result.decision?.digest).toBe(one.got.result.decision?.digest);
|
|
137
|
+
expect(many.got.result.decision?.members).toEqual(one.got.result.decision?.members);
|
|
138
|
+
expect(many.got.result.decision?.members.map((m) => m.member)).toEqual(ROOTS);
|
|
139
|
+
expect(many.got.files).toEqual(one.got.files);
|
|
140
|
+
expect(many.got.files.every((f) => f !== undefined)).toBe(true);
|
|
141
|
+
expect(many.after).toEqual(one.after);
|
|
142
|
+
expect([...many.before].sort()).toEqual(one.before);
|
|
143
|
+
expect(many.got.result.applied).toEqual(one.got.result.applied);
|
|
144
|
+
// One at a time, a run's context has no serial section.
|
|
145
|
+
expect(one.c.seen.serial).toEqual([false, false, false, false]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("a failing plan fails the wave with the first failing run in the wave's order, though a later one failed first", async () => {
|
|
149
|
+
const c = capability({ fail: { b: 40, c: 1 } });
|
|
150
|
+
// c's init takes its turn after b's and fails at once; b fails later, and it is the one one at a time stops at.
|
|
151
|
+
await expect(wave(spec(4), c.registry)).rejects.toThrow(/^planning b through fake-apply failed: b broke$/);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("a plan that fails starts no more plans", async () => {
|
|
155
|
+
const c = capability({ fail: { a: 1 } });
|
|
156
|
+
await expect(wave(spec(2), c.registry)).rejects.toThrow(/planning a through fake-apply failed/);
|
|
157
|
+
// a fails beside b, which finishes; c and d never start.
|
|
158
|
+
expect(c.seen.planned).toEqual(["b"]);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe("keyedSerial (#4864)", () => {
|
|
163
|
+
test("one call per key at a time, other keys beside it, and a failure is the call's own", async () => {
|
|
164
|
+
const serial = keyedSerial();
|
|
165
|
+
const same = gauge();
|
|
166
|
+
const order: string[] = [];
|
|
167
|
+
const call = (key: string, name: string, ms: number, fail = false) =>
|
|
168
|
+
serial(key, () =>
|
|
169
|
+
same.in(async () => {
|
|
170
|
+
await sleep(ms);
|
|
171
|
+
order.push(name);
|
|
172
|
+
if (fail) throw new Error(name);
|
|
173
|
+
return name;
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
const other = serial("other", async () => {
|
|
177
|
+
order.push("other");
|
|
178
|
+
return "other";
|
|
179
|
+
});
|
|
180
|
+
const got = await Promise.allSettled([call("k", "k1", 30, true), call("k", "k2", 5), other]);
|
|
181
|
+
expect(got.map((g) => g.status)).toEqual(["rejected", "fulfilled", "fulfilled"]);
|
|
182
|
+
expect(order).toEqual(["other", "k1", "k2"]);
|
|
183
|
+
expect(same.g.most).toBe(1);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -81,6 +81,11 @@ describe("runs applied at once (#4625)", () => {
|
|
|
81
81
|
expect(seen.most).toBe(1);
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
+
test("the spec refuses together with a parallelism over 1", () => {
|
|
85
|
+
const s = spec(2, [{ target: "a" }, { target: "b" }]);
|
|
86
|
+
expect(() => assertOpWavesSpec({ ...s, waves: [{ ...s.waves[0]!, together: true, parallelism: 2 }] })).toThrow(/no parallelism over 1/);
|
|
87
|
+
});
|
|
88
|
+
|
|
84
89
|
test("the spec refuses a parallelism over 1 without a step, and one that is not a whole number", () => {
|
|
85
90
|
const { step: _s, ...noStep } = spec(2, [{ target: "a" }]);
|
|
86
91
|
expect(() => assertOpWavesSpec({ ...noStep, apply: ["./apply", "{target}"], plan: ["./plan", "{target}", "{plan}"] })).toThrow(/apply at once only through `step`/);
|
|
@@ -176,9 +176,8 @@ describe("run hooks in the job's process (#4842)", () => {
|
|
|
176
176
|
h.done();
|
|
177
177
|
});
|
|
178
178
|
|
|
179
|
-
test("the floor is
|
|
179
|
+
test("the floor is 0.124.79", async () => {
|
|
180
180
|
const entry = await import("./index");
|
|
181
|
-
|
|
182
|
-
expect(entry.OP_WAVE_RUN_HOOKS_FLOOR).toBe(NEXT_RELEASE);
|
|
181
|
+
expect(entry.OP_WAVE_RUN_HOOKS_FLOOR).toBe("0.124.79");
|
|
183
182
|
});
|
|
184
183
|
});
|
|
@@ -26,11 +26,10 @@
|
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
import { isAbsolute } from "node:path";
|
|
29
|
-
import { NEXT_RELEASE } from "../release-floors";
|
|
30
29
|
import { opWaveHookRuns } from "./op-waves";
|
|
31
30
|
|
|
32
31
|
/** The first chant that runs a product's `runHooks` around each run of a wave with a `step` (#4842), and hands its `env` and `afterInit` to the capability (`DeployContext.processEnv`, `DeployContext.afterInit`). */
|
|
33
|
-
export const OP_WAVE_RUN_HOOKS_FLOOR =
|
|
32
|
+
export const OP_WAVE_RUN_HOOKS_FLOOR = "0.124.79";
|
|
34
33
|
|
|
35
34
|
/** One run of a wave, as a run hook sees it (#4842). */
|
|
36
35
|
export interface OpWaveRunHookRun {
|