@intentius/chant 0.124.70 → 0.124.72
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-agent.d.ts +12 -1
- package/dist/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +13 -8
- package/dist/ci-commit.d.ts +326 -0
- package/dist/ci-commit.d.ts.map +1 -0
- package/dist/ci-commit.js +725 -0
- package/dist/ci-estate/delivery.d.ts +75 -2
- package/dist/ci-estate/delivery.d.ts.map +1 -1
- package/dist/ci-estate/delivery.js +129 -0
- package/dist/ci-estate.d.ts +3 -1
- package/dist/ci-estate.d.ts.map +1 -1
- package/dist/ci-estate.js +4 -1
- package/dist/ci-product-words.d.ts +6 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +3 -1
- package/dist/ci-product.d.ts +1 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +1 -1
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +7 -2
- package/dist/cli/handlers/commit.d.ts +26 -0
- package/dist/cli/handlers/commit.d.ts.map +1 -0
- package/dist/cli/handlers/commit.js +145 -0
- package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
- package/dist/cli/handlers/notify-relay.js +22 -2
- package/dist/cli/handlers/pr.d.ts +6 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +16 -7
- package/dist/cli/handlers/release.d.ts +9 -0
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +114 -5
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +17 -0
- package/dist/components/product-pipeline.d.ts +33 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +34 -1
- package/dist/components/release-compile.d.ts +2 -0
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +8 -4
- package/dist/config.d.ts +60 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -0
- package/dist/lexicon.d.ts +54 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +28 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +4 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
- package/dist/lifecycle/__fixtures__/publish-fakes.js +6 -2
- package/dist/lifecycle/gated-request.d.ts +3 -1
- package/dist/lifecycle/gated-request.d.ts.map +1 -1
- package/dist/lifecycle/gated-request.js +5 -2
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +57 -0
- package/dist/lifecycle/publish-declaration.d.ts +16 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +35 -3
- package/dist/lifecycle/publish-forge.d.ts +12 -0
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +102 -19
- package/dist/lifecycle/publish-npm.d.ts +15 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +28 -1
- package/dist/lifecycle/publish-oci.d.ts +2 -0
- package/dist/lifecycle/publish-oci.d.ts.map +1 -1
- package/dist/lifecycle/publish-oci.js +10 -0
- 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 +8 -1
- package/dist/lifecycle/release-images.d.ts +87 -0
- package/dist/lifecycle/release-images.d.ts.map +1 -0
- package/dist/lifecycle/release-images.js +138 -0
- package/dist/lifecycle/release-publish.d.ts +2 -0
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/notify-relay.d.ts +41 -1
- package/dist/notify-relay.d.ts.map +1 -1
- package/dist/notify-relay.js +40 -0
- package/dist/notify.d.ts +16 -3
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +16 -10
- package/dist/op/activities/review-agent.d.ts.map +1 -1
- package/dist/op/activities/review-agent.js +4 -2
- package/dist/op/gate.d.ts +5 -1
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +7 -2
- package/dist/op/op-waves-notify.d.ts +1 -1
- package/dist/op/op-waves-notify.d.ts.map +1 -1
- package/dist/op/op-waves-notify.js +2 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +12 -8
- package/dist/op/op-waves.d.ts +9 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +11 -0
- package/dist/pr-forge-base.d.ts +18 -0
- package/dist/pr-forge-base.d.ts.map +1 -0
- package/dist/pr-forge-base.js +29 -0
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +315 -315
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +1 -2
- package/dist/workspace/release-workflow.d.ts +47 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +258 -14
- package/package.json +1 -1
- package/src/ci-agent.ts +13 -8
- package/src/ci-commit.test.ts +415 -0
- package/src/ci-commit.ts +901 -0
- package/src/ci-estate/__fixtures__/terragucci-dora.json +1305 -0
- package/src/ci-estate/delivery.ts +186 -2
- package/src/ci-estate/records-delivery.test.ts +55 -0
- package/src/ci-estate.ts +10 -0
- package/src/ci-product-words.ts +6 -2
- package/src/ci-product.ts +1 -0
- package/src/cli/handlers/approve.ts +6 -2
- package/src/cli/handlers/commit.ts +155 -0
- package/src/cli/handlers/notify-relay.ts +21 -2
- package/src/cli/handlers/operator.test.ts +2 -0
- package/src/cli/handlers/pr-wave-approve-lines.test.ts +32 -0
- package/src/cli/handlers/pr.ts +17 -7
- package/src/cli/handlers/release.ts +110 -5
- package/src/cli/main.ts +17 -0
- package/src/components/product-pipeline.test.ts +28 -1
- package/src/components/product-pipeline.ts +54 -1
- package/src/components/release-compile.ts +9 -3
- package/src/config.ts +31 -0
- package/src/lexicon.ts +72 -0
- package/src/lifecycle/__fixtures__/publish-fakes.ts +11 -5
- package/src/lifecycle/gated-request-spend.test.ts +115 -0
- package/src/lifecycle/gated-request.ts +5 -2
- package/src/lifecycle/git.ts +53 -0
- package/src/lifecycle/ledger-two-clones.test.ts +132 -0
- package/src/lifecycle/publish-declaration.ts +35 -3
- package/src/lifecycle/publish-forge-notes.test.ts +193 -0
- package/src/lifecycle/publish-forge.ts +100 -22
- package/src/lifecycle/publish-npm.ts +31 -2
- package/src/lifecycle/publish-oci.ts +10 -0
- package/src/lifecycle/publish-targets.test.ts +2 -1
- package/src/lifecycle/release-cut.ts +17 -1
- package/src/lifecycle/release-images.test.ts +242 -0
- package/src/lifecycle/release-images.ts +174 -0
- package/src/lifecycle/release-publish.ts +2 -0
- package/src/notify-relay.test.ts +55 -1
- package/src/notify-relay.ts +49 -1
- package/src/notify.ts +25 -12
- package/src/op/activities/review-agent.test.ts +20 -1
- package/src/op/activities/review-agent.ts +5 -2
- package/src/op/gate.ts +7 -2
- package/src/op/op-waves-approve-target.test.ts +108 -0
- package/src/op/op-waves-notify.ts +2 -2
- package/src/op/op-waves-run.ts +12 -7
- package/src/op/op-waves.ts +12 -0
- package/src/pr-forge-base.test.ts +37 -0
- package/src/pr-forge-base.ts +36 -0
- package/src/release-floors.ts +1 -1
- package/src/workspace/__fixtures__/release-workflow/forgejo-plain-member.yml +26 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-plain.yml +23 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-secure-member.yml +27 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-secure.yml +24 -0
- package/src/workspace/__fixtures__/release-workflow/github-plain-member.yml +26 -0
- package/src/workspace/__fixtures__/release-workflow/github-plain.yml +23 -0
- package/src/workspace/__fixtures__/release-workflow/github-secure-member.yml +27 -0
- package/src/workspace/__fixtures__/release-workflow/github-secure.yml +24 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-plain-member.yml +13 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-plain.yml +12 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-secure-member.yml +14 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-secure.yml +13 -0
- package/src/workspace/ci-green.ts +1 -2
- package/src/workspace/release-workflow.test.ts +199 -0
- package/src/workspace/release-workflow.ts +356 -14
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The commit job (#4722) against real git repositories, with a fake forge, a
|
|
3
|
+
* fake command and an in-memory ledger: the decision, the run, the landing,
|
|
4
|
+
* the loop guard and the approval refusal.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { mkdtempSync, mkdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
11
|
+
import { afterEach, describe, expect, test } from "vitest";
|
|
12
|
+
import type { AgentGit } from "./ci-agent";
|
|
13
|
+
import {
|
|
14
|
+
COMMIT_HEAD_REF,
|
|
15
|
+
COMMIT_TRAILER,
|
|
16
|
+
commitCommandLines,
|
|
17
|
+
commitRefusedPaths,
|
|
18
|
+
commitSettingsEnv,
|
|
19
|
+
commitSettingsFromEnv,
|
|
20
|
+
landCommitChange,
|
|
21
|
+
prepareCommitRun,
|
|
22
|
+
resolveCommitSpec,
|
|
23
|
+
runCommit,
|
|
24
|
+
type CommitRunCommand,
|
|
25
|
+
type CommitSettings,
|
|
26
|
+
type OpCommitSpec,
|
|
27
|
+
} from "./ci-commit";
|
|
28
|
+
import { assertProductWords, parseProductComment } from "./ci-product-words";
|
|
29
|
+
import { PLYWOOD } from "./__fixtures__/product-words";
|
|
30
|
+
import type { OpRunRecord, OpRunRecordInput } from "./op/runtime";
|
|
31
|
+
import type { PullRequestHead } from "./pr-forge";
|
|
32
|
+
|
|
33
|
+
const words = assertProductWords({ ...PLYWOOD, commands: { ...PLYWOOD.commands, fmt: "commit" as const } });
|
|
34
|
+
const NOW = new Date("2026-11-07T12:00:00Z");
|
|
35
|
+
const dirs: string[] = [];
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function tmp(name: string): string {
|
|
42
|
+
const d = realpathSync(mkdtempSync(join(tmpdir(), `chant-commit-${name}-`)));
|
|
43
|
+
dirs.push(d);
|
|
44
|
+
return d;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function sh(args: string[], cwd: string, input?: string): string {
|
|
48
|
+
return execFileSync("git", args, { cwd, encoding: "utf8", input, env: { ...process.env, GIT_AUTHOR_NAME: "ana", GIT_AUTHOR_EMAIL: "ana@x", GIT_COMMITTER_NAME: "ana", GIT_COMMITTER_EMAIL: "ana@x" } });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function write(root: string, files: Record<string, string>): void {
|
|
52
|
+
for (const [p, c] of Object.entries(files)) {
|
|
53
|
+
mkdirSync(dirname(join(root, p)), { recursive: true });
|
|
54
|
+
writeFileSync(join(root, p), c);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** An origin with `main` and a pull request branch `feature`, and a checkout of `main` with the head fetched into the commit ref. */
|
|
59
|
+
function repo(): { origin: string; checkout: string; head: string; git: AgentGit } {
|
|
60
|
+
const origin = tmp("origin");
|
|
61
|
+
sh(["init", "-q", "--bare", "-b", "main"], origin);
|
|
62
|
+
const seed = tmp("seed");
|
|
63
|
+
sh(["clone", "-q", origin, seed], tmpdir());
|
|
64
|
+
write(seed, { "main.tf": "a=1\n", "README.md": "x\n" });
|
|
65
|
+
sh(["add", "-A"], seed);
|
|
66
|
+
sh(["commit", "-q", "-m", "init"], seed);
|
|
67
|
+
sh(["push", "-q", "origin", "main"], seed);
|
|
68
|
+
sh(["checkout", "-q", "-b", "feature"], seed);
|
|
69
|
+
write(seed, { "main.tf": "a = 1\n" });
|
|
70
|
+
sh(["commit", "-q", "-am", "unformatted"], seed);
|
|
71
|
+
sh(["push", "-q", "origin", "feature"], seed);
|
|
72
|
+
const head = sh(["rev-parse", "HEAD"], seed).trim();
|
|
73
|
+
const checkout = tmp("checkout");
|
|
74
|
+
sh(["clone", "-q", origin, checkout], tmpdir());
|
|
75
|
+
sh(["fetch", "-q", "origin", `+refs/heads/feature:${COMMIT_HEAD_REF}`], checkout);
|
|
76
|
+
const git: AgentGit = (args, opts = {}) => sh(["-c", "core.hooksPath=/dev/null", ...args], opts.cwd ?? checkout, opts.input);
|
|
77
|
+
return { origin, checkout, head, git };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A fake formatter: collapses the spaces in main.tf, and writes `extra` too. */
|
|
81
|
+
function formatter(extra: Record<string, string> = {}, exitCode = 0): CommitRunCommand {
|
|
82
|
+
return async (_argv, o) => {
|
|
83
|
+
const { readFileSync } = await import("node:fs");
|
|
84
|
+
const file = join(o.cwd, "main.tf");
|
|
85
|
+
writeFileSync(file, readFileSync(file, "utf8").replace(/ +/g, " ").replace(" = ", "="));
|
|
86
|
+
write(o.cwd, extra);
|
|
87
|
+
return { exitCode, timedOut: false };
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function settings(extra: Partial<OpCommitSpec> = {}): CommitSettings {
|
|
92
|
+
return resolveCommitSpec("plywood-fmt", { on: "comment", comment: "/plywood fmt", command: ["terraform", "fmt", "-recursive"], allowed: ["main.tf", "modules/"], ...extra }, "plywood");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const comment = (body = "/plywood fmt", user = "ana") => ({ comment: { body, user: { login: user } }, issue: { number: 7, pull_request: {} } });
|
|
96
|
+
const checkEvent = { pull_request: { number: 7 } };
|
|
97
|
+
|
|
98
|
+
interface World {
|
|
99
|
+
r: ReturnType<typeof repo>;
|
|
100
|
+
records: OpRunRecord[];
|
|
101
|
+
replies: string[];
|
|
102
|
+
heads: () => PullRequestHead & { base?: string };
|
|
103
|
+
approvals: Map<string, string>;
|
|
104
|
+
canWrite: boolean;
|
|
105
|
+
/** The open pull request whose head is `feature`, for a check that runs on push. */
|
|
106
|
+
pushPr?: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function world(): World {
|
|
110
|
+
const r = repo();
|
|
111
|
+
const w: World = { r, records: [], replies: [], approvals: new Map(), canWrite: true, pushPr: 7, heads: () => ({ sha: sh(["rev-parse", "refs/heads/feature"], r.origin).trim(), branch: "feature", open: true, sameRepo: true, base: "main" }) };
|
|
112
|
+
return w;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function cycle(w: World, s: CommitSettings, o: { event?: unknown; command?: CommitRunCommand; env?: Record<string, string>; between?: () => void } = {}) {
|
|
116
|
+
const d = tmp("dir");
|
|
117
|
+
const forge = {
|
|
118
|
+
pullRequestHead: async () => w.heads(),
|
|
119
|
+
userCanWrite: async () => w.canWrite,
|
|
120
|
+
findPullRequest: async (head: string) => (head === "feature" && w.pushPr ? ({ number: w.pushPr, title: "", body: "", head, base: "main" } as never) : undefined),
|
|
121
|
+
addComment: async (_pr: number, body: string) => {
|
|
122
|
+
w.replies.push(body);
|
|
123
|
+
return { url: "" } as never;
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
const event = o.event ?? (s.on === "comment" ? comment() : checkEvent);
|
|
127
|
+
const env = o.env ?? {};
|
|
128
|
+
const approval = async (_pr: number, sha: string) => w.approvals.get(sha);
|
|
129
|
+
const readRuns = async () => w.records;
|
|
130
|
+
const pullRequestBase = async () => w.heads().base;
|
|
131
|
+
const decision = await prepareCommitRun({ settings: s, words, dir: d, env, event, forge, pullRequestBase, readRuns, approval, git: w.r.git, now: NOW });
|
|
132
|
+
const ran = await runCommit({ settings: s, dir: d, checkout: w.r.checkout, workDir: join(tmp("work"), "w"), env: { PATH: process.env.PATH }, git: w.r.git, runCommand: o.command ?? formatter() });
|
|
133
|
+
o.between?.();
|
|
134
|
+
let t = NOW.getTime();
|
|
135
|
+
const out = await landCommitChange({
|
|
136
|
+
pullRequestBase,
|
|
137
|
+
settings: s,
|
|
138
|
+
words,
|
|
139
|
+
dir: d,
|
|
140
|
+
workDir: join(tmp("land"), "w"),
|
|
141
|
+
env,
|
|
142
|
+
event,
|
|
143
|
+
forge,
|
|
144
|
+
git: w.r.git,
|
|
145
|
+
push: ({ cwd, ref }) => {
|
|
146
|
+
w.r.git(["push", "-q", "origin", `HEAD:${ref}`], { cwd });
|
|
147
|
+
},
|
|
148
|
+
readRuns,
|
|
149
|
+
approval,
|
|
150
|
+
record: async (input: OpRunRecordInput) => {
|
|
151
|
+
w.records.push({ version: 1, id: String(w.records.length), ...input } as OpRunRecord);
|
|
152
|
+
},
|
|
153
|
+
now: () => new Date((t += 1000)),
|
|
154
|
+
});
|
|
155
|
+
// The next cycle sees the branch as it is now.
|
|
156
|
+
w.r.git(["fetch", "-q", "origin", `+refs/heads/feature:${COMMIT_HEAD_REF}`]);
|
|
157
|
+
return { decision, ran, out };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const featureLog = (w: World) => sh(["log", "--format=%s%n%b", "refs/heads/feature"], w.r.origin);
|
|
161
|
+
|
|
162
|
+
describe("settings", () => {
|
|
163
|
+
test("fill the defaults, round-trip through the job's variables, and refuse what no job could run", () => {
|
|
164
|
+
const s = settings();
|
|
165
|
+
expect(s).toMatchObject({ maxRuns: 3, timeout: 10, findings: [2], env: "local", guarded: [] });
|
|
166
|
+
expect(commitSettingsFromEnv(commitSettingsEnv(s), "plywood")).toEqual(s);
|
|
167
|
+
expect(commitSettingsFromEnv(commitSettingsEnv(settings({ mergeBase: true })), "plywood").mergeBase).toBe(true);
|
|
168
|
+
const bad = (spec: Partial<OpCommitSpec>) => () => settings(spec);
|
|
169
|
+
expect(bad({ allowed: [] })).toThrow(/allowed names at least one path/);
|
|
170
|
+
expect(bad({ allowed: ["../x"] })).toThrow(/paths from the repository root/);
|
|
171
|
+
expect(bad({ command: [] })).toThrow(/command is an argv/);
|
|
172
|
+
expect(bad({ command: ["-rf"] })).toThrow(/command is an argv/);
|
|
173
|
+
expect(bad({ comment: "fmt" })).toThrow(/needs comment/);
|
|
174
|
+
expect(bad({ tokenEnv: "not a var" })).toThrow(/tokenEnv is a variable name/);
|
|
175
|
+
expect(bad({ findings: [] })).toThrow(/findings lists/);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("the comment word maps onto commit and takes nothing after it", () => {
|
|
179
|
+
expect(parseProductComment(words, "/plywood fmt")).toEqual({ kind: "commit", word: "fmt" });
|
|
180
|
+
expect(parseProductComment(words, "/plywood fmt now")).toEqual({ kind: "refused", reason: "`/plywood fmt` takes nothing after it" });
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("a path outside allowed and a guarded path are both refused", () => {
|
|
184
|
+
expect(commitRefusedPaths(["main.tf", "modules/a.tf", "other.tf", ".github/workflows/x.yml"], settings())).toEqual({ forbidden: [".github/workflows/x.yml"], outside: ["other.tf", ".github/workflows/x.yml"] });
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("the job lines run the product's bin", () => {
|
|
188
|
+
expect(commitCommandLines("github", "npx --no-install plywood").land).toBe("npx --no-install plywood commit land --forge github --output .chant/commit");
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe("the comment trigger", () => {
|
|
193
|
+
test("pushes the command's change to the branch with the trailer, says so, and records it", async () => {
|
|
194
|
+
const w = world();
|
|
195
|
+
const { out } = await cycle(w, settings());
|
|
196
|
+
expect(out).toMatchObject({ result: "pushed", paths: ["main.tf"], requestedBy: "ana", code: 0 });
|
|
197
|
+
expect(sh(["show", "refs/heads/feature:main.tf"], w.r.origin)).toBe("a=1\n");
|
|
198
|
+
expect(featureLog(w)).toContain(`${COMMIT_TRAILER}: plywood-fmt`);
|
|
199
|
+
expect(featureLog(w)).toContain("Requested-by: ana");
|
|
200
|
+
expect(w.replies[0]).toMatch(/^plywood: pushed `[0-9a-f]{8}` to `feature` for ana, from `terraform fmt -recursive`, changing `main.tf`\. Nothing was applied/);
|
|
201
|
+
expect(w.records).toHaveLength(1);
|
|
202
|
+
expect(w.records[0]!.outcomes.commit).toMatchObject({ trigger: "comment", result: "pushed", pr: 7, requestedBy: "ana" });
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("a second run changes nothing and says so", async () => {
|
|
206
|
+
const w = world();
|
|
207
|
+
await cycle(w, settings());
|
|
208
|
+
const before = sh(["rev-parse", "refs/heads/feature"], w.r.origin);
|
|
209
|
+
const { out } = await cycle(w, settings());
|
|
210
|
+
expect(out).toMatchObject({ result: "refused", reason: "the command changed nothing" });
|
|
211
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin)).toBe(before);
|
|
212
|
+
expect(w.replies[1]).toBe("plywood: `terraform fmt -recursive` changed nothing, so nothing was pushed.");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("goes ahead on an approved head and says the new commit needs approval again", async () => {
|
|
216
|
+
const w = world();
|
|
217
|
+
w.approvals.set(w.r.head, "bo");
|
|
218
|
+
const { out } = await cycle(w, settings());
|
|
219
|
+
expect(out.result).toBe("pushed");
|
|
220
|
+
expect(w.replies[0]).toContain("was approved by bo; the new commit is planned again and needs approval again");
|
|
221
|
+
expect(w.records[0]!.outcomes.commit).toMatchObject({ approvalVoided: "bo" });
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("refuses a commenter who cannot write, a fork, another word and a closed pull request, pushing nothing", async () => {
|
|
225
|
+
for (const [setup, reason] of [
|
|
226
|
+
[(w: World) => (w.canWrite = false), /ana cannot write to the repository/],
|
|
227
|
+
[(w: World) => (w.heads = () => ({ sha: w.r.head, branch: "feature", open: true, sameRepo: false })), /comes from a fork/],
|
|
228
|
+
[(w: World) => (w.heads = () => ({ sha: w.r.head, branch: "feature", open: false, sameRepo: true })), /is not open/],
|
|
229
|
+
] as const) {
|
|
230
|
+
const w = world();
|
|
231
|
+
setup(w);
|
|
232
|
+
const { out } = await cycle(w, settings());
|
|
233
|
+
expect(out.result).toBe("refused");
|
|
234
|
+
expect(out.reason).toMatch(reason);
|
|
235
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
236
|
+
expect(w.replies).toHaveLength(1);
|
|
237
|
+
expect(w.records).toHaveLength(1);
|
|
238
|
+
}
|
|
239
|
+
const w = world();
|
|
240
|
+
const { out } = await cycle(w, settings(), { event: comment("/plywood up") });
|
|
241
|
+
expect(out.result).toBe("refused");
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("refuses a head that moved between the jobs", async () => {
|
|
245
|
+
const w = world();
|
|
246
|
+
const real = w.heads;
|
|
247
|
+
let calls = 0;
|
|
248
|
+
w.heads = () => (++calls > 1 ? { ...real(), sha: "c".repeat(40) } : real());
|
|
249
|
+
const { out } = await cycle(w, settings());
|
|
250
|
+
expect(out).toMatchObject({ result: "refused", reason: "the head moved" });
|
|
251
|
+
expect(w.replies[0]).toContain("moved while plywood-fmt ran");
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("refuses a change outside allowed and one on a guarded path", async () => {
|
|
255
|
+
for (const extra of [{ "other.tf": "x\n" }, { ".github/workflows/x.yml": "on: push\n" }] as Record<string, string>[]) {
|
|
256
|
+
const w = world();
|
|
257
|
+
const { out } = await cycle(w, settings(), { command: formatter(extra) });
|
|
258
|
+
expect(out.result).toBe("refused");
|
|
259
|
+
expect(out.reason).toContain(Object.keys(extra)[0]!);
|
|
260
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
261
|
+
expect(w.replies[0]).toContain("which plywood-fmt may not change");
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("a command that fails pushes nothing", async () => {
|
|
266
|
+
const w = world();
|
|
267
|
+
const { out } = await cycle(w, settings(), { command: formatter({}, 3) });
|
|
268
|
+
expect(out).toMatchObject({ result: "failed", reason: "the command exited 3", code: 1 });
|
|
269
|
+
expect(w.replies[0]).toContain("stopped with exit code 3");
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test("stops at maxRuns pushes to one pull request, counted on the ledger", async () => {
|
|
273
|
+
const w = world();
|
|
274
|
+
w.records.push(
|
|
275
|
+
...[1, 2].map((n) => ({ version: 1, id: `r${n}`, op: "plywood-fmt", env: "local", started: "2026-11-01T00:00:00Z", ended: "2026-11-01T00:00:01Z", status: "ok", labels: {}, phases: [], outcomes: { commit: { pr: 7, result: "pushed" } } }) as unknown as OpRunRecord),
|
|
276
|
+
);
|
|
277
|
+
const { out } = await cycle(w, settings({ maxRuns: 2 }));
|
|
278
|
+
expect(out).toMatchObject({ result: "stopped", reason: "plywood-fmt pushed 2 commits to #7, and its limit is 2" });
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe("the check trigger", () => {
|
|
283
|
+
const check = () => settings({ on: "check", comment: undefined });
|
|
284
|
+
|
|
285
|
+
test("pushes after a failed check, and a second run on its own commit does nothing", async () => {
|
|
286
|
+
const w = world();
|
|
287
|
+
const first = await cycle(w, check());
|
|
288
|
+
expect(first.out.result).toBe("pushed");
|
|
289
|
+
expect(w.replies).toHaveLength(1);
|
|
290
|
+
// The check runs again on the job's own commit: the loop guard skips it, silently and unrecorded.
|
|
291
|
+
const second = await cycle(w, check());
|
|
292
|
+
expect(second.decision).toMatchObject({ go: false, stop: "skipped", reason: "the head is plywood-fmt's own commit" });
|
|
293
|
+
expect(second.out).toMatchObject({ result: "skipped", code: 0 });
|
|
294
|
+
expect(w.replies).toHaveLength(1);
|
|
295
|
+
expect(w.records).toHaveLength(1);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test("an empty change lands nothing and says nothing", async () => {
|
|
299
|
+
const w = world();
|
|
300
|
+
const { out } = await cycle(w, check(), { command: async () => ({ exitCode: 0, timedOut: false }) });
|
|
301
|
+
expect(out).toMatchObject({ result: "skipped", reason: "the command changed nothing" });
|
|
302
|
+
expect(w.replies).toHaveLength(0);
|
|
303
|
+
expect(w.records).toHaveLength(0);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("refuses once the head's plan is approved, so no approval is voided unasked", async () => {
|
|
307
|
+
const w = world();
|
|
308
|
+
w.approvals.set(w.r.head, "bo");
|
|
309
|
+
const { decision, out } = await cycle(w, check());
|
|
310
|
+
expect(decision).toMatchObject({ go: false, reason: `the plan of ${w.r.head.slice(0, 8)} is approved by bo, and a commit would void that approval` });
|
|
311
|
+
expect(out.result).toBe("refused");
|
|
312
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
313
|
+
expect(w.replies).toHaveLength(0);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("refuses on land too when the approval came while the command ran", async () => {
|
|
317
|
+
const w = world();
|
|
318
|
+
let calls = 0;
|
|
319
|
+
const approve = w.approvals;
|
|
320
|
+
w.approvals = { get: (sha: string) => (++calls > 1 ? "bo" : approve.get(sha)) } as unknown as Map<string, string>;
|
|
321
|
+
const { out } = await cycle(w, check());
|
|
322
|
+
expect(out.result).toBe("refused");
|
|
323
|
+
expect(out.reason).toContain("approved by bo");
|
|
324
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test("a check that runs on push finds the branch's open pull request, and a branch with none is skipped silently", async () => {
|
|
328
|
+
const w = world();
|
|
329
|
+
const push = { GITHUB_EVENT_NAME: "push", GITHUB_REF: "refs/heads/feature" };
|
|
330
|
+
const { out } = await cycle(w, check(), { event: { ref: "refs/heads/feature" }, env: push });
|
|
331
|
+
expect(out.result).toBe("pushed");
|
|
332
|
+
expect(w.replies).toHaveLength(1);
|
|
333
|
+
|
|
334
|
+
const none = world();
|
|
335
|
+
none.pushPr = undefined;
|
|
336
|
+
const { decision, out: skipped } = await cycle(none, check(), { event: { ref: "refs/heads/feature" }, env: push });
|
|
337
|
+
expect(decision).toMatchObject({ go: false, stop: "skipped", reason: "feature has no open pull request" });
|
|
338
|
+
expect(skipped.result).toBe("skipped");
|
|
339
|
+
expect(none.replies).toHaveLength(0);
|
|
340
|
+
expect(sh(["rev-parse", "refs/heads/feature"], none.r.origin).trim()).toBe(none.r.head);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("a GitLab branch pipeline reads its merge request from CI_OPEN_MERGE_REQUESTS, this project's only", async () => {
|
|
344
|
+
const w = world();
|
|
345
|
+
const env = { GITLAB_CI: "true", CI_PROJECT_PATH: "acme/infra", CI_OPEN_MERGE_REQUESTS: "fork/infra!3,acme/infra!7" };
|
|
346
|
+
const { out } = await cycle(w, check(), { event: {}, env });
|
|
347
|
+
expect(out.result).toBe("pushed");
|
|
348
|
+
const other = world();
|
|
349
|
+
const { out: skipped } = await cycle(other, check(), { event: {}, env: { ...env, CI_OPEN_MERGE_REQUESTS: "fork/infra!7" } });
|
|
350
|
+
expect(skipped.result).toBe("skipped");
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("reads the merge request on GitLab", async () => {
|
|
354
|
+
const w = world();
|
|
355
|
+
const { out } = await cycle(w, check(), { event: {}, env: { GITLAB_CI: "true", CI_MERGE_REQUEST_IID: "7" } });
|
|
356
|
+
expect(out.result).toBe("pushed");
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
/** A commit on origin's main, from a fresh clone. */
|
|
361
|
+
function onMain(w: World, files: Record<string, string>, message = "on main"): string {
|
|
362
|
+
const c = tmp("main");
|
|
363
|
+
sh(["clone", "-q", "-b", "main", w.r.origin, c], tmpdir());
|
|
364
|
+
write(c, files);
|
|
365
|
+
sh(["add", "-A"], c);
|
|
366
|
+
sh(["commit", "-q", "-m", message], c);
|
|
367
|
+
sh(["push", "-q", "origin", "main"], c);
|
|
368
|
+
return sh(["rev-parse", "HEAD"], c).trim();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
describe("mergeBase (#4723)", () => {
|
|
372
|
+
const merging = () => settings({ mergeBase: true });
|
|
373
|
+
|
|
374
|
+
test("merges the base tip into the head, runs the command on the merge and pushes one commit with both parents", async () => {
|
|
375
|
+
const w = world();
|
|
376
|
+
const tip = onMain(w, { "migrations/002.sql": "create table b;\n" });
|
|
377
|
+
const { decision, out } = await cycle(w, merging());
|
|
378
|
+
expect(decision).toMatchObject({ go: true, base: "main", baseSha: tip });
|
|
379
|
+
expect(out.result).toBe("pushed");
|
|
380
|
+
expect(out.paths).toEqual(["main.tf"]);
|
|
381
|
+
const parents = sh(["log", "-1", "--format=%P", "refs/heads/feature"], w.r.origin).trim().split(" ");
|
|
382
|
+
expect(parents).toEqual([w.r.head, tip]);
|
|
383
|
+
expect(sh(["show", "refs/heads/feature:migrations/002.sql"], w.r.origin)).toBe("create table b;\n");
|
|
384
|
+
expect(sh(["show", "refs/heads/feature:main.tf"], w.r.origin)).toBe("a=1\n");
|
|
385
|
+
expect(w.replies[0]).toContain("from a merge of `main` and `terraform fmt -recursive`");
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test("refuses a merge that conflicts, running nothing", async () => {
|
|
389
|
+
const w = world();
|
|
390
|
+
onMain(w, { "main.tf": "b=2\n" });
|
|
391
|
+
let ran = false;
|
|
392
|
+
const { out } = await cycle(w, merging(), { command: async () => ((ran = true), { exitCode: 0, timedOut: false }) });
|
|
393
|
+
expect(ran).toBe(false);
|
|
394
|
+
expect(out).toMatchObject({ result: "refused", reason: "merging main into the head conflicts" });
|
|
395
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
396
|
+
expect(w.replies[0]).toContain("conflicts, so plywood-fmt did not run");
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test("refuses when the base moved while the command ran", async () => {
|
|
400
|
+
const w = world();
|
|
401
|
+
onMain(w, { "migrations/002.sql": "x\n" });
|
|
402
|
+
const { out } = await cycle(w, merging(), { between: () => void onMain(w, { "migrations/003.sql": "y\n" }, "moved") });
|
|
403
|
+
expect(out).toMatchObject({ result: "refused", reason: "the base moved" });
|
|
404
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test("refuses a change outside allowed, though the merge itself brings other paths", async () => {
|
|
408
|
+
const w = world();
|
|
409
|
+
onMain(w, { "migrations/002.sql": "x\n" });
|
|
410
|
+
const { out } = await cycle(w, merging(), { command: formatter({ "other.tf": "z\n" }) });
|
|
411
|
+
expect(out.result).toBe("refused");
|
|
412
|
+
expect(out.reason).toBe("the change touches other.tf");
|
|
413
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
414
|
+
});
|
|
415
|
+
});
|