@intentius/chant 0.124.87 → 0.124.88
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/action-pins.d.ts +1 -0
- package/dist/action-pins.d.ts.map +1 -1
- package/dist/action-pins.js +2 -0
- package/dist/actor.d.ts +12 -0
- package/dist/actor.d.ts.map +1 -0
- package/dist/actor.js +18 -0
- package/dist/bundle-check.d.ts +20 -5
- package/dist/bundle-check.d.ts.map +1 -1
- package/dist/bundle-check.js +20 -5
- package/dist/chant-install.d.ts +98 -0
- package/dist/chant-install.d.ts.map +1 -1
- package/dist/chant-install.js +204 -2
- package/dist/ci-commit.d.ts +1 -1
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +1 -2
- package/dist/ci-control.d.ts +1 -1
- package/dist/ci-control.d.ts.map +1 -1
- package/dist/ci-control.js +1 -1
- package/dist/ci-evidence-claims.d.ts +59 -0
- package/dist/ci-evidence-claims.d.ts.map +1 -0
- package/dist/ci-evidence-claims.js +87 -0
- package/dist/ci-evidence-from-job.d.ts +103 -0
- package/dist/ci-evidence-from-job.d.ts.map +1 -0
- package/dist/ci-evidence-from-job.js +162 -0
- package/dist/ci-evidence-jobs.d.ts +39 -4
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +38 -4
- package/dist/ci-handover.d.ts +12 -0
- package/dist/ci-handover.d.ts.map +1 -1
- package/dist/ci-handover.js +15 -3
- package/dist/ci-identity.d.ts +32 -6
- package/dist/ci-identity.d.ts.map +1 -1
- package/dist/ci-identity.js +40 -8
- package/dist/ci-image.d.ts +47 -9
- package/dist/ci-image.d.ts.map +1 -1
- package/dist/ci-image.js +45 -18
- package/dist/ci-jobs.d.ts +1 -1
- package/dist/ci-jobs.d.ts.map +1 -1
- package/dist/ci-jobs.js +7 -2
- package/dist/ci-login.d.ts +75 -13
- package/dist/ci-login.d.ts.map +1 -1
- package/dist/ci-login.js +89 -37
- package/dist/ci-product-words.d.ts +20 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +27 -1
- package/dist/ci-product.d.ts +21 -2
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +21 -2
- package/dist/cli/handlers/approve-confirm.d.ts +14 -0
- package/dist/cli/handlers/approve-confirm.d.ts.map +1 -1
- package/dist/cli/handlers/approve-confirm.js +46 -0
- package/dist/cli/handlers/build.d.ts +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +22 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +21 -1
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +227 -18
- package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-forge-check.js +34 -17
- package/dist/cli/handlers/generated-check.d.ts +3 -0
- package/dist/cli/handlers/generated-check.d.ts.map +1 -0
- package/dist/cli/handlers/generated-check.js +41 -0
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +3 -0
- package/dist/cli/handlers/local-chant.d.ts +13 -0
- package/dist/cli/handlers/local-chant.d.ts.map +1 -1
- package/dist/cli/handlers/local-chant.js +42 -1
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +42 -5
- package/dist/cli/handlers/run-wave.js +8 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +38 -4
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +66 -0
- package/dist/cli/registry.d.ts +24 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/check-hooks.d.ts +10 -0
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-hooks.js +18 -0
- package/dist/components/pr-checks.d.ts +105 -0
- package/dist/components/pr-checks.d.ts.map +1 -0
- package/dist/components/pr-checks.js +119 -0
- package/dist/components/pr-pipeline.d.ts +34 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +14 -1
- package/dist/components/product-pipeline.d.ts +16 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +17 -2
- package/dist/components/product-plan.d.ts +257 -4
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +241 -11
- package/dist/config.d.ts +10 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +11 -6
- package/dist/control/consumers.d.ts +6 -0
- package/dist/control/consumers.d.ts.map +1 -1
- package/dist/control/consumers.js +6 -0
- package/dist/dead-guards.d.ts.map +1 -1
- package/dist/dead-guards.js +9 -6
- package/dist/discovery/files.d.ts +1 -1
- package/dist/discovery/files.js +1 -1
- package/dist/drift-issue.d.ts +20 -3
- package/dist/drift-issue.d.ts.map +1 -1
- package/dist/drift-issue.js +16 -0
- package/dist/drift-record.d.ts +45 -5
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +27 -6
- package/dist/floor-table.d.ts +6 -6
- package/dist/floor-table.d.ts.map +1 -1
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +58 -21
- package/dist/floor-table.js +10 -7
- package/dist/forge-check/contract.d.ts +8 -0
- package/dist/forge-check/contract.d.ts.map +1 -1
- package/dist/forge-check/contract.js +4 -1
- package/dist/forge-check/index.d.ts +2 -0
- package/dist/forge-check/index.d.ts.map +1 -1
- package/dist/forge-check/index.js +2 -0
- package/dist/forge-flags.d.ts +10 -0
- package/dist/forge-flags.d.ts.map +1 -1
- package/dist/forge-flags.js +31 -0
- package/dist/forge-remote.d.ts +47 -0
- package/dist/forge-remote.d.ts.map +1 -0
- package/dist/forge-remote.js +69 -0
- package/dist/generated-check.d.ts +74 -0
- package/dist/generated-check.d.ts.map +1 -0
- package/dist/generated-check.js +216 -0
- package/dist/lexicon.d.ts +16 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.d.ts +15 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +49 -3
- package/dist/lifecycle/release-images.d.ts +22 -1
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +27 -3
- package/dist/lifecycle/release-ledger.d.ts +4 -3
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- package/dist/lifecycle/release-ledger.js +3 -2
- package/dist/local-chant.d.ts +57 -3
- package/dist/local-chant.d.ts.map +1 -1
- package/dist/local-chant.js +122 -13
- package/dist/op/op-waves-evidence-jobs.d.ts +92 -0
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -0
- package/dist/op/op-waves-evidence-jobs.js +112 -0
- package/dist/op/op-waves-evidence.d.ts +12 -1
- package/dist/op/op-waves-evidence.d.ts.map +1 -1
- package/dist/op/op-waves-evidence.js +23 -2
- package/dist/op/op-waves-run.d.ts +12 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +54 -3
- package/dist/op/op-waves.d.ts +8 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +10 -0
- package/dist/op/schedule-overdue.d.ts +39 -2
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +89 -7
- package/dist/pr-forge-reads.d.ts +21 -1
- package/dist/pr-forge-reads.d.ts.map +1 -1
- package/dist/pr-forge-reads.js +19 -1
- package/dist/pr-forge.d.ts +7 -1
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +7 -2
- package/dist/pr-plan-note.d.ts +24 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +11 -1
- package/dist/pr-plan-record.d.ts +47 -0
- package/dist/pr-plan-record.d.ts.map +1 -0
- package/dist/pr-plan-record.js +89 -0
- package/dist/pr-post.d.ts +40 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +79 -6
- package/dist/pr-requires.d.ts +8 -0
- package/dist/pr-requires.d.ts.map +1 -1
- package/dist/pr-requires.js +3 -1
- package/dist/ref-gate-init.d.ts +76 -0
- package/dist/ref-gate-init.d.ts.map +1 -0
- package/dist/ref-gate-init.js +144 -0
- package/dist/ref-gate-rules.d.ts +19 -0
- package/dist/ref-gate-rules.d.ts.map +1 -0
- package/dist/ref-gate-rules.js +17 -0
- package/dist/release-floors.d.ts +64 -16
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +65 -17
- package/dist/state-migration.d.ts +24 -1
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +39 -3
- package/dist/state-unlock.d.ts +32 -1
- package/dist/state-unlock.d.ts.map +1 -1
- package/dist/state-unlock.js +31 -0
- package/dist/wave-runtime.mjs +292 -285
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +13 -7
- package/dist/workspace/drift-cli.d.ts +1 -1
- package/dist/workspace/drift-cli.d.ts.map +1 -1
- package/dist/workspace/drift-cli.js +5 -12
- package/dist/workspace/forge-work.d.ts +3 -2
- package/dist/workspace/forge-work.d.ts.map +1 -1
- package/dist/workspace/forge-work.js +7 -17
- package/dist/workspace/lexicon-outputs.js +2 -2
- package/dist/workspace/release-workflow.d.ts +26 -3
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +48 -6
- package/dist/workspace/trust/check-evidence-report.d.ts +18 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +13 -0
- package/dist/workspace/trust/check-evidence.d.ts +13 -1
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence.js +8 -3
- package/dist/workspace/trust/evidence.d.ts +5 -0
- package/dist/workspace/trust/evidence.d.ts.map +1 -1
- package/dist/workspace/trust/evidence.js +5 -0
- package/dist/workspace/trust/open-evidence.d.ts +67 -0
- package/dist/workspace/trust/open-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/open-evidence.js +92 -0
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate-cli.js +65 -3
- package/dist/workspace/trust/ref-gate.d.ts +61 -2
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate.js +72 -7
- package/package.json +1 -1
- package/src/action-pins.ts +2 -0
- package/src/actor.test.ts +12 -0
- package/src/actor.ts +19 -0
- package/src/bundle-check.test.ts +22 -0
- package/src/bundle-check.ts +33 -5
- package/src/chant-install.test.ts +109 -1
- package/src/chant-install.ts +243 -2
- package/src/ci-commit.test.ts +51 -5
- package/src/ci-commit.ts +1 -2
- package/src/ci-control.ts +1 -0
- package/src/ci-evidence-claims.ts +102 -0
- package/src/ci-evidence-from-job.test.ts +147 -0
- package/src/ci-evidence-from-job.ts +195 -0
- package/src/ci-evidence-jobs.ts +41 -4
- package/src/ci-handover.ts +16 -3
- package/src/ci-identity.test.ts +3 -3
- package/src/ci-identity.ts +51 -11
- package/src/ci-image.test.ts +60 -10
- package/src/ci-image.ts +78 -19
- package/src/ci-jobs.ts +7 -2
- package/src/ci-login.test.ts +131 -3
- package/src/ci-login.token-drop.test.ts +204 -0
- package/src/ci-login.ts +137 -39
- package/src/ci-product-words.ts +30 -0
- package/src/ci-product.ts +26 -1
- package/src/cli/commands/__fixtures__/source-dir-root/migrations/0001-init/backfill.ts +3 -0
- package/src/cli/handlers/approve-confirm.test.ts +35 -0
- package/src/cli/handlers/approve-confirm.ts +44 -0
- package/src/cli/handlers/build-source-dir.test.ts +4 -0
- package/src/cli/handlers/build.ts +20 -2
- package/src/cli/handlers/ci-check.ts +19 -1
- package/src/cli/handlers/ci-evidence-open.test.ts +164 -0
- package/src/cli/handlers/ci-evidence.ts +210 -16
- package/src/cli/handlers/ci-forge-check.ts +22 -9
- package/src/cli/handlers/generated-check.ts +39 -0
- package/src/cli/handlers/lifecycle.test.ts +20 -0
- package/src/cli/handlers/lifecycle.ts +4 -0
- package/src/cli/handlers/local-chant.ts +39 -1
- package/src/cli/handlers/pr.ts +43 -5
- package/src/cli/handlers/run-wave.ts +7 -0
- package/src/cli/main.ts +38 -4
- package/src/cli/parse-args.ts +46 -0
- package/src/cli/registry.ts +24 -0
- package/src/components/check-hooks.ts +22 -0
- package/src/components/check-report-summary.test.ts +78 -0
- package/src/components/pr-checks.ts +159 -0
- package/src/components/pr-pipeline.ts +41 -1
- package/src/components/product-pipeline.ts +25 -3
- package/src/components/product-plan.test.ts +102 -1
- package/src/components/product-plan.ts +416 -15
- package/src/config.ts +13 -8
- package/src/control/consumers.ts +7 -0
- package/src/dead-guards.test.ts +27 -5
- package/src/dead-guards.ts +9 -6
- package/src/discovery/files.ts +1 -1
- package/src/drift-issue.test.ts +29 -1
- package/src/drift-issue.ts +28 -3
- package/src/drift-record.test.ts +25 -0
- package/src/drift-record.ts +55 -6
- package/src/floor-table.data.ts +58 -21
- package/src/floor-table.ts +12 -9
- package/src/forge-check/contract.ts +11 -1
- package/src/forge-check/forge-check.test.ts +8 -0
- package/src/forge-check/index.ts +2 -0
- package/src/forge-flags.test.ts +25 -1
- package/src/forge-flags.ts +34 -0
- package/src/forge-remote.test.ts +37 -0
- package/src/forge-remote.ts +79 -0
- package/src/generated-check.e2e.test.ts +98 -0
- package/src/generated-check.test.ts +104 -0
- package/src/generated-check.ts +269 -0
- package/src/lexicon.ts +17 -0
- package/src/lifecycle/publish-npm.ts +56 -3
- package/src/lifecycle/release-catalog.test.ts +2 -2
- package/src/lifecycle/release-images-dockerfile.test.ts +20 -0
- package/src/lifecycle/release-images.test.ts +44 -0
- package/src/lifecycle/release-images.ts +39 -3
- package/src/lifecycle/release-ledger.ts +4 -3
- package/src/local-chant.e2e.test.ts +81 -6
- package/src/local-chant.test.ts +22 -3
- package/src/local-chant.ts +130 -13
- package/src/op/op-waves-evidence-jobs.ts +134 -0
- package/src/op/op-waves-evidence.test.ts +36 -3
- package/src/op/op-waves-evidence.ts +23 -3
- package/src/op/op-waves-run.ts +57 -2
- package/src/op/op-waves.ts +11 -0
- package/src/op/schedule-overdue.test.ts +83 -1
- package/src/op/schedule-overdue.ts +107 -9
- package/src/pr-forge-reads-compare.test.ts +2 -1
- package/src/pr-forge-reads.ts +37 -1
- package/src/pr-forge.ts +14 -3
- package/src/pr-plan-note.ts +32 -3
- package/src/pr-plan-record.test.ts +75 -0
- package/src/pr-plan-record.ts +101 -0
- package/src/pr-post-plan-note.test.ts +60 -0
- package/src/pr-post.test.ts +30 -0
- package/src/pr-post.ts +110 -6
- package/src/pr-requires.test.ts +20 -0
- package/src/pr-requires.ts +10 -1
- package/src/ref-gate-init.ts +189 -0
- package/src/ref-gate-rules.ts +26 -0
- package/src/release-floors.ts +86 -17
- package/src/state-migration-record.test.ts +90 -0
- package/src/state-migration.test.ts +1 -1
- package/src/state-migration.ts +52 -3
- package/src/state-unlock.test.ts +33 -1
- package/src/state-unlock.ts +49 -1
- package/src/workspace/ci-green-cli.ts +12 -6
- package/src/workspace/drift-cli.ts +6 -18
- package/src/workspace/forge-work.ts +7 -14
- package/src/workspace/lexicon-outputs.ts +2 -2
- package/src/workspace/release-workflow.test.ts +70 -0
- package/src/workspace/release-workflow.ts +56 -8
- package/src/workspace/trust/check-evidence-report.ts +24 -0
- package/src/workspace/trust/check-evidence.ts +17 -5
- package/src/workspace/trust/evidence.ts +5 -0
- package/src/workspace/trust/open-evidence.ts +129 -0
- package/src/workspace/trust/ref-gate-cli.ts +59 -3
- package/src/workspace/trust/ref-gate-pieces.test.ts +175 -0
- package/src/workspace/trust/ref-gate.e2e.test.ts +17 -0
- package/src/workspace/trust/ref-gate.ts +87 -6
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4899: the product plan job's run record, written by the plan step's
|
|
3
|
+
* record line and read back as data by the note job; and #4935's pull
|
|
4
|
+
* request loop flags.
|
|
5
|
+
*/
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { describe, expect, test } from "vitest";
|
|
11
|
+
import { PLAN_RECORD_JS, PLAN_RUN_RECORD_ENV, planVerbLines } from "./components/product-plan";
|
|
12
|
+
import { PLAN_RUN_RECORD_FILE, readPlanRunRecord } from "./pr-plan-record";
|
|
13
|
+
import { prLoopFlagsProblem } from "./cli/handlers/build";
|
|
14
|
+
import { prCheckJob, PR_CHECK_REPORT_DIR, prRefGateJob } from "./components/pr-checks";
|
|
15
|
+
import { CHECK_HOOKS_DIR } from "./components/check-hooks";
|
|
16
|
+
|
|
17
|
+
const HEAD = "a".repeat(40);
|
|
18
|
+
const config = JSON.stringify({ op: "pr-plan", env: "prod", labels: { Env: "prod", Pipeline: "pr", Job: "plan", Target: "staging" } });
|
|
19
|
+
|
|
20
|
+
function written(exit: number): string {
|
|
21
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-plan-record-"));
|
|
22
|
+
execFileSync(process.execPath, ["-e", PLAN_RECORD_JS, dir], { cwd: dir, env: { ...process.env, [PLAN_RUN_RECORD_ENV]: config, CHANT_PLAN_EXIT: String(exit), CHANT_PLAN_STARTED: "2026-11-10T00:00:00Z" } });
|
|
23
|
+
return dir;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("the product plan job's run record (#4899)", () => {
|
|
27
|
+
test("the record line writes a record the note job keeps, its op, commit and origin its own", () => {
|
|
28
|
+
const dir = written(0);
|
|
29
|
+
const raw = JSON.parse(readFileSync(join(dir, PLAN_RUN_RECORD_FILE), "utf-8"));
|
|
30
|
+
expect(raw).toMatchObject({ op: "pr-plan", env: "prod", status: "ok", started: "2026-11-10T00:00:00.000Z" });
|
|
31
|
+
const read = readPlanRunRecord(dir, { env: "prod", head: HEAD, target: "staging", result: "success", origin: { forge: "github", jobId: "plan-staging" } });
|
|
32
|
+
expect(read && "record" in read ? read.record : read).toMatchObject({ id: raw.id, op: "pr-plan", status: "ok", gitSha: HEAD, runOrigin: { forge: "github", jobId: "plan-staging" }, labels: { Target: "staging" } });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("a failed verb, or a failed job, records a failed run", () => {
|
|
36
|
+
const failed = readPlanRunRecord(written(3), { env: "prod", head: HEAD, target: "staging" });
|
|
37
|
+
expect(failed && "record" in failed ? failed.record.failure : failed).toEqual({ code: "command-failed", reason: "the plan verb exited 3", phase: "plan", exitCode: 3 });
|
|
38
|
+
const job = readPlanRunRecord(written(0), { env: "prod", head: HEAD, target: "staging", result: "failure" });
|
|
39
|
+
expect(job && "record" in job ? job.record.status : job).toBe("fail");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("a record for another environment, target or commit is refused, and none is undefined", () => {
|
|
43
|
+
const dir = written(0);
|
|
44
|
+
expect(readPlanRunRecord(dir, { env: "dev", head: HEAD, target: "staging" })).toEqual({ refused: expect.stringMatching(/environment "prod", not dev/) });
|
|
45
|
+
expect(readPlanRunRecord(dir, { env: "prod", head: HEAD })).toEqual({ refused: expect.stringMatching(/target "staging"/) });
|
|
46
|
+
const forged = JSON.parse(readFileSync(join(dir, PLAN_RUN_RECORD_FILE), "utf-8"));
|
|
47
|
+
writeFileSync(join(dir, PLAN_RUN_RECORD_FILE), JSON.stringify({ ...forged, gitSha: "b".repeat(40) }));
|
|
48
|
+
expect(readPlanRunRecord(dir, { env: "prod", head: HEAD, target: "staging" })).toEqual({ refused: expect.stringMatching(/commit/) });
|
|
49
|
+
expect(readPlanRunRecord(mkdtempSync(join(tmpdir(), "chant-plan-record-")), { env: "prod", head: HEAD })).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("the plan step's lines: the verb alone without record or report", () => {
|
|
53
|
+
expect(planVerbLines({ command: "yodel plan" })).toEqual(["yodel plan"]);
|
|
54
|
+
const lines = planVerbLines({ command: "yodel plan", record: { env: {} } });
|
|
55
|
+
expect(lines[0]).toMatch(/^chant_plan_started=/);
|
|
56
|
+
expect(lines.at(-1)).toBe('[ "$chant_plan_exit" -eq 0 ] || exit "$chant_plan_exit"');
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("the pull request loop's evidence, check and ref gate flags (#4935)", () => {
|
|
61
|
+
test("they need --pr-loop and one runner identity", () => {
|
|
62
|
+
expect(prLoopFlagsProblem({ checkJob: true })).toMatch(/--check-job .*needs --pr-loop/);
|
|
63
|
+
expect(prLoopFlagsProblem({ prLoop: true, evidenceRunnerKeySecret: "K", evidenceIdentity: "oidc" })).toMatch(/give one of them/);
|
|
64
|
+
expect(prLoopFlagsProblem({ prLoop: true, evidenceAudience: "x" })).toMatch(/goes with --evidence-identity oidc/);
|
|
65
|
+
expect(prLoopFlagsProblem({ prLoop: true, evidenceRunnerKeySecret: "1K" })).toMatch(/secret name/);
|
|
66
|
+
expect(prLoopFlagsProblem({ prLoop: true, evidenceIdentity: "oidc", evidenceAudience: "sigstore", checkJob: true, refGateStatus: true })).toBeUndefined();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("the descriptors: the check report directory is ci check's, and the gate's branch is checked", () => {
|
|
70
|
+
expect(PR_CHECK_REPORT_DIR).toBe(CHECK_HOOKS_DIR);
|
|
71
|
+
expect(prCheckJob("github").evidence).toBeUndefined();
|
|
72
|
+
expect(() => prCheckJob("github", { evidence: { runnerKeySecret: "not a name" } })).toThrow(/secret name/);
|
|
73
|
+
expect(() => prRefGateJob("github", { branch: "a b" })).toThrow(/not a branch name/);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A product plan job's run record (#4899), as the note job reads it from the
|
|
3
|
+
* hand-off and keeps it on `chant/lifecycle`.
|
|
4
|
+
*
|
|
5
|
+
* `chant ci run plan --in-place` records a `pr-plan` job as Op `pr-plan` in
|
|
6
|
+
* the run ledger (`<env>/runs__pr-plan.jsonl`). A product's plan verb runs
|
|
7
|
+
* without `ci run`, and its plan job holds no token to push with, so its plan
|
|
8
|
+
* step writes the record into `.chant/pr/run-record.json`
|
|
9
|
+
* (`PLAN_RECORD_JS` in ./components/product-plan.ts) and the note job,
|
|
10
|
+
* which holds the token, appends it (`pr-post --record-run <plan job>`).
|
|
11
|
+
*
|
|
12
|
+
* The record is the change's: the plan job runs its code. So it is read as
|
|
13
|
+
* data, as the report is (./pr-post.ts). The note job keeps the record's id,
|
|
14
|
+
* its times and the plan verb's exit code, and fills the op, environment,
|
|
15
|
+
* labels, commit, run origin and status from what it knows itself. A record
|
|
16
|
+
* that names another op, environment, target or commit is refused, and a
|
|
17
|
+
* plan job that failed records a failed run whatever the record says.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import type { OpRunRecordInput } from "./op/runtime";
|
|
23
|
+
import type { RunOrigin } from "./lifecycle/release-ledger";
|
|
24
|
+
|
|
25
|
+
/** The record's file under the hand-off directory: `PLAN_RUN_RECORD_FILE` in ./components/product-plan.ts. */
|
|
26
|
+
export const PLAN_RUN_RECORD_FILE = "run-record.json";
|
|
27
|
+
|
|
28
|
+
/** The op a product plan job's run is recorded under: `pr-plan`'s. */
|
|
29
|
+
export const PLAN_RUN_OP = "pr-plan";
|
|
30
|
+
|
|
31
|
+
/** What the note job knows of the plan job it records. */
|
|
32
|
+
export interface PlanRunExpect {
|
|
33
|
+
/** The pipeline's environment, `--env`. */
|
|
34
|
+
env: string;
|
|
35
|
+
/** The commit the plan job checked out, `--head`. */
|
|
36
|
+
head: string;
|
|
37
|
+
/** The target, `--member`. */
|
|
38
|
+
target?: string;
|
|
39
|
+
/** The plan job's result as the forge says it (`needs.<job>.result`, GitLab's job status). */
|
|
40
|
+
result?: string;
|
|
41
|
+
/** The plan job's run, as the note job names it. */
|
|
42
|
+
origin?: RunOrigin;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
46
|
+
const SHA = /^[0-9a-f]{40}$/;
|
|
47
|
+
|
|
48
|
+
function instant(v: unknown): string | undefined {
|
|
49
|
+
return typeof v === "string" && v.length <= 40 && Number.isFinite(Date.parse(v)) ? new Date(Date.parse(v)).toISOString() : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The run record to keep for the plan job, read from `dir`, or why it is
|
|
54
|
+
* refused; undefined when the plan job wrote none.
|
|
55
|
+
*/
|
|
56
|
+
export function readPlanRunRecord(dir: string, expect: PlanRunExpect): { record: OpRunRecordInput } | { refused: string } | undefined {
|
|
57
|
+
const file = join(dir, PLAN_RUN_RECORD_FILE);
|
|
58
|
+
if (!existsSync(file)) return undefined;
|
|
59
|
+
let doc: unknown;
|
|
60
|
+
try {
|
|
61
|
+
doc = JSON.parse(readFileSync(file, "utf-8"));
|
|
62
|
+
} catch (err) {
|
|
63
|
+
return { refused: `the run record does not read: ${err instanceof Error ? err.message : String(err)}` };
|
|
64
|
+
}
|
|
65
|
+
if (!doc || typeof doc !== "object" || Array.isArray(doc)) return { refused: "the run record is not an object" };
|
|
66
|
+
const r = doc as Record<string, unknown>;
|
|
67
|
+
if (typeof r.id !== "string" || !ID.test(r.id)) return { refused: "the run record's id is not a UUID" };
|
|
68
|
+
if (r.op !== PLAN_RUN_OP) return { refused: `the run record is for op ${JSON.stringify(r.op)}, not ${PLAN_RUN_OP}` };
|
|
69
|
+
if (r.env !== expect.env) return { refused: `the run record is for environment ${JSON.stringify(r.env)}, not ${expect.env}` };
|
|
70
|
+
const labels = r.labels && typeof r.labels === "object" && !Array.isArray(r.labels) ? (r.labels as Record<string, unknown>) : {};
|
|
71
|
+
if ((labels.Target ?? undefined) !== expect.target) return { refused: `the run record is for target ${JSON.stringify(labels.Target ?? null)}, not ${JSON.stringify(expect.target ?? null)}` };
|
|
72
|
+
if (r.gitSha !== undefined && r.gitSha !== expect.head) return { refused: `the run record is for commit ${JSON.stringify(r.gitSha)}, not ${expect.head}` };
|
|
73
|
+
if (!SHA.test(expect.head)) return { refused: `the head ${JSON.stringify(expect.head)} is not a full commit` };
|
|
74
|
+
const started = instant(r.started);
|
|
75
|
+
const ended = instant(r.ended);
|
|
76
|
+
if (!started || !ended || Date.parse(ended) < Date.parse(started)) return { refused: "the run record's start and end are not times in order" };
|
|
77
|
+
const failure = r.failure && typeof r.failure === "object" ? (r.failure as Record<string, unknown>) : undefined;
|
|
78
|
+
const exitCode = typeof failure?.exitCode === "number" && Number.isInteger(failure.exitCode) && failure.exitCode > 0 && failure.exitCode < 256 ? failure.exitCode : undefined;
|
|
79
|
+
const failedJob = expect.result === "failure" || expect.result === "cancelled";
|
|
80
|
+
const failed = failedJob || r.status !== "ok" || exitCode !== undefined;
|
|
81
|
+
const status = failed ? "fail" : "ok";
|
|
82
|
+
const durationMs = Date.parse(ended) - Date.parse(started);
|
|
83
|
+
return {
|
|
84
|
+
record: {
|
|
85
|
+
id: r.id,
|
|
86
|
+
op: PLAN_RUN_OP,
|
|
87
|
+
env: expect.env,
|
|
88
|
+
started,
|
|
89
|
+
ended,
|
|
90
|
+
status,
|
|
91
|
+
labels: { Env: expect.env, Pipeline: "pr", Job: "plan", ...(expect.target ? { Target: expect.target } : {}) },
|
|
92
|
+
outcomes: {},
|
|
93
|
+
phases: [{ name: "plan", status, steps: [{ fn: "shellCmd", status, durationMs, ...(failed ? { error: exitCode !== undefined ? `command exited ${exitCode}` : "the plan job failed" } : {}) }] }],
|
|
94
|
+
gitSha: expect.head,
|
|
95
|
+
...(expect.origin ? { runOrigin: expect.origin } : {}),
|
|
96
|
+
...(failed
|
|
97
|
+
? { failure: { code: "command-failed", reason: exitCode !== undefined ? `the plan verb exited ${exitCode}` : "the plan job failed", phase: "plan", ...(exitCode !== undefined ? { exitCode } : {}) } }
|
|
98
|
+
: {}),
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -144,3 +144,63 @@ describe("pr-post posts a product's plan note hand-off (#4799)", () => {
|
|
|
144
144
|
expect(notes[0]!.marker).toBe(prNoteMarker("default", "prod"));
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
|
+
|
|
148
|
+
describe("pr-post keeps the product's marker and adds the note job's notices (#4931)", () => {
|
|
149
|
+
const markerWords = { ...TERRAGUCCI_NOTE, productMarker: "terragucci:plan" };
|
|
150
|
+
|
|
151
|
+
test("the hand-off's marker body goes under chant's marker as the product's own hidden line", async () => {
|
|
152
|
+
const { forge, notes } = fakeForge();
|
|
153
|
+
await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir: handoffDir(planNoteHandoff(NOTE, { ...at, marker: "roots=live/a,live/b" })), pr: 7, head: HEAD, env: "default", noteWords: markerWords }));
|
|
154
|
+
const lines = notes[0]!.body.split("\n");
|
|
155
|
+
expect(lines[0]).toBe(prNoteMarker("default"));
|
|
156
|
+
expect(lines[1]).toBe("<!-- terragucci:plan roots=live/a,live/b -->");
|
|
157
|
+
expect(notes[0]!.body.split("<!--")).toHaveLength(4);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("without a productMarker in the words, the hand-off's marker is left out", async () => {
|
|
161
|
+
const { forge, notes } = fakeForge();
|
|
162
|
+
await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir: handoffDir(planNoteHandoff(NOTE, { ...at, marker: "roots=a" })), pr: 7, head: HEAD, env: "default", noteWords: TERRAGUCCI_NOTE }));
|
|
163
|
+
expect(notes[0]!.body).not.toContain("terragucci:plan");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test.each([["a comment end", "roots=a --> <!-- x"], ["a newline", "roots=a\nb"], ["a quote", 'roots="a"']])("a marker with %s is refused, and no note is posted", async (_what, marker) => {
|
|
167
|
+
const { forge, notes, statuses } = fakeForge();
|
|
168
|
+
const r = await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir: handoffDir(planNoteHandoff(NOTE, { ...at, marker })), pr: 7, head: HEAD, env: "default", noteWords: markerWords }));
|
|
169
|
+
expect(r.refused).toMatch(/marker is not words/);
|
|
170
|
+
expect(notes).toEqual([]);
|
|
171
|
+
expect(statuses[0]!.status.state).toBe("failure");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("the note job's notices and the overdue Ops go under the counts, each once", async () => {
|
|
175
|
+
const { forge, notes } = fakeForge();
|
|
176
|
+
const overdue = async () => [{ op: "tf-drift", cron: "0 * * * *", since: "2026-11-01T00:00:00Z", message: "Op `tf-drift` is overdue: it last ran 2026-11-01." }];
|
|
177
|
+
await withProductWords(TERRAGUCCI, () =>
|
|
178
|
+
postPlanReport({ forge, dir: handoffDir(planNoteHandoff(NOTE, at)), pr: 7, head: HEAD, env: "default", noteWords: TERRAGUCCI_NOTE, overdue, notices: ["A review by bob doesn't count toward the gate.", "A review by bob doesn't count toward the gate."] }),
|
|
179
|
+
);
|
|
180
|
+
const body = notes[0]!.body;
|
|
181
|
+
expect(body).toContain("> Op `tf-drift` is overdue: it last ran 2026-11-01.");
|
|
182
|
+
expect(body.split("> A review by bob doesn't count toward the gate.")).toHaveLength(2);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("an Op the product's own notices call overdue is not said twice", async () => {
|
|
186
|
+
const { forge, notes } = fakeForge();
|
|
187
|
+
const own = { ...NOTE, notices: ["Op `tf-drift` is overdue: the plan job saw it."] };
|
|
188
|
+
const overdue = async () => [{ op: "tf-drift", cron: "0 * * * *", since: "2026-11-01T00:00:00Z", message: "Op `tf-drift` is overdue: it last ran 2026-11-01." }];
|
|
189
|
+
await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir: handoffDir(planNoteHandoff(own, at)), pr: 7, head: HEAD, env: "default", noteWords: TERRAGUCCI_NOTE, overdue }));
|
|
190
|
+
expect(notes[0]!.body).not.toContain("it last ran 2026-11-01");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("the notices come from the file CHANT_PLAN_NOTE_NOTICES names", async () => {
|
|
194
|
+
const { forge, notes } = fakeForge();
|
|
195
|
+
const file = join(mkdtempSync(join(tmpdir(), "chant-notices-")), "notices");
|
|
196
|
+
dirs.push(file.slice(0, file.lastIndexOf("/")));
|
|
197
|
+
writeFileSync(file, "first notice\n\nsecond notice\n");
|
|
198
|
+
process.env.CHANT_PLAN_NOTE_NOTICES = file;
|
|
199
|
+
try {
|
|
200
|
+
await withProductWords(TERRAGUCCI, () => postPlanReport({ forge, dir: handoffDir(planNoteHandoff(NOTE, at)), pr: 7, head: HEAD, env: "default", noteWords: TERRAGUCCI_NOTE }));
|
|
201
|
+
} finally {
|
|
202
|
+
delete process.env.CHANT_PLAN_NOTE_NOTICES;
|
|
203
|
+
}
|
|
204
|
+
expect(notes[0]!.body).toContain("> first notice\n\n> second notice");
|
|
205
|
+
});
|
|
206
|
+
});
|
package/src/pr-post.test.ts
CHANGED
|
@@ -227,6 +227,36 @@ describe("pr-post --open posts each open merge request's plan from a pipeline of
|
|
|
227
227
|
expect(g.overdueCalls()).toBe(1);
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
+
test("#4914: with --evidence-dir the note ends with the checks the signing job signed for that head, and a file for another head is not used", async () => {
|
|
231
|
+
const evidence = reportDir(undefined);
|
|
232
|
+
const keep = (pr: number, head: string, signed: string[]) => {
|
|
233
|
+
mkdirSync(join(evidence, String(pr)), { recursive: true });
|
|
234
|
+
writeFileSync(
|
|
235
|
+
join(evidence, String(pr), "evidence.json"),
|
|
236
|
+
JSON.stringify({ pr, head, signed: signed.map((check) => ({ check, runner: "ci", commit: head, tree: "t".repeat(40) })), skipped: [{ check: "policy", reason: "the plan ran no policy" }] }),
|
|
237
|
+
);
|
|
238
|
+
};
|
|
239
|
+
keep(REPORT.pr!, HEAD, ["plan"]);
|
|
240
|
+
keep(9, OTHER, ["plan"]);
|
|
241
|
+
const g = gitlab({
|
|
242
|
+
jobs: [
|
|
243
|
+
{ pr: REPORT.pr!, head: HEAD, id: 101, status: "success" },
|
|
244
|
+
{ pr: 9, head: HEAD, id: 103, status: "success" },
|
|
245
|
+
],
|
|
246
|
+
artifacts: { 101: JSON.stringify(REPORT), 103: JSON.stringify({ ...REPORT, pr: 9 }) },
|
|
247
|
+
});
|
|
248
|
+
const { posts } = await postOpenPlanReports({ forge: g.forge, branch: "main", job: "plan", artifactDir: ".chant/pr", env: REPORT.env, evidenceDir: evidence });
|
|
249
|
+
expect(posts.map((p) => p.posted?.noted)).toEqual([true, true]);
|
|
250
|
+
const byPr = new Map(g.notes.map((n) => [n.pr, n.body]));
|
|
251
|
+
expect(byPr.get(REPORT.pr!)).toContain("Checks: signed evidence for `plan` as ci; not signed: `policy` (the plan ran no policy).");
|
|
252
|
+
// !9's file names another head: the note says nothing it cannot stand behind.
|
|
253
|
+
expect(byPr.get(9)).not.toContain("Checks:");
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("#4914: the flag parses", () => {
|
|
257
|
+
expect(parseArgs(["components", "pr-post", "--open", "--env", "prod", "--forge", "gitlab", "--evidence-dir", ".chant/evidence/plan"])).toMatchObject({ open: true, evidenceDir: ".chant/evidence/plan" });
|
|
258
|
+
});
|
|
259
|
+
|
|
230
260
|
test("a forge that cannot list merge request jobs is refused", async () => {
|
|
231
261
|
await expect(postOpenPlanReports({ forge: fakeForge().forge, branch: "main", job: "plan", artifactDir: ".chant/pr", env: REPORT.env })).rejects.toThrow(/it is for GitLab/);
|
|
232
262
|
});
|
package/src/pr-post.ts
CHANGED
|
@@ -37,8 +37,11 @@ import { forgePrincipalOf, type PrForge } from "./pr-forge";
|
|
|
37
37
|
import { GITHUB_COMMENT_LIMIT, GITLAB_NOTE_LIMIT } from "./plan-summary";
|
|
38
38
|
import { activeProductWords, commentLine, type CiProductWords } from "./ci-product-words";
|
|
39
39
|
import { controlEdgeFactsFromEnv, remarkCrossStackEdges, type ControlEdgeFacts } from "./control/edges";
|
|
40
|
-
import { checkEvidenceNoteLine } from "./workspace/trust/check-evidence-report";
|
|
41
|
-
import {
|
|
40
|
+
import { CHECK_EVIDENCE_FILE, checkEvidenceNoteLine, openEvidenceFor } from "./workspace/trust/check-evidence-report";
|
|
41
|
+
import { PLAN_RUN_RECORD_FILE, readPlanRunRecord } from "./pr-plan-record";
|
|
42
|
+
import type { OpRunRecordInput } from "./op/runtime";
|
|
43
|
+
import type { RunOrigin } from "./lifecycle/release-ledger";
|
|
44
|
+
import { isPlanNote, planNoteMarker, PR_PLAN_NOTE_CONTRACT, PR_PLAN_NOTE_FILE, PRODUCT_MARKER_BODY, PRODUCT_MARKER_LIMIT, PRODUCT_MARKER_NAME, productMarkerLine, renderPlanNote, type PrPlanNoteHandoff, type PrPlanNoteWords } from "./pr-plan-note";
|
|
42
45
|
|
|
43
46
|
/** The plan report's file under the report directory. */
|
|
44
47
|
export const PR_PLAN_REPORT_FILE = "pr-plan.json";
|
|
@@ -90,6 +93,27 @@ export interface PlanPostInput {
|
|
|
90
93
|
* from the pipeline, never from the report.
|
|
91
94
|
*/
|
|
92
95
|
noteWords?: PrPlanNoteWords;
|
|
96
|
+
/**
|
|
97
|
+
* Notices the note job's own lines wrote (#4931), each added under a
|
|
98
|
+
* product's plan note hand-off's counts, after its own. Default: the
|
|
99
|
+
* lines of the file `CHANT_PLAN_NOTE_NOTICES` names, which the generated
|
|
100
|
+
* note job sets to a file outside the report the plan job handed on.
|
|
101
|
+
*/
|
|
102
|
+
notices?: string[];
|
|
103
|
+
/**
|
|
104
|
+
* Keep the plan job's run record (#4899, ./pr-plan-record.ts), when it
|
|
105
|
+
* wrote one into the hand-off: read as data, with `origin` naming the plan
|
|
106
|
+
* job's run, and handed to `keep`, which appends it to the run ledger and
|
|
107
|
+
* pushes. `keep` returns a warning to say, when there is one.
|
|
108
|
+
*/
|
|
109
|
+
recordRun?: PlanRunRecorder;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** How the note job keeps the plan job's run record (#4899). */
|
|
113
|
+
export interface PlanRunRecorder {
|
|
114
|
+
/** The plan job's run, as the note job names it. */
|
|
115
|
+
origin?: RunOrigin;
|
|
116
|
+
keep(record: OpRunRecordInput): Promise<string | undefined>;
|
|
93
117
|
}
|
|
94
118
|
|
|
95
119
|
/** What {@link postPlanReport} did. */
|
|
@@ -100,6 +124,8 @@ export interface PlanPostResult {
|
|
|
100
124
|
noted: boolean;
|
|
101
125
|
/** Why the report was not used, when it was not. */
|
|
102
126
|
refused?: string;
|
|
127
|
+
/** The id of the plan job's run record kept on chant/lifecycle (#4899), when one was. */
|
|
128
|
+
recorded?: string;
|
|
103
129
|
warnings: string[];
|
|
104
130
|
}
|
|
105
131
|
|
|
@@ -229,7 +255,40 @@ export async function postPlanReport(input: PlanPostInput): Promise<PlanPostResu
|
|
|
229
255
|
warnings.push(`the description check did not run: ${err instanceof Error ? err.message : String(err)}`);
|
|
230
256
|
}
|
|
231
257
|
}
|
|
232
|
-
|
|
258
|
+
const recorded = await keepRunRecord(input, warnings);
|
|
259
|
+
return { state, description: cut(description), noted: note !== undefined, ...(refused ? { refused } : {}), ...(recorded ? { recorded } : {}), warnings };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Keep the plan job's run record on chant/lifecycle (#4899), with
|
|
264
|
+
* `input.recordRun`. A record that is missing, refused or not kept is a
|
|
265
|
+
* warning: the note and the status stand. Returns the record's id once kept.
|
|
266
|
+
*/
|
|
267
|
+
async function keepRunRecord(input: PlanPostInput, warnings: string[]): Promise<string | undefined> {
|
|
268
|
+
if (!input.recordRun) return undefined;
|
|
269
|
+
const read = readPlanRunRecord(input.dir, {
|
|
270
|
+
env: input.env,
|
|
271
|
+
head: input.head,
|
|
272
|
+
...(input.member ? { target: input.member } : {}),
|
|
273
|
+
...(input.result ? { result: input.result } : {}),
|
|
274
|
+
...(input.recordRun.origin ? { origin: input.recordRun.origin } : {}),
|
|
275
|
+
});
|
|
276
|
+
if (!read) {
|
|
277
|
+
warnings.push("the plan job wrote no run record, so none is kept");
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
if ("refused" in read) {
|
|
281
|
+
warnings.push(`the plan job's run record was not kept: ${read.refused}`);
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const said = await input.recordRun.keep(read.record);
|
|
286
|
+
if (said) warnings.push(said);
|
|
287
|
+
return read.record.id;
|
|
288
|
+
} catch (err) {
|
|
289
|
+
warnings.push(`the plan job's run record was not kept on chant/lifecycle: ${err instanceof Error ? err.message : String(err)}`);
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
233
292
|
}
|
|
234
293
|
|
|
235
294
|
/**
|
|
@@ -297,9 +356,24 @@ export function readPlanNoteHandoff(input: Pick<PlanPostInput, "dir" | "pr" | "h
|
|
|
297
356
|
if (!isPlanNote(r.note) || r.note.head !== r.head || !Array.isArray(r.note.waves) || !Array.isArray(r.note.groups) || !Array.isArray(r.note.named)) {
|
|
298
357
|
return { refused: "the plan note's note is not a plan note for its head" };
|
|
299
358
|
}
|
|
359
|
+
// #4931: the product's hidden line is the change's too, so it holds only plain words.
|
|
360
|
+
if (r.marker !== undefined && (typeof r.marker !== "string" || r.marker.length > PRODUCT_MARKER_LIMIT || (r.marker !== "" && !PRODUCT_MARKER_BODY.test(r.marker)))) {
|
|
361
|
+
return { refused: `the plan note's marker is not words of letters, digits and _.,/@+=:- of at most ${PRODUCT_MARKER_LIMIT} characters` };
|
|
362
|
+
}
|
|
300
363
|
return { handoff: doc as PrPlanNoteHandoff };
|
|
301
364
|
}
|
|
302
365
|
|
|
366
|
+
/** The notices in the file `CHANT_PLAN_NOTE_NOTICES` names (#4931), one a line, or none when unset or unreadable. */
|
|
367
|
+
export function noticesFromEnv(env: NodeJS.ProcessEnv = process.env): string[] {
|
|
368
|
+
const file = env.CHANT_PLAN_NOTE_NOTICES;
|
|
369
|
+
if (!file || !existsSync(file)) return [];
|
|
370
|
+
try {
|
|
371
|
+
return readFileSync(file, "utf-8").split("\n").map((l) => l.trim()).filter((l) => l !== "");
|
|
372
|
+
} catch {
|
|
373
|
+
return [];
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
303
377
|
/** The note words from `CHANT_PLAN_NOTE_WORDS` (#4799), or undefined when unset or not an object. */
|
|
304
378
|
function noteWordsFromEnv(): PrPlanNoteWords | undefined {
|
|
305
379
|
const raw = process.env.CHANT_PLAN_NOTE_WORDS;
|
|
@@ -327,7 +401,10 @@ export function planNoteHandoffNote(handoff: PrPlanNoteHandoff, forge: Pick<PrFo
|
|
|
327
401
|
const waves = planNoteMarker(noteWords?.marker ?? `${words.product}:waves`, { head: n.head, waves: n.waves.map((x) => ({ number: x.number, digest: x.digest ?? null, waits: x.waits === true })), ...(previews.length ? { previews } : {}) });
|
|
328
402
|
body = body.replace(`<!--${waves.slice(4)}`, waves);
|
|
329
403
|
const tip = baseTip && SHA.test(baseTip) ? `${body.endsWith("\n") ? "" : "\n"}${prNoteTipMarker(baseTip)}\n` : "";
|
|
330
|
-
|
|
404
|
+
// #4931: the product's own line, from the pipeline's name and the hand-off's checked body, under chant's marker.
|
|
405
|
+
const name = noteWords?.productMarker;
|
|
406
|
+
const own = name !== undefined && PRODUCT_MARKER_NAME.test(name) && handoff.marker !== undefined ? `${productMarkerLine(name, handoff.marker)}\n` : "";
|
|
407
|
+
return `${marker}\n${own}${body}${tip}`;
|
|
331
408
|
}
|
|
332
409
|
|
|
333
410
|
/** {@link postPlanReport} for a product's plan note hand-off (#4799). */
|
|
@@ -347,8 +424,14 @@ async function postPlanNoteHandoff(input: PlanPostInput): Promise<PlanPostResult
|
|
|
347
424
|
} else {
|
|
348
425
|
state = read.handoff.state;
|
|
349
426
|
description = read.handoff.description;
|
|
427
|
+
// #4931: the overdue Ops (#4289), asked here with the job's token, and the note job's own notices, under the counts.
|
|
428
|
+
const given = read.handoff.note.notices ?? [];
|
|
429
|
+
// An Op the product's own notices already call overdue is not said twice.
|
|
430
|
+
const overdue = input.overdue ? (await input.overdue().catch(() => [] as PrOverdue[])).filter((o) => !given.some((g) => g.includes(`\`${o.op}\``) && g.includes("overdue"))).map((o) => o.message) : [];
|
|
431
|
+
const added = [...overdue, ...(input.notices ?? noticesFromEnv())].filter((n, i, all) => !given.includes(n) && all.indexOf(n) === i);
|
|
432
|
+
const handoff = added.length > 0 ? { ...read.handoff, note: { ...read.handoff.note, notices: [...given, ...added] } } : read.handoff;
|
|
350
433
|
try {
|
|
351
|
-
note = planNoteHandoffNote(
|
|
434
|
+
note = planNoteHandoffNote(handoff, input.forge, prNoteMarker(input.env, input.member), input.noteWords ?? noteWordsFromEnv(), input.baseTip);
|
|
352
435
|
} catch (err) {
|
|
353
436
|
refused = `the plan note does not render: ${err instanceof Error ? err.message : String(err)}`;
|
|
354
437
|
state = "failure";
|
|
@@ -360,7 +443,8 @@ async function postPlanNoteHandoff(input: PlanPostInput): Promise<PlanPostResult
|
|
|
360
443
|
}
|
|
361
444
|
}
|
|
362
445
|
note = await postOutcome(input, context, state, description, note, refused, warnings);
|
|
363
|
-
|
|
446
|
+
const recorded = await keepRunRecord(input, warnings);
|
|
447
|
+
return { state, description: cut(description), noted: note !== undefined, ...(refused ? { refused } : {}), ...(recorded ? { recorded } : {}), warnings };
|
|
364
448
|
}
|
|
365
449
|
|
|
366
450
|
/**
|
|
@@ -398,6 +482,17 @@ export interface OpenPlanPostInput {
|
|
|
398
482
|
description?: (report: PrReport) => Promise<void>;
|
|
399
483
|
/** The target branch's commit this pipeline runs at (#4628), for each note's tip line. */
|
|
400
484
|
baseTip?: string;
|
|
485
|
+
/**
|
|
486
|
+
* Keep each plan job's run record (#4899) from its artifacts, the job
|
|
487
|
+
* named as its run origin's `jobId`. `repo` is the project's path.
|
|
488
|
+
*/
|
|
489
|
+
recordRun?: { repo?: string; keep: PlanRunRecorder["keep"] };
|
|
490
|
+
/**
|
|
491
|
+
* Where the signing job of this pipeline kept each merge request's
|
|
492
|
+
* `evidence.json` (#4914), `<dir>/<iid>/evidence.json`: the note of a
|
|
493
|
+
* merge request whose file names its head ends with the checks line.
|
|
494
|
+
*/
|
|
495
|
+
evidenceDir?: string;
|
|
401
496
|
}
|
|
402
497
|
|
|
403
498
|
/** What {@link postOpenPlanReports} did for one merge request. */
|
|
@@ -447,6 +542,12 @@ export async function postOpenPlanReports(input: OpenPlanPostInput): Promise<{ p
|
|
|
447
542
|
// #4799: a product's plan verb writes its plan note hand-off in place of the report.
|
|
448
543
|
const handoff = text === undefined ? await forge.jobArtifact(job.id, `${input.artifactDir.replace(/\/+$/, "")}/${PR_PLAN_NOTE_FILE}`) : undefined;
|
|
449
544
|
if (handoff !== undefined) writeFileSync(join(dir, PR_PLAN_NOTE_FILE), handoff);
|
|
545
|
+
// #4899: the plan job's run record, kept with its note.
|
|
546
|
+
const runRecord = input.recordRun ? await forge.jobArtifact(job.id, `${input.artifactDir.replace(/\/+$/, "")}/${PLAN_RUN_RECORD_FILE}`) : undefined;
|
|
547
|
+
if (runRecord !== undefined) writeFileSync(join(dir, PLAN_RUN_RECORD_FILE), runRecord);
|
|
548
|
+
// #4914: what the signing job signed for this head, which the note's checks line says.
|
|
549
|
+
const evidence = input.evidenceDir ? openEvidenceFor(input.evidenceDir, job.pr, job.head) : undefined;
|
|
550
|
+
if (evidence !== undefined) writeFileSync(join(dir, CHECK_EVIDENCE_FILE), evidence);
|
|
450
551
|
const posted = await postPlanReport({
|
|
451
552
|
// The status links to the plan job it reports on, which is how the next run knows it is posted.
|
|
452
553
|
forge: job.url ? { ...forge, runUrl: job.url } : forge,
|
|
@@ -459,6 +560,9 @@ export async function postOpenPlanReports(input: OpenPlanPostInput): Promise<{ p
|
|
|
459
560
|
...(overdueOnce ? { overdue: overdueOnce } : {}),
|
|
460
561
|
...(input.description ? { description: input.description } : {}),
|
|
461
562
|
...(input.baseTip ? { baseTip: input.baseTip } : {}),
|
|
563
|
+
...(input.recordRun
|
|
564
|
+
? { recordRun: { origin: { forge: "gitlab", ...(input.recordRun.repo ? { repo: input.recordRun.repo } : {}), ...(job.url ? { url: job.url } : {}), jobId: String(job.id) }, keep: input.recordRun.keep } }
|
|
565
|
+
: {}),
|
|
462
566
|
});
|
|
463
567
|
posts.push({ pr: job.pr, head: job.head, posted });
|
|
464
568
|
} finally {
|
package/src/pr-requires.test.ts
CHANGED
|
@@ -129,6 +129,20 @@ describe("github", () => {
|
|
|
129
129
|
const f = forge({ [`GET ${repo}/commits/${HEAD}/status`]: { statuses: [] }, [`GET ${repo}/commits/${HEAD}/check-runs`]: { check_runs: [] } });
|
|
130
130
|
expect(await f.prChecksPassed!(7, HEAD)).toMatchObject({ passed: false, pending: true });
|
|
131
131
|
});
|
|
132
|
+
|
|
133
|
+
test("checks: a required status that has not reported is pending, through checkPrRequires' require (#4913)", async () => {
|
|
134
|
+
const green = { [`GET ${repo}/commits/${HEAD}/check-runs`]: { check_runs: [{ name: "lint", status: "completed", conclusion: "success" }] } };
|
|
135
|
+
const before = forge({ [`GET ${repo}/commits/${HEAD}/status`]: { statuses: [{ context: "ci/test", state: "success" }] }, ...green });
|
|
136
|
+
expect(await before.prChecksPassed!(7, HEAD, [], ["chant/ref-gate"])).toEqual({ passed: false, pending: true, reason: "chant/ref-gate still running on aaaaaaaa" });
|
|
137
|
+
const out = await checkPrRequires(before, 7, HEAD, { only: ["checks"], require: ["chant/ref-gate"], wait: async () => {} });
|
|
138
|
+
expect(out.find((o) => o.name === "checks")).toMatchObject({ passed: false, pending: true, reason: "chant/ref-gate still running on aaaaaaaa" });
|
|
139
|
+
// Without require, the same head passes: the gap the ref gate's status job leaves until it posts.
|
|
140
|
+
expect((await before.prChecksPassed!(7, HEAD)).passed).toBe(true);
|
|
141
|
+
const after = forge({ [`GET ${repo}/commits/${HEAD}/status`]: { statuses: [{ context: "ci/test", state: "success" }, { context: "chant/ref-gate", state: "success" }] }, ...green });
|
|
142
|
+
expect(await after.prChecksPassed!(7, HEAD, [], ["chant/ref-gate"])).toEqual({ passed: true, reason: "3 checks passed on aaaaaaaa" });
|
|
143
|
+
const refused = forge({ [`GET ${repo}/commits/${HEAD}/status`]: { statuses: [{ context: "chant/ref-gate", state: "failure" }] }, ...green });
|
|
144
|
+
expect((await refused.prChecksPassed!(7, HEAD, [], ["chant/ref-gate"])).reason).toBe("chant/ref-gate failed on aaaaaaaa");
|
|
145
|
+
});
|
|
132
146
|
});
|
|
133
147
|
|
|
134
148
|
describe("forgejo", () => {
|
|
@@ -264,6 +278,12 @@ describe("gitlab", () => {
|
|
|
264
278
|
expect(await f.prChecksPassed!(3, HEAD, ["apply"])).toEqual({ passed: true, reason: "2 checks passed on aaaaaaaa" });
|
|
265
279
|
expect((await f.prChecksPassed!(3, HEAD)).pending).toBe(true);
|
|
266
280
|
});
|
|
281
|
+
|
|
282
|
+
test("checks: a required status that has not reported is pending (#4913)", async () => {
|
|
283
|
+
const f = (statuses: unknown[]) => forge({ [`GET ${project}/repository/commits/${HEAD}/statuses`]: statuses });
|
|
284
|
+
expect(await f([{ id: 1, name: "test", status: "success" }]).prChecksPassed!(3, HEAD, [], ["chant/ref-gate"])).toEqual({ passed: false, pending: true, reason: "chant/ref-gate still running on aaaaaaaa" });
|
|
285
|
+
expect((await f([{ id: 1, name: "test", status: "success" }, { id: 2, name: "chant/ref-gate", status: "success" }]).prChecksPassed!(3, HEAD, [], ["chant/ref-gate"])).passed).toBe(true);
|
|
286
|
+
});
|
|
267
287
|
});
|
|
268
288
|
|
|
269
289
|
describe("checkPrRequires", () => {
|
package/src/pr-requires.ts
CHANGED
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import type { PrApproverFilter, PrExcludedApprover, PrForge, PrRequireResult } from "./pr-forge";
|
|
18
18
|
|
|
19
|
+
/** `require` in {@link PrRequiresOptions} (#4913). */
|
|
20
|
+
export { REF_GATE_PIECES_FLOOR } from "./release-floors";
|
|
21
|
+
|
|
19
22
|
/** The four checks, in the order they run and the report lists them. */
|
|
20
23
|
export const PR_APPLY_REQUIRES = ["approved", "mergeable", "undiverged", "checks"] as const;
|
|
21
24
|
|
|
@@ -40,6 +43,12 @@ export interface PrRequiresOptions {
|
|
|
40
43
|
approvers?: PrApproverFilter;
|
|
41
44
|
/** Status names the `checks` require leaves out: the apply's own. */
|
|
42
45
|
ignore?: readonly string[];
|
|
46
|
+
/**
|
|
47
|
+
* Statuses the `checks` require needs to have reported and passed (#4913),
|
|
48
|
+
* such as the ref gate's: `refGateRulesAt(...).status` from
|
|
49
|
+
* `@intentius/chant/ref-gate-rules`. One not reported yet is pending.
|
|
50
|
+
*/
|
|
51
|
+
require?: readonly string[];
|
|
43
52
|
/** How many times a pending check is asked in all. Default 5. */
|
|
44
53
|
reads?: number;
|
|
45
54
|
/** The wait between reads. Default 3 seconds. */
|
|
@@ -61,7 +70,7 @@ export async function checkPrRequires(forge: PrForge, pr: number, head: string,
|
|
|
61
70
|
approved: forge.prApproved ? () => forge.prApproved!(pr, head, opts.approvers) : undefined,
|
|
62
71
|
mergeable: forge.prMergeable ? () => forge.prMergeable!(pr, head) : undefined,
|
|
63
72
|
undiverged: forge.prUndiverged ? () => forge.prUndiverged!(pr, head) : undefined,
|
|
64
|
-
checks: forge.prChecksPassed ? () => forge.prChecksPassed!(pr, head, opts.ignore ?? []) : undefined,
|
|
73
|
+
checks: forge.prChecksPassed ? () => forge.prChecksPassed!(pr, head, opts.ignore ?? [], opts.require ?? []) : undefined,
|
|
65
74
|
};
|
|
66
75
|
const out: PrRequireOutcome[] = [];
|
|
67
76
|
const asked = new Set<PrApplyRequire>(opts.only ?? PR_APPLY_REQUIRES);
|