@intentius/chant 0.124.93 → 0.124.95
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-comment-commands.d.ts +12 -1
- package/dist/ci-comment-commands.d.ts.map +1 -1
- package/dist/ci-comment-commands.js +29 -0
- package/dist/ci-note-commands.d.ts +1 -1
- package/dist/ci-note-commands.d.ts.map +1 -1
- package/dist/ci-note-commands.js +11 -1
- package/dist/ci-product.d.ts +19 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +25 -8
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
- package/dist/cli/handlers/pr-comment.js +11 -4
- package/dist/cli/handlers/run-wave.js +17 -3
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +4 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +4 -2
- package/dist/components/product-plan.d.ts +6 -0
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +9 -1
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +15 -6
- package/dist/gate-resume-run.d.ts +7 -0
- package/dist/gate-resume-run.d.ts.map +1 -1
- package/dist/gate-resume-run.js +42 -3
- package/dist/lexicon.d.ts +47 -1
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gate-applied.d.ts +18 -0
- package/dist/lifecycle/gate-applied.d.ts.map +1 -1
- package/dist/op/before-merge-decide.d.ts +39 -2
- package/dist/op/before-merge-decide.d.ts.map +1 -1
- package/dist/op/before-merge-decide.js +59 -0
- package/dist/op/gate-run-locator.d.ts +17 -0
- package/dist/op/gate-run-locator.d.ts.map +1 -1
- package/dist/op/index.d.ts +3 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +2 -1
- package/dist/op/op-waves-names.d.ts +40 -0
- package/dist/op/op-waves-names.d.ts.map +1 -1
- package/dist/op/op-waves-names.js +79 -0
- package/dist/op/op-waves-remainder.d.ts +110 -0
- package/dist/op/op-waves-remainder.d.ts.map +1 -0
- package/dist/op/op-waves-remainder.js +120 -0
- package/dist/op/op-waves-render-spec.d.ts +63 -5
- package/dist/op/op-waves-render-spec.d.ts.map +1 -1
- package/dist/op/op-waves-render-spec.js +68 -10
- package/dist/op/op-waves-run.d.ts +27 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +192 -4
- package/dist/op/op-waves-split-resume.d.ts +57 -0
- package/dist/op/op-waves-split-resume.d.ts.map +1 -0
- package/dist/op/op-waves-split-resume.js +94 -0
- package/dist/op/op-waves.d.ts +26 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +11 -2
- package/dist/release-floors.d.ts +13 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +13 -1
- package/dist/wave-runtime.mjs +360 -360
- package/package.json +1 -1
- package/src/ci-comment-commands.test.ts +147 -0
- package/src/ci-comment-commands.ts +29 -1
- package/src/ci-note-commands.ts +12 -2
- package/src/ci-product.ts +28 -8
- package/src/cli/handlers/pr-comment.ts +10 -4
- package/src/cli/handlers/run-wave.ts +16 -3
- package/src/cli/main.ts +4 -1
- package/src/components/product-pipeline.ts +4 -2
- package/src/components/product-plan.ts +9 -2
- package/src/floor-table.data.ts +15 -6
- package/src/gate-resume-run.ts +38 -3
- package/src/lexicon.ts +47 -1
- package/src/lifecycle/gate-applied.ts +16 -0
- package/src/op/before-merge-decide.ts +74 -2
- package/src/op/gate-run-locator.ts +14 -0
- package/src/op/index.ts +5 -0
- package/src/op/op-waves-names.ts +80 -0
- package/src/op/op-waves-remainder.test.ts +341 -0
- package/src/op/op-waves-remainder.ts +146 -0
- package/src/op/op-waves-render-spec.test.ts +106 -0
- package/src/op/op-waves-render-spec.ts +81 -10
- package/src/op/op-waves-run.ts +200 -5
- package/src/op/op-waves-split-resume.test.ts +148 -0
- package/src/op/op-waves-split-resume.ts +109 -0
- package/src/op/op-waves.ts +33 -2
- package/src/release-floors.ts +19 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #5047: the record of an apply under an approval is chant's own. Under
|
|
3
|
+
* `approvals.remainder` (with `approvals.spend`, both read at base) the
|
|
4
|
+
* applied line names each change the approved plans make, the job that
|
|
5
|
+
* applies the whole wave (a split wave's record job) writes how the apply
|
|
6
|
+
* ended, and a wave run again at the same commit applies the rest of a
|
|
7
|
+
* stopped apply under its approval when its plans make only changes that
|
|
8
|
+
* apply did not finish. A wave that plans no change closes a stopped
|
|
9
|
+
* apply; `approvals.spendStanding` spends an approval of the digest a wave
|
|
10
|
+
* its gate let through applies.
|
|
11
|
+
*/
|
|
12
|
+
import { afterAll, describe, expect, test, vi } from "vitest";
|
|
13
|
+
import { OP_WAVES_RESUME_ENV } from "./op-waves-split-resume";
|
|
14
|
+
import { execFileSync } from "node:child_process";
|
|
15
|
+
import { mkdtempSync, realpathSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { tmpdir } from "node:os";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import { assertOpWavesSpec, opWaveOutcomeDir, type OpWavesSpec } from "./op-waves";
|
|
19
|
+
import { runOpWave, type OpWaveRunPort, type OpWaveShowAtBase } from "./op-waves-run";
|
|
20
|
+
import { opWaveRunRecordFileName } from "./op-waves-split";
|
|
21
|
+
import { memoryGateLedgerPort } from "./gate";
|
|
22
|
+
import { CapabilityRegistry, type Capability } from "../components/capability";
|
|
23
|
+
import { CHANT_EXIT } from "../exit-codes";
|
|
24
|
+
import {
|
|
25
|
+
OP_WAVES_REMAINDER_FLOOR,
|
|
26
|
+
OP_WAVES_REMAINDER_PARITY_FLOOR,
|
|
27
|
+
OP_WAVE_REMAINDER_FOLLOWS,
|
|
28
|
+
opWaveApprovedChanges,
|
|
29
|
+
opWaveCoverRemainder,
|
|
30
|
+
opWaveStoppedApply,
|
|
31
|
+
opWaveUnfinishedApply,
|
|
32
|
+
type AppliedGateChange,
|
|
33
|
+
} from "./op-waves-remainder";
|
|
34
|
+
import type { AppliedGateRecord, FinishedGateRecord } from "../lifecycle/gate-applied";
|
|
35
|
+
import { OP_WAVE_COST_MEMBER } from "./op-waves-capability-spec";
|
|
36
|
+
|
|
37
|
+
const dirs: string[] = [];
|
|
38
|
+
afterAll(() => {
|
|
39
|
+
for (const d of dirs) rmSync(d, { recursive: true, force: true });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function tmp(prefix: string): string {
|
|
43
|
+
const d = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
|
|
44
|
+
dirs.push(d);
|
|
45
|
+
return d;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function git(cwd: string, ...args: string[]): string {
|
|
49
|
+
return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A clone of a bare remote, a writer of chant/lifecycle (the resource grain's rows live there). */
|
|
53
|
+
function writer(): string {
|
|
54
|
+
const remote = tmp("remainder-remote-");
|
|
55
|
+
git(remote, "init", "-q", "--bare", "-b", "main");
|
|
56
|
+
const c = tmp("remainder-clone-");
|
|
57
|
+
git(c, "init", "-q", "-b", "main");
|
|
58
|
+
git(c, "config", "user.email", "w@chant.dev");
|
|
59
|
+
git(c, "config", "user.name", "Writer");
|
|
60
|
+
git(c, "config", "commit.gpgsign", "false");
|
|
61
|
+
writeFileSync(join(c, "README.md"), "# t\n");
|
|
62
|
+
git(c, "add", "README.md");
|
|
63
|
+
git(c, "commit", "-q", "-m", "init");
|
|
64
|
+
git(c, "remote", "add", "origin", remote);
|
|
65
|
+
git(c, "push", "-q", "origin", "main");
|
|
66
|
+
return c;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const alive = async () => "alive" as const;
|
|
70
|
+
const HEAD = "c".repeat(40);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A root whose engine records each resource as its apply returns (the
|
|
74
|
+
* resource grain): its plan makes the resources not done yet, each with its
|
|
75
|
+
* digest. `stopAfter` has the next apply record that many resources and
|
|
76
|
+
* then fail, as a killed apply leaves its records.
|
|
77
|
+
*/
|
|
78
|
+
function engine() {
|
|
79
|
+
const want: Record<string, string> = { "aws_s3_bucket.a": `sha256:${"a".repeat(64)}`, "aws_s3_bucket.b": `sha256:${"b".repeat(64)}` };
|
|
80
|
+
const done = new Set<string>();
|
|
81
|
+
const ran: string[][] = [];
|
|
82
|
+
const at = { stopAfter: undefined as number | undefined };
|
|
83
|
+
const remaining = (): Record<string, string> => Object.fromEntries(Object.entries(want).filter(([k]) => !done.has(k)));
|
|
84
|
+
const planDigest = (r: Record<string, string>): string => `sha256:${Buffer.from(JSON.stringify(r)).toString("hex").padEnd(64, "0").slice(0, 64)}`;
|
|
85
|
+
const cap: Capability<Record<string, unknown>, unknown> = {
|
|
86
|
+
kind: "fake-cdf",
|
|
87
|
+
async plan(_ctx, input) {
|
|
88
|
+
const root = String(input.root);
|
|
89
|
+
const r = remaining();
|
|
90
|
+
const entries = Object.keys(r).map((address) => ({ member: root, address, type: "aws_s3_bucket", action: "create" }));
|
|
91
|
+
return {
|
|
92
|
+
member: root,
|
|
93
|
+
planDigest: planDigest(r),
|
|
94
|
+
artifact: { root, r },
|
|
95
|
+
resourceDigests: r,
|
|
96
|
+
changeSet: { member: { member: root, lexicon: "terraform", planner: "chant", status: "planned", planDigest: planDigest(r), holes: [] }, entries } as never,
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
async run(_ctx, input) {
|
|
100
|
+
const r = Object.keys(remaining());
|
|
101
|
+
const stop = at.stopAfter;
|
|
102
|
+
at.stopAfter = undefined;
|
|
103
|
+
const now: string[] = [];
|
|
104
|
+
for (const [i, address] of r.entries()) {
|
|
105
|
+
if (stop !== undefined && i >= stop) {
|
|
106
|
+
ran.push(now);
|
|
107
|
+
throw new Error(`${String(input.root)}: the apply stopped`);
|
|
108
|
+
}
|
|
109
|
+
done.add(address);
|
|
110
|
+
now.push(address);
|
|
111
|
+
}
|
|
112
|
+
ran.push(now);
|
|
113
|
+
return { applied: input.root };
|
|
114
|
+
},
|
|
115
|
+
defaultLockGrain: () => "resource",
|
|
116
|
+
// On the resource grain with no rows to hold, so the test leases nothing on chant/lifecycle.
|
|
117
|
+
lockRows: () => [],
|
|
118
|
+
};
|
|
119
|
+
return { registry: new CapabilityRegistry().register(cap), want, done, ran, at };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const spec = (approvals: Record<string, boolean>, gate: "always" | "never" = "always"): OpWavesSpec => ({
|
|
123
|
+
name: "roots",
|
|
124
|
+
op: "tf-apply",
|
|
125
|
+
step: { kind: "fake-cdf", root: "{target}" },
|
|
126
|
+
approvals,
|
|
127
|
+
waves: [{ name: "dev", runs: [{ target: "network" }], gate }],
|
|
128
|
+
});
|
|
129
|
+
const showOf = (s: OpWavesSpec): OpWaveShowAtBase => () => ({ sha: "b".repeat(40), text: JSON.stringify(s) });
|
|
130
|
+
|
|
131
|
+
let shared: string | undefined;
|
|
132
|
+
|
|
133
|
+
function harness(approvals: Record<string, boolean>, gate: "always" | "never" = "always") {
|
|
134
|
+
const s = spec(approvals, gate);
|
|
135
|
+
const cdf = engine();
|
|
136
|
+
const gates = memoryGateLedgerPort();
|
|
137
|
+
const lines: string[] = [];
|
|
138
|
+
// One writer for the file: each wave lets go of its rows when it ends, and the tests run one at a time.
|
|
139
|
+
shared ??= writer();
|
|
140
|
+
const base = { spec: s, specFile: "waves.json", wave: 1, cwd: shared, show: showOf(s), gates, capabilities: cdf.registry, lockLiveness: alive, releases: false as const, runs: { append: async () => {} } as OpWaveRunPort, head: HEAD, log: (l: string) => void lines.push(l) };
|
|
141
|
+
const approve = async (digest: string) => void (await gates.appendResolution!({ op: "roots", gate: "roots-wave-1", resolvedBy: "alice", timestamp: new Date(Date.now() + 5).toISOString(), planDigest: digest }));
|
|
142
|
+
return { s, cdf, gates, base, lines, approve };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
describe("the stopped-apply record (#5047)", () => {
|
|
146
|
+
test("the pure rules: changes on the resource grain, the stopped apply at this commit, the rest of it", () => {
|
|
147
|
+
const grains = new Map([["network", { lock: { grain: "resource" } }], ["dns", { lock: { grain: "target" } }]]);
|
|
148
|
+
expect(opWaveApprovedChanges([{ member: "network", resources: { b: "2", a: "1" } }, { member: "dns", empty: true }], grains)).toEqual([
|
|
149
|
+
{ target: "network", address: "a", digest: "1" },
|
|
150
|
+
{ target: "network", address: "b", digest: "2" },
|
|
151
|
+
]);
|
|
152
|
+
// A changing run on another grain, or without resource digests, cannot resume.
|
|
153
|
+
expect(opWaveApprovedChanges([{ member: "dns", resources: { x: "1" } }], grains)).toBeUndefined();
|
|
154
|
+
expect(opWaveApprovedChanges([{ member: "network" }], grains)).toBeUndefined();
|
|
155
|
+
|
|
156
|
+
const approved: AppliedGateChange[] = [{ target: "network", address: "a", digest: "1" }, { target: "network", address: "b", digest: "2" }];
|
|
157
|
+
expect(opWaveCoverRemainder(approved, [approved[1]!])).toEqual({ covered: true, remaining: [approved[1]], done: [approved[0]] });
|
|
158
|
+
expect(opWaveCoverRemainder(approved, [{ ...approved[1]!, digest: "9" }])).toMatchObject({ covered: false, why: "network b is a change the approved plans did not make" });
|
|
159
|
+
expect(opWaveCoverRemainder(approved, [approved[1]!], { now: [{ member: "(cost)", planDigest: "c" }] })).toMatchObject({ covered: false });
|
|
160
|
+
expect(opWaveCoverRemainder(approved, [approved[1]!], { now: [{ member: "(cost)", planDigest: "c" }], approved: [{ member: "(cost)", planDigest: "c" }] })).toMatchObject({ covered: true });
|
|
161
|
+
|
|
162
|
+
const line = (at: string, commit: string, changes?: AppliedGateChange[]): AppliedGateRecord => ({ version: 1, kind: "applied", op: "roots", gate: "g", planDigest: `d-${at}`, approvedAt: "2026-11-01T00:00:00Z", approvedBy: "alice", timestamp: at, commit, ...(changes ? { changes } : {}) });
|
|
163
|
+
const first = line("2026-11-02T00:00:00Z", HEAD, approved);
|
|
164
|
+
const fin = (l: AppliedGateRecord, result: "applied" | "failed"): FinishedGateRecord => ({ version: 1, kind: "finished", op: "roots", gate: "g", planDigest: l.planDigest, applied: l.timestamp, result, timestamp: "2026-11-03T00:00:00Z" });
|
|
165
|
+
expect(opWaveStoppedApply([first], [], "g", HEAD)).toBe(first);
|
|
166
|
+
expect(opWaveStoppedApply([first], [fin(first, "failed")], "g", HEAD)).toBe(first);
|
|
167
|
+
expect(opWaveStoppedApply([first], [fin(first, "applied")], "g", HEAD)).toBeUndefined();
|
|
168
|
+
expect(opWaveStoppedApply([first], [], "g", "d".repeat(40))).toBeUndefined();
|
|
169
|
+
// A newer apply of the gate at another commit leaves nothing to take up.
|
|
170
|
+
expect(opWaveStoppedApply([first, line("2026-11-04T00:00:00Z", "d".repeat(40), approved)], [], "g", HEAD)).toBeUndefined();
|
|
171
|
+
expect(opWaveUnfinishedApply([first], [], "g")).toBe(first);
|
|
172
|
+
expect(opWaveUnfinishedApply([first], [fin(first, "failed")], "g")).toBeUndefined();
|
|
173
|
+
expect(OP_WAVES_REMAINDER_FLOOR).toBe("0.124.94");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("#5056: the cost member's digest follows from the plans, so the rest covers it moved; any other extra still has to match", () => {
|
|
177
|
+
const approved: AppliedGateChange[] = [{ target: "network", address: "a", digest: "1" }, { target: "network", address: "b", digest: "2" }];
|
|
178
|
+
const cost = (d: string) => ({ member: OP_WAVE_COST_MEMBER, planDigest: d });
|
|
179
|
+
expect(OP_WAVE_REMAINDER_FOLLOWS).toEqual(["(monthly cost)"]);
|
|
180
|
+
// Part of the wave applied, so the rest costs less: the cost member moved, and every change is an approved one.
|
|
181
|
+
expect(opWaveCoverRemainder(approved, [approved[1]!], { now: [cost("sha256:less")], approved: [cost("sha256:all")] })).toEqual({ covered: true, remaining: [approved[1]], done: [approved[0]] });
|
|
182
|
+
expect(opWaveCoverRemainder(approved, [approved[1]!], { now: [cost("sha256:less")] })).toMatchObject({ covered: true });
|
|
183
|
+
// A change is still compared, and another extra still has to be the approved one.
|
|
184
|
+
expect(opWaveCoverRemainder(approved, [{ ...approved[1]!, digest: "9" }], { now: [cost("sha256:less")], approved: [cost("sha256:all")] })).toMatchObject({ covered: false });
|
|
185
|
+
expect(opWaveCoverRemainder(approved, [approved[1]!], { now: [cost("sha256:less"), { member: "migrate:m1", planDigest: "m" }], approved: [cost("sha256:all")] })).toMatchObject({ covered: false, why: "migrate:m1 is not as the approved set held it" });
|
|
186
|
+
expect(OP_WAVES_REMAINDER_PARITY_FLOOR).toBe("0.124.94");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("the spec takes approvals.remainder and approvals.spendStanding beside approvals.spend alone", () => {
|
|
190
|
+
expect(() => assertOpWavesSpec(spec({ spend: true, remainder: true, spendStanding: true }))).not.toThrow();
|
|
191
|
+
expect(() => assertOpWavesSpec(spec({ remainder: true }))).toThrow(/approvals.remainder works on the lines approvals.spend writes/);
|
|
192
|
+
expect(() => assertOpWavesSpec(spec({ spend: true, spendStanding: "yes" } as never))).toThrow(/approvals.spendStanding must be true or false/);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("a wave run again at the same commit applies the rest of its stopped apply under the approval, and says how it ended", async () => {
|
|
196
|
+
const { cdf, gates, base, approve } = harness({ spend: true, remainder: true });
|
|
197
|
+
const waited = await runOpWave(base);
|
|
198
|
+
expect(waited.exitCode).toBe(CHANT_EXIT.waiting);
|
|
199
|
+
await approve(waited.decision!.digest);
|
|
200
|
+
// The apply stops after one of its two resources.
|
|
201
|
+
cdf.at.stopAfter = 1;
|
|
202
|
+
const stopped = await runOpWave(base);
|
|
203
|
+
expect(stopped.exitCode).toBe(CHANT_EXIT.failed);
|
|
204
|
+
expect(gates.applied).toHaveLength(1);
|
|
205
|
+
expect(gates.applied[0]).toMatchObject({
|
|
206
|
+
planDigest: waited.decision!.digest,
|
|
207
|
+
approvedBy: "alice",
|
|
208
|
+
commit: HEAD,
|
|
209
|
+
changes: [
|
|
210
|
+
{ target: "network", address: "aws_s3_bucket.a", digest: cdf.want["aws_s3_bucket.a"] },
|
|
211
|
+
{ target: "network", address: "aws_s3_bucket.b", digest: cdf.want["aws_s3_bucket.b"] },
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
expect(gates.finished).toEqual([expect.objectContaining({ planDigest: waited.decision!.digest, applied: gates.applied[0]!.timestamp, result: "failed" })]);
|
|
215
|
+
|
|
216
|
+
const rest = await runOpWave(base);
|
|
217
|
+
expect(rest.exitCode).toBe(0);
|
|
218
|
+
expect(rest.decision).toMatchObject({ status: "approved", approvedBy: "alice", resumes: { planDigest: waited.decision!.digest, appliedAt: gates.applied[0]!.timestamp } });
|
|
219
|
+
expect(rest.decision!.digest).not.toBe(waited.decision!.digest);
|
|
220
|
+
expect(cdf.ran.at(-1)).toEqual(["aws_s3_bucket.b"]);
|
|
221
|
+
// It applied under the stopped apply's line: no applied line of its own, and that line's finished line says applied.
|
|
222
|
+
expect(gates.applied).toHaveLength(1);
|
|
223
|
+
expect(gates.finished.at(-1)).toMatchObject({ planDigest: waited.decision!.digest, applied: gates.applied[0]!.timestamp, result: "applied" });
|
|
224
|
+
// Nothing is left: the wave plans no change and applies nothing again.
|
|
225
|
+
const after = await runOpWave(base);
|
|
226
|
+
expect(after.exitCode).toBe(0);
|
|
227
|
+
expect(gates.finished).toHaveLength(2);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("another commit, or a change the approved plans did not make, waits for an approval of its own", async () => {
|
|
231
|
+
const { cdf, gates, base, approve, lines } = harness({ spend: true, remainder: true });
|
|
232
|
+
const waited = await runOpWave(base);
|
|
233
|
+
await approve(waited.decision!.digest);
|
|
234
|
+
cdf.at.stopAfter = 1;
|
|
235
|
+
await runOpWave(base);
|
|
236
|
+
expect((await runOpWave({ ...base, head: "d".repeat(40) })).exitCode).toBe(CHANT_EXIT.waiting);
|
|
237
|
+
cdf.want["aws_s3_bucket.b"] = `sha256:${"9".repeat(64)}`;
|
|
238
|
+
expect((await runOpWave(base)).exitCode).toBe(CHANT_EXIT.waiting);
|
|
239
|
+
expect(lines.some((l) => l.includes("aws_s3_bucket.b is a change the approved plans did not make, so these plans need an approval of their own"))).toBe(true);
|
|
240
|
+
expect(cdf.ran.at(-1)).toEqual(["aws_s3_bucket.a"]);
|
|
241
|
+
expect(gates.applied).toHaveLength(1);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("without approvals.remainder the applied line names no changes, nothing finishes, and the rest waits", async () => {
|
|
245
|
+
const { cdf, gates, base, approve } = harness({ spend: true });
|
|
246
|
+
const waited = await runOpWave(base);
|
|
247
|
+
await approve(waited.decision!.digest);
|
|
248
|
+
cdf.at.stopAfter = 1;
|
|
249
|
+
await runOpWave(base);
|
|
250
|
+
expect(gates.applied).toHaveLength(1);
|
|
251
|
+
expect(gates.applied[0]).not.toHaveProperty("changes");
|
|
252
|
+
expect(gates.applied[0]).not.toHaveProperty("commit");
|
|
253
|
+
expect(gates.finished).toEqual([]);
|
|
254
|
+
expect((await runOpWave(base)).exitCode).toBe(CHANT_EXIT.waiting);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("a wave that plans no change closes a stopped apply as applied", async () => {
|
|
258
|
+
const { cdf, gates, base, approve } = harness({ spend: true, remainder: true });
|
|
259
|
+
const waited = await runOpWave(base);
|
|
260
|
+
await approve(waited.decision!.digest);
|
|
261
|
+
cdf.at.stopAfter = 1;
|
|
262
|
+
await runOpWave(base);
|
|
263
|
+
// The killed apply wrote no finished line; something else applied the rest.
|
|
264
|
+
gates.finished.length = 0;
|
|
265
|
+
cdf.done.add("aws_s3_bucket.b");
|
|
266
|
+
expect((await runOpWave(base)).exitCode).toBe(0);
|
|
267
|
+
expect(gates.finished).toEqual([expect.objectContaining({ planDigest: waited.decision!.digest, applied: gates.applied[0]!.timestamp, result: "applied" })]);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("approvals.spendStanding: a wave its gate lets through spends the approval of its digest that stands", async () => {
|
|
271
|
+
// The digest the plans give, as an earlier wait's approval names it.
|
|
272
|
+
const digest = (await runOpWave(harness({ spend: true }).base)).decision!.digest;
|
|
273
|
+
const standing = harness({ spend: true, spendStanding: true }, "never");
|
|
274
|
+
await standing.approve(digest);
|
|
275
|
+
expect((await runOpWave(standing.base)).exitCode).toBe(0);
|
|
276
|
+
expect(standing.gates.applied).toEqual([expect.objectContaining({ gate: "roots-wave-1", planDigest: digest, approvedBy: "alice" })]);
|
|
277
|
+
// Off by default.
|
|
278
|
+
const plain = harness({ spend: true }, "never");
|
|
279
|
+
await plain.approve(digest);
|
|
280
|
+
expect((await runOpWave(plain.base)).exitCode).toBe(0);
|
|
281
|
+
expect(plain.gates.applied).toEqual([]);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("a split wave: the gate job records the changes, the record job says how the apply ended, and the applying job run again applies the rest", async () => {
|
|
285
|
+
const { cdf, gates, base, approve } = harness({ spend: true, remainder: true });
|
|
286
|
+
await runOpWave({ ...base, phase: "plan" });
|
|
287
|
+
const waited = await runOpWave({ ...base, phase: "gate" });
|
|
288
|
+
expect(waited.exitCode).toBe(CHANT_EXIT.waiting);
|
|
289
|
+
await approve(waited.decision!.digest);
|
|
290
|
+
await runOpWave({ ...base, phase: "plan" });
|
|
291
|
+
expect((await runOpWave({ ...base, phase: "gate" })).exitCode).toBe(CHANT_EXIT.done);
|
|
292
|
+
expect(gates.applied).toEqual([expect.objectContaining({ commit: HEAD, changes: expect.arrayContaining([expect.objectContaining({ address: "aws_s3_bucket.b" })]) })]);
|
|
293
|
+
// The applying job is killed after one resource: it leaves no run record, and the record job writes no finished line.
|
|
294
|
+
cdf.at.stopAfter = 1;
|
|
295
|
+
await runOpWave({ ...base, phase: "apply" });
|
|
296
|
+
unlinkSync(join(base.cwd, opWaveOutcomeDir(base.spec), opWaveRunRecordFileName(1)));
|
|
297
|
+
expect((await runOpWave({ ...base, phase: "record" })).exitCode).toBe(CHANT_EXIT.failed);
|
|
298
|
+
expect(gates.finished).toEqual([]);
|
|
299
|
+
// GitHub re-runs the failed applying and record jobs: the applying job's plan moved, to the rest of the decision's changes.
|
|
300
|
+
const again = await runOpWave({ ...base, phase: "apply" });
|
|
301
|
+
expect(again).toMatchObject({ exitCode: 0, applied: ["network"], moved: [] });
|
|
302
|
+
expect(cdf.ran.at(-1)).toEqual(["aws_s3_bucket.b"]);
|
|
303
|
+
expect((await runOpWave({ ...base, phase: "record" })).exitCode).toBe(0);
|
|
304
|
+
expect(gates.finished).toEqual([expect.objectContaining({ planDigest: waited.decision!.digest, applied: gates.applied[0]!.timestamp, result: "applied" })]);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test("#5052: on GitLab the gate job's line names the applying and record jobs; a new run of the same commit (Forgejo's resume) applies the rest", async () => {
|
|
308
|
+
vi.stubEnv("GITLAB_CI", "true");
|
|
309
|
+
vi.stubEnv("CI_API_V4_URL", "https://gl/api/v4");
|
|
310
|
+
vi.stubEnv("CI_PROJECT_ID", "7");
|
|
311
|
+
vi.stubEnv("CI_PIPELINE_ID", "100");
|
|
312
|
+
vi.stubEnv("CI_JOB_ID", "555");
|
|
313
|
+
vi.stubEnv("CI_JOB_NAME", "wave-1-dev-gate");
|
|
314
|
+
vi.stubEnv(OP_WAVES_RESUME_ENV, JSON.stringify({ apply: ["wave-1-dev"], record: "wave-1-dev-record" }));
|
|
315
|
+
try {
|
|
316
|
+
const { cdf, gates, base, approve } = harness({ spend: true, remainder: true });
|
|
317
|
+
await runOpWave({ ...base, phase: "plan" });
|
|
318
|
+
const waited = await runOpWave({ ...base, phase: "gate" });
|
|
319
|
+
await approve(waited.decision!.digest);
|
|
320
|
+
await runOpWave({ ...base, phase: "plan" });
|
|
321
|
+
expect((await runOpWave({ ...base, phase: "gate" })).exitCode).toBe(CHANT_EXIT.done);
|
|
322
|
+
expect(gates.applied[0]!.resume).toMatchObject({ forge: "gitlab", run: "100", job: "555", retry: { apply: ["wave-1-dev"], record: "wave-1-dev-record" } });
|
|
323
|
+
cdf.at.stopAfter = 1;
|
|
324
|
+
await runOpWave({ ...base, phase: "apply" });
|
|
325
|
+
unlinkSync(join(base.cwd, opWaveOutcomeDir(base.spec), opWaveRunRecordFileName(1)));
|
|
326
|
+
expect((await runOpWave({ ...base, phase: "record" })).exitCode).toBe(CHANT_EXIT.failed);
|
|
327
|
+
// A new run at the same commit, from its plan job: the gate job takes up the stopped apply, and writes no line of its own.
|
|
328
|
+
await runOpWave({ ...base, phase: "plan" });
|
|
329
|
+
const gate = await runOpWave({ ...base, phase: "gate" });
|
|
330
|
+
expect(gate.exitCode).toBe(CHANT_EXIT.done);
|
|
331
|
+
expect(gate.decision?.resumes).toMatchObject({ planDigest: waited.decision!.digest, appliedAt: gates.applied[0]!.timestamp });
|
|
332
|
+
expect(gates.applied).toHaveLength(1);
|
|
333
|
+
expect(await runOpWave({ ...base, phase: "apply" })).toMatchObject({ exitCode: 0, applied: ["network"] });
|
|
334
|
+
expect(cdf.ran.at(-1)).toEqual(["aws_s3_bucket.b"]);
|
|
335
|
+
expect((await runOpWave({ ...base, phase: "record" })).exitCode).toBe(0);
|
|
336
|
+
expect(gates.finished).toEqual([expect.objectContaining({ planDigest: waited.decision!.digest, applied: gates.applied[0]!.timestamp, result: "applied" })]);
|
|
337
|
+
} finally {
|
|
338
|
+
vi.unstubAllEnvs();
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rest of an apply that stopped, under the approval it applied under
|
|
3
|
+
* (#5047), with the spec's `approvals.remainder` and `approvals.spend`, both
|
|
4
|
+
* read at base.
|
|
5
|
+
*
|
|
6
|
+
* A wave that applies under an approval writes its applied line on
|
|
7
|
+
* `chant/lifecycle` (`_gates/<op>/applied.jsonl`, #3784) first. Under
|
|
8
|
+
* `remainder` that line carries each change the approved plans make: a run's
|
|
9
|
+
* resource, by the engine's address, and the resource's digest (the
|
|
10
|
+
* capability's `resourceDigests`), with the commit and the run (`resume`,
|
|
11
|
+
* which `chant run resume` starts again once it is gone). Only an engine that
|
|
12
|
+
* records each resource as its apply returns (the `resource` lock grain, such
|
|
13
|
+
* as choudoufu's) plans exactly what it did not apply after a stop, so a wave
|
|
14
|
+
* with a changing run on another grain, or with no resource digests, records
|
|
15
|
+
* no changes and never resumes as a remainder. The job that applies the
|
|
16
|
+
* whole wave (a split wave's record job) writes how the apply ended, a
|
|
17
|
+
* `finished` line; a killed apply writes none.
|
|
18
|
+
*
|
|
19
|
+
* Run again at the same commit (the resume re-runs the stopped job), the
|
|
20
|
+
* wave plans what is left. That plan has another digest, so the spent
|
|
21
|
+
* approval would not count. It does when every change the plans make is one
|
|
22
|
+
* the stopped apply's line names, with the same digest: the ones it no longer
|
|
23
|
+
* makes are done, since the config is the same and the engine records each
|
|
24
|
+
* resource it applied. Any other change, a digest member that is no run
|
|
25
|
+
* beyond the approved ones, or another commit, leaves the wave to wait for an
|
|
26
|
+
* approval of its own. The wave then applies under the stopped line, writes
|
|
27
|
+
* no applied line of its own, and writes that line's finished line.
|
|
28
|
+
*
|
|
29
|
+
* A split wave's applying job (#4987) re-plans its runs through the step: a
|
|
30
|
+
* run whose plan moved since the gate job's decision applies when its plan
|
|
31
|
+
* makes only changes the decision recorded, with the same digests.
|
|
32
|
+
*
|
|
33
|
+
* A wave whose plans change nothing closes the newest stopped apply of its
|
|
34
|
+
* gate as applied, since something applied the rest. With
|
|
35
|
+
* `approvals.spendStanding` a wave its gate lets through spends an approval
|
|
36
|
+
* of its digest that stands (`./op-waves-run.ts`).
|
|
37
|
+
*
|
|
38
|
+
* Pure: no git, no ledger, no clock.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import type { AppliedGateChange, AppliedGateRecord, FinishedGateRecord } from "../lifecycle/gate-applied";
|
|
42
|
+
import { finishedApply } from "../lifecycle/gate-applied";
|
|
43
|
+
import { samePlanDigest } from "../lifecycle/plan-digest";
|
|
44
|
+
import { OP_WAVE_COST_MEMBER } from "./op-waves-capability-spec";
|
|
45
|
+
|
|
46
|
+
export type { AppliedGateChange } from "../lifecycle/gate-applied";
|
|
47
|
+
|
|
48
|
+
export { OP_WAVES_REMAINDER_FLOOR, OP_WAVES_REMAINDER_PARITY_FLOOR } from "../release-floors";
|
|
49
|
+
|
|
50
|
+
/** A planned run, as the remainder reads it: its member, whether its plan is empty, and its resources' digests. */
|
|
51
|
+
export interface OpWaveRemainderMember {
|
|
52
|
+
member: string;
|
|
53
|
+
empty?: boolean;
|
|
54
|
+
resources?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The lock grain of each run's step plan, by target. */
|
|
58
|
+
export type OpWaveRemainderGrains = ReadonlyMap<string, { lock?: { grain: string } }> | undefined;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Every change the plans make, sorted by target and address, or undefined
|
|
62
|
+
* when a run that changes something did not plan through the step on the
|
|
63
|
+
* `resource` grain or gave no resource digests: the wave cannot resume as a
|
|
64
|
+
* remainder.
|
|
65
|
+
*/
|
|
66
|
+
export function opWaveApprovedChanges(members: readonly OpWaveRemainderMember[], grains: OpWaveRemainderGrains): AppliedGateChange[] | undefined {
|
|
67
|
+
const out: AppliedGateChange[] = [];
|
|
68
|
+
for (const m of members) {
|
|
69
|
+
if (m.empty === true) continue;
|
|
70
|
+
if (grains?.get(m.member)?.lock?.grain !== "resource" || m.resources === undefined) return undefined;
|
|
71
|
+
for (const [address, digest] of Object.entries(m.resources)) out.push({ target: m.member, address, digest });
|
|
72
|
+
}
|
|
73
|
+
return out.sort((a, b) => (a.target === b.target ? (a.address < b.address ? -1 : a.address > b.address ? 1 : 0) : a.target < b.target ? -1 : 1));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const time = (iso: string): number => new Date(iso).getTime();
|
|
77
|
+
|
|
78
|
+
/** The newest applied line of `gate`, oldest wins a tie by order. */
|
|
79
|
+
function newestLine(applied: readonly AppliedGateRecord[], gate: string): AppliedGateRecord | undefined {
|
|
80
|
+
return applied.filter((a) => a.gate === gate).reduce<AppliedGateRecord | undefined>((n, a) => (!n || time(a.timestamp) >= time(n.timestamp) ? a : n), undefined);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The apply of `gate` a wave at `commit` takes up: the gate's newest applied
|
|
85
|
+
* line, when it names changes, was written at `commit`, and no finished line
|
|
86
|
+
* says it applied. Undefined when there is none.
|
|
87
|
+
*/
|
|
88
|
+
export function opWaveStoppedApply(applied: readonly AppliedGateRecord[], finished: readonly FinishedGateRecord[], gate: string, commit: string | undefined): AppliedGateRecord | undefined {
|
|
89
|
+
const line = newestLine(applied, gate);
|
|
90
|
+
if (!line?.changes || commit === undefined || line.commit !== commit) return undefined;
|
|
91
|
+
return finishedApply(finished, line)?.result === "applied" ? undefined : line;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The newest applied line of `gate` that names changes and has no finished line at all: what a wave that changes nothing closes. */
|
|
95
|
+
export function opWaveUnfinishedApply(applied: readonly AppliedGateRecord[], finished: readonly FinishedGateRecord[], gate: string): AppliedGateRecord | undefined {
|
|
96
|
+
const line = newestLine(applied, gate);
|
|
97
|
+
return line?.changes && !finishedApply(finished, line) ? line : undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Whether the plans now are the rest of the approved changes. */
|
|
101
|
+
export type OpWaveCover =
|
|
102
|
+
| { covered: true; remaining: AppliedGateChange[]; done: AppliedGateChange[] }
|
|
103
|
+
| { covered: false; why: string };
|
|
104
|
+
|
|
105
|
+
const key = (c: Pick<AppliedGateChange, "target" | "address">): string => `${c.target} ${c.address}`;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The digest members that are no run whose digest follows from the plans
|
|
109
|
+
* (#5056): the cost member, `(monthly cost)`, chant's `holds.cost` and
|
|
110
|
+
* terragucci's alike, which digests the wave's monthly change. Part of the
|
|
111
|
+
* wave applied, so the rest costs less and the digest moves; every change is
|
|
112
|
+
* still compared, so the cover leaves it out on both sides.
|
|
113
|
+
*/
|
|
114
|
+
export const OP_WAVE_REMAINDER_FOLLOWS: readonly string[] = [OP_WAVE_COST_MEMBER];
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Whether `now`, the changes the plans make, are the rest of `approved`:
|
|
118
|
+
* each one approved with the same digest. The approved ones it no longer
|
|
119
|
+
* makes are done. `extras` are the digest members that are no run, now and
|
|
120
|
+
* as approved: each one now must be approved with the same digest, except
|
|
121
|
+
* the ones whose digest follows from the plans ({@link OP_WAVE_REMAINDER_FOLLOWS}).
|
|
122
|
+
*/
|
|
123
|
+
export function opWaveCoverRemainder(
|
|
124
|
+
approved: readonly AppliedGateChange[],
|
|
125
|
+
now: readonly AppliedGateChange[] | undefined,
|
|
126
|
+
extras: { now?: readonly { member: string; planDigest: string }[]; approved?: readonly { member: string; planDigest: string }[] } = {},
|
|
127
|
+
): OpWaveCover {
|
|
128
|
+
if (!now) return { covered: false, why: "a run that changes something plans on no resource grain, or gave no resource digests" };
|
|
129
|
+
const was = new Map(approved.map((c) => [key(c), c]));
|
|
130
|
+
const moved = now.filter((c) => was.get(key(c))?.digest !== c.digest).map(key);
|
|
131
|
+
if (moved.length > 0) return { covered: false, why: `${moved.join(", ")} ${moved.length === 1 ? "is a change" : "are changes"} the approved plans did not make` };
|
|
132
|
+
const extra = (extras.now ?? []).filter((e) => !OP_WAVE_REMAINDER_FOLLOWS.includes(e.member) && !(extras.approved ?? []).some((a) => a.member === e.member && samePlanDigest(a.planDigest, e.planDigest))).map((e) => e.member);
|
|
133
|
+
if (extra.length > 0) return { covered: false, why: `${extra.join(", ")} ${extra.length === 1 ? "is" : "are"} not as the approved set held ${extra.length === 1 ? "it" : "them"}` };
|
|
134
|
+
const planned = new Set(now.map(key));
|
|
135
|
+
return { covered: true, remaining: [...now], done: approved.filter((c) => !planned.has(key(c))) };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A run's plan in a split wave's applying job, against the changes the gate
|
|
140
|
+
* job's decision recorded (#5047): covered when it makes only changes of
|
|
141
|
+
* that run the decision holds, with the same digests.
|
|
142
|
+
*/
|
|
143
|
+
export function opWaveRunCovered(approved: readonly AppliedGateChange[], target: string, plan: OpWaveRemainderMember, grains: OpWaveRemainderGrains): OpWaveCover {
|
|
144
|
+
const now = opWaveApprovedChanges([plan], grains);
|
|
145
|
+
return opWaveCoverRemainder(approved.filter((c) => c.target === target), now?.map((c) => ({ ...c, target })));
|
|
146
|
+
}
|
|
@@ -15,13 +15,18 @@ import { gitShowAtBase, parseOpWavesSpec, readOpWavePolicy, runOpWave, type OpWa
|
|
|
15
15
|
import { memoryGateLedgerPort } from "./gate";
|
|
16
16
|
import {
|
|
17
17
|
commandSpecRender,
|
|
18
|
+
OP_WAVES_SPEC_BASE_ENV,
|
|
18
19
|
OP_WAVES_SPEC_COMMAND_ENV,
|
|
20
|
+
OP_WAVES_SPEC_RUNS_ENV,
|
|
19
21
|
opWavesRenderSpecEnv,
|
|
20
22
|
opWavesSpecCommandFromEnv,
|
|
23
|
+
opWavesSpecRunsAtHead,
|
|
21
24
|
renderedJobMissing,
|
|
22
25
|
renderedSpecShow,
|
|
26
|
+
renderOpWavesJobSpec,
|
|
23
27
|
renderOpWavesSpecFile,
|
|
24
28
|
RUNTIME_WAVES_SPEC_FLOOR,
|
|
29
|
+
RUNTIME_WAVES_SPEC_RUNS_AT_HEAD_FLOOR,
|
|
25
30
|
} from "./op-waves-render-spec";
|
|
26
31
|
import type { OpWavesSpec } from "./op-waves";
|
|
27
32
|
import { parseArgs } from "../cli/parse-args";
|
|
@@ -44,6 +49,21 @@ process.stdout.write(JSON.stringify({
|
|
|
44
49
|
}));
|
|
45
50
|
`;
|
|
46
51
|
|
|
52
|
+
/** #5046: a product whose runs are in its config too; it logs each commit it is handed and the base beside it. */
|
|
53
|
+
const RUNS_JS = `
|
|
54
|
+
const { execFileSync } = require("node:child_process");
|
|
55
|
+
const { appendFileSync } = require("node:fs");
|
|
56
|
+
const at = process.env.CHANT_WAVES_SPEC_AT;
|
|
57
|
+
if (process.env.RENDER_LOG) appendFileSync(process.env.RENDER_LOG, at + " base=" + (process.env.CHANT_WAVES_SPEC_BASE ?? "") + "\\n");
|
|
58
|
+
let config;
|
|
59
|
+
try { config = JSON.parse(execFileSync("git", ["show", at + ":config.json"], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] })); } catch { process.exit(0); }
|
|
60
|
+
process.stdout.write(JSON.stringify({
|
|
61
|
+
name: "tf-apply", op: "tf-apply",
|
|
62
|
+
plan: ["tool", "plan", "{target}", "--out", "{plan}"], apply: ["tool", "apply", "{target}", "--plan", "{plan}"],
|
|
63
|
+
waves: [{ name: "dev", gate: config.gate, shares: 2, runs: config.runs.map((target) => ({ target })) }],
|
|
64
|
+
}));
|
|
65
|
+
`;
|
|
66
|
+
|
|
47
67
|
let repo: string;
|
|
48
68
|
let tools: string;
|
|
49
69
|
let command: string[];
|
|
@@ -128,6 +148,7 @@ describe("a waves spec the job renders at run time (#4982)", () => {
|
|
|
128
148
|
expect(renderedJobMissing(spec, 2, { group: "us" })).toBe('wave 2 (g) has no job group "us" in the spec rendered at base');
|
|
129
149
|
expect(renderedJobMissing(spec, 2, { group: "eu", share: 3 })).toBe('job group "eu" of wave 2 (g) has 2 shares in the spec rendered at base');
|
|
130
150
|
expect(renderedJobMissing(spec, 2, { group: "eu", share: 1 })).toBeUndefined();
|
|
151
|
+
expect(renderedJobMissing(spec, 1, { share: 3 }, "head")).toBe("wave 1 (w) has 2 shares in the spec rendered at head");
|
|
131
152
|
});
|
|
132
153
|
|
|
133
154
|
test("the command comes from CHANT_WAVES_SPEC_COMMAND as a JSON list of words", () => {
|
|
@@ -140,6 +161,91 @@ describe("a waves spec the job renders at run time (#4982)", () => {
|
|
|
140
161
|
expect(RUNTIME_WAVES_SPEC_FLOOR).toBe("0.124.89");
|
|
141
162
|
});
|
|
142
163
|
|
|
164
|
+
test("runsAtHead (#5046): the job's runs come from the render at the applied commit, the gate from the render at base", async () => {
|
|
165
|
+
// The product's runs are in its config too: the change adds root c and loosens the gate.
|
|
166
|
+
writeFileSync(join(tools, "runs.cjs"), RUNS_JS);
|
|
167
|
+
const runs = [process.execPath, join(tools, "runs.cjs")];
|
|
168
|
+
const log = join(tools, "renders.log");
|
|
169
|
+
git("checkout", "-q", "HEAD^1");
|
|
170
|
+
writeFileSync(join(repo, "config.json"), JSON.stringify({ gate: "always", runs: ["a", "b"] }));
|
|
171
|
+
git("commit", "-q", "-am", "runs at base");
|
|
172
|
+
const baseSha = git("rev-parse", "HEAD");
|
|
173
|
+
writeFileSync(join(repo, "config.json"), JSON.stringify({ gate: "never", runs: ["a", "b", "c"] }));
|
|
174
|
+
git("commit", "-q", "-am", "add c and loosen");
|
|
175
|
+
const headSha = git("rev-parse", "HEAD");
|
|
176
|
+
process.env.RENDER_LOG = log;
|
|
177
|
+
try {
|
|
178
|
+
const rendered = renderOpWavesJobSpec({
|
|
179
|
+
specFile: SPEC_FILE,
|
|
180
|
+
base: "HEAD^1",
|
|
181
|
+
cwd: repo,
|
|
182
|
+
render: commandSpecRender(runs, SPEC_FILE, repo),
|
|
183
|
+
fallback: gitShowAtBase,
|
|
184
|
+
parse: parseOpWavesSpec,
|
|
185
|
+
runsAtHead: true,
|
|
186
|
+
headRender: (sha) => commandSpecRender(runs, SPEC_FILE, repo, { [OP_WAVES_SPEC_BASE_ENV]: sha }),
|
|
187
|
+
});
|
|
188
|
+
expect(rendered).toMatchObject({ at: "head", sha: headSha });
|
|
189
|
+
expect(rendered.spec.waves[0]!.runs.map((r) => r.target)).toEqual(["a", "b", "c"]);
|
|
190
|
+
expect(parseOpWavesSpec(readFileSync(join(repo, SPEC_FILE), "utf-8"), "file").waves[0]!.runs).toHaveLength(3);
|
|
191
|
+
const rules = readOpWavePolicy(SPEC_FILE, "dev", "HEAD^1", repo, rendered.show);
|
|
192
|
+
expect(rules).toMatchObject({ policy: "always", source: "base", base: baseSha });
|
|
193
|
+
// The head render alone is handed the base; the rules render is the base's own.
|
|
194
|
+
expect(readFileSync(log, "utf-8").trim().split("\n")).toEqual([`${headSha} base=${baseSha}`, `${baseSha} base=`]);
|
|
195
|
+
const applied: string[] = [];
|
|
196
|
+
const exec: OpWaveExec = (argv, dir) => {
|
|
197
|
+
if (argv[1] === "plan") writeFileSync(join(dir, argv[4]!), JSON.stringify({ planDigest: `sha256:${"1".repeat(64)}`, changes: { create: 1 } }));
|
|
198
|
+
if (argv[1] === "apply") applied.push(argv[2]!);
|
|
199
|
+
return 0;
|
|
200
|
+
};
|
|
201
|
+
const result = await runOpWave({ spec: rendered.spec, specFile: SPEC_FILE, wave: 1, cwd: repo, exec, show: rendered.show, gates: memoryGateLedgerPort(), head: headSha });
|
|
202
|
+
expect(result.exitCode).toBe(3);
|
|
203
|
+
expect(result.decision).toMatchObject({ status: "waiting", policy: "always" });
|
|
204
|
+
expect(result.decision!.members.map((m) => m.member).sort()).toEqual(["a", "b", "c"]);
|
|
205
|
+
expect(applied).toEqual([]);
|
|
206
|
+
// Off by default: the runs are the base's.
|
|
207
|
+
const off = renderOpWavesJobSpec({ specFile: SPEC_FILE, base: "HEAD^1", cwd: repo, render: commandSpecRender(runs, SPEC_FILE, repo), fallback: gitShowAtBase, parse: parseOpWavesSpec });
|
|
208
|
+
expect(off).toMatchObject({ at: "base", sha: baseSha });
|
|
209
|
+
expect(off.spec.waves[0]!.runs.map((r) => r.target)).toEqual(["a", "b"]);
|
|
210
|
+
} finally {
|
|
211
|
+
delete process.env.RENDER_LOG;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("CHANT_WAVES_SPEC_RUNS is head or unset", () => {
|
|
216
|
+
expect(opWavesSpecRunsAtHead({})).toBe(false);
|
|
217
|
+
expect(opWavesSpecRunsAtHead({ [OP_WAVES_SPEC_RUNS_ENV]: "head" })).toBe(true);
|
|
218
|
+
expect(() => opWavesSpecRunsAtHead({ [OP_WAVES_SPEC_RUNS_ENV]: "base" })).toThrow(/CHANT_WAVES_SPEC_RUNS is head or unset/);
|
|
219
|
+
expect(opWavesRenderSpecEnv({ command: ["terragucci", "waves-spec"], runsAtHead: true })).toEqual({ CHANT_WAVES_SPEC_COMMAND: '["terragucci","waves-spec"]', CHANT_WAVES_SPEC_RUNS: "head" });
|
|
220
|
+
expect(opWavesRenderSpecEnv({ command: ["terragucci", "waves-spec"], runsAtHead: false })).toEqual({ CHANT_WAVES_SPEC_COMMAND: '["terragucci","waves-spec"]' });
|
|
221
|
+
expect(RUNTIME_WAVES_SPEC_RUNS_AT_HEAD_FLOOR).toBe("0.124.94");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("chant run wave --render-spec with CHANT_WAVES_SPEC_RUNS=head writes the spec rendered at HEAD (#5046)", async () => {
|
|
225
|
+
writeFileSync(join(tools, "runs.cjs"), RUNS_JS);
|
|
226
|
+
git("checkout", "-q", "HEAD^1");
|
|
227
|
+
writeFileSync(join(repo, "config.json"), JSON.stringify({ gate: "always", runs: ["a"] }));
|
|
228
|
+
git("commit", "-q", "-am", "runs at base");
|
|
229
|
+
writeFileSync(join(repo, "config.json"), JSON.stringify({ gate: "always", runs: ["a", "b"] }));
|
|
230
|
+
git("commit", "-q", "-am", "add b");
|
|
231
|
+
const was = process.cwd();
|
|
232
|
+
const saved = { command: process.env[OP_WAVES_SPEC_COMMAND_ENV], runs: process.env[OP_WAVES_SPEC_RUNS_ENV] };
|
|
233
|
+
process.env[OP_WAVES_SPEC_COMMAND_ENV] = JSON.stringify([process.execPath, join(tools, "runs.cjs")]);
|
|
234
|
+
process.env[OP_WAVES_SPEC_RUNS_ENV] = "head";
|
|
235
|
+
process.chdir(repo);
|
|
236
|
+
try {
|
|
237
|
+
const ctx = { args: parseArgs(["run", "wave", "--spec", SPEC_FILE, "--wave", "1", "--share", "3", "--render-spec"]), plugins: [], serializers: [] } as unknown as CommandContext;
|
|
238
|
+
expect(await runOpWaveCommand(ctx)).toBe(0);
|
|
239
|
+
expect(parseOpWavesSpec(readFileSync(join(repo, SPEC_FILE), "utf-8"), "file").waves[0]!.runs.map((r) => r.target)).toEqual(["a", "b"]);
|
|
240
|
+
} finally {
|
|
241
|
+
process.chdir(was);
|
|
242
|
+
for (const [k, v] of [[OP_WAVES_SPEC_COMMAND_ENV, saved.command], [OP_WAVES_SPEC_RUNS_ENV, saved.runs]] as const) {
|
|
243
|
+
if (v === undefined) delete process.env[k];
|
|
244
|
+
else process.env[k] = v;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
143
249
|
test("chant run wave --render-spec writes the rendered spec, and a share it does not have exits 0", async () => {
|
|
144
250
|
const was = process.cwd();
|
|
145
251
|
const env = process.env[OP_WAVES_SPEC_COMMAND_ENV];
|