forgedock 1.66.0 → 1.67.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 +2 -0
- package/bin/engine/outcome-codes.mjs +1 -0
- package/bin/engine-cli.mjs +96 -17
- package/bin/forgedock.mjs +7 -0
- package/bin/help-text.mjs +3 -3
- package/bin/introspect-schedule.mjs +98 -0
- package/bin/introspect-schedule.test.mjs +67 -0
- package/bin/lean/advisory.test.mjs +49 -0
- package/bin/lean/amendment-schema.mjs +31 -0
- package/bin/lean/attempts.mjs +159 -0
- package/bin/lean/attempts.test.mjs +127 -0
- package/bin/lean/basered.mjs +55 -0
- package/bin/lean/basered.test.mjs +68 -1
- package/bin/lean/batch-health.mjs +3 -0
- package/bin/lean/batch-health.test.mjs +16 -0
- package/bin/lean/batch.mjs +45 -0
- package/bin/lean/batch.test.mjs +54 -3
- package/bin/lean/capwait.mjs +14 -3
- package/bin/lean/capwait.test.mjs +20 -0
- package/bin/lean/clear-breaker.mjs +14 -0
- package/bin/lean/commentstate.mjs +41 -0
- package/bin/lean/commentstate.test.mjs +32 -0
- package/bin/lean/concurrency.mjs +89 -0
- package/bin/lean/concurrency.test.mjs +113 -0
- package/bin/lean/conformance.e2e.test.mjs +4 -2
- package/bin/lean/conformance.mjs +35 -3
- package/bin/lean/conformance.test.mjs +52 -0
- package/bin/lean/efficiency.mjs +162 -0
- package/bin/lean/efficiency.test.mjs +79 -0
- package/bin/lean/execution.mjs +31 -13
- package/bin/lean/execution.test.mjs +46 -0
- package/bin/lean/failure-stop.mjs +46 -0
- package/bin/lean/failure-stop.test.mjs +45 -0
- package/bin/lean/fixtures/capacity-storm.json +609 -0
- package/bin/lean/lean.mjs +123 -24
- package/bin/lean/lean.test.mjs +137 -46
- package/bin/lean/liveness.mjs +37 -0
- package/bin/lean/liveness.test.mjs +33 -0
- package/bin/lean/orchestrate-attempts.test.mjs +74 -0
- package/bin/lean/orchestrate-pause.test.mjs +23 -0
- package/bin/lean/orchestrate-reconcile.test.mjs +147 -0
- package/bin/lean/orchestrate.mjs +170 -26
- package/bin/lean/phaseledger.mjs +6 -0
- package/bin/lean/phaseledger.test.mjs +13 -1
- package/bin/lean/prompts.mjs +6 -10
- package/bin/lean/reconcile.mjs +90 -0
- package/bin/lean/recurrence.mjs +38 -2
- package/bin/lean/recurrence.test.mjs +56 -1
- package/bin/lean/sandbox-remote.mjs +33 -2
- package/bin/lean/sched.mjs +19 -0
- package/bin/lean/sched.test.mjs +11 -1
- package/bin/lean/schedd-health.mjs +4 -4
- package/bin/lean/schedd-health.test.mjs +8 -4
- package/bin/lean/schedd.mjs +34 -2
- package/bin/lean/schedd.test.mjs +55 -2
- package/bin/lean/slo.mjs +126 -0
- package/bin/lean/slo.test.mjs +112 -0
- package/bin/lean/statuscomment.mjs +37 -0
- package/bin/lean/statuscomment.test.mjs +48 -1
- package/bin/lean/verify.mjs +2 -1
- package/bin/pool/agent.mjs +2 -2
- package/bin/pool/cli.mjs +16 -1
- package/bin/pool/lane-tools.mjs +21 -0
- package/bin/stats/attempts.mjs +54 -0
- package/bin/stats/attempts.test.mjs +30 -0
- package/bin/stats/churn.mjs +49 -0
- package/bin/stats/churn.test.mjs +31 -0
- package/bin/stats/index.mjs +11 -3
- package/commands/orchestrate.md +21 -18
- package/docs/OUTCOME-CODES.md +1 -0
- package/package.json +1 -1
- package/scripts/check-devdocs-freshness.sh +1 -1
package/bin/lean/batch.test.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { join } from "node:path";
|
|
|
8
8
|
import { tmpDir } from "../tests/_tmp.mjs";
|
|
9
9
|
import { resolveLane, makeLaneCache } from "./lane.mjs";
|
|
10
10
|
import { orchestrate, deferPolicy, DEFER_BACKOFF_S, formatOutcomeLists, CAPACITY_FALLBACK_AFTER, isTransientEngineError, transientRetryDelayMs, DEFAULT_TRANSIENT_RETRIES } from "./orchestrate.mjs";
|
|
11
|
-
import { openBatch, fsTypeOf, assertDiskPath, isLaneAlive, writeAtomic, launchLane, detachedLanes, stackedOnOf } from "./batch.mjs";
|
|
11
|
+
import { openBatch, fsTypeOf, assertDiskPath, isLaneAlive, writeAtomic, launchLane, detachedLanes, stackedOnOf, keptSandboxes } from "./batch.mjs";
|
|
12
12
|
import { makeLedger } from "./ledger.mjs";
|
|
13
13
|
import { placeLane } from "./execution.mjs";
|
|
14
14
|
import { liveRemote } from "./live-execution.mjs";
|
|
@@ -273,9 +273,9 @@ await orchestrateFromCli(["1", "2", "3", "--parallel", "2", "--repo", "o/r", "--
|
|
|
273
273
|
assert.equal(isLaneAlive(42, "lane", { kill: () => true, procDir: proc }), false);
|
|
274
274
|
assert.deepEqual(stackedOnOf({ stacked: { 7: { dependency: 6, branch: "b", sha: "abcdef1" } } }, 7), { dependency: 6, branch: "b", sha: "abcdef1" }, "#5832: stackedOn read from batch state");
|
|
275
275
|
assert.equal(stackedOnOf({}, 7), null);
|
|
276
|
-
assert.deepEqual(readOrchestration(root), { breaker: { errors: 3, window_min: 30 }, maxDeferrals: 3, transientRetries: 4, blockedLabel: "blocked", globalParallel: null, stacking: "off", recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, baseSync: { enabled: true, unionGlobs: [] }, mergeTrain: "off", mergeTrainBatch: 4 });
|
|
276
|
+
assert.deepEqual(readOrchestration(root), { breaker: { errors: 3, window_min: 30 }, maxDeferrals: 3, transientRetries: 4, blockedLabel: "blocked", globalParallel: null, stacking: "off", recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, baseSync: { enabled: true, unionGlobs: [] }, mergeTrain: "off", mergeTrainBatch: 4, maxAttemptsPerIssue: 4, maxIdenticalSignature: 2 });
|
|
277
277
|
writeFileSync(join(root, "forge.yaml"), "orchestration:\n breaker:\n errors: 5\n window_min: 10\n max_deferrals: 2\n global_parallel: 4\n transient_retries: 2\n");
|
|
278
|
-
assert.deepEqual(readOrchestration(root), { breaker: { errors: 5, window_min: 10 }, maxDeferrals: 2, transientRetries: 2, blockedLabel: "blocked", globalParallel: 4, stacking: "off", recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, baseSync: { enabled: true, unionGlobs: [] }, mergeTrain: "off", mergeTrainBatch: 4 });
|
|
278
|
+
assert.deepEqual(readOrchestration(root), { breaker: { errors: 5, window_min: 10 }, maxDeferrals: 2, transientRetries: 2, blockedLabel: "blocked", globalParallel: 4, stacking: "off", recovery: { maxAttempts: 1, mechanicalMaxAttempts: 2 }, baseSync: { enabled: true, unionGlobs: [] }, mergeTrain: "off", mergeTrainBatch: 4, maxAttemptsPerIssue: 4, maxIdenticalSignature: 2 });
|
|
279
279
|
});
|
|
280
280
|
|
|
281
281
|
it("run-issue --result-file writes the lane result, also when the run throws", async () => {
|
|
@@ -2145,3 +2145,54 @@ describe("#5975: batch pause", () => {
|
|
|
2145
2145
|
assert.equal(evaluateDispatchStall(state, { ...opts, paused: { reason: "x" } }), null);
|
|
2146
2146
|
});
|
|
2147
2147
|
});
|
|
2148
|
+
|
|
2149
|
+
describe("#5992: base.red is a batch hold, not a per-issue capped deferral", () => {
|
|
2150
|
+
it("base.red is uncapped; other codes still cap", () => {
|
|
2151
|
+
assert.deepEqual(deferPolicy({ code: "base.red", retryInSeconds: 900 }, { now: 0, deferrals: 99, maxDeferrals: 3 }), { delayMs: 900000, host: true });
|
|
2152
|
+
assert.deepEqual(deferPolicy({ code: "merge.transient", retryInSeconds: 60 }, { now: 0, deferrals: 3, maxDeferrals: 3 }), { capped: true });
|
|
2153
|
+
});
|
|
2154
|
+
|
|
2155
|
+
it("10 lanes + red base: 1 probe run, only the fixer launches, no 'gave up'; a sha move resumes admission in one pass", async () => {
|
|
2156
|
+
const { c, now, sleep } = fakeClock();
|
|
2157
|
+
const issues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
2158
|
+
const launches = [], updates = [];
|
|
2159
|
+
let sha = "a".repeat(40), probes = 0;
|
|
2160
|
+
const baseProbe = async () => { probes++; return sha === "a".repeat(40) ? { red: true, sha, commands: ["guard"], att: { sha: "f".repeat(40), issue: 10 } } : { red: false, sha }; };
|
|
2161
|
+
let passes = 0;
|
|
2162
|
+
const rows = await orchestrate({ issues, parallel: 10, maxDeferrals: 3, now, readBody: async () => "", baseProbe, pollMs: 10,
|
|
2163
|
+
onUpdate: (u) => updates.push(u),
|
|
2164
|
+
sleep: async (ms) => { await sleep(ms); if (++passes === 3) sha = "b".repeat(40); },
|
|
2165
|
+
runOne: async (n) => { launches.push([n, sha === "a".repeat(40) ? "red" : "green"]); return { terminalReason: "merged", pr: 100 + n }; } });
|
|
2166
|
+
const redLaunches = launches.filter((l) => l[1] === "red").map((l) => l[0]);
|
|
2167
|
+
assert.deepEqual(redLaunches, [10], "only the attributed fixer is admitted while the base is red");
|
|
2168
|
+
assert.equal(launches.length, 10, "every lane runs once after the base moves");
|
|
2169
|
+
assert.ok(rows.every((r) => r.outcome === "merged"));
|
|
2170
|
+
assert.ok(!rows.some((r) => /gave up/.test(r.detail ?? "")));
|
|
2171
|
+
assert.equal(updates.filter((u) => u.code === "base.red").length, 1, "one batch-level hold row");
|
|
2172
|
+
assert.ok(updates.some((u) => /base\.red cleared/.test(u.detail ?? "")));
|
|
2173
|
+
assert.ok(c.t >= 1_000_000);
|
|
2174
|
+
});
|
|
2175
|
+
});
|
|
2176
|
+
|
|
2177
|
+
// #5978: the selector is kept in the batch plan argv/state; coverage classifies every matching open issue.
|
|
2178
|
+
import { coverage as coverage5978 } from "./batch.mjs";
|
|
2179
|
+
describe("coverage (#5978)", () => {
|
|
2180
|
+
it("every open match lands in exactly one class; human-blocked is the only unscheduled-allowed class", () => {
|
|
2181
|
+
const state = { pending: [2], running: { 1: {} }, results: { 3: { outcome: "needs-human", detail: "needs a product decision" } } };
|
|
2182
|
+
const c = coverage5978({ state, open: [1, 2, 3].map((number) => ({ number })) });
|
|
2183
|
+
assert.deepEqual([c.running, c.queued, c.humanBlocked, c.unscheduled], [[1], [2], [3], []]);
|
|
2184
|
+
});
|
|
2185
|
+
it("a human label blocks an issue with no row; an unknown one is unscheduled", () => {
|
|
2186
|
+
const c = coverage5978({ state: { pending: [] }, open: [{ number: 4, labels: ["human:credentials"] }, { number: 5, labels: ["bug"] }] });
|
|
2187
|
+
assert.deepEqual([c.humanBlocked, c.unscheduled], [[4], [5]]);
|
|
2188
|
+
});
|
|
2189
|
+
});
|
|
2190
|
+
|
|
2191
|
+
describe("#6008 kept-sandbox listing", () => {
|
|
2192
|
+
it("lists issue, age and phase from state.kept and, with no live dispatcher, from remote run records", () => {
|
|
2193
|
+
const state = { kept: { 5: { issue: 5, since: 1_000, phase: "review", id: "sbx-5" } }, running: { 6: { startedAt: 4_000, remote: true, handle: { id: "sbx-6" } }, 7: { startedAt: 4_000, pid: 99 } } };
|
|
2194
|
+
const rows = keptSandboxes(state, { now: 61_000 });
|
|
2195
|
+
assert.deepEqual(rows.map((r) => [r.issue, r.ageMs, r.phase]), [[5, 60_000, "review"], [6, 57_000, null]]);
|
|
2196
|
+
assert.deepEqual(keptSandboxes(state, { now: 61_000, live: true }).map((r) => r.issue), [5], "a live dispatcher's running lanes are not kept");
|
|
2197
|
+
});
|
|
2198
|
+
});
|
package/bin/lean/capwait.mjs
CHANGED
|
@@ -4,22 +4,33 @@
|
|
|
4
4
|
* Capacity wait (#4909): a lane whose sandbox launch was refused for capacity (`sandbox.capacity`) is admitted again only
|
|
5
5
|
* once the pool reports a free slot (`capacity() -> {free}`), not on a blind timer retry; the wait is recorded as queue
|
|
6
6
|
* time (`waits.queue`, ms). A pool that does not report `free` is unknown: the provider's retry-in applies as before.
|
|
7
|
+
* #5985: a refusal that names its reason (`pool.host_load`, `pool.host_mem`) waits on that condition clearing (load below
|
|
8
|
+
* 1.0, free memory above the floor) instead; with no figures for it the slot count above is the fallback.
|
|
7
9
|
*/
|
|
10
|
+
import { conditionCleared } from "./concurrency.mjs";
|
|
11
|
+
|
|
8
12
|
export function makeCapWait({ now = Date.now } = {}) {
|
|
9
13
|
const since = new Map(); // issue -> when its launch was refused for capacity
|
|
14
|
+
const reasons = new Map(); // issue -> the pool reason of its refusal (#5985)
|
|
10
15
|
const waited = new Map(); // issue -> queue ms accumulated, not yet recorded on a row
|
|
11
16
|
const isFree = (cap) => Boolean(cap) && Number.isInteger(cap.free) && cap.free > 0;
|
|
12
17
|
const isFull = (cap) => Boolean(cap) && Number.isInteger(cap.free) && cap.free <= 0;
|
|
13
18
|
return {
|
|
14
19
|
/** A launch of `issue` was refused for capacity. */
|
|
15
|
-
refused(issue) { if (!since.has(issue)) since.set(issue, now()); },
|
|
20
|
+
refused(issue, reason = null) { if (!since.has(issue)) since.set(issue, now()); if (reason) reasons.set(issue, reason); else reasons.delete(issue); },
|
|
16
21
|
/** True while a refused `issue` must keep waiting: the sampled pool reports no free slot. */
|
|
17
|
-
blocked(issue, cap) {
|
|
22
|
+
blocked(issue, cap) {
|
|
23
|
+
if (!since.has(issue)) return false;
|
|
24
|
+
const c = conditionCleared(reasons.get(issue), cap);
|
|
25
|
+
return c === null ? isFull(cap) : !c;
|
|
26
|
+
},
|
|
27
|
+
/** True when `cap` has the figures the refusal's named condition needs (the timer is not the wake). */
|
|
28
|
+
conditional(issue, cap) { return since.has(issue) && conditionCleared(reasons.get(issue), cap) !== null; },
|
|
18
29
|
/** `issue` was admitted: bank its wait as queue time. Returns the ms waited (0 when it was not refused). */
|
|
19
30
|
admitted(issue) {
|
|
20
31
|
if (!since.has(issue)) return 0;
|
|
21
32
|
const ms = Math.max(0, now() - since.get(issue));
|
|
22
|
-
since.delete(issue);
|
|
33
|
+
since.delete(issue); reasons.delete(issue);
|
|
23
34
|
waited.set(issue, (waited.get(issue) ?? 0) + ms);
|
|
24
35
|
return ms;
|
|
25
36
|
},
|
|
@@ -46,3 +46,23 @@ describe("at pool capacity a lane waits for a free slot (#4909)", () => {
|
|
|
46
46
|
assert.ok(Number.isFinite(rows[0].waits?.queue) && rows[0].waits.queue >= 0, "wait recorded as queue time");
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
+
|
|
50
|
+
describe("capwait wakes on the named condition (#5985)", () => {
|
|
51
|
+
it("a host_load refusal holds until load < 1.0 whatever the slots say; host_mem until free mem > floor; no figures: slot fallback", () => {
|
|
52
|
+
let t = 0;
|
|
53
|
+
const w = makeCapWait({ now: () => t });
|
|
54
|
+
w.refused(1, "host_load");
|
|
55
|
+
assert.equal(w.blocked(1, { free: 5, load_per_core: 1.2 }), true, "free slots do not wake a load refusal");
|
|
56
|
+
t += 1000;
|
|
57
|
+
assert.equal(w.blocked(1, { free: 0, load_per_core: 0.8 }), false, "wakes the moment load clears, not on a timer");
|
|
58
|
+
w.refused(2, "pool.host_mem");
|
|
59
|
+
assert.equal(w.blocked(2, { mem_available_gb: 2 }), true);
|
|
60
|
+
assert.equal(w.blocked(2, { mem_available_gb: 9 }), false);
|
|
61
|
+
w.refused(3, "host_load");
|
|
62
|
+
assert.equal(w.blocked(3, { free: 0 }), true, "no load figure: the slot count is the fallback");
|
|
63
|
+
assert.equal(w.conditional(3, { free: 0 }), false);
|
|
64
|
+
assert.equal(w.conditional(1, { load_per_core: 0.5 }), true);
|
|
65
|
+
w.refused(4);
|
|
66
|
+
assert.equal(w.blocked(4, { free: 1, load_per_core: 3 }), false, "no reason: slot gate only");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -13,3 +13,17 @@ export function decideClear({ tripped, requestAt }) {
|
|
|
13
13
|
if (tripped && Number.isFinite(tripped.at) && tripped.at > requestAt) return { clear: false, stale: true };
|
|
14
14
|
return { clear: true, stale: false };
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* #5978: the runner's own reset of a tripped breaker. It closes after `cooldownMs` when the failures were environmental
|
|
19
|
+
* (VM restart, mirror, network: `environmental`) and the pool is healthy again (#5947 classes); anything else needs `--clear-breaker`.
|
|
20
|
+
* @param {{tripped: ({at?: number}|null|undefined), now: number, cooldownMs: number, environmental: boolean, poolHealthy: boolean}} p
|
|
21
|
+
* @returns {{reset: boolean, why: string}}
|
|
22
|
+
*/
|
|
23
|
+
export function decideAutoReset({ tripped, now, cooldownMs, environmental, poolHealthy }) {
|
|
24
|
+
if (!tripped || !Number.isFinite(tripped.at)) return { reset: false, why: "not tripped" };
|
|
25
|
+
if (!environmental) return { reset: false, why: "failure signature is not environmental" };
|
|
26
|
+
if (now - tripped.at < cooldownMs) return { reset: false, why: "cooldown not elapsed" };
|
|
27
|
+
if (!poolHealthy) return { reset: false, why: "pool not healthy" };
|
|
28
|
+
return { reset: true, why: "environmental signature, cooldown elapsed, pool healthy" };
|
|
29
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #5979: post a machine comment only on a state change. A scheduler pass that re-derives the same DEPENDENCY, FACTS, or
|
|
5
|
+
* NEEDS_HUMAN text posts nothing; a changed FACTS or DEPENDENCY is edited in place; a changed NEEDS_HUMAN is a new comment
|
|
6
|
+
* (statuscomment.mjs header: a new comment notifies a person, an edit does not, and issuewatch keys on the newest one). Pure.
|
|
7
|
+
*/
|
|
8
|
+
import { IN_PLACE_MARKERS } from "./statuscomment.mjs";
|
|
9
|
+
|
|
10
|
+
/** Markers whose changed state is PATCHed rather than posted again. */
|
|
11
|
+
export const PATCH_MARKERS = Object.freeze(IN_PLACE_MARKERS.filter((m) => m !== "FORGE:NEEDS_HUMAN"));
|
|
12
|
+
|
|
13
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
14
|
+
|
|
15
|
+
/** The body without what changes between identical states: the cost/usage line, comment urls and ids, shas, whitespace. */
|
|
16
|
+
export function normalizeState(body) {
|
|
17
|
+
return String(body ?? "")
|
|
18
|
+
.split("\n")
|
|
19
|
+
.filter((l) => !/^\s*_?\s*cost \$[\d.]+/i.test(l))
|
|
20
|
+
.join("\n")
|
|
21
|
+
.replace(/https?:\/\/\S*#issuecomment-\d+/g, "")
|
|
22
|
+
.replace(/\b[0-9a-f]{7,40}\b/g, "")
|
|
23
|
+
.replace(/\s+/g, " ")
|
|
24
|
+
.trim();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The newest trusted comment carrying `marker` (a `<!-- marker` line anywhere in the body), or null. */
|
|
28
|
+
export function findLast(comments, marker, trusted = () => true) {
|
|
29
|
+
const re = new RegExp(`<!--\\s*${esc(marker)}(?![A-Za-z0-9_])`);
|
|
30
|
+
const list = Array.isArray(comments) ? comments : [];
|
|
31
|
+
for (let i = list.length - 1; i >= 0; i--) if (re.test(String(list[i]?.body ?? "")) && trusted(list[i])) return list[i];
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** `{action: "skip"|"patch"|"create", prior}` for posting `body` under `marker` given the issue's comments. */
|
|
36
|
+
export function decidePost({ marker, body, comments, trusted }) {
|
|
37
|
+
const prior = findLast(comments, marker, trusted);
|
|
38
|
+
if (!prior) return { action: "create", prior: null };
|
|
39
|
+
if (normalizeState(prior.body) === normalizeState(body)) return { action: "skip", prior };
|
|
40
|
+
return { action: PATCH_MARKERS.includes(marker) ? "patch" : "create", prior };
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { normalizeState, findLast, decidePost } from "./commentstate.mjs";
|
|
6
|
+
import { IN_PLACE_MARKERS } from "./statuscomment.mjs";
|
|
7
|
+
|
|
8
|
+
const body = (m, text, cost = "0.10") => `<!-- ${m} -->\n${text}\n\n_cost $${cost}, tokens 1 in / 2 out_`;
|
|
9
|
+
const url = "https://github.com/o/r/issues/1#issuecomment-5";
|
|
10
|
+
|
|
11
|
+
describe("post only on a state change (#5979)", () => {
|
|
12
|
+
for (const m of IN_PLACE_MARKERS) {
|
|
13
|
+
it(`a second identical ${m} post is skipped, even when only the usage line differs`, () => {
|
|
14
|
+
const comments = [{ body: body(m, "same state"), url }];
|
|
15
|
+
assert.equal(decidePost({ marker: m, body: body(m, "same state", "9.99"), comments }).action, "skip");
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
it("a changed DEPENDENCY or FACTS is patched in place; a changed NEEDS_HUMAN is a new comment", () => {
|
|
19
|
+
const comments = (m) => [{ body: body(m, "old"), url }];
|
|
20
|
+
assert.equal(decidePost({ marker: "FORGE:DEPENDENCY", body: body("FORGE:DEPENDENCY", "new"), comments: comments("FORGE:DEPENDENCY") }).action, "patch");
|
|
21
|
+
assert.equal(decidePost({ marker: "FORGE:FACTS", body: body("FORGE:FACTS", "new"), comments: comments("FORGE:FACTS") }).action, "patch");
|
|
22
|
+
assert.equal(decidePost({ marker: "FORGE:NEEDS_HUMAN", body: body("FORGE:NEEDS_HUMAN", "new"), comments: comments("FORGE:NEEDS_HUMAN") }).action, "create");
|
|
23
|
+
});
|
|
24
|
+
it("no earlier comment creates; an untrusted one is ignored", () => {
|
|
25
|
+
assert.equal(decidePost({ marker: "FORGE:DEPENDENCY", body: "x", comments: [] }).action, "create");
|
|
26
|
+
assert.equal(decidePost({ marker: "FORGE:DEPENDENCY", body: "x", comments: [{ body: body("FORGE:DEPENDENCY", "x") }], trusted: () => false }).action, "create");
|
|
27
|
+
});
|
|
28
|
+
it("findLast returns the newest; normalizeState drops usage, ids and shas", () => {
|
|
29
|
+
assert.equal(findLast([{ body: "<!-- FORGE:FACTS -->\na" }, { body: "<!-- FORGE:FACTS -->\nb" }], "FORGE:FACTS").body.endsWith("b"), true);
|
|
30
|
+
assert.equal(normalizeState(body("M", "a b 1e0c3e45")), normalizeState(body("M", "a b", "5")));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Closed-loop lane concurrency (#5985). K (`getParallel`/`--parallel`) is the ceiling; the operating point moves under it:
|
|
5
|
+
* additive increase while the pool reports headroom and has refused nothing lately, multiplicative decrease (halve) on a
|
|
6
|
+
* `pool.*` refusal or load above 1.5/core. A lane the pool refused is held for REFUSAL_HOLD_MS unless the named condition
|
|
7
|
+
* (load below 1.0, free memory above the floor) clears first. Pure: no I/O, the caller feeds samples and persists events.
|
|
8
|
+
*/
|
|
9
|
+
export const REFUSAL_HOLD_MS = 5 * 60_000;
|
|
10
|
+
export const HEAVY_CPU_AVG = 1.5;
|
|
11
|
+
export const LOAD_HALVE = 1.5;
|
|
12
|
+
export const LOAD_GREEN = 1.0;
|
|
13
|
+
export const MEM_FLOOR_GB = 4;
|
|
14
|
+
export const MEM_HEADROOM_GB = 2;
|
|
15
|
+
|
|
16
|
+
const fin = (v) => typeof v === "number" && Number.isFinite(v);
|
|
17
|
+
/** `host_load` from a refusal reason/code (`pool.host_load` or `host_load`); "" when it is not a pool reason. */
|
|
18
|
+
export const poolReason = (v) => { const m = /^(?:pool\.)?(host_load|host_mem|projected_peak|disk(?:_low|_cap)?)$/.exec(String(v ?? "")); return m ? m[1].replace(/^disk_.*/, "disk") : ""; };
|
|
19
|
+
|
|
20
|
+
/** The named condition a refusal waits on: true = cleared, false = still holding, null = unknown (no figures, or no named condition). */
|
|
21
|
+
export function conditionCleared(reason, cap, { memFloorGb = MEM_FLOOR_GB } = {}) {
|
|
22
|
+
const r = poolReason(reason);
|
|
23
|
+
if (r === "host_load") return fin(cap?.load_per_core) ? cap.load_per_core < LOAD_GREEN : null;
|
|
24
|
+
if (r === "host_mem") return fin(cap?.mem_available_gb) ? cap.mem_available_gb > memFloorGb : null;
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A repo is heavy when its recent finished lanes average more than 1.5 cpus (`usage-history.jsonl` rows `{repo, cpu_avg}`). */
|
|
29
|
+
export function classifyRepo(rows, repo, { window = 20 } = {}) {
|
|
30
|
+
const v = (rows ?? []).filter((x) => x && x.repo === repo && fin(x.cpu_avg)).slice(-window).map((x) => x.cpu_avg);
|
|
31
|
+
return v.length > 0 && v.reduce((a, b) => a + b, 0) / v.length > HEAVY_CPU_AVG ? "heavy" : "light";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function makeController({ ceiling, heavyCap = null, now = Date.now, memFloorGb = MEM_FLOOR_GB, holdMs = REFUSAL_HOLD_MS, start = null } = {}) {
|
|
35
|
+
let top = Math.max(1, Number.isInteger(ceiling) ? ceiling : 1);
|
|
36
|
+
let k = Math.min(top, Math.max(1, Number.isInteger(start) ? start : top)); // no signal yet: run at the ceiling, as before
|
|
37
|
+
let factor = "ceiling";
|
|
38
|
+
let lastRefusal = -Infinity;
|
|
39
|
+
const held = new Map(); // issue -> { at, reason }
|
|
40
|
+
const hcap = () => Math.max(1, Math.min(top, Number.isInteger(heavyCap) ? heavyCap : Math.ceil(top / 3)));
|
|
41
|
+
const ev = (change, inputs) => ({ event: "concurrency", change, k, ceiling: top, factor, inputs });
|
|
42
|
+
return {
|
|
43
|
+
setCeiling(c) { if (Number.isInteger(c) && c >= 1) { const was = top; top = c; k = k >= was ? top : Math.min(k, top); } },
|
|
44
|
+
/** The operating point under the ceiling; a heavy lane class has its own, lower cap. */
|
|
45
|
+
operating(klass = "light") { return Math.min(top, k, klass === "heavy" ? hcap() : Infinity); },
|
|
46
|
+
ceiling: () => top,
|
|
47
|
+
/** Concurrent heavy lanes allowed, separate from light lanes. */
|
|
48
|
+
heavyLimit: () => hcap(),
|
|
49
|
+
limiting(klass = "light") { return klass === "heavy" && hcap() < Math.min(top, k) ? "heavy cap" : k < top ? factor : "ceiling"; },
|
|
50
|
+
/** A launch was refused. Halves on a `pool.*` reason or load above 1.5/core. Returns the event, or null when nothing moved. */
|
|
51
|
+
refused({ issue = null, code = "", reason = "", live = null } = {}) {
|
|
52
|
+
const r = poolReason(reason) || poolReason(code);
|
|
53
|
+
const hot = fin(live?.load_per_core) && live.load_per_core > LOAD_HALVE;
|
|
54
|
+
if (issue !== null && r) held.set(issue, { at: now(), reason: r });
|
|
55
|
+
if (!r && !hot) return null;
|
|
56
|
+
const t = now();
|
|
57
|
+
if (t - lastRefusal < 1000) return null; // one storm of simultaneous refusals is one halving
|
|
58
|
+
lastRefusal = t;
|
|
59
|
+
const before = k;
|
|
60
|
+
k = Math.max(1, Math.floor(k / 2));
|
|
61
|
+
factor = r || "host_load";
|
|
62
|
+
return k === before ? null : ev("decrease", { from: before, reason: r || "load", live });
|
|
63
|
+
},
|
|
64
|
+
/** One pool sample: +1 while memory is above floor+headroom, load below 1 and nothing was refused for `holdMs`. */
|
|
65
|
+
observe(cap) {
|
|
66
|
+
if (!cap || !fin(cap.load_per_core) || !fin(cap.mem_available_gb)) return null; // unknown pool: K applies unchanged
|
|
67
|
+
if (k >= top) { factor = "ceiling"; return null; }
|
|
68
|
+
if (cap.mem_available_gb > memFloorGb + MEM_HEADROOM_GB && cap.load_per_core < LOAD_GREEN && now() - lastRefusal >= holdMs) {
|
|
69
|
+
const before = k; k += 1;
|
|
70
|
+
if (k >= top) factor = "ceiling";
|
|
71
|
+
return ev("increase", { from: before, load_per_core: cap.load_per_core, mem_available_gb: cap.mem_available_gb });
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
},
|
|
75
|
+
/** True while `issue` must not be launched: refused within holdMs and its named condition has not cleared. */
|
|
76
|
+
holding(issue, cap) {
|
|
77
|
+
const h = held.get(issue);
|
|
78
|
+
if (!h) return false;
|
|
79
|
+
if (conditionCleared(h.reason, cap, { memFloorGb }) === true || now() - h.at >= holdMs) { held.delete(issue); return false; }
|
|
80
|
+
return true;
|
|
81
|
+
},
|
|
82
|
+
release(issue) { held.delete(issue); },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** `running/K/ceiling (limiting factor)`, with the configured ceiling as the achieved-vs-configured reference. */
|
|
87
|
+
export function formatConcurrency({ running, k, ceiling, factor = "ceiling" } = {}) {
|
|
88
|
+
return `concurrency: ${running ?? 0}/${k ?? ceiling}/${ceiling} (${factor})`;
|
|
89
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/** #5985: closed-loop lane concurrency. */
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { makeController, classifyRepo, conditionCleared, formatConcurrency, poolReason, REFUSAL_HOLD_MS } from "./concurrency.mjs";
|
|
8
|
+
|
|
9
|
+
const green = { load_per_core: 0.4, mem_available_gb: 12 };
|
|
10
|
+
const mk = (o = {}) => { const c = { t: 1_000_000 }; return { c, ctl: makeController({ ceiling: 8, now: () => c.t, ...o }) }; };
|
|
11
|
+
|
|
12
|
+
describe("controller (#5985)", () => {
|
|
13
|
+
it("halves on pool.host_load, increases +1 under a green pool, never above the ceiling or below 1", () => {
|
|
14
|
+
const { c, ctl } = mk();
|
|
15
|
+
assert.equal(ctl.operating(), 8, "no signal: K is the ceiling");
|
|
16
|
+
const e = ctl.refused({ issue: 1, code: "pool.host_load", live: { load_per_core: 2.2 } });
|
|
17
|
+
assert.equal(e.change, "decrease");
|
|
18
|
+
assert.equal(ctl.operating(), 4);
|
|
19
|
+
assert.equal(ctl.observe(green), null, "refusal in the last N minutes: no increase");
|
|
20
|
+
c.t += REFUSAL_HOLD_MS;
|
|
21
|
+
assert.equal(ctl.observe(green).change, "increase");
|
|
22
|
+
assert.equal(ctl.operating(), 5);
|
|
23
|
+
for (let i = 0; i < 10; i++) ctl.observe(green);
|
|
24
|
+
assert.equal(ctl.operating(), 8);
|
|
25
|
+
assert.equal(ctl.limiting(), "ceiling");
|
|
26
|
+
for (let i = 0; i < 6; i++) { c.t += 2000; ctl.refused({ code: "pool.host_mem" }); }
|
|
27
|
+
assert.equal(ctl.operating(), 1);
|
|
28
|
+
});
|
|
29
|
+
it("a high load alone halves; an unknown pool and a non-pool refusal leave K unchanged", () => {
|
|
30
|
+
const { ctl } = mk();
|
|
31
|
+
assert.equal(ctl.refused({ code: "sandbox.capacity" }), null);
|
|
32
|
+
assert.equal(ctl.observe(null), null);
|
|
33
|
+
assert.equal(ctl.observe({ load_per_core: 0.2 }), null);
|
|
34
|
+
assert.ok(ctl.refused({ live: { load_per_core: 1.8 } }));
|
|
35
|
+
assert.equal(ctl.operating(), 4);
|
|
36
|
+
assert.equal(ctl.limiting(), "host_load");
|
|
37
|
+
});
|
|
38
|
+
it("a red pool (low memory or load >= 1) does not increase", () => {
|
|
39
|
+
const { c, ctl } = mk();
|
|
40
|
+
ctl.refused({ code: "pool.host_load" }); c.t += REFUSAL_HOLD_MS;
|
|
41
|
+
assert.equal(ctl.observe({ load_per_core: 1.2, mem_available_gb: 12 }), null);
|
|
42
|
+
assert.equal(ctl.observe({ load_per_core: 0.3, mem_available_gb: 5 }), null);
|
|
43
|
+
});
|
|
44
|
+
it("classifies heavy repos from usage-history cpu_avg > 1.5 and caps heavy lanes below light", () => {
|
|
45
|
+
const rows = [{ repo: "a/h", cpu_avg: 3 }, { repo: "a/h", cpu_avg: 2 }, { repo: "a/l", cpu_avg: 0.4 }];
|
|
46
|
+
assert.equal(classifyRepo(rows, "a/h"), "heavy");
|
|
47
|
+
assert.equal(classifyRepo(rows, "a/l"), "light");
|
|
48
|
+
assert.equal(classifyRepo(rows, "a/none"), "light", "no history: light");
|
|
49
|
+
const { ctl } = mk({ ceiling: 16 });
|
|
50
|
+
assert.equal(ctl.operating("light"), 16);
|
|
51
|
+
assert.equal(ctl.operating("heavy"), 6);
|
|
52
|
+
assert.equal(ctl.limiting("heavy"), "heavy cap");
|
|
53
|
+
});
|
|
54
|
+
it("names the cleared condition and formats running/K/ceiling (limiting factor)", () => {
|
|
55
|
+
assert.equal(conditionCleared("pool.host_load", { load_per_core: 1.2 }), false);
|
|
56
|
+
assert.equal(conditionCleared("host_load", { load_per_core: 0.9 }), true);
|
|
57
|
+
assert.equal(conditionCleared("pool.host_mem", { mem_available_gb: 9 }), true);
|
|
58
|
+
assert.equal(conditionCleared("pool.host_mem", {}), null);
|
|
59
|
+
assert.equal(conditionCleared("pool.projected_peak", green), null);
|
|
60
|
+
assert.equal(poolReason("pool.disk_cap"), "disk");
|
|
61
|
+
assert.equal(poolReason("sandbox.capacity"), "");
|
|
62
|
+
assert.equal(formatConcurrency({ running: 3, k: 4, ceiling: 8, factor: "host_load" }), "concurrency: 3/4/8 (host_load)");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("503-storm replay (#5985)", () => {
|
|
67
|
+
it("at most 1 refusal per lane per 5 min: refused lanes hold until the condition clears", () => {
|
|
68
|
+
const fx = JSON.parse(readFileSync(new URL("./fixtures/capacity-storm.json", import.meta.url), "utf8"));
|
|
69
|
+
const c = { t: 0 };
|
|
70
|
+
const ctl = makeController({ ceiling: fx.lanes, now: () => c.t });
|
|
71
|
+
const byLane = new Map();
|
|
72
|
+
for (const a of fx.attempts) (byLane.get(a.lane) ?? byLane.set(a.lane, []).get(a.lane)).push(a);
|
|
73
|
+
const refusals = new Map();
|
|
74
|
+
for (c.t = 0; c.t <= fx.endMs; c.t += fx.pollMs) {
|
|
75
|
+
const cap = c.t < fx.clearsAtMs ? { load_per_core: 2.1, mem_available_gb: 1.2 } : { load_per_core: 0.6, mem_available_gb: 9 };
|
|
76
|
+
ctl.observe(cap);
|
|
77
|
+
for (const [lane, rows] of byLane) {
|
|
78
|
+
if (ctl.holding(lane, cap)) continue;
|
|
79
|
+
const storm = c.t < fx.clearsAtMs;
|
|
80
|
+
if (!storm) { ctl.release(lane); continue; }
|
|
81
|
+
const rec = rows.reduce((b, r) => (Math.abs(r.at - c.t) < Math.abs(b.at - c.t) ? r : b)); // the recorded refusal code nearest this attempt
|
|
82
|
+
ctl.refused({ issue: lane, code: rec.code, live: cap });
|
|
83
|
+
(refusals.get(lane) ?? refusals.set(lane, []).get(lane)).push(c.t);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
assert.ok(refusals.size === fx.lanes);
|
|
87
|
+
for (const [lane, ts] of refusals) for (let i = 0; i < ts.length; i++) {
|
|
88
|
+
const inWin = ts.filter((x) => x >= ts[i] && x < ts[i] + 300_000).length;
|
|
89
|
+
assert.ok(inWin <= 1, `lane ${lane}: ${inWin} refusals within 5 min`);
|
|
90
|
+
}
|
|
91
|
+
const unreplayed = fx.attempts.length; // the unconstrained timer retry would have refused each lane every minute
|
|
92
|
+
assert.ok([...refusals.values()].flat().length < unreplayed / 3);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("heavy lanes in orchestrate (#5985)", () => {
|
|
97
|
+
it("a heavy repo's lanes run at most the heavy cap at once while light lanes keep the rest of K", async () => {
|
|
98
|
+
const { orchestrate } = await import("./orchestrate.mjs");
|
|
99
|
+
const usageRows = [{ repo: "o/heavy", cpu_avg: 3 }, { repo: "o/light", cpu_avg: 0.3 }];
|
|
100
|
+
const run = async (repo) => {
|
|
101
|
+
let cur = 0, max = 0;
|
|
102
|
+
const events = [];
|
|
103
|
+
await orchestrate({ issues: [1, 2, 3, 4, 5, 6], parallel: 6, usageRows: () => usageRows, repoSlug: "o/none", repoOf: () => repo, readBody: async () => "", onUpdate: (e) => events.push(e),
|
|
104
|
+
sleep: async () => { await new Promise((r) => setImmediate(r)); },
|
|
105
|
+
runOne: async () => { cur++; max = Math.max(max, cur); await new Promise((r) => setTimeout(r, 20)); cur--; return { terminalReason: "merged", pr: 1 }; } });
|
|
106
|
+
return { max, events };
|
|
107
|
+
};
|
|
108
|
+
const heavy = await run("o/heavy"), light = await run("o/light");
|
|
109
|
+
assert.equal(heavy.max, 2, "ceiling 6, heavy cap ceil(6/3)");
|
|
110
|
+
assert.equal(light.max, 6);
|
|
111
|
+
assert.ok(heavy.events.some((e) => e.event === "concurrency" && e.change === "heavy-cap"));
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -204,10 +204,12 @@ describe("conformance gate end-to-end (real git, disposable repo)", { skip: !HAV
|
|
|
204
204
|
res.amendments = [{ kind: "add-requirement", requirement: req("R3"), why: "the issue's requirement 3 was missing" }, { kind: "add-deliverable", id: "D3", path: "src/routes/export.js", why: "implements R3" }]; } });
|
|
205
205
|
merged(o); assert.ok(o.staging.export); assert.ok(o.markers.includes("FORGE:AMENDMENT"));
|
|
206
206
|
});
|
|
207
|
-
it("3 scope creep: an unauthorized billing change is
|
|
207
|
+
it("3 scope creep: an unauthorized billing change is caught by the review's preserve check and reverted before it can reach staging", async () => {
|
|
208
208
|
const o = await runCase({ contract: FULL, impl: (t) => { fix(t, ["scrape", "search", "export"]); t.write({ "src/billing.js": "export function price(units) { return Math.round(units) * 0.01; }\n" }); },
|
|
209
209
|
resume: (t) => t.restore("src/billing.js") });
|
|
210
|
-
|
|
210
|
+
// unclog: file scope alone is advisory (no precheck stop); the violated preserve row (P1) blocks and the resume reverts it
|
|
211
|
+
merged(o); assert.equal(o.staging.billingChanged, false); assert.deepEqual([o.counts.builder, o.counts.reviewer], [3, 2]);
|
|
212
|
+
assert.ok(o.log.some((e) => e.event === "ADVISORY" && e.rows.includes("scope_creep")), "scope creep is recorded as advisory");
|
|
211
213
|
});
|
|
212
214
|
it("4 a claimed follow-up without a tracking issue blocks merge before any review", async () => {
|
|
213
215
|
const o = await runCase({ contract: FULL, impl: (t) => fix(t, ["scrape", "search"]), claims: (k) => claimAll(k).map((r) => (r.id === "R3" ? { id: "R3", status: "deferred", note: "follow-up" } : r)) });
|
package/bin/lean/conformance.mjs
CHANGED
|
@@ -50,6 +50,7 @@ import { globToRegex } from "../../scripts/ci-local/lib.mjs";
|
|
|
50
50
|
import { contractBriefProblems } from "./pagegate.mjs"; // #5428
|
|
51
51
|
import { counterGrowth } from "./hotarea.mjs"; // #5751
|
|
52
52
|
import { designContractFailures } from "./recurrence.mjs"; // #5751
|
|
53
|
+
import { AMEND_KINDS } from "./amendment-schema.mjs"; // #5979
|
|
53
54
|
const C = OUTCOME_CODES;
|
|
54
55
|
|
|
55
56
|
/** #4789: folds what a builder retyping a quote changes: unicode punctuation, markdown links/markup, escapes, invisible chars. */
|
|
@@ -662,7 +663,6 @@ export function validateContract(c, issueText, { repro = false, pages = null, te
|
|
|
662
663
|
/** forge#4519: a shell pattern as in scripts/hotspots.sh `case` (`*` crosses `/`, `?` one character), anchored. */
|
|
663
664
|
const shellGlobRe = (g) => new RegExp(`^${String(g).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".")}$`);
|
|
664
665
|
|
|
665
|
-
const AMEND_KINDS = ["add-deliverable", "add-requirement", ...TRACKED, "amend-requirement", "supersedes", "decision", "substitute-validate", "out-of-band"];
|
|
666
666
|
const UNRELATED_CI_KIND = "unrelated-ci-failure";
|
|
667
667
|
const GUARD_ID_RE = /^#?\d+$/;
|
|
668
668
|
const AMEND_SLIPS = { "amend-requirement": "defer", limitation: "defer", deferred: "defer", deferral: "defer", "scope-deferral": "defer", "verification-substitution": "substitute-validate", "out-of-band-verification": "out-of-band" };
|
|
@@ -709,15 +709,19 @@ function splitRequirementRefs(ref) {
|
|
|
709
709
|
function amendmentProblem(a, tag) {
|
|
710
710
|
const kind = a?.kind;
|
|
711
711
|
const need = kind === "add-deliverable" ? "needs a path" : kind === "add-requirement" ? "needs requirement {id, quote}"
|
|
712
|
-
: kind === "supersedes" ? "needs guard: \"#N\" (the guarded issue) or mechanism: \"<name>\" (#5752: retires the guards whose tests the lane deletes)" : TRACKED.includes(kind) ? "needs requirement: \"R#\"" : kind === "amend-requirement" ? "needs requirement: \"R#\" and text (the revised wording)"
|
|
712
|
+
: kind === "supersedes" ? "needs guard: \"#N\" (the guarded issue) or mechanism: \"<name>\" (#5752: retires the guards whose tests the lane deletes); a validate row id such as G2 is not a guard: use substitute-validate {validate, command, why}" : TRACKED.includes(kind) ? "needs requirement: \"R#\"" : kind === "amend-requirement" ? "needs requirement: \"R#\" and text (the revised wording)"
|
|
713
713
|
: kind === "substitute-validate" ? "needs validate: \"V#\" and command" : kind === "out-of-band" ? "needs requirement: \"R#\" and evidence (the job or workflow that measures it)"
|
|
714
714
|
: kind === "decision" ? "needs decision {choice, anchors: [paths or globs], symbols?, supersedes?: decision id}" : null;
|
|
715
715
|
const why = need ? `amendment kind '${kind}' ${need}` : `unknown kind '${kind ?? ""}'; valid kinds are ${AMEND_KINDS.join(", ")}`;
|
|
716
716
|
return `unknown or incomplete amendment: ${why}: ${tag}`;
|
|
717
717
|
}
|
|
718
718
|
|
|
719
|
+
/** #5979: a supersedes whose guard is a frozen validate-row id (G2, V1), not a #N guard issue. */
|
|
720
|
+
const isValidateRowGuard = (a, ids) => !blank(a.guard) && !GUARD_ID_RE.test(String(a.guard).trim()) && (ids ?? []).includes(String(a.guard).trim());
|
|
721
|
+
const validateRowProblem = (id, tag) => `supersedes guard '${String(id).trim()}' is a validate row of the contract, not a guard issue; use {"kind":"substitute-validate","validate":"${String(id).trim()}","command":"<runnable equivalent>","why":"..."}: ${tag}`;
|
|
722
|
+
|
|
719
723
|
/** #5089: shape-only check of the builder's amendments (unknown kind, missing path or requirement), run before the gate so one in-lane correction can fix them. Returns the rejection strings; [] when valid. */
|
|
720
|
-
export function amendmentKindProblems(amendments) {
|
|
724
|
+
export function amendmentKindProblems(amendments, validateIds = []) {
|
|
721
725
|
const out = [];
|
|
722
726
|
for (const raw of Array.isArray(amendments) ? amendments : []) {
|
|
723
727
|
const a = normalizeAmendment(raw);
|
|
@@ -726,7 +730,9 @@ export function amendmentKindProblems(amendments) {
|
|
|
726
730
|
const known = AMEND_KINDS.includes(a?.kind);
|
|
727
731
|
const missing = a?.kind === "add-deliverable" ? blank(a.path)
|
|
728
732
|
: TRACKED.includes(a?.kind) || a?.kind === "amend-requirement" ? blank(a.requirement) : false;
|
|
733
|
+
const validateRow = known && a.kind === "supersedes" && isValidateRowGuard(a, validateIds);
|
|
729
734
|
if (!known || missing) out.push(amendmentProblem(a, tag));
|
|
735
|
+
else if (validateRow) out.push(validateRowProblem(a.guard, tag));
|
|
730
736
|
}
|
|
731
737
|
return out;
|
|
732
738
|
}
|
|
@@ -822,6 +828,8 @@ export function applyAmendments(frozen, amendments, issueText = null, { generate
|
|
|
822
828
|
c.mechanisms = [...(c.mechanisms ?? []).filter((m) => m.mechanism !== mechanism), { mechanism, why: String(a.why).trim() }];
|
|
823
829
|
applied.push({ kind: a.kind, target: `mechanism ${mechanism}`, why: String(a.why).trim() });
|
|
824
830
|
continue;
|
|
831
|
+
} else if (a.kind === "supersedes" && isValidateRowGuard(a, [...(c.validate ?? []), ...(c.regression ?? [])].map((v) => v?.id))) {
|
|
832
|
+
problems.push(validateRowProblem(a.guard, tag)); continue;
|
|
825
833
|
} else if (a.kind === "supersedes" && GUARD_ID_RE.test(String(a.guard ?? "").trim())) {
|
|
826
834
|
// #4693: retires one guard's guard_broken for this lane; the reviewer judges it, the engine tells the guarded issue after merge
|
|
827
835
|
const guard = `#${String(a.guard).trim().replace(/^#/, "")}`;
|
|
@@ -2027,6 +2035,30 @@ export function normalizeKindModes(raw) {
|
|
|
2027
2035
|
* @param {{code?: string}[]} failures
|
|
2028
2036
|
* @param {{shadow?: boolean, kinds?: Record<string,string>|null, allow?: string[]}} [o]
|
|
2029
2037
|
*/
|
|
2038
|
+
/**
|
|
2039
|
+
* Advisory gates (2026-11-26 unclog): rules about the shape of the work (file scope, registries, docs placement,
|
|
2040
|
+
* recurrence design, amendment syntax, growth counters) are reported, never blocking. Measured on 102 open FD/AlterLab
|
|
2041
|
+
* issues: these rows caused ~30% of needs-human parks, repeated identically across reruns, and forced every lane to edit
|
|
2042
|
+
* the same shared files (45 of 67 conflicted base-syncs). A lane still blocks on what shows the change is wrong: failing
|
|
2043
|
+
* validate/CI/guard/repro runs, regressions and unimplemented requirements.
|
|
2044
|
+
*/
|
|
2045
|
+
export const ADVISORY_CODES = Object.freeze([OUTCOME_CODES.CONFORMANCE_SCOPE_CREEP, OUTCOME_CODES.RECURRENCE_DESIGN_MISSING, OUTCOME_CODES.MAINTENANCE_HOTSPOT_GROWTH, OUTCOME_CODES.MAINTENANCE_COUNTER_GROWTH]);
|
|
2046
|
+
export const ADVISORY_KINDS = Object.freeze([
|
|
2047
|
+
"scope_creep", "check_unknown", "design_missing", "design_missing_repeated", "docs_missing", "docs_link_broken",
|
|
2048
|
+
"ci_budget_unannotated", "hotspot_growth", "counter_growth",
|
|
2049
|
+
"amendment_invalid",
|
|
2050
|
+
"page_metadata_missing", "page_sitemap_missing", "page_canonical_missing", "page_structured_data_missing",
|
|
2051
|
+
]);
|
|
2052
|
+
/**
|
|
2053
|
+
* Split failures into {block, advisory}; advisory rows are reported on the issue and never park a lane. `enforce`: codes
|
|
2054
|
+
* a repo explicitly set to "enforce" (forge.yaml engine.conformance_kinds), which stay blocking.
|
|
2055
|
+
*/
|
|
2056
|
+
export function splitAdvisory(failures, { enforce = [] } = {}) {
|
|
2057
|
+
const block = [], advisory = [];
|
|
2058
|
+
for (const f of failures ?? []) (!enforce.includes(f?.code) && (ADVISORY_KINDS.includes(f?.kind) || ADVISORY_CODES.includes(f?.code)) ? advisory : block).push(f);
|
|
2059
|
+
return { block, advisory };
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2030
2062
|
export function blockingFailures(failures, { shadow = false, kinds = null, allow = [] } = {}) {
|
|
2031
2063
|
const block = [], record = [];
|
|
2032
2064
|
for (const f of failures ?? []) {
|
|
@@ -1719,6 +1719,27 @@ describe("#5087 a plan decision may not weaken an e2e/integration criterion to m
|
|
|
1719
1719
|
});
|
|
1720
1720
|
});
|
|
1721
1721
|
|
|
1722
|
+
describe("supersedes naming a validate row (#5979)", () => {
|
|
1723
|
+
const frozen = { requirements: [], deliverables: [], validate: [{ id: "V1", command: "true" }, { id: "G2", command: "node --test a.test.mjs" }] };
|
|
1724
|
+
it("rejects guard G2 with a substitute-validate hint and records no supersedes", () => {
|
|
1725
|
+
const r = applyAmendments(frozen, [{ kind: "supersedes", guard: "G2", why: "w" }]);
|
|
1726
|
+
assert.equal(r.problems.length, 1);
|
|
1727
|
+
assert.match(r.problems[0], /substitute-validate/);
|
|
1728
|
+
assert.deepEqual(r.contract.supersedes ?? [], []);
|
|
1729
|
+
});
|
|
1730
|
+
it("amendmentKindProblems reports it only when given the validate ids", () => {
|
|
1731
|
+
const a = [{ kind: "supersedes", guard: "G2", why: "w" }];
|
|
1732
|
+
assert.match(amendmentKindProblems(a, ["G2"])[0], /substitute-validate/);
|
|
1733
|
+
assert.deepEqual(amendmentKindProblems(a), []);
|
|
1734
|
+
});
|
|
1735
|
+
it("a #N guard and a mechanism still apply", () => {
|
|
1736
|
+
const r = applyAmendments(frozen, [{ kind: "supersedes", guard: "#123", why: "w" }, { kind: "supersedes", mechanism: "m", why: "w" }]);
|
|
1737
|
+
assert.deepEqual(r.problems, []);
|
|
1738
|
+
assert.equal(r.contract.supersedes[0].guard, "#123");
|
|
1739
|
+
assert.equal(r.contract.mechanisms[0].mechanism, "m");
|
|
1740
|
+
});
|
|
1741
|
+
});
|
|
1742
|
+
|
|
1722
1743
|
describe("amendmentKindProblems (#5089)", () => {
|
|
1723
1744
|
it("flags the invented deliverable_change kind and names the valid kinds", () => {
|
|
1724
1745
|
const p = amendmentKindProblems([{ kind: "deliverable_change", requirement: "R1", why: "no Linux build" }]);
|
|
@@ -2432,3 +2453,34 @@ describe("#5754 precheck fails fast on a deliver row the placement cannot produc
|
|
|
2432
2453
|
assert.equal(run("zero 429 lines against the live stack").failures.some((x) => x.kind === "e2e_placement"), false);
|
|
2433
2454
|
});
|
|
2434
2455
|
});
|
|
2456
|
+
|
|
2457
|
+
import { AMENDMENT_EXAMPLES, AMEND_KINDS as SCHEMA_KINDS } from "./amendment-schema.mjs";
|
|
2458
|
+
import { builderImplementPrompt, amendmentCorrectionPrompt } from "./prompts.mjs";
|
|
2459
|
+
|
|
2460
|
+
describe("builder prompt amendments agree with the validator (#5979)", () => {
|
|
2461
|
+
const frozen = {
|
|
2462
|
+
requirements: [{ id: "R1", quote: "q", disposition: "deliver" }],
|
|
2463
|
+
deliverables: [{ id: "D1", path: "a.mjs", change: "c", requirements: ["R1"] }],
|
|
2464
|
+
validate: [{ id: "V1", command: "true" }, { id: "G2", command: "node --test a.test.mjs" }],
|
|
2465
|
+
};
|
|
2466
|
+
it("every documented example passes the shape check and applies without problems", () => {
|
|
2467
|
+
assert.equal(AMENDMENT_EXAMPLES.length, SCHEMA_KINDS.length);
|
|
2468
|
+
for (const ex of AMENDMENT_EXAMPLES) {
|
|
2469
|
+
assert.deepEqual(amendmentKindProblems([ex], ["V1", "G2"]), [], ex.kind);
|
|
2470
|
+
const r = applyAmendments(frozen, [ex]);
|
|
2471
|
+
assert.deepEqual(r.problems, [], `${ex.kind}: ${r.problems}`);
|
|
2472
|
+
}
|
|
2473
|
+
});
|
|
2474
|
+
it("the builder prompt names every kind and the substitute-validate path", () => {
|
|
2475
|
+
const p = builderImplementPrompt();
|
|
2476
|
+
for (const k of SCHEMA_KINDS) assert.ok(p.includes(`"${k.replace("defer|post-deploy", "defer")}`) || p.includes(k), k);
|
|
2477
|
+
assert.match(p, /"kind":"substitute-validate","validate":"G2"/);
|
|
2478
|
+
assert.match(p, /never a supersedes guard/);
|
|
2479
|
+
assert.match(amendmentCorrectionPrompt(["x"]), /substitute-validate/);
|
|
2480
|
+
});
|
|
2481
|
+
it("substitute-validate for G2 validates; supersedes G2 is still rejected", () => {
|
|
2482
|
+
const ok = applyAmendments(frozen, [{ kind: "substitute-validate", validate: "G2", command: "node --test a.test.mjs", why: "w" }]);
|
|
2483
|
+
assert.deepEqual(ok.problems, []);
|
|
2484
|
+
assert.match(applyAmendments(frozen, [{ kind: "supersedes", guard: "G2", why: "w" }]).problems[0], /substitute-validate/);
|
|
2485
|
+
});
|
|
2486
|
+
});
|