@intentius/chant 0.124.57 → 0.124.59
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-product-words.d.ts +47 -2
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +59 -1
- package/dist/ci-product.d.ts +26 -2
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +25 -2
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +5 -1
- package/dist/cli/handlers/init.d.ts.map +1 -1
- package/dist/cli/handlers/init.js +16 -0
- package/dist/cli/handlers/lifecycle-drift.d.ts +2 -1
- package/dist/cli/handlers/lifecycle-drift.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle-drift.js +4 -2
- package/dist/cli/handlers/lock.d.ts.map +1 -1
- package/dist/cli/handlers/lock.js +45 -2
- package/dist/cli/handlers/serve.d.ts.map +1 -1
- package/dist/cli/handlers/serve.js +9 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +11 -3
- package/dist/cli/mcp/product-tools.d.ts +40 -7
- package/dist/cli/mcp/product-tools.d.ts.map +1 -1
- package/dist/cli/mcp/product-tools.js +58 -15
- package/dist/cli/mcp/read-only.d.ts +2 -1
- package/dist/cli/mcp/read-only.d.ts.map +1 -1
- package/dist/cli/mcp/read-only.js +2 -1
- package/dist/cli/mcp/server.d.ts +11 -0
- package/dist/cli/mcp/server.d.ts.map +1 -1
- package/dist/cli/mcp/server.js +15 -3
- package/dist/cli/mcp-config.d.ts +4 -1
- package/dist/cli/mcp-config.d.ts.map +1 -1
- package/dist/cli/mcp-config.js +6 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +27 -0
- package/dist/cli/registry.d.ts +14 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-pipeline.d.ts +56 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +55 -2
- package/dist/components/product-pipeline.d.ts +18 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +8 -2
- package/dist/drift-record.d.ts +5 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/e2e-harness/driver.d.ts.map +1 -1
- package/dist/e2e-harness/driver.js +97 -0
- package/dist/e2e-harness/forgejo.d.ts +5 -1
- package/dist/e2e-harness/forgejo.d.ts.map +1 -1
- package/dist/e2e-harness/forgejo.js +35 -0
- package/dist/e2e-harness/index.d.ts +7 -0
- package/dist/e2e-harness/index.d.ts.map +1 -1
- package/dist/e2e-harness/index.js +10 -1
- package/dist/e2e-harness/ports.d.ts +31 -0
- package/dist/e2e-harness/ports.d.ts.map +1 -1
- package/dist/e2e-harness/scenario.d.ts.map +1 -1
- package/dist/e2e-harness/scenario.js +9 -5
- package/dist/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
- package/dist/e2e-harness/schemas/index.d.ts +22 -1
- package/dist/e2e-harness/schemas/index.d.ts.map +1 -1
- package/dist/e2e-harness/schemas/index.js +1 -1
- package/dist/e2e-harness/steps.d.ts.map +1 -1
- package/dist/e2e-harness/steps.js +4 -0
- package/dist/lifecycle/lock-beat.d.ts +27 -0
- package/dist/lifecycle/lock-beat.d.ts.map +1 -0
- package/dist/lifecycle/lock-beat.js +84 -0
- package/dist/lifecycle/resource-lock.d.ts +54 -1
- package/dist/lifecycle/resource-lock.d.ts.map +1 -1
- package/dist/lifecycle/resource-lock.js +128 -7
- package/dist/mcp/types.d.ts +9 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/op/index.d.ts +1 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -1
- package/dist/op/op-waves-notify.d.ts.map +1 -1
- package/dist/op/op-waves-notify.js +11 -0
- package/dist/op/op-waves-run.d.ts +28 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +92 -7
- package/dist/op/op-waves.d.ts +12 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +9 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/template-request/index.d.ts +9 -0
- package/dist/template-request/index.d.ts.map +1 -0
- package/dist/template-request/index.js +8 -0
- package/dist/template-request/request-body.d.ts +21 -0
- package/dist/template-request/request-body.d.ts.map +1 -0
- package/dist/template-request/request-body.js +86 -0
- package/dist/template-request/template-request.d.ts +100 -0
- package/dist/template-request/template-request.d.ts.map +1 -0
- package/dist/template-request/template-request.js +149 -0
- package/dist/template-request/template-request.schema.json +100 -0
- package/dist/template-request/template-spec.d.ts +83 -0
- package/dist/template-request/template-spec.d.ts.map +1 -0
- package/dist/template-request/template-spec.js +146 -0
- package/dist/template-request/template.schema.json +114 -0
- package/dist/template-request/validate.d.ts +4 -0
- package/dist/template-request/validate.d.ts.map +1 -0
- package/dist/template-request/validate.js +21 -0
- package/dist/wave-runtime.mjs +298 -298
- package/dist/workspace/drift-cli.d.ts +13 -1
- package/dist/workspace/drift-cli.d.ts.map +1 -1
- package/dist/workspace/drift-cli.js +19 -3
- package/package.json +8 -1
- package/src/ci-product-words.test.ts +23 -0
- package/src/ci-product-words.ts +68 -3
- package/src/ci-product.ts +31 -1
- package/src/cli/commands/init.ts +3 -1
- package/src/cli/handlers/build.ts +5 -1
- package/src/cli/handlers/init.ts +18 -0
- package/src/cli/handlers/lifecycle-drift.test.ts +52 -0
- package/src/cli/handlers/lifecycle-drift.ts +4 -2
- package/src/cli/handlers/lock.ts +41 -2
- package/src/cli/handlers/serve.ts +9 -0
- package/src/cli/main.ts +11 -3
- package/src/cli/mcp/product-tools.test.ts +56 -1
- package/src/cli/mcp/product-tools.ts +66 -15
- package/src/cli/mcp/read-only.ts +2 -1
- package/src/cli/mcp/server.ts +20 -5
- package/src/cli/mcp-config.test.ts +52 -2
- package/src/cli/mcp-config.ts +6 -3
- package/src/cli/parse-args.ts +19 -0
- package/src/cli/registry.ts +14 -0
- package/src/components/pr-pipeline.ts +87 -2
- package/src/components/product-actions.test.ts +76 -0
- package/src/components/product-pipeline.ts +21 -2
- package/src/drift-record.ts +5 -0
- package/src/e2e-harness/driver.test.ts +163 -0
- package/src/e2e-harness/driver.ts +86 -1
- package/src/e2e-harness/forgejo.ts +42 -1
- package/src/e2e-harness/index.ts +11 -1
- package/src/e2e-harness/ports.ts +33 -0
- package/src/e2e-harness/scenario.ts +8 -6
- package/src/e2e-harness/schemas/README.md +11 -2
- package/src/e2e-harness/schemas/e2e-scenario.schema.json +43 -3
- package/src/e2e-harness/schemas/index.ts +5 -1
- package/src/e2e-harness/schemas.test.ts +44 -1
- package/src/e2e-harness/steps.ts +4 -0
- package/src/lifecycle/lock-beat.ts +99 -0
- package/src/lifecycle/resource-lock-liveness.test.ts +289 -0
- package/src/lifecycle/resource-lock.ts +143 -8
- package/src/mcp/types.ts +9 -0
- package/src/op/index.ts +1 -0
- package/src/op/op-waves-notify.ts +11 -0
- package/src/op/op-waves-preview.test.ts +167 -0
- package/src/op/op-waves-run.ts +116 -8
- package/src/op/op-waves.ts +20 -3
- package/src/release-floors.ts +1 -1
- package/src/template-request/__fixtures__/request-body.md +41 -0
- package/src/template-request/index.ts +8 -0
- package/src/template-request/request-body.ts +91 -0
- package/src/template-request/template-request.schema.json +100 -0
- package/src/template-request/template-request.test.ts +315 -0
- package/src/template-request/template-request.ts +234 -0
- package/src/template-request/template-spec.ts +176 -0
- package/src/template-request/template.schema.json +114 -0
- package/src/template-request/validate.ts +28 -0
- package/src/workspace/drift-cli.test.ts +35 -1
- package/src/workspace/drift-cli.ts +21 -3
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Day-2 actions in the product pipeline (#4654): `actions: true` counts the
|
|
3
|
+
* `action` command as answered by the product's own workflow, and
|
|
4
|
+
* `actionJob` writes the job that answers the comment and a dispatch with a
|
|
5
|
+
* member and an action, running the product's action verb, which reads
|
|
6
|
+
* what was asked with `productActionFromEnv`.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, expect, test } from "vitest";
|
|
9
|
+
import { productPipelineJobs } from "./product-pipeline";
|
|
10
|
+
import { prActionJob, prLoopJobStage, PR_ACTION_JOB } from "./pr-pipeline";
|
|
11
|
+
import { assertProductWords, productActionFromEnv, PRODUCT_ACTION_ENV, PRODUCT_ACTION_EVENT_FLAG } from "../ci-product-words";
|
|
12
|
+
import { PLYWOOD, TERRAGUCCI } from "../__fixtures__/product-words";
|
|
13
|
+
|
|
14
|
+
const PW = { ...PLYWOOD, commands: { preview: "plan" as const, action: "action" as const } };
|
|
15
|
+
const TG = { ...TERRAGUCCI, commands: { plan: "plan" as const, action: "action" as const }, aliases: [], bin: "terragucci" };
|
|
16
|
+
|
|
17
|
+
describe("the action command in the product pipeline (#4654)", () => {
|
|
18
|
+
test("refused without actions, counted with it, and named among the comments", () => {
|
|
19
|
+
expect(() => productPipelineJobs("github", "production", { words: TG })).toThrow(/commands.action needs a action job/);
|
|
20
|
+
const tg = productPipelineJobs("github", "production", { words: TG, actions: true });
|
|
21
|
+
expect(tg.comments.action).toBe("/terragucci action");
|
|
22
|
+
// The product's own workflow answers it: no job here.
|
|
23
|
+
expect(tg.action).toBeUndefined();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("actionJob writes the job, answering the comment and a dispatch with the stack and action inputs", () => {
|
|
27
|
+
const pw = productPipelineJobs("github", "production", { words: PW, actionJob: true });
|
|
28
|
+
expect(pw.comments.action).toBe("/plywood action");
|
|
29
|
+
expect(pw.action).toMatchObject({ jobName: PR_ACTION_JOB, comment: "/plywood action", inputs: { member: "stack", action: "action" } });
|
|
30
|
+
expect(pw.action!.command).toBe(`npx --no-install plywood action ${PRODUCT_ACTION_EVENT_FLAG}`);
|
|
31
|
+
expect(pw.action!.env).toMatchObject({
|
|
32
|
+
[PRODUCT_ACTION_ENV.comment]: "${{ github.event.comment.body }}",
|
|
33
|
+
[PRODUCT_ACTION_ENV.member]: "${{ github.event.inputs.stack }}",
|
|
34
|
+
[PRODUCT_ACTION_ENV.action]: "${{ github.event.inputs.action }}",
|
|
35
|
+
});
|
|
36
|
+
// A pending approval is the expected first answer, so chant's waiting exit is a green job.
|
|
37
|
+
expect(pw.action!.script).toContain('if [ "$code" -eq 3 ]; then');
|
|
38
|
+
expect(prLoopJobStage(PR_ACTION_JOB)).toBe("apply");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("the inputs can be named, and the job is refused where it cannot run", () => {
|
|
42
|
+
expect(prActionJob("forgejo", { words: TG, actionJob: { inputs: { member: "root", action: "address" } } })!.inputs).toEqual({ member: "root", action: "address" });
|
|
43
|
+
expect(prActionJob("github", { words: PW })).toBeUndefined();
|
|
44
|
+
expect(() => prActionJob("gitlab", { words: PW, actionJob: true })).toThrow(/GitHub and Forgejo/);
|
|
45
|
+
expect(() => prActionJob("github", { words: { ...PW, commands: { preview: "plan" as const } }, actionJob: true })).toThrow(/name no action command/);
|
|
46
|
+
expect(() => prActionJob("github", { words: { ...PW, bin: undefined }, actionJob: true })).toThrow(/no bin/);
|
|
47
|
+
expect(() => prActionJob("github", { words: PW, actionJob: { inputs: { member: "a b" } } })).toThrow(/plain name/);
|
|
48
|
+
expect(() => prActionJob("github", { words: PW, actionJob: { inputs: { member: "action" } } })).toThrow(/two names/);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("what an action job was asked for (#4654)", () => {
|
|
53
|
+
const words = assertProductWords(PW, { jobs: ["plan", "action"] });
|
|
54
|
+
|
|
55
|
+
test("a comment, parsed as a comment is", () => {
|
|
56
|
+
expect(productActionFromEnv(words, { [PRODUCT_ACTION_ENV.comment]: "/plywood action shop/prod-us rotate" })).toEqual({ kind: "action", member: "shop/prod-us", address: "rotate", from: "comment" });
|
|
57
|
+
expect(productActionFromEnv(words, { [PRODUCT_ACTION_ENV.comment]: "/plywood action shop/prod-us" })).toMatchObject({ kind: "refused" });
|
|
58
|
+
expect(productActionFromEnv(words, { [PRODUCT_ACTION_ENV.comment]: "/plywood preview" })).toMatchObject({ kind: "refused", reason: expect.stringContaining("/plywood action <stack> <action>") });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("a dispatch's two inputs, checked by the same rules", () => {
|
|
62
|
+
expect(productActionFromEnv(words, { [PRODUCT_ACTION_ENV.member]: "shop/prod-us", [PRODUCT_ACTION_ENV.action]: "rotate", [PRODUCT_ACTION_ENV.comment]: "" })).toEqual({
|
|
63
|
+
kind: "action",
|
|
64
|
+
member: "shop/prod-us",
|
|
65
|
+
address: "rotate",
|
|
66
|
+
from: "dispatch",
|
|
67
|
+
});
|
|
68
|
+
for (const [member, action] of [["", "rotate"], ["shop/prod-us", ""], ["../etc", "rotate"], ["shop/prod-us", "rotate; id"], ["shop/prod-us", "$(id)"], ["shop prod", "rotate"]]) {
|
|
69
|
+
expect(productActionFromEnv(words, { [PRODUCT_ACTION_ENV.member]: member, [PRODUCT_ACTION_ENV.action]: action })).toMatchObject({ kind: "refused" });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("words with no action command answer no action", () => {
|
|
74
|
+
expect(productActionFromEnv(assertProductWords(PLYWOOD), { [PRODUCT_ACTION_ENV.member]: "s", [PRODUCT_ACTION_ENV.action]: "a" })).toMatchObject({ kind: "refused", reason: expect.stringMatching(/no action command/) });
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
type CiProductWords,
|
|
35
35
|
type CiProductWordsInput,
|
|
36
36
|
} from "../ci-product-words";
|
|
37
|
-
import { prCommentLockJobs, prCommentPreviewJob, prLoopJobs, prLoopPostJob, prLoopRunner, prStaleJob, withProductBin, type PrCommentLockJob, type PrCommentPreviewJob, type PrLoopJob, type PrLoopPipelineOptions } from "./pr-pipeline";
|
|
37
|
+
import { prActionJob, prCommentLockJobs, prCommentPreviewJob, prLoopJobs, prLoopPostJob, prLoopRunner, prStaleJob, withProductBin, type PrActionJob, type PrCommentLockJob, type PrCommentPreviewJob, type PrLoopJob, type PrLoopPipelineOptions } from "./pr-pipeline";
|
|
38
38
|
import type { DriverComponent } from "./driver";
|
|
39
39
|
import type { ScheduledOpSpec } from "../lexicon";
|
|
40
40
|
import type { CiRunner } from "../ci-jobs";
|
|
@@ -70,6 +70,15 @@ export interface ProductPipelineOptions extends Omit<PrLoopPipelineOptions, "wor
|
|
|
70
70
|
* scheduled Ops.
|
|
71
71
|
*/
|
|
72
72
|
agent?: boolean | ProductAgentOptions;
|
|
73
|
+
/**
|
|
74
|
+
* The product answers its `action` command (#4654) from a workflow of its
|
|
75
|
+
* own, such as terragucci's action workflow: `true` counts the command as
|
|
76
|
+
* answered, so words that map a word onto `action` are not refused, and
|
|
77
|
+
* `comments.action` names the comment. The pipeline writes no job for it.
|
|
78
|
+
* A product with no workflow of its own sets `actionJob` instead, and the
|
|
79
|
+
* pipeline writes the job ({@link ProductPipelineJobs.action}).
|
|
80
|
+
*/
|
|
81
|
+
actions?: boolean;
|
|
73
82
|
/**
|
|
74
83
|
* The apply on merge from the component graph (#4588), when `waves` is
|
|
75
84
|
* absent: the spec `pr-apply --wave-gate` runs, a wave per layer of
|
|
@@ -143,6 +152,12 @@ export interface ProductPipelineJobs {
|
|
|
143
152
|
* job with the write token.
|
|
144
153
|
*/
|
|
145
154
|
agent?: { comment: string; name: string; spec: ScheduledOpSpec };
|
|
155
|
+
/**
|
|
156
|
+
* The action job (#4654), with `actionJob`: the comment and the dispatch
|
|
157
|
+
* inputs it answers, and the product's action verb it runs. The GitHub and
|
|
158
|
+
* Forgejo lexicons render the same job.
|
|
159
|
+
*/
|
|
160
|
+
action?: PrActionJob & { runner?: CiRunner };
|
|
146
161
|
}
|
|
147
162
|
|
|
148
163
|
/** An agent's settings as a product passes them (#4616): {@link OpAgentSpec} without the trigger, which the pipeline names. */
|
|
@@ -204,12 +219,14 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
|
|
|
204
219
|
if (options.applyBeforeMerge || options.waves || options.componentWaves) jobs.push("apply");
|
|
205
220
|
if (options.locks === "plan") jobs.push("lock", "unlock");
|
|
206
221
|
if (options.agent) jobs.push("agent");
|
|
222
|
+
// #4654: the action command, answered by the product's own workflow (`actions`) or by the pipeline's action job.
|
|
223
|
+
if (options.actions || options.actionJob) jobs.push("action");
|
|
207
224
|
// #4601: the note's merge sentence follows the jobs built here: waves on merge, an apply before merge, else a record for a release.
|
|
208
225
|
// Words that ask for before-merge keep it when the pipeline has that job beside its waves.
|
|
209
226
|
const built: CiProductApplyMode = options.waves || options.componentWaves ? "on-merge" : options.applyBeforeMerge ? "before-merge" : "release";
|
|
210
227
|
const applyMode: CiProductApplyMode = options.words.applyMode === "before-merge" && options.applyBeforeMerge ? "before-merge" : built;
|
|
211
228
|
const words = assertProductWords({ ...options.words, applyMode }, { jobs });
|
|
212
|
-
const { waves: given, wavesSpecFile, member, agent: _agent, componentWaves, ...loop } = options;
|
|
229
|
+
const { waves: given, wavesSpecFile, member, agent: _agent, actions: _actions, componentWaves, ...loop } = options;
|
|
213
230
|
const { respond } = options;
|
|
214
231
|
// #4629: the pull request loop puts the responses on the apply and note jobs, as `chant build --pr-loop --respond` does.
|
|
215
232
|
const prLoop: PrLoopPipelineOptions = { ...loop, words, gate: options.gate ?? words.prGate };
|
|
@@ -234,6 +251,8 @@ export function productPipelineJobs(forge: ForgeKind, env: string, options: Prod
|
|
|
234
251
|
};
|
|
235
252
|
const locks = prCommentLockJobs(forge, { locks: options.locks, words });
|
|
236
253
|
if (locks.length > 0) out.locks = locks.map((job) => ({ ...job, ...defaultRunner }));
|
|
254
|
+
const action = prActionJob(forge, prLoop);
|
|
255
|
+
if (action) out.action = { ...action, ...(prLoopRunner(options, "apply") !== undefined ? { runner: prLoopRunner(options, "apply")! } : {}) };
|
|
237
256
|
const stale = prStaleJob(forge, env, prLoop, member);
|
|
238
257
|
if (stale) out.stale = { ...stale, ...defaultRunner };
|
|
239
258
|
const preview = prCommentPreviewJob(forge, env, prLoop, member);
|
package/src/drift-record.ts
CHANGED
|
@@ -1190,6 +1190,11 @@ export interface ReadDriftOptions {
|
|
|
1190
1190
|
read?: DriftRead;
|
|
1191
1191
|
/** One address to read, on an engine that can read one resource on its own. */
|
|
1192
1192
|
resource?: string;
|
|
1193
|
+
/**
|
|
1194
|
+
* The stack to read (`chant workspace drift --stack`), for an engine whose store holds one export per stack.
|
|
1195
|
+
* A lexicon with no such store refuses it with `read-unsupported`; one whose store lacks that stack's export refuses with `no-drift-read`.
|
|
1196
|
+
*/
|
|
1197
|
+
stack?: string;
|
|
1193
1198
|
/** RFC 3339, the `observedAt` of every record the lexicon builds itself. */
|
|
1194
1199
|
observedAt: string;
|
|
1195
1200
|
}
|
|
@@ -302,3 +302,166 @@ describe("the e2e harness's driver", () => {
|
|
|
302
302
|
expect(run.reason).toBe("change-merge: Forgejo answered 500");
|
|
303
303
|
});
|
|
304
304
|
});
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* A product's pull request (chant#4650): the out-of-band command stands in
|
|
308
|
+
* for `terragucci request`, which pushes a branch and opens the pull request
|
|
309
|
+
* itself. The pipeline plans it as it would any other.
|
|
310
|
+
*/
|
|
311
|
+
function productWorld(o: { neverOpens?: boolean; files?: string[]; staleOpen?: boolean } = {}) {
|
|
312
|
+
const w = world();
|
|
313
|
+
const pulls: Array<{ number: number; title: string; branch: string; head: string; files: string[]; open: boolean }> = [];
|
|
314
|
+
const posted: Array<{ pull: number; body: string; as: string }> = [];
|
|
315
|
+
let next = 100;
|
|
316
|
+
const make = async (branch: string, title: string) => {
|
|
317
|
+
const number = next++;
|
|
318
|
+
const head = `c${String(number).padStart(39, "0")}`;
|
|
319
|
+
pulls.push({ number, title, branch, head, files: o.files ?? ["apps/orders/main.tf"], open: true });
|
|
320
|
+
await w.bucket.put(
|
|
321
|
+
reportObjectKey(PREFIX, number, head, "plan"),
|
|
322
|
+
JSON.stringify({ stage: "plan", pr: number, head, op: `pr-${number}`, gate: "pr-apply", digest: `jcs1-sha256:${number}`, status: "planned", selection: { waves: [] }, members: [] }),
|
|
323
|
+
"application/json",
|
|
324
|
+
);
|
|
325
|
+
};
|
|
326
|
+
if (o.staleOpen) void make("request/bucket/orders", "Request bucket orders");
|
|
327
|
+
const forge: DriverPorts["forge"] = {
|
|
328
|
+
...w.ports.forge,
|
|
329
|
+
openPulls: async () => pulls.filter((p) => p.open).map((p) => p.number),
|
|
330
|
+
findPull: async (branch) => {
|
|
331
|
+
const p = pulls.filter((x) => x.open && x.branch === branch).sort((a, b) => a.number - b.number)[0];
|
|
332
|
+
return p && { number: p.number, title: p.title, branch: p.branch, head: p.head };
|
|
333
|
+
},
|
|
334
|
+
pullInfo: async (n) => {
|
|
335
|
+
const p = pulls.find((x) => x.number === n);
|
|
336
|
+
return p && { number: p.number, title: p.title, branch: p.branch, head: p.head };
|
|
337
|
+
},
|
|
338
|
+
changedFiles: async (n) => pulls.find((x) => x.number === n)?.files ?? [],
|
|
339
|
+
postComment: async (pull, body, as) => void posted.push({ pull, body, as }),
|
|
340
|
+
};
|
|
341
|
+
const outOfBand = {
|
|
342
|
+
run: async (command: string[]) => {
|
|
343
|
+
if (!o.neverOpens) await make(command.at(-1)!, "Request bucket orders");
|
|
344
|
+
return 0;
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
return { ...w, pulls, posted, ports: { ...w.ports, forge, outOfBand } as DriverPorts };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function requestScenario(over: Partial<Scenario> = {}): Scenario {
|
|
351
|
+
return fanOut({
|
|
352
|
+
id: "tg-template-app",
|
|
353
|
+
product: "terragucci",
|
|
354
|
+
claim: "template/app-request",
|
|
355
|
+
steps: [
|
|
356
|
+
{ id: "request", do: "out-of-band", command: ["terragucci", "request", "bucket", "orders", "request/bucket/orders"], expect: [{ exit: 0 }] },
|
|
357
|
+
{ id: "pr", do: "await-pull", branch: "request/bucket/orders", title: "orders" },
|
|
358
|
+
{ id: "pr-plan", do: "plan", pull: "pr", expect: [{ report: { status: "planned" } }] },
|
|
359
|
+
],
|
|
360
|
+
...over,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
describe("a pull request a product opened", () => {
|
|
365
|
+
test("await-pull binds the product's pull request and its head, and plan reads the report there", async () => {
|
|
366
|
+
const w = productWorld();
|
|
367
|
+
const s = requestScenario();
|
|
368
|
+
expect(lintScenario(s)).toEqual([]);
|
|
369
|
+
const run = await runArm(s, "plain", w.ports, OPTS);
|
|
370
|
+
expect(run.outcome).toBe("held");
|
|
371
|
+
expect(verdictsOf(run, run).plain).toBe("pass");
|
|
372
|
+
expect(run.steps.map((x) => [x.id, x.pull, x.commit])).toEqual([
|
|
373
|
+
["request", undefined, undefined],
|
|
374
|
+
["pr", 100, `c${"100".padStart(39, "0")}`],
|
|
375
|
+
["pr-plan", 100, `c${"100".padStart(39, "0")}`],
|
|
376
|
+
]);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
test("no pull request ever opened stalls at the await-pull limit, and is not a fail of the outcome", async () => {
|
|
380
|
+
const w = productWorld({ neverOpens: true });
|
|
381
|
+
const start = w.clock.t;
|
|
382
|
+
const run = await runArm(requestScenario(), "plain", w.ports, OPTS);
|
|
383
|
+
expect(run.outcome).toBe("stalled");
|
|
384
|
+
expect(run.reason).toBe("pr: no open pull request from request/bucket/orders within 300s");
|
|
385
|
+
expect(run.steps.at(-1)).toMatchObject({ id: "pr", stopped: { outcome: "stalled" } });
|
|
386
|
+
expect(w.clock.t - start).toBeGreaterThanOrEqual(300_000);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test("the BREAK run waits for the same branch, and never binds a pull request open before it started", async () => {
|
|
390
|
+
const fresh = productWorld();
|
|
391
|
+
const brk = await runArm(requestScenario(), "break", fresh.ports, OPTS);
|
|
392
|
+
expect(brk.steps.find((x) => x.id === "pr")?.pull).toBe(100);
|
|
393
|
+
|
|
394
|
+
const stale = productWorld({ staleOpen: true, neverOpens: true });
|
|
395
|
+
const run = await runArm(requestScenario(), "break", stale.ports, OPTS);
|
|
396
|
+
expect(run.outcome).toBe("stalled");
|
|
397
|
+
expect(run.reason).toBe("pr: pull request 100 from request/bucket/orders was open before the run started, and no new one came within 300s");
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
test("comment posts the exact body on the bound pull request, as the author unless the step says", async () => {
|
|
401
|
+
const w = productWorld();
|
|
402
|
+
const s = requestScenario();
|
|
403
|
+
s.steps.push(
|
|
404
|
+
{ id: "invoke", do: "comment", pull: "pr", body: "/terragucci action orders rotate" },
|
|
405
|
+
{ id: "again", do: "comment", pull: "pr", body: "/terragucci action orders rotate", as: "reviewer", expect: [{ pull: { title: "orders" } }] },
|
|
406
|
+
);
|
|
407
|
+
expect(lintScenario(s)).toEqual([]);
|
|
408
|
+
const run = await runArm(s, "plain", w.ports, OPTS);
|
|
409
|
+
expect(run.outcome).toBe("held");
|
|
410
|
+
expect(w.posted).toEqual([
|
|
411
|
+
{ pull: 100, body: "/terragucci action orders rotate", as: "author" },
|
|
412
|
+
{ pull: 100, body: "/terragucci action orders rotate", as: "reviewer" },
|
|
413
|
+
]);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test("a pull outcome holds for exactly the files named, and names the extra path when there is one", async () => {
|
|
417
|
+
const outcome = { pull: { files: ["apps/orders/main.tf"], only: true } };
|
|
418
|
+
const s = () => {
|
|
419
|
+
const x = requestScenario();
|
|
420
|
+
(x.steps[1] as { expect?: unknown[] }).expect = [outcome];
|
|
421
|
+
return x;
|
|
422
|
+
};
|
|
423
|
+
expect(lintScenario(s())).toEqual([]);
|
|
424
|
+
expect((await runArm(s(), "plain", productWorld().ports, OPTS)).outcome).toBe("held");
|
|
425
|
+
|
|
426
|
+
const run = await runArm(s(), "plain", productWorld({ files: ["apps/orders/main.tf", "apps/other/main.tf"] }).ports, OPTS);
|
|
427
|
+
expect(run.outcome).toBe("broke");
|
|
428
|
+
expect(run.reason).toBe("pr: pull request 100 also changes apps/other/main.tf beyond the files named");
|
|
429
|
+
|
|
430
|
+
const missing = await runArm(s(), "plain", productWorld({ files: ["apps/other/main.tf"] }).ports, OPTS);
|
|
431
|
+
expect(missing.reason).toBe("pr: pull request 100 does not change apps/orders/main.tf");
|
|
432
|
+
|
|
433
|
+
const titled = requestScenario();
|
|
434
|
+
(titled.steps[1] as { expect?: unknown[] }).expect = [{ pull: { title: "payments" } }];
|
|
435
|
+
expect((await runArm(titled, "plain", productWorld().ports, OPTS)).reason).toBe('pr: pull request 100 is titled "Request bucket orders", which does not hold "payments"');
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
test("a gated outcome reads the gated requests asked since the run started: gated, then ok or failed", async () => {
|
|
439
|
+
const w = productWorld();
|
|
440
|
+
const at = (ms: number) => new Date(Date.parse("2026-10-28T10:00:00Z") + ms).toISOString();
|
|
441
|
+
const req = (ts: string, result?: "applied" | "failed") =>
|
|
442
|
+
({
|
|
443
|
+
op: "tf-action",
|
|
444
|
+
gate: "tf-action",
|
|
445
|
+
digest: `d-${ts}`,
|
|
446
|
+
request: {},
|
|
447
|
+
pending: { timestamp: ts },
|
|
448
|
+
approvals: [],
|
|
449
|
+
...(result ? { finished: { result } } : {}),
|
|
450
|
+
}) as unknown as import("../lifecycle/gated-request").GatedRequestRead;
|
|
451
|
+
const asked = [req(at(-60_000), "applied"), req(at(1000)), req(at(2000), "applied"), req(at(3000), "failed")];
|
|
452
|
+
const ports: DriverPorts = { ...w.ports, ledger: { runs: async () => [], gatedRequests: async (op) => (op === "tf-action" ? asked : []) } };
|
|
453
|
+
const s = (expect: Scenario["steps"][number]["expect"]) => fanOut({ steps: [{ id: "x", do: "out-of-band", command: ["true"], expect }] });
|
|
454
|
+
|
|
455
|
+
expect((await runArm(s([{ gated: { op: "tf-action", status: "gated", count: 1 } }, { gated: { op: "tf-action", status: "ok", count: 1 } }, { gated: { op: "tf-action", status: "failed" } }, { gated: { op: "tf-action", count: 3 } }]), "plain", ports, OPTS)).outcome).toBe("held");
|
|
456
|
+
expect((await runArm(s([{ gated: { op: "pulumi-stack-ops", status: "ok" } }]), "plain", ports, OPTS)).reason).toBe("x: no gated pulumi-stack-ops request ok on the ledger since the run started");
|
|
457
|
+
expect((await runArm(s([{ gated: { op: "tf-action", status: "ok", count: 2 } }]), "plain", ports, OPTS)).reason).toBe("x: 1 gated tf-action requests ok on the ledger, not 2");
|
|
458
|
+
expect((await runArm(s([{ gated: { op: "tf-action" } }]), "plain", w.ports, OPTS)).reason).toBe("x: a gated outcome needs the ledger's gated requests");
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
test("await-pull and comment stall without the forge reads they need", async () => {
|
|
462
|
+
const w = world();
|
|
463
|
+
const s = requestScenario();
|
|
464
|
+
const run = await runArm(s, "plain", { ...w.ports, outOfBand: { run: async () => 0 } }, OPTS);
|
|
465
|
+
expect(run.reason).toBe("pr: an await-pull step needs the forge's findPull");
|
|
466
|
+
});
|
|
467
|
+
});
|
|
@@ -5,14 +5,19 @@
|
|
|
5
5
|
* the BREAK run, and checks each step's outcomes against chant's own reports
|
|
6
6
|
* and run ledger, never the runner's status or logs.
|
|
7
7
|
*
|
|
8
|
+
* A pull request comes from the driver's own open step or from a product:
|
|
9
|
+
* an await-pull step waits for the one a product opened from its branch
|
|
10
|
+
* (chant#4650), and later steps name it as they name an open step's.
|
|
11
|
+
*
|
|
8
12
|
* A run ends one of three ways. Every outcome held: the plain run passes, and
|
|
9
13
|
* a BREAK run that ends so was missed. An outcome did not hold: the run stops
|
|
10
14
|
* there, the plain run fails, and the BREAK run was caught. A step did not
|
|
11
15
|
* finish (past its limit, or an error): the run stalled, which is neither.
|
|
12
16
|
*/
|
|
13
17
|
import { reportKey } from "../pr-report-url";
|
|
18
|
+
import type { GatedRequestRead } from "../lifecycle/gated-request";
|
|
14
19
|
import type { OpRunRecord } from "../op/runtime";
|
|
15
|
-
import type { Bucket, Chant, Clock, ForgeReads, Jobs, Ledger, Log, OutOfBand, PullForge } from "./ports";
|
|
20
|
+
import type { Bucket, Chant, Clock, ForgePull, ForgeReads, Jobs, Ledger, Log, OutOfBand, PullForge } from "./ports";
|
|
16
21
|
import { componentStatuses, reportObjectKey, splitReportUrl, waitForReport, type PrReportView, type ReportStage } from "./reports";
|
|
17
22
|
import type { BreakVerdict, PlainVerdict, Scenario, ScenarioOutcome, ScenarioStep, ScenarioStepKind } from "./schemas/index";
|
|
18
23
|
import { limitsFor } from "./steps";
|
|
@@ -75,6 +80,12 @@ interface Opened {
|
|
|
75
80
|
|
|
76
81
|
const iso = (ms: number) => new Date(ms).toISOString();
|
|
77
82
|
|
|
83
|
+
/** How a gated request stands: gated until a finished line names it, then ok or failed. */
|
|
84
|
+
function gatedStatus(r: GatedRequestRead): "gated" | "ok" | "failed" {
|
|
85
|
+
if (!r.finished) return "gated";
|
|
86
|
+
return r.finished.result === "applied" ? "ok" : "failed";
|
|
87
|
+
}
|
|
88
|
+
|
|
78
89
|
/** The check of one outcome, or null when it holds. */
|
|
79
90
|
async function checkOutcome(
|
|
80
91
|
o: ScenarioOutcome,
|
|
@@ -106,6 +117,36 @@ async function checkOutcome(
|
|
|
106
117
|
}
|
|
107
118
|
return matching.length > 0 ? null : `no ${o.ledger.op} run${o.ledger.status ? ` ${o.ledger.status}` : ""} on the ledger since the run started`;
|
|
108
119
|
}
|
|
120
|
+
if ("gated" in o) {
|
|
121
|
+
if (!p.ledger?.gatedRequests) throw new Stall("a gated outcome needs the ledger's gated requests");
|
|
122
|
+
const asked = (await p.ledger.gatedRequests(o.gated.op)).filter((r) => r.pending.timestamp >= ctx.since);
|
|
123
|
+
const matching = o.gated.status ? asked.filter((r) => gatedStatus(r) === o.gated.status) : asked;
|
|
124
|
+
const status = o.gated.status ? ` ${o.gated.status}` : "";
|
|
125
|
+
if (o.gated.count !== undefined) {
|
|
126
|
+
return matching.length === o.gated.count ? null : `${matching.length} gated ${o.gated.op} requests${status} on the ledger, not ${o.gated.count}`;
|
|
127
|
+
}
|
|
128
|
+
return matching.length > 0 ? null : `no gated ${o.gated.op} request${status} on the ledger since the run started`;
|
|
129
|
+
}
|
|
130
|
+
if ("pull" in o) {
|
|
131
|
+
if (ctx.pull === undefined) return "no pull request to read";
|
|
132
|
+
if (o.pull.title !== undefined) {
|
|
133
|
+
if (!p.forge.pullInfo) throw new Stall("a pull outcome with a title needs the forge's pull requests");
|
|
134
|
+
const info = await p.forge.pullInfo(ctx.pull);
|
|
135
|
+
if (!info) return `the forge does not know pull request ${ctx.pull}`;
|
|
136
|
+
if (!info.title.includes(o.pull.title)) return `pull request ${ctx.pull} is titled "${info.title}", which does not hold "${o.pull.title}"`;
|
|
137
|
+
}
|
|
138
|
+
if (o.pull.files !== undefined) {
|
|
139
|
+
if (!p.forge.changedFiles) throw new Stall("a pull outcome with files needs the forge's changed files");
|
|
140
|
+
const changed = await p.forge.changedFiles(ctx.pull);
|
|
141
|
+
const missing = o.pull.files.filter((f) => !changed.includes(f));
|
|
142
|
+
if (missing.length > 0) return `pull request ${ctx.pull} does not change ${missing.join(", ")}`;
|
|
143
|
+
if (o.pull.only) {
|
|
144
|
+
const extra = changed.filter((f) => !o.pull.files!.includes(f));
|
|
145
|
+
if (extra.length > 0) return `pull request ${ctx.pull} also changes ${extra.join(", ")} beyond the files named`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
109
150
|
if ("comment" in o) {
|
|
110
151
|
if (!p.forge.comments) throw new Stall("a comment outcome needs the forge's comments");
|
|
111
152
|
if (ctx.pull === undefined) return "no pull request to read comments of";
|
|
@@ -175,10 +216,39 @@ export async function runArm(s: Scenario, arm: Arm, p: DriverPorts, opts: Driver
|
|
|
175
216
|
if (!o) throw new Stall(`no pull request from ${id}`);
|
|
176
217
|
return o;
|
|
177
218
|
};
|
|
219
|
+
// The pull requests open when the run started. await-pull never binds one
|
|
220
|
+
// of these, so the BREAK run cannot pick up the plain run's pull request
|
|
221
|
+
// when the reset left it open.
|
|
222
|
+
let before = new Set<number>();
|
|
223
|
+
const awaitPull = async (step: Extract<ScenarioStep, { do: "await-pull" }>): Promise<StepResult> => {
|
|
224
|
+
const find = p.forge.findPull;
|
|
225
|
+
if (!find) throw new Stall("an await-pull step needs the forge's findPull");
|
|
226
|
+
// The product picks the branch, so it is the same on both runs.
|
|
227
|
+
const deadline = deadlineOf("await-pull");
|
|
228
|
+
let seen: ForgePull | undefined;
|
|
229
|
+
for (;;) {
|
|
230
|
+
const found = await find.call(p.forge, step.branch);
|
|
231
|
+
if (found && !before.has(found.number) && (step.title === undefined || found.title.includes(step.title))) {
|
|
232
|
+
opened.set(step.id, { pull: found.number, head: found.head });
|
|
233
|
+
log(`${s.id} ${arm}: ${step.id} found pull request ${found.number} at ${found.head.slice(0, 8)}`);
|
|
234
|
+
return { id: step.id, do: step.do, pull: found.number, commit: found.head };
|
|
235
|
+
}
|
|
236
|
+
if (found) seen = found;
|
|
237
|
+
if (p.clock.now() >= deadline) break;
|
|
238
|
+
await p.clock.sleep(opts.pollMs ?? 2000);
|
|
239
|
+
}
|
|
240
|
+
const why = !seen
|
|
241
|
+
? `no open pull request from ${step.branch} within ${limits["await-pull"]}s`
|
|
242
|
+
: before.has(seen.number)
|
|
243
|
+
? `pull request ${seen.number} from ${step.branch} was open before the run started, and no new one came within ${limits["await-pull"]}s`
|
|
244
|
+
: `pull request ${seen.number} from ${step.branch} is titled "${seen.title}", which does not hold "${step.title}", after ${limits["await-pull"]}s`;
|
|
245
|
+
throw new Stall(why);
|
|
246
|
+
};
|
|
178
247
|
|
|
179
248
|
try {
|
|
180
249
|
await p.reset?.();
|
|
181
250
|
await p.arm?.(arm, arm === "break" ? { ...s.break.env } : {});
|
|
251
|
+
if (s.steps.some((x) => x.do === "await-pull")) before = new Set(await p.forge.openPulls());
|
|
182
252
|
for (let i = 0; i < s.steps.length; i++) {
|
|
183
253
|
const step = s.steps[i]!;
|
|
184
254
|
let result: StepResult;
|
|
@@ -204,6 +274,11 @@ export async function runArm(s: Scenario, arm: Arm, p: DriverPorts, opts: Driver
|
|
|
204
274
|
}
|
|
205
275
|
continue;
|
|
206
276
|
}
|
|
277
|
+
case "await-pull": {
|
|
278
|
+
result = await awaitPull(step);
|
|
279
|
+
ctx.pull = result.pull;
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
207
282
|
case "plan": {
|
|
208
283
|
const o = pullOf(step.pull);
|
|
209
284
|
const r = await report("plan", o.pull, o.head, "plan");
|
|
@@ -230,6 +305,16 @@ export async function runArm(s: Scenario, arm: Arm, p: DriverPorts, opts: Driver
|
|
|
230
305
|
result = { id: step.id, do: step.do, pull: o.pull, commit };
|
|
231
306
|
break;
|
|
232
307
|
}
|
|
308
|
+
case "comment": {
|
|
309
|
+
const o = pullOf(step.pull);
|
|
310
|
+
const post = p.forge.postComment;
|
|
311
|
+
if (!post) throw new Stall("a comment step needs the forge's postComment");
|
|
312
|
+
await within("comment", post.call(p.forge, o.pull, step.body, step.as ?? "author"));
|
|
313
|
+
log(`${s.id} ${arm}: ${step.id} commented on pull request ${o.pull} as ${step.as ?? "author"}`);
|
|
314
|
+
ctx.pull = o.pull;
|
|
315
|
+
result = { id: step.id, do: step.do, pull: o.pull };
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
233
318
|
case "apply": {
|
|
234
319
|
const m = merged.get(step.merge);
|
|
235
320
|
if (!m) throw new Stall(`no merge from ${step.merge}`);
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { dirname, join } from "node:path";
|
|
13
13
|
import { guardedGit, remoteWith, type GuardedGit } from "./git";
|
|
14
|
-
import type { Clock, ForgeIssue, ForgeRun, HarnessForge } from "./ports";
|
|
14
|
+
import type { Clock, ForgeIssue, ForgePerson, ForgePull, ForgeRun, HarnessForge } from "./ports";
|
|
15
15
|
import { forgejoRunnerConfig, type RunnerConfigOptions } from "./stack";
|
|
16
16
|
|
|
17
17
|
export interface Person {
|
|
@@ -73,6 +73,16 @@ interface ActionRun {
|
|
|
73
73
|
workflow_id?: string;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/** A pull request as Forgejo's API answers, the fields read here. */
|
|
77
|
+
interface ForgejoPull {
|
|
78
|
+
number: number;
|
|
79
|
+
title: string;
|
|
80
|
+
head?: { ref?: string; sha?: string; repo?: { full_name?: string } | null };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const pullOf = (p: ForgejoPull): ForgePull => ({ number: p.number, title: p.title, branch: p.head?.ref ?? "", head: p.head?.sha ?? "" });
|
|
84
|
+
const sameRepo = (a: string | undefined, b: string) => a !== undefined && a.toLowerCase() === b.toLowerCase();
|
|
85
|
+
|
|
76
86
|
const DONE = new Set(["success", "failure", "cancelled", "skipped"]);
|
|
77
87
|
|
|
78
88
|
export class ForgejoForge implements HarnessForge {
|
|
@@ -201,6 +211,37 @@ export class ForgejoForge implements HarnessForge {
|
|
|
201
211
|
return out;
|
|
202
212
|
}
|
|
203
213
|
|
|
214
|
+
async findPull(branch: string): Promise<ForgePull | undefined> {
|
|
215
|
+
const found: ForgePull[] = [];
|
|
216
|
+
for (let page = 1; page < 50; page++) {
|
|
217
|
+
const list = await this.api<ForgejoPull[]>(this.o.admin, "GET", `${this.r}/pulls?state=open&sort=oldest&page=${page}&limit=50`);
|
|
218
|
+
if (!list || list.length === 0) break;
|
|
219
|
+
for (const p of list) if (p.head?.ref === branch && sameRepo(p.head.repo?.full_name, this.o.repo)) found.push(pullOf(p));
|
|
220
|
+
if (list.length < 50) break;
|
|
221
|
+
}
|
|
222
|
+
return found.sort((a, b) => a.number - b.number)[0];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async pullInfo(pull: number): Promise<ForgePull | undefined> {
|
|
226
|
+
const p = await this.api<ForgejoPull>(this.o.admin, "GET", `${this.r}/pulls/${pull}`, undefined, true);
|
|
227
|
+
return p ? pullOf(p) : undefined;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async changedFiles(pull: number): Promise<string[]> {
|
|
231
|
+
const out: string[] = [];
|
|
232
|
+
for (let page = 1; page < 50; page++) {
|
|
233
|
+
const list = await this.api<Array<{ filename: string }>>(this.o.admin, "GET", `${this.r}/pulls/${pull}/files?page=${page}&limit=50`);
|
|
234
|
+
if (!list || list.length === 0) break;
|
|
235
|
+
out.push(...list.map((f) => f.filename));
|
|
236
|
+
if (list.length < 50) break;
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async postComment(pull: number, body: string, as: ForgePerson): Promise<void> {
|
|
242
|
+
await this.api(this.o[as], "POST", `${this.r}/issues/${pull}/comments`, { body });
|
|
243
|
+
}
|
|
244
|
+
|
|
204
245
|
applyAgain(sha: string, workflow: string): Promise<ForgeRun> {
|
|
205
246
|
return this.dispatch(sha, workflow);
|
|
206
247
|
}
|
package/src/e2e-harness/index.ts
CHANGED
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
* - the no-real-cloud wrapper: ./safe-run.ts
|
|
14
14
|
*
|
|
15
15
|
* A product on a published chant without this subpath feature-detects:
|
|
16
|
-
* import it lazily, and use it when `E2E_HARNESS_FLOOR` is there.
|
|
16
|
+
* import it lazily, and use it when `E2E_HARNESS_FLOOR` is there. A scenario
|
|
17
|
+
* with await-pull or comment steps, or a pull or gated outcome, needs
|
|
18
|
+
* `E2E_HARNESS_PULL_STEPS_FLOOR` as well.
|
|
17
19
|
*/
|
|
18
20
|
import { existsSync } from "node:fs";
|
|
19
21
|
import { join } from "node:path";
|
|
@@ -21,6 +23,14 @@ import { join } from "node:path";
|
|
|
21
23
|
/** The first chant with the e2e harness. */
|
|
22
24
|
export const E2E_HARNESS_FLOOR = "0.124.56";
|
|
23
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The first chant whose harness follows a pull request a product opened
|
|
28
|
+
* (chant#4650): the await-pull and comment steps, the pull and gated
|
|
29
|
+
* outcomes, and the forge reads under them. A scenario that uses one needs
|
|
30
|
+
* this chant or newer.
|
|
31
|
+
*/
|
|
32
|
+
export const E2E_HARNESS_PULL_STEPS_FLOOR = "0.124.58";
|
|
33
|
+
|
|
24
34
|
/**
|
|
25
35
|
* The harness's chant docker-lexicon project, to `chant build <dir>/src
|
|
26
36
|
* --lexicon docker`. It ships as source in the package's src/.
|
package/src/e2e-harness/ports.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* chant's reports land, chant run outside the pipeline, the ledger, and time.
|
|
5
5
|
* The real ones are ./forgejo.ts and ./bucket.ts; tests pass fakes.
|
|
6
6
|
*/
|
|
7
|
+
import type { GatedRequestRead } from "../lifecycle/gated-request";
|
|
7
8
|
import type { OpRunRecord } from "../op/runtime";
|
|
8
9
|
|
|
9
10
|
/** A forge repository as the author, the reviewer and the admin: the pull request loop. */
|
|
@@ -48,6 +49,19 @@ export interface ForgeIssue {
|
|
|
48
49
|
open: boolean;
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
/** An open pull request as the forge reads it. */
|
|
53
|
+
export interface ForgePull {
|
|
54
|
+
number: number;
|
|
55
|
+
title: string;
|
|
56
|
+
/** Its head branch. */
|
|
57
|
+
branch: string;
|
|
58
|
+
/** Its head commit's sha. */
|
|
59
|
+
head: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Who on the forge a comment comes from. */
|
|
63
|
+
export type ForgePerson = "author" | "reviewer" | "admin";
|
|
64
|
+
|
|
51
65
|
/**
|
|
52
66
|
* sql-yodeler's Forge verbs (scenarios/forges/forge.ts:26-61) that the pull
|
|
53
67
|
* request loop lacks. `openPr` and `merge` there are `openPull` and
|
|
@@ -59,6 +73,18 @@ export interface ForgeReads {
|
|
|
59
73
|
comments(pull: number): Promise<string[]>;
|
|
60
74
|
/** The repository's issues, open and closed, without pull requests. */
|
|
61
75
|
issues(): Promise<ForgeIssue[]>;
|
|
76
|
+
/**
|
|
77
|
+
* The OPEN pull request from `branch` in this repository (a fork's branch
|
|
78
|
+
* of the same name is not it), or undefined. The oldest when there are
|
|
79
|
+
* several. A product opens it, and the await-pull step finds it.
|
|
80
|
+
*/
|
|
81
|
+
findPull(branch: string): Promise<ForgePull | undefined>;
|
|
82
|
+
/** Pull request `pull`, open or not, or undefined when the forge does not know it. */
|
|
83
|
+
pullInfo(pull: number): Promise<ForgePull | undefined>;
|
|
84
|
+
/** The repo-relative paths pull request `pull` changes, a renamed file under its new path. */
|
|
85
|
+
changedFiles(pull: number): Promise<string[]>;
|
|
86
|
+
/** Post `body` as a comment on pull request `pull`, as `as`. */
|
|
87
|
+
postComment(pull: number, body: string, as: ForgePerson): Promise<void>;
|
|
62
88
|
}
|
|
63
89
|
|
|
64
90
|
export interface ForgeRuns {
|
|
@@ -107,6 +133,13 @@ export interface Chant {
|
|
|
107
133
|
/** The run ledger of the scenario's repo (`chant/lifecycle`), read. */
|
|
108
134
|
export interface Ledger {
|
|
109
135
|
runs(env: string, op: string): Promise<OpRunRecord[]>;
|
|
136
|
+
/**
|
|
137
|
+
* The gated requests of `op`, oldest first, for the gated outcome. A gated
|
|
138
|
+
* request writes no op-run record, so `runs` never sees it. The real one
|
|
139
|
+
* is `readGatedRequests(op, location)` from the lifecycle module, on the
|
|
140
|
+
* scenario repo's ledger.
|
|
141
|
+
*/
|
|
142
|
+
gatedRequests?(op: string): Promise<GatedRequestRead[]>;
|
|
110
143
|
}
|
|
111
144
|
|
|
112
145
|
/** Work outside the forge and chant: a change made out of band. */
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* a repo tree, an ordered list of pull request steps, and the outcomes each
|
|
4
4
|
* step must show. The lint refuses one that cannot record a row: no claim
|
|
5
5
|
* id, no BREAK arm, nothing to check, or a step that names a pull request or
|
|
6
|
-
* a merge no earlier step made.
|
|
6
|
+
* a merge no earlier step made. An await-pull step makes a pull request as
|
|
7
|
+
* an open step does.
|
|
7
8
|
*/
|
|
8
9
|
import { readFileSync } from "node:fs";
|
|
9
10
|
import { validateScenario, type Scenario, type ScenarioStep } from "./schemas/index";
|
|
@@ -41,7 +42,7 @@ export function lintScenario(data: unknown): ScenarioFinding[] {
|
|
|
41
42
|
if (seen.has(step.id)) out.push({ at: `${at}/id`, message: `step id ${step.id} is used twice` });
|
|
42
43
|
const opened = (id: string) => {
|
|
43
44
|
const o = seen.get(id);
|
|
44
|
-
return o !== undefined && (o.do === "open" || o.do === "open-concurrent");
|
|
45
|
+
return o !== undefined && (o.do === "open" || o.do === "open-concurrent" || o.do === "await-pull");
|
|
45
46
|
};
|
|
46
47
|
switch (step.do) {
|
|
47
48
|
case "open-concurrent": {
|
|
@@ -54,7 +55,8 @@ export function lintScenario(data: unknown): ScenarioFinding[] {
|
|
|
54
55
|
case "plan":
|
|
55
56
|
case "approve":
|
|
56
57
|
case "merge":
|
|
57
|
-
|
|
58
|
+
case "comment":
|
|
59
|
+
if (!opened(step.pull)) out.push({ at: `${at}/pull`, message: `${step.do} names ${step.pull}, which is not an earlier open or await-pull step` });
|
|
58
60
|
break;
|
|
59
61
|
case "apply": {
|
|
60
62
|
const m = seen.get(step.merge);
|
|
@@ -69,9 +71,9 @@ export function lintScenario(data: unknown): ScenarioFinding[] {
|
|
|
69
71
|
if ("report" in e && step.do !== "plan" && step.do !== "apply") {
|
|
70
72
|
out.push({ at: `${at}/expect/${j}`, message: `a report outcome belongs on a plan or apply step, not ${step.do}` });
|
|
71
73
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
74
|
+
const hasPull = "pull" in step || step.do === "open" || step.do === "open-concurrent" || step.do === "await-pull";
|
|
75
|
+
if ("comment" in e && !hasPull) out.push({ at: `${at}/expect/${j}`, message: "a comment outcome belongs on a step with a pull request" });
|
|
76
|
+
if ("pull" in e && !hasPull) out.push({ at: `${at}/expect/${j}`, message: "a pull outcome belongs on a step with a pull request" });
|
|
75
77
|
if ("exit" in e && step.do !== "out-of-band") out.push({ at: `${at}/expect/${j}`, message: "an exit outcome belongs on an out-of-band step" });
|
|
76
78
|
}
|
|
77
79
|
seen.set(step.id, step);
|