forgedock 1.52.0 → 1.54.0
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/.claude-plugin/marketplace.json +51 -0
- package/README.md +8 -2
- package/bin/auth/app-manifest.mjs +89 -0
- package/bin/auth/app-manifest.test.mjs +75 -0
- package/bin/auth/app-token.mjs +256 -0
- package/bin/auth/app-token.test.mjs +232 -0
- package/bin/brand.mjs +7 -0
- package/bin/config-history.mjs +151 -0
- package/bin/config-schema.mjs +115 -0
- package/bin/demo.mjs +65 -11
- package/bin/engine/outcome-codes.mjs +9 -3
- package/bin/engine/telemetry-seam.mjs +11 -3
- package/bin/engine/telemetry-seam.test.mjs +17 -0
- package/bin/engine-cli.mjs +110 -36
- package/bin/experiment.mjs +58 -6
- package/bin/first-run.mjs +122 -0
- package/bin/forge-utils.mjs +6 -2
- package/bin/forgedock.mjs +138 -142
- package/bin/help-text.mjs +144 -0
- package/bin/hooks/pre-tool-use.mjs +7 -0
- package/bin/journey.mjs +82 -83
- package/bin/lean/acceptance.mjs +313 -0
- package/bin/lean/acceptance.test.mjs +215 -0
- package/bin/lean/account-watch.mjs +28 -0
- package/bin/lean/account-watch.test.mjs +30 -0
- package/bin/lean/activation.mjs +38 -0
- package/bin/lean/activation.test.mjs +36 -1
- package/bin/lean/basered.mjs +115 -0
- package/bin/lean/basered.test.mjs +66 -0
- package/bin/lean/batch-health.mjs +114 -7
- package/bin/lean/batch-health.test.mjs +87 -1
- package/bin/lean/batch.mjs +41 -2
- package/bin/lean/batch.test.mjs +115 -11
- package/bin/lean/branchlock.mjs +54 -0
- package/bin/lean/branchlock.test.mjs +49 -0
- package/bin/lean/ceiling.mjs +72 -0
- package/bin/lean/ceiling.test.mjs +54 -0
- package/bin/lean/checkpoint-reconcile.mjs +43 -0
- package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
- package/bin/lean/ci-budget.mjs +366 -0
- package/bin/lean/ci-budget.test.mjs +167 -0
- package/bin/lean/conformance.e2e.test.mjs +8 -1
- package/bin/lean/conformance.mjs +269 -38
- package/bin/lean/conformance.test.mjs +280 -7
- package/bin/lean/context.mjs +35 -6
- package/bin/lean/context.test.mjs +27 -1
- package/bin/lean/depcache.mjs +25 -1
- package/bin/lean/depcache.test.mjs +26 -0
- package/bin/lean/e2e.mjs +18 -2
- package/bin/lean/e2e.test.mjs +26 -1
- package/bin/lean/effects.mjs +47 -14
- package/bin/lean/execution.mjs +19 -3
- package/bin/lean/execution.test.mjs +63 -0
- package/bin/lean/facts.mjs +3 -3
- package/bin/lean/facts.test.mjs +5 -0
- package/bin/lean/findinglabel.mjs +16 -0
- package/bin/lean/findinglabel.test.mjs +39 -0
- package/bin/lean/fixround.mjs +14 -0
- package/bin/lean/fixround.test.mjs +25 -2
- package/bin/lean/gh-assoc.test.mjs +2 -1
- package/bin/lean/integration.mjs +100 -9
- package/bin/lean/integration.test.mjs +98 -0
- package/bin/lean/issuewatch-parity.mjs +64 -0
- package/bin/lean/issuewatch-parity.test.mjs +127 -0
- package/bin/lean/issuewatch-release.mjs +6 -2
- package/bin/lean/issuewatch-release.test.mjs +17 -1
- package/bin/lean/issuewatch.mjs +45 -6
- package/bin/lean/issuewatch.test.mjs +3 -2
- package/bin/lean/lanelock.mjs +14 -0
- package/bin/lean/lean.mjs +473 -100
- package/bin/lean/lean.test.mjs +686 -33
- package/bin/lean/light.mjs +48 -7
- package/bin/lean/light.test.mjs +37 -3
- package/bin/lean/limits.test.mjs +142 -9
- package/bin/lean/mechfix.mjs +124 -0
- package/bin/lean/mechfix.test.mjs +75 -0
- package/bin/lean/orchestrate-cancel.test.mjs +143 -0
- package/bin/lean/orchestrate.mjs +116 -28
- package/bin/lean/phaseledger.mjs +47 -5
- package/bin/lean/phaseledger.test.mjs +30 -1
- package/bin/lean/postdeploy-check.test.mjs +39 -0
- package/bin/lean/precheck.mjs +23 -4
- package/bin/lean/precheck.test.mjs +14 -1
- package/bin/lean/prereq.mjs +28 -0
- package/bin/lean/prereq.test.mjs +20 -0
- package/bin/lean/probe.mjs +4 -2
- package/bin/lean/prodparity.mjs +52 -0
- package/bin/lean/prodparity.test.mjs +67 -0
- package/bin/lean/prompts.mjs +77 -19
- package/bin/lean/quota.mjs +39 -0
- package/bin/lean/recovery.test.mjs +11 -1
- package/bin/lean/relaxation.mjs +73 -0
- package/bin/lean/relaxation.test.mjs +54 -0
- package/bin/lean/release-io.test.mjs +42 -0
- package/bin/lean/release-postmerge.mjs +125 -0
- package/bin/lean/release-preflight.mjs +58 -0
- package/bin/lean/release-preflight.test.mjs +114 -0
- package/bin/lean/release-rehearsal.mjs +64 -0
- package/bin/lean/release-rehearsal.test.mjs +93 -0
- package/bin/lean/release-review.e2e.test.mjs +77 -0
- package/bin/lean/release-review.mjs +254 -0
- package/bin/lean/release-review.test.mjs +307 -0
- package/bin/lean/release-snapshot.mjs +188 -0
- package/bin/lean/release-snapshot.test.mjs +190 -0
- package/bin/lean/release.mjs +296 -0
- package/bin/lean/release.test.mjs +387 -0
- package/bin/lean/render.mjs +1 -1
- package/bin/lean/replan.mjs +184 -0
- package/bin/lean/replan.test.mjs +110 -0
- package/bin/lean/resume.mjs +9 -7
- package/bin/lean/resume.test.mjs +16 -0
- package/bin/lean/rotator.mjs +150 -31
- package/bin/lean/rotator.test.mjs +105 -2
- package/bin/lean/sandbox-remote.mjs +9 -2
- package/bin/lean/schedd.mjs +83 -5
- package/bin/lean/schedd.test.mjs +108 -7
- package/bin/lean/selfreview.mjs +94 -0
- package/bin/lean/selfreview.test.mjs +58 -1
- package/bin/lean/selftest-gate.mjs +22 -0
- package/bin/lean/selftest-gate.test.mjs +18 -1
- package/bin/lean/selftest-journey.mjs +234 -0
- package/bin/lean/selftest-journey.test.mjs +130 -0
- package/bin/lean/selftest-live.mjs +2 -1
- package/bin/lean/seqlease.mjs +35 -1
- package/bin/lean/seqlease.test.mjs +15 -0
- package/bin/lean/seqreserve.e2e.test.mjs +135 -0
- package/bin/lean/seqreserve.mjs +73 -0
- package/bin/lean/seqreserve.test.mjs +134 -0
- package/bin/lean/sequence.mjs +35 -6
- package/bin/lean/seqversioned.mjs +147 -0
- package/bin/lean/stagestamp.mjs +28 -0
- package/bin/lean/stagestamp.test.mjs +32 -0
- package/bin/lean/surfaces.mjs +75 -0
- package/bin/lean/surfaces.test.mjs +59 -0
- package/bin/lean/toolplace.mjs +28 -0
- package/bin/lean/toolplace.test.mjs +24 -0
- package/bin/lean/toolstats.mjs +3 -1
- package/bin/lean/toolstats.test.mjs +11 -0
- package/bin/lean/validatebest.mjs +28 -0
- package/bin/lean/validatebest.test.mjs +27 -0
- package/bin/lean/verifier.mjs +3 -2
- package/bin/lean/verify.mjs +2 -1
- package/bin/lean/verify.test.mjs +6 -0
- package/bin/pool/agent.mjs +27 -4
- package/bin/pool/docker.mjs +5 -0
- package/bin/pool/router.mjs +74 -28
- package/bin/prereqs.mjs +111 -0
- package/bin/replay-timelapse.mjs +149 -0
- package/bin/review-staging.mjs +123 -16
- package/bin/review-staging.test.mjs +18 -0
- package/bin/runner.mjs +43 -6
- package/bin/splash-install.mjs +157 -0
- package/bin/stats/aggregate.mjs +8 -1
- package/bin/stats/conformance-outcomes.mjs +289 -0
- package/bin/stats/conformance-outcomes.test.mjs +274 -0
- package/bin/stats/depth.mjs +275 -0
- package/bin/stats/depth.test.mjs +158 -0
- package/bin/stats/efficiency.mjs +26 -5
- package/bin/stats/efficiency.test.mjs +45 -1
- package/bin/stats/experiment.mjs +7 -5
- package/bin/stats/first-review.mjs +77 -0
- package/bin/stats/first-review.test.mjs +36 -0
- package/bin/stats/firstmerge.mjs +40 -0
- package/bin/stats/firstmerge.test.mjs +41 -0
- package/bin/stats/github-source.mjs +53 -15
- package/bin/stats/index.mjs +147 -9
- package/bin/stats/local-source.mjs +12 -0
- package/bin/stats/origin.mjs +80 -0
- package/bin/stats/origin.test.mjs +58 -0
- package/bin/stats/query.mjs +69 -0
- package/bin/stats/render.mjs +3 -1
- package/bin/stats/scoreboard.mjs +137 -0
- package/bin/stats/scoreboard.test.mjs +87 -0
- package/bin/stats/selffiled.mjs +52 -0
- package/bin/stats/selffiled.test.mjs +71 -0
- package/bin/stats/stats.test.mjs +80 -0
- package/bin/tui.mjs +3 -2
- package/commands/bootstrap.md +15 -14
- package/commands/deploy-pr.md +18 -3
- package/commands/forge-stats.md +1 -1
- package/commands/forgedock-ci-setup.md +28 -0
- package/commands/forgedock-init.md +4 -5
- package/commands/issue.md +2 -0
- package/commands/milestone.md +9 -1
- package/commands/orchestrate.md +1 -1
- package/commands/replay.md +2 -0
- package/commands/review-pr-agents/security.md +4 -0
- package/commands/review-pr-staging.md +6 -1
- package/commands/work-on/build.md +4 -6
- package/commands/work-on/close.md +8 -0
- package/docs/CONFIG.md +170 -18
- package/docs/ISSUE-WATCH.md +25 -0
- package/docs/OUTCOME-CODES.md +4 -0
- package/docs/REPLAY.md +9 -0
- package/docs/SELFTEST.md +11 -0
- package/docs/STATS.md +61 -0
- package/docs/TELEMETRY.md +1 -1
- package/docs/eval/README.md +6 -0
- package/docs/eval/adversarial-bench.md +68 -0
- package/docs/eval/corpus/adversarial-v1.json +285 -0
- package/docs/eval/feature-bench.md +42 -0
- package/docs/eval/feature-specs/crud-auth/journeys/notes-crud-isolated.mjs +21 -0
- package/docs/eval/feature-specs/crud-auth/journeys/register-login.mjs +12 -0
- package/docs/eval/feature-specs/crud-auth/spec.md +15 -0
- package/docs/site/start-a-new-project.md +2 -1
- package/package.json +5 -2
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +10 -0
- package/plugins/forgedock-splash/README.md +27 -0
- package/plugins/forgedock-splash/hooks/hooks.json +1 -0
- package/plugins/forgedock-splash/hooks/register.tsx +74 -0
- package/plugins/forgedock-splash/hooks/scene.ts +222 -0
- package/plugins/forgedock-splash/types/index.d.ts +10 -0
- package/pool/README.md +1 -1
- package/pool/image/cs-cred +14 -1
- package/scripts/backfill-finding-labels.mjs +50 -0
- package/scripts/backfill-finding-labels.test.mjs +36 -0
- package/scripts/bench-adversarial.mjs +216 -0
- package/scripts/bench-feature.mjs +170 -0
- package/scripts/bench-lightlane.mjs +2 -2
- package/scripts/bootstrap-create.mjs +2 -2
- package/scripts/bootstrap-validate.mjs +35 -2
- package/scripts/check-spec-size.sh +4 -3
- package/scripts/check-spec-size.test.sh +3 -0
- package/scripts/doctor-pipeline-state.sh +21 -6
- package/scripts/file-deferred-followups.sh +59 -251
- package/scripts/file-deferred-followups.test.sh +85 -206
- package/scripts/followup-route.mjs +12 -0
- package/scripts/owner-route-parity.test.sh +17 -1
- package/scripts/plan-validate-live.mjs +40 -6
- package/scripts/review-pr-side-effects.test.sh +40 -0
- package/scripts/review-pr-staging-scope.test.sh +1 -1
- package/scripts/review-staging-post.sh +23 -0
- package/scripts/review-staging-post.test.sh +8 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
|
+
import { releaseFromCli, readReleaseConfig, openRelease, newReleaseId } from "./release.mjs";
|
|
9
|
+
import { reviewStep, fixStep } from "./release-review.mjs";
|
|
10
|
+
import { postMergeStep } from "./release-postmerge.mjs";
|
|
11
|
+
|
|
12
|
+
const DISK = [{ mount: "/", type: "ext4" }]; // CI /tmp can be tmpfs, which assertDiskPath refuses
|
|
13
|
+
const tmp = () => tmpDir("release-");
|
|
14
|
+
const REPO = "o/r", HEAD = "a".repeat(40);
|
|
15
|
+
|
|
16
|
+
/** io fake; `world` tunes the gh answers. */
|
|
17
|
+
function fakeIo(world = {}) {
|
|
18
|
+
const calls = [], par = [], printed = [];
|
|
19
|
+
const w = { lanes: [], openStaging: [], batches: [], releasePr: [{ number: 7, headRefOid: HEAD, url: "u" }], comments: [{ body: "FORGE:GATE_PASS" }], gate: "success", ...world };
|
|
20
|
+
const io = {
|
|
21
|
+
calls, par, printed, now: () => 1_700_000_000_000, print: (l) => printed.push(l),
|
|
22
|
+
sleeps: [], ran: [], sleep: async (ms) => { io.sleeps.push(ms); },
|
|
23
|
+
run: async (cmd) => { io.ran.push(cmd); return { ok: io.ran.length >= (w.artifactOkAt ?? 1) }; },
|
|
24
|
+
runningLanes: async () => w.lanes,
|
|
25
|
+
batches: async () => w.batches,
|
|
26
|
+
setParallel: async (id, k) => { par.push([id, k]); },
|
|
27
|
+
gh: async (a) => {
|
|
28
|
+
calls.push(a);
|
|
29
|
+
const j = a.join(" ");
|
|
30
|
+
const pm = w.pm?.(a); if (pm !== undefined) return pm;
|
|
31
|
+
if (a[0] === "pr" && a[1] === "list" && a.includes("--state") && a[a.indexOf("--state") + 1] === "open") return JSON.stringify(a.includes("--head") ? w.releasePr : w.openStaging);
|
|
32
|
+
if (a[0] === "pr" && a[1] === "list") return JSON.stringify([]);
|
|
33
|
+
if (a[0] === "pr" && a[1] === "create") return "https://github.com/o/r/pull/9";
|
|
34
|
+
if (a[0] === "pr" && a[1] === "view" && j.includes("--json state,mergeCommit,headRefOid")) return JSON.stringify({ state: w.prState ?? "OPEN", mergeCommit: w.prState === "MERGED" ? { oid: "m".repeat(40) } : null, headRefOid: HEAD });
|
|
35
|
+
if (j.includes("--json headRefOid")) return JSON.stringify({ headRefOid: HEAD });
|
|
36
|
+
if (j.includes("--json comments")) return JSON.stringify({ comments: w.comments });
|
|
37
|
+
if (a[0] === "api") return JSON.stringify(w.gate ? [{ name: "forge/deploy-gate", conclusion: w.gate }] : []);
|
|
38
|
+
if (a[0] === "pr" && a[1] === "merge") return "";
|
|
39
|
+
throw new Error(`unexpected gh ${j}`);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return io;
|
|
43
|
+
}
|
|
44
|
+
const ok = async () => ({ ok: true });
|
|
45
|
+
|
|
46
|
+
describe("release job (#5211)", () => {
|
|
47
|
+
const promote = async (world, { opts = {}, config = {} } = {}) => {
|
|
48
|
+
const io = fakeIo(world), root = tmp(), id = newReleaseId();
|
|
49
|
+
// Real preflight/release-pr/promotion, with review/fixes/post-merge replaced by no-ops.
|
|
50
|
+
const mod = await import("./release.mjs");
|
|
51
|
+
const out = await mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts, config, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ review: ok, fixes: ok, "post-merge": ok }) });
|
|
52
|
+
return { io, out, root, id };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
it("R3: stops at GATE_PASS without --merge / auto_merge and prints the command; never merges", async () => {
|
|
56
|
+
const { io, out } = await promote({});
|
|
57
|
+
assert.equal(out.status, "stopped");
|
|
58
|
+
assert.ok(io.printed.some((l) => l.includes(`gh pr merge 7 --repo ${REPO} --merge --match-head-commit ${HEAD}`)));
|
|
59
|
+
assert.ok(!io.calls.some((a) => a[0] === "pr" && a[1] === "merge"));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("R3: --merge merges with --match-head-commit when forge/deploy-gate is success", async () => {
|
|
63
|
+
const { io, out } = await promote({}, { opts: { merge: true } });
|
|
64
|
+
assert.equal(out.status, "done");
|
|
65
|
+
assert.ok(io.calls.some((a) => a[1] === "merge" && a.includes("--match-head-commit") && a.includes(HEAD)));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("R3: release.auto_merge merges too; a non-success deploy-gate does not", async () => {
|
|
69
|
+
const a = await promote({}, { config: { autoMerge: true } });
|
|
70
|
+
assert.equal(a.out.status, "done");
|
|
71
|
+
for (const gate of ["pending", "failure", null]) {
|
|
72
|
+
const b = await promote({ gate }, { opts: { merge: true } });
|
|
73
|
+
assert.equal(b.out.status, "stopped", String(gate));
|
|
74
|
+
assert.ok(!b.io.calls.some((c) => c[1] === "merge"));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("#5266: a release PR merged by hand moves to post-merge with the merge sha, without the opt-in stop", async () => {
|
|
79
|
+
const io = fakeIo({ prState: "MERGED" }), root = tmp(), id = newReleaseId();
|
|
80
|
+
const mod = await import("./release.mjs");
|
|
81
|
+
let seen = null;
|
|
82
|
+
const out = await mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: {}, config: {}, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ review: ok, fixes: ok, "post-merge": async (c) => { seen = c.state.steps.promotion.result; return {}; } }) });
|
|
83
|
+
assert.equal(out.status, "done");
|
|
84
|
+
assert.equal(seen.alreadyMerged, true);
|
|
85
|
+
assert.equal(seen.mergeCommit, "m".repeat(40));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("#5266: --merge resume on an already-merged PR does not call gh pr merge", async () => {
|
|
89
|
+
const { io, out } = await promote({ prState: "MERGED" }, { opts: { merge: true } });
|
|
90
|
+
assert.equal(out.status, "done");
|
|
91
|
+
assert.ok(!io.calls.some((a) => a[0] === "pr" && a[1] === "merge"));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("#5266: a release PR closed without merging stops", async () => {
|
|
95
|
+
const { io, out } = await promote({ prState: "CLOSED" }, { opts: { merge: true } });
|
|
96
|
+
assert.equal(out.status, "stopped");
|
|
97
|
+
assert.ok(!io.calls.some((a) => a[0] === "pr" && a[1] === "merge"));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("R3: no GATE_PASS marker never merges", async () => {
|
|
101
|
+
const { io, out } = await promote({ comments: [{ body: "FORGE:GATE_FAILURE" }] }, { opts: { merge: true } });
|
|
102
|
+
assert.equal(out.status, "stopped");
|
|
103
|
+
assert.ok(!io.calls.some((c) => c[1] === "merge"));
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("preflight refuses while a lane runs; nothing is held", async () => {
|
|
107
|
+
const { io, out } = await promote({ lanes: [{ batch: "b1", issue: 3 }], batches: [{ id: "b1", k: 4 }] });
|
|
108
|
+
assert.equal(out.status, "refused");
|
|
109
|
+
assert.match(out.reason, /b1#3/);
|
|
110
|
+
assert.deepEqual(io.par, []);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("preflight refuses while PRs to the staging branch are open", async () => {
|
|
114
|
+
const { io, out } = await promote({ openStaging: [{ number: 12 }], batches: [{ id: "b1", k: 4 }] });
|
|
115
|
+
assert.equal(out.status, "refused");
|
|
116
|
+
assert.match(out.reason, /#12/);
|
|
117
|
+
assert.deepEqual(io.par, []);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("preflight holds batches at K=1 and restores the previous K at the end", async () => {
|
|
121
|
+
const { io, out, root, id } = await promote({ batches: [{ id: "b1", k: 4 }, { id: "b2", k: 2 }] });
|
|
122
|
+
assert.equal(out.status, "stopped");
|
|
123
|
+
assert.deepEqual(io.par, [["b1", 1], ["b2", 1], ["b1", 4], ["b2", 2]]);
|
|
124
|
+
assert.ok(openRelease(root, id).load().held.every((h) => h.restored));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("release PR: reuses an open one; otherwise creates it with the bundle list", async () => {
|
|
128
|
+
const a = await promote({});
|
|
129
|
+
assert.ok(!a.io.calls.some((c) => c[1] === "create"));
|
|
130
|
+
const b = await promote({ releasePr: [] });
|
|
131
|
+
const create = b.io.calls.find((c) => c[1] === "create");
|
|
132
|
+
assert.ok(create && create.includes("--head") && create.includes("staging") && create.includes("main"));
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("R5: a killed job resumes from the last completed step", async () => {
|
|
136
|
+
const io = fakeIo(), root = tmp(), id = newReleaseId();
|
|
137
|
+
const mod = await import("./release.mjs");
|
|
138
|
+
const ran = [];
|
|
139
|
+
const rec = (n, fn) => async (ctx) => { ran.push(n); return fn(ctx); };
|
|
140
|
+
const base = mod.withStubs({ review: ok, fixes: ok, "post-merge": ok });
|
|
141
|
+
const kill = async () => { throw new Error("killed"); };
|
|
142
|
+
const first = { ...base, preflight: rec("preflight", base.preflight), "release-pr": rec("release-pr", base["release-pr"]), review: kill };
|
|
143
|
+
await assert.rejects(() => mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config: {}, branches: {}, steps: first }), /killed/);
|
|
144
|
+
const st = openRelease(root, id).load();
|
|
145
|
+
assert.deepEqual(Object.keys(st.steps), ["preflight", "release-pr"]);
|
|
146
|
+
const second = { ...base, preflight: rec("preflight2", base.preflight), "release-pr": rec("release-pr2", base["release-pr"]) };
|
|
147
|
+
const out = await mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config: {}, branches: {}, steps: second });
|
|
148
|
+
assert.equal(out.status, "done");
|
|
149
|
+
assert.deepEqual(ran, ["preflight", "release-pr"]); // preflight/release-pr not run again
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("unfinished steps return a blocked result that names the manual path; the job exits blocked", async () => {
|
|
153
|
+
for (const r of [await reviewStep({}), await fixStep({})]) { assert.equal(r.blocked, true); assert.match(r.reason, /manual path/); }
|
|
154
|
+
const io = fakeIo(), root = tmp();
|
|
155
|
+
io.review = { pre: async () => ({ code: 1, data: null, lines: ["stopped"] }) }; // the review step runs against a seam, never a real repo
|
|
156
|
+
const out = await (await import("./release.mjs")).runRelease({ io, repo: REPO, root, mounts: DISK, id: newReleaseId(), opts: {}, config: {}, branches: {} });
|
|
157
|
+
assert.equal(out.status, "blocked");
|
|
158
|
+
assert.equal(out.step, "review");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("state is written atomically under FORGEDOCK_RELEASE_DIR and is private", async () => {
|
|
162
|
+
const root = tmp(), id = newReleaseId();
|
|
163
|
+
openRelease(root, id, DISK).save({ v: 1 });
|
|
164
|
+
assert.deepEqual(JSON.parse(readFileSync(join(root, id, "state.json"), "utf8")), { v: 1 });
|
|
165
|
+
assert.ok(!existsSync(join(root, id, `state.json.tmp-${process.pid}`)));
|
|
166
|
+
assert.throws(() => openRelease(root, "../x"), /invalid release id/);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("readReleaseConfig reads auto_merge / artifact_check / version_sync", () => {
|
|
170
|
+
assert.deepEqual(readReleaseConfig("release:\n auto_merge: true\n artifact_check: npm view x\n version_sync: true\n"), { autoMerge: true, artifactCheck: "npm view x", versionSync: true, publishWorkflow: null });
|
|
171
|
+
assert.deepEqual(readReleaseConfig(""), { autoMerge: false, artifactCheck: null, versionSync: false, publishWorkflow: null });
|
|
172
|
+
assert.equal(readReleaseConfig("release:\n publish_workflow: pub.yml\n").publishWorkflow, "pub.yml");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("CLI: rejects unknown options and exits 3 on a blocked step, naming the resume command", async () => {
|
|
176
|
+
const root = tmp(), io = fakeIo();
|
|
177
|
+
await assert.rejects(() => releaseFromCli(["--bogus"], { io, env: { FORGEDOCK_RELEASE_DIR: root }, cwd: root, mounts: DISK }), /unknown option/);
|
|
178
|
+
const code = await releaseFromCli(["--repo", REPO], { io, env: { FORGEDOCK_RELEASE_DIR: root }, cwd: root, mounts: DISK });
|
|
179
|
+
assert.equal(code, 3);
|
|
180
|
+
assert.ok(io.printed.some((l) => /forgedock release --resume r\d/.test(l)));
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("release post-merge step (#5213)", () => {
|
|
185
|
+
const SHA = "b".repeat(40);
|
|
186
|
+
const PKG = Buffer.from(JSON.stringify({ version: "1.2.3" })).toString("base64");
|
|
187
|
+
/** gh answers for the post-merge calls; `o` tunes them. */
|
|
188
|
+
const pmWorld = (o = {}) => {
|
|
189
|
+
const st = { runs: o.runs ?? [[{ databaseId: 5, status: "completed", conclusion: "success" }]], runCalls: 0, dispatched: 0, syncPrs: o.syncPrs ?? [], created: 0 };
|
|
190
|
+
return {
|
|
191
|
+
st,
|
|
192
|
+
pm: (a) => {
|
|
193
|
+
const j = a.join(" ");
|
|
194
|
+
if (a[0] === "pr" && a[1] === "view" && j.includes("mergeCommit")) return JSON.stringify({ state: o.prState ?? "MERGED", mergeCommit: { oid: SHA } });
|
|
195
|
+
if (a[0] === "run" && a[1] === "list") { assert.ok(j.includes(`--commit ${SHA}`) && j.includes(`--workflow ${o.wf ?? "publish.yml"}`)); const r = st.runs[Math.min(st.runCalls++, st.runs.length - 1)]; return JSON.stringify(r); }
|
|
196
|
+
if (a[0] === "workflow" && a[1] === "run") { st.dispatched++; assert.ok(a.includes("main")); return ""; }
|
|
197
|
+
if (a[0] === "api" && j.includes("contents/package.json")) return PKG;
|
|
198
|
+
if (a[0] === "api" && j.includes("branches/chore/sync-version-1.2.3")) { if (o.noBranch) throw new Error("404"); return "x"; }
|
|
199
|
+
if (a[0] === "pr" && a[1] === "list" && j.includes("chore/sync-version")) return JSON.stringify(st.syncPrs);
|
|
200
|
+
if (a[0] === "pr" && a[1] === "create") { st.created++; assert.ok(a.includes("staging") && a.includes("chore/sync-version-1.2.3")); return "https://github.com/o/r/pull/30"; }
|
|
201
|
+
if (a[0] === "pr" && a[1] === "view" && j.includes("statusCheckRollup")) return JSON.stringify({ state: "OPEN", headRefOid: "c".repeat(40), statusCheckRollup: o.checks ?? [{ conclusion: "SUCCESS" }] });
|
|
202
|
+
if (a[0] === "pr" && a[1] === "merge" && Number(a[2]) >= 30) return "";
|
|
203
|
+
return undefined;
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
const run = (o = {}, config = {}) => {
|
|
208
|
+
const w = pmWorld(o), io = fakeIo({ pm: w.pm, ...o });
|
|
209
|
+
const ctx = { io, repo: REPO, def: "main", staging: "staging", config: { postMerge: { publishPolls: 2, runPolls: 2, branchPolls: 2, checkPolls: 2, artifactTries: 3 }, ...config }, state: { steps: { "release-pr": { result: { pr: 7 } } } } };
|
|
210
|
+
return postMergeStep(ctx).then((out) => ({ out, io, st: w.st }));
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
it("R1: a publish run for the merge commit is confirmed; nothing is dispatched", async () => {
|
|
214
|
+
const { out, st } = await run();
|
|
215
|
+
assert.equal(out.published, true);
|
|
216
|
+
assert.equal(out.run, 5);
|
|
217
|
+
assert.equal(st.dispatched, 0);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("R2: no run appears -> one is dispatched on the default branch, then awaited", async () => {
|
|
221
|
+
const { out, st } = await run({ runs: [[], [], [{ databaseId: 8, status: "completed", conclusion: "success" }]] });
|
|
222
|
+
assert.equal(out.published, true);
|
|
223
|
+
assert.equal(out.dispatched, true);
|
|
224
|
+
assert.equal(st.dispatched, 1);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("R2: a custom release.publish_workflow is used", async () => {
|
|
228
|
+
const { out } = await run({ wf: "pub.yml" }, { publishWorkflow: "pub.yml" });
|
|
229
|
+
assert.equal(out.published, true);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("blocked when no run appears even after the dispatch, or the run fails or never finishes", async () => {
|
|
233
|
+
const a = await run({ runs: [[]] });
|
|
234
|
+
assert.equal(a.out.blocked, true); assert.equal(a.st.dispatched, 1);
|
|
235
|
+
const b = await run({ runs: [[{ databaseId: 1, status: "completed", conclusion: "failure" }]] });
|
|
236
|
+
assert.match(b.out.reason, /failure/);
|
|
237
|
+
const c = await run({ runs: [[{ databaseId: 1, status: "in_progress", conclusion: null }]] });
|
|
238
|
+
assert.match(c.out.reason, /did not finish/);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("stopped (not blocked) while the release PR is not merged", async () => {
|
|
242
|
+
const { out, st } = await run({ prState: "OPEN" });
|
|
243
|
+
assert.equal(out.stopped, true);
|
|
244
|
+
assert.equal(st.runCalls, 0);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("R3: artifact_check is polled with exponential backoff until it passes; exhausting it blocks", async () => {
|
|
248
|
+
const a = await run({ artifactOkAt: 3 }, { artifactCheck: "npm view x@1" });
|
|
249
|
+
assert.equal(a.out.artifact, true);
|
|
250
|
+
assert.deepEqual(a.io.ran, ["npm view x@1", "npm view x@1", "npm view x@1"]);
|
|
251
|
+
assert.deepEqual(a.io.sleeps.slice(-2), [5000, 10000]);
|
|
252
|
+
const b = await run({ artifactOkAt: 99 }, { artifactCheck: "npm view x@1" });
|
|
253
|
+
assert.equal(b.out.blocked, true);
|
|
254
|
+
assert.match(b.out.reason, /artifact_check/);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("R4: version_sync opens the sync PR to staging and merges it with --match-head-commit when green", async () => {
|
|
258
|
+
const { out, st, io } = await run({}, { versionSync: true });
|
|
259
|
+
assert.equal(st.created, 1);
|
|
260
|
+
assert.equal(out.sync.merged, true);
|
|
261
|
+
assert.ok(io.calls.some((a) => a[1] === "merge" && a.includes("30") && a.includes("--match-head-commit") && a.includes("c".repeat(40))));
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("version_sync reuses an open sync PR, skips a merged one, and never merges red or check-less PRs", async () => {
|
|
265
|
+
const open = await run({ syncPrs: [{ number: 31, state: "OPEN" }] }, { versionSync: true });
|
|
266
|
+
assert.equal(open.st.created, 0);
|
|
267
|
+
assert.ok(open.io.calls.some((a) => a[1] === "merge" && a.includes("31")));
|
|
268
|
+
const merged = await run({ syncPrs: [{ number: 32, state: "MERGED" }] }, { versionSync: true });
|
|
269
|
+
assert.equal(merged.out.sync.merged, true);
|
|
270
|
+
assert.ok(!merged.io.calls.some((a) => a[1] === "merge"));
|
|
271
|
+
for (const checks of [[], [{ conclusion: "FAILURE" }], [{ conclusion: "SUCCESS" }, { status: "IN_PROGRESS", state: "PENDING" }]]) {
|
|
272
|
+
const r = await run({ syncPrs: [{ number: 33, state: "OPEN" }], checks }, { versionSync: true });
|
|
273
|
+
assert.equal(r.out.blocked, true, JSON.stringify(checks));
|
|
274
|
+
assert.ok(!r.io.calls.some((a) => a[1] === "merge"));
|
|
275
|
+
}
|
|
276
|
+
const nb = await run({ noBranch: true }, { versionSync: true });
|
|
277
|
+
assert.equal(nb.out.blocked, true);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("R1: through the job, a blocked post-merge is retried on resume and finishes once the run exists", async () => {
|
|
281
|
+
const mod = await import("./release.mjs");
|
|
282
|
+
const root = tmp(), id = newReleaseId();
|
|
283
|
+
const world = (runs) => pmWorld({ runs });
|
|
284
|
+
const go = async (runs) => {
|
|
285
|
+
const io = fakeIo({ pm: world(runs).pm });
|
|
286
|
+
const config = { postMerge: { publishPolls: 1, runPolls: 1 } };
|
|
287
|
+
return mod.runRelease({ io, repo: REPO, root, mounts: DISK, id, opts: { merge: true }, config, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ review: ok, fixes: ok }) });
|
|
288
|
+
};
|
|
289
|
+
assert.equal((await go([[{ databaseId: 1, status: "completed", conclusion: "failure" }]])).status, "blocked");
|
|
290
|
+
assert.equal((await go([[{ databaseId: 2, status: "completed", conclusion: "success" }]])).status, "done");
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
describe("snapshot releases (#5276)", () => {
|
|
295
|
+
const S = "5".repeat(40), F = "f".repeat(40);
|
|
296
|
+
/** git fake for a clean cut and an unmodified chain; `revList` is what `rev-list snapshot..head` answers. */
|
|
297
|
+
const gitFake = (revList = "") => (a) => {
|
|
298
|
+
if (a[0] === "rev-parse" && a[1].startsWith("refs/remotes/")) return `${S}\n`;
|
|
299
|
+
if (a[0] === "rev-list") return revList;
|
|
300
|
+
return "";
|
|
301
|
+
};
|
|
302
|
+
const snapWorld = (extra = {}) => ({
|
|
303
|
+
releasePr: [], git: gitFake(), lanes: [{ batch: "b1", issue: 7 }], openStaging: [{ number: 5 }], batches: [{ id: "b1", k: 20 }],
|
|
304
|
+
pm: (a) => (a[1] === "view" && a.includes("body") ? JSON.stringify({ body: "" }) : a[1] === "edit" ? "" : undefined), ...extra,
|
|
305
|
+
});
|
|
306
|
+
const go = async (world, config = { mode: "snapshot" }, opts = { merge: true }) => {
|
|
307
|
+
const io = fakeIo(world);
|
|
308
|
+
if (world.git) io.git = world.git;
|
|
309
|
+
const mod = await import("./release.mjs");
|
|
310
|
+
const out = await mod.runRelease({ io, repo: REPO, root: tmp(), mounts: DISK, id: newReleaseId(), opts, config, branches: { staging: "staging", default: "main" }, steps: mod.withStubs({ review: ok, fixes: ok, "post-merge": ok }) });
|
|
311
|
+
return { io, out };
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
it("readReleaseConfig reads mode / branch_pattern / fix_mode only when set; unknown values fall back", () => {
|
|
315
|
+
assert.deepEqual(readReleaseConfig("release:\n mode: snapshot\n branch_pattern: \"rel/{date}-{n}\"\n fix_mode: recut\n"), { autoMerge: false, artifactCheck: null, versionSync: false, publishWorkflow: null, mode: "snapshot", branchPattern: "rel/{date}-{n}", fixMode: "recut" });
|
|
316
|
+
assert.deepEqual(readReleaseConfig("release:\n mode: weird\n fix_mode: nope\n").mode, "freeze");
|
|
317
|
+
assert.equal(readReleaseConfig("release:\n fix_mode: nope\n").fixMode, "cherry-pick");
|
|
318
|
+
assert.equal("mode" in readReleaseConfig(""), false);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("R1/R6: with lanes running and PRs open on staging, the cut refuses nothing, leaves every K alone and opens release/<id> -> main", async () => {
|
|
322
|
+
const { io, out } = await go(snapWorld());
|
|
323
|
+
assert.equal(out.status, "done");
|
|
324
|
+
assert.deepEqual(io.par, [], "no batch K was set (no hold, no restore)");
|
|
325
|
+
const create = io.calls.find((a) => a[1] === "create");
|
|
326
|
+
assert.equal(create[create.indexOf("--head") + 1], "release/20231114-1");
|
|
327
|
+
assert.equal(create[create.indexOf("--base") + 1], "main");
|
|
328
|
+
assert.ok(!io.calls.some((a) => (a[1] === "create" || a.includes("open")) && a[a.indexOf("--head") + 1] === "staging"), "staging is never the PR head");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("R8: promotion still merges with --match-head-commit", async () => {
|
|
332
|
+
const { io } = await go(snapWorld());
|
|
333
|
+
assert.ok(io.calls.some((a) => a[1] === "merge" && a.includes("--merge") && a.includes("--match-head-commit") && a.includes(HEAD)));
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it("R3: a commit on the release branch that is not a recorded cherry-pick stops promotion; nothing is merged", async () => {
|
|
337
|
+
const { io, out } = await go(snapWorld({ git: gitFake(`${F} ${S}\n`) }));
|
|
338
|
+
assert.equal(out.status, "stopped");
|
|
339
|
+
assert.match(out.reason, /not snapshot \+ recorded cherry-picks: 1 commit\(s\)/);
|
|
340
|
+
assert.ok(!io.calls.some((a) => a[1] === "merge"));
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("R11: a release branch already in flight refuses the cut", async () => {
|
|
344
|
+
const world = snapWorld({ git: (a) => (a[0] === "ls-remote" ? `${S}\trefs/heads/release/20231114-1\n` : "") });
|
|
345
|
+
const { out } = await go(world);
|
|
346
|
+
assert.equal(out.status, "refused");
|
|
347
|
+
assert.match(out.reason, /already in flight/);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("R4: freeze mode (and no mode) keeps the refusal on running lanes, the K=1 hold and staging as PR head", async () => {
|
|
351
|
+
for (const config of [{ mode: "freeze" }, {}]) {
|
|
352
|
+
const { io, out } = await go({ lanes: [{ batch: "b1", issue: 7 }] }, config);
|
|
353
|
+
assert.equal(out.status, "refused");
|
|
354
|
+
assert.match(out.reason, /lanes of o\/r are running/);
|
|
355
|
+
}
|
|
356
|
+
const { io, out } = await go({ batches: [{ id: "b1", k: 20 }], releasePr: [] }, { mode: "freeze" });
|
|
357
|
+
assert.equal(out.status, "done");
|
|
358
|
+
assert.deepEqual(io.par, [["b1", 1], ["b1", 20]]);
|
|
359
|
+
const create = io.calls.find((a) => a[1] === "create");
|
|
360
|
+
assert.equal(create[create.indexOf("--head") + 1], "staging");
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("R10: `release verify <sha>` exits 0 for a head that is the snapshot, 1 for a PR without a record", async () => {
|
|
364
|
+
const rec = { v: 1, snapshot: S, picks: [] };
|
|
365
|
+
const mk = (body) => { const io = fakeIo({ pm: (a) => (a[0] === "api" ? JSON.stringify([{ number: 9, body }]) : undefined) }); io.git = gitFake(); io.git = ((g) => (a, o) => (a[0] === "rev-parse" && !a[1].startsWith("refs/") ? `${S}\n` : g(a, o)))(io.git); return io; };
|
|
366
|
+
const good = mk(`x\n<!-- FORGE:RELEASE ${JSON.stringify(rec)} -->`);
|
|
367
|
+
assert.equal(await releaseFromCli(["verify", S.slice(0, 12), "--repo", REPO], { io: good, cwd: tmp() }), 0);
|
|
368
|
+
assert.ok(good.printed.some((l) => /: ok \(snapshot \+ 0 cherry-pick/.test(l)));
|
|
369
|
+
const bad = mk("no record");
|
|
370
|
+
assert.equal(await releaseFromCli(["verify", S, "--repo", REPO], { io: bad, cwd: tmp() }), 1);
|
|
371
|
+
await assert.rejects(releaseFromCli(["verify"], { io: bad, cwd: tmp() }), /needs a commit sha/);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("R9: post-merge deletes release/<id> after a snapshot release, and touches no branch otherwise", async () => {
|
|
375
|
+
const pm = (a) => (a[1] === "view" ? JSON.stringify({ state: "MERGED", mergeCommit: { oid: "b".repeat(40) } }) : a[0] === "run" ? JSON.stringify([{ databaseId: 5, status: "completed", conclusion: "success" }]) : undefined);
|
|
376
|
+
const step = async (release) => {
|
|
377
|
+
const io = fakeIo({ pm }), pushes = [];
|
|
378
|
+
io.git = (a) => { pushes.push(a); return ""; };
|
|
379
|
+
const out = await postMergeStep({ io, repo: REPO, def: "main", staging: "staging", config: {}, state: { release, steps: { "release-pr": { result: { pr: 7 } } } } });
|
|
380
|
+
return { out, pushes };
|
|
381
|
+
};
|
|
382
|
+
const snap = await step({ branch: "release/20231114-1" });
|
|
383
|
+
assert.equal(snap.out.published, true);
|
|
384
|
+
assert.deepEqual(snap.pushes, [["push", "--quiet", "origin", "--delete", "release/20231114-1"]]);
|
|
385
|
+
assert.deepEqual((await step(undefined)).pushes, []);
|
|
386
|
+
});
|
|
387
|
+
});
|
package/bin/lean/render.mjs
CHANGED
|
@@ -125,7 +125,7 @@ const CONTRACT_BLOCK_RE = /<summary>contract\.json \(sha256 ([0-9a-f]{12})(?:, i
|
|
|
125
125
|
export function renderContract(c, hash, { compact = false, scope = null } = {}) {
|
|
126
126
|
const json = `<details><summary>contract.json (sha256 ${hash}${scope ? `, issue ${scope}` : ""})</summary>\n\n\`\`\`json\n${contractJson(c)}\n\`\`\`\n</details>`;
|
|
127
127
|
if (compact) return `## Builder Contract (frozen \`${hash}\`)\n\n${c.requirements.length} requirement(s), ${(c.deliverables ?? []).length} deliverable(s); the tables are omitted because the contract is large.\n\n${json}`;
|
|
128
|
-
const disp = (r) => `${r.disposition}${r.verify === "out_of_band" ? `, verified out of band${r.evidence ? ` (${escl(r.evidence)})` : ""}` : ""}${r.tracked ? ` → ${r.tracked}` : ["defer", "post-deploy"].includes(r.disposition) ? " (filed after review accepts it)" : ""}${r.why ? ` (${escl(r.why)})` : ""}`;
|
|
128
|
+
const disp = (r) => `${r.disposition === "post-deploy" && /\[type:(?:e2e|manual)\]/i.test(String(r.quote ?? "")) ? "post-deploy, transferred to the epic (not met)" : r.disposition}${r.verify === "out_of_band" ? `, verified out of band${r.evidence ? ` (${escl(r.evidence)})` : ""}` : ""}${r.tracked ? ` → ${r.tracked}` : ["defer", "post-deploy"].includes(r.disposition) ? " (filed after review accepts it)" : ""}${r.why ? ` (${escl(r.why)})` : ""}`;
|
|
129
129
|
const req = c.requirements.map((r) => `| ${esc(r.id)} | ${esc(r.quote)} | ${esc(disp(r))} |`).join("\n");
|
|
130
130
|
const del = (c.deliverables ?? []).map((d) => `| ${esc(d.id)} | \`${esc(d.path)}\` | ${esc(d.change)} | ${esc((d.requirements ?? []).join(", "))} |`).join("\n");
|
|
131
131
|
const dec = Array.isArray(c.decisions) && c.decisions.length // forge#4165: decision provenance
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// Re-plan loop (#5342): a `design-invalidated` block files one spike-amendment issue, holds the affected open siblings
|
|
4
|
+
// behind it with the existing `**Depends on**` edge, and `replan apply` re-evaluates each child once the amendment merged.
|
|
5
|
+
// Pure and deterministic: no LLM call. The amendment lane writes the per-child dispositions; the engine only applies them.
|
|
6
|
+
import { parentOf } from "./context.mjs";
|
|
7
|
+
import { selectChildren, readChildList } from "./autochildren.mjs";
|
|
8
|
+
|
|
9
|
+
export const REPLAN_MARKER = "FORGE:REPLAN";
|
|
10
|
+
export const CHILD_DISPOSITIONS = Object.freeze(["unchanged", "re-scoped", "dropped"]);
|
|
11
|
+
export const DISPOSITIONS_TAG = "forge-replan-dispositions";
|
|
12
|
+
const TEXT_MAX = 600;
|
|
13
|
+
|
|
14
|
+
const text = (v, max = TEXT_MAX) => (typeof v === "string" ? v.replace(/\s+/g, " ").trim().slice(0, max) : "");
|
|
15
|
+
const issueNo = (v) => { const n = Number(String(v ?? "").replace(/^#/, "")); return Number.isSafeInteger(n) && n > 0 ? n : null; };
|
|
16
|
+
const strList = (v) => [...new Set((Array.isArray(v) ? v : []).filter((x) => typeof x === "string").map((x) => x.trim().replace(/^\.?\/+/, "")).filter(Boolean))];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The typed `design-invalidated` block: {decision, why} required; `epic` (the epic or tracker to amend), `supersedes` (a
|
|
20
|
+
* decision-register id), `paths` (files of the invalidated interface) optional. Null when decision or why is missing.
|
|
21
|
+
*/
|
|
22
|
+
export function normaliseInvalidation(block, issue = null) {
|
|
23
|
+
const decision = text(block?.decision), why = text(block?.why);
|
|
24
|
+
if (!decision || !why) return null;
|
|
25
|
+
const epic = issueNo(block?.epic);
|
|
26
|
+
return { decision, why, epic: epic && epic !== Number(issue) ? epic : null, supersedes: text(block?.supersedes, 60) || null, paths: strList(block?.paths ?? block?.anchors) };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The epic of `issue`: the block's own `epic`, else the `**Parent**: #N` line of the issue body. */
|
|
30
|
+
export const epicOf = (inv, body) => inv?.epic ?? parentOf(body ?? "");
|
|
31
|
+
|
|
32
|
+
/** Hidden record on the amendment issue body, read back to find it again (idempotent filing) and to reach its epic. */
|
|
33
|
+
const recordOf = (body) => {
|
|
34
|
+
const m = new RegExp(`<!--\\s*${REPLAN_MARKER}\\s*(\\{[\\s\\S]*?\\})\\s*-->`).exec(String(body ?? ""));
|
|
35
|
+
if (!m) return null;
|
|
36
|
+
try { const j = JSON.parse(m[1]); return issueNo(j?.epic) ? { epic: issueNo(j.epic), from: issueNo(j.from) } : null; } catch { return null; }
|
|
37
|
+
};
|
|
38
|
+
export const amendmentEpic = (body) => recordOf(body)?.epic ?? null;
|
|
39
|
+
|
|
40
|
+
/** Open amendment issue of `epic` in one open-issue list, or null (a second invalidation joins it, never files another). */
|
|
41
|
+
export function findAmendment(list, epic) {
|
|
42
|
+
const hit = (list ?? []).find((it) => recordOf(it?.body)?.epic === epic);
|
|
43
|
+
return hit ? hit.number : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Open children of `epic` an invalidation touches: every open child, or only those naming one of `paths` when given. `self` is excluded. */
|
|
47
|
+
export function affectedChildren({ list, epic, self = null, paths = [] }) {
|
|
48
|
+
const kids = selectChildren({ list, roots: [epic], skip: self ? [self] : [] });
|
|
49
|
+
if (!paths.length) return kids;
|
|
50
|
+
const by = new Map((list ?? []).map((it) => [it.number, it]));
|
|
51
|
+
return kids.filter((n) => paths.some((p) => String(by.get(n)?.body ?? "").includes(p)));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const amendmentTitle = (inv, epic) => `spike amendment: ${inv.decision.slice(0, 80)} no longer holds (epic #${epic})`;
|
|
55
|
+
|
|
56
|
+
/** Body of the amendment issue: the invalidated decision, why, the held children and the disposition block it must produce. */
|
|
57
|
+
export function amendmentBody({ inv, epic, from, children }) {
|
|
58
|
+
const rec = JSON.stringify({ epic, from });
|
|
59
|
+
return [`<!-- ${REPLAN_MARKER} ${rec} -->`, `**Parent**: #${epic}`, "",
|
|
60
|
+
"## Spike amendment", `Invalidated by #${from}: **${inv.decision}**`, "", `Why: ${inv.why}`, ...(inv.supersedes ? ["", `Supersedes decision ${inv.supersedes}.`] : []), "",
|
|
61
|
+
"Update the spike and the epic so the design holds again, and record the replacement decision (`supersedes`). Then give every held child a disposition in one fenced block:", "",
|
|
62
|
+
`\`\`\`${DISPOSITIONS_TAG}`, JSON.stringify({ children: Object.fromEntries(children.map((n) => [n, { disposition: "unchanged" }])) }, null, 2), "```", "",
|
|
63
|
+
`\`${CHILD_DISPOSITIONS.join("`, `")}`.concat("` (a re-scoped child carries `body`, regenerated from the amended design; a dropped child is closed as superseded)."), "",
|
|
64
|
+
"A re-scoped child that is user-visible (a page or UI) must say in its body to run `/design` before build, so the rendered page is judged before the lanes merge (#5330).", "",
|
|
65
|
+
`Held until this merges: ${children.length ? children.map((n) => `#${n}`).join(", ") : "none"}.`].join("\n");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const dependsLine = (n) => `**Depends on**: #${n}`;
|
|
69
|
+
const holdRe = (n) => new RegExp(`^[ \\t]*\\*\\*Depends on\\*\\*: #${n}[ \\t]*$\\n?`, "gim");
|
|
70
|
+
|
|
71
|
+
/** `body` with the hold edge on `amendment` added (once). */
|
|
72
|
+
export function holdEdge(body, amendment) {
|
|
73
|
+
const b = String(body ?? "");
|
|
74
|
+
return holdRe(amendment).test(b) ? b : `${b.replace(/\s+$/, "")}\n\n${dependsLine(amendment)}\n`;
|
|
75
|
+
}
|
|
76
|
+
/** `body` without the hold edge on `amendment`. */
|
|
77
|
+
export const releaseEdge = (body, amendment) => String(body ?? "").replace(holdRe(amendment), "").replace(/\s+$/, "") + "\n";
|
|
78
|
+
|
|
79
|
+
/** The last disposition block in the texts (issue body first, then comments): `{children:{N:{disposition, body?}}}` or null. */
|
|
80
|
+
export function parseDispositions(texts) {
|
|
81
|
+
const re = new RegExp(`\`\`\`${DISPOSITIONS_TAG}\\s*\\n([\\s\\S]*?)\`\`\``, "g");
|
|
82
|
+
let last = null;
|
|
83
|
+
for (const t of texts ?? []) for (const m of String(t ?? "").matchAll(re)) { try { last = JSON.parse(m[1]); } catch { /* an unparsable block is skipped */ } }
|
|
84
|
+
return last && typeof last.children === "object" && last.children ? last : null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Fail closed: every affected child needs one known disposition; a re-scoped child needs its regenerated body.
|
|
89
|
+
* @returns {{ok:boolean, problem?:string, rows?:{n:number, disposition:string, body?:string}[]}}
|
|
90
|
+
*/
|
|
91
|
+
export function validateDispositions(d, affected) {
|
|
92
|
+
const rows = [];
|
|
93
|
+
for (const n of affected) {
|
|
94
|
+
const e = d?.children?.[n] ?? d?.children?.[`#${n}`];
|
|
95
|
+
if (!e || !CHILD_DISPOSITIONS.includes(e.disposition)) return { ok: false, problem: `open child #${n} has no valid disposition (${CHILD_DISPOSITIONS.join(", ")})` };
|
|
96
|
+
if (e.disposition === "re-scoped" && !text(e.body, 100000)) return { ok: false, problem: `re-scoped child #${n} carries no regenerated body` };
|
|
97
|
+
rows.push({ n, disposition: e.disposition, ...(e.disposition === "re-scoped" ? { body: String(e.body) } : {}) });
|
|
98
|
+
}
|
|
99
|
+
return { ok: true, rows };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The epic body with each child's checklist line marked once: dropped is checked and struck, re-scoped is annotated. */
|
|
103
|
+
export function renderEpicChecklist(epicBody, rows, amendment) {
|
|
104
|
+
let out = String(epicBody ?? "");
|
|
105
|
+
for (const r of rows) {
|
|
106
|
+
if (r.disposition === "unchanged") continue;
|
|
107
|
+
const re = new RegExp(`^([ \\t]*[-*+][ \\t]+)\\[[ xX]\\]([ \\t]+)(.*#${r.n}\\b.*)$`, "gm");
|
|
108
|
+
out = out.replace(re, (_m, pre, sp, rest) => {
|
|
109
|
+
if (/superseded by #|re-scoped by #/.test(rest)) return `${pre}[${r.disposition === "dropped" ? "x" : " "}]${sp}${rest}`;
|
|
110
|
+
return r.disposition === "dropped" ? `${pre}[x]${sp}~~${rest}~~ (dropped, superseded by #${amendment})` : `${pre}[ ]${sp}${rest} (re-scoped by #${amendment})`;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Files (or joins) the one amendment issue of `epic` and holds every affected open child, and `self`, behind it.
|
|
118
|
+
* @param {{gh:Function, create:Function, repo:string, issue:number, inv:object, epic:number, milestone?:string|null}} p
|
|
119
|
+
* gh: read, create: write (retried) `gh` runners returning stdout.
|
|
120
|
+
* @returns {Promise<{amendment:number, created:boolean, held:number[]}>}
|
|
121
|
+
*/
|
|
122
|
+
export async function fileAmendment({ gh, create, repo, issue, inv, epic, milestone = null }) {
|
|
123
|
+
const list = await readChildList({ gh, repo });
|
|
124
|
+
const children = affectedChildren({ list, epic, self: issue, paths: inv.paths });
|
|
125
|
+
let amendment = findAmendment(list, epic), created = false;
|
|
126
|
+
if (!amendment) {
|
|
127
|
+
const out = String(await create(["issue", "create", "-R", repo, "--title", amendmentTitle(inv, epic), "--body", amendmentBody({ inv, epic, from: issue, children }), ...(milestone ? ["--milestone", milestone] : [])]));
|
|
128
|
+
amendment = issueNo(/\/issues\/(\d+)/.exec(out)?.[1]);
|
|
129
|
+
if (!amendment) throw new Error(`cannot parse the amendment issue number from: ${out.slice(0, 200)}`);
|
|
130
|
+
created = true;
|
|
131
|
+
}
|
|
132
|
+
const held = [];
|
|
133
|
+
for (const n of [...children, issue]) {
|
|
134
|
+
if (n === amendment) continue;
|
|
135
|
+
const rec = JSON.parse(String(await gh(["issue", "view", String(n), "-R", repo, "--json", "body"])) || "{}");
|
|
136
|
+
const next = holdEdge(rec.body, amendment);
|
|
137
|
+
if (next !== String(rec.body ?? "")) await create(["issue", "edit", String(n), "-R", repo, "--body", next]);
|
|
138
|
+
held.push(n);
|
|
139
|
+
}
|
|
140
|
+
return { amendment, created, held };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* After the amendment merged: re-evaluate every held open child from the dispositions the amendment lane wrote, release
|
|
145
|
+
* the hold, and rewrite the epic checklist. Nothing is changed unless every affected child has a valid disposition.
|
|
146
|
+
* @returns {Promise<{ok:boolean, problem?:string, rows?:object[]}>}
|
|
147
|
+
*/
|
|
148
|
+
export async function applyReplan({ gh, create, repo, amendment }) {
|
|
149
|
+
const view = JSON.parse(String(await gh(["issue", "view", String(amendment), "-R", repo, "--json", "body,comments"])) || "{}");
|
|
150
|
+
const epic = amendmentEpic(view.body);
|
|
151
|
+
if (!epic) return { ok: false, problem: `#${amendment} is not a spike amendment (no ${REPLAN_MARKER} record)` };
|
|
152
|
+
const d = parseDispositions([view.body, ...(view.comments ?? []).map((c) => c?.body)]);
|
|
153
|
+
if (!d) return { ok: false, problem: `#${amendment} carries no \`${DISPOSITIONS_TAG}\` block` };
|
|
154
|
+
const list = await readChildList({ gh, repo });
|
|
155
|
+
const held = selectChildren({ list, roots: [epic] }).filter((n) => String(list.find((it) => it.number === n)?.body ?? "").includes(dependsLine(amendment)));
|
|
156
|
+
const v = validateDispositions(d, held);
|
|
157
|
+
if (!v.ok) return v;
|
|
158
|
+
for (const r of v.rows) {
|
|
159
|
+
const cur = String(list.find((it) => it.number === r.n)?.body ?? "");
|
|
160
|
+
if (r.disposition === "dropped") {
|
|
161
|
+
await create(["issue", "close", String(r.n), "-R", repo, "--reason", "not planned", "--comment", `Dropped: superseded by the design amendment in #${amendment}.`]);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const base = r.disposition === "re-scoped" ? (parentOf(r.body) ? r.body : `${r.body.replace(/\s+$/, "")}\n\n**Parent**: #${epic}\n`) : cur;
|
|
165
|
+
await create(["issue", "edit", String(r.n), "-R", repo, "--body", releaseEdge(base, amendment)]);
|
|
166
|
+
}
|
|
167
|
+
const ep = JSON.parse(String(await gh(["issue", "view", String(epic), "-R", repo, "--json", "body"])) || "{}");
|
|
168
|
+
const next = renderEpicChecklist(ep.body, v.rows, amendment);
|
|
169
|
+
if (next !== String(ep.body ?? "")) await create(["issue", "edit", String(epic), "-R", repo, "--body", next]);
|
|
170
|
+
return { ok: true, rows: v.rows };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** `forgedock replan apply --amendment N --repo owner/repo`. */
|
|
174
|
+
export async function replanFromCli(argv, deps = {}) {
|
|
175
|
+
const arg = (k) => { const i = argv.indexOf(k); return i >= 0 ? argv[i + 1] : null; };
|
|
176
|
+
const usage = "usage: forgedock replan apply --amendment N --repo owner/repo";
|
|
177
|
+
const amendment = issueNo(arg("--amendment")), repo = arg("--repo") ?? deps.repo;
|
|
178
|
+
if (argv[0] !== "apply" || !amendment || !repo) throw new Error(usage);
|
|
179
|
+
const io = deps.io ?? (await import("./effects.mjs")).makeLeanIo({ repo });
|
|
180
|
+
const r = await applyReplan({ gh: (a) => io.gh(a), create: (a) => io.gh(a), repo, amendment });
|
|
181
|
+
if (!r.ok) { process.stderr.write(`replan: ${r.problem}\n`); return 1; }
|
|
182
|
+
for (const x of r.rows) process.stdout.write(`#${x.n}: ${x.disposition}\n`);
|
|
183
|
+
return 0;
|
|
184
|
+
}
|