@intentius/chant 0.124.79 → 0.124.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/ci-note-commands.d.ts +199 -0
  2. package/dist/ci-note-commands.d.ts.map +1 -0
  3. package/dist/ci-note-commands.js +372 -0
  4. package/dist/cli/handlers/build.d.ts.map +1 -1
  5. package/dist/cli/handlers/build.js +7 -1
  6. package/dist/cli/handlers/pr-notes.d.ts +13 -0
  7. package/dist/cli/handlers/pr-notes.d.ts.map +1 -0
  8. package/dist/cli/handlers/pr-notes.js +73 -0
  9. package/dist/cli/main.d.ts.map +1 -1
  10. package/dist/cli/main.js +10 -1
  11. package/dist/cli/mcp/product-tools.d.ts.map +1 -1
  12. package/dist/cli/mcp/product-tools.js +1 -2
  13. package/dist/cli/parse-args.d.ts.map +1 -1
  14. package/dist/cli/parse-args.js +10 -0
  15. package/dist/cli/registry.d.ts +4 -0
  16. package/dist/cli/registry.d.ts.map +1 -1
  17. package/dist/components/capability.d.ts +11 -0
  18. package/dist/components/capability.d.ts.map +1 -1
  19. package/dist/components/pr-pipeline.d.ts +22 -0
  20. package/dist/components/pr-pipeline.d.ts.map +1 -1
  21. package/dist/components/pr-pipeline.js +26 -0
  22. package/dist/components/product-pipeline.d.ts +12 -0
  23. package/dist/components/product-pipeline.d.ts.map +1 -1
  24. package/dist/components/product-pipeline.js +5 -1
  25. package/dist/lifecycle/release-version.d.ts.map +1 -1
  26. package/dist/lifecycle/release-version.js +1 -2
  27. package/dist/op/index.d.ts +2 -2
  28. package/dist/op/index.d.ts.map +1 -1
  29. package/dist/op/index.js +1 -1
  30. package/dist/op/op-waves-after-plan.d.ts +33 -0
  31. package/dist/op/op-waves-after-plan.d.ts.map +1 -1
  32. package/dist/op/op-waves-after-plan.js +41 -3
  33. package/dist/op/op-waves-capability.d.ts +4 -1
  34. package/dist/op/op-waves-capability.d.ts.map +1 -1
  35. package/dist/op/op-waves-capability.js +14 -14
  36. package/dist/op/op-waves-run-hooks.d.ts.map +1 -1
  37. package/dist/op/op-waves-run-hooks.js +1 -2
  38. package/dist/op/op-waves-run.d.ts.map +1 -1
  39. package/dist/op/op-waves-run.js +78 -12
  40. package/dist/pr-forge-reads.d.ts +151 -1
  41. package/dist/pr-forge-reads.d.ts.map +1 -1
  42. package/dist/pr-forge-reads.js +265 -1
  43. package/dist/release-floors.d.ts +15 -1
  44. package/dist/release-floors.d.ts.map +1 -1
  45. package/dist/release-floors.js +17 -3
  46. package/dist/wave-runtime.mjs +272 -272
  47. package/package.json +1 -1
  48. package/src/ci-note-commands.test.ts +377 -0
  49. package/src/ci-note-commands.ts +479 -0
  50. package/src/cli/handlers/build.ts +7 -1
  51. package/src/cli/handlers/pr-notes.ts +70 -0
  52. package/src/cli/main.ts +10 -1
  53. package/src/cli/mcp/product-tools.test.ts +1 -2
  54. package/src/cli/mcp/product-tools.ts +1 -2
  55. package/src/cli/parse-args.ts +8 -0
  56. package/src/cli/registry.ts +4 -0
  57. package/src/components/capability.ts +11 -0
  58. package/src/components/pr-pipeline.ts +35 -0
  59. package/src/components/product-pipeline.test.ts +14 -0
  60. package/src/components/product-pipeline.ts +13 -1
  61. package/src/lifecycle/release-version.ts +1 -2
  62. package/src/op/index.ts +2 -2
  63. package/src/op/op-waves-after-plan-wave.test.ts +2 -3
  64. package/src/op/op-waves-after-plan.ts +61 -3
  65. package/src/op/op-waves-capability.test.ts +3 -1
  66. package/src/op/op-waves-capability.ts +17 -17
  67. package/src/op/op-waves-gate-port.test.ts +232 -0
  68. package/src/op/op-waves-run-hooks.test.ts +2 -3
  69. package/src/op/op-waves-run-hooks.ts +1 -2
  70. package/src/op/op-waves-run.ts +78 -14
  71. package/src/op/op-waves-step-wave.test.ts +3 -4
  72. package/src/pr-forge-reads-compare.test.ts +145 -0
  73. package/src/pr-forge-reads.test.ts +203 -0
  74. package/src/pr-forge-reads.ts +398 -1
  75. package/src/release-floors.ts +24 -3
