forgedock 1.61.2 → 1.62.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 +10 -1
- package/bin/engine/outcome-codes.mjs +4 -0
- package/bin/engine-cli.mjs +159 -17
- package/bin/env/env.mjs +6 -4
- package/bin/forge-home-check.mjs +91 -0
- package/bin/forgedock.mjs +50 -7
- package/bin/gc.mjs +2 -0
- package/bin/hooks/pre-tool-use.mjs +4 -0
- package/bin/journey.mjs +55 -5
- package/bin/lean/admission.mjs +16 -5
- package/bin/lean/batch-health.mjs +55 -16
- package/bin/lean/batch-health.test.mjs +67 -1
- package/bin/lean/batch.mjs +8 -0
- package/bin/lean/batch.test.mjs +5 -0
- package/bin/lean/ceiling.mjs +20 -0
- package/bin/lean/ceiling.test.mjs +33 -2
- package/bin/lean/ci-gate.mjs +240 -0
- package/bin/lean/ci-gate.test.mjs +227 -0
- package/bin/lean/ci-precheck.mjs +178 -0
- package/bin/lean/ci-precheck.test.mjs +149 -0
- package/bin/lean/conformance.mjs +85 -9
- package/bin/lean/conformance.test.mjs +155 -3
- package/bin/lean/context.test.mjs +7 -6
- package/bin/lean/dag.mjs +128 -0
- package/bin/lean/dag.test.mjs +131 -0
- package/bin/lean/decisions.mjs +5 -4
- package/bin/lean/decisions.test.mjs +11 -0
- package/bin/lean/delguard.mjs +84 -0
- package/bin/lean/delguard.test.mjs +104 -0
- package/bin/lean/depcache.mjs +125 -17
- package/bin/lean/depcache.test.mjs +111 -0
- package/bin/lean/design-gate.mjs +5 -5
- package/bin/lean/design-gate.test.mjs +14 -0
- package/bin/lean/effects.mjs +72 -4
- package/bin/lean/execution.mjs +41 -7
- package/bin/lean/execution.test.mjs +99 -3
- package/bin/lean/forgedock-lane-workflow.test.mjs +35 -0
- package/bin/lean/guardgate.mjs +30 -7
- package/bin/lean/guardgate.test.mjs +44 -1
- package/bin/lean/guards.test.mjs +1 -1
- package/bin/lean/heavy.test.mjs +87 -0
- package/bin/lean/hotarea.mjs +73 -0
- package/bin/lean/hotarea.test.mjs +73 -0
- package/bin/lean/issuewatch-reconcile.mjs +20 -1
- package/bin/lean/issuewatch-reconcile.test.mjs +30 -0
- package/bin/lean/lanecheck.mjs +27 -3
- package/bin/lean/lanecheck.test.mjs +47 -5
- package/bin/lean/laneconfine.mjs +83 -0
- package/bin/lean/laneconfine.test.mjs +113 -0
- package/bin/lean/lean.mjs +376 -79
- package/bin/lean/lean.test.mjs +710 -22
- package/bin/lean/live-reconcile.mjs +169 -0
- package/bin/lean/live-reconcile.test.mjs +176 -0
- package/bin/lean/orchestrate-envhold.test.mjs +245 -0
- package/bin/lean/orchestrate-hostfallback.test.mjs +39 -0
- package/bin/lean/orchestrate.mjs +207 -17
- package/bin/lean/outcomeevidence.mjs +104 -0
- package/bin/lean/outcomeevidence.test.mjs +78 -0
- package/bin/lean/page-capture.mjs +68 -0
- package/bin/lean/page-capture.test.mjs +44 -0
- package/bin/lean/pagegate.mjs +46 -7
- package/bin/lean/pagegate.test.mjs +66 -1
- package/bin/lean/postdeploy-check.mjs +18 -4
- package/bin/lean/postdeploy-check.test.mjs +32 -1
- package/bin/lean/prefilter.mjs +36 -4
- package/bin/lean/prefilter.test.mjs +31 -1
- package/bin/lean/preflight.mjs +22 -0
- package/bin/lean/preflight.test.mjs +19 -1
- package/bin/lean/probe.mjs +18 -0
- package/bin/lean/probe.test.mjs +40 -0
- package/bin/lean/prompts.mjs +40 -3
- package/bin/lean/recovery.test.mjs +20 -0
- package/bin/lean/recurrence.mjs +133 -0
- package/bin/lean/recurrence.test.mjs +99 -0
- package/bin/lean/release-config.mjs +2 -1
- package/bin/lean/release-config.test.mjs +18 -0
- package/bin/lean/release-control.mjs +4 -2
- package/bin/lean/release-control.test.mjs +15 -0
- package/bin/lean/release-merge-hold.mjs +65 -0
- package/bin/lean/release-merge-hold.test.mjs +69 -0
- package/bin/lean/release-review.mjs +26 -9
- package/bin/lean/release-review.test.mjs +53 -0
- package/bin/lean/release-status.mjs +3 -1
- package/bin/lean/release-status.test.mjs +11 -0
- package/bin/lean/release.test.mjs +26 -1
- package/bin/lean/render.mjs +8 -7
- package/bin/lean/routing.mjs +49 -0
- package/bin/lean/routing.test.mjs +54 -1
- package/bin/lean/run-issue-placement.test.mjs +30 -1
- package/bin/lean/sandbox-actions.mjs +121 -0
- package/bin/lean/sandbox-actions.test.mjs +94 -0
- package/bin/lean/sandbox-provider.contract.test.mjs +22 -1
- package/bin/lean/sandbox-remote.mjs +3 -1
- package/bin/lean/schedd-health.mjs +14 -2
- package/bin/lean/schedd-health.test.mjs +13 -0
- package/bin/lean/schedd.mjs +43 -17
- package/bin/lean/schedd.test.mjs +61 -1
- package/bin/lean/toolchain.mjs +16 -6
- package/bin/lean/toolplace.mjs +12 -0
- package/bin/lean/weakguard.mjs +105 -0
- package/bin/lean/weakguard.test.mjs +59 -0
- package/bin/lean/winspawn.mjs +61 -0
- package/bin/lean/winspawn.test.mjs +45 -0
- package/bin/lean/worktree.mjs +3 -1
- package/bin/lean/worktree.test.mjs +11 -0
- package/bin/pool/agent.mjs +210 -14
- package/bin/pool/cache-sweep.mjs +74 -0
- package/bin/pool/cli.mjs +11 -3
- package/bin/pool/docker.mjs +33 -2
- package/bin/pool/health.mjs +38 -0
- package/bin/pool/lane-tools.mjs +23 -4
- package/bin/pool/lane-tools.test.mjs +12 -1
- package/bin/pool/router.mjs +21 -3
- package/bin/runner.mjs +37 -0
- package/bin/splash-scene.mjs +356 -0
- package/bin/win-hide-children.mjs +114 -0
- package/commands/orchestrate.md +18 -27
- package/commands/review-pr-agents/infra.md +1 -0
- package/commands/review-pr-staging.md +2 -2
- package/docs/CONFIG.md +60 -3
- package/docs/OUTCOME-CODES.md +3 -0
- package/package.json +1 -1
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +1 -1
- package/plugins/forgedock-splash/README.md +1 -1
- package/plugins/forgedock-splash/hooks/scene.ts +142 -8
- package/pool/README.md +6 -0
- package/pool/image/entrypoint.sh +1 -0
- package/scripts/check-spec-size.sh +3 -1
- package/scripts/gen-splash-scene.mjs +24 -0
- package/scripts/review-staging-pre.sh +8 -3
- package/scripts/review-staging-pre.test.sh +2 -0
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import { describe, it } from "node:test";
|
|
5
5
|
import assert from "node:assert/strict";
|
|
6
|
-
import {
|
|
6
|
+
import { toolMisses } from "./toolplace.mjs";
|
|
7
|
+
import { FORGEDOCK_CHECKS_VAR, FORGEDOCK_ENTRY_VAR, portableForgedockPaths, resolvingIo, testPlanProblems, proofEchoesDeliverable, outputTail, removedNamedPaths, removedPathsOf, shellSyntaxError, unrunnableValidate, noopCommand, substituteVerdict, describesUnrunnableCommand, vitestQuietFlag, normalizeRunnerCommand, cliUsageError, validateContract, applyAmendments, amendmentKindProblems, precheck, hotspotGrowth, reproFailures, reproQualityFailures, isBugIssue, parseReview, checkCompleteness, decide, closePlan, isInvestigation, formatShadowSummary, followupItems, inIssue, snapQuote, snapQuotes, isTestPath, normalizeEvidencePath, mergeReviewRows, reviewSkeleton, missingIds, resolveEvidencePath, movingBaseDiff, scopeText, evidencePathLine, evidencePathOnly, reaskable, matchCriterion, criterionLines, fillEngineRows, explainFailures, resolveForgedockPaths, missingTool, repoTracks, tmpdirInputs, isScopeCheck, isPureScopeCheck, dropScopeValidates, tagOutOfBand, outOfBandRequirements, isOutOfBand, followupMap, renderPendingFollowups, VERIFY_MODES, OUT_OF_BAND_RE, FOLLOWUP_CLASSES, followupClass, inLaneDeferral, pendingTracking, BUCKETS, bucketKind, bucketProblems, bucketTally, isE2eCommand, e2eVerified, impliedDocDeliverables, applyValidateRecipes, deferChecklessPostDeploy, substituteShellProblem, reproEnvMiss, ORCHESTRATOR_BUCKET, ownerRoute, weakenedE2eDecisions, guessedUvEnv, envProvisioningCommand, assertionFailure, projectDirPathMiss, rewriteProjectDirCommand, convertDelivered, mockedDeliverable, proofEchoDetail, contractRuleCounts, onlyTestPlanProblems } from "./conformance.mjs";
|
|
7
8
|
|
|
8
9
|
const ISSUE = "## Requirements\n1. The scrape route must release the spend reservation on 429.\n2. The search route must release the spend reservation on 429.\n\n- [ ] Billing pricing is unchanged.";
|
|
9
10
|
const Q1 = "The scrape route must release the spend reservation on 429.";
|
|
@@ -153,6 +154,12 @@ describe("#4574 amendment slips", () => {
|
|
|
153
154
|
|
|
154
155
|
describe("precheck (deterministic, no reviewer)", () => {
|
|
155
156
|
const res = { requirements: [{ id: "R1", status: "implemented" }, { id: "R2", status: "implemented" }], validation: [{ id: "V1", exit: 0 }] };
|
|
157
|
+
it("#5760 ciBudgetFailures surface as precheck failures", () => {
|
|
158
|
+
const f = { code: "conformance.unimplemented", kind: "ci_budget_unannotated", detail: "x" };
|
|
159
|
+
const r = precheck({ contract: C, result: res, changedFiles: files, ciBudgetFailures: [f] });
|
|
160
|
+
assert.equal(r.ok, false);
|
|
161
|
+
assert.deepEqual(r.failures, [f]);
|
|
162
|
+
});
|
|
156
163
|
it("passes a complete, validated, in-scope change", () => assert.deepEqual(precheck({ contract: C, result: res, changedFiles: files }), { ok: true, failures: [], superseded: [], ciCovered: [], equivalent: [] }));
|
|
157
164
|
it("unauthorized file -> scope_creep; tests and ignored paths are always allowed", () => {
|
|
158
165
|
assert.deepEqual(codes(precheck({ contract: C, result: res, changedFiles: [...files, "src/billing.js", ".forge-lean/x", "tests/test_x.py", "pkg/foo_test.go"], ignore: [".forge-lean/"] })), ["conformance.scope_creep"]);
|
|
@@ -387,7 +394,7 @@ describe("precheck (deterministic, no reviewer)", () => {
|
|
|
387
394
|
});
|
|
388
395
|
it("#5005 a missing forgedock install is env.tool_missing, not conformance; other absolute paths stay code defects", () => {
|
|
389
396
|
const out = "node:internal/modules/cjs/loader\nError: Cannot find module '/opt/node/lib/node_modules/forgedock/bin/lean/checks.mjs'\n code: 'MODULE_NOT_FOUND'";
|
|
390
|
-
assert.deepEqual(missingTool({ rc: 1, output: out }), { tool: "forgedock", kind: "
|
|
397
|
+
assert.deepEqual(missingTool({ rc: 1, output: out }), { tool: "forgedock", kind: "forgedock-path" }); // #5727: a path mismatch, not a tool
|
|
391
398
|
assert.equal(missingTool({ rc: 1, output: "Error: Cannot find module '/repo/forgedock/src/x.mjs'" }), null);
|
|
392
399
|
const contract = { requirements: [], deliverables: [], validate: [{ id: "V2", command: "node /opt/node/lib/node_modules/forgedock/bin/lean/checks.mjs --base origin/staging" }] };
|
|
393
400
|
const result = { validation: [{ id: "V2", command: "", exit: 1 }] };
|
|
@@ -401,6 +408,39 @@ describe("precheck (deterministic, no reviewer)", () => {
|
|
|
401
408
|
assert.equal(resolveForgedockPaths(cmd, { ...o, exists: () => true }), cmd);
|
|
402
409
|
assert.equal(resolveForgedockPaths("node bin/x.mjs", { ...o, exists: () => false }), "node bin/x.mjs");
|
|
403
410
|
});
|
|
411
|
+
it("#5727 missingTool: a forgedock entry path is not a tool miss", () => {
|
|
412
|
+
const out = "Error: Cannot find module '/home/dev/.local/lib/node_modules/forgedock/bin/lean/checks.mjs'\n code: 'MODULE_NOT_FOUND'";
|
|
413
|
+
const miss = missingTool({ rc: 1, output: out });
|
|
414
|
+
assert.equal(miss.kind, "forgedock-path");
|
|
415
|
+
assert.deepEqual(toolMisses([{ ...miss, ids: ["V5"], source: "run" }]), { tools: [], ids: [] });
|
|
416
|
+
assert.deepEqual(missingTool({ rc: 1, output: "Error: Cannot find module 'left-pad'" }), { tool: "left-pad", kind: "node-module" });
|
|
417
|
+
});
|
|
418
|
+
it("#5727 resolveForgedockPaths expands the portable placeholders", () => {
|
|
419
|
+
const o = { checksCli: "/h/forgedock/bin/lean/checks.mjs", forgedockCli: "/h/forgedock/bin/forgedock.mjs", exists: () => true };
|
|
420
|
+
assert.equal(resolveForgedockPaths('node $FORGEDOCK_CHECKS_CLI --base origin/staging && node "${FORGEDOCK_ENTRY_CLI}" check', o), 'node /h/forgedock/bin/lean/checks.mjs --base origin/staging && node "/h/forgedock/bin/forgedock.mjs" check');
|
|
421
|
+
assert.equal(resolveForgedockPaths("echo $FORGEDOCK_CHECKS_CLIX", o), "echo $FORGEDOCK_CHECKS_CLIX");
|
|
422
|
+
assert.equal(resolveForgedockPaths("node /usr/lib/node_modules/forgedock/bin/lean/checks.mjs", o), "node /usr/lib/node_modules/forgedock/bin/lean/checks.mjs");
|
|
423
|
+
assert.equal(resolveForgedockPaths("node $FORGEDOCK_CHECKS_CLI", {}), "node $FORGEDOCK_CHECKS_CLI");
|
|
424
|
+
});
|
|
425
|
+
it("#5727 portableForgedockPaths rewrites entry tokens to placeholders", () => {
|
|
426
|
+
const cmd = "node /home/dev/.local/lib/node_modules/forgedock/bin/lean/checks.mjs --base origin/staging && node /opt/node/lib/node_modules/forgedock/bin/forgedock.mjs check";
|
|
427
|
+
assert.equal(portableForgedockPaths(cmd), "node $FORGEDOCK_CHECKS_CLI --base origin/staging && node $FORGEDOCK_ENTRY_CLI check");
|
|
428
|
+
assert.ok(portableForgedockPaths(cmd).includes(`$${FORGEDOCK_CHECKS_VAR}`) && portableForgedockPaths(cmd).includes(`$${FORGEDOCK_ENTRY_VAR}`));
|
|
429
|
+
assert.equal(portableForgedockPaths("node bin/lean/checks.mjs && node /repo/src/x.mjs"), "node bin/lean/checks.mjs && node /repo/src/x.mjs");
|
|
430
|
+
assert.equal(resolveForgedockPaths(portableForgedockPaths(cmd), { checksCli: "/c.mjs", forgedockCli: "/f.mjs" }), "node /c.mjs --base origin/staging && node /f.mjs check");
|
|
431
|
+
});
|
|
432
|
+
it("#5727 resolvingIo wraps only the command runners", async () => {
|
|
433
|
+
const seen = [], fs = { read: () => "" };
|
|
434
|
+
const io = { fs, runCommand: async (a) => { seen.push(["run", a.command, a.cwd]); return { rc: 0 }; }, probeCommand: async (a) => { seen.push(["probe", a.command]); return { rc: 0 }; },
|
|
435
|
+
preflightRun: async (a) => { seen.push(["pre", a.command]); return { rc: 0 }; }, redGreen: async (a) => { seen.push(["rg", a.command]); return {}; }, git: async (args) => args };
|
|
436
|
+
const w = resolvingIo(io, { checksCli: "/c.mjs", forgedockCli: "/f.mjs", exists: () => false });
|
|
437
|
+
await w.runCommand({ command: "node /x/forgedock/bin/lean/checks.mjs", cwd: "/wt" }); await w.probeCommand({ command: "node $FORGEDOCK_CHECKS_CLI" });
|
|
438
|
+
await w.preflightRun({ command: "node /x/forgedock/bin/forgedock.mjs check" }); await w.redGreen({ command: "node --test a.mjs" });
|
|
439
|
+
assert.deepEqual(seen, [["run", "node /c.mjs", "/wt"], ["probe", "node /c.mjs"], ["pre", "node /f.mjs check"], ["rg", "node --test a.mjs"]]);
|
|
440
|
+
assert.equal(w.fs, fs); assert.deepEqual(await w.git(["status"]), ["status"]);
|
|
441
|
+
io.later = 1; assert.equal(w.later, 1, "a member set on io later is seen");
|
|
442
|
+
assert.equal(resolvingIo(null), null);
|
|
443
|
+
});
|
|
404
444
|
it("a deliver requirement reported deferred without an amendment -> untracked_deferral; partial -> unimplemented", () => {
|
|
405
445
|
const r = { ...res, requirements: [{ id: "R1", status: "deferred" }, { id: "R2", status: "partial" }] };
|
|
406
446
|
assert.deepEqual(codes(precheck({ contract: C, result: r, changedFiles: files })), ["conformance.untracked_deferral", "conformance.unimplemented"]);
|
|
@@ -1471,7 +1511,7 @@ describe("mutation check (#4913)", () => {
|
|
|
1471
1511
|
const { tmpDir } = await import("../tests/_tmp.mjs");
|
|
1472
1512
|
const d = tmpDir("mut-");
|
|
1473
1513
|
const g = (...a) => execFileSync("git", ["-C", d, "-c", "user.email=t@t", "-c", "user.name=t", ...a], { encoding: "utf8" });
|
|
1474
|
-
g("init", "-q", "-b", "main"); writeFileSync(join(d, "a.js"), "a1\n"); writeFileSync(join(d, "b.js"), "b\n"); g("add", "."); g("commit", "-qm", "base");
|
|
1514
|
+
g("init", "-q", "-b", "main"); g("config", "core.autocrlf", "false"); writeFileSync(join(d, "a.js"), "a1\n"); writeFileSync(join(d, "b.js"), "b\n"); g("add", "."); g("commit", "-qm", "base"); // #5751: autocrlf off, else a host autocrlf restores CRLF
|
|
1475
1515
|
g("checkout", "-qb", "lane"); writeFileSync(join(d, "a.js"), "a2\n"); g("rm", "-q", "b.js"); g("add", "a.js"); g("commit", "-qm", "change");
|
|
1476
1516
|
const r = await runMutationCheck({ targets: [{ id: "R1", commands: [{ id: "V1", command: "t" }] }], files: ["a.js", "b.js"], base: "main",
|
|
1477
1517
|
git: async (a) => g(...a), runCommand: async () => ({ rc: 1 }), cwd: d, tmp: d });
|
|
@@ -2188,3 +2228,115 @@ describe("#5732 repro commands and failures", () => {
|
|
|
2188
2228
|
assert.deepEqual(missingTool({ rc: 1, output: "Could not find the python executable python3.11" }), { tool: "Python interpreter", kind: "environment" });
|
|
2189
2229
|
});
|
|
2190
2230
|
});
|
|
2231
|
+
|
|
2232
|
+
import { dedupeAddRequirements } from "./conformance.mjs";
|
|
2233
|
+
describe("#5773 operator decisions survive requeue and amendment replay", () => {
|
|
2234
|
+
const Q5 = "Backfill dry-run lists all affected historical charges with counts; the real run creates invoices with no customer emails [type:manual]";
|
|
2235
|
+
const Q = "the real run creates invoices with no customer emails";
|
|
2236
|
+
const Q6 = "Post-deploy: one live quick deposit as the production test identity yields a downloadable invoice in the dashboard";
|
|
2237
|
+
const ISS = `## Acceptance\n- ${Q5}\n- ${Q6}`;
|
|
2238
|
+
const frozen = { requirements: [{ id: "R5", quote: Q5, disposition: "deliver" }, { id: "R6", quote: Q6, disposition: "deliver" }], deliverables: [{ id: "D1", path: "scripts/backfill.py", requirements: ["R5", "R6"] }], preserve: [], validate: [] };
|
|
2239
|
+
const dec = (j) => ({ body: `<!-- FORGE:DECISION ${JSON.stringify(j)} -->\n**tracked post-deploy**` });
|
|
2240
|
+
const BOT = "<!-- FORGE:CONTRACT -->\n{}";
|
|
2241
|
+
it("#5773 a structured decision comment does not change the issue scope (the frozen contract is not stale)", () => {
|
|
2242
|
+
const iss = { title: "t", body: ISS };
|
|
2243
|
+
assert.equal(scopeText(iss, [{ body: BOT }, dec({ requirement: "R5", disposition: "post-deploy" })]), scopeText(iss, [{ body: BOT }]));
|
|
2244
|
+
});
|
|
2245
|
+
it("#5773 a decision matches by quote over a stale id, and the decided row is checkless", () => {
|
|
2246
|
+
const c = { ...frozen, requirements: [...frozen.requirements, { id: "R11", quote: "other row", disposition: "deliver" }, { id: "R12", quote: Q, disposition: "post-deploy", check: "made-up-check" }] };
|
|
2247
|
+
const out = applyRequirementDecisions(c, [{ body: BOT }, dec({ requirement: "R11", disposition: "post-deploy", quote: Q })]);
|
|
2248
|
+
assert.deepEqual(out.applied, [], "a post-deploy row is not a deliver/defer row");
|
|
2249
|
+
const c2 = { ...c, requirements: c.requirements.map((r) => (r.id === "R12" ? { ...r, disposition: "deliver" } : r)) };
|
|
2250
|
+
const out2 = applyRequirementDecisions(c2, [{ body: BOT }, dec({ requirement: "R11", disposition: "post-deploy", quote: Q })]);
|
|
2251
|
+
assert.deepEqual(out2.applied, ["R12"], "the quote wins over the renumbered id");
|
|
2252
|
+
const r12 = out2.contract.requirements.find((r) => r.id === "R12");
|
|
2253
|
+
assert.equal(r12.check, undefined); assert.equal(r12.engine_check, undefined);
|
|
2254
|
+
assert.deepEqual(applyRequirementDecisions(out2.contract, [{ body: BOT }, dec({ requirement: "R11", disposition: "post-deploy", quote: Q })]).applied, [], "idempotent");
|
|
2255
|
+
assert.deepEqual(applyRequirementDecisions(c2, [{ body: BOT }, dec({ requirement: "R11", disposition: "post-deploy", quote: "no such row" })]).applied, ["R11"], "id fallback");
|
|
2256
|
+
});
|
|
2257
|
+
it("#5786 a quote over 400 chars still matches its row by quote, not the renumbered id", () => {
|
|
2258
|
+
const longQ = `${"the real run creates invoices with no customer emails and ".repeat(10)}done`;
|
|
2259
|
+
const c = { requirements: [{ id: "R11", quote: "other row", disposition: "deliver" }, { id: "R12", quote: longQ, disposition: "deliver" }] };
|
|
2260
|
+
const out = applyRequirementDecisions(c, [{ body: BOT }, dec({ requirement: "R11", disposition: "post-deploy", quote: longQ })]);
|
|
2261
|
+
assert.deepEqual(out.applied, ["R12"]);
|
|
2262
|
+
});
|
|
2263
|
+
it("#5773 dedupeAddRequirements keeps the last add per quote and drops one that repeats a frozen row", () => {
|
|
2264
|
+
const add = (id, quote, why) => ({ kind: "add-requirement", requirement: { id, quote, disposition: "post-deploy" }, why });
|
|
2265
|
+
const am = [{ kind: "amend-requirement", requirement: "R5", text: "dry-run only", why: "w" }, add("R11", Q, "a"), add("R11", Q, "b"), add("R12", Q6, "c")];
|
|
2266
|
+
const d = dedupeAddRequirements(frozen, am);
|
|
2267
|
+
assert.deepEqual(d.amendments.map((a) => a.why ?? a.kind), ["w", "b"]);
|
|
2268
|
+
assert.deepEqual(d.dropped.map((x) => x.id), ["R11", "R12"]);
|
|
2269
|
+
});
|
|
2270
|
+
it("#5773 the #41245 replay: decision -> requeue -> rows keep their ids, stay tracked post-deploy and pass the check-id gate", () => {
|
|
2271
|
+
const add = (id, quote, why) => ({ kind: "add-requirement", requirement: { id, quote, disposition: "post-deploy" }, why });
|
|
2272
|
+
const replay = [{ kind: "amend-requirement", requirement: "R5", text: "Backfill dry-run lists all affected historical charges with counts", why: "real run moves to R11" }, add("R11", Q, "live Stripe run"), add("R11", Q, "no-email guarantee in code"), add("R12", Q6, "binding decision R6")];
|
|
2273
|
+
const comments = [{ body: BOT }, dec({ requirement: "R5", disposition: "post-deploy" }), dec({ requirement: "R6", disposition: "post-deploy" }), dec({ requirement: "R12", disposition: "post-deploy", quote: Q })];
|
|
2274
|
+
for (let run = 0; run < 3; run++) {
|
|
2275
|
+
const a = applyAmendments(frozen, dedupeAddRequirements(frozen, replay).amendments, ISS);
|
|
2276
|
+
assert.deepEqual(a.problems, []);
|
|
2277
|
+
const ad = applyRequirementDecisions(a.contract, comments);
|
|
2278
|
+
const eff = deferChecklessPostDeploy(ad.contract).contract;
|
|
2279
|
+
assert.deepEqual(eff.requirements.map((r) => r.id), ["R5", "R6", "R11"], "no renumbered R12+");
|
|
2280
|
+
for (const r of eff.requirements) { assert.equal(r.disposition, "defer", r.id); assert.equal(r.bucket, ORCHESTRATOR_BUCKET, r.id); assert.equal(r.check, undefined, r.id); }
|
|
2281
|
+
const pc = precheck({ contract: eff, result: { requirements: [], validation: [] }, changedFiles: ["scripts/backfill.py"], checkIds: new Set() });
|
|
2282
|
+
assert.ok(!pc.failures.some((f) => f.kind === "check_unknown"), JSON.stringify(pc.failures));
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
});
|
|
2286
|
+
|
|
2287
|
+
describe("#5752 mechanism supersedes", () => {
|
|
2288
|
+
const K = { requirements: [], deliverables: [{ id: "D1", path: "src/triage.mjs" }], validate: [] };
|
|
2289
|
+
const broken = (guard, test) => ({ code: "conformance.guard_broken", kind: "guard_broken", guard, test, detail: `guard ${guard} broken` });
|
|
2290
|
+
it("validates {mechanism, why} and stores it as contract.mechanisms; per-guard supersedes keeps working", () => {
|
|
2291
|
+
const a = applyAmendments(K, [{ kind: "supersedes", mechanism: "keyword triage", why: "replaced by the scorer" }, { kind: "supersedes", guard: "#12", why: "own" }]);
|
|
2292
|
+
assert.deepEqual(a.problems, []);
|
|
2293
|
+
assert.deepEqual(a.contract.mechanisms, [{ mechanism: "keyword triage", why: "replaced by the scorer" }]);
|
|
2294
|
+
assert.deepEqual(a.contract.supersedes, [{ guard: "#12", why: "own" }]);
|
|
2295
|
+
assert.deepEqual(a.applied.map((x) => x.target), ["mechanism keyword triage", "#12"]);
|
|
2296
|
+
assert.match(applyAmendments(K, [{ kind: "supersedes", mechanism: " ", why: "x" }]).problems[0], /needs guard: "#N".*or mechanism/);
|
|
2297
|
+
assert.match(applyAmendments(K, [{ kind: "supersedes", mechanism: "m" }]).problems[0], /without why/);
|
|
2298
|
+
});
|
|
2299
|
+
it("one amendment retires every guard_broken whose test the lane deleted; a strong guard with a surviving test still fails", () => {
|
|
2300
|
+
const contract = applyAmendments(K, [{ kind: "supersedes", mechanism: "keyword triage", why: "removed" }]).contract;
|
|
2301
|
+
const guardFailures = [broken("#7", "src/kw.test.mjs"), broken("#8", "src/kw2.test.mjs"), broken("#9", "src/score.test.mjs")];
|
|
2302
|
+
const pc = precheck({ contract, result: {}, changedFiles: ["src/triage.mjs"], guardFailures, removedPaths: ["src/kw.test.mjs", "src/kw2.test.mjs"] });
|
|
2303
|
+
assert.deepEqual(pc.failures.filter((f) => f.kind === "guard_broken").map((f) => f.guard), ["#9"]);
|
|
2304
|
+
const none = precheck({ contract: K, result: {}, changedFiles: ["src/triage.mjs"], guardFailures, removedPaths: ["src/kw.test.mjs", "src/kw2.test.mjs"] });
|
|
2305
|
+
assert.deepEqual(none.failures.filter((f) => f.kind === "guard_broken").map((f) => f.guard), ["#7", "#8", "#9"], "deleting a guard's test without a mechanism amendment retires nothing");
|
|
2306
|
+
const unread = precheck({ contract, result: {}, changedFiles: ["src/triage.mjs"], guardFailures, removedPaths: null });
|
|
2307
|
+
assert.equal(unread.failures.filter((f) => f.kind === "guard_broken").length, 3, "unreadable removed paths fail closed");
|
|
2308
|
+
});
|
|
2309
|
+
it("precheck pushes outcome-evidence failures", () => {
|
|
2310
|
+
const pc = precheck({ contract: K, result: {}, changedFiles: ["src/triage.mjs"], outcomeEvidenceFailures: [{ code: "conformance.unimplemented", kind: "outcome_evidence_missing", detail: "x" }] });
|
|
2311
|
+
assert.equal(pc.ok, false);
|
|
2312
|
+
assert.deepEqual(pc.failures.map((f) => f.kind), ["outcome_evidence_missing"]);
|
|
2313
|
+
});
|
|
2314
|
+
});
|
|
2315
|
+
|
|
2316
|
+
describe("recurrence counters and design lane precheck (#5751)", () => {
|
|
2317
|
+
const result = { validation: [{ id: "V1", exit: 0 }], requirements: [{ id: "R1", status: "implemented" }, { id: "R2", status: "implemented" }] };
|
|
2318
|
+
const run = (extra, contract = C) => precheck({ contract, result, changedFiles: files, ...extra });
|
|
2319
|
+
const rec = { recurs: true, count: 2, threshold: 2, evidence: [], reason: "r" };
|
|
2320
|
+
const design = { why_failed: "#1 and #2 patched the symptom", disposition: "replace", outcome: { metric: "retries per day", target: "0" } };
|
|
2321
|
+
|
|
2322
|
+
it("a counter that grew without a counter-ok decision fails with maintenance.counter_growth", () => {
|
|
2323
|
+
const pc = run({ counters: { before: { exports: 3 }, after: { exports: 4 } } });
|
|
2324
|
+
assert.deepEqual(pc.failures.map((f) => [f.code, f.kind]), [["maintenance.counter_growth", "counter_growth"]]);
|
|
2325
|
+
assert.match(pc.failures[0].detail, /counter exports grew from 3 to 4/);
|
|
2326
|
+
});
|
|
2327
|
+
it("a counter-ok decision, an unchanged or shrinking counter, and no counters all pass", () => {
|
|
2328
|
+
const ok = { ...C, decisions: [{ id: "K1", choice: "counter-ok: exports the new parser needs one entry point", justification: "" }] };
|
|
2329
|
+
assert.equal(run({ counters: { before: { exports: 3 }, after: { exports: 4 } } }, ok).ok, true);
|
|
2330
|
+
assert.equal(run({ counters: { before: { exports: 3 }, after: { exports: 3 } } }).ok, true);
|
|
2331
|
+
assert.equal(run({ counters: { before: { exports: 3 }, after: { exports: 1 } } }).ok, true);
|
|
2332
|
+
assert.equal(run({}).ok, true);
|
|
2333
|
+
});
|
|
2334
|
+
it("a recurring issue's contract without a complete design block fails with recurrence.design_missing", () => {
|
|
2335
|
+
const pc = run({ recurrence: rec });
|
|
2336
|
+
assert.deepEqual(pc.failures.map((f) => [f.code, f.kind]), [["recurrence.design_missing", "design_missing"]]);
|
|
2337
|
+
const partial = run({ recurrence: rec }, { ...C, design: { ...design, disposition: "patch", outcome: { metric: "x" } } });
|
|
2338
|
+
assert.match(partial.failures[0].detail, /disposition.*; design\.outcome needs a metric and a target/);
|
|
2339
|
+
assert.equal(run({ recurrence: rec }, { ...C, design }).ok, true);
|
|
2340
|
+
assert.equal(run({ recurrence: { ...rec, recurs: false } }).ok, true, "no recurrence: no design check");
|
|
2341
|
+
});
|
|
2342
|
+
});
|
|
@@ -2,6 +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 { join } from "node:path"; // #5751: the cache path uses the host separator
|
|
5
6
|
import { normaliseFacts, renderFactsRecord, FACTS_MARKER } from "./facts.mjs";
|
|
6
7
|
import { closedResult, gatherContextFacts, compileContextPack, contextPackFor, contextArm, contextPackCacheKey, linkStateStamp, LINK_STAMP_MAX, parseContextPackConfig, resolveContextMode, laneType, priorAttempts, issueSymbols, bodyLinks, parentOf, renderContextRecord, DEFAULT_CONTEXT_BYTES, noComments, subjectTerms, subjectHistory, MAX_SUBJECT_ITEMS, MAX_SUBJECT_QUERIES } from "./context.mjs";
|
|
7
8
|
|
|
@@ -123,7 +124,7 @@ describe("context pack (forge#4275)", () => {
|
|
|
123
124
|
assert.equal(contextPackCacheKey(50, "abc", cfg, {}), contextPackCacheKey(50, "abc", cfg), "no repo: today's key");
|
|
124
125
|
await contextPackFor({ cfg, issue: 50, repo: "acme/one", headSha: "abc", cacheDir: "/runs", fs, gather: g });
|
|
125
126
|
await contextPackFor({ cfg, issue: 50, repo: "acme/two", headSha: "def", cacheDir: "/runs", fs, gather: g });
|
|
126
|
-
assert.deepEqual([...store.keys()].map((k) => k.split("-").slice(0, 2).join("-")).sort(), ["/runs
|
|
127
|
+
assert.deepEqual([...store.keys()].map((k) => k.split("-").slice(0, 2).join("-")).sort(), [join("/runs", "context-acme__one__50"), join("/runs", "context-acme__two__50")]);
|
|
127
128
|
const again = await contextPackFor({ cfg, issue: 50, repo: "acme/one", headSha: "abc", cacheDir: "/runs", fs, gather: g });
|
|
128
129
|
assert.equal(again.cached, true);
|
|
129
130
|
});
|
|
@@ -319,14 +320,14 @@ describe("#4298 context-pack cache and shared names", () => {
|
|
|
319
320
|
|
|
320
321
|
it("writes through a temp file and a rename, then prunes the issue's other packs only", async () => {
|
|
321
322
|
const { fs, store, ops } = memFs();
|
|
322
|
-
store.set("/runs
|
|
323
|
-
store.set("/runs
|
|
324
|
-
store.set("/runs
|
|
323
|
+
store.set(join("/runs", "context-50-old-aaaaaaaaaaaa.json"), "{}");
|
|
324
|
+
store.set(join("/runs", "context-500-x-bbbbbbbbbbbb.json"), "{}");
|
|
325
|
+
store.set(join("/runs", "50-run.jsonl"), "");
|
|
325
326
|
await contextPackFor({ cfg, issue: 50, headSha: "abc", cacheDir: "/runs", fs, stamp: { scope: "t", attempts: 0 }, gather: async () => facts() });
|
|
326
|
-
const file =
|
|
327
|
+
const file = join("/runs", contextPackCacheKey(50, "abc", cfg, { scope: "t", attempts: 0 }));
|
|
327
328
|
assert.equal(ops[0][0], "write"); assert.match(ops[0][1], /\.tmp$/);
|
|
328
329
|
assert.deepEqual(ops[1], ["rename", ops[0][1], file]);
|
|
329
|
-
assert.deepEqual([...store.keys()].sort(), ["/runs
|
|
330
|
+
assert.deepEqual([...store.keys()].sort(), [join("/runs", "50-run.jsonl"), join("/runs", "context-500-x-bbbbbbbbbbbb.json"), file].sort());
|
|
330
331
|
});
|
|
331
332
|
|
|
332
333
|
it("a rename or prune failure is not an error, and a seam without rename still writes", async () => {
|
package/bin/lean/dag.mjs
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #5824: the batch dependency DAG, built in code (no LLM): `forgedock orchestrate` prints it as the plan table before the
|
|
5
|
+
* first lane and keeps it in the batch plan, so a resume schedules from the same edges and the report counts false holds.
|
|
6
|
+
*
|
|
7
|
+
* Edge X -> N (N waits until X merges) comes from two sources only:
|
|
8
|
+
* - declared: N's trusted body has a `Depends on #X` / `Blocked by #X` line (bold, list, `:`, comma/and lists, any case),
|
|
9
|
+
* read by the engine's own parser (`parseDependsOn`), so the plan and the admission check agree;
|
|
10
|
+
* - logical: X's frozen contract (its last trusted FORGE:CONTRACT comment) delivers a file that is not on the base yet and
|
|
11
|
+
* N's body names that path (N uses what X creates). No contract, no logical edge.
|
|
12
|
+
* Predicted file overlap (paths named in both bodies, or a shared existing deliverable) is a warning in the plan, never an
|
|
13
|
+
* edge: each lane merges its base and resolves the conflict itself. A cycle that a logical edge closes drops that edge.
|
|
14
|
+
* False hold: a planned edge no longer present when the batch ends (an operator removed the line), counted per batch.
|
|
15
|
+
*/
|
|
16
|
+
import { parseDependsOn, isTrustedActor } from "../engine/phases.mjs";
|
|
17
|
+
import { parseContractComment } from "./render.mjs";
|
|
18
|
+
import { namedPaths } from "./prefilter.mjs";
|
|
19
|
+
import { cyclicNodes } from "./orchestrate.mjs";
|
|
20
|
+
|
|
21
|
+
const CONTRACT_HEAD = "<!-- FORGE:CONTRACT -->";
|
|
22
|
+
const commentTrusted = (c) => isTrustedActor({ association: c?.authorAssociation ?? c?.author_association, type: c?.author?.is_bot ? "Bot" : c?.user?.type, login: c?.author?.login ?? c?.user?.login });
|
|
23
|
+
|
|
24
|
+
/** Deliverable paths of the last trusted, parseable FORGE:CONTRACT comment (`gh --json comments` shape), or []. */
|
|
25
|
+
export function contractDeliverables(comments, { trusted = commentTrusted } = {}) {
|
|
26
|
+
let out = [];
|
|
27
|
+
for (const c of Array.isArray(comments) ? comments : []) {
|
|
28
|
+
const body = String(c?.body ?? "").trimStart();
|
|
29
|
+
if (!body.startsWith(CONTRACT_HEAD) || !trusted(c)) continue;
|
|
30
|
+
const d = parseContractComment(body)?.contract?.deliverables;
|
|
31
|
+
if (Array.isArray(d)) out = [...new Set(d.map((x) => x?.path).filter((p) => typeof p === "string" && p))];
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** One issue's plan inputs from a `gh issue view` object: `{title, body, trusted, files, deliverables}`. */
|
|
37
|
+
export function planView(v, { trusted = false } = {}) {
|
|
38
|
+
const body = String(v?.body ?? "");
|
|
39
|
+
return { title: String(v?.title ?? ""), body, trusted: trusted === true, files: namedPaths(body), deliverables: contractDeliverables(v?.comments) };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Declared dependencies of `n` (only a trusted body declares, the engine admission's rule). */
|
|
43
|
+
export function declaredDeps(n, view) {
|
|
44
|
+
return view?.trusted ? parseDependsOn(view.body, n) : [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The batch DAG. `views`: Map issue -> planView; `exists(path)`: the path is on the lane base (a deliverable already there
|
|
49
|
+
* is shared work, an overlap, not a prerequisite). Returns `{edges:[{from,to,kind,why?}], outside:[{issue,dep}],
|
|
50
|
+
* overlaps:[{a,b,files}], dropped:[edge]}`; `outside` lists declared dependencies not in the batch (the runner pulls open ones in).
|
|
51
|
+
*/
|
|
52
|
+
export function buildDag(issues, views, { exists = () => false } = {}) {
|
|
53
|
+
const set = new Set(issues), edges = [], outside = [], seen = new Set();
|
|
54
|
+
const add = (e) => { const k = `${e.from}>${e.to}`; if (e.from === e.to || seen.has(k)) return; seen.add(k); edges.push(e); };
|
|
55
|
+
for (const n of issues) for (const d of declaredDeps(n, views.get(n))) {
|
|
56
|
+
if (set.has(d)) add({ from: d, to: n, kind: "declared" }); else outside.push({ issue: n, dep: d });
|
|
57
|
+
}
|
|
58
|
+
const isNew = (p) => { try { return !exists(p); } catch { return false; } };
|
|
59
|
+
for (const x of issues) for (const p of (views.get(x)?.deliverables ?? []).filter(isNew)) {
|
|
60
|
+
for (const n of issues) {
|
|
61
|
+
const v = views.get(n);
|
|
62
|
+
if (n === x || !v?.files.includes(p) || v.deliverables.includes(p)) continue;
|
|
63
|
+
add({ from: x, to: n, kind: "logical", why: p });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const dropped = [];
|
|
67
|
+
const depsOf = (n) => edges.filter((e) => e.to === n).map((e) => e.from);
|
|
68
|
+
for (let cyc = cyclicNodes(issues, depsOf); cyc.size; cyc = cyclicNodes(issues, depsOf)) {
|
|
69
|
+
const weak = edges.filter((e) => e.kind === "logical" && cyc.has(e.from) && cyc.has(e.to));
|
|
70
|
+
if (!weak.length) break; // a declared cycle stays: the runner reports it (#5162)
|
|
71
|
+
for (const e of weak) { dropped.push(e); edges.splice(edges.indexOf(e), 1); }
|
|
72
|
+
}
|
|
73
|
+
const overlaps = [];
|
|
74
|
+
for (let i = 0; i < issues.length; i++) for (let j = i + 1; j < issues.length; j++) {
|
|
75
|
+
const a = views.get(issues[i]), b = views.get(issues[j]);
|
|
76
|
+
if (!a || !b) continue;
|
|
77
|
+
const fa = new Set([...a.files, ...a.deliverables]);
|
|
78
|
+
const files = [...new Set([...b.files, ...b.deliverables])].filter((f) => fa.has(f));
|
|
79
|
+
if (files.length && !seen.has(`${issues[i]}>${issues[j]}`) && !seen.has(`${issues[j]}>${issues[i]}`)) overlaps.push({ a: issues[i], b: issues[j], files });
|
|
80
|
+
}
|
|
81
|
+
return { edges, outside, overlaps, dropped };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Logical dependencies of `n` in a (persisted) DAG: the runner adds them to the declared ones. */
|
|
85
|
+
export function logicalDepsOf(dag, n) {
|
|
86
|
+
return (dag?.edges ?? []).filter((e) => e.kind === "logical" && e.to === n).map((e) => e.from);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const cell = (s, max = 48) => { const t = String(s ?? "").replace(/\s+/g, " ").replace(/\|/g, "/").trim(); return t.length > max ? `${t.slice(0, max - 1)}…` : t || "-"; };
|
|
90
|
+
|
|
91
|
+
/** The plan table (issue, title, waits on, likely files, overlap warning) and its summary lines. */
|
|
92
|
+
export function formatPlan(issues, views, dag, { parallel = null, parallelFrom = null } = {}) {
|
|
93
|
+
const lines = [`plan: ${issues.length} issue(s), ${dag.edges.length} edge(s) (declared ${dag.edges.filter((e) => e.kind === "declared").length}, logical ${dag.edges.filter((e) => e.kind === "logical").length})${parallel ? `, K=${parallel}${parallelFrom ? ` (${parallelFrom})` : ""}` : ""}`,
|
|
94
|
+
"| issue | title | waits on | likely files | overlap (warning) |", "| --- | --- | --- | --- | --- |"];
|
|
95
|
+
for (const n of issues) {
|
|
96
|
+
const v = views.get(n);
|
|
97
|
+
const waits = dag.edges.filter((e) => e.to === n).map((e) => `#${e.from}${e.kind === "logical" ? ` (logical: ${e.why})` : ""}`);
|
|
98
|
+
const out = dag.outside.filter((o) => o.issue === n).map((o) => `#${o.dep} (outside)`);
|
|
99
|
+
const ov = dag.overlaps.filter((o) => o.a === n || o.b === n).map((o) => `#${o.a === n ? o.b : o.a}`);
|
|
100
|
+
lines.push(`| #${n} | ${cell(v?.title)} | ${[...waits, ...out].join(", ") || "-"} | ${cell((v?.files ?? []).slice(0, 3).join(", "), 60)} | ${ov.join(", ") || "-"} |`);
|
|
101
|
+
}
|
|
102
|
+
for (const e of dag.dropped) lines.push(`plan: dropped logical edge #${e.from} -> #${e.to} (${e.why}): it closed a cycle`);
|
|
103
|
+
if (dag.overlaps.length) lines.push(`plan: overlaps are warnings only, never edges: ${dag.overlaps.map((o) => `#${o.a}/#${o.b} (${o.files.slice(0, 2).join(", ")})`).join("; ")}`);
|
|
104
|
+
return lines;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* False holds: planned edges an operator removed before the batch ended. `currentDeps(n)` is n's declared dependencies now
|
|
109
|
+
* (null = unreadable: its edges are not judged). Logical edges are code-derived and not judged. Returns the removed edges.
|
|
110
|
+
*/
|
|
111
|
+
export async function falseHolds(dag, currentDeps) {
|
|
112
|
+
const removed = [], byTo = new Map();
|
|
113
|
+
for (const e of (dag?.edges ?? []).filter((x) => x.kind === "declared")) byTo.set(e.to, [...(byTo.get(e.to) ?? []), e]);
|
|
114
|
+
for (const [n, es] of byTo) {
|
|
115
|
+
let now;
|
|
116
|
+
try { now = await currentDeps(n); } catch { now = null; }
|
|
117
|
+
if (!Array.isArray(now)) continue;
|
|
118
|
+
for (const e of es) if (!now.includes(e.from)) removed.push(e);
|
|
119
|
+
}
|
|
120
|
+
return removed;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** `false holds: R/P planned edges removed by an operator (...)`, or null without planned edges. */
|
|
124
|
+
export function formatFalseHolds(dag, removed) {
|
|
125
|
+
const planned = (dag?.edges ?? []).length;
|
|
126
|
+
if (!planned) return null;
|
|
127
|
+
return `false holds: ${removed.length}/${planned} planned edge(s) removed by an operator${removed.length ? ` (${removed.map((e) => `#${e.to} on #${e.from}`).join(", ")})` : ""}`;
|
|
128
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// #5824: the batch dependency DAG in code: declared and logical edges, overlap warnings, plan table, false holds.
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { buildDag, contractDeliverables, declaredDeps, falseHolds, formatFalseHolds, formatPlan, logicalDepsOf, planView } from "./dag.mjs";
|
|
7
|
+
import { renderContract } from "./render.mjs";
|
|
8
|
+
import { orchestrate } from "./orchestrate.mjs";
|
|
9
|
+
|
|
10
|
+
const OWNER = { authorAssociation: "OWNER", author: { login: "maintainer" } };
|
|
11
|
+
const contractComment = (paths, who = OWNER) => ({ ...who, body: `<!-- FORGE:CONTRACT -->\n${renderContract({ requirements: [], deliverables: paths.map((path, i) => ({ id: `D${i + 1}`, path, change: "x", requirements: [] })), preserve: [], validate: [] }, "0123456789ab")}` });
|
|
12
|
+
const view = (body, { title = "t", comments = [], trusted = true } = {}) => planView({ title, body, comments }, { trusted });
|
|
13
|
+
const viewsOf = (o) => new Map(Object.entries(o).map(([k, v]) => [Number(k), v]));
|
|
14
|
+
|
|
15
|
+
describe("#5824 declared edges", () => {
|
|
16
|
+
it("reads every form the command spec lists: bold, list, colon, comma/and lists, any case, Blocked by", () => {
|
|
17
|
+
const forms = ["Depends on #1", "**Depends on** #1", "- Depends on: #1, #2", "* depends ON #1 and #2", "**Blocked by:** #2", "blocked by #1, #2 (needs the helper)", "__Depends on__ #1 & #2"];
|
|
18
|
+
for (const f of forms) {
|
|
19
|
+
const want = /#2/.test(f) ? (/#1/.test(f) ? [1, 2] : [2]) : [1];
|
|
20
|
+
assert.deepEqual(declaredDeps(9, view(`Intro\n${f}\nmore`)).sort(), want, f);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("ignores mid-line mentions, self references and an untrusted body", () => {
|
|
25
|
+
assert.deepEqual(declaredDeps(9, view("This depends on #1 somehow.\nDepends on #9")), []);
|
|
26
|
+
assert.deepEqual(declaredDeps(9, view("Depends on #1", { trusted: false })), []);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("in-batch dependencies are edges, out-of-batch ones are listed as outside", () => {
|
|
30
|
+
const dag = buildDag([1, 2], viewsOf({ 1: view(""), 2: view("Depends on #1, #7") }));
|
|
31
|
+
assert.deepEqual(dag.edges, [{ from: 1, to: 2, kind: "declared" }]);
|
|
32
|
+
assert.deepEqual(dag.outside, [{ issue: 2, dep: 7 }]);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("#5824 logical edges and overlap", () => {
|
|
37
|
+
it("a dependency's new contract deliverable named by the dependent is a logical edge", () => {
|
|
38
|
+
const v = viewsOf({ 1: view("adds the helper", { comments: [contractComment(["bin/lean/newhelper.mjs"])] }), 2: view("use `bin/lean/newhelper.mjs` in the runner") });
|
|
39
|
+
const dag = buildDag([1, 2], v, { exists: () => false });
|
|
40
|
+
assert.deepEqual(dag.edges, [{ from: 1, to: 2, kind: "logical", why: "bin/lean/newhelper.mjs" }]);
|
|
41
|
+
assert.deepEqual(logicalDepsOf(dag, 2), [1]);
|
|
42
|
+
assert.deepEqual(dag.overlaps, []);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("no contract, an existing deliverable, or an untrusted contract gives no edge; shared files are a warning only", () => {
|
|
46
|
+
const noContract = buildDag([1, 2], viewsOf({ 1: view("edit `bin/a/x.mjs`"), 2: view("also `bin/a/x.mjs`") }));
|
|
47
|
+
assert.deepEqual(noContract.edges, []);
|
|
48
|
+
assert.deepEqual(noContract.overlaps, [{ a: 1, b: 2, files: ["bin/a/x.mjs"] }]);
|
|
49
|
+
const existing = buildDag([1, 2], viewsOf({ 1: view("", { comments: [contractComment(["bin/a/x.mjs"])] }), 2: view("touch bin/a/x.mjs") }), { exists: () => true });
|
|
50
|
+
assert.deepEqual(existing.edges, []);
|
|
51
|
+
assert.equal(existing.overlaps.length, 1);
|
|
52
|
+
const stranger = { authorAssociation: "NONE", author: { login: "someone" } };
|
|
53
|
+
assert.deepEqual(contractDeliverables([contractComment(["bin/a/y.mjs"], stranger)]), []);
|
|
54
|
+
assert.deepEqual(contractDeliverables([contractComment(["bin/a/y.mjs"]), contractComment(["bin/a/z.mjs"])]), ["bin/a/z.mjs"]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("a cycle closed by logical edges drops them; a declared cycle stays for the runner", () => {
|
|
58
|
+
const v = viewsOf({
|
|
59
|
+
1: view("Depends on #2\nuses `bin/b/one.mjs`", { comments: [contractComment(["bin/b/two.mjs"])] }),
|
|
60
|
+
2: view("uses `bin/b/two.mjs`", { comments: [contractComment(["bin/b/one.mjs"])] }),
|
|
61
|
+
});
|
|
62
|
+
const dag = buildDag([1, 2], v);
|
|
63
|
+
assert.deepEqual(dag.edges, [{ from: 2, to: 1, kind: "declared" }]);
|
|
64
|
+
assert.equal(dag.dropped.length, 1);
|
|
65
|
+
const decl = buildDag([1, 2], viewsOf({ 1: view("Depends on #2"), 2: view("Depends on #1") }));
|
|
66
|
+
assert.equal(decl.edges.length, 2);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("#5824 plan table and false holds", () => {
|
|
71
|
+
it("prints one row per issue with waits-on, files and overlap warnings", () => {
|
|
72
|
+
const v = viewsOf({ 1: view("edit `bin/a/x.mjs`", { title: "first | piped" }), 2: view("Depends on #1\n`bin/a/x.mjs`"), 3: view("also `bin/a/x.mjs`") });
|
|
73
|
+
const dag = buildDag([1, 2, 3], v);
|
|
74
|
+
const lines = formatPlan([1, 2, 3], v, dag, { parallel: 3, parallelFrom: "--parallel" });
|
|
75
|
+
assert.match(lines[0], /^plan: 3 issue\(s\), 1 edge\(s\) \(declared 1, logical 0\), K=3 \(--parallel\)$/);
|
|
76
|
+
assert.match(lines.find((l) => l.startsWith("| #2 ")), /\| #1 \| bin\/a\/x\.mjs \| #3 \|$/);
|
|
77
|
+
assert.match(lines.find((l) => l.startsWith("| #1 ")), /first \/ piped/);
|
|
78
|
+
assert.match(lines.at(-1), /overlaps are warnings only, never edges: #1\/#3 .*#2\/#3/);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("counts planned declared edges an operator removed; unreadable issues are not judged", async () => {
|
|
82
|
+
const dag = { edges: [{ from: 1, to: 2, kind: "declared" }, { from: 3, to: 2, kind: "declared" }, { from: 1, to: 4, kind: "declared" }, { from: 1, to: 5, kind: "logical", why: "p" }] };
|
|
83
|
+
const removed = await falseHolds(dag, async (n) => { if (n === 4) throw new Error("gh down"); return n === 2 ? [3] : []; });
|
|
84
|
+
assert.deepEqual(removed, [{ from: 1, to: 2, kind: "declared" }]);
|
|
85
|
+
assert.equal(formatFalseHolds(dag, removed), "false holds: 1/4 planned edge(s) removed by an operator (#2 on #1)");
|
|
86
|
+
assert.equal(formatFalseHolds({ edges: [] }, []), null);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("#5824 orchestrate honours logical edges", () => {
|
|
91
|
+
it("an issue with a logical dependency starts only after it merges, without a Depends on line", async () => {
|
|
92
|
+
const started = [], done = [];
|
|
93
|
+
const rows = await orchestrate({ issues: [2, 1], parallel: 2, readBody: async () => "", recovery: { maxAttempts: 0 }, logicalDeps: (n) => (n === 2 ? [1] : []),
|
|
94
|
+
runOne: async (n) => { started.push({ n, after: [...done] }); await new Promise((r) => setTimeout(r, 5)); done.push(n); return { terminalReason: "merged", pr: 100 + n }; } });
|
|
95
|
+
assert.deepEqual(rows.map((r) => r.outcome), ["merged", "merged"]);
|
|
96
|
+
assert.deepEqual(started.find((s) => s.n === 2).after, [1]);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("#5824 forgedock orchestrate prints the plan from code and reports false holds", () => {
|
|
101
|
+
it("plan table before the first lane, DAG kept in the plan, one view per issue, a removed edge counted", async () => {
|
|
102
|
+
const { tmpDir } = await import("../tests/_tmp.mjs");
|
|
103
|
+
const { openBatch } = await import("./batch.mjs");
|
|
104
|
+
const { orchestrateFromCli } = await import("../engine-cli.mjs");
|
|
105
|
+
const { writeFileSync, readdirSync } = await import("node:fs");
|
|
106
|
+
const { join } = await import("node:path");
|
|
107
|
+
const bodies = { 1: "adds the thing", 2: "**Depends on:** #1" }, views = { 1: 0, 2: 0 };
|
|
108
|
+
const leanIo = { gh: async (a) => {
|
|
109
|
+
if (a[0] === "api") return "OWNER\n";
|
|
110
|
+
if (a[0] === "issue" && a[1] === "view") { if (a.some((x) => /^title,body,/.test(x))) views[a[2]] = (views[a[2]] ?? 0) + 1; return JSON.stringify({ title: `issue ${a[2]}`, body: bodies[a[2]] ?? "", milestone: null, comments: [], author: { login: "o" } }); }
|
|
111
|
+
return a[0] === "repo" ? "main\n" : "[]";
|
|
112
|
+
}, git: async (a) => (a[0] === "ls-remote" ? "abc\tref\n" : "") };
|
|
113
|
+
const batchRoot = tmpDir("dag-batch-");
|
|
114
|
+
const deps = { dir: tmpDir("dag-run-"), batchRoot, sched: null, allowTmpfs: true, emitTelemetry: async () => {}, leanIo, pollMs: 5, preflight: null,
|
|
115
|
+
io: { gh: async (a) => (a[0] === "issue" ? JSON.stringify({ body: bodies[a[2]] ?? "", state: "OPEN" }) : "o/r\n"), git: async () => "" },
|
|
116
|
+
leanModule: { runCore: async (o) => { if (o.issue === 1) bodies[2] = "operator dropped the line"; return { terminalReason: "merged", pr: o.issue, cost_usd: 0, wall_ms: 1 }; } } };
|
|
117
|
+
const adm = tmpDir("dag-adm-"), prevCwd = process.cwd();
|
|
118
|
+
writeFileSync(join(adm, "forge.yaml"), "engine:\n admission_enabled: false\n");
|
|
119
|
+
process.chdir(adm);
|
|
120
|
+
const lines = [], l = console.log; console.log = (...a) => lines.push(a.join(" "));
|
|
121
|
+
try { await orchestrateFromCli(["1", "2", "--repo", "o/r", "--no-prefilter", "--parallel", "2"], deps); } finally { console.log = l; process.chdir(prevCwd); }
|
|
122
|
+
const out = lines.join("\n");
|
|
123
|
+
assert.match(out, /plan: 2 issue\(s\), 1 edge\(s\) \(declared 1, logical 0\), K=2 \(--parallel\)/);
|
|
124
|
+
assert.match(out, /\| #2 \| issue 2 \| #1 \|/);
|
|
125
|
+
assert.match(out, /false holds: 1\/1 planned edge\(s\) removed by an operator \(#2 on #1\)/);
|
|
126
|
+
assert.equal(views[1], 1, "the plan pass's view is reused by the runner");
|
|
127
|
+
const b = openBatch(batchRoot, readdirSync(batchRoot)[0]);
|
|
128
|
+
assert.deepEqual(b.readPlan().dag.edges, [{ from: 1, to: 2, kind: "declared" }]);
|
|
129
|
+
assert.equal(b.readReport().dag.falseHolds.length, 1);
|
|
130
|
+
});
|
|
131
|
+
});
|
package/bin/lean/decisions.mjs
CHANGED
|
@@ -22,9 +22,9 @@ const TEXT_MAX = 200;
|
|
|
22
22
|
const ANCHORS_MAX = 10;
|
|
23
23
|
const MARKER_RE = /^<!--\s*FORGE:DECISION\s+(\{.*\})\s*-->/;
|
|
24
24
|
|
|
25
|
-
const one = (v, max = TEXT_MAX) => {
|
|
25
|
+
const one = (v, max = TEXT_MAX, ellipsis = true) => {
|
|
26
26
|
const t = typeof v === "string" ? noComments(v, " ").replace(/\s+/g, " ").trim() : "";
|
|
27
|
-
return t.length > max ? `${t.slice(0, max - 1)}…` : t;
|
|
27
|
+
return t.length > max ? (ellipsis ? `${t.slice(0, max - 1)}…` : t.slice(0, max).trimEnd()) : t;
|
|
28
28
|
};
|
|
29
29
|
const strs = (v, max = ANCHORS_MAX, len = 200) => [...new Set((Array.isArray(v) ? v : []).map((x) => one(x, len)).filter(Boolean))].slice(0, max);
|
|
30
30
|
const cleanAnchor = (a) => String(a).replace(/^\.\//, "").replace(/^\/+/, "");
|
|
@@ -81,7 +81,7 @@ export function parseDecisionComment(body, { issue = null } = {}) {
|
|
|
81
81
|
} catch { return null; }
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
/** #5547: `<!-- FORGE:DECISION {"requirement":"R2","disposition":"post-deploy","why":"..."} -->` -> {requirement, disposition, why}; null for anything else (anchored records included). */
|
|
84
|
+
/** #5547: `<!-- FORGE:DECISION {"requirement":"R2","disposition":"post-deploy","why":"...","quote":"..."} -->` -> {requirement, disposition, why, quote?}; null for anything else (anchored records included). */
|
|
85
85
|
export function parseRequirementDecision(body) {
|
|
86
86
|
const m = MARKER_RE.exec(String(body ?? "").split("\n", 1)[0]);
|
|
87
87
|
if (!m) return null;
|
|
@@ -89,7 +89,8 @@ export function parseRequirementDecision(body) {
|
|
|
89
89
|
const raw = JSON.parse(m[1]);
|
|
90
90
|
const id = typeof raw?.requirement === "string" ? raw.requirement.trim() : "";
|
|
91
91
|
if (!/^R\d+$/.test(id) || raw.disposition !== "post-deploy") return null;
|
|
92
|
-
|
|
92
|
+
const quote = one(raw.quote, 400, false); // #5773: the row's quote, so the decision survives a renumbering; #5786: clipped with no ellipsis so it stays a prefix of the row quote
|
|
93
|
+
return { requirement: id, disposition: "post-deploy", why: one(raw.why), ...(quote ? { quote } : {}) };
|
|
93
94
|
} catch { return null; }
|
|
94
95
|
}
|
|
95
96
|
|
|
@@ -97,4 +97,15 @@ describe("#5547 requirement decisions", () => {
|
|
|
97
97
|
assert.equal(parseRequirementDecision('<!-- FORGE:DECISION {"choice":"x","anchors":["a.js"]} -->'), null);
|
|
98
98
|
assert.equal(parseRequirementDecision("FORGE:DECISION prose"), null);
|
|
99
99
|
});
|
|
100
|
+
it("#5786 a quote over 400 chars is clipped without an ellipsis, so it stays a prefix of the row quote", () => {
|
|
101
|
+
const long = `${"word ".repeat(100)}end`;
|
|
102
|
+
const q = parseRequirementDecision(`<!-- FORGE:DECISION ${JSON.stringify({ requirement: "R2", disposition: "post-deploy", quote: long })} -->`).quote;
|
|
103
|
+
assert.ok(q.length >= 399 && q.length <= 400);
|
|
104
|
+
assert.equal(q.includes("…"), false);
|
|
105
|
+
assert.ok(long.startsWith(q));
|
|
106
|
+
});
|
|
107
|
+
it("#5773 an optional quote is returned; without it the decision parses as before", () => {
|
|
108
|
+
assert.deepEqual(parseRequirementDecision('<!-- FORGE:DECISION {"requirement":"R12","disposition":"post-deploy","quote":" the real run creates invoices "} -->'), { requirement: "R12", disposition: "post-deploy", why: "", quote: "the real run creates invoices" });
|
|
109
|
+
assert.equal("quote" in parseRequirementDecision('<!-- FORGE:DECISION {"requirement":"R2","disposition":"post-deploy"} -->'), false);
|
|
110
|
+
});
|
|
100
111
|
});
|