forgedock 1.56.0 → 1.57.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/bin/config-schema.mjs +1 -1
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine/phases.mjs +4 -3
- package/bin/engine-cli.mjs +46 -10
- package/bin/forgedock.mjs +52 -3
- package/bin/gc.mjs +43 -6
- package/bin/help-text.mjs +3 -1
- package/bin/lean/batch-health.mjs +5 -1
- package/bin/lean/batch-health.test.mjs +7 -1
- package/bin/lean/batch.mjs +7 -2
- package/bin/lean/batch.test.mjs +45 -0
- package/bin/lean/conformance.e2e.test.mjs +3 -2
- package/bin/lean/conformance.mjs +88 -17
- package/bin/lean/conformance.test.mjs +98 -3
- package/bin/lean/decisions.mjs +86 -1
- package/bin/lean/decisions.test.mjs +21 -1
- package/bin/lean/depcache.mjs +124 -13
- package/bin/lean/depcache.test.mjs +121 -3
- package/bin/lean/design-gate.mjs +144 -0
- package/bin/lean/design-gate.test.mjs +169 -0
- package/bin/lean/effects-cap.test.mjs +17 -0
- package/bin/lean/effects.mjs +58 -13
- package/bin/lean/heavy.mjs +25 -8
- package/bin/lean/hostload.test.mjs +28 -0
- package/bin/lean/intake.mjs +97 -0
- package/bin/lean/intake.test.mjs +105 -0
- package/bin/lean/interfaces.mjs +181 -0
- package/bin/lean/interfaces.test.mjs +192 -0
- package/bin/lean/issuewatch-install.mjs +52 -12
- package/bin/lean/issuewatch-install.test.mjs +50 -0
- package/bin/lean/issuewatch-parity.mjs +12 -2
- package/bin/lean/issuewatch-parity.test.mjs +26 -0
- package/bin/lean/issuewatch-reconcile.mjs +29 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +21 -0
- package/bin/lean/issuewatch.mjs +34 -3
- package/bin/lean/issuewatch.test.mjs +49 -1
- package/bin/lean/lanecheck.test.mjs +15 -4
- package/bin/lean/lean.mjs +72 -21
- package/bin/lean/lean.test.mjs +149 -3
- package/bin/lean/orchestrate-blocked.test.mjs +18 -2
- package/bin/lean/orchestrate-owned.test.mjs +14 -5
- package/bin/lean/orchestrate.mjs +26 -4
- package/bin/lean/orphan-pr.mjs +3 -2
- package/bin/lean/orphan-pr.test.mjs +8 -1
- package/bin/lean/pagegate.mjs +35 -12
- package/bin/lean/pagegate.test.mjs +39 -1
- package/bin/lean/preflight.mjs +35 -1
- package/bin/lean/preflight.test.mjs +27 -1
- package/bin/lean/prompts.mjs +2 -1
- package/bin/lean/reap.test.mjs +39 -0
- package/bin/lean/recovery.test.mjs +25 -0
- package/bin/lean/release-config.mjs +158 -0
- package/bin/lean/release-config.test.mjs +109 -0
- package/bin/lean/release-control.mjs +148 -0
- package/bin/lean/release-control.test.mjs +143 -0
- package/bin/lean/release-fence.mjs +50 -0
- package/bin/lean/release-fence.test.mjs +105 -0
- package/bin/lean/release-flakes.mjs +139 -0
- package/bin/lean/release-flakes.test.mjs +116 -0
- package/bin/lean/release-ledger.mjs +160 -0
- package/bin/lean/release-ledger.test.mjs +226 -0
- package/bin/lean/release-minutes.mjs +92 -0
- package/bin/lean/release-minutes.test.mjs +99 -0
- package/bin/lean/release-nightly.mjs +75 -0
- package/bin/lean/release-nightly.test.mjs +48 -0
- package/bin/lean/release-postmerge.mjs +8 -2
- package/bin/lean/release-review.e2e.test.mjs +1 -0
- package/bin/lean/release-review.mjs +54 -7
- package/bin/lean/release-review.test.mjs +76 -7
- package/bin/lean/release-unitmap.mjs +35 -0
- package/bin/lean/release-unitmap.test.mjs +41 -0
- package/bin/lean/release.mjs +177 -19
- package/bin/lean/release.test.mjs +40 -0
- package/bin/lean/render.mjs +3 -1
- package/bin/lean/run-issue-placement.test.mjs +82 -0
- package/bin/lean/sandbox-remote.mjs +16 -0
- package/bin/lean/schedd.mjs +1 -1
- package/bin/lean/seam.mjs +115 -0
- package/bin/lean/seam.test.mjs +118 -0
- package/bin/lean/selftest-journey.mjs +40 -2
- package/bin/lean/selftest-journey.test.mjs +43 -3
- package/bin/lean/statuscomment.mjs +168 -0
- package/bin/lean/statuscomment.test.mjs +133 -0
- package/bin/lean/ui-quality.mjs +57 -0
- package/bin/lean/ui-quality.test.mjs +55 -0
- package/bin/lean/visual-gate.test.mjs +63 -0
- package/bin/pool/agent.mjs +16 -2
- package/bin/pool/router.mjs +5 -1
- package/bin/review-staging.mjs +5 -3
- package/bin/stats/card.mjs +117 -0
- package/bin/stats/card.test.mjs +109 -0
- package/bin/stats/conformance-outcomes.test.mjs +2 -1
- package/bin/stats/depth.mjs +1 -1
- package/bin/stats/gh-retry.test.mjs +152 -0
- package/bin/stats/github-source.mjs +147 -14
- package/bin/stats/index.mjs +35 -2
- package/bin/stats/stats.test.mjs +31 -3
- package/bin/vendor/js-yaml/LICENSE +21 -0
- package/bin/vendor/js-yaml/PIN.md +7 -0
- package/bin/vendor/js-yaml/js-yaml.mjs +3851 -0
- package/commands/design-render-critique-loop.md +2 -0
- package/commands/design.md +2 -0
- package/commands/issue.md +1 -1
- package/commands/milestone.md +1 -1
- package/commands/review-pr-agents/frontend.md +1 -0
- package/commands/review-pr-staging.md +5 -0
- package/docs/CONFIG.md +75 -1
- package/docs/ISSUE-WATCH.md +7 -0
- package/docs/OUTCOME-CODES.md +1 -0
- package/docs/STATS.md +10 -0
- package/docs/design/visual-gate.md +25 -0
- package/docs/eval/adversarial-bench.md +2 -2
- package/docs/eval/corpus/adversarial-v1.json +3 -3
- package/docs/site/start-a-new-project.md +7 -0
- package/docs/spec/forge-protocol-v1.md +31 -0
- package/package.json +1 -1
- package/pool/README.md +2 -0
- package/scripts/acceptance-red-green.sh +15 -1
- package/scripts/acceptance-red-green.test.sh +12 -0
- package/scripts/bench-adversarial.mjs +4 -0
- package/scripts/bench-lightlane.mjs +4 -1
- package/scripts/bootstrap-create.mjs +8 -2
- package/scripts/ci-local.test.sh +3 -3
- package/scripts/fixtures/ci-local/gha-dorny/.github/workflows/ci.yml +4 -0
- package/scripts/plan-validate-live.mjs +9 -6
- package/scripts/review-prepare.sh +7 -1
- package/scripts/review-roster.sh +5 -2
- package/scripts/review-roster.test.sh +9 -0
- package/scripts/visual-gate.mjs +64 -0
- package/templates/bootstrap/technical-spike.md +17 -0
- package/templates/contracts/seam-check.mjs +236 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Nightly results for managed releases (#5569, epic #5549 5.6): read the latest nightly run on the integration branch
|
|
5
|
+
* (T0-T2 daily, T3-T4 weekly), file or refresh one `nightly-red` issue, and decide whether a red blocks a release.
|
|
6
|
+
* Only `lane: release` is ever blocked, and only by T0-T2 reds or unskippable classes; T3/T4, train and p0 never.
|
|
7
|
+
* Pure functions plus `gh`-injected reads; no model call. forge.yaml `nightly:` block, used only when `release.managed`.
|
|
8
|
+
*/
|
|
9
|
+
export const NIGHTLY_LABEL = "nightly-red";
|
|
10
|
+
const json = (s) => { try { return JSON.parse(String(s)); } catch { return null; } };
|
|
11
|
+
const off = (v) => ["false", "off", "no", "0"].includes(String(v ?? "").trim().toLowerCase());
|
|
12
|
+
const list = (v) => String(v ?? "").split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
13
|
+
const hours = (v, d) => { const n = Number(v); return Number.isFinite(n) && n > 0 ? n : d; };
|
|
14
|
+
|
|
15
|
+
/** forge.yaml `nightly:` -> null when unset, else {branch, workflow, blockRelease, t0t2Hours, t3t4Hours, unskippable, t3, t4}. */
|
|
16
|
+
export function parseNightlyConfig(sec) {
|
|
17
|
+
if (!sec || typeof sec !== "object" || (!sec.workflow && !sec.branch)) return null;
|
|
18
|
+
return {
|
|
19
|
+
branch: String(sec.branch || "staging"), workflow: String(sec.workflow || "nightly.yml"),
|
|
20
|
+
blockRelease: !off(sec.block_release ?? "true"),
|
|
21
|
+
t0t2Hours: hours(sec.t0_t2_hours, 24), t3t4Hours: hours(sec.t3_t4_hours, 168),
|
|
22
|
+
unskippable: list(sec.unskippable), t3: list(sec.t3_jobs), t4: list(sec.t4_jobs),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Tier 0-4 of a job: a leading `T<n>`, else a configured t3_jobs/t4_jobs substring, else T2 (unclassified counts as blocking-eligible). */
|
|
27
|
+
export function classifyTier(name, cfg = {}) {
|
|
28
|
+
const n = String(name ?? "").toLowerCase();
|
|
29
|
+
const m = /^t([0-4])\b/.exec(n);
|
|
30
|
+
if (m) return Number(m[1]);
|
|
31
|
+
if ((cfg.t4 ?? []).some((p) => n.includes(p))) return 4;
|
|
32
|
+
if ((cfg.t3 ?? []).some((p) => n.includes(p))) return 3;
|
|
33
|
+
return 2;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const RED = new Set(["failure", "timed_out", "startup_failure"]);
|
|
37
|
+
const ageH = (iso, now) => (now - Date.parse(iso)) / 3_600_000;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Latest completed nightly runs -> {run, stale, reds:[{name, tier, run}]}. T0-T2 reds come from the newest run (stale when older than
|
|
41
|
+
* 2x t0_t2_hours); T3-T4 reds from the newest run inside t3_t4_hours that has a T3/T4 job. null when the runs are unreadable.
|
|
42
|
+
*/
|
|
43
|
+
export async function readNightly({ gh, repo, cfg, now = Date.now() }) {
|
|
44
|
+
const runs = json(await gh(["api", `repos/${repo}/actions/workflows/${cfg.workflow}/runs?branch=${encodeURIComponent(cfg.branch)}&status=completed&per_page=20`]))?.workflow_runs;
|
|
45
|
+
if (!Array.isArray(runs)) return null;
|
|
46
|
+
if (!runs.length) return { run: null, stale: true, reds: [] };
|
|
47
|
+
const jobsOf = async (r) => json(await gh(["api", `repos/${repo}/actions/runs/${r.id}/jobs?per_page=100`]))?.jobs ?? [];
|
|
48
|
+
const reds = [];
|
|
49
|
+
const first = runs[0];
|
|
50
|
+
for (const j of await jobsOf(first)) if (classifyTier(j.name, cfg) <= 2 && RED.has(j.conclusion)) reds.push({ name: j.name, tier: classifyTier(j.name, cfg), run: first.id });
|
|
51
|
+
for (const r of runs) {
|
|
52
|
+
if (ageH(r.created_at, now) > cfg.t3t4Hours) break;
|
|
53
|
+
const high = (await jobsOf(r)).filter((j) => classifyTier(j.name, cfg) >= 3);
|
|
54
|
+
if (!high.length) continue;
|
|
55
|
+
for (const j of high) if (RED.has(j.conclusion)) reds.push({ name: j.name, tier: classifyTier(j.name, cfg), run: r.id });
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
return { run: first.id, stale: ageH(first.created_at, now) > cfg.t0t2Hours * 2, reds };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The reds that stop `lane`: only `release` is ever blocked, by T0-T2 reds or a job matching `unskippable` (never when block_release is off). */
|
|
62
|
+
export function blocksRelease({ lane = "release", reds = [], cfg }) {
|
|
63
|
+
if (lane !== "release" || !cfg?.blockRelease) return [];
|
|
64
|
+
return reds.filter((r) => r.tier <= 2 || cfg.unskippable.some((p) => r.name.toLowerCase().includes(p)));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** One open `nightly-red` issue: created on the first red, its body edited afterwards. @returns {{issue, created}|null} null when nothing is red. */
|
|
68
|
+
export async function fileNightlyRed({ gh, repo, reds, run }) {
|
|
69
|
+
if (!reds.length) return null;
|
|
70
|
+
const body = `<!-- FORGE:NIGHTLY -->\nNightly run ${run ?? "?"} is red:\n${reds.map((r) => `- T${r.tier}: ${r.name} (run ${r.run})`).join("\n")}\n`;
|
|
71
|
+
const open = json(await gh(["issue", "list", "--repo", repo, "--label", NIGHTLY_LABEL, "--state", "open", "--json", "number", "--limit", "1"])) ?? [];
|
|
72
|
+
if (open[0]) { await gh(["issue", "edit", String(open[0].number), "--repo", repo, "--body", body]); return { issue: open[0].number, created: false }; }
|
|
73
|
+
const url = String(await gh(["issue", "create", "--repo", repo, "--label", NIGHTLY_LABEL, "--title", `nightly-red: ${reds.length} red job(s) on the integration branch`, "--body", body])).trim();
|
|
74
|
+
return { issue: Number(/(\d+)$/.exec(url)?.[1]) || null, created: true };
|
|
75
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { parseNightlyConfig, classifyTier, readNightly, blocksRelease, fileNightlyRed } from "./release-nightly.mjs";
|
|
6
|
+
|
|
7
|
+
const cfg = parseNightlyConfig({ workflow: "nightly.yml", branch: "staging", t3_jobs: "hands e2e", t4_jobs: "trivy", unskippable: "migration" });
|
|
8
|
+
const NOW = Date.parse("2026-11-12T12:00:00Z");
|
|
9
|
+
const hAgo = (h) => new Date(NOW - h * 3_600_000).toISOString();
|
|
10
|
+
|
|
11
|
+
describe("nightly (#5569)", () => {
|
|
12
|
+
it("config is null when unset and has the 24h/168h defaults", () => {
|
|
13
|
+
assert.equal(parseNightlyConfig(undefined), null);
|
|
14
|
+
assert.equal(cfg.t0t2Hours, 24); assert.equal(cfg.t3t4Hours, 168); assert.equal(cfg.blockRelease, true);
|
|
15
|
+
});
|
|
16
|
+
it("classifies tiers by prefix, then config, else T2", () => {
|
|
17
|
+
assert.equal(classifyTier("T1 unit api", cfg), 1);
|
|
18
|
+
assert.equal(classifyTier("Hands e2e", cfg), 3);
|
|
19
|
+
assert.equal(classifyTier("Trivy scan", cfg), 4);
|
|
20
|
+
assert.equal(classifyTier("lint", cfg), 2);
|
|
21
|
+
});
|
|
22
|
+
it("blocks only a release, only by T0-T2 or unskippable reds, never T3/T4", () => {
|
|
23
|
+
const reds = [{ name: "T1 unit", tier: 1 }, { name: "Hands e2e", tier: 3 }, { name: "migration safety", tier: 3 }];
|
|
24
|
+
assert.deepEqual(blocksRelease({ lane: "release", reds, cfg }).map((r) => r.name), ["T1 unit", "migration safety"]);
|
|
25
|
+
assert.deepEqual(blocksRelease({ lane: "release", reds: [reds[1]], cfg }), []);
|
|
26
|
+
assert.deepEqual(blocksRelease({ lane: "train", reds, cfg }), []);
|
|
27
|
+
assert.deepEqual(blocksRelease({ lane: "p0", reds, cfg }), []);
|
|
28
|
+
assert.deepEqual(blocksRelease({ lane: "release", reds, cfg: { ...cfg, blockRelease: false } }), []);
|
|
29
|
+
});
|
|
30
|
+
it("reads T0-T2 from the newest run and T3/T4 from the newest weekly run", async () => {
|
|
31
|
+
const jobs = { 1: [{ name: "T1 unit", conclusion: "failure" }, { name: "lint", conclusion: "success" }], 2: [{ name: "Hands e2e", conclusion: "failure" }] };
|
|
32
|
+
const gh = async (a) => /workflows/.test(a[1]) ? JSON.stringify({ workflow_runs: [{ id: 1, created_at: hAgo(2) }, { id: 2, created_at: hAgo(30) }] }) : JSON.stringify({ jobs: jobs[/runs\/(\d)/.exec(a[1])[1]] });
|
|
33
|
+
const n = await readNightly({ gh, repo: "o/r", cfg, now: NOW });
|
|
34
|
+
assert.deepEqual(n.reds.map((r) => [r.name, r.tier, r.run]), [["T1 unit", 1, 1], ["Hands e2e", 3, 2]]);
|
|
35
|
+
assert.equal(n.stale, false);
|
|
36
|
+
assert.equal(await readNightly({ gh: async () => "x", repo: "o/r", cfg, now: NOW }), null);
|
|
37
|
+
});
|
|
38
|
+
it("files one nightly-red issue and edits it afterwards; green files nothing", async () => {
|
|
39
|
+
const calls = []; let open = [];
|
|
40
|
+
const gh = async (a) => { calls.push(a.slice(0, 2).join(" ")); if (a[1] === "list") return JSON.stringify(open); if (a[1] === "create") return "https://github.com/o/r/issues/77"; return ""; };
|
|
41
|
+
const reds = [{ name: "T1 unit", tier: 1, run: 1 }];
|
|
42
|
+
assert.equal(await fileNightlyRed({ gh, repo: "o/r", reds: [], run: 1 }), null);
|
|
43
|
+
assert.deepEqual(await fileNightlyRed({ gh, repo: "o/r", reds, run: 1 }), { issue: 77, created: true });
|
|
44
|
+
open = [{ number: 77 }];
|
|
45
|
+
assert.deepEqual(await fileNightlyRed({ gh, repo: "o/r", reds, run: 2 }), { issue: 77, created: false });
|
|
46
|
+
assert.deepEqual(calls, ["issue list", "issue create", "issue list", "issue edit"]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { cleanupSnapshot } from "./release-snapshot.mjs";
|
|
12
|
+
import { fenced } from "./release-fence.mjs";
|
|
13
|
+
import { buildDispatchArgs } from "./release-control.mjs";
|
|
12
14
|
|
|
13
15
|
const BOUNDS = {
|
|
14
16
|
publishPolls: 6, publishPollMs: 10_000, // wait for a run to appear (bot merges never trigger one)
|
|
@@ -43,7 +45,8 @@ async function publishRun(ctx, sha, b) {
|
|
|
43
45
|
let run = await poll(io, b.publishPolls, b.publishPollMs, look);
|
|
44
46
|
let dispatched = false;
|
|
45
47
|
if (!run) {
|
|
46
|
-
await
|
|
48
|
+
const f = await fenced(ctx.fence, { action: "dispatch", key: `dispatch:${sha}` }, (epoch) => io.gh(buildDispatchArgs({ workflow, repo, ref: ctx.def, inputs: epoch != null ? { forge_epoch: epoch } : {} })));
|
|
49
|
+
if (f.refused) return { err: `dispatch ${f.refused}` };
|
|
47
50
|
dispatched = true;
|
|
48
51
|
run = await poll(io, b.publishPolls, b.publishPollMs, look);
|
|
49
52
|
if (!run) return { err: `no ${workflow} run for ${sha.slice(0, 8)} after a dispatch on ${ctx.def}; check the Actions tab, then resume` };
|
|
@@ -103,7 +106,10 @@ async function versionSync(ctx, sha, b) {
|
|
|
103
106
|
pr = { number: n };
|
|
104
107
|
}
|
|
105
108
|
const warn = (why) => ({ pr: pr.number, merged: false, warning: `version-sync PR #${pr.number} ${why}; merge it by hand so ${staging} reaches ${version}` });
|
|
106
|
-
try {
|
|
109
|
+
try {
|
|
110
|
+
const f = await fenced(ctx.fence, { action: "merge", key: `sync-merge:${pr.number}` }, () => io.gh(["pr", "merge", String(pr.number), "--repo", repo, "--merge", "--auto"]));
|
|
111
|
+
if (f.refused) return { err: `version-sync merge ${f.refused}` };
|
|
112
|
+
} catch (e) { return warn(`could not enable auto-merge (${String(e.message).split("\n")[0]})`); }
|
|
107
113
|
const end = await poll(io, b.autoPolls, b.autoPollMs, async () => {
|
|
108
114
|
const st = json(await io.gh(["pr", "view", String(pr.number), "--repo", repo, "--json", "state"]))?.state;
|
|
109
115
|
return st === "MERGED" || st === "CLOSED" ? st : null;
|
|
@@ -35,6 +35,7 @@ function world() {
|
|
|
35
35
|
readFile: () => "brief",
|
|
36
36
|
markLaunched: (_f, domains) => { w.launched = domains; },
|
|
37
37
|
saveTestGate: () => "/sd/gate.txt",
|
|
38
|
+
testGatePlan: async () => ({ clusters: 1, skill: "test-gate" }),
|
|
38
39
|
runAgent: async ({ role }) => { w.agents.push(role); return { text: "FORGE:TEST_GATE:RESULT=PASS" }; },
|
|
39
40
|
finalize: async () => ({ code: 0, lines: [], data: { head: sha(w.head), notes: ["- nit"], toFile: w.fixed ? [] : [{ title: "leak", severity: "HIGH" }] } }),
|
|
40
41
|
fileIssue: async ({ item }) => { w.issues.push(item.title); return 100 + w.issues.length; },
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { execFileSync, spawn } from "node:child_process";
|
|
12
12
|
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, appendFileSync, rmSync } from "node:fs";
|
|
13
|
-
import { tmpdir } from "node:os";
|
|
13
|
+
import { tmpdir, homedir } from "node:os";
|
|
14
14
|
import { delimiter, join } from "node:path";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
16
|
import { runHostPreflight } from "./release-preflight.mjs";
|
|
@@ -68,6 +68,41 @@ const sessionFailure = (e) => {
|
|
|
68
68
|
const failureNote = (failures) => (failures.size ? `; session failures: ${[...failures].map(([d, f]) => `${d} (${f})`).join("; ")}` : "");
|
|
69
69
|
const headMoved = (lines) => /head moved since/.test((lines ?? []).join("\n"));
|
|
70
70
|
|
|
71
|
+
/** #5516: commands/test-gate.md missing-config guard output, verbatim markers (consumed by review-staging-post.sh test-gate). */
|
|
72
|
+
export const TEST_GATE_SKIP_NO_TESTS = "ADVISORY: verification.integration_tests is not configured in forge.yaml.\nNo tests to run. Emitting SKIP verdict.\n<!-- FORGE:TEST_GATE:SKIP|reason=no-tests-configured -->\n<!-- FORGE:TEST_GATE:RESULT=SKIP -->\n";
|
|
73
|
+
/** #5516: the gate session's prompt names the exact Skill to invoke (prefixed on a plugin install). */
|
|
74
|
+
export const testGatePrompt = (skill, bundle, def) =>
|
|
75
|
+
`Invoke the Skill "${skill}" with args: --prs "${(bundle ?? []).join(" ")}" --base ${def}\n\nPrint the complete gate output, ending with its FORGE:TEST_GATE:RESULT= marker. If the Skill cannot be invoked, say so and print no marker.`;
|
|
76
|
+
/** #5516: count of `verification.integration_tests` entries in forge.yaml text; null when it cannot be read (the gate session then runs). */
|
|
77
|
+
export function integrationTestCount(raw) {
|
|
78
|
+
const lines = String(raw ?? "").split("\n");
|
|
79
|
+
const v = lines.findIndex((l) => /^verification:\s*(#.*)?$/.test(l));
|
|
80
|
+
if (v < 0) return 0;
|
|
81
|
+
let n = null;
|
|
82
|
+
for (let i = v + 1; i < lines.length && !/^\S/.test(lines[i]); i++) {
|
|
83
|
+
const m = /^(\s+)integration_tests:\s*(.*)$/.exec(lines[i]);
|
|
84
|
+
if (!m) continue;
|
|
85
|
+
const inline = m[2].replace(/#.*$/, "").trim();
|
|
86
|
+
if (inline === "[]" || inline === "null" || inline === "~") return 0;
|
|
87
|
+
if (inline) return null; // a flow sequence or anchor: not parsed here
|
|
88
|
+
n = 0;
|
|
89
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
90
|
+
const l = lines[j];
|
|
91
|
+
if (!l.trim() || /^\s*#/.test(l)) continue;
|
|
92
|
+
const ind = /^(\s*)/.exec(l)[1].length;
|
|
93
|
+
if (ind <= m[1].length && !/^\s*-/.test(l)) break;
|
|
94
|
+
if (ind < m[1].length) break;
|
|
95
|
+
if (/^\s*-\s/.test(l) && ind <= m[1].length + 2) n++;
|
|
96
|
+
}
|
|
97
|
+
return n;
|
|
98
|
+
}
|
|
99
|
+
return n ?? 0;
|
|
100
|
+
}
|
|
101
|
+
/** #5516: `forgedock:<name>` when ForgeDock is installed as a Claude Code plugin under `configDir`, else the bare name. */
|
|
102
|
+
export function resolveSkillName(name, { configDir, read = (p) => readFileSync(p, "utf8") } = {}) {
|
|
103
|
+
try { return /"forgedock(@[^"]*)?"\s*:/.test(read(join(configDir, "plugins", "installed_plugins.json"))) ? `forgedock:${name}` : name; } catch { return name; }
|
|
104
|
+
}
|
|
105
|
+
|
|
71
106
|
/** One review round at the current head: dispatch, test gate, head check, finalize. @returns {{moved: string}|{fail}|{ok}} */
|
|
72
107
|
async function reviewRound({ seam, pr, def, delta }) {
|
|
73
108
|
const pre = await seam.pre({ pr, delta });
|
|
@@ -85,7 +120,11 @@ async function reviewRound({ seam, pr, def, delta }) {
|
|
|
85
120
|
const failures = new Map();
|
|
86
121
|
const attempt = (domain, note) => send(domain, note).catch((e) => { failures.set(domain, sessionFailure(e)); return null; });
|
|
87
122
|
await Promise.all(agents.map((a) => attempt(a.domain)));
|
|
88
|
-
|
|
123
|
+
// #5516: the missing-config guard of commands/test-gate.md is deterministic, so no session decides it; otherwise the gate
|
|
124
|
+
// session gets a full tool set (Skill, Task, Bash) and the resolved skill name, never a bare `/test-gate`.
|
|
125
|
+
const plan = await seam.testGatePlan();
|
|
126
|
+
const gate = plan.clusters === 0 ? { text: TEST_GATE_SKIP_NO_TESTS }
|
|
127
|
+
: await seam.runAgent({ role: "release-test-gate", issue: pr, fullSession: true, prompt: testGatePrompt(plan.skill, m.bundle, def) });
|
|
89
128
|
const gateFile = seam.saveTestGate(pr, gate?.text ?? "");
|
|
90
129
|
|
|
91
130
|
// The head moved while the panel ran: finalize would refuse, and must never run at the moved head. Delta from what was reviewed.
|
|
@@ -126,7 +165,7 @@ async function runReview({ seam, pr, def, delta = null }) {
|
|
|
126
165
|
if ((st.notes ?? []).length) await seam.addNotes(pr, st.notes);
|
|
127
166
|
const sum = await seam.summary({ pr, filed });
|
|
128
167
|
if (!sum.data) return blocked(`the gate summary was not posted (exit ${sum.code}): ${(sum.lines ?? []).slice(-1).join("").slice(0, 200)}`);
|
|
129
|
-
return { pr, head: st.head, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly), filed, blocking, delta: st.delta?.from ?? null };
|
|
168
|
+
return { pr, head: st.head, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly), ciPendingOnly: Boolean(sum.data.ciPendingOnly), filed, blocking, delta: st.delta?.from ?? null };
|
|
130
169
|
}
|
|
131
170
|
|
|
132
171
|
/** Review step. @returns {{pr, head, verdict, marker, filed, blocking}|{blocked: true, reason: string}} */
|
|
@@ -147,13 +186,15 @@ export async function fixStep(ctx) {
|
|
|
147
186
|
if (!r.blocking?.length && r.ciFailing > 0 && r.ciCancelOnly) {
|
|
148
187
|
const sum = await seam.summary({ pr: r.pr, filed: r.filed ?? [] });
|
|
149
188
|
if (!sum.data) return blocked(`the gate summary was not posted (exit ${sum.code}) after rerunning the cancelled checks of #${r.pr}`);
|
|
150
|
-
r = { ...r, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly) };
|
|
189
|
+
r = { ...r, verdict: sum.data.verdict, marker: sum.data.marker, ciFailing: sum.data.ciFailing, ciCancelOnly: Boolean(sum.data.ciCancelOnly), ciPendingOnly: Boolean(sum.data.ciPendingOnly) };
|
|
151
190
|
ctx.state.steps.review = { ...ctx.state.steps.review, result: r };
|
|
152
191
|
ctx.save();
|
|
153
192
|
if (r.marker === "FORGE:GATE_PASS") break;
|
|
154
193
|
if (r.ciCancelOnly) return blocked(`required checks of #${r.pr} still cancelled after a rerun, with no failure to fix`);
|
|
155
194
|
round--; continue;
|
|
156
195
|
}
|
|
196
|
+
// Required checks that are only still pending (#5519) have not failed: no CI issue or lane, the release re-runs once CI finishes.
|
|
197
|
+
if (!r.blocking?.length && r.ciFailing > 0 && r.ciPendingOnly) return blocked(`required checks of #${r.pr} still pending, with no failure to fix; re-run the release once CI finishes`);
|
|
157
198
|
// Blocking findings are already filed issues; red CI has none, so it gets one issue naming the failing checks.
|
|
158
199
|
const issues = [...(r.blocking ?? [])];
|
|
159
200
|
if (r.ciFailing > 0) {
|
|
@@ -211,10 +252,16 @@ export function realSeam({ repo, def, env = process.env, cwd = process.cwd(), ma
|
|
|
211
252
|
readFile: (p) => readFileSync(p, "utf8"),
|
|
212
253
|
markLaunched: (file, domains, head) => { appendFileSync(file, domains.map((d) => `${d}\n`).join("")); writeFileSync(`${file}.head`, `${head}\n`); },
|
|
213
254
|
saveTestGate: (pr, text) => { mkdirSync(sd, { recursive: true }); const f = join(sd, `${pr}_test_gate_output.txt`); writeFileSync(f, text); return f; },
|
|
214
|
-
runAgent: async ({ role, issue, prompt }) => {
|
|
255
|
+
runAgent: async ({ role, issue, prompt, fullSession = false }) => {
|
|
215
256
|
runner ??= makeRunner ? makeRunner() : (await import("./effects.mjs")).makeLeanRunner();
|
|
216
|
-
// not readOnly: each reviewer posts its own PR comment
|
|
217
|
-
return runner({ role, issue, cwd, env: pinnedEnv(), prompt, system: "You are an isolated reviewer of one release PR. Do only what the prompt asks.", maxMs: REVIEW_MS, idleMs: 10 * 60_000 });
|
|
257
|
+
// not readOnly: each reviewer posts its own PR comment; the test gate (#5516) needs Skill/Task, so a full session
|
|
258
|
+
return runner({ role, issue, cwd, env: pinnedEnv(), prompt, fullSession, system: "You are an isolated reviewer of one release PR. Do only what the prompt asks.", maxMs: REVIEW_MS, idleMs: 10 * 60_000 });
|
|
259
|
+
},
|
|
260
|
+
testGatePlan: async () => {
|
|
261
|
+
let raw = null;
|
|
262
|
+
try { raw = readFileSync(env.FORGE_CONFIG || join(cwd, "forge.yaml"), "utf8"); } catch { raw = null; }
|
|
263
|
+
const clusters = raw == null ? null : integrationTestCount(raw);
|
|
264
|
+
return { clusters, skill: resolveSkillName("test-gate", { configDir: env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude") }) };
|
|
218
265
|
},
|
|
219
266
|
// closed by a merged fix: state CLOSED with the workflow:merged label (a read failure is "not merged", so the lane runs)
|
|
220
267
|
issueMerged: async (issue) => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
3
|
import { describe, it } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { reviewStep, fixStep, missingReviewers, SPEC_PANEL, MAX_DELTA_PASSES, MAX_FIX_ROUNDS, realSeam, withIntegrityMarker } from "./release-review.mjs";
|
|
5
|
+
import { reviewStep, fixStep, missingReviewers, SPEC_PANEL, MAX_DELTA_PASSES, MAX_FIX_ROUNDS, realSeam, withIntegrityMarker, TEST_GATE_SKIP_NO_TESTS, testGatePrompt, integrationTestCount, resolveSkillName } from "./release-review.mjs";
|
|
6
6
|
import { readFileSync } from "node:fs";
|
|
7
7
|
import { reviewStagingJson } from "../review-staging.mjs";
|
|
8
8
|
|
|
@@ -11,19 +11,20 @@ const manifest = (head, delta = null) => ({ pr: 7, headSha: head, bundle: [1, 2]
|
|
|
11
11
|
const fin = (extra = {}) => ({ code: 0, data: { head: H1, toFile: [], notes: [], ...extra }, lines: [] });
|
|
12
12
|
|
|
13
13
|
/** Seam fake: `heads` is what headOf answers in turn; `fins` what finalize answers in turn. */
|
|
14
|
-
function fakeSeam({ heads = [H1], fins = [fin()], summary, lanes = [] } = {}) {
|
|
15
|
-
const log = [], agents = [];
|
|
14
|
+
function fakeSeam({ heads = [H1], fins = [fin()], summary, lanes = [], gatePlan = { clusters: 1, skill: "forgedock:test-gate" } } = {}) {
|
|
15
|
+
const log = [], agents = [], gateSaved = [], agentCalls = [];
|
|
16
16
|
let h = 0, f = 0, l = 0, n = 100;
|
|
17
17
|
return {
|
|
18
|
-
log, agents,
|
|
18
|
+
log, agents, gateSaved, agentCalls,
|
|
19
19
|
pre: async (a) => { log.push(["pre", a.delta]); return { code: 0, data: manifest(a.delta ? heads[heads.length - 1] : H1, a.delta ? { from: a.delta, files: ["x"] } : null), lines: [] }; },
|
|
20
20
|
finalize: async () => { log.push(["finalize"]); return fins[Math.min(f++, fins.length - 1)]; },
|
|
21
21
|
summary: async (a) => { log.push(["summary", a.filed]); return summary ?? { code: 0, data: { verdict: "APPROVE FOR DEPLOY", marker: "FORGE:GATE_PASS", ciFailing: 0 }, lines: [] }; },
|
|
22
22
|
headOf: async () => heads[Math.min(h++, heads.length - 1)],
|
|
23
23
|
readFile: (p) => `brief ${p}`,
|
|
24
24
|
markLaunched: (file, domains) => log.push(["launched", domains]),
|
|
25
|
-
saveTestGate: () => "/sd/7_test_gate_output.txt",
|
|
26
|
-
|
|
25
|
+
saveTestGate: (pr, text) => { gateSaved.push(text); return "/sd/7_test_gate_output.txt"; },
|
|
26
|
+
testGatePlan: async () => gatePlan,
|
|
27
|
+
runAgent: async (a) => { agentCalls.push(a); agents.push(a.role + (a.prompt.includes("findings block required") ? ":reask" : "")); return { text: "ok" }; },
|
|
27
28
|
fileIssue: async ({ item }) => { log.push(["file", item.title]); return n++; },
|
|
28
29
|
fileCiIssue: async () => { log.push(["ci-issue"]); return n++; },
|
|
29
30
|
issueMerged: async () => false,
|
|
@@ -53,7 +54,7 @@ describe("reviewStep", () => {
|
|
|
53
54
|
|
|
54
55
|
it("realSeam exposes every effect the steps use, matching the fake seam", () => {
|
|
55
56
|
const real = Object.keys(realSeam({ repo: "o/r", def: "main", env: {}, cwd: "/tmp" })).sort();
|
|
56
|
-
assert.deepEqual(real, Object.keys(fakeSeam()).filter((k) =>
|
|
57
|
+
assert.deepEqual(real, Object.keys(fakeSeam()).filter((k) => !["log", "agents", "gateSaved", "agentCalls"].includes(k)).sort());
|
|
57
58
|
});
|
|
58
59
|
|
|
59
60
|
it("runs the briefs and the spec panel in parallel, then test gate, finalize and summary in order", async () => {
|
|
@@ -206,6 +207,16 @@ describe("fixStep", () => {
|
|
|
206
207
|
assert.ok(!s2.log.some((e) => e[0] === "ci-issue" || e[0] === "lane"));
|
|
207
208
|
});
|
|
208
209
|
|
|
210
|
+
it("only pending CI (#5519): blocks without a CI issue or lane; a real failure alongside still files", async () => {
|
|
211
|
+
const s = fakeSeam();
|
|
212
|
+
const r = await fixStep(ctx(s, { review: { result: { ...failed, blocking: [], filed: [], ciFailing: 1, ciPendingOnly: true } } }));
|
|
213
|
+
assert.match(r.reason, /still pending/);
|
|
214
|
+
assert.deepEqual(s.log, []);
|
|
215
|
+
const s2 = fakeSeam();
|
|
216
|
+
await fixStep(ctx(s2, { review: { result: { ...failed, blocking: [], filed: [], ciFailing: 2, ciPendingOnly: false } } }));
|
|
217
|
+
assert.ok(s2.log.some((e) => e[0] === "ci-issue"));
|
|
218
|
+
});
|
|
219
|
+
|
|
209
220
|
it("blocks when the verdict is not a pass but there is nothing to fix", async () => {
|
|
210
221
|
assert.match((await fixStep(ctx(fakeSeam(), { review: { result: { ...failed, blocking: [], ciFailing: 0 } } }))).reason, /nothing to fix|neither/);
|
|
211
222
|
});
|
|
@@ -319,3 +330,61 @@ describe("withIntegrityMarker (filing release findings through issue-create.sh)"
|
|
|
319
330
|
assert.match(out, /FORGE:BODY-INTEGRITY:fix-auto-spawned-schedd-review-finding -->/);
|
|
320
331
|
});
|
|
321
332
|
});
|
|
333
|
+
|
|
334
|
+
describe("#5516 release test gate", () => {
|
|
335
|
+
it("no integration_tests configured: no gate session, and the saved output carries the guard's SKIP marker", async () => {
|
|
336
|
+
const s = fakeSeam({ gatePlan: { clusters: 0, skill: "forgedock:test-gate" } });
|
|
337
|
+
await reviewStep(ctx(s));
|
|
338
|
+
assert.ok(!s.agents.includes("release-test-gate"), "no session decides a deterministic SKIP");
|
|
339
|
+
assert.equal(s.gateSaved.length, 1);
|
|
340
|
+
assert.match(s.gateSaved[0], /FORGE:TEST_GATE:RESULT=SKIP/);
|
|
341
|
+
assert.match(s.gateSaved[0], /reason=no-tests-configured/);
|
|
342
|
+
});
|
|
343
|
+
it("before the fix the gate output had no marker (finalize failed closed); the SKIP output has exactly one RESULT marker", () => {
|
|
344
|
+
assert.equal((TEST_GATE_SKIP_NO_TESTS.match(/FORGE:TEST_GATE:RESULT=(BLOCK|PASS|SKIP)/g) ?? []).length, 1);
|
|
345
|
+
});
|
|
346
|
+
it("clusters configured: the gate runs in a full session and the prompt names the resolved skill", async () => {
|
|
347
|
+
const s = fakeSeam({ gatePlan: { clusters: 2, skill: "forgedock:test-gate" } });
|
|
348
|
+
await reviewStep(ctx(s));
|
|
349
|
+
const g = s.agentCalls.find((a) => a.role === "release-test-gate");
|
|
350
|
+
assert.ok(g && g.fullSession === true, "Skill/Task/Bash available to the gate session");
|
|
351
|
+
assert.match(g.prompt, /Invoke the Skill "forgedock:test-gate" with args: --prs "1 2" --base main/);
|
|
352
|
+
assert.ok(!/^\/test-gate/.test(g.prompt));
|
|
353
|
+
const reviewers = s.agentCalls.filter((a) => a.role !== "release-test-gate");
|
|
354
|
+
assert.ok(reviewers.every((a) => !a.fullSession), "reviewers keep the lean session");
|
|
355
|
+
});
|
|
356
|
+
it("an unreadable config (clusters null) still runs the gate session, never a SKIP", async () => {
|
|
357
|
+
const s = fakeSeam({ gatePlan: { clusters: null, skill: "test-gate" } });
|
|
358
|
+
await reviewStep(ctx(s));
|
|
359
|
+
assert.ok(s.agents.includes("release-test-gate"));
|
|
360
|
+
});
|
|
361
|
+
it("integrationTestCount reads the verification block", () => {
|
|
362
|
+
assert.equal(integrationTestCount("project:\n repo: x\n"), 0);
|
|
363
|
+
assert.equal(integrationTestCount("verification:\n integration_tests: []\n"), 0);
|
|
364
|
+
assert.equal(integrationTestCount("verification:\n test_gate:\n posture: blocking\n"), 0);
|
|
365
|
+
assert.equal(integrationTestCount("verification:\n integration_tests:\n - cluster: api\n command: pytest\n - cluster: web\n command: npm test\n test_services:\n api: c\n"), 2);
|
|
366
|
+
assert.equal(integrationTestCount("verification:\n integration_tests: [{cluster: a}]\n"), null);
|
|
367
|
+
});
|
|
368
|
+
it("resolveSkillName: prefixed on a plugin install, bare otherwise", () => {
|
|
369
|
+
assert.equal(resolveSkillName("test-gate", { configDir: "/c", read: () => '{"plugins":{"forgedock@forgedock":[{}]}}' }), "forgedock:test-gate");
|
|
370
|
+
assert.equal(resolveSkillName("test-gate", { configDir: "/c", read: () => '{"plugins":{}}' }), "test-gate");
|
|
371
|
+
assert.equal(resolveSkillName("test-gate", { configDir: "/c", read: () => { throw new Error("ENOENT"); } }), "test-gate");
|
|
372
|
+
});
|
|
373
|
+
it("testGatePrompt", () => {
|
|
374
|
+
assert.match(testGatePrompt("test-gate", [5, 6], "main"), /Skill "test-gate" with args: --prs "5 6" --base main/);
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
describe("#5516 makeLeanRunner fullSession", () => {
|
|
379
|
+
it("fullSession drops the lean minimal flags (slash commands/Skill stay available); the default keeps them", async () => {
|
|
380
|
+
const { makeLeanRunner } = await import("./effects.mjs");
|
|
381
|
+
const seen = [];
|
|
382
|
+
const runCli = async (o) => { seen.push(o.sessionFlags); return { text: "", usage: null, costUsd: 0, durationMs: 0, turns: 0, sessionId: "s" }; };
|
|
383
|
+
const base = { role: "release-test-gate", issue: 1, cwd: process.cwd(), prompt: "p", system: "" };
|
|
384
|
+
await makeLeanRunner({ runCli, probe: () => false })({ ...base });
|
|
385
|
+
await makeLeanRunner({ runCli, probe: () => false })({ ...base, fullSession: true });
|
|
386
|
+
const [lean, full] = seen;
|
|
387
|
+
assert.deepEqual(full, [], "no --disable-slash-commands / tool restriction for the gate session");
|
|
388
|
+
if (lean.length) assert.ok(lean.some((f) => /slash|tools|mcp/i.test(f)), `lean flags restrict the session: ${lean.join(" ")}`);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/** Unit/coupling/contract/force resolver for `.forge/release.yaml` (#5551): every path resolves to a unit or "none". */
|
|
4
|
+
|
|
5
|
+
/** Glob to RegExp: `**` any depth (a trailing `/**` also matches the directory's files), `*` within a segment, `?` one char. */
|
|
6
|
+
export function unitGlobToRegExp(glob) {
|
|
7
|
+
let re = "";
|
|
8
|
+
for (let i = 0; i < glob.length; i++) {
|
|
9
|
+
const c = glob[i];
|
|
10
|
+
if (c === "*" && glob[i + 1] === "*") {
|
|
11
|
+
i++;
|
|
12
|
+
if (glob[i + 1] === "/") { i++; re += "(?:.*/)?"; } else re += ".*";
|
|
13
|
+
} else if (c === "*") re += "[^/]*";
|
|
14
|
+
else if (c === "?") re += "[^/]";
|
|
15
|
+
else re += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
16
|
+
}
|
|
17
|
+
return new RegExp(`^${re}$`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const matchesAny = (globs, path) => (globs ?? []).some((g) => unitGlobToRegExp(String(g)).test(path));
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @returns {{path, unit: string|"none", units: string[], affects: string[], contracts: object[], forces: object[]}}
|
|
24
|
+
* `unit` is the first unit (declaration order) owning the path; `units` every owner; `affects` the units the matching couplings fan out to.
|
|
25
|
+
*/
|
|
26
|
+
export function resolvePath(policy, rawPath) {
|
|
27
|
+
const path = String(rawPath).replace(/^\.\//, "");
|
|
28
|
+
const units = Object.entries(policy?.units ?? {}).filter(([, u]) => matchesAny(u?.paths, path)).map(([id]) => id);
|
|
29
|
+
const affects = [...new Set((policy?.couplings ?? []).filter((c) => matchesAny(c.paths, path)).flatMap((c) => c.affects ?? []))];
|
|
30
|
+
return {
|
|
31
|
+
path, unit: units[0] ?? "none", units, affects,
|
|
32
|
+
contracts: (policy?.contracts ?? []).filter((c) => matchesAny(c.paths, path)),
|
|
33
|
+
forces: (policy?.forces ?? []).filter((f) => matchesAny(f.paths, path)),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 { unitGlobToRegExp, resolvePath } from "./release-unitmap.mjs";
|
|
6
|
+
|
|
7
|
+
const policy = {
|
|
8
|
+
units: { api: { paths: ["services/api/**"] }, worker: { paths: ["services/worker/**"] }, web: { paths: ["web/*.js"] } },
|
|
9
|
+
couplings: [{ paths: ["shared/**"], affects: ["api", "worker"] }, { paths: ["emails/**"], affects: ["api", "web"] }],
|
|
10
|
+
contracts: [{ producer: "api", consumers: ["web"], paths: ["services/api/app/routers/**"] }],
|
|
11
|
+
forces: [{ paths: ["infra/migrations/**"], pipeline: "full", reason: "migrations" }, { paths: ["docker-compose*.yml"], pipeline: "full", reason: "deploy-mechanics" }],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
describe("unitGlobToRegExp", () => {
|
|
15
|
+
it("** crosses directories, * does not, ? is one char", () => {
|
|
16
|
+
assert.ok(unitGlobToRegExp("a/**").test("a/b/c.txt"));
|
|
17
|
+
assert.ok(unitGlobToRegExp("**/x.json").test("x.json") && unitGlobToRegExp("**/x.json").test("a/b/x.json"));
|
|
18
|
+
assert.ok(unitGlobToRegExp("a/*.js").test("a/b.js") && !unitGlobToRegExp("a/*.js").test("a/b/c.js"));
|
|
19
|
+
assert.ok(unitGlobToRegExp("a?.js").test("ab.js") && !unitGlobToRegExp("a?.js").test("a/.js"));
|
|
20
|
+
assert.ok(!unitGlobToRegExp("a.js").test("axjs"));
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("resolvePath", () => {
|
|
25
|
+
it("resolves a path to its unit or none", () => {
|
|
26
|
+
for (const [p, u] of [["services/api/app/main.py", "api"], ["services/worker/x.py", "worker"], ["web/a.js", "web"], ["README.md", "none"], ["web/sub/a.js", "none"]]) assert.equal(resolvePath(policy, p).unit, u, p);
|
|
27
|
+
});
|
|
28
|
+
it("fans a coupling out, flags a contract and a force", () => {
|
|
29
|
+
assert.deepEqual(resolvePath(policy, "shared/x.py").affects, ["api", "worker"]);
|
|
30
|
+
assert.equal(resolvePath(policy, "shared/x.py").unit, "none");
|
|
31
|
+
assert.equal(resolvePath(policy, "services/api/app/routers/a.py").contracts[0].producer, "api");
|
|
32
|
+
assert.equal(resolvePath(policy, "infra/migrations/001.sql").forces[0].reason, "migrations");
|
|
33
|
+
assert.equal(resolvePath(policy, "./docker-compose.prod.yml").forces[0].reason, "deploy-mechanics");
|
|
34
|
+
});
|
|
35
|
+
it("first declared unit wins and every owner is listed", () => {
|
|
36
|
+
const p = { units: { a: { paths: ["x/**"] }, b: { paths: ["x/y/**"] } } };
|
|
37
|
+
const r = resolvePath(p, "x/y/z");
|
|
38
|
+
assert.equal(r.unit, "a"); assert.deepEqual(r.units, ["a", "b"]);
|
|
39
|
+
});
|
|
40
|
+
it("an empty policy resolves everything to none", () => assert.equal(resolvePath({}, "a").unit, "none"));
|
|
41
|
+
});
|