@intentius/chant 0.124.77 → 0.124.78
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/__fixtures__/notify-messages/events.d.ts +9 -0
- package/dist/__fixtures__/notify-messages/events.d.ts.map +1 -0
- package/dist/__fixtures__/notify-messages/events.js +21 -0
- package/dist/__fixtures__/product-words.d.ts +14 -0
- package/dist/__fixtures__/product-words.d.ts.map +1 -1
- package/dist/__fixtures__/product-words.js +11 -0
- package/dist/__fixtures__/terragucci-notify.d.ts +66 -0
- package/dist/__fixtures__/terragucci-notify.d.ts.map +1 -0
- package/dist/__fixtures__/terragucci-notify.js +133 -0
- package/dist/action-pins.d.ts +8 -0
- package/dist/action-pins.d.ts.map +1 -1
- package/dist/action-pins.js +9 -0
- package/dist/agent-guard.d.ts.map +1 -1
- package/dist/agent-guard.js +1 -2
- package/dist/ci-commit.d.ts +66 -2
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +148 -19
- package/dist/ci-own-jobs.d.ts.map +1 -1
- package/dist/ci-own-jobs.js +1 -2
- package/dist/ci-product-words.d.ts +18 -4
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +26 -6
- package/dist/ci-product.d.ts +1 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +3 -4
- package/dist/cli/handlers/release.js +4 -4
- package/dist/components/pr-env-components.d.ts.map +1 -1
- package/dist/components/pr-env-components.js +1 -2
- package/dist/config.d.ts +14 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -1
- package/dist/lexicon.d.ts +8 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +9 -0
- package/dist/lifecycle/release-images.d.ts +77 -3
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +132 -6
- package/dist/notify-product.d.ts +11 -2
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +16 -4
- package/dist/notify-relay.d.ts.map +1 -1
- package/dist/notify-relay.js +1 -2
- package/dist/notify.d.ts +36 -4
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +31 -21
- package/dist/notify.schema.json +1 -0
- package/dist/op/activities/review-product.d.ts +111 -0
- package/dist/op/activities/review-product.d.ts.map +1 -0
- package/dist/op/activities/review-product.js +116 -0
- package/dist/policy-engine.d.ts.map +1 -1
- package/dist/policy-engine.js +1 -2
- package/dist/pr-forge-reads.d.ts +124 -0
- package/dist/pr-forge-reads.d.ts.map +1 -0
- package/dist/pr-forge-reads.js +322 -0
- package/dist/pr-forge.d.ts +14 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +21 -13
- package/dist/pr-plan-note.d.ts +293 -0
- package/dist/pr-plan-note.d.ts.map +1 -0
- package/dist/pr-plan-note.js +362 -0
- package/dist/release-floors.d.ts +9 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +9 -1
- package/dist/state-export.d.ts.map +1 -1
- package/dist/state-export.js +1 -2
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +1 -2
- package/dist/state-unlock.d.ts.map +1 -1
- package/dist/state-unlock.js +1 -2
- package/dist/wave-runtime.mjs +271 -271
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +2 -1
- package/package.json +1 -1
- package/src/__fixtures__/notify-messages/events.ts +23 -0
- package/src/__fixtures__/notify-messages/messages.json +50 -0
- package/src/__fixtures__/pr-loop/terragucci-plan.note.golden.md +53 -0
- package/src/__fixtures__/pr-loop/terragucci-plan.note.json +83 -0
- package/src/__fixtures__/product-words.ts +12 -0
- package/src/__fixtures__/review-agent/terragucci-review.json +94 -0
- package/src/__fixtures__/terragucci-notify.ts +170 -0
- package/src/action-pins.test.ts +12 -1
- package/src/action-pins.ts +11 -0
- package/src/agent-guard.test.ts +1 -2
- package/src/agent-guard.ts +1 -2
- package/src/ci-commit.test.ts +163 -0
- package/src/ci-commit.ts +168 -21
- package/src/ci-own-jobs.test.ts +1 -2
- package/src/ci-own-jobs.ts +1 -2
- package/src/ci-product-words.ts +35 -7
- package/src/ci-product.ts +3 -4
- package/src/cli/handlers/build-pr-loop-control.test.ts +1 -2
- package/src/cli/handlers/build-run-group.test.ts +1 -2
- package/src/cli/handlers/release.ts +5 -5
- package/src/components/pr-env-components.test.ts +1 -2
- package/src/components/pr-env-components.ts +1 -2
- package/src/config.ts +23 -3
- package/src/gate-policy-bundle.test.ts +1 -1
- package/src/lexicon.ts +10 -0
- package/src/lifecycle/release-images-dockerfile.test.ts +221 -0
- package/src/lifecycle/release-images.ts +167 -8
- package/src/notify-message-words.test.ts +186 -0
- package/src/notify-product.ts +17 -4
- package/src/notify-relay.ts +1 -2
- package/src/notify.schema.json +1 -0
- package/src/notify.ts +59 -19
- package/src/op/activities/review-product.test.ts +116 -0
- package/src/op/activities/review-product.ts +200 -0
- package/src/op/schedule-overdue.test.ts +26 -0
- package/src/policy-engine.test.ts +1 -2
- package/src/policy-engine.ts +1 -2
- package/src/pr-forge-reads.test.ts +285 -0
- package/src/pr-forge-reads.ts +424 -0
- package/src/pr-forge.ts +30 -16
- package/src/pr-plan-note.test.ts +105 -0
- package/src/pr-plan-note.ts +521 -0
- package/src/release-floors.ts +13 -1
- package/src/state-export.test.ts +1 -2
- package/src/state-export.ts +1 -2
- package/src/state-migration.test.ts +1 -2
- package/src/state-migration.ts +1 -2
- package/src/state-unlock.test.ts +1 -2
- package/src/state-unlock.ts +1 -2
- package/src/workspace/release-workflow.ts +2 -1
package/src/action-pins.ts
CHANGED
|
@@ -9,11 +9,21 @@
|
|
|
9
9
|
* forgejo lexicon moves `upload-artifact` and `download-artifact` to v3, whose
|
|
10
10
|
* rows are here too: v4 and later refuse to run on a Forgejo runner (#4008).
|
|
11
11
|
*
|
|
12
|
+
* actions/cache has a v4 row beside v6 (#4816): terragucci's Terragrunt cache
|
|
13
|
+
* step uses the action itself at the commit the restore and save rows pin.
|
|
14
|
+
* It follows them in the table, so `pinAtMajor` on that shared commit still
|
|
15
|
+
* starts from the restore row.
|
|
16
|
+
*
|
|
12
17
|
* Refresh a row by resolving the major tag to its commit:
|
|
13
18
|
*
|
|
14
19
|
* gh api repos/actions/checkout/commits/v6 --jq .sha
|
|
15
20
|
*/
|
|
16
21
|
|
|
22
|
+
import { NEXT_RELEASE } from "./release-floors";
|
|
23
|
+
|
|
24
|
+
/** The first chant whose table has the `cache4` row (#4816). */
|
|
25
|
+
export const CACHE4_PIN_FLOOR = NEXT_RELEASE;
|
|
26
|
+
|
|
17
27
|
export interface ActionPin {
|
|
18
28
|
/** The action, with its subpath: `actions/cache/restore`. */
|
|
19
29
|
readonly slug: string;
|
|
@@ -47,6 +57,7 @@ export const ACTION_PINS = {
|
|
|
47
57
|
createGithubAppToken2: pin("actions/create-github-app-token", "v2", "fee1f7d63c2ff003460e3d139729b119787bc349", "v2.2.2"),
|
|
48
58
|
cacheRestore4: pin("actions/cache/restore", "v4", "0057852bfaa89a56745cba8c7296529d2fc39830", "v4.3.0"),
|
|
49
59
|
cacheSave4: pin("actions/cache/save", "v4", "0057852bfaa89a56745cba8c7296529d2fc39830", "v4.3.0"),
|
|
60
|
+
cache4: pin("actions/cache", "v4", "0057852bfaa89a56745cba8c7296529d2fc39830", "v4.3.0"),
|
|
50
61
|
uploadArtifact4: pin("actions/upload-artifact", "v4", "ea165f8d65b6e75b540449e92b4886f43607fa02", "v4.6.2"),
|
|
51
62
|
uploadArtifact3: pin("actions/upload-artifact", "v3", "ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5", "v3.2.1"),
|
|
52
63
|
downloadArtifact4: pin("actions/download-artifact", "v4", "d3f86a106a0bac45b974a628896c90dbdf5c8093", "v4.3.0"),
|
package/src/agent-guard.test.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { tmpdir } from "node:os";
|
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
import { describe, expect, it, onTestFinished } from "vitest";
|
|
12
12
|
import { AGENT_GUARD_FLOOR, agentGuard, CLAUDE_SETTINGS_LOCAL, CLAUDE_SETTINGS_SHARED, installAgentGuard, withAgentGuardHook } from "./agent-guard";
|
|
13
|
-
import { NEXT_RELEASE } from "./release-floors";
|
|
14
13
|
import { PLYWOOD_GUARD } from "./__fixtures__/agent-guard/plywood";
|
|
15
14
|
import { TERRAGUCCI_GUARD } from "./__fixtures__/agent-guard/terragucci";
|
|
16
15
|
|
|
@@ -60,7 +59,7 @@ function terragucci() {
|
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
describe("AGENT_GUARD_FLOOR", () => {
|
|
63
|
-
it("names the next release", () => expect(AGENT_GUARD_FLOOR).toBe(
|
|
62
|
+
it("names the next release", () => expect(AGENT_GUARD_FLOOR).toBe("0.124.77"));
|
|
64
63
|
});
|
|
65
64
|
|
|
66
65
|
describe("terragucci's guard: the wrappers", () => {
|
package/src/agent-guard.ts
CHANGED
|
@@ -33,10 +33,9 @@
|
|
|
33
33
|
import { spawnSync } from "node:child_process";
|
|
34
34
|
import { chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
35
35
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
36
|
-
import { NEXT_RELEASE } from "./release-floors";
|
|
37
36
|
|
|
38
37
|
/** The first chant with the shared agent guard (#4770). Products feature-detect on it, or on `installAgentGuard`. */
|
|
39
|
-
export const AGENT_GUARD_FLOOR =
|
|
38
|
+
export const AGENT_GUARD_FLOOR = "0.124.77";
|
|
40
39
|
|
|
41
40
|
/** What the guard refuses of one engine binary (tofu, pulumi, terragrunt). Flag names are written with their dashes. */
|
|
42
41
|
export interface AgentGuardEngine {
|
package/src/ci-commit.test.ts
CHANGED
|
@@ -22,6 +22,13 @@ import {
|
|
|
22
22
|
resolveCommitSpec,
|
|
23
23
|
runCommit,
|
|
24
24
|
COMMIT_PR_ENV,
|
|
25
|
+
CI_COMMIT_ARG_FLOOR,
|
|
26
|
+
CI_COMMIT_HARNESS_BREAK_FLOOR,
|
|
27
|
+
COMMIT_HARNESS_BREAK_ENV,
|
|
28
|
+
COMMIT_HARNESS_FORGE,
|
|
29
|
+
commitHarnessBreaks,
|
|
30
|
+
commitArgv,
|
|
31
|
+
GITLAB_COMMIT_ARG_VAR,
|
|
25
32
|
type CommitRefusalReply,
|
|
26
33
|
type CommitRunCommand,
|
|
27
34
|
type CommitSettings,
|
|
@@ -29,6 +36,7 @@ import {
|
|
|
29
36
|
} from "./ci-commit";
|
|
30
37
|
import { assertProductWords, parseProductComment } from "./ci-product-words";
|
|
31
38
|
import { PLYWOOD } from "./__fixtures__/product-words";
|
|
39
|
+
import { NEXT_RELEASE } from "./release-floors";
|
|
32
40
|
import type { OpRunRecord, OpRunRecordInput } from "./op/runtime";
|
|
33
41
|
import type { PullRequestHead } from "./pr-forge";
|
|
34
42
|
|
|
@@ -482,3 +490,158 @@ describe("the command's variables and its refusal reply (#4724)", () => {
|
|
|
482
490
|
expect(w.replies[0]).toContain("stopped with exit code 3");
|
|
483
491
|
});
|
|
484
492
|
});
|
|
493
|
+
|
|
494
|
+
describe("the comment's argument (#4820)", () => {
|
|
495
|
+
const NAME_PATTERN = "^[a-z0-9]+(?:[-_][a-z0-9]+)*$";
|
|
496
|
+
const named = (extra: Partial<OpCommitSpec> = {}) => settings({ commentArg: { pattern: NAME_PATTERN, position: 1 }, ...extra });
|
|
497
|
+
const seeing = (into: (readonly string[])[]): CommitRunCommand => async (argv, o) => {
|
|
498
|
+
into.push(argv);
|
|
499
|
+
return formatter()(argv, o);
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
test("the parse reads one argument only for a word that declares it, against its pattern and chant's own", () => {
|
|
503
|
+
const args = { fmt: new RegExp(NAME_PATTERN) };
|
|
504
|
+
expect(parseProductComment(words, "/plywood fmt", {}, args)).toEqual({ kind: "commit", word: "fmt" });
|
|
505
|
+
expect(parseProductComment(words, "/plywood fmt add-note", {}, args)).toEqual({ kind: "commit", word: "fmt", arg: "add-note" });
|
|
506
|
+
expect(parseProductComment(words, "/plywood fmt Add-Note", {}, args)).toMatchObject({ kind: "refused", reason: expect.stringMatching(/`\/plywood fmt` takes nothing, or one name after it/) });
|
|
507
|
+
expect(parseProductComment(words, "/plywood fmt a b", {}, args)).toMatchObject({ kind: "refused" });
|
|
508
|
+
expect(parseProductComment(words, "/plywood fmt --force", {}, args)).toMatchObject({ kind: "refused" });
|
|
509
|
+
// chant's own check holds whatever the product's pattern lets through.
|
|
510
|
+
expect(parseProductComment(words, "/plywood fmt ../x", {}, { fmt: /^.*$/ })).toMatchObject({ kind: "refused" });
|
|
511
|
+
expect(parseProductComment(words, "/plywood fmt $(id)", {}, { fmt: /^.*$/ })).toMatchObject({ kind: "refused" });
|
|
512
|
+
expect(parseProductComment(words, "/plywood fmt add-note")).toEqual({ kind: "refused", reason: "`/plywood fmt` takes nothing after it" });
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
test("commentArg round-trips through the job's variables and refuses a loose pattern, a bad position or the check trigger", () => {
|
|
516
|
+
const s = named();
|
|
517
|
+
expect(s.commentArg).toEqual({ pattern: NAME_PATTERN, position: 1 });
|
|
518
|
+
expect(commitSettingsFromEnv(commitSettingsEnv(s), "plywood")).toEqual(s);
|
|
519
|
+
expect(settings().commentArg).toBeUndefined();
|
|
520
|
+
expect(() => named({ commentArg: { pattern: "[a-z]+", position: 1 } })).toThrow(/anchored/);
|
|
521
|
+
expect(() => named({ commentArg: { pattern: "^(?:$", position: 1 } })).toThrow(/pattern/);
|
|
522
|
+
expect(() => named({ commentArg: { pattern: NAME_PATTERN, position: 0 } })).toThrow(/position/);
|
|
523
|
+
expect(() => named({ commentArg: { pattern: NAME_PATTERN, position: 4 } })).toThrow(/position/);
|
|
524
|
+
expect(() => resolveCommitSpec("plywood-fmt", { on: "check", command: ["terraform", "fmt"], allowed: ["main.tf"], commentArg: { pattern: NAME_PATTERN, position: 1 } }, "plywood")).toThrow(/comment trigger/);
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
test("commitArgv puts the argument at its position and refuses one the settings do not take", () => {
|
|
528
|
+
expect(commitArgv(named(), "add-note")).toEqual(["terraform", "add-note", "fmt", "-recursive"]);
|
|
529
|
+
expect(commitArgv(named(), undefined)).toEqual(["terraform", "fmt", "-recursive"]);
|
|
530
|
+
expect(() => commitArgv(settings(), "add-note")).toThrow(/takes no argument/);
|
|
531
|
+
expect(() => commitArgv(named(), "Bad")).toThrow(/not a name/);
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
test("the comment's argument reaches the command's argv, the commit and the reply", async () => {
|
|
535
|
+
const w = world();
|
|
536
|
+
const argvs: (readonly string[])[] = [];
|
|
537
|
+
const { decision, out } = await cycle(w, named(), { event: comment("/plywood fmt add-note"), command: seeing(argvs) });
|
|
538
|
+
expect(decision.arg).toBe("add-note");
|
|
539
|
+
expect(argvs).toEqual([["terraform", "add-note", "fmt", "-recursive"]]);
|
|
540
|
+
expect(out.result).toBe("pushed");
|
|
541
|
+
expect(featureLog(w)).toContain("/plywood fmt add-note asked for by ana");
|
|
542
|
+
expect(featureLog(w)).toContain("Ran terraform add-note fmt -recursive on ");
|
|
543
|
+
expect(w.replies[0]).toContain("from `terraform add-note fmt -recursive`");
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
test("without an argument the argv is the spec's", async () => {
|
|
547
|
+
const w = world();
|
|
548
|
+
const argvs: (readonly string[])[] = [];
|
|
549
|
+
const { decision } = await cycle(w, named(), { command: seeing(argvs) });
|
|
550
|
+
expect(decision.arg).toBeUndefined();
|
|
551
|
+
expect(argvs).toEqual([["terraform", "fmt", "-recursive"]]);
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
test("an argument off the pattern is refused before anything runs", async () => {
|
|
555
|
+
const w = world();
|
|
556
|
+
const argvs: (readonly string[])[] = [];
|
|
557
|
+
const { out } = await cycle(w, named(), { event: comment("/plywood fmt Not_ok!"), command: seeing(argvs) });
|
|
558
|
+
expect(argvs).toEqual([]);
|
|
559
|
+
expect(out.result).toBe("refused");
|
|
560
|
+
expect(out.reason).toMatch(/takes nothing, or one name after it/);
|
|
561
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
test("GitLab takes the argument from its own pipeline variable", async () => {
|
|
565
|
+
const w = world();
|
|
566
|
+
const argvs: (readonly string[])[] = [];
|
|
567
|
+
const env = { GITLAB_CI: "true", CHANT_COMMIT_PR: "7", CHANT_COMMIT: "fmt", [GITLAB_COMMIT_ARG_VAR]: "add-note", GITLAB_USER_LOGIN: "ana" };
|
|
568
|
+
const { out } = await cycle(w, named(), { event: {}, env, command: seeing(argvs) });
|
|
569
|
+
expect(out.result).toBe("pushed");
|
|
570
|
+
expect(argvs).toEqual([["terraform", "add-note", "fmt", "-recursive"]]);
|
|
571
|
+
const bad = world();
|
|
572
|
+
const { out: refused } = await cycle(bad, named(), { event: {}, env: { ...env, [GITLAB_COMMIT_ARG_VAR]: "a b" }, command: seeing([]) });
|
|
573
|
+
expect(refused.result).toBe("refused");
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
test("the floor is the next release until it ships", () => {
|
|
577
|
+
expect(CI_COMMIT_ARG_FLOOR).toBe(NEXT_RELEASE);
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
describe("the harness's BREAK switch for land (#4836)", () => {
|
|
582
|
+
const harness = (checks: string) => ({ [COMMIT_HARNESS_BREAK_ENV]: checks, BREAK: "1", GITHUB_SERVER_URL: COMMIT_HARNESS_FORGE });
|
|
583
|
+
|
|
584
|
+
test("is read only in a BREAK arm on the harness's Forgejo, and refused anywhere else", () => {
|
|
585
|
+
expect(commitHarnessBreaks({})).toEqual({ checks: [] });
|
|
586
|
+
expect(commitHarnessBreaks(harness("paths"))).toEqual({ checks: ["paths"] });
|
|
587
|
+
expect(commitHarnessBreaks({ ...harness("paths, moved-base"), GITHUB_SERVER_URL: `${COMMIT_HARNESS_FORGE}/` })).toEqual({ checks: ["paths", "moved-base"] });
|
|
588
|
+
expect(commitHarnessBreaks({ ...harness("paths"), BREAK: undefined })).toMatchObject({ refused: expect.stringMatching(/only in a BREAK arm of chant's e2e harness/) });
|
|
589
|
+
expect(commitHarnessBreaks({ ...harness("paths"), GITHUB_SERVER_URL: "https://github.com" })).toMatchObject({ refused: expect.stringMatching(/only in a BREAK arm/) });
|
|
590
|
+
expect(commitHarnessBreaks({ ...harness("paths"), GITHUB_SERVER_URL: undefined })).toMatchObject({ refused: expect.any(String) });
|
|
591
|
+
expect(commitHarnessBreaks({ ...harness("paths"), GITLAB_CI: "true" })).toMatchObject({ refused: expect.any(String) });
|
|
592
|
+
expect(commitHarnessBreaks(harness("guarded"))).toMatchObject({ refused: expect.stringMatching(/paths and moved-base/) });
|
|
593
|
+
expect(commitHarnessBreaks(harness(""))).toEqual({ checks: [] });
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
test("the harness's Forgejo is the one chant's e2e stack runs", async () => {
|
|
597
|
+
const { HARNESS_HOSTS } = await import("./e2e-harness/stack");
|
|
598
|
+
expect(COMMIT_HARNESS_FORGE).toBe(HARNESS_HOSTS.forgejo);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
test("outside a harness the switch fails the land and pushes nothing", async () => {
|
|
602
|
+
const w = world();
|
|
603
|
+
const { out } = await cycle(w, settings(), { env: { [COMMIT_HARNESS_BREAK_ENV]: "paths" } });
|
|
604
|
+
expect(out).toMatchObject({ result: "failed", code: 1 });
|
|
605
|
+
expect(out.reason).toMatch(new RegExp(COMMIT_HARNESS_BREAK_ENV));
|
|
606
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
607
|
+
expect(w.replies[0]).toMatch(/only in a BREAK arm.*nothing was pushed/);
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
test("paths: a change outside allowed lands, and says the check was off", async () => {
|
|
611
|
+
const w = world();
|
|
612
|
+
const { out } = await cycle(w, settings(), { command: formatter({ "other.tf": "z\n" }), env: harness("paths") });
|
|
613
|
+
expect(out.result).toBe("pushed");
|
|
614
|
+
expect(out.paths).toEqual(["main.tf", "other.tf"]);
|
|
615
|
+
expect(out.reason).toContain("BREAK: the path check was off");
|
|
616
|
+
expect(w.replies[0]).toContain("BREAK: the path check was off");
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
test("paths: a guarded path is still refused", async () => {
|
|
620
|
+
const w = world();
|
|
621
|
+
const { out } = await cycle(w, settings(), { command: formatter({ ".github/workflows/x.yml": "on: push\n" }), env: harness("paths") });
|
|
622
|
+
expect(out.result).toBe("refused");
|
|
623
|
+
expect(out.reason).toBe("the change touches .github/workflows/x.yml");
|
|
624
|
+
expect(sh(["rev-parse", "refs/heads/feature"], w.r.origin).trim()).toBe(w.r.head);
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
test("moved-base: a base that moved while the command ran lands the merge of the tip the command ran on", async () => {
|
|
628
|
+
const w = world();
|
|
629
|
+
const ran = onMain(w, { "migrations/002.sql": "x\n" });
|
|
630
|
+
const { out } = await cycle(w, settings({ mergeBase: true }), { env: harness("moved-base"), between: () => void onMain(w, { "migrations/003.sql": "y\n" }, "moved") });
|
|
631
|
+
expect(out.result).toBe("pushed");
|
|
632
|
+
expect(out.reason).toContain("BREAK: the moved-base check was off");
|
|
633
|
+
const parents = sh(["log", "-1", "--format=%P", "refs/heads/feature"], w.r.origin).trim().split(" ");
|
|
634
|
+
expect(parents).toEqual([w.r.head, ran]);
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
test("one check off leaves the other on", async () => {
|
|
638
|
+
const w = world();
|
|
639
|
+
onMain(w, { "migrations/002.sql": "x\n" });
|
|
640
|
+
const { out } = await cycle(w, settings({ mergeBase: true }), { env: harness("paths"), between: () => void onMain(w, { "migrations/003.sql": "y\n" }, "moved") });
|
|
641
|
+
expect(out).toMatchObject({ result: "refused", reason: "the base moved" });
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
test("the floor is the next release until it ships", () => {
|
|
645
|
+
expect(CI_COMMIT_HARNESS_BREAK_FLOOR).toBe(NEXT_RELEASE);
|
|
646
|
+
});
|
|
647
|
+
});
|
package/src/ci-commit.ts
CHANGED
|
@@ -30,9 +30,9 @@ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "no
|
|
|
30
30
|
import { join } from "node:path";
|
|
31
31
|
import { CHANT_EXIT } from "./exit-codes";
|
|
32
32
|
import { FORGE_TOKEN_VARS } from "./ci-handover";
|
|
33
|
-
import { NEXT_RELEASE } from "./release-floors";
|
|
34
33
|
import { agentForbiddenPaths, AgentError, branchOk, errText, LOGIN, readSmall, SHA, type AgentGit } from "./ci-agent";
|
|
35
|
-
import { parseProductComment, type CiProductWords } from "./ci-product-words";
|
|
34
|
+
import { COMMIT_COMMENT_ARG, parseProductComment, type CiProductWords } from "./ci-product-words";
|
|
35
|
+
import { NEXT_RELEASE } from "./release-floors";
|
|
36
36
|
import type { OpRunRecord, OpRunRecordInput } from "./op/runtime";
|
|
37
37
|
import type { RunOrigin } from "./lifecycle/release-ledger";
|
|
38
38
|
import type { PrForge } from "./pr-forge";
|
|
@@ -49,7 +49,11 @@ export const CI_COMMIT_FILES_FLOOR = "0.124.73";
|
|
|
49
49
|
* `CHANT_COMMIT_PR`, keeps the tail of its standard error and replies with a
|
|
50
50
|
* product's refusal text ({@link setCommitRefusalReply}) (#4724).
|
|
51
51
|
*/
|
|
52
|
-
export const CI_COMMIT_REPLY_FLOOR =
|
|
52
|
+
export const CI_COMMIT_REPLY_FLOOR = "0.124.77";
|
|
53
|
+
/** The first chant whose commit job takes `commentArg`, one argument after the comment's word passed into the argv (#4820). */
|
|
54
|
+
export const CI_COMMIT_ARG_FLOOR = NEXT_RELEASE;
|
|
55
|
+
/** The first chant whose `commit land` reads {@link COMMIT_HARNESS_BREAK_ENV} in a BREAK arm of chant's e2e harness (#4836). */
|
|
56
|
+
export const CI_COMMIT_HARNESS_BREAK_FLOOR = NEXT_RELEASE;
|
|
53
57
|
|
|
54
58
|
/** What starts a commit run: a person's comment, or a check job's finding. */
|
|
55
59
|
export type CommitTrigger = "comment" | "check";
|
|
@@ -119,6 +123,22 @@ export interface OpCommitSpec {
|
|
|
119
123
|
* on GitLab they are the project's CI/CD variables.
|
|
120
124
|
*/
|
|
121
125
|
commandEnv?: string[];
|
|
126
|
+
/**
|
|
127
|
+
* For `on: "comment"` (#4820): the comment may carry one argument after
|
|
128
|
+
* the word, `/<product> <word> <arg>`, which must match `pattern` (a
|
|
129
|
+
* regular expression's source, anchored with `^` and `$`) and chant's
|
|
130
|
+
* own plain-name check ({@link COMMIT_COMMENT_ARG}). It goes into the
|
|
131
|
+
* command's argv at index `position`, from 1 (after the program) to the
|
|
132
|
+
* argv's length (at the end). With no argument the argv is `command`. On
|
|
133
|
+
* GitLab the pipeline's {@link GITLAB_COMMIT_ARG_VAR} carries it.
|
|
134
|
+
*/
|
|
135
|
+
commentArg?: CommitCommentArg;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Where a commit job's command takes the comment's argument (#4820). */
|
|
139
|
+
export interface CommitCommentArg {
|
|
140
|
+
pattern: string;
|
|
141
|
+
position: number;
|
|
122
142
|
}
|
|
123
143
|
|
|
124
144
|
/** A commit job's settings, every default filled and checked. */
|
|
@@ -141,6 +161,8 @@ export interface CommitSettings {
|
|
|
141
161
|
after: string[];
|
|
142
162
|
/** The job variables the command sees (#4724). */
|
|
143
163
|
commandEnv: string[];
|
|
164
|
+
/** The comment's argument and where it goes in the argv (#4820). */
|
|
165
|
+
commentArg?: CommitCommentArg;
|
|
144
166
|
}
|
|
145
167
|
|
|
146
168
|
export const COMMIT_MAX_RUNS = 3;
|
|
@@ -165,6 +187,7 @@ export const COMMIT_ENV = {
|
|
|
165
187
|
env: "CHANT_COMMIT_ENV",
|
|
166
188
|
mergeBase: "CHANT_COMMIT_MERGE_BASE",
|
|
167
189
|
commandEnv: "CHANT_COMMIT_COMMAND_ENV",
|
|
190
|
+
commentArg: "CHANT_COMMIT_COMMENT_ARG",
|
|
168
191
|
} as const;
|
|
169
192
|
|
|
170
193
|
/** The variable the command reads the pull request's number from (#4724), such as for a default name. */
|
|
@@ -173,6 +196,8 @@ export const COMMIT_PR_ENV = "CHANT_COMMIT_PR";
|
|
|
173
196
|
/** GitLab starts no pipeline on a note: a pipeline of the default branch started with these runs a comment commit job. */
|
|
174
197
|
export const GITLAB_COMMIT_PR_VAR = "CHANT_COMMIT_PR";
|
|
175
198
|
export const GITLAB_COMMIT_WORD_VAR = "CHANT_COMMIT";
|
|
199
|
+
/** With `commentArg` (#4820): the argument, as the comment would give it after the word. */
|
|
200
|
+
export const GITLAB_COMMIT_ARG_VAR = "CHANT_COMMIT_ARG";
|
|
176
201
|
|
|
177
202
|
/** Where the jobs keep the decision, the exit code and the patch, from the job's directory. */
|
|
178
203
|
export const COMMIT_DIR = ".chant/commit";
|
|
@@ -259,6 +284,20 @@ export function resolveCommitSpec(name: string, spec: OpCommitSpec, product = "c
|
|
|
259
284
|
if (!Array.isArray(commandEnv) || !commandEnv.every((v) => typeof v === "string" && VAR.test(v))) throw new AgentError(`${where}: commandEnv is a list of variable names`);
|
|
260
285
|
const tokens = commandEnv.filter((v) => (FORGE_TOKEN_VARS as readonly string[]).includes(v) || v === spec.tokenEnv || v.startsWith("CHANT_COMMIT_"));
|
|
261
286
|
if (tokens.length > 0) throw new AgentError(`${where}: commandEnv may not pass ${tokens.join(", ")}: the command never sees a forge token or the job's own settings`);
|
|
287
|
+
let commentArg: CommitCommentArg | undefined;
|
|
288
|
+
if (spec.commentArg !== undefined) {
|
|
289
|
+
const a = spec.commentArg as Partial<CommitCommentArg>;
|
|
290
|
+
if (spec.on !== "comment") throw new AgentError(`${where}: commentArg is for the comment trigger, which has a comment to read it from`);
|
|
291
|
+
if (typeof a.pattern !== "string" || !a.pattern.startsWith("^") || !a.pattern.endsWith("$") || a.pattern.length > 200) {
|
|
292
|
+
throw new AgentError(`${where}: commentArg's pattern is a regular expression's source anchored with ^ and $, such as "^[a-z0-9]+(?:[-_][a-z0-9]+)*$"`);
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
new RegExp(a.pattern);
|
|
296
|
+
} catch (e) {
|
|
297
|
+
throw new AgentError(`${where}: commentArg's pattern is not a regular expression (${(e as Error).message})`);
|
|
298
|
+
}
|
|
299
|
+
commentArg = { pattern: a.pattern, position: intIn(`${where}: commentArg's position`, a.position, 1, spec.command.length) };
|
|
300
|
+
}
|
|
262
301
|
return {
|
|
263
302
|
name,
|
|
264
303
|
on: spec.on,
|
|
@@ -275,9 +314,28 @@ export function resolveCommitSpec(name: string, spec: OpCommitSpec, product = "c
|
|
|
275
314
|
jobToken: spec.jobToken === true,
|
|
276
315
|
after: [...after],
|
|
277
316
|
commandEnv: [...new Set(commandEnv)],
|
|
317
|
+
...(commentArg ? { commentArg } : {}),
|
|
278
318
|
};
|
|
279
319
|
}
|
|
280
320
|
|
|
321
|
+
/** The words that take an argument, for {@link parseProductComment}: this job's word, when it has `commentArg`. */
|
|
322
|
+
function commentArgPatterns(s: Partial<Pick<CommitSettings, "comment" | "commentArg">>): Record<string, RegExp> {
|
|
323
|
+
const word = s.comment?.split(" ")[1];
|
|
324
|
+
return word && s.commentArg ? { [word]: new RegExp(s.commentArg.pattern) } : {};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* The argv the command runs (#4820): `command`, with the comment's argument
|
|
329
|
+
* at `commentArg.position` when there is one. An argument the settings do
|
|
330
|
+
* not take, or one off its pattern, throws.
|
|
331
|
+
*/
|
|
332
|
+
export function commitArgv(s: Pick<CommitSettings, "command"> & Partial<Pick<CommitSettings, "commentArg">>, arg: string | undefined): string[] {
|
|
333
|
+
if (arg === undefined) return [...s.command];
|
|
334
|
+
if (!s.commentArg) throw new AgentError("this commit job takes no argument after its word");
|
|
335
|
+
if (!COMMIT_COMMENT_ARG.test(arg) || !new RegExp(s.commentArg.pattern).test(arg)) throw new AgentError(`${JSON.stringify(arg)} is not a name this commit job takes`);
|
|
336
|
+
return [...s.command.slice(0, s.commentArg.position), arg, ...s.command.slice(s.commentArg.position)];
|
|
337
|
+
}
|
|
338
|
+
|
|
281
339
|
/** The settings as the generated jobs' variables. */
|
|
282
340
|
export function commitSettingsEnv(s: CommitSettings): Record<string, string> {
|
|
283
341
|
return {
|
|
@@ -294,6 +352,7 @@ export function commitSettingsEnv(s: CommitSettings): Record<string, string> {
|
|
|
294
352
|
[COMMIT_ENV.env]: s.env,
|
|
295
353
|
...(s.mergeBase ? { [COMMIT_ENV.mergeBase]: "1" } : {}),
|
|
296
354
|
...(s.commandEnv.length > 0 ? { [COMMIT_ENV.commandEnv]: JSON.stringify(s.commandEnv) } : {}),
|
|
355
|
+
...(s.commentArg ? { [COMMIT_ENV.commentArg]: JSON.stringify(s.commentArg) } : {}),
|
|
297
356
|
};
|
|
298
357
|
}
|
|
299
358
|
|
|
@@ -323,6 +382,17 @@ export function commitSettingsFromEnv(env: Record<string, string | undefined>, p
|
|
|
323
382
|
const maxRuns = num(COMMIT_ENV.maxRuns);
|
|
324
383
|
const timeout = num(COMMIT_ENV.timeout);
|
|
325
384
|
const guarded = list(COMMIT_ENV.guarded);
|
|
385
|
+
let commentArg: CommitCommentArg | undefined;
|
|
386
|
+
const argText = env[COMMIT_ENV.commentArg];
|
|
387
|
+
if (argText) {
|
|
388
|
+
try {
|
|
389
|
+
const parsed = JSON.parse(argText) as unknown;
|
|
390
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("not an object");
|
|
391
|
+
commentArg = parsed as CommitCommentArg;
|
|
392
|
+
} catch (e) {
|
|
393
|
+
throw new AgentError(`${COMMIT_ENV.commentArg} is a JSON object with pattern and position (${(e as Error).message})`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
326
396
|
const spec: OpCommitSpec = {
|
|
327
397
|
on: env[COMMIT_ENV.on] as CommitTrigger,
|
|
328
398
|
...(env[COMMIT_ENV.comment] ? { comment: env[COMMIT_ENV.comment] } : {}),
|
|
@@ -336,6 +406,7 @@ export function commitSettingsFromEnv(env: Record<string, string | undefined>, p
|
|
|
336
406
|
...(env[COMMIT_ENV.env] ? { env: env[COMMIT_ENV.env] } : {}),
|
|
337
407
|
...(env[COMMIT_ENV.mergeBase] === "1" ? { mergeBase: true } : {}),
|
|
338
408
|
...(list(COMMIT_ENV.commandEnv) ? { commandEnv: list(COMMIT_ENV.commandEnv)! } : {}),
|
|
409
|
+
...(commentArg ? { commentArg } : {}),
|
|
339
410
|
};
|
|
340
411
|
return resolveCommitSpec(name, spec, product);
|
|
341
412
|
}
|
|
@@ -368,6 +439,8 @@ export interface CommitRequest {
|
|
|
368
439
|
pr: number;
|
|
369
440
|
/** The commenter, or the person who started the GitLab pipeline. Absent on the `check` trigger. */
|
|
370
441
|
user?: string;
|
|
442
|
+
/** The comment's argument (#4820), checked against `commentArg`. */
|
|
443
|
+
arg?: string;
|
|
371
444
|
}
|
|
372
445
|
|
|
373
446
|
/**
|
|
@@ -378,7 +451,7 @@ export interface CommitRequest {
|
|
|
378
451
|
* pull request the check ran for, from the `pull_request` event or the
|
|
379
452
|
* merge request pipeline.
|
|
380
453
|
*/
|
|
381
|
-
export function commitRequestFromRun(words: CiProductWords, s: Pick<CommitSettings, "on" | "comment"
|
|
454
|
+
export function commitRequestFromRun(words: CiProductWords, s: Pick<CommitSettings, "on" | "comment"> & Partial<Pick<CommitSettings, "commentArg">>, env: Record<string, string | undefined>, event: unknown): CommitRequest | { refused: string } {
|
|
382
455
|
const gitlab = env.GITLAB_CI === "true";
|
|
383
456
|
let pr: unknown;
|
|
384
457
|
if (s.on === "check") {
|
|
@@ -391,7 +464,8 @@ export function commitRequestFromRun(words: CiProductWords, s: Pick<CommitSettin
|
|
|
391
464
|
const word = s.comment?.split(" ")[1];
|
|
392
465
|
if (gitlab) {
|
|
393
466
|
pr = Number(env[GITLAB_COMMIT_PR_VAR]);
|
|
394
|
-
|
|
467
|
+
const arg = env[GITLAB_COMMIT_ARG_VAR];
|
|
468
|
+
body = env[GITLAB_COMMIT_WORD_VAR] === word ? `${s.comment}${arg ? ` ${arg}` : ""}` : `/${words.product} ${env[GITLAB_COMMIT_WORD_VAR] ?? ""}`;
|
|
395
469
|
user = env.GITLAB_USER_LOGIN;
|
|
396
470
|
} else {
|
|
397
471
|
const e = event as { comment?: { body?: unknown; user?: { login?: unknown } }; issue?: { number?: unknown } } | undefined;
|
|
@@ -401,10 +475,10 @@ export function commitRequestFromRun(words: CiProductWords, s: Pick<CommitSettin
|
|
|
401
475
|
}
|
|
402
476
|
if (typeof pr !== "number" || !Number.isInteger(pr) || pr < 1) return { refused: "the run names no pull request" };
|
|
403
477
|
if (typeof user !== "string" || !LOGIN.test(user)) return { refused: "the run names nobody who asked" };
|
|
404
|
-
const parsed = parseProductComment(words, body, env);
|
|
478
|
+
const parsed = parseProductComment(words, body, env, commentArgPatterns(s));
|
|
405
479
|
if (parsed?.kind === "refused") return { refused: parsed.reason };
|
|
406
480
|
if (parsed?.kind !== "commit" || parsed.word !== word) return { refused: `the comment is not ${s.comment}` };
|
|
407
|
-
return { pr, user };
|
|
481
|
+
return { pr, user, ...(parsed.arg !== undefined ? { arg: parsed.arg } : {}) };
|
|
408
482
|
}
|
|
409
483
|
|
|
410
484
|
/**
|
|
@@ -441,7 +515,7 @@ function pushedBranch(env: Record<string, string | undefined>): string | undefin
|
|
|
441
515
|
*/
|
|
442
516
|
export async function resolveCommitRequest(
|
|
443
517
|
words: CiProductWords,
|
|
444
|
-
s: Pick<CommitSettings, "on" | "comment"
|
|
518
|
+
s: Pick<CommitSettings, "on" | "comment"> & Partial<Pick<CommitSettings, "commentArg">>,
|
|
445
519
|
env: Record<string, string | undefined>,
|
|
446
520
|
event: unknown,
|
|
447
521
|
forge?: Partial<Pick<PrForge, "findPullRequest">>,
|
|
@@ -472,6 +546,8 @@ export interface CommitDecision {
|
|
|
472
546
|
pr?: number;
|
|
473
547
|
branch?: string;
|
|
474
548
|
user?: string;
|
|
549
|
+
/** The comment's argument (#4820), which `commit run` puts in the argv. */
|
|
550
|
+
arg?: string;
|
|
475
551
|
/** With `mergeBase`: the base branch and the tip the command ran on. */
|
|
476
552
|
base?: string;
|
|
477
553
|
baseSha?: string;
|
|
@@ -487,6 +563,7 @@ export function readCommitDecision(dir: string): CommitDecision | undefined {
|
|
|
487
563
|
if (d.branch !== undefined && !branchOk(d.branch)) return undefined;
|
|
488
564
|
if (d.base !== undefined && !branchOk(d.base)) return undefined;
|
|
489
565
|
if (d.baseSha !== undefined && !SHA.test(d.baseSha)) return undefined;
|
|
566
|
+
if (d.arg !== undefined && !(typeof d.arg === "string" && COMMIT_COMMENT_ARG.test(d.arg))) return undefined;
|
|
490
567
|
return d as CommitDecision;
|
|
491
568
|
} catch {
|
|
492
569
|
return undefined;
|
|
@@ -618,7 +695,7 @@ export async function prepareCommitRun(i: CommitPrepareInput): Promise<CommitDec
|
|
|
618
695
|
|
|
619
696
|
const req = await resolveCommitRequest(i.words, s, i.env, i.event, i.forge);
|
|
620
697
|
if ("refused" in req) return no(req.refused, s.on === "check" ? "skipped" : "refused");
|
|
621
|
-
const who = { pr: req.pr, ...(req.user ? { user: req.user } : {}) };
|
|
698
|
+
const who = { pr: req.pr, ...(req.user ? { user: req.user } : {}), ...(req.arg !== undefined ? { arg: req.arg } : {}) };
|
|
622
699
|
if (req.user && i.forge?.userCanWrite && !(await i.forge.userCanWrite(req.user))) return no(`${req.user} cannot write to the repository, so ${s.name} does not run for them`, "refused", who);
|
|
623
700
|
|
|
624
701
|
let sha: string;
|
|
@@ -747,6 +824,13 @@ export async function runCommit(i: CommitRunInput): Promise<{ rc: string; change
|
|
|
747
824
|
writeFileSync(rcFile, "refused\n");
|
|
748
825
|
return { rc: "refused", changed: false };
|
|
749
826
|
}
|
|
827
|
+
let argv: string[];
|
|
828
|
+
try {
|
|
829
|
+
argv = commitArgv(i.settings, decision.arg);
|
|
830
|
+
} catch {
|
|
831
|
+
writeFileSync(rcFile, "refused\n");
|
|
832
|
+
return { rc: "refused", changed: false };
|
|
833
|
+
}
|
|
750
834
|
i.git(["worktree", "add", "--detach", "--force", i.workDir, decision.sha]);
|
|
751
835
|
if (i.settings.mergeBase) {
|
|
752
836
|
if (!decision.baseSha) {
|
|
@@ -762,7 +846,7 @@ export async function runCommit(i: CommitRunInput): Promise<{ rc: string; change
|
|
|
762
846
|
}
|
|
763
847
|
}
|
|
764
848
|
const env = commitCommandEnv(i.env, i.checkout, { names: i.settings.commandEnv, ...(decision.pr !== undefined ? { pr: decision.pr } : {}) });
|
|
765
|
-
const out = await i.runCommand(
|
|
849
|
+
const out = await i.runCommand(argv, { cwd: i.workDir, env, timeoutMs: i.settings.timeout * 60_000 });
|
|
766
850
|
const rc = out.timedOut ? "timeout" : out.exitCode === null ? "no-exit" : String(out.exitCode);
|
|
767
851
|
writeFileSync(rcFile, `${rc}\n`);
|
|
768
852
|
if (out.output) writeFileSync(join(i.dir, COMMIT_OUTPUT_FILE), out.output.slice(-COMMIT_OUTPUT_LIMIT));
|
|
@@ -772,6 +856,51 @@ export async function runCommit(i: CommitRunInput): Promise<{ rc: string; change
|
|
|
772
856
|
return { rc, changed: patch.length > 0 };
|
|
773
857
|
}
|
|
774
858
|
|
|
859
|
+
// ── the harness's BREAK switch (#4836) ─────────────────────────────────────
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* The push job's variable that turns one of land's checks off, for a BREAK
|
|
863
|
+
* arm of a product's e2e harness scenario: a comma list of
|
|
864
|
+
* {@link COMMIT_HARNESS_CHECKS}. It proves the check matters: with it off,
|
|
865
|
+
* the scenario's expectations must fail. Read only by `chant commit land`,
|
|
866
|
+
* and refused anywhere but chant's harness ({@link commitHarnessBreaks}).
|
|
867
|
+
* The command never sees it: `commandEnv` refuses every `CHANT_COMMIT_*`.
|
|
868
|
+
*/
|
|
869
|
+
export const COMMIT_HARNESS_BREAK_ENV = "CHANT_COMMIT_HARNESS_BREAK";
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* The checks the switch may turn off. `paths`: a change outside `allowed`
|
|
873
|
+
* and `allowedFiles` lands (a guarded path is still refused). `moved-base`:
|
|
874
|
+
* with `mergeBase`, a base that moved while the command ran lands the merge
|
|
875
|
+
* of the tip the command ran on.
|
|
876
|
+
*/
|
|
877
|
+
export const COMMIT_HARNESS_CHECKS = ["paths", "moved-base"] as const;
|
|
878
|
+
export type CommitHarnessCheck = (typeof COMMIT_HARNESS_CHECKS)[number];
|
|
879
|
+
|
|
880
|
+
/** The forge a job of chant's e2e harness reaches, `HARNESS_HOSTS.forgejo` (./e2e-harness/stack.ts). */
|
|
881
|
+
export const COMMIT_HARNESS_FORGE = "http://forgejo:3000";
|
|
882
|
+
|
|
883
|
+
const HARNESS_WORDS: Record<CommitHarnessCheck, string> = { paths: "the path check", "moved-base": "the moved-base check" };
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* The checks {@link COMMIT_HARNESS_BREAK_ENV} turns off, or why it is
|
|
887
|
+
* refused. It is read only in a BREAK arm of chant's e2e harness: `BREAK=1`,
|
|
888
|
+
* not GitLab, and a job whose `GITHUB_SERVER_URL` is the harness's Forgejo,
|
|
889
|
+
* {@link COMMIT_HARNESS_FORGE}. Unset or empty, no check is off.
|
|
890
|
+
*/
|
|
891
|
+
export function commitHarnessBreaks(env: Record<string, string | undefined>): { checks: CommitHarnessCheck[] } | { refused: string } {
|
|
892
|
+
const raw = env[COMMIT_HARNESS_BREAK_ENV]?.trim() ?? "";
|
|
893
|
+
if (raw === "") return { checks: [] };
|
|
894
|
+
const server = env.GITHUB_SERVER_URL?.replace(/\/+$/, "");
|
|
895
|
+
if (env.BREAK !== "1" || env.GITLAB_CI === "true" || server !== COMMIT_HARNESS_FORGE) {
|
|
896
|
+
return { refused: `${COMMIT_HARNESS_BREAK_ENV} is read only in a BREAK arm of chant's e2e harness (BREAK=1 on the harness's Forgejo, ${COMMIT_HARNESS_FORGE}), and this job is not one` };
|
|
897
|
+
}
|
|
898
|
+
const named = raw.split(",").map((c) => c.trim()).filter((c) => c !== "");
|
|
899
|
+
const bad = named.filter((c) => !(COMMIT_HARNESS_CHECKS as readonly string[]).includes(c));
|
|
900
|
+
if (bad.length > 0) return { refused: `${COMMIT_HARNESS_BREAK_ENV} names ${bad.join(", ")}; the checks it turns off are ${COMMIT_HARNESS_CHECKS.join(" and ")}` };
|
|
901
|
+
return { checks: [...new Set(named)] as CommitHarnessCheck[] };
|
|
902
|
+
}
|
|
903
|
+
|
|
775
904
|
// ── commit land ────────────────────────────────────────────────────────────
|
|
776
905
|
|
|
777
906
|
/**
|
|
@@ -888,16 +1017,27 @@ export async function landCommitChange(i: CommitLandInput): Promise<CommitLandOu
|
|
|
888
1017
|
const req = await resolveCommitRequest(i.words, s, i.env, i.event, i.forge);
|
|
889
1018
|
if ("refused" in req) return finish({ result: s.on === "check" ? "skipped" : "refused", reason: req.refused });
|
|
890
1019
|
({ pr, user } = req);
|
|
1020
|
+
// #4836: a BREAK arm of the harness may turn a check off; anywhere else the switch fails the land.
|
|
1021
|
+
const harness = commitHarnessBreaks(i.env);
|
|
1022
|
+
if ("refused" in harness) return finish({ result: "failed", reason: harness.refused }, `${harness.refused}, so nothing was pushed.`);
|
|
1023
|
+
const off = new Set(harness.checks);
|
|
891
1024
|
const decision = readCommitDecision(i.dir);
|
|
892
|
-
if (!decision || decision.name !== s.name || decision.on !== s.on || (decision.pr !== undefined && decision.pr !== pr)) {
|
|
1025
|
+
if (!decision || decision.name !== s.name || decision.on !== s.on || (decision.pr !== undefined && decision.pr !== pr) || (decision.go && decision.arg !== req.arg)) {
|
|
893
1026
|
return finish({ result: "failed", reason: "the commit job left no decision this job can read" }, "the commit job left nothing to land, so nothing was pushed.");
|
|
894
1027
|
}
|
|
895
1028
|
if (!decision.go) return finish({ result: decision.stop ?? "refused", reason: decision.reason ?? "refused" }, `${decision.reason ?? `${s.name} did not run`}, so nothing was pushed.`);
|
|
1029
|
+
// What ran, as the replies and the commit name it: the command with the comment's argument (#4820).
|
|
1030
|
+
let ranArgv: string;
|
|
1031
|
+
try {
|
|
1032
|
+
ranArgv = commitArgv(s, req.arg).join(" ");
|
|
1033
|
+
} catch (e) {
|
|
1034
|
+
return finish({ result: "refused", reason: errText(e) }, `${errText(e)}, so nothing was pushed.`);
|
|
1035
|
+
}
|
|
896
1036
|
const rc = readSmall(join(i.dir, COMMIT_RC_FILE))?.trim() ?? "";
|
|
897
1037
|
if (rc === "conflict") {
|
|
898
1038
|
return finish({ result: "refused", reason: `merging ${decision.base ?? "the base"} into the head conflicts` }, `merging ${code(decision.base ?? "the base")} into the ${what} conflicts, so ${s.name} did not run and nothing was pushed. Resolve the conflict on the branch.`);
|
|
899
1039
|
}
|
|
900
|
-
if (rc === "timeout") return finish({ result: "stopped", reason: `the command passed its ${s.timeout} minute limit` }, `${code(
|
|
1040
|
+
if (rc === "timeout") return finish({ result: "stopped", reason: `the command passed its ${s.timeout} minute limit` }, `${code(ranArgv)} was stopped at its ${s.timeout} minute limit, so nothing was pushed.`);
|
|
901
1041
|
if (rc !== "0" && /^[0-9]+$/.test(rc) && i.refusalReply) {
|
|
902
1042
|
let said: string | undefined;
|
|
903
1043
|
try {
|
|
@@ -907,7 +1047,7 @@ export async function landCommitChange(i: CommitLandInput): Promise<CommitLandOu
|
|
|
907
1047
|
}
|
|
908
1048
|
if (said) return finish({ result: "refused", reason: `the command refused, exiting ${rc}` }, `${said.trim()} Nothing was pushed.`);
|
|
909
1049
|
}
|
|
910
|
-
if (rc !== "0") return finish({ result: "failed", reason: `the command exited ${rc || "with no code"}` }, `${code(
|
|
1050
|
+
if (rc !== "0") return finish({ result: "failed", reason: `the command exited ${rc || "with no code"}` }, `${code(ranArgv)} stopped with ${rc ? `exit code ${rc}` : "no exit code"}, so nothing was pushed. The commit job's log has its output.`);
|
|
911
1051
|
|
|
912
1052
|
const head = await i.forge.pullRequestHead?.(pr!).catch(() => undefined);
|
|
913
1053
|
if (!head || !head.open || !head.sameRepo || !branchOk(head.branch)) return finish({ result: "refused", reason: `#${pr} is not an open ${what} from this repository` }, `#${pr} is not an open ${what} from this repository, so nothing was pushed.`);
|
|
@@ -928,7 +1068,11 @@ export async function landCommitChange(i: CommitLandInput): Promise<CommitLandOu
|
|
|
928
1068
|
} catch (e) {
|
|
929
1069
|
return finish({ result: "failed", reason: `could not fetch ${target} (${errText(e)})` });
|
|
930
1070
|
}
|
|
931
|
-
if (baseSha !== decision.baseSha)
|
|
1071
|
+
if (baseSha !== decision.baseSha) {
|
|
1072
|
+
if (!off.has("moved-base")) return finish({ result: s.on === "check" ? "skipped" : "refused", reason: "the base moved" }, `${code(target)} moved while ${s.name} ran, so nothing was pushed. Ask again.`);
|
|
1073
|
+
// BREAK: land the merge of the tip the command ran on, which the check exists to stop.
|
|
1074
|
+
baseSha = decision.baseSha;
|
|
1075
|
+
}
|
|
932
1076
|
}
|
|
933
1077
|
|
|
934
1078
|
// The limit and the approval again, on this job's own read.
|
|
@@ -945,7 +1089,7 @@ export async function landCommitChange(i: CommitLandInput): Promise<CommitLandOu
|
|
|
945
1089
|
|
|
946
1090
|
const patch = join(i.dir, COMMIT_PATCH_FILE);
|
|
947
1091
|
const nothing = (): Promise<CommitLandOutcome> =>
|
|
948
|
-
finish({ result: s.on === "check" ? "skipped" : "refused", reason: "the command changed nothing" }, `${code(
|
|
1092
|
+
finish({ result: s.on === "check" ? "skipped" : "refused", reason: "the command changed nothing" }, `${code(ranArgv)} changed nothing, so nothing was pushed.`);
|
|
949
1093
|
if (!existsSync(patch) || statSync(patch).size === 0) return nothing();
|
|
950
1094
|
let paths: string[];
|
|
951
1095
|
try {
|
|
@@ -966,17 +1110,19 @@ export async function landCommitChange(i: CommitLandInput): Promise<CommitLandOu
|
|
|
966
1110
|
return finish({ result: "refused", reason: `the patch does not apply to ${sha.slice(0, 8)}` }, `the change does not apply to ${sha.slice(0, 8)} (${errText(e)}), so nothing was pushed.`);
|
|
967
1111
|
}
|
|
968
1112
|
if (paths.length === 0) return nothing();
|
|
969
|
-
const
|
|
1113
|
+
const refusedPaths = commitRefusedPaths(paths, s);
|
|
1114
|
+
const forbidden = refusedPaths.forbidden;
|
|
1115
|
+
const outside = off.has("paths") ? [] : refusedPaths.outside;
|
|
970
1116
|
if (forbidden.length > 0 || outside.length > 0) {
|
|
971
1117
|
const bad = [...new Set([...forbidden, ...outside])];
|
|
972
1118
|
return finish(
|
|
973
1119
|
{ result: "refused", reason: `the change touches ${bad.join(", ")}`, paths },
|
|
974
|
-
`${code(
|
|
1120
|
+
`${code(ranArgv)} changed ${bad.map(code).join(", ")}, which ${s.name} may not change (it may change ${[...s.allowed, ...s.allowedFiles].map(code).join(", ")}, and never CI, chant's settings and state, code owners, agent instructions or git settings), so nothing was pushed.`,
|
|
975
1121
|
);
|
|
976
1122
|
}
|
|
977
1123
|
|
|
978
|
-
const title = s.on === "comment" ? `${s.comment} asked for by ${user} on ${what} #${pr}` : `${s.name} after the check found something at ${sha.slice(0, 8)}`;
|
|
979
|
-
const ran = baseSha ? `Merged ${decision.base} at ${baseSha.slice(0, 12)} into ${sha.slice(0, 12)}, then ran ${
|
|
1124
|
+
const title = s.on === "comment" ? `${s.comment}${req.arg !== undefined ? ` ${req.arg}` : ""} asked for by ${user} on ${what} #${pr}` : `${s.name} after the check found something at ${sha.slice(0, 8)}`;
|
|
1125
|
+
const ran = baseSha ? `Merged ${decision.base} at ${baseSha.slice(0, 12)} into ${sha.slice(0, 12)}, then ran ${ranArgv}.` : `Ran ${ranArgv} on ${sha.slice(0, 12)}.`;
|
|
980
1126
|
const message = [title, "", ran, "", ...(user ? [`Requested-by: ${user}`] : []), `${COMMIT_TRAILER}: ${s.name}`, ""].join("\n");
|
|
981
1127
|
let commitSha: string;
|
|
982
1128
|
try {
|
|
@@ -991,10 +1137,11 @@ export async function landCommitChange(i: CommitLandInput): Promise<CommitLandOu
|
|
|
991
1137
|
} catch (e) {
|
|
992
1138
|
return finish({ result: "failed", reason: `could not push to ${head.branch} (${errText(e)})`, commit: commitSha }, `could not push to ${code(head.branch)} (${errText(e)}), so nothing was pushed.`);
|
|
993
1139
|
}
|
|
1140
|
+
const breakNote = off.size > 0 ? ` (BREAK: ${[...off].map((c) => HARNESS_WORDS[c]).join(" and ")} ${off.size === 1 ? "was" : "were"} off)` : "";
|
|
994
1141
|
const voided = approved ? ` The plan of ${code(sha.slice(0, 8))} was approved by ${approved}; the new commit is planned again and needs approval again.` : "";
|
|
995
1142
|
return finish(
|
|
996
|
-
{ result: "pushed", reason: `pushed ${commitSha} to ${head.branch}`, commit: commitSha, paths, ...(approved ? { approvalVoided: approved } : {}) },
|
|
997
|
-
`pushed ${code(commitSha.slice(0, 8))} to ${code(head.branch)}${user ? ` for ${user}` : ""}, from ${baseSha ? `a merge of ${code(decision.base!)} and ` : ""}${code(
|
|
1143
|
+
{ result: "pushed", reason: `pushed ${commitSha} to ${head.branch}${breakNote}`, commit: commitSha, paths, ...(approved ? { approvalVoided: approved } : {}) },
|
|
1144
|
+
`pushed ${code(commitSha.slice(0, 8))} to ${code(head.branch)}${user ? ` for ${user}` : ""}, from ${baseSha ? `a merge of ${code(decision.base!)} and ` : ""}${code(ranArgv)}, changing ${paths.map(code).join(", ")}.${voided} Nothing was applied, approved or merged.${breakNote}`,
|
|
998
1145
|
);
|
|
999
1146
|
}
|
|
1000
1147
|
|