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,313 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Feature-level acceptance (#5336): an epic declares user journeys, each a probe-format command that runs against the
|
|
5
|
+
* assembled milestone branch; a milestone with an epic cannot ship or close, and its release review cannot pass, while a
|
|
6
|
+
* journey is red, has never run on the branch head, or (at close) a post-deploy journey has not yet passed in production.
|
|
7
|
+
* Deterministic: no model call. Same trust rule as probes (`isProbeDeclarer`, fail closed).
|
|
8
|
+
*
|
|
9
|
+
* Declaration, a top-level fenced block in the epic body or a declarer's comment (the latest wins):
|
|
10
|
+
* ```forge-acceptance
|
|
11
|
+
* journey: create a session-backed task and get a result
|
|
12
|
+
* run: ./scripts/journey-task.sh
|
|
13
|
+
* pass: exit 0 # or /regex/flags against stdout
|
|
14
|
+
* timeout: 300
|
|
15
|
+
* when: milestone # default; `post-deploy` journeys run after release and hold the epic open
|
|
16
|
+
* ```
|
|
17
|
+
* Each run is posted on the epic as a `FORGE:ACCEPTANCE` comment: {head, at, site, results}.
|
|
18
|
+
* `forgedock acceptance check --body-file F | run --milestone T [--site post-deploy] | gate --milestone T|--branch B [--stage ship|close]`.
|
|
19
|
+
*/
|
|
20
|
+
import { readFileSync } from "node:fs";
|
|
21
|
+
import { isTrustedComment } from "../engine/phases.mjs";
|
|
22
|
+
import { noComments } from "./render.mjs";
|
|
23
|
+
import { fencedBlocks, isProbeDeclarer, runProbe, probeEnv, readProbeConfig, MAX_TIMEOUT_S } from "./probe.mjs";
|
|
24
|
+
import { listMilestones, milestoneSlug, readBranches, DEFAULT_FEATURE_PATTERN } from "./lane.mjs";
|
|
25
|
+
|
|
26
|
+
export const ACCEPTANCE_MARKER = "FORGE:ACCEPTANCE";
|
|
27
|
+
export const ACCEPTANCE_TAG = "forge-acceptance";
|
|
28
|
+
export const AWAITING_LABEL = "awaiting-measurement";
|
|
29
|
+
export const WHEN = ["milestone", "post-deploy"];
|
|
30
|
+
export const TRANSFER_MARKER = "FORGE:TRANSFERRED";
|
|
31
|
+
|
|
32
|
+
const isForgeMarker = (body) => /^\s*<!--\s*FORGE:/.test(String(body ?? ""));
|
|
33
|
+
const sameSha = (a, b) => !!a && !!b && (a.startsWith(b) || b.startsWith(a));
|
|
34
|
+
const actorOf = (o) => ({ association: o?.author_association, type: o?.user?.type, login: o?.user?.login });
|
|
35
|
+
|
|
36
|
+
function journeyOf(f) {
|
|
37
|
+
const bad = (why) => ({ error: `journey "${f.journey ?? "?"}": ${why}` });
|
|
38
|
+
if (!f.journey) return { error: "a journey section has no name" };
|
|
39
|
+
if (!f.run) return bad("no `run:` command");
|
|
40
|
+
let pass = { kind: "exit" };
|
|
41
|
+
const p = (f.pass ?? "").replace(/\s+#.*$/, "");
|
|
42
|
+
if (p && !/^exit\s+0$/i.test(p)) {
|
|
43
|
+
const r = /^\/(.+)\/([a-z]*)$/.exec(p);
|
|
44
|
+
try { if (!r) return bad("`pass:` must be `exit 0` or /regex/flags"); new RegExp(r[1], r[2]); } catch { return bad("`pass:` regex does not compile"); }
|
|
45
|
+
pass = { kind: "regex", re: r[1], flags: r[2] };
|
|
46
|
+
}
|
|
47
|
+
let timeoutS = null;
|
|
48
|
+
if (f.timeout) {
|
|
49
|
+
const t = parseInt(f.timeout, 10);
|
|
50
|
+
if (!Number.isFinite(t) || t <= 0) return bad("`timeout:` must be a positive number of seconds");
|
|
51
|
+
timeoutS = Math.min(t, MAX_TIMEOUT_S);
|
|
52
|
+
}
|
|
53
|
+
const when = (f.when ?? "milestone").toLowerCase();
|
|
54
|
+
if (!WHEN.includes(when)) return bad("`when:` must be milestone or post-deploy");
|
|
55
|
+
return { journey: { name: f.journey, run: f.run, pass, timeoutS, when } };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The last top-level forge-acceptance block of `text`: {journeys, errors}; journeys is empty when no block exists. */
|
|
59
|
+
export function parseAcceptance(text) {
|
|
60
|
+
const blocks = fencedBlocks(noComments(String(text ?? ""), " ").replace(/\r\n?/g, "\n"), ACCEPTANCE_TAG);
|
|
61
|
+
const out = { journeys: [], errors: [] };
|
|
62
|
+
if (!blocks.length) return out;
|
|
63
|
+
const sections = [];
|
|
64
|
+
for (const line of blocks[blocks.length - 1].split("\n")) {
|
|
65
|
+
const m = /^\s*(journey|run|pass|timeout|when)\s*:\s*(.*?)\s*$/i.exec(line);
|
|
66
|
+
if (!m) continue;
|
|
67
|
+
const k = m[1].toLowerCase();
|
|
68
|
+
if (k === "journey") sections.push({ journey: m[2] });
|
|
69
|
+
else if (sections.length && !(k in sections.at(-1))) sections.at(-1)[k] = m[2];
|
|
70
|
+
}
|
|
71
|
+
for (const s of sections) { const j = journeyOf(s); if (j.error) out.errors.push(j.error); else out.journeys.push(j.journey); }
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Creation gate: {ok, journeys, errors}. An epic body needs at least one valid journey and no malformed one. */
|
|
76
|
+
export function validateEpic(body) {
|
|
77
|
+
const { journeys, errors } = parseAcceptance(body);
|
|
78
|
+
const all = journeys.length ? errors : ["no `forge-acceptance` block with at least one journey (journey/run/pass)", ...errors];
|
|
79
|
+
return { ok: !all.length, journeys, errors: all };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The epic's declared journeys: the latest declarer comment, else the body when its author is a declarer. {journeys, errors, source} | {untrusted:true} | null. */
|
|
83
|
+
export function declaredAcceptance(iss) {
|
|
84
|
+
let untrusted = false;
|
|
85
|
+
for (const c of [...(iss?.comments ?? [])].reverse()) {
|
|
86
|
+
if (isForgeMarker(c?.body)) continue;
|
|
87
|
+
const a = parseAcceptance(c?.body);
|
|
88
|
+
if (!a.journeys.length && !a.errors.length) continue;
|
|
89
|
+
if (isProbeDeclarer(actorOf(c))) return { ...a, source: "comment" };
|
|
90
|
+
untrusted = true;
|
|
91
|
+
}
|
|
92
|
+
const a = parseAcceptance(iss?.body);
|
|
93
|
+
if (a.journeys.length || a.errors.length) {
|
|
94
|
+
if (isProbeDeclarer(actorOf(iss))) return { ...a, source: "body" };
|
|
95
|
+
untrusted = true;
|
|
96
|
+
}
|
|
97
|
+
return untrusted ? { untrusted: true } : null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The FORGE:ACCEPTANCE comment: pass/fail, when, and on which head. */
|
|
101
|
+
export function renderAcceptanceComment({ head, at, site, branch, rows }) {
|
|
102
|
+
const pass = rows.length > 0 && rows.every((r) => r.result === "pass");
|
|
103
|
+
const rec = { head, at, site, branch, result: pass ? "pass" : "fail", results: Object.fromEntries(rows.map((r) => [r.name, { result: r.result, exit: r.exit, ms: r.ms }])) };
|
|
104
|
+
const table = rows.map((r) => `| ${r.name.replace(/\|/g, "/")} | ${r.result} | ${r.exit ?? "timeout"} |`);
|
|
105
|
+
const tails = rows.filter((r) => r.result === "fail").map((r) => `<details><summary>${r.name.replace(/[<>]/g, "")}</summary>\n\n\`\`\`\`\n${String(r.output ?? "").trim() || "(no output)"}\n\`\`\`\`\n</details>`);
|
|
106
|
+
return [`<!-- ${ACCEPTANCE_MARKER} -->`, `## Feature acceptance (${site}): ${rec.result}`, JSON.stringify(rec), "",
|
|
107
|
+
`Ran on \`${String(head).slice(0, 12)}\`${branch ? ` of \`${branch}\`` : ""} at ${at}.`, "", "| Journey | Result | Exit |", "|---|---|---|", ...table, "", ...tails].join("\n");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** {head, at, site, result, results} of a FORGE:ACCEPTANCE comment body, or null. */
|
|
111
|
+
export function acceptanceResultOf(body) {
|
|
112
|
+
const s = String(body ?? "");
|
|
113
|
+
if (!s.trimStart().startsWith(`<!-- ${ACCEPTANCE_MARKER} -->`)) return null;
|
|
114
|
+
const line = s.split("\n").find((l) => /^\{.*"results"/.test(l.trim()));
|
|
115
|
+
try { const j = line && JSON.parse(line.trim()); return j && typeof j.head === "string" && j.results && typeof j.results === "object" ? j : null; } catch { return null; }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Run `journeys` (those of `site`) in `cwd`; rows {name, when, result, exit, ms, output}. */
|
|
119
|
+
export async function runJourneys({ journeys, site = "milestone", cwd, config = readProbeConfig(cwd), env = process.env, spawn }) {
|
|
120
|
+
const rows = [];
|
|
121
|
+
for (const j of journeys.filter((x) => x.when === site)) {
|
|
122
|
+
const r = await runProbe(j, { cwd, env: probeEnv(config.env, env), mask: config.env.map((k) => env[k]), timeoutS: config.timeoutS, ...(spawn ? { spawn } : {}) });
|
|
123
|
+
rows.push({ name: j.name, when: j.when, ...r });
|
|
124
|
+
}
|
|
125
|
+
return rows;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** #5339: the name a journey must carry to settle a requirement transferred from `issue`'s `req`. */
|
|
129
|
+
export const transferName = (issue, req) => `#${issue} ${req}`;
|
|
130
|
+
|
|
131
|
+
/** #5339: {issue, req, quote} of a FORGE:TRANSFERRED comment body (posted by the engine; it declares no command), or null. */
|
|
132
|
+
export function transferOf(body) {
|
|
133
|
+
const s = String(body ?? "");
|
|
134
|
+
if (!s.trimStart().startsWith(`<!-- ${TRANSFER_MARKER} -->`)) return null;
|
|
135
|
+
const line = s.split("\n").find((l) => /^\{.*"req"/.test(l.trim()));
|
|
136
|
+
try { const j = line && JSON.parse(line.trim()); return j && Number.isInteger(j.issue) && typeof j.req === "string" ? j : null; } catch { return null; }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The gate for one milestone's epics. `epics`: [{number, declared, comments}]. `stage`: "ship" needs every milestone journey
|
|
141
|
+
* green on `head`; "close" also needs every post-deploy journey to have passed (any head, site post-deploy).
|
|
142
|
+
* Returns {ok, reasons}. A milestone with no epics is not gated.
|
|
143
|
+
*/
|
|
144
|
+
export function gateMilestone({ epics, head, stage = "ship" }) {
|
|
145
|
+
const reasons = [];
|
|
146
|
+
for (const e of epics) {
|
|
147
|
+
const tag = `epic #${e.number}`;
|
|
148
|
+
const d = e.declared;
|
|
149
|
+
if (!d || d.untrusted || !d.journeys?.length) { reasons.push(`${tag}: no runnable journey declared${d?.untrusted ? " (only by untrusted authors)" : ""}`); continue; }
|
|
150
|
+
if (d.errors?.length) reasons.push(`${tag}: ${d.errors.join("; ")}`);
|
|
151
|
+
const recs = (e.comments ?? []).filter((c) => isTrustedComment(c)).map((c) => acceptanceResultOf(c.body)).filter(Boolean);
|
|
152
|
+
// close after ship: the branch is deleted (head null), so the last milestone-site run is the shipped head's record
|
|
153
|
+
const onHead = recs.filter((r) => r.site !== "post-deploy" && (head == null || sameSha(r.head, head))).at(-1);
|
|
154
|
+
for (const j of d.journeys.filter((x) => x.when === "milestone")) {
|
|
155
|
+
const got = onHead?.results?.[j.name]?.result;
|
|
156
|
+
if (got === "pass") continue;
|
|
157
|
+
reasons.push(`${tag}: journey "${j.name}" ${got ? "is red" : recs.length ? `has not run on ${String(head).slice(0, 7)}` : "has never run"}`);
|
|
158
|
+
}
|
|
159
|
+
if (stage === "close") {
|
|
160
|
+
// #5339: a requirement transferred from a lane is open until a post-deploy journey named `#<issue> <req>` passes
|
|
161
|
+
for (const t of (e.comments ?? []).filter((c) => isTrustedComment(c)).map((c) => transferOf(c.body)).filter(Boolean)) {
|
|
162
|
+
if (!recs.some((r) => r.site === "post-deploy" && r.results?.[transferName(t.issue, t.req)]?.result === "pass")) reasons.push(`${tag}: requirement ${t.req} transferred from #${t.issue} has not been run (post-deploy journey "${transferName(t.issue, t.req)}" must pass; epic stays open, ${AWAITING_LABEL})`);
|
|
163
|
+
}
|
|
164
|
+
for (const j of d.journeys.filter((x) => x.when === "post-deploy")) {
|
|
165
|
+
if (!recs.some((r) => r.site === "post-deploy" && r.results?.[j.name]?.result === "pass")) reasons.push(`${tag}: post-deploy journey "${j.name}" has not passed in production (epic stays open, ${AWAITING_LABEL})`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return { ok: !reasons.length, reasons };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const branchOf = (pattern, title) => { const slug = milestoneSlug(title); return slug ? String(pattern || DEFAULT_FEATURE_PATTERN).replace("{slug}", slug) : null; };
|
|
173
|
+
|
|
174
|
+
/** The open milestone whose branch is `branch` (or titled `title`): {number, title, branch}, or null. */
|
|
175
|
+
export async function findMilestone({ io, repo, title = null, branch = null, pattern = DEFAULT_FEATURE_PATTERN }) {
|
|
176
|
+
for (const m of await listMilestones({ gh: io.gh, repo, state: "all" })) {
|
|
177
|
+
const b = branchOf(pattern, m.title);
|
|
178
|
+
if ((title && m.title === title) || (branch && b === branch)) return { number: m.number, title: m.title, branch: b };
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The milestone's epic issues, each with comments and declared journeys. */
|
|
184
|
+
export async function readEpics({ io, repo, milestone }) {
|
|
185
|
+
const list = JSON.parse(String(await io.gh(["api", `repos/${repo}/issues?milestone=${milestone.number}&labels=epic&state=all&per_page=100`, "--jq", "[.[] | select(.pull_request == null)]"])) || "[]");
|
|
186
|
+
const out = [];
|
|
187
|
+
for (const iss of list) {
|
|
188
|
+
const raw = String(await io.gh(["api", `repos/${repo}/issues/${iss.number}/comments`, "--paginate", "--jq", ".[]"]));
|
|
189
|
+
const comments = raw.split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l));
|
|
190
|
+
out.push({ number: iss.number, state: iss.state, declared: declaredAcceptance({ ...iss, comments }), comments });
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Gate by milestone title or branch. Fails closed: a milestone with epics whose head cannot be read is blocked. Not gated: no milestone or no epic. */
|
|
196
|
+
export async function gateByRef({ io, repo, title = null, branch = null, head = null, stage = "ship", pattern = DEFAULT_FEATURE_PATTERN }) {
|
|
197
|
+
const ms = await findMilestone({ io, repo, title, branch, pattern });
|
|
198
|
+
if (!ms) return { gated: false, ok: true, reasons: [] };
|
|
199
|
+
const epics = await readEpics({ io, repo, milestone: ms });
|
|
200
|
+
if (!epics.length) return { gated: false, ok: true, reasons: [], milestone: ms };
|
|
201
|
+
let h = head;
|
|
202
|
+
if (!h && ms.branch) { try { h = String(await io.gh(["api", `repos/${repo}/branches/${encodeURIComponent(ms.branch)}`, "--jq", ".commit.sha"])).trim(); } catch { h = null; } }
|
|
203
|
+
if (!h && stage !== "close") return { gated: true, ok: false, reasons: [`milestone ${ms.title}: head of ${ms.branch} unreadable (fail closed)`], milestone: ms };
|
|
204
|
+
return { gated: true, ...gateMilestone({ epics, head: h, stage }), milestone: ms, epics, head: h };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* #5339: record each requirement of `issue` that cannot run in the lane on the milestone's epic (a FORGE:TRANSFERRED comment,
|
|
209
|
+
* idempotent per issue+req), so `gate --stage close` holds the epic open until it runs. Returns the epic number, or null
|
|
210
|
+
* (no milestone or no epic: the requirement stays open on the issue, which closes partial).
|
|
211
|
+
*/
|
|
212
|
+
export async function transferToEpic({ io, repo, milestoneTitle, issue, reqs, now = () => new Date().toISOString(), pattern = DEFAULT_FEATURE_PATTERN }) {
|
|
213
|
+
if (!milestoneTitle || !reqs?.length) return null;
|
|
214
|
+
const ms = await findMilestone({ io, repo, title: milestoneTitle, pattern });
|
|
215
|
+
if (!ms) return null;
|
|
216
|
+
const epics = await readEpics({ io, repo, milestone: ms });
|
|
217
|
+
const epic = epics.find((e) => e.state === "open") ?? epics[0];
|
|
218
|
+
if (!epic) return null;
|
|
219
|
+
const have = new Set(epic.comments.map((c) => transferOf(c.body)).filter(Boolean).map((t) => transferName(t.issue, t.req)));
|
|
220
|
+
for (const r of reqs) {
|
|
221
|
+
if (have.has(transferName(issue, r.id))) continue;
|
|
222
|
+
const rec = { issue, req: r.id, quote: String(r.quote ?? "").slice(0, 300), at: now() };
|
|
223
|
+
await io.gh(["issue", "comment", String(epic.number), "-R", repo, "--body", [`<!-- ${TRANSFER_MARKER} -->`, `## Requirement transferred from #${issue} (${r.id}): not met, open`, JSON.stringify(rec), "",
|
|
224
|
+
`The lane could not run this end to end. Declare a post-deploy journey named \`${transferName(issue, r.id)}\` in the epic's \`forge-acceptance\` block; the epic cannot close until it passes.`].join("\n")]);
|
|
225
|
+
}
|
|
226
|
+
return epic.number;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Run a milestone's journeys in `cwd` (checked out at its branch head) and post the result on each epic. Resolves [{epic, result, rows}]. */
|
|
230
|
+
export async function runMilestoneJourneys({ io, repo, milestone, cwd, head, site = "milestone", now = () => new Date().toISOString(), config, env, spawn, dryRun = false }) {
|
|
231
|
+
const out = [];
|
|
232
|
+
for (const e of await readEpics({ io, repo, milestone })) {
|
|
233
|
+
if (!e.declared?.journeys?.length || e.declared.untrusted) { out.push({ epic: e.number, result: "no-journey", rows: [] }); continue; }
|
|
234
|
+
const rows = await runJourneys({ journeys: e.declared.journeys, site, cwd, ...(config ? { config } : {}), ...(env ? { env } : {}), ...(spawn ? { spawn } : {}) });
|
|
235
|
+
if (!rows.length) { out.push({ epic: e.number, result: "no-journey", rows }); continue; }
|
|
236
|
+
const body = renderAcceptanceComment({ head, at: now(), site, branch: milestone.branch, rows });
|
|
237
|
+
if (!dryRun) {
|
|
238
|
+
await io.gh(["issue", "comment", String(e.number), "-R", repo, "--body", body]);
|
|
239
|
+
if (site === "milestone" && rows.some((r) => r.result === "fail")) { try { await io.gh(["issue", "edit", String(e.number), "-R", repo, "--add-label", "integration-red"]); } catch { /* label is advisory */ } }
|
|
240
|
+
}
|
|
241
|
+
out.push({ epic: e.number, result: rows.every((r) => r.result === "pass") ? "pass" : "fail", rows });
|
|
242
|
+
}
|
|
243
|
+
return out;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** `forgedock acceptance check|run|gate`. Resolves the exit code (1: invalid, red or blocked). */
|
|
247
|
+
export async function acceptanceFromCli(argv, deps = {}) {
|
|
248
|
+
const val = (n) => { const i = argv.indexOf(n); return i >= 0 ? argv[i + 1] : null; };
|
|
249
|
+
const print = deps.print ?? ((t) => console.log(t));
|
|
250
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
251
|
+
const usage = "usage: forgedock acceptance check --body-file F | run --milestone T [--site milestone|post-deploy] [--repo o/r] | gate (--milestone T | --branch B) [--stage ship|close] [--repo o/r]";
|
|
252
|
+
if (argv[0] === "check") {
|
|
253
|
+
const f = val("--body-file");
|
|
254
|
+
if (!f) throw new Error(usage);
|
|
255
|
+
const v = validateEpic(deps.readFile ? deps.readFile(f) : readFileSync(f, "utf8"));
|
|
256
|
+
if (v.ok) print(`acceptance: ${v.journeys.length} journey(s): ${v.journeys.map((j) => `${j.name} [${j.when}]`).join("; ")}`);
|
|
257
|
+
else for (const e of v.errors) print(`acceptance: ${e}`);
|
|
258
|
+
return v.ok ? 0 : 1;
|
|
259
|
+
}
|
|
260
|
+
if (argv[0] !== "run" && argv[0] !== "gate") throw new Error(usage);
|
|
261
|
+
const repo = val("--repo") ?? deps.repo;
|
|
262
|
+
if (!repo) throw new Error("acceptance needs the repo: pass --repo owner/repo");
|
|
263
|
+
const io = deps.io ?? (await import("./effects.mjs")).makeLeanIo({ repo });
|
|
264
|
+
const pattern = deps.pattern ?? readBranches(cwd).featurePattern ?? DEFAULT_FEATURE_PATTERN;
|
|
265
|
+
if (argv[0] === "gate") {
|
|
266
|
+
const stage = val("--stage") ?? "ship";
|
|
267
|
+
if (stage !== "ship" && stage !== "close") throw new Error(usage);
|
|
268
|
+
if (!val("--milestone") && !val("--branch")) throw new Error(usage);
|
|
269
|
+
const g = await gateByRef({ io, repo, title: val("--milestone"), branch: val("--branch"), stage, pattern });
|
|
270
|
+
if (!g.gated) print("acceptance: milestone has no epic; not gated");
|
|
271
|
+
else if (g.ok) print(`acceptance: pass (${g.milestone.title} @ ${g.head ? String(g.head).slice(0, 7) : "branch deleted"}, ${stage})`);
|
|
272
|
+
else for (const r of g.reasons) print(`acceptance: BLOCKED: ${r}`);
|
|
273
|
+
return g.ok ? 0 : 1;
|
|
274
|
+
}
|
|
275
|
+
const title = val("--milestone");
|
|
276
|
+
const site = val("--site") ?? "milestone";
|
|
277
|
+
if (!title || !WHEN.includes(site)) throw new Error(usage);
|
|
278
|
+
const ms = await findMilestone({ io, repo, title, pattern });
|
|
279
|
+
if (!ms) throw new Error(`no milestone titled ${title}`);
|
|
280
|
+
const head = String(await (deps.git ?? io.git)(["rev-parse", "HEAD"], { cwd })).trim();
|
|
281
|
+
const res = await runMilestoneJourneys({ io, repo, milestone: ms, cwd, head, site, dryRun: argv.includes("--dry-run"), ...(deps.spawn ? { spawn: deps.spawn } : {}) });
|
|
282
|
+
for (const r of res) print(`acceptance: epic #${r.epic}: ${r.result}`);
|
|
283
|
+
return res.some((r) => r.result === "fail") ? 1 : 0;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The orchestrate seam's `journeys({title, branch, number})`: fetch the milestone branch, check it out detached in a
|
|
288
|
+
* throwaway worktree, run the epics' milestone journeys there and post the results. Milestones with no epic or journey are a no-op (a string);
|
|
289
|
+
* a run resolves {summary, red, ran, head} (#5337).
|
|
290
|
+
*/
|
|
291
|
+
export function makeJourneyRunner({ repo, io, cwd = process.cwd(), tmpRoot }) {
|
|
292
|
+
return async ({ title, branch, number }) => {
|
|
293
|
+
if (!branch) return "no branch";
|
|
294
|
+
const git = (a, o = {}) => io.git(a, { cwd, ...o });
|
|
295
|
+
const epics = await readEpics({ io, repo, milestone: { number } });
|
|
296
|
+
if (!epics.some((e) => e.declared?.journeys?.some((j) => j.when === "milestone"))) return "no journey declared";
|
|
297
|
+
await git(["fetch", "origin", branch]);
|
|
298
|
+
const { mkdtempSync, rmSync } = await import("node:fs");
|
|
299
|
+
const { tmpdir } = await import("node:os");
|
|
300
|
+
const { join } = await import("node:path");
|
|
301
|
+
const dir = join(mkdtempSync(join(tmpRoot ?? tmpdir(), "forge-journey-")), "wt");
|
|
302
|
+
try {
|
|
303
|
+
await git(["worktree", "add", "--detach", dir, `origin/${branch}`]);
|
|
304
|
+
const head = String(await git(["rev-parse", "HEAD"], { cwd: dir })).trim();
|
|
305
|
+
const res = await runMilestoneJourneys({ io, repo, milestone: { number, title, branch }, cwd: dir, head });
|
|
306
|
+
// #5337: structured so the integration seam can file the red issue and hold admission; it still reads as its `summary`.
|
|
307
|
+
return { summary: res.map((r) => `#${r.epic} ${r.result}`).join(", ") || "no journey declared", red: res.some((r) => r.result === "fail"), ran: res.some((r) => r.result === "pass" || r.result === "fail"), head };
|
|
308
|
+
} finally {
|
|
309
|
+
try { await git(["worktree", "remove", "--force", dir]); } catch { /* pruned below */ }
|
|
310
|
+
try { rmSync(join(dir, ".."), { recursive: true, force: true }); await git(["worktree", "prune"]); } catch { /* best effort */ }
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
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 { parseAcceptance, validateEpic, declaredAcceptance, renderAcceptanceComment, acceptanceResultOf, gateMilestone, gateByRef, transferToEpic, transferOf, transferName, runMilestoneJourneys, makeJourneyRunner, acceptanceFromCli } from "./acceptance.mjs";
|
|
6
|
+
import { makeIntegration } from "./integration.mjs";
|
|
7
|
+
|
|
8
|
+
const F = "```";
|
|
9
|
+
const block = (inner) => `Epic\n\n${F}forge-acceptance\n${inner}\n${F}\n`;
|
|
10
|
+
const J1 = block("journey: create a task and get a result\nrun: ./j.sh\npass: exit 0\ntimeout: 60");
|
|
11
|
+
const HEAD = "a".repeat(40), OLD = "b".repeat(40);
|
|
12
|
+
const owner = { author_association: "OWNER", user: { type: "User", login: "me" } };
|
|
13
|
+
const bot = { user: { type: "Bot", login: "forge[bot]" }, author_association: "NONE" };
|
|
14
|
+
const rec = (head, results, site = "milestone") => ({ ...bot, body: renderAcceptanceComment({ head, at: "t", site, rows: Object.entries(results).map(([name, result]) => ({ name, result, exit: result === "pass" ? 0 : 1, ms: 1, output: "x" })) }) });
|
|
15
|
+
const epic = (declared, comments = []) => ({ number: 7, declared, comments });
|
|
16
|
+
const decl = declaredAcceptance({ body: J1, ...owner });
|
|
17
|
+
|
|
18
|
+
describe("acceptance parsing and the creation gate", () => {
|
|
19
|
+
it("parses journeys with defaults and post-deploy", () => {
|
|
20
|
+
const a = parseAcceptance(block("journey: a\nrun: x\njourney: b\nrun: y\npass: /ok/i\nwhen: post-deploy"));
|
|
21
|
+
assert.deepEqual(a.errors, []);
|
|
22
|
+
assert.equal(a.journeys[0].when, "milestone");
|
|
23
|
+
assert.deepEqual(a.journeys[1].pass, { kind: "regex", re: "ok", flags: "i" });
|
|
24
|
+
assert.equal(a.journeys[1].when, "post-deploy");
|
|
25
|
+
});
|
|
26
|
+
it("rejects an epic without a runnable journey", () => {
|
|
27
|
+
assert.equal(validateEpic("## Epic\nno journeys").ok, false);
|
|
28
|
+
assert.equal(validateEpic(block("journey: a")).ok, false, "no run command");
|
|
29
|
+
assert.equal(validateEpic(block("journey: a\nrun: x\nwhen: never")).ok, false);
|
|
30
|
+
assert.equal(validateEpic(`${F}\n${J1}\n${F}`.replace(/forge-acceptance/, "forge-probe")).ok, false);
|
|
31
|
+
assert.equal(validateEpic(J1).ok, true);
|
|
32
|
+
});
|
|
33
|
+
it("a quoted block (inside another fence) is not a declaration", () => {
|
|
34
|
+
assert.equal(validateEpic(`~~~md\n${J1}\n~~~`).ok, false);
|
|
35
|
+
});
|
|
36
|
+
it("only declarers' journeys count", () => {
|
|
37
|
+
assert.deepEqual(declaredAcceptance({ body: J1, ...bot }), { untrusted: true });
|
|
38
|
+
assert.equal(declaredAcceptance({ body: J1, ...owner }).journeys.length, 1);
|
|
39
|
+
assert.equal(declaredAcceptance({ body: "x", ...owner, comments: [{ body: J1, ...owner }] }).source, "comment");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("acceptance gate", () => {
|
|
44
|
+
it("blocks a journey that never ran, is red, or ran on an older head", () => {
|
|
45
|
+
const never = gateMilestone({ epics: [epic(decl)], head: HEAD });
|
|
46
|
+
assert.equal(never.ok, false); assert.match(never.reasons[0], /never run/);
|
|
47
|
+
const red = gateMilestone({ epics: [epic(decl, [rec(HEAD, { "create a task and get a result": "fail" })])], head: HEAD });
|
|
48
|
+
assert.match(red.reasons[0], /is red/);
|
|
49
|
+
const stale = gateMilestone({ epics: [epic(decl, [rec(OLD, { "create a task and get a result": "pass" })])], head: HEAD });
|
|
50
|
+
assert.match(stale.reasons[0], /has not run on/);
|
|
51
|
+
});
|
|
52
|
+
it("passes a green run on the head; an epic with no journey blocks", () => {
|
|
53
|
+
assert.equal(gateMilestone({ epics: [epic(decl, [rec(HEAD, { "create a task and get a result": "pass" })])], head: HEAD }).ok, true);
|
|
54
|
+
assert.equal(gateMilestone({ epics: [epic(null)], head: HEAD }).ok, false);
|
|
55
|
+
});
|
|
56
|
+
it("an untrusted (non-bot-marker) result comment does not count", () => {
|
|
57
|
+
const forged = { ...rec(HEAD, { "create a task and get a result": "pass" }), user: { type: "User", login: "rando" }, author_association: "NONE" };
|
|
58
|
+
assert.equal(gateMilestone({ epics: [epic(decl, [forged])], head: HEAD }).ok, false);
|
|
59
|
+
});
|
|
60
|
+
it("post-deploy journeys hold the epic at close, not at ship", () => {
|
|
61
|
+
const d = declaredAcceptance({ body: block("journey: live\nrun: curl x\nwhen: post-deploy"), ...owner });
|
|
62
|
+
assert.equal(gateMilestone({ epics: [epic(d)], head: HEAD, stage: "ship" }).ok, true);
|
|
63
|
+
const c = gateMilestone({ epics: [epic(d)], head: HEAD, stage: "close" });
|
|
64
|
+
assert.equal(c.ok, false); assert.match(c.reasons[0], /post-deploy journey "live"/);
|
|
65
|
+
assert.equal(gateMilestone({ epics: [epic(d, [rec(OLD, { live: "pass" }, "post-deploy")])], head: HEAD, stage: "close" }).ok, true);
|
|
66
|
+
});
|
|
67
|
+
it("result comment round-trips head, time and result", () => {
|
|
68
|
+
const r = acceptanceResultOf(rec(HEAD, { a: "pass", b: "fail" }).body);
|
|
69
|
+
assert.equal(r.head, HEAD); assert.equal(r.at, "t"); assert.equal(r.result, "fail"); assert.equal(r.results.b.result, "fail");
|
|
70
|
+
assert.equal(acceptanceResultOf("no"), null);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/** gh stub: milestone "M One" (#3) with epic #7, comments `comments`. */
|
|
75
|
+
function world({ comments = [], body = J1, author = owner, labels = true } = {}) {
|
|
76
|
+
const w = { calls: [], posted: [] };
|
|
77
|
+
const epicIssue = { number: 7, state: "open", body, ...author, labels: [{ name: "epic" }] };
|
|
78
|
+
w.io = {
|
|
79
|
+
gh: async (a) => {
|
|
80
|
+
w.calls.push(a);
|
|
81
|
+
if (/milestones\?state=all/.test(a[1])) return JSON.stringify([{ number: 3, title: "M One", description: "" }]);
|
|
82
|
+
if (/issues\?milestone=3/.test(a[1])) return labels ? JSON.stringify([epicIssue]) : "[]";
|
|
83
|
+
if (/issues\/7\/comments/.test(a[1])) return comments.map((c) => JSON.stringify(c)).join("\n");
|
|
84
|
+
if (/\/branches\//.test(a[1])) return `${HEAD}\n`;
|
|
85
|
+
if (a[0] === "issue" && a[1] === "comment") { w.posted.push(a[a.indexOf("--body") + 1]); return ""; }
|
|
86
|
+
if (a[0] === "issue" && a[1] === "edit") return "";
|
|
87
|
+
throw new Error(`unexpected gh ${a.join(" ")}`);
|
|
88
|
+
},
|
|
89
|
+
git: async () => `${HEAD}\n`,
|
|
90
|
+
};
|
|
91
|
+
return w;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
describe("gateByRef, run and CLI", () => {
|
|
95
|
+
it("a milestone cannot ship while its journey never ran (ship and close)", async () => {
|
|
96
|
+
for (const stage of ["ship", "close"]) {
|
|
97
|
+
const w = world();
|
|
98
|
+
const g = await gateByRef({ io: w.io, repo: "o/r", title: "M One", stage });
|
|
99
|
+
assert.equal(g.gated, true); assert.equal(g.ok, false);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
it("no epic means not gated; an unreadable head fails closed", async () => {
|
|
103
|
+
assert.equal((await gateByRef({ io: world({ labels: false }).io, repo: "o/r", title: "M One" })).gated, false);
|
|
104
|
+
assert.equal((await gateByRef({ io: world().io, repo: "o/r", title: "Nope" })).gated, false);
|
|
105
|
+
const w = world(); const gh = w.io.gh; w.io.gh = async (a) => { if (/\/branches\//.test(a[1])) throw new Error("404"); return gh(a); };
|
|
106
|
+
const g = await gateByRef({ io: w.io, repo: "o/r", branch: "milestone/m-one" });
|
|
107
|
+
assert.equal(g.ok, false); assert.match(g.reasons[0], /fail closed/);
|
|
108
|
+
});
|
|
109
|
+
it("close after ship: a deleted milestone branch uses the last recorded milestone run (#5393)", async () => {
|
|
110
|
+
const pd = declaredAcceptance({ body: block("journey: create a task and get a result\nrun: ./j.sh\njourney: live\nrun: ./l.sh\nwhen: post-deploy"), ...owner });
|
|
111
|
+
const gone = (w) => { const gh = w.io.gh; w.io.gh = async (a) => { if (/\/branches\//.test(a[1])) throw new Error("404"); return gh(a); }; return w; };
|
|
112
|
+
const ok = [rec(HEAD, { "create a task and get a result": "pass" }), rec(OLD, { live: "pass" }, "post-deploy")];
|
|
113
|
+
assert.equal(gateMilestone({ epics: [epic(pd, ok)], head: null, stage: "close" }).ok, true);
|
|
114
|
+
assert.equal(gateMilestone({ epics: [epic(pd, [ok[0]])], head: null, stage: "close" }).ok, false, "post-deploy journey still required");
|
|
115
|
+
assert.match(gateMilestone({ epics: [epic(pd, [rec(HEAD, { "create a task and get a result": "fail" }), ok[1]])], head: null, stage: "close" }).reasons[0], /is red/);
|
|
116
|
+
assert.equal(gateMilestone({ epics: [epic(pd, [ok[1]])], head: null, stage: "close" }).ok, false, "no milestone run");
|
|
117
|
+
const w = gone(world({ comments: [{ ...bot, body: rec(HEAD, { "create a task and get a result": "pass" }).body }] }));
|
|
118
|
+
assert.equal((await gateByRef({ io: w.io, repo: "o/r", title: "M One", stage: "close" })).ok, true);
|
|
119
|
+
const w2 = gone(world());
|
|
120
|
+
assert.equal((await gateByRef({ io: w2.io, repo: "o/r", title: "M One", stage: "close" })).ok, false);
|
|
121
|
+
assert.match((await gateByRef({ io: gone(world()).io, repo: "o/r", title: "M One", stage: "ship" })).reasons[0], /fail closed/);
|
|
122
|
+
});
|
|
123
|
+
it("runs journeys, posts the result on the epic with the head, and the gate then passes", async () => {
|
|
124
|
+
const w = world();
|
|
125
|
+
const res = await runMilestoneJourneys({ io: w.io, repo: "o/r", milestone: { number: 3, title: "M One", branch: "milestone/m-one" }, cwd: "/x", head: HEAD, now: () => "2026-11-10T00:00:00Z",
|
|
126
|
+
spawn: async () => ({ code: 0, stdout: "ok", stderr: "", timedOut: false }) });
|
|
127
|
+
assert.equal(res[0].result, "pass");
|
|
128
|
+
assert.equal(w.posted.length, 1);
|
|
129
|
+
const r = acceptanceResultOf(w.posted[0]);
|
|
130
|
+
assert.equal(r.head, HEAD); assert.equal(r.at, "2026-11-10T00:00:00Z"); assert.equal(r.result, "pass");
|
|
131
|
+
const w2 = world({ comments: [{ ...bot, body: w.posted[0] }] });
|
|
132
|
+
assert.equal((await gateByRef({ io: w2.io, repo: "o/r", title: "M One" })).ok, true);
|
|
133
|
+
});
|
|
134
|
+
it("a failing journey posts fail", async () => {
|
|
135
|
+
const w = world();
|
|
136
|
+
const res = await runMilestoneJourneys({ io: w.io, repo: "o/r", milestone: { number: 3, title: "M One", branch: "b" }, cwd: "/x", head: HEAD, spawn: async () => ({ code: 1, stdout: "", stderr: "boom", timedOut: false }) });
|
|
137
|
+
assert.equal(res[0].result, "fail"); assert.match(w.posted[0], /: fail/);
|
|
138
|
+
});
|
|
139
|
+
it("CLI check/gate exit codes", async () => {
|
|
140
|
+
const out = [];
|
|
141
|
+
const print = (t) => out.push(t);
|
|
142
|
+
assert.equal(await acceptanceFromCli(["check", "--body-file", "f"], { print, readFile: () => "no journeys" }), 1);
|
|
143
|
+
assert.equal(await acceptanceFromCli(["check", "--body-file", "f"], { print, readFile: () => J1 }), 0);
|
|
144
|
+
assert.equal(await acceptanceFromCli(["gate", "--milestone", "M One", "--repo", "o/r"], { print, io: world().io, cwd: "/nonexistent" }), 1);
|
|
145
|
+
assert.match(out.at(-1), /BLOCKED/);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("makeJourneyRunner structured result (#5337)", () => {
|
|
150
|
+
it("stays a string when nothing ran, and resolves {summary, red, ran, head} after a run", async () => {
|
|
151
|
+
const none = world({ labels: false });
|
|
152
|
+
assert.equal(await makeJourneyRunner({ repo: "o/r", io: none.io })({ title: "M One", branch: "milestone/m-one", number: 3 }), "no journey declared");
|
|
153
|
+
const w = world();
|
|
154
|
+
const git = w.io.git;
|
|
155
|
+
w.io.git = async (a, o) => (a[0] === "rev-parse" ? `${HEAD}\n` : git(a, o));
|
|
156
|
+
const r = await makeJourneyRunner({ repo: "o/r", io: w.io, cwd: process.cwd() })({ title: "M One", branch: "milestone/m-one", number: 3 });
|
|
157
|
+
assert.equal(typeof r.summary, "string");
|
|
158
|
+
assert.equal(r.head, HEAD);
|
|
159
|
+
assert.equal(typeof r.red, "boolean");
|
|
160
|
+
assert.equal(typeof r.ran, "boolean");
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe("integration seam runs journeys after a child merge", () => {
|
|
165
|
+
it("calls journeys without an integration cfg and survives its failure", async () => {
|
|
166
|
+
const calls = [], events = [];
|
|
167
|
+
const io = { gh: async (a) => (/milestones\?state=all/.test(a[1]) ? JSON.stringify([{ number: 3, title: "M One", description: "" }]) : "{}") };
|
|
168
|
+
const ig = makeIntegration({ repo: "o/r", io, cfg: null, journeys: async (m) => { calls.push(m); return "ok"; }, onEvent: (e) => events.push(e.detail) });
|
|
169
|
+
await ig.onMerged(1, {}, { milestone: "M One", pr: 5 });
|
|
170
|
+
await ig.settle();
|
|
171
|
+
assert.deepEqual(calls, [{ title: "M One", branch: "milestone/m-one", number: 3 }]);
|
|
172
|
+
assert.equal(ig.holds(1, { lane: "milestone/m-one" }), null);
|
|
173
|
+
const bad = makeIntegration({ repo: "o/r", io, cfg: null, journeys: async () => { throw new Error("x"); }, onEvent: (e) => events.push(e.detail) });
|
|
174
|
+
await bad.onMerged(1, {}, { milestone: "M One" }); await bad.settle();
|
|
175
|
+
assert.ok(events.some((e) => /journey run failed/.test(e)));
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe("transferred requirements (#5339)", () => {
|
|
180
|
+
const rows = (name, result) => [{ name, result, exit: result === "pass" ? 0 : 1, ms: 1 }];
|
|
181
|
+
const declPd = declaredAcceptance({ body: block("journey: smoke\nrun: ./j.sh\nwhen: post-deploy"), ...owner });
|
|
182
|
+
const tcomment = { ...bot, body: ["<!-- FORGE:TRANSFERRED -->", "## t", JSON.stringify({ issue: 5339, req: "R1", quote: "q", at: "t" })].join("\n") };
|
|
183
|
+
const pd = (results) => ({ ...bot, body: renderAcceptanceComment({ head: HEAD, at: "t", site: "post-deploy", rows: Object.entries(results).map(([name, result]) => ({ name, result, exit: result === "pass" ? 0 : 1, ms: 1 })) }) });
|
|
184
|
+
it("blocks the epic's close until a post-deploy journey named for the requirement passes; ship is not blocked", () => {
|
|
185
|
+
const passSmoke = pd({ smoke: "pass" });
|
|
186
|
+
const open = gateMilestone({ epics: [epic(declPd, [tcomment, passSmoke])], head: HEAD, stage: "close" });
|
|
187
|
+
assert.equal(open.ok, false);
|
|
188
|
+
assert.match(open.reasons.join(), /R1 transferred from #5339 has not been run/);
|
|
189
|
+
assert.equal(gateMilestone({ epics: [epic(declPd, [tcomment])], head: HEAD, stage: "ship" }).ok, true);
|
|
190
|
+
assert.equal(gateMilestone({ epics: [epic(declPd, [tcomment, passSmoke, pd({ [transferName(5339, "R1")]: "fail" })])], head: HEAD, stage: "close" }).ok, false);
|
|
191
|
+
assert.equal(gateMilestone({ epics: [epic(declPd, [tcomment, passSmoke, pd({ [transferName(5339, "R1")]: "pass" })])], head: HEAD, stage: "close" }).ok, true);
|
|
192
|
+
});
|
|
193
|
+
it("transferToEpic posts one FORGE:TRANSFERRED comment per requirement, idempotently, and returns null without an epic", async () => {
|
|
194
|
+
const posted = [];
|
|
195
|
+
let existing = [];
|
|
196
|
+
const gh = async (a) => {
|
|
197
|
+
const u = a.join(" ");
|
|
198
|
+
if (u.includes("/milestones")) return JSON.stringify([{ number: 3, title: "Feature X", state: "open" }]);
|
|
199
|
+
if (u.includes("issues?milestone=")) return JSON.stringify([{ number: 7, state: "open", body: "", user: owner.user, author_association: "OWNER" }]);
|
|
200
|
+
if (u.includes("/comments")) return existing.map((b) => JSON.stringify({ body: b, ...bot })).join("\n");
|
|
201
|
+
if (a[0] === "issue" && a[1] === "comment") { posted.push(a[a.indexOf("--body") + 1]); return ""; }
|
|
202
|
+
return "[]";
|
|
203
|
+
};
|
|
204
|
+
const reqs = [{ id: "R1", quote: "Live search works [type:e2e]" }];
|
|
205
|
+
const n = await transferToEpic({ io: { gh }, repo: "o/r", milestoneTitle: "Feature X", issue: 5339, reqs });
|
|
206
|
+
assert.equal(n, 7);
|
|
207
|
+
assert.equal(posted.length, 1);
|
|
208
|
+
assert.deepEqual([transferOf(posted[0]).issue, transferOf(posted[0]).req], [5339, "R1"]);
|
|
209
|
+
existing = [posted[0]];
|
|
210
|
+
await transferToEpic({ io: { gh }, repo: "o/r", milestoneTitle: "Feature X", issue: 5339, reqs });
|
|
211
|
+
assert.equal(posted.length, 1, "idempotent");
|
|
212
|
+
assert.equal(await transferToEpic({ io: { gh }, repo: "o/r", milestoneTitle: null, issue: 5339, reqs }), null);
|
|
213
|
+
assert.equal(await transferToEpic({ io: { gh: async () => "[]" }, repo: "o/r", milestoneTitle: "Feature X", issue: 5339, reqs }), null);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Late account capture for a lane (#5268). The tokenbaton shim exports the chosen account and then execs claude with
|
|
5
|
+
* the same pid, so a single /proc read at spawn sees the shim's env and finds no account. `watchAccount` keeps
|
|
6
|
+
* reading while the child is alive until an account shows up, so a usage limit can exclude the limited account.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Polls `read()` (a number or null) every `intervalMs` for up to `maxMs` until it returns a value, then calls `onFound`.
|
|
11
|
+
* Reads once at once. Returns `{stop, current}`; `current()` is the account found so far (or null). Timers are unref'd.
|
|
12
|
+
*/
|
|
13
|
+
export function watchAccount(read, { intervalMs = 200, maxMs = 15000, setTimer = setTimeout, clearTimer = clearTimeout, onFound = () => {} } = {}) {
|
|
14
|
+
let found = null, timer = null, stopped = false, waited = 0;
|
|
15
|
+
const probe = () => { try { const v = read(); return v ?? null; } catch { return null; } };
|
|
16
|
+
const stop = () => { stopped = true; if (timer !== null) { clearTimer(timer); timer = null; } };
|
|
17
|
+
const tick = () => {
|
|
18
|
+
timer = null;
|
|
19
|
+
if (stopped) return;
|
|
20
|
+
const v = probe();
|
|
21
|
+
if (v !== null) { found = v; stopped = true; onFound(v); return; }
|
|
22
|
+
waited += intervalMs;
|
|
23
|
+
if (waited >= maxMs) { stopped = true; return; }
|
|
24
|
+
timer = setTimer(tick, intervalMs); timer?.unref?.();
|
|
25
|
+
};
|
|
26
|
+
tick();
|
|
27
|
+
return { stop, current: () => found, refresh: () => { if (found === null) { const v = probe(); if (v !== null) { found = v; onFound(v); } } return found; } };
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { watchAccount } from "./account-watch.mjs";
|
|
6
|
+
|
|
7
|
+
const fakeTimers = () => { const q = []; return { q, setTimer: (fn) => { const t = { fn, cleared: false }; q.push(t); return t; }, clearTimer: (t) => { t.cleared = true; }, run: () => { const t = q.shift(); if (t && !t.cleared) t.fn(); } }; };
|
|
8
|
+
|
|
9
|
+
describe("#5268 watchAccount", () => {
|
|
10
|
+
it("resolves once the shim has exec'd (null reads first), then stops polling", () => {
|
|
11
|
+
const ft = fakeTimers(); let n = 0, got = null;
|
|
12
|
+
const w = watchAccount(() => (++n >= 3 ? 2 : null), { setTimer: ft.setTimer, clearTimer: ft.clearTimer, onFound: (a) => { got = a; } });
|
|
13
|
+
assert.equal(w.current(), null);
|
|
14
|
+
ft.run(); assert.equal(w.current(), null);
|
|
15
|
+
ft.run(); assert.equal(w.current(), 2); assert.equal(got, 2);
|
|
16
|
+
assert.equal(ft.q.length, 0, "no further timer");
|
|
17
|
+
});
|
|
18
|
+
it("gives up after maxMs and never throws on a failing read", () => {
|
|
19
|
+
const ft = fakeTimers();
|
|
20
|
+
const w = watchAccount(() => { throw new Error("gone"); }, { intervalMs: 100, maxMs: 300, setTimer: ft.setTimer, clearTimer: ft.clearTimer });
|
|
21
|
+
for (let i = 0; i < 10; i++) ft.run();
|
|
22
|
+
assert.equal(w.current(), null); assert.equal(ft.q.length, 0);
|
|
23
|
+
});
|
|
24
|
+
it("stop() clears the pending timer; refresh() re-reads once", () => {
|
|
25
|
+
const ft = fakeTimers(); let v = null;
|
|
26
|
+
const w = watchAccount(() => v, { setTimer: ft.setTimer, clearTimer: ft.clearTimer });
|
|
27
|
+
const t = ft.q[0]; w.stop(); assert.equal(t.cleared, true);
|
|
28
|
+
v = 3; assert.equal(w.refresh(), 3); assert.equal(w.current(), 3);
|
|
29
|
+
});
|
|
30
|
+
});
|
package/bin/lean/activation.mjs
CHANGED
|
@@ -74,3 +74,41 @@ export async function dormancyReport({ introduced = [], flagState, decisions = [
|
|
|
74
74
|
}
|
|
75
75
|
return out.sort((a, b) => b.days - a.days);
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
const LIVE_MODES = /^(?:on|true|1|enforce|enforced|live|treated|active)$/i;
|
|
79
|
+
const MODE_LINE_RE = /^["']?([A-Za-z_][\w.-]*)["']?\s*[:=]\s*["']?([A-Za-z0-9_]+)["']?\s*,?;?\s*(?:#.*|\/\/.*)?$/;
|
|
80
|
+
/**
|
|
81
|
+
* #5240: the current mode of every rollout flag (declared in the forge.yaml `rollouts` registry files) that a changed file
|
|
82
|
+
* names, `[{flag, mode, live}]`; `live` is false for shadow/off/cohort-less modes, i.e. the change is inert in production.
|
|
83
|
+
* `read(path)` returns file text or throws; unreadable files and an absent registry give [].
|
|
84
|
+
*/
|
|
85
|
+
export function rolloutModes(cfg, changedFiles, read) {
|
|
86
|
+
if (!cfg?.files?.length) return [];
|
|
87
|
+
const modes = new Map();
|
|
88
|
+
for (const f of cfg.files) {
|
|
89
|
+
let text; try { text = String(read(f)); } catch { continue; }
|
|
90
|
+
for (const l of text.split("\n")) { const m = MODE_LINE_RE.exec(l.trim()); if (m) modes.set(m[1], m[2]); }
|
|
91
|
+
}
|
|
92
|
+
if (!modes.size) return [];
|
|
93
|
+
const texts = [];
|
|
94
|
+
for (const f of changedFiles ?? []) { if (inRegistry(cfg, f)) continue; try { texts.push(String(read(f))); } catch { /* deleted or unreadable */ } }
|
|
95
|
+
return [...modes].filter(([flag]) => texts.some((t) => flagRe(flag).test(t))).map(([flag, mode]) => ({ flag, mode, live: LIVE_MODES.test(mode) })).sort((a, b) => a.flag.localeCompare(b.flag));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const LIVE_ACCEPTANCE_RE = /\b(?:live|production|prod|post-deploy|real[- ]browser|measur\w*)\b/i;
|
|
99
|
+
/**
|
|
100
|
+
* #5285: a requirement deferred for live or post-deploy verification while a live (default-on) rollout is touched ships
|
|
101
|
+
* unverified in production. `modes` is rolloutModes' output; returns `[{id, flag}]` of the deferred rows that block close.
|
|
102
|
+
*/
|
|
103
|
+
export function liveDeferralBlocks(contract, modes) {
|
|
104
|
+
const live = (modes ?? []).filter((m) => m.live).map((m) => m.flag);
|
|
105
|
+
if (!live.length) return [];
|
|
106
|
+
const out = [];
|
|
107
|
+
for (const r of contract?.requirements ?? []) {
|
|
108
|
+
if (r?.disposition !== "defer" && r?.disposition !== "post-deploy") continue;
|
|
109
|
+
if (r.transferred || /\[type:(?:e2e|manual)\]/i.test(String(r.quote ?? ""))) { out.push({ id: r.id, flag: live.join(", ") }); continue; } // #5339: transferred to the epic, still unrun
|
|
110
|
+
const b = String(r.bucket ?? "");
|
|
111
|
+
if (r.disposition === "post-deploy" || b === "post-deploy" || b === "verify-now" || b === "host" || LIVE_ACCEPTANCE_RE.test(`${r.quote ?? ""} ${r.why ?? ""}`)) out.push({ id: r.id, flag: live.join(", ") });
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|