@@ -0,0 +1,232 @@
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 next release", async () => {
228
+ const entry = await import("./index");
229
+ const { NEXT_RELEASE } = await import("../release-floors");
230
+ expect(entry.OP_WAVE_ANSWER_APPROVALS_FLOOR).toBe(NEXT_RELEASE);
231
+ });
232
+ });
@@ -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 the next release", async () => {
179
+ test("the floor is 0.124.79", async () => {
180
180
  const entry = await import("./index");
181
- const { NEXT_RELEASE } = await import("../release-floors");
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 = NEXT_RELEASE;
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 {
@@ -93,7 +93,7 @@ import { LifecyclePushLostError, pushLifecycleRebasing } from "../lifecycle/git"
93
93
  import { resolveCiJob } from "../lifecycle/release-ledger";
94
94
  import type { OpRunPolicyRow, OpRunRecordInput, OpRunStepRecord, OpRunWave, OpRunWavePlan, OpRunWaveTarget } from "./runtime";
95
95
  import { opWaveRunHookList, opWaveRunHooksProblems, runOpWaveAfterApply, runOpWaveBeforeApply, runOpWaveBeforePlan, type OpWaveRunHooks } from "./op-waves-run-hooks";
96
- import { foldPolicyRows, opWaveAfterPlanProblems, runOpWaveAfterPlanHooks, type OpWaveAfterPlanHook, type OpWaveAfterPlanRun, type OpWaveAfterPlanWaveOutcome } from "./op-waves-after-plan";
96
+ import { foldPolicyRows, opWaveAfterPlanProblems, runOpWaveAfterPlanHooks, type OpWaveAfterPlanHook, type OpWaveAfterPlanRun, type OpWaveAfterPlanWaveOutcome, type OpWaveAnswerApproval } from "./op-waves-after-plan";
97
97
  import { activeOtlp, RunEventTrace, type CapabilityTraceFacts, type OtlpExporter } from "../otlp";
98
98
  import { joinRunEventSinks, resolveRunEventRun, type RunEventSink } from "../run-event-stream";
99
99
  import { OpWaveRunEvents } from "./op-waves-events";
@@ -127,7 +127,7 @@ import {
127
127
  type OpWaveStepPlan,
128
128
  } from "./op-waves-capability";
129
129
  import {
130
- changeInvolvement, quorumProblems, quorumRuleLine, quorumRulesFor, quorumWaiting, recordedReviewApprovals, ruleNeedsProof, samePrincipal, trustQuorumJudge,
130
+ changeInvolvement, quorumProblems, quorumRuleLine, quorumRulesFor, quorumWaiting, recordedReviewApprovals, recordedReviewOf, ruleNeedsProof, samePrincipal, trustQuorumJudge,
131
131
  type GateQuorumJudge, type GateQuorumRule, type GateQuorumRuleProgress, type QuorumJudgement,
132
132
  } from "./gate-quorum";
133
133
  import {
@@ -716,10 +716,11 @@ function quorumAtBase(spec: OpWavesSpec, where: string): Pick<OpWaveBaseRules, "
716
716
  if (bad.length > 0) return { quorumRefused: `the approval rules in ${where} cannot be read (${bad.join("; ")})` };
717
717
  extra.involved = structuredClone(a.involved as OpWavesInvolved);
718
718
  }
719
- if (raw === undefined) return {};
719
+ // terragucci issue 1303: the review ledger and the involved count without rules too.
720
+ if (raw === undefined) return extra;
720
721
  const problems = Array.isArray(raw) ? quorumProblems(raw, "approvals.quorum", { notAuthor: true }) : ["`approvals.quorum` must be a list of rules"];
721
722
  if (problems.length > 0) return { quorumRefused: `the approval rules in ${where} cannot be read (${problems.join("; ")})` };
722
- return (raw as GateQuorumRule[]).length > 0 ? { quorum: raw as GateQuorumRule[], ...extra } : {};
723
+ return (raw as GateQuorumRule[]).length > 0 ? { quorum: raw as GateQuorumRule[], ...extra } : extra;
723
724
  }
724
725
 
725
726
  /** The holds at base (#4545), or why they cannot be read. */
@@ -974,6 +975,8 @@ interface WaveContext {
974
975
  changeSetDoc?: ChangeSetDocument;
975
976
  /** An after-plan hook's report of the wave's plans (#4842), stored beside the pending fact. */
976
977
  report?: string;
978
+ /** The approvals the after-plan hooks settled before the gate (terragucci issue 1303), recorded at it before it is decided. */
979
+ answerApprovals?: OpWaveAnswerApproval[];
977
980
  }
978
981
 
979
982
  function planRun(opts: { spec: OpWavesSpec; wave: number; cwd: string; exec: OpWaveExec }, waveName: string, run: OpWaveRun): OpWaveMember {
@@ -1161,11 +1164,11 @@ async function applyStepRun(ctx: WaveContext, registry: CapabilityRegistry, run:
1161
1164
  const { spec, wave, k, options } = ctx;
1162
1165
  const hooks = opWaveRunHookList(options.runHooks);
1163
1166
  const env = ctx.runEnv?.get(run.target);
1164
- if (hooks.length === 0) return applyOpWaveStep({ spec, wave, registry, ...(env ? { processEnv: env } : {}) }, run, plan);
1167
+ if (hooks.length === 0) return applyOpWaveStep({ spec, wave, registry, cwd: ctx.cwd, ...(env ? { processEnv: env } : {}) }, run, plan);
1165
1168
  const planned = { ...runHookRun(ctx, run), planDigest: plan.planDigest, plan: opWavePlanPath(spec, k, run.target), ...(plan.artifact !== undefined ? { artifact: plan.artifact } : {}) };
1166
1169
  const stop = await runOpWaveBeforeApply(hooks, planned);
1167
1170
  if (stop !== undefined) return { outcome: "failed", reason: stop };
1168
- const got = await applyOpWaveStep({ spec, wave, registry, ...(env ? { processEnv: env } : {}) }, run, plan);
1171
+ const got = await applyOpWaveStep({ spec, wave, registry, cwd: ctx.cwd, ...(env ? { processEnv: env } : {}) }, run, plan);
1169
1172
  const after = await runOpWaveAfterApply(hooks, { ...planned, outcome: got.outcome, ...(got.outcome === "applied" ? { output: got.output } : { reason: got.reason }) });
1170
1173
  const files = after.files.length > 0 ? { files: after.files } : {};
1171
1174
  if (after.failed && got.outcome === "applied") return { outcome: "failed", reason: `applied, and then ${after.failed}`, ...(got.facts ? { facts: got.facts } : {}), ...files };
@@ -1191,7 +1194,7 @@ async function planWaveRuns(
1191
1194
  // #4613: a step's own policy engine (CrossGuard) reads its packs at the base the wave's rules were read at.
1192
1195
  const policyBase = base && base !== "HEAD" ? base : undefined;
1193
1196
  // #4842: a discovering wave's runs are the ones its step's capability finds for wave k.
1194
- const found = discover ? await discoverOpWaveStepRuns({ spec, wave, k, registry }) : undefined;
1197
+ const found = discover ? await discoverOpWaveStepRuns({ spec, wave, k, registry, cwd }) : undefined;
1195
1198
  if (found) runs = found.runs;
1196
1199
  const plans: OpWaveStepPlan[] = [];
1197
1200
  const hooks = opWaveRunHookList(at.options.runHooks);
@@ -2634,6 +2637,7 @@ async function planOpWave(options: RunOpWaveOptions, { k, pass }: WaveAttempt<Ru
2634
2637
  extras = [...(extras ?? []), ...answer.members];
2635
2638
  }
2636
2639
  if (answer?.report !== undefined) ctx.report = answer.report;
2640
+ if (answer?.approvals.length) ctx.answerApprovals = answer.approvals;
2637
2641
  if (wave.discover) {
2638
2642
  wave = { ...wave, runs: members.map((m) => ({ target: m.member, ...(m.op !== spec.op ? { op: m.op } : {}) })) };
2639
2643
  ctx.wave = wave;
@@ -2707,8 +2711,9 @@ async function decideOpWave(
2707
2711
  decision.members = members;
2708
2712
  // #4290: the rules at base whose targets glob matches one of the wave's runs.
2709
2713
  const takes = planned.rules.quorum ? quorumRulesFor(planned.rules.quorum, members.map((m) => m.member)) : [];
2710
- if (takes.length > 0) {
2711
- decision.quorum = takes;
2714
+ if (takes.length > 0) decision.quorum = takes;
2715
+ // terragucci issue 1303: a wave no rule covers still leaves the involved out, and counts a review the product recorded.
2716
+ if (takes.length > 0 || opWaveOneApprover(decision.approval, planned.rules)) {
2712
2717
  if (planned.rules.reviewLedger) decision.reviewLedger = planned.rules.reviewLedger;
2713
2718
  if (planned.rules.involved) decision.involved = planned.rules.involved;
2714
2719
  }
@@ -2751,6 +2756,8 @@ async function decideOpWave(
2751
2756
  decision.status = "approved";
2752
2757
  log(`wave ${k} (${wave.name}): planned again to the same digest, so the approval by ${was.approvedBy} still holds`);
2753
2758
  } else if (decision.status !== "refused" && (unseen || opWaveNeedsApproval(policy, members) || holds.length > 0)) {
2759
+ // terragucci issue 1303: what the product settled before the gate, recorded at it for these plans first.
2760
+ if (ctx.answerApprovals?.length) await recordAnswerApprovals(options, ctx, decision);
2754
2761
  await settleGate(options, ctx, decision);
2755
2762
  // Plans nobody previewed apply only under an approval of these very plans, whatever the gate policy says.
2756
2763
  if (unseen) refuseUnseen(ctx, decision);
@@ -3124,6 +3131,8 @@ function failed(ctx: WaveContext, line: string): RunOpWaveResult {
3124
3131
  async function settleGate(options: RunOpWaveOptions, ctx: WaveContext, decision: OpWaveDecision): Promise<void> {
3125
3132
  if (decision.point) return settlePointGate(options, ctx, decision, decision.point);
3126
3133
  if (decision.quorum?.length) return settleQuorumGate(options, ctx, decision, decision.quorum);
3134
+ // terragucci issue 1303: with no rule, `approvals.involved.exclude` and a review ledger still judge each approval, as one approver's rule does.
3135
+ if ((decision.involved?.exclude || decision.reviewLedger) && decision.approval !== "pull-request") return settleQuorumGate(options, ctx, decision, [{ count: 1 }], true);
3127
3136
  const { spec, k, wave, cwd } = ctx;
3128
3137
  const { gate, digest, approval, base, policy, members } = decision;
3129
3138
  // #4574: the run target a product's approve line names.
@@ -3279,7 +3288,7 @@ const gitCommitsBetween = (cwd: string) => (base: string, head: string): { sha:
3279
3288
  * the same pull request; with none, no approver can show they are someone
3280
3289
  * else and the rule waits.
3281
3290
  */
3282
- async function settleQuorumGate(options: RunOpWaveOptions, ctx: WaveContext, decision: OpWaveDecision, rules: GateQuorumRule[]): Promise<void> {
3291
+ async function settleQuorumGate(options: RunOpWaveOptions, ctx: WaveContext, decision: OpWaveDecision, rules: GateQuorumRule[], oneApprover = false): Promise<void> {
3283
3292
  const { spec, k, wave, cwd, log } = ctx;
3284
3293
  const { gate, digest, approval, base, policy, members } = decision;
3285
3294
  const { ledger, port } = await gatePort(options, cwd, gate, approval, base);
@@ -3384,7 +3393,11 @@ async function settleQuorumGate(options: RunOpWaveOptions, ctx: WaveContext, dec
3384
3393
  ...(reviewed ? { review: reviewed } : {}),
3385
3394
  ...(recorded.length > 0 ? { recorded } : {}),
3386
3395
  });
3387
- const judge: GateQuorumJudge = (r) => sayExcluded(judgeBase(r));
3396
+ // terragucci issue 1303: on the spec's own ledger a product's review line names every reviewer in one approver, and each reviewer counts on their own line.
3397
+ const judge: GateQuorumJudge = (r) =>
3398
+ decision.reviewLedger === spec.name && recordedReviewOf(r) !== null
3399
+ ? { proven: false, roles: [], excluded: `the review line by ${r.resolvedBy} counts each of its reviewers on their own` }
3400
+ : sayExcluded(judgeBase(r));
3388
3401
  const held = decision.heldBy?.length ? `, held by ${decision.heldBy.join(", ")}` : "";
3389
3402
  const check = await decideWaveGate(port, {
3390
3403
  op: spec.name,
@@ -3404,7 +3417,7 @@ async function settleQuorumGate(options: RunOpWaveOptions, ctx: WaveContext, dec
3404
3417
  decision.via = reviewed && check.resolution.review?.head === reviewed.head ? "pr-review" : "ledger";
3405
3418
  decision.approvedBy = by.join(", ");
3406
3419
  decision.approvedAt = check.resolution.timestamp;
3407
- log(`${label}: the approval rules at ${base.slice(0, 12)} are met by ${by.join(", ")}`);
3420
+ log(oneApprover ? `${label}: approved by ${by.join(", ")}, who had no hand in the change` : `${label}: the approval rules at ${base.slice(0, 12)} are met by ${by.join(", ")}`);
3408
3421
  return;
3409
3422
  }
3410
3423
  logRefused(log, label, check);
@@ -3412,7 +3425,8 @@ async function settleQuorumGate(options: RunOpWaveOptions, ctx: WaveContext, dec
3412
3425
  decision.recorded = check.recorded;
3413
3426
  decision.waitingSince = check.pending.timestamp;
3414
3427
  if (check.mismatch) decision.mismatch = check.mismatch;
3415
- if (check.quorum?.rules) {
3428
+ if (oneApprover) log(`${label}: no approval of ${digest} counts once the people behind the change are left out, so it waits for one`);
3429
+ else if (check.quorum?.rules) {
3416
3430
  decision.quorumProgress = check.quorum.rules;
3417
3431
  for (const p of check.quorum.rules) log(`${label}: approval rule ${quorumRuleLine(p)}`);
3418
3432
  log(`${label}: the approval rules at ${base.slice(0, 12)} are not met (${quorumWaiting(check.quorum.rules)}), so it waits for more approvals of ${digest}`);
@@ -3938,7 +3952,7 @@ async function applyStepRunsTogether(options: RunOpWaveOptions, ctx: WaveContext
3938
3952
  result.failed.push(...runs.map((r) => r.target));
3939
3953
  return;
3940
3954
  }
3941
- const got = await applyOpWaveStepGroup({ spec, wave, registry, runEnv: (target) => ctx.runEnv?.get(target) }, planned);
3955
+ const got = await applyOpWaveStepGroup({ spec, wave, registry, cwd: ctx.cwd, runEnv: (target) => ctx.runEnv?.get(target) }, planned);
3942
3956
  for (const [i, p] of planned.entries()) {
3943
3957
  let outcome = got[i]!;
3944
3958
  let files: string[] | undefined;
@@ -4252,3 +4266,53 @@ async function writeHeadPlans(plans: HeadPlans, cwd: string): Promise<void> {
4252
4266
  const pushed = await pushLifecycleRebasing({ cwd });
4253
4267
  if (!pushed.pushed) throw new Error(`the plans were recorded locally only: ${pushed.pushWarning ?? "chant/lifecycle has no remote to push to"}`);
4254
4268
  }
4269
+
4270
+ /**
4271
+ * Whether a wave no approval rule covers is still judged approver by
4272
+ * approver (terragucci issue 1303): `approvals.involved.exclude`, or a
4273
+ * review ledger under `pr-review`, at base. Not under `pull-request`, whose
4274
+ * approval is the pull request's gate.
4275
+ */
4276
+ function opWaveOneApprover(approval: GateApprovalSource, rules: Pick<OpWaveBaseRules, "involved" | "reviewLedger">): boolean {
4277
+ if (approval === "pull-request") return false;
4278
+ return rules.involved?.exclude === true || (rules.reviewLedger !== undefined && approval === "pr-review");
4279
+ }
4280
+
4281
+ /**
4282
+ * Record the approvals the after-plan hooks settled before the gate
4283
+ * (terragucci issue 1303) at the wave's gate, for the digest it decides, on
4284
+ * the spec's op. An approval already recorded for the digest by the same
4285
+ * approver with the same note is not written again. A gate that asks a
4286
+ * decision point records none: only its answer passes the wave.
4287
+ */
4288
+ async function recordAnswerApprovals(options: RunOpWaveOptions, ctx: WaveContext, decision: OpWaveDecision): Promise<void> {
4289
+ const { spec, k, wave, cwd, log } = ctx;
4290
+ const label = `wave ${k} (${wave.name})`;
4291
+ const approvals = ctx.answerApprovals ?? [];
4292
+ if (decision.point) {
4293
+ log(`${label}: the gate asks a decision point, so the ${approvals.length} approval${approvals.length === 1 ? "" : "s"} the after-plan hooks gave ${approvals.length === 1 ? "is" : "are"} not recorded`);
4294
+ return;
4295
+ }
4296
+ const ledger = options.gates ?? gitGateLedgerPort({ cwd });
4297
+ if (!ledger.appendResolution) {
4298
+ log(`${label}: the gate ledger takes no approvals, so the ones the after-plan hooks gave are not recorded`);
4299
+ return;
4300
+ }
4301
+ const now = options.now ?? new Date().toISOString();
4302
+ const had = (await ledger.read(spec.name)).resolutions.filter((r) => r.gate === decision.gate && samePlanDigest(r.planDigest, decision.digest));
4303
+ for (const a of approvals) {
4304
+ if (had.some((r) => r.resolvedBy === a.resolvedBy && r.note === a.note)) continue;
4305
+ const review = a.review ? { via: "pr-review", pr: a.review.pr, head: a.review.head, reviewers: a.review.reviewers } : {};
4306
+ await ledger.appendResolution({
4307
+ op: spec.name,
4308
+ gate: decision.gate,
4309
+ resolvedBy: a.resolvedBy,
4310
+ timestamp: now,
4311
+ planDigest: decision.digest,
4312
+ note: a.note,
4313
+ ...(a.url ? { url: a.url } : {}),
4314
+ ...(review as object),
4315
+ } as Parameters<NonNullable<GateLedgerPort["appendResolution"]>>[0]);
4316
+ log(`${label}: ${a.resolvedBy}'s approval recorded for ${decision.digest}: ${a.note}`);
4317
+ }
4318
+ }
@@ -16,7 +16,6 @@ import { CapabilityRegistry, type Capability, type CapabilityGroupOutcome, type
16
16
  import type { ChangeSetPart } from "../change-set";
17
17
  import { groupDigest } from "../components/groups";
18
18
  import { waveSetDigest } from "../wave-engine";
19
- import { NEXT_RELEASE } from "../release-floors";
20
19
  import type { OpWaveRunHooks } from "./op-waves-run-hooks";
21
20
 
22
21
  const digest = (n: string) => `sha256:${n.repeat(64)}`;
@@ -127,7 +126,7 @@ describe("a wave planned as one through a step (#4842)", () => {
127
126
  expect(result.exitCode).toBe(0);
128
127
  // The input has {op} and {wave} filled and {target} as written; the wave number is the one planned.
129
128
  expect(seen.discovered.map((d) => d.ctx)).toEqual([
130
- { env: "rest", wave: { name: "rest", number: 2 } },
129
+ { env: "rest", cwd: h.cwd, wave: { name: "rest", number: 2 } },
131
130
  ]);
132
131
  expect(seen.discovered[0]!.input).toEqual({ unit: "{target}", dir: ".", wave: "rest" });
133
132
  expect(seen.planned).toEqual(["live/c"]);
@@ -175,7 +174,7 @@ describe("a wave planned as one through a step (#4842)", () => {
175
174
  expect(result.exitCode).toBe(0);
176
175
  expect(seen.planned).toEqual([]);
177
176
  expect(seen.groups).toHaveLength(1);
178
- expect(seen.groups[0]!.ctx).toEqual({ env: "layer", components: ["live/a", "live/b"] });
177
+ expect(seen.groups[0]!.ctx).toEqual({ env: "layer", cwd: h.cwd, components: ["live/a", "live/b"] });
179
178
  expect(seen.groups[0]!.members.map((m) => m.input)).toEqual([
180
179
  { unit: "live/a", dir: ".", wave: "layer" },
181
180
  { unit: "live/b", dir: ".", wave: "layer" },
@@ -272,6 +271,6 @@ describe("a wave planned as one through a step (#4842)", () => {
272
271
 
273
272
  test("the floor is the next release", async () => {
274
273
  const entry = await import("./index");
275
- expect(entry.OP_WAVE_STEP_WAVE_FLOOR).toBe(NEXT_RELEASE);
274
+ expect(entry.OP_WAVE_STEP_WAVE_FLOOR).toBe("0.124.79");
276
275
  });
277
276
  });
@@ -0,0 +1,145 @@
1
+ /**
2
+ * The forge reads of a comparison, a job and a job's artifact file (#4862),
3
+ * against a loopback fake of each forge: the calls each makes on GitHub,
4
+ * Forgejo and GitLab, and what each reads back.
5
+ */
6
+
7
+ import { afterAll, beforeAll, beforeEach, describe, expect, test } from "vitest";
8
+ import { createServer, type Server } from "node:http";
9
+ import type { AddressInfo } from "node:net";
10
+ import { forgejoReads, githubReads, gitlabReads } from "./pr-forge-reads";
11
+
12
+ const SHA = "a".repeat(40);
13
+
14
+ /** A route answers JSON, a status, or `{ raw }`, a body sent as it is. */
15
+ type Answer = unknown;
16
+ let routes: Record<string, Answer> = {};
17
+ let calls: { method: string; url: string; headers: Record<string, string | string[] | undefined> }[] = [];
18
+ let server: Server;
19
+ let origin = "";
20
+
21
+ beforeAll(async () => {
22
+ server = createServer((req, res) => {
23
+ calls.push({ method: req.method ?? "", url: req.url ?? "", headers: req.headers });
24
+ const path = new URL(req.url ?? "/", "http://x").pathname;
25
+ const found = routes[`${req.method} ${path}`];
26
+ if (found === undefined) {
27
+ res.writeHead(404, { "content-type": "application/json" });
28
+ res.end('{"message":"404 Not Found"}');
29
+ return;
30
+ }
31
+ if (typeof found === "number") {
32
+ res.writeHead(found);
33
+ res.end();
34
+ return;
35
+ }
36
+ if (typeof found === "object" && found !== null && "raw" in found) {
37
+ res.writeHead(200, { "content-type": "application/octet-stream" });
38
+ res.end(String((found as { raw: string }).raw));
39
+ return;
40
+ }
41
+ res.writeHead(200, { "content-type": "application/json" });
42
+ res.end(JSON.stringify(found));
43
+ });
44
+ await new Promise<void>((r) => server.listen(0, "127.0.0.1", () => r()));
45
+ origin = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
46
+ });
47
+
48
+ afterAll(() => new Promise<void>((r) => server.close(() => r())));
49
+
50
+ beforeEach(() => {
51
+ routes = {};
52
+ calls = [];
53
+ });
54
+
55
+ const urls = () => calls.map((c) => `${c.method} ${c.url}`);
56
+ const gh = () => githubReads({ apiBase: origin, repo: "acme/infra", token: "t0k" });
57
+ const fj = () => forgejoReads({ apiBase: `${origin}/api/v1`, repo: "acme/infra", token: "t0k" });
58
+ const gl = () => gitlabReads({ apiBase: `${origin}/api/v4`, project: "acme/infra", token: "glpat" });
59
+ const P = "/api/v4/projects/acme%2Finfra";
60
+
61
+ describe("compare", () => {
62
+ test("github: the files a head changes since its merge base, a rename with its old path", async () => {
63
+ routes[`GET /repos/acme/infra/compare/main...${SHA}`] = {
64
+ behind_by: 1,
65
+ files: [{ filename: "a.tf", status: "modified" }, { filename: ".github/workflows/ci.yml", previous_filename: "ci.yml", status: "renamed" }],
66
+ };
67
+ expect(await gh().compare("main", SHA)).toEqual({ files: [{ path: "a.tf" }, { path: ".github/workflows/ci.yml", previousPath: "ci.yml" }], truncated: false });
68
+ expect(urls()).toEqual([`GET /repos/acme/infra/compare/main...${SHA}`]);
69
+ expect(calls[0]!.headers.authorization).toBe("Bearer t0k");
70
+ });
71
+
72
+ test("github: a list of 300 files is the most GitHub lists, so it says it may be cut short", async () => {
73
+ routes[`GET /repos/acme/infra/compare/release%2F1...${SHA}`] = { files: Array.from({ length: 300 }, (_, i) => ({ filename: `f${i}` })) };
74
+ const got = await gh().compare("release/1", SHA);
75
+ expect(got.files).toHaveLength(300);
76
+ expect(got.truncated).toBe(true);
77
+ });
78
+
79
+ test("forgejo: the files its commits change, once each, cut short when it lists fewer commits than it counts", async () => {
80
+ routes[`GET /api/v1/repos/acme/infra/compare/main...${SHA}`] = {
81
+ total_commits: 2,
82
+ commits: [{ sha: SHA, files: [{ filename: "a.tf", status: "modified" }, { filename: ".forgejo/workflows/ci.yml", status: "added" }] }, { sha: "b".repeat(40), files: [{ filename: "a.tf", status: "modified" }] }],
83
+ };
84
+ expect(await fj().compare("main", SHA)).toEqual({ files: [{ path: "a.tf" }, { path: ".forgejo/workflows/ci.yml" }], truncated: false });
85
+ expect(calls[0]!.headers.authorization).toBe("token t0k");
86
+ routes[`GET /api/v1/repos/acme/infra/compare/main...${SHA}`] = { total_commits: 3, commits: [{ sha: SHA, files: [{ filename: "a.tf" }] }] };
87
+ expect((await fj().compare("main", SHA)).truncated).toBe(true);
88
+ routes[`GET /api/v1/repos/acme/infra/compare/main...${SHA}`] = { total_commits: 1, commits: [{ sha: SHA }] };
89
+ expect((await fj().compare("main", SHA)).truncated).toBe(true);
90
+ });
91
+
92
+ test("gitlab: the diffs' paths from the merge base, cut short when the compare timed out", async () => {
93
+ routes[`GET ${P}/repository/compare`] = { diffs: [{ old_path: "a.tf", new_path: "a.tf" }, { old_path: "ci.yml", new_path: ".gitlab-ci.yml", renamed_file: true }], compare_timeout: false };
94
+ expect(await gl().compare("main", SHA)).toEqual({ files: [{ path: "a.tf" }, { path: ".gitlab-ci.yml", previousPath: "ci.yml" }], truncated: false });
95
+ expect(urls()).toEqual([`GET ${P}/repository/compare?from=main&to=${SHA}&straight=false`]);
96
+ expect(calls[0]!.headers["private-token"]).toBe("glpat");
97
+ routes[`GET ${P}/repository/compare`] = { diffs: [], compare_timeout: true };
98
+ expect((await gl().compare("main", SHA)).truncated).toBe(true);
99
+ });
100
+ });
101
+
102
+ describe("a job by id, and the jobs' URLs", () => {
103
+ test("github: a job with its run, branch and URL; undefined when missing", async () => {
104
+ routes["GET /repos/acme/infra/actions/jobs/5"] = { id: 5, run_id: 10, name: "review", status: "completed", conclusion: "success", head_branch: "main", html_url: "https://github.com/acme/infra/actions/runs/10/job/5" };
105
+ expect(await gh().job(5)).toEqual({ id: 5, name: "review", status: "completed", conclusion: "success", done: true, run: 10, ref: "main", url: "https://github.com/acme/infra/actions/runs/10/job/5" });
106
+ expect(await gh().job(6)).toBeUndefined();
107
+ expect(urls()).toEqual(["GET /repos/acme/infra/actions/jobs/5", "GET /repos/acme/infra/actions/jobs/6"]);
108
+ });
109
+
110
+ test("forgejo: a job by id", async () => {
111
+ routes["GET /api/v1/repos/acme/infra/actions/jobs/5"] = { id: 5, run_id: 10, name: "review", status: "running", head_branch: "main", html_url: "https://code.acme.io/acme/infra/actions/runs/3/jobs/0" };
112
+ expect(await fj().job(5)).toEqual({ id: 5, name: "review", status: "running", done: false, run: 10, ref: "main", url: "https://code.acme.io/acme/infra/actions/runs/3/jobs/0" });
113
+ });
114
+
115
+ test("gitlab: a job with its pipeline, ref, tag and URL; a pipeline's jobs with their URLs", async () => {
116
+ routes[`GET ${P}/jobs/5`] = { id: 5, name: "review", status: "success", ref: "main", tag: false, web_url: "https://gitlab.com/acme/infra/-/jobs/5", pipeline: { id: 10, sha: SHA } };
117
+ routes[`GET ${P}/jobs/6`] = { id: 6, name: "plan", status: "failed", ref: "v1", tag: true, pipeline: { id: 11 } };
118
+ expect(await gl().job(5)).toEqual({ id: 5, name: "review", status: "success", done: true, run: 10, ref: "main", tag: false, url: "https://gitlab.com/acme/infra/-/jobs/5" });
119
+ expect(await gl().job(6)).toEqual({ id: 6, name: "plan", status: "failed", done: true, run: 11, ref: "v1", tag: true });
120
+ expect(await gl().job(7)).toBeUndefined();
121
+ routes[`GET ${P}/pipelines/10/jobs`] = [{ id: 4, name: "plan", status: "success", ref: "refs/merge-requests/3/head", tag: false, web_url: "https://gitlab.com/acme/infra/-/jobs/4", pipeline: { id: 10 } }];
122
+ expect(await gl().runJobs(10)).toEqual([{ id: 4, name: "plan", status: "success", done: true, run: 10, ref: "refs/merge-requests/3/head", tag: false, url: "https://gitlab.com/acme/infra/-/jobs/4" }]);
123
+ });
124
+ });
125
+
126
+ describe("a job's artifact file", () => {
127
+ test("gitlab: one file of a job's artifacts as text, each path segment encoded; undefined when there is none", async () => {
128
+ routes[`GET ${P}/jobs/5/artifacts/terragucci-report/plan%20note.md`] = { raw: "## plan\n\nno changes\n" };
129
+ const reads = gl();
130
+ expect(await reads.artifactFile!(5, "terragucci-report/plan note.md")).toBe("## plan\n\nno changes\n");
131
+ expect(await reads.artifactFile!(5, "terragucci-report/status")).toBeUndefined();
132
+ expect(urls()).toEqual([`GET ${P}/jobs/5/artifacts/terragucci-report/plan%20note.md`, `GET ${P}/jobs/5/artifacts/terragucci-report/status`]);
133
+ expect(calls[0]!.headers["private-token"]).toBe("glpat");
134
+ });
135
+
136
+ test("gitlab: another error throws", async () => {
137
+ routes[`GET ${P}/jobs/5/artifacts/r/x`] = 500;
138
+ await expect(gl().artifactFile!(5, "r/x")).rejects.toThrow(/500/);
139
+ });
140
+
141
+ test("github and forgejo hand an artifact out as one archive, so they read no file of one", () => {
142
+ expect(gh().artifactFile).toBeUndefined();
143
+ expect(fj().artifactFile).toBeUndefined();
144
+ });
145
+ });