forgedock 1.29.1 → 1.31.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/engine/outcome-codes.mjs +5 -2
- package/bin/engine/phases.mjs +20 -3
- package/bin/engine/runlog.mjs +82 -12
- package/bin/engine/telemetry-seam.mjs +11 -4
- package/bin/engine/telemetry-seam.test.mjs +18 -0
- package/bin/engine-cli.mjs +453 -66
- package/bin/engine.mjs +50 -38
- package/bin/forgedock.mjs +35 -3
- package/bin/gc.mjs +50 -17
- package/bin/labels.json +5 -0
- package/bin/lean/apishape.mjs +170 -0
- package/bin/lean/apishape.test.mjs +187 -0
- package/bin/lean/batch.mjs +32 -0
- package/bin/lean/batch.test.mjs +356 -2
- package/bin/lean/budget.mjs +89 -0
- package/bin/lean/budget.test.mjs +106 -0
- package/bin/lean/checks.mjs +32 -9
- package/bin/lean/checks.test.mjs +78 -1
- package/bin/lean/conformance.e2e.test.mjs +27 -5
- package/bin/lean/conformance.mjs +278 -22
- package/bin/lean/conformance.test.mjs +251 -5
- package/bin/lean/context.mjs +133 -55
- package/bin/lean/context.test.mjs +175 -9
- package/bin/lean/decompose.mjs +90 -0
- package/bin/lean/decompose.test.mjs +105 -0
- package/bin/lean/depcache.mjs +11 -7
- package/bin/lean/depcache.test.mjs +81 -0
- package/bin/lean/e2e.mjs +102 -0
- package/bin/lean/e2e.test.mjs +86 -0
- package/bin/lean/effects.mjs +55 -19
- package/bin/lean/enumerating.mjs +189 -0
- package/bin/lean/enumerating.test.mjs +97 -0
- package/bin/lean/explore.mjs +47 -0
- package/bin/lean/explore.test.mjs +61 -0
- package/bin/lean/facts.mjs +84 -0
- package/bin/lean/facts.test.mjs +66 -0
- package/bin/lean/fixround.mjs +90 -0
- package/bin/lean/fixround.test.mjs +117 -0
- package/bin/lean/heavy.mjs +35 -2
- package/bin/lean/heavy.test.mjs +32 -2
- package/bin/lean/lean.mjs +799 -127
- package/bin/lean/lean.test.mjs +1749 -37
- package/bin/lean/ledger.mjs +5 -3
- package/bin/lean/ledger.test.mjs +18 -0
- package/bin/lean/light.mjs +135 -0
- package/bin/lean/light.test.mjs +173 -0
- package/bin/lean/limits.test.mjs +36 -1
- package/bin/lean/orchestrate.mjs +341 -99
- package/bin/lean/pitfalls.mjs +136 -0
- package/bin/lean/pitfalls.test.mjs +117 -0
- package/bin/lean/postmerge.mjs +85 -0
- package/bin/lean/postmerge.test.mjs +79 -0
- package/bin/lean/precheck.mjs +180 -0
- package/bin/lean/precheck.test.mjs +205 -0
- package/bin/lean/prefilter.mjs +180 -9
- package/bin/lean/prefilter.test.mjs +175 -3
- package/bin/lean/preflight.mjs +238 -0
- package/bin/lean/preflight.test.mjs +108 -0
- package/bin/lean/probe.mjs +297 -0
- package/bin/lean/probe.test.mjs +210 -0
- package/bin/lean/prompts.mjs +134 -12
- package/bin/lean/recovery.test.mjs +75 -0
- package/bin/lean/render.mjs +7 -3
- package/bin/lean/resume.mjs +67 -0
- package/bin/lean/resume.test.mjs +84 -0
- package/bin/lean/review-trigger.mjs +12 -0
- package/bin/lean/review-trigger.test.mjs +17 -1
- package/bin/lean/routing.mjs +74 -0
- package/bin/lean/routing.test.mjs +67 -0
- package/bin/lean/sched.test.mjs +127 -1
- package/bin/lean/schedd.mjs +55 -9
- package/bin/lean/schedd.test.mjs +149 -3
- package/bin/lean/selfreview.mjs +37 -0
- package/bin/lean/selfreview.test.mjs +51 -0
- package/bin/lean/seqlease.mjs +40 -0
- package/bin/lean/seqlease.test.mjs +101 -0
- package/bin/lean/sequence.mjs +385 -0
- package/bin/lean/sequence.test.mjs +373 -0
- package/bin/lean/testmap.mjs +43 -6
- package/bin/lean/testmap.test.mjs +38 -1
- package/bin/lean/toolchain.mjs +60 -15
- package/bin/lean/toolchain.test.mjs +120 -3
- package/bin/lean/toolstats.mjs +72 -0
- package/bin/lean/toolstats.test.mjs +47 -0
- package/bin/lean/verifier.mjs +232 -0
- package/bin/lean/verifier.test.mjs +163 -0
- package/bin/lean/verify.mjs +77 -10
- package/bin/lean/verify.test.mjs +74 -3
- package/bin/review-staging.mjs +533 -0
- package/bin/runner.mjs +82 -13
- package/bin/stats/aggregate.mjs +87 -2
- package/bin/stats/efficiency.mjs +319 -0
- package/bin/stats/efficiency.test.mjs +233 -0
- package/bin/stats/github-source.mjs +8 -3
- package/bin/stats/index.mjs +69 -6
- package/bin/stats/local-source.mjs +86 -3
- package/bin/stats/query.mjs +48 -0
- package/bin/stats/render.mjs +22 -0
- package/bin/stats/stats.test.mjs +224 -5
- package/commands/orchestrate.md +6 -2
- package/commands/review-pr-agents/protocols.md +1 -1
- package/commands/review-pr-staging.md +84 -831
- package/commands/review-pr.md +1 -1
- package/commands/work-on/build/implement.md +1 -0
- package/commands/work-on/build/validate.md +11 -1
- package/docs/CONFIG.md +88 -6
- package/docs/OUTCOME-CODES.md +7 -4
- package/docs/RELEASE-NOTES.md +10 -0
- package/docs/STATS.md +53 -1
- package/docs/TELEMETRY.md +1 -1
- package/docs/spec/review-protocol.md +1 -1
- package/package.json +1 -1
- package/scripts/acceptance-red-green.sh +13 -4
- package/scripts/acceptance-red-green.test.sh +14 -0
- package/scripts/ci-local/lib.mjs +20 -0
- package/scripts/ci-local/plan.mjs +2 -12
- package/scripts/ci-local/scoping.mjs +10 -1
- package/scripts/ci-local.test.sh +2 -0
- package/scripts/fixtures/apishape/other/go-change/base/x.go +3 -0
- package/scripts/fixtures/apishape/other/go-change/head/x.go +3 -0
- package/scripts/fixtures/apishape/python/generator-function/base/seq.py +3 -0
- package/scripts/fixtures/apishape/python/generator-function/head/seq.py +2 -0
- package/scripts/fixtures/apishape/python/ichunked/base/more.py +17 -0
- package/scripts/fixtures/apishape/python/ichunked/head/more.py +20 -0
- package/scripts/fixtures/apishape/python/private-edit/base/calc.py +6 -0
- package/scripts/fixtures/apishape/python/private-edit/head/calc.py +9 -0
- package/scripts/fixtures/apishape/python/removed/base/ops.py +6 -0
- package/scripts/fixtures/apishape/python/removed/head/ops.py +2 -0
- package/scripts/fixtures/apishape/python/renamed/base/text.py +2 -0
- package/scripts/fixtures/apishape/python/renamed/head/text.py +2 -0
- package/scripts/fixtures/apishape/python/signature/base/shapes.py +2 -0
- package/scripts/fixtures/apishape/python/signature/head/shapes.py +2 -0
- package/scripts/fixtures/apishape/python/sync-async/base/client.py +7 -0
- package/scripts/fixtures/apishape/python/sync-async/head/client.py +7 -0
- package/scripts/fixtures/apishape/ts/generator-function/base/seq.js +3 -0
- package/scripts/fixtures/apishape/ts/generator-function/head/seq.js +5 -0
- package/scripts/fixtures/apishape/ts/private-edit/base/calc.ts +7 -0
- package/scripts/fixtures/apishape/ts/private-edit/head/calc.ts +9 -0
- package/scripts/fixtures/apishape/ts/removed/base/ops.ts +7 -0
- package/scripts/fixtures/apishape/ts/removed/head/ops.ts +3 -0
- package/scripts/fixtures/apishape/ts/renamed/base/text.ts +3 -0
- package/scripts/fixtures/apishape/ts/renamed/head/text.ts +3 -0
- package/scripts/fixtures/apishape/ts/signature/base/shapes.ts +3 -0
- package/scripts/fixtures/apishape/ts/signature/head/shapes.ts +3 -0
- package/scripts/fixtures/apishape/ts/sync-async/base/client.mjs +5 -0
- package/scripts/fixtures/apishape/ts/sync-async/head/client.mjs +5 -0
- package/scripts/forge-root.test.sh +2 -2
- package/scripts/publish-staging-sync.test.sh +62 -4
- package/scripts/review-finalize.sh +17 -6
- package/scripts/review-finalize.test.sh +47 -0
- package/scripts/review-pr-arguments.test.sh +13 -1
- package/scripts/review-pr-delta-wiring.test.sh +2 -2
- package/scripts/review-pr-gate2.test.sh +6 -14
- package/scripts/review-pr-staging-finding-filter.test.sh +4 -4
- package/scripts/review-pr-staging-scope.test.sh +39 -33
- package/scripts/review-prepare.sh +73 -6
- package/scripts/review-prepare.test.sh +85 -0
- package/scripts/review-staging-post.sh +293 -0
- package/scripts/review-staging-post.test.sh +143 -0
- package/scripts/review-staging-pre.sh +401 -0
- package/scripts/review-staging-pre.test.sh +150 -0
- package/scripts/symbol-index.mjs +26 -7
- package/scripts/symbol-index.py +55 -9
- package/scripts/test-map.sh +63 -17
- package/scripts/test-map.test.sh +55 -0
- package/scripts/trusted-comments.test.sh +1 -1
package/bin/lean/effects.mjs
CHANGED
|
@@ -15,6 +15,14 @@ import { makeLedger, countLiveLanes, ledgerRoot } from "./ledger.mjs";
|
|
|
15
15
|
import { makeDepCache } from "./depcache.mjs";
|
|
16
16
|
import { makeHeavyIo } from "./heavy.mjs";
|
|
17
17
|
import { gatherContextFacts } from "./context.mjs";
|
|
18
|
+
import { makePitfallStore } from "./pitfalls.mjs";
|
|
19
|
+
import { enumeratingTests, missingEntries } from "./enumerating.mjs";
|
|
20
|
+
import { sequenceCollisions, snapshotLane, verifyRenumber, renumberLane, resolveSequenceConflicts } from "./sequence.mjs";
|
|
21
|
+
import { duplicateExports } from "./postmerge.mjs";
|
|
22
|
+
import { scopedChecks } from "./checks.mjs";
|
|
23
|
+
import { makeSequenceLeaseIo } from "./seqlease.mjs";
|
|
24
|
+
import { followupMap } from "./conformance.mjs";
|
|
25
|
+
import { toolStats } from "./toolstats.mjs";
|
|
18
26
|
|
|
19
27
|
const pexec = promisify(execFile);
|
|
20
28
|
const script = (n) => fileURLToPath(new URL(`../../scripts/${n}`, import.meta.url));
|
|
@@ -53,15 +61,18 @@ export const noToolFlags = (caps) => (caps?.strictMcp ? ["--tools", ""]
|
|
|
53
61
|
: ["--disallowedTools", "Read", "Grep", "Glob", "Bash", "Edit", "Write", "MultiEdit", "NotebookEdit", "WebFetch", "WebSearch", "Task"]);
|
|
54
62
|
|
|
55
63
|
export function makeLeanRunner({ runCli = runCliBackendAsync, probe = systemdRunAvailable } = {}) {
|
|
56
|
-
return async ({ role, issue, cwd, model, resume, system, prompt, readOnly = false, noTools = false, env = null, idleMs = 0, maxMs = 0, laneLimits = null, control = null, onSpawn = null }) => {
|
|
64
|
+
return async ({ role, issue, cwd, model, resume, system, prompt, readOnly = false, noTools = false, maxTurns = null, agents = null, env = null, idleMs = 0, maxMs = 0, laneLimits = null, control = null, onSpawn = null, contextMax = 0, turnMax = 0, busy = null, busyMs = 0, onIdleExtend = null }) => {
|
|
57
65
|
const bin = resolveClaudeCliBinary(cwd) || "claude";
|
|
58
66
|
const caps = getClaudeCliCapabilities(cwd);
|
|
59
|
-
|
|
67
|
+
// #4391: custom subagents (the explorer) for the builder session; null leaves argv unchanged
|
|
68
|
+
const flags = [...buildLeanSessionFlags(caps), ...(noTools ? noToolFlags(caps) : readOnly ? buildReadOnlyToolFlags(caps) : []), ...(agents ? ["--agents", JSON.stringify(agents)] : [])];
|
|
60
69
|
const r = await runCli({ spec: { name: `core-${role}` }, userMessage: prompt, systemPrompt: resume ? "" : system,
|
|
61
|
-
args: [String(issue)], cwd, bin, model, env, sessionFlags: flags, extraArgs: resume ? ["--resume", resume] : [],
|
|
70
|
+
args: [String(issue)], cwd, bin, model, maxTurns: caps?.maxTurns ? maxTurns : null, env, sessionFlags: flags, extraArgs: resume ? ["--resume", resume] : [],
|
|
62
71
|
logger: { log() {} },
|
|
63
|
-
idleMs, maxMs, stream: idleMs > 0, control, onSpawn, wrap: laneLimits && probe() ? (b, a) => wrapLaneLimits(b, a, laneLimits) : null });
|
|
64
|
-
|
|
72
|
+
idleMs, maxMs, stream: idleMs > 0, control, onSpawn, busy, busyMs, onIdleExtend, ...(contextMax > 0 ? { contextMax } : {}), ...(turnMax > 0 ? { turnMax } : {}), wrap: laneLimits && probe() ? (b, a) => wrapLaneLimits(b, a, laneLimits) : null });
|
|
73
|
+
// #4395: a resumed session's first turn carries the prior history, so only a fresh session reports a baseline.
|
|
74
|
+
return { text: r.text, sessionId: r.sessionId, usage: r.usage, costUsd: r.costUsd, durationMs: r.durationMs, turns: r.turns, model: r.cliModel ?? "default",
|
|
75
|
+
baselineTokens: resume ? null : (r.baselineTokens ?? null), tools: toolStats(r.toolUses) }; // #4410: tool calls per turn, re-reads
|
|
65
76
|
};
|
|
66
77
|
}
|
|
67
78
|
|
|
@@ -197,12 +208,12 @@ export async function requiredChecksFor({ gh, repo, lane }) {
|
|
|
197
208
|
|
|
198
209
|
/** Combined stdout+stderr kept per declared check command (tail). */
|
|
199
210
|
const CHECK_OUTPUT_CAP = 64000;
|
|
200
|
-
/** #4240: run a forge.yaml declared check command locally (no gh, no Actions); {rc, output}, rc 124 on timeout. */
|
|
201
|
-
export function runCheckCommand({ command, cwd, timeoutMs = 300000 }) {
|
|
211
|
+
/** #4240: run a forge.yaml declared check command locally (no gh, no Actions); {rc, output}, rc 124 on timeout. `env` (#4323) is merged over process.env. */
|
|
212
|
+
export function runCheckCommand({ command, cwd, timeoutMs = 300000, env = null }) {
|
|
202
213
|
return new Promise((done) => {
|
|
203
214
|
let out = "", timedOut = false, child;
|
|
204
215
|
const add = (b) => { out += String(b); if (out.length > 2 * CHECK_OUTPUT_CAP) out = out.slice(-CHECK_OUTPUT_CAP); };
|
|
205
|
-
try { child = spawn("bash", ["-c", String(command)], { cwd, detached: true, stdio: ["ignore", "pipe", "pipe"] }); }
|
|
216
|
+
try { child = spawn("bash", ["-c", String(command)], { cwd, detached: true, stdio: ["ignore", "pipe", "pipe"], ...(env ? { env: { ...process.env, ...env } } : {}) }); }
|
|
206
217
|
catch (e) { done({ rc: 127, output: String(e?.message ?? e) }); return; }
|
|
207
218
|
const kill = () => { try { process.kill(-child.pid, "SIGKILL"); } catch { try { child.kill("SIGKILL"); } catch { /* gone */ } } };
|
|
208
219
|
const timer = setTimeout(() => { timedOut = true; kill(); }, timeoutMs);
|
|
@@ -236,22 +247,30 @@ export function makeLeanIo({ repo }) {
|
|
|
236
247
|
},
|
|
237
248
|
/** #4240: one declared check command (`bash -c`) in `cwd`; never throws. A timeout kills the process group and gives rc 124. */
|
|
238
249
|
runCommand: runCheckCommand,
|
|
250
|
+
/** #4328: a read-only freeze-time probe of a validate command's tool or module (separate from runCommand). */
|
|
251
|
+
probeCommand: runCheckCommand,
|
|
252
|
+
/** #4393: freeze-time execution of a validate command on the base worktree (not read-only; the engine reverts what it changes). */
|
|
253
|
+
preflightRun: runCheckCommand,
|
|
239
254
|
/** #4167 verify-by-CI: `gh workflow run` on the lane branch; inputs become -f key=value. */
|
|
240
255
|
async dispatchWorkflow({ workflow, ref, inputs = {} }) {
|
|
241
256
|
await run("gh")(["workflow", "run", String(workflow), "-R", repo, "--ref", String(ref), ...Object.entries(inputs).flatMap(([k, v]) => ["-f", `${k}=${v}`])]);
|
|
242
257
|
},
|
|
243
|
-
/** Recent workflow_dispatch runs of `workflow` on `branch`, newest first: [{databaseId, headSha, status, conclusion, url, name}]. */
|
|
258
|
+
/** Recent workflow_dispatch runs of `workflow` on `branch`, newest first: [{databaseId, headSha, status, conclusion, url, name, attempt}]. */
|
|
244
259
|
async workflowRuns({ workflow, branch }) {
|
|
245
260
|
return JSON.parse(await run("gh")(["run", "list", "-R", repo, "--workflow", String(workflow), "--branch", String(branch), "--event", "workflow_dispatch",
|
|
246
|
-
"--limit", "10", "--json", "databaseId,headSha,status,conclusion,url,name"]) || "[]");
|
|
261
|
+
"--limit", "10", "--json", "databaseId,headSha,status,conclusion,url,name,attempt"]) || "[]");
|
|
247
262
|
},
|
|
248
|
-
/**
|
|
263
|
+
/** #4387: rerun the failed jobs of an Actions run once (`gh run rerun <id> --failed`); throws when it cannot start. */
|
|
264
|
+
async rerunFailedJobs(runId) {
|
|
265
|
+
await run("gh")(["run", "rerun", String(runId), "--failed", "-R", repo]);
|
|
266
|
+
},
|
|
267
|
+
/** Check runs on a commit (push-triggered CI): [{name, state: success|failure|pending, url, id, conclusion}], same mapping as checkStates; `id` orders attempts (#4387). */
|
|
249
268
|
async commitChecks(sha) {
|
|
250
|
-
const out = String(await run("gh")(["api", "--paginate", `repos/${repo}/commits/${sha}/check-runs`, "--jq", ".check_runs[] | {name, status, conclusion, url: .html_url} | @json"]));
|
|
269
|
+
const out = String(await run("gh")(["api", "--paginate", `repos/${repo}/commits/${sha}/check-runs`, "--jq", ".check_runs[] | {id, name, status, conclusion, url: .html_url} | @json"]));
|
|
251
270
|
return out.split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l)).map((c) => {
|
|
252
271
|
const v = String(c.status === "completed" ? c.conclusion ?? "" : "").toUpperCase();
|
|
253
272
|
const state = ["SUCCESS", "NEUTRAL", "SKIPPED"].includes(v) ? "success" : ["FAILURE", "ERROR", "TIMED_OUT", "CANCELLED", "ACTION_REQUIRED", "STARTUP_FAILURE", "STALE"].includes(v) ? "failure" : "pending";
|
|
254
|
-
return { name: c.name, state, url: c.url ?? null };
|
|
273
|
+
return { name: c.name, state, url: c.url ?? null, id: c.id ?? null, conclusion: c.status === "completed" ? String(c.conclusion ?? "").toLowerCase() || null : null }; // #4387 id orders attempts; #4403 raw conclusion (skipped = not run)
|
|
255
274
|
});
|
|
256
275
|
},
|
|
257
276
|
/**
|
|
@@ -276,9 +295,7 @@ export function makeLeanIo({ repo }) {
|
|
|
276
295
|
async fileFollowups({ parent, items }) {
|
|
277
296
|
const tsv = items.map((i) => `${i.key}\t${i.why}\t`).join("\n") + "\n";
|
|
278
297
|
const out = await runWithInput("bash", [script("file-deferred-followups.sh"), "--parent", String(parent), "--repo", repo], tsv, 180000);
|
|
279
|
-
|
|
280
|
-
for (const l of out.split("\n")) { const [k, n] = l.split("\t"); if (k && /^\d+$/.test(String(n ?? "").trim())) map[k] = Number(n); }
|
|
281
|
-
return map;
|
|
298
|
+
return followupMap(out, items);
|
|
282
299
|
},
|
|
283
300
|
/**
|
|
284
301
|
* forge#4163: forge.yaml env.setup, once per fresh lane worktree: `bash -c <command>` in cwd with the lane env.
|
|
@@ -299,6 +316,8 @@ export function makeLeanIo({ repo }) {
|
|
|
299
316
|
async structureDelta({ cwd, base }) {
|
|
300
317
|
try { return JSON.parse((await pexec("bash", [script("structure-delta.sh"), `${base}...HEAD`], { cwd, timeout: 30000, maxBuffer: 16 * 1024 * 1024 })).stdout); } catch { return null; }
|
|
301
318
|
},
|
|
319
|
+
/** #4375: the repo's learned-pitfall ledger, local only (~/.forge/pitfalls, FORGE_PITFALLS_DIR). */
|
|
320
|
+
pitfalls: makePitfallStore(),
|
|
302
321
|
/** forge#4275: the context pack's facts for one issue (bin/lean/context.mjs), from gh and git only; sources fail independently. */
|
|
303
322
|
contextFacts: (args) => gatherContextFacts({ ...args, io: { gh: run("gh"), git: run("git"), exists: async (p) => existsSync(p) } }),
|
|
304
323
|
/** forge#4195: scripts/hotspots.sh facts for `paths` in cwd (growth since base when given); null on any failure. */
|
|
@@ -306,11 +325,28 @@ export function makeLeanIo({ repo }) {
|
|
|
306
325
|
const args = [script("hotspots.sh"), ...(base ? ["--base", base] : []), "--", ...paths];
|
|
307
326
|
try { return JSON.parse((await pexec("bash", args, { cwd, timeout: 30000, maxBuffer: 16 * 1024 * 1024 })).stdout); } catch { return null; }
|
|
308
327
|
},
|
|
309
|
-
/** #
|
|
310
|
-
|
|
328
|
+
/** #4322: tests enumerating the members of the given paths, and new members those tests miss (bin/lean/enumerating.mjs); [] on failure. */
|
|
329
|
+
enumeratingTests: ({ cwd, paths = [] }) => enumeratingTests({ git: (a) => run("git")(a, { cwd }), cwd, paths }),
|
|
330
|
+
enumeratingMissing: ({ cwd, base }) => missingEntries({ git: (a) => run("git")(a, { cwd }), cwd, base }),
|
|
331
|
+
/** #4322: sequence-numbered files the lane shares with the base (bin/lean/sequence.mjs); snapshot before, verify after a renumber. */
|
|
332
|
+
sequenceCheck: ({ cwd, base }) => sequenceCollisions({ git: (a) => run("git")(a, { cwd }), base }),
|
|
333
|
+
sequenceSnapshot: ({ cwd, base }) => snapshotLane({ git: (a) => run("git")(a, { cwd }), base }),
|
|
334
|
+
sequenceVerify: ({ cwd, base, before, moves }) => verifyRenumber({ git: (a) => run("git")(a, { cwd }), base, before, moves }),
|
|
335
|
+
/** #4386: the deterministic renumber, sequence-only base-sync resolution, and the host sequence lease at the merge gate. */
|
|
336
|
+
sequenceRenumber: ({ cwd, base, laneRef, regenerate }) => renumberLane({ git: (a) => run("git")(a, { cwd }), base, cwd, laneRef, regenerate }),
|
|
337
|
+
sequenceResolve: ({ cwd, files }) => resolveSequenceConflicts({ git: (a) => run("git")(a, { cwd }), files }),
|
|
338
|
+
sequenceLease: makeSequenceLeaseIo(),
|
|
339
|
+
/** #4406: the lane's scoped checks after a base merge (bin/lean/checks.mjs; [] on failure), and same-app duplicate exports (bin/lean/postmerge.mjs). */
|
|
340
|
+
postMergeChecks: async ({ cwd, base }) => { try { return scopedChecks({ repo: cwd, base }); } catch { return []; } },
|
|
341
|
+
duplicateExports: ({ cwd, base }) => duplicateExports({ git: (a) => run("git")(a, { cwd }), cwd, base }),
|
|
342
|
+
/**
|
|
343
|
+
* #4271: scripts/acceptance-red-green.sh for the frozen repro_test in cwd; {base, head} words, or null on any failure.
|
|
344
|
+
* `env` (#4325): the lane env (run TMPDIR, toolchain), merged over process.env, so the command sees what the builder saw.
|
|
345
|
+
*/
|
|
346
|
+
async redGreen({ cwd, base, command, timeoutSec = 300, env = null }) {
|
|
311
347
|
const args = [script("acceptance-red-green.sh"), "--repo-path", cwd, "--base-ref", base, "--test-cmd", command, "--timeout", String(timeoutSec)];
|
|
312
348
|
try {
|
|
313
|
-
const m = /BASE=(\w+) HEAD=(\w+)/.exec(String((await pexec("bash", args, { cwd, timeout: (timeoutSec * 2 + 60) * 1000, maxBuffer: 4 * 1024 * 1024 })).stdout ?? ""));
|
|
349
|
+
const m = /BASE=(\w+) HEAD=(\w+)/.exec(String((await pexec("bash", args, { cwd, timeout: (timeoutSec * 2 + 60) * 1000, maxBuffer: 4 * 1024 * 1024, ...(env ? { env: { ...process.env, ...env } } : {}) })).stdout ?? ""));
|
|
314
350
|
return m ? { base: m[1], head: m[2] } : null;
|
|
315
351
|
} catch { return null; }
|
|
316
352
|
},
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Enumerating tests (#4322): tests whose expected list names every member of a group (a module's exports, or the files
|
|
5
|
+
* of one directory), so a new member must join the list or CI goes red. Deterministic and codebase-agnostic: git + fs,
|
|
6
|
+
* no LLM, runs none of the repo's commands. A test enumerates a group when it names at least min(3, n) members as string
|
|
7
|
+
* literals or object keys, or calls Object.keys/Object.entries on an import of the module. Never throws: failures are [].
|
|
8
|
+
*/
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import { basename, dirname, join, posix } from "node:path";
|
|
11
|
+
|
|
12
|
+
const SOURCE_RE = /\.(?:[cm]?[jt]sx?|py)$/;
|
|
13
|
+
const TEST_RE = /(?:^|\/)(?:__tests__|tests?)\/|\.(?:test|spec)\.[^/]+$|(?:^|\/)test_[^/]+\.py$|_test\.[^/]+$/;
|
|
14
|
+
const SKIP_RE = /(?:^|\/)(?:node_modules|vendor|dist|build|coverage)\//;
|
|
15
|
+
const MAX_TEST_BYTES = 512 * 1024;
|
|
16
|
+
const MAX_TESTS = 5000;
|
|
17
|
+
const MAX_MODULES = 20, MAX_TESTS_PER_MODULE = 10;
|
|
18
|
+
const MIN_NAME = 3;
|
|
19
|
+
|
|
20
|
+
export const isTestPath = (p) => TEST_RE.test(p);
|
|
21
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
22
|
+
const lines = (s) => String(s ?? "").split("\n").map((x) => x.trim()).filter(Boolean);
|
|
23
|
+
const stem = (p) => basename(p).replace(/\.[^.]+$/, "").replace(/\.d$/, "");
|
|
24
|
+
|
|
25
|
+
/** Exported names of a JS/TS or Python source text. */
|
|
26
|
+
export function exportNames(text, path = "") {
|
|
27
|
+
const t = String(text ?? ""), out = new Set();
|
|
28
|
+
if (/\.py$/.test(path)) {
|
|
29
|
+
const all = /^__all__\s*=\s*[[(]([\s\S]*?)[\])]/m.exec(t);
|
|
30
|
+
if (all) for (const m of all[1].matchAll(/["']([A-Za-z_]\w*)["']/g)) out.add(m[1]);
|
|
31
|
+
else for (const m of t.matchAll(/^(?:async\s+)?(?:def|class)\s+([A-Za-z]\w*)/gm)) out.add(m[1]);
|
|
32
|
+
return [...out];
|
|
33
|
+
}
|
|
34
|
+
for (const m of t.matchAll(/^\s*export\s+(?:default\s+)?(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:function\*?|const|let|var|class|enum)\s+([A-Za-z_$][\w$]*)/gm)) out.add(m[1]);
|
|
35
|
+
for (const m of t.matchAll(/^\s*export\s+(?!type\b)\{([^}]*)\}/gm)) {
|
|
36
|
+
for (const part of m[1].split(",")) {
|
|
37
|
+
const p = part.trim().replace(/^type\s+/, "");
|
|
38
|
+
if (!p || part.trim().startsWith("type ")) continue;
|
|
39
|
+
const name = (/\bas\s+([A-Za-z_$][\w$]*)$/.exec(p)?.[1]) ?? /^[A-Za-z_$][\w$]*/.exec(p)?.[0];
|
|
40
|
+
if (name && name !== "default") out.add(name);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [...out];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Line (1-based) of the first literal/key mention of any of `names` in `text`, and the distinct names mentioned. */
|
|
47
|
+
function mentions(text, names) {
|
|
48
|
+
const hit = new Set();
|
|
49
|
+
let line = 0;
|
|
50
|
+
for (const n of names) {
|
|
51
|
+
if (n.length < MIN_NAME) continue;
|
|
52
|
+
const re = new RegExp(`(["'\`])${esc(n)}\\1|(?:^|[{,\\s])${esc(n)}\\s*:(?!:)`, "m");
|
|
53
|
+
const m = re.exec(text);
|
|
54
|
+
if (!m) continue;
|
|
55
|
+
hit.add(n);
|
|
56
|
+
const l = text.slice(0, m.index).split("\n").length;
|
|
57
|
+
if (!line || l < line) line = l;
|
|
58
|
+
}
|
|
59
|
+
return { hit, line };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Local names bound to an import of `module` in a test at `testPath` (namespace, default or require). */
|
|
63
|
+
function importBindings(text, testPath, module, pkgs) {
|
|
64
|
+
const out = [];
|
|
65
|
+
const target = module.replace(SOURCE_RE, "");
|
|
66
|
+
const targets = new Set([target, ...(stem(module) === "index" ? [dirname(module)] : [])]);
|
|
67
|
+
const pkgNames = pkgs.filter((p) => stem(module) === "index" && [p.dir, posix.join(p.dir, "src")].includes(dirname(module))).map((p) => p.name);
|
|
68
|
+
const matches = (spec) => {
|
|
69
|
+
if (pkgNames.includes(spec)) return true;
|
|
70
|
+
if (!spec.startsWith(".")) return false;
|
|
71
|
+
const r = posix.normalize(posix.join(dirname(testPath), spec)).replace(SOURCE_RE, "");
|
|
72
|
+
return targets.has(r) || targets.has(r.replace(/\/index$/, ""));
|
|
73
|
+
};
|
|
74
|
+
for (const m of text.matchAll(/import\s+(?:\*\s+as\s+([A-Za-z_$][\w$]*)|([A-Za-z_$][\w$]*))\s+from\s+["']([^"']+)["']/g)) if (matches(m[3])) out.push(m[1] ?? m[2]);
|
|
75
|
+
for (const m of text.matchAll(/(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:await\s+import|require)\(\s*["']([^"']+)["']\s*\)/g)) if (matches(m[2])) out.push(m[1]);
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** {path, text} of the repo's tracked test files (read from the working tree; absent/sparse/oversize files skipped). */
|
|
80
|
+
async function loadTests(git, cwd) {
|
|
81
|
+
let files;
|
|
82
|
+
try { files = lines(await git(["-c", "core.quotepath=off", "ls-files"])); } catch { return { tests: [], files: [], pkgs: [] }; }
|
|
83
|
+
const tests = [];
|
|
84
|
+
for (const f of files) {
|
|
85
|
+
if (tests.length >= MAX_TESTS) break;
|
|
86
|
+
if (!isTestPath(f) || SKIP_RE.test(f) || !SOURCE_RE.test(f)) continue;
|
|
87
|
+
try {
|
|
88
|
+
const p = join(cwd, f);
|
|
89
|
+
if (fs.statSync(p).size > MAX_TEST_BYTES) continue;
|
|
90
|
+
tests.push({ path: f, text: fs.readFileSync(p, "utf8") });
|
|
91
|
+
} catch { /* sparse or unreadable: skip */ }
|
|
92
|
+
}
|
|
93
|
+
const pkgs = [];
|
|
94
|
+
for (const f of files.filter((x) => /(?:^|\/)package\.json$/.test(x) && !SKIP_RE.test(x))) {
|
|
95
|
+
try { const n = JSON.parse(fs.readFileSync(join(cwd, f), "utf8")).name; if (typeof n === "string" && n) pkgs.push({ name: n, dir: dirname(f) }); } catch { /* skip */ }
|
|
96
|
+
}
|
|
97
|
+
return { tests, files, pkgs };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Tests enumerating one group: [{test, line, why}]. `exports` groups also match Object.keys/entries of an import of `module`. */
|
|
101
|
+
function enumerators(tests, { module, names, kind }, pkgs) {
|
|
102
|
+
const out = [];
|
|
103
|
+
const usable = names.filter((n) => n.length >= MIN_NAME);
|
|
104
|
+
if (usable.length < 2) return out;
|
|
105
|
+
const need = Math.min(3, usable.length);
|
|
106
|
+
for (const t of tests) {
|
|
107
|
+
if (t.path === module) continue;
|
|
108
|
+
const { hit, line } = mentions(t.text, usable);
|
|
109
|
+
if (hit.size >= need) { out.push({ test: t.path, line, why: `literal list of ${hit.size} sibling ${kind === "files" ? "file names" : "export names"}` }); continue; }
|
|
110
|
+
if (kind !== "exports") continue;
|
|
111
|
+
for (const b of importBindings(t.text, t.path, module, pkgs)) {
|
|
112
|
+
const m = new RegExp(`Object\\.(?:keys|entries)\\(\\s*${esc(b)}\\s*\\)`).exec(t.text);
|
|
113
|
+
if (m) { out.push({ test: t.path, line: t.text.slice(0, m.index).split("\n").length, why: `Object.keys(${b})` }); break; }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return out.slice(0, MAX_TESTS_PER_MODULE);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const fileGroup = (files, dir, exclude = new Set()) => [...new Set(files.filter((f) => dirname(f) === dir && !isTestPath(f) && !exclude.has(f) && stem(f) !== "index").map(stem))];
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Plan time: tests enumerating the exports or directory siblings of each path the issue names.
|
|
123
|
+
* @returns {Promise<Array<{module:string, test:string, line:number, why:string}>>}
|
|
124
|
+
*/
|
|
125
|
+
export async function enumeratingTests({ git, cwd, paths = [] }) {
|
|
126
|
+
try {
|
|
127
|
+
const { tests, files, pkgs } = await loadTests(git, cwd);
|
|
128
|
+
if (!tests.length) return [];
|
|
129
|
+
const tracked = new Set(files), out = [], seen = new Set();
|
|
130
|
+
for (const raw of [...new Set(paths.map((p) => String(p).replace(/^\.\//, "").replace(/\/$/, "")))].slice(0, MAX_MODULES)) {
|
|
131
|
+
const groups = [];
|
|
132
|
+
if (tracked.has(raw) && SOURCE_RE.test(raw) && !isTestPath(raw)) {
|
|
133
|
+
let text = ""; try { text = fs.readFileSync(join(cwd, raw), "utf8"); } catch { /* sparse */ }
|
|
134
|
+
groups.push({ module: raw, names: exportNames(text, raw), kind: "exports" });
|
|
135
|
+
groups.push({ module: dirname(raw), names: fileGroup(files, dirname(raw)), kind: "files" });
|
|
136
|
+
} else if (files.some((f) => dirname(f) === raw)) groups.push({ module: raw, names: fileGroup(files, raw), kind: "files" });
|
|
137
|
+
for (const g of groups) for (const e of enumerators(tests, g, pkgs)) {
|
|
138
|
+
const k = `${g.module}\0${e.test}`;
|
|
139
|
+
if (!seen.has(k)) { seen.add(k); out.push({ module: g.module, ...e }); }
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
} catch { return []; }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* After implement: each new export (vs `base`) of a changed source file and each new file, paired with every test that
|
|
148
|
+
* enumerates its existing siblings but never names it. @returns {Promise<Array<{symbol, module, test, line}>>}
|
|
149
|
+
*/
|
|
150
|
+
export async function missingEntries({ git, cwd, base }) {
|
|
151
|
+
try {
|
|
152
|
+
const changed = lines(await git(["-c", "core.quotepath=off", "diff", "--name-only", "--diff-filter=AM", `${base}...HEAD`]));
|
|
153
|
+
const added = new Set(lines(await git(["-c", "core.quotepath=off", "diff", "--name-only", "--diff-filter=A", `${base}...HEAD`])));
|
|
154
|
+
const groups = [];
|
|
155
|
+
for (const f of changed) {
|
|
156
|
+
if (isTestPath(f) || SKIP_RE.test(f)) continue;
|
|
157
|
+
if (SOURCE_RE.test(f)) {
|
|
158
|
+
let head = "", old = "";
|
|
159
|
+
try { head = fs.readFileSync(join(cwd, f), "utf8"); } catch { continue; }
|
|
160
|
+
if (!added.has(f)) { try { old = String(await git(["show", `${base}:${f}`])); } catch { old = ""; } }
|
|
161
|
+
const now = exportNames(head, f), was = new Set(exportNames(old, f));
|
|
162
|
+
const fresh = now.filter((n) => !was.has(n) && n.length >= MIN_NAME);
|
|
163
|
+
if (fresh.length) groups.push({ module: f, names: now.filter((n) => was.has(n)), fresh, kind: "exports" });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (!groups.length && !added.size) return [];
|
|
167
|
+
const { tests, files, pkgs } = await loadTests(git, cwd);
|
|
168
|
+
if (!tests.length) return [];
|
|
169
|
+
const newFiles = [...added].filter((f) => !isTestPath(f) && !SKIP_RE.test(f));
|
|
170
|
+
for (const dir of [...new Set(newFiles.map(dirname))]) {
|
|
171
|
+
const fresh = newFiles.filter((f) => dirname(f) === dir).map(stem).filter((s) => s.length >= MIN_NAME && s !== "index");
|
|
172
|
+
if (fresh.length) groups.push({ module: dir, names: fileGroup(files, dir, added), fresh, kind: "files" });
|
|
173
|
+
}
|
|
174
|
+
const out = [];
|
|
175
|
+
for (const g of groups.slice(0, MAX_MODULES)) {
|
|
176
|
+
for (const e of enumerators(tests, g, pkgs)) {
|
|
177
|
+
const text = tests.find((t) => t.path === e.test)?.text ?? "";
|
|
178
|
+
for (const s of g.fresh) if (!new RegExp(`(?<![\\w$])${esc(s)}(?![\\w$])`).test(text)) out.push({ symbol: s, module: g.module, test: e.test, line: e.line });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
} catch { return []; }
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Drop entries the builder justified in result.json "not_members" [{symbol, test, why}] (a non-empty why is required). */
|
|
186
|
+
export function unjustified(missing, notMembers) {
|
|
187
|
+
const ok = new Set((Array.isArray(notMembers) ? notMembers : []).filter((n) => n && String(n.why ?? "").trim()).map((n) => `${n.symbol}\0${n.test}`));
|
|
188
|
+
return (missing ?? []).filter((m) => !ok.has(`${m.symbol}\0${m.test}`));
|
|
189
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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 { execFileSync } from "node:child_process";
|
|
6
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
9
|
+
import { exportNames, enumeratingTests, missingEntries, unjustified } from "./enumerating.mjs";
|
|
10
|
+
import { enumeratingPlanNote, enumeratingBuildRule, missingEntriesPrompt, builderPlanPrompt } from "./prompts.mjs";
|
|
11
|
+
|
|
12
|
+
const sh = (cwd, ...a) => execFileSync("git", a, { cwd, encoding: "utf8", env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" } });
|
|
13
|
+
const gitIn = (cwd) => async (a) => sh(cwd, ...a);
|
|
14
|
+
const put = (root, files) => { for (const [p, t] of Object.entries(files)) { mkdirSync(dirname(join(root, p)), { recursive: true }); writeFileSync(join(root, p), t); } };
|
|
15
|
+
function repo(files) {
|
|
16
|
+
const d = tmpDir("enum-");
|
|
17
|
+
sh(d, "init", "-q", "-b", "main");
|
|
18
|
+
put(d, files);
|
|
19
|
+
sh(d, "add", "-A"); sh(d, "commit", "-qm", "base");
|
|
20
|
+
return d;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const CORE = "export async function getUser() {}\nexport const listUsers = () => [];\nexport function deleteUser() {}\nexport { helperA as renamedHelper, type Foo } from './x';\n";
|
|
24
|
+
const FILES = {
|
|
25
|
+
"packages/core/package.json": JSON.stringify({ name: "@acme/core" }),
|
|
26
|
+
"packages/core/src/index.ts": CORE,
|
|
27
|
+
"packages/core/test/registry.test.ts": "import * as core from '../src/index';\nconst SERVICE_TESTS = { getUser: 1, listUsers: 1 };\nconst NOT_A_SERVICE = ['deleteUser', 'renamedHelper'];\nexpect(Object.keys(core).filter((k) => !(k in SERVICE_TESTS) && !NOT_A_SERVICE.includes(k))).toEqual([]);\n",
|
|
28
|
+
"packages/web/test/pkg.test.ts": "import * as c from '@acme/core';\nit('all', () => expect(Object.keys(c).length).toBe(4));\n",
|
|
29
|
+
"packages/core/test/unrelated.test.ts": "import { getUser } from '../src/index';\nit('x', () => getUser());\n",
|
|
30
|
+
"locales/en/common.json": "{}", "locales/en/auth.json": "{}", "locales/en/billing.json": "{}",
|
|
31
|
+
"tests/catalog.test.ts": "const NAMESPACES = ['common', 'auth', 'billing'];\n",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe("enumerating tests (#4322)", () => {
|
|
35
|
+
it("reads JS/TS and Python exports", () => {
|
|
36
|
+
assert.deepEqual(exportNames(CORE, "a.ts").sort(), ["deleteUser", "getUser", "listUsers", "renamedHelper"]);
|
|
37
|
+
assert.deepEqual(exportNames("__all__ = ['a', \"bb\"]\ndef c(): pass", "m.py"), ["a", "bb"]);
|
|
38
|
+
assert.deepEqual(exportNames("def run():\n pass\nclass Job: pass\ndef _private(): pass", "m.py"), ["run", "Job"]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("plan: lists every test enumerating the exports of a module the issue names (literal list, Object.keys of a relative or package import)", async () => {
|
|
42
|
+
const d = repo(FILES);
|
|
43
|
+
const list = await enumeratingTests({ git: gitIn(d), cwd: d, paths: ["packages/core/src/index.ts"] });
|
|
44
|
+
const tests = list.filter((e) => e.module === "packages/core/src/index.ts").map((e) => e.test).sort();
|
|
45
|
+
assert.deepEqual(tests, ["packages/core/test/registry.test.ts", "packages/web/test/pkg.test.ts"]);
|
|
46
|
+
assert.ok(!list.some((e) => e.test.endsWith("unrelated.test.ts")), "a test importing one export does not enumerate them");
|
|
47
|
+
assert.match(list.find((e) => e.test.endsWith("registry.test.ts")).why, /literal list of [34] sibling export names/);
|
|
48
|
+
assert.match(list.find((e) => e.test.endsWith("pkg.test.ts")).why, /^Object\.keys\(c\)$/);
|
|
49
|
+
const files = await enumeratingTests({ git: gitIn(d), cwd: d, paths: ["locales/en"] });
|
|
50
|
+
assert.deepEqual(files.map((e) => [e.module, e.test, e.line]), [["locales/en", "tests/catalog.test.ts", 1]]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("plan note and build rule cite the list; no enumerating tests means no new plan step (prompt unchanged)", async () => {
|
|
54
|
+
const d = repo(FILES);
|
|
55
|
+
assert.deepEqual(await enumeratingTests({ git: gitIn(d), cwd: d, paths: ["README.md", "packages/core/package.json"] }), []);
|
|
56
|
+
assert.equal(enumeratingPlanNote([]), ""); assert.equal(enumeratingPlanNote(null), "");
|
|
57
|
+
assert.equal(enumeratingBuildRule([]), "");
|
|
58
|
+
const list = [{ module: "packages/core/src/index.ts", test: "packages/core/test/registry.test.ts", line: 2, why: "literal list of 4 sibling export names" }];
|
|
59
|
+
assert.match(enumeratingPlanNote(list), /Enumerating tests[\s\S]*Affected Files[\s\S]*validate command[\s\S]*- packages\/core\/src\/index\.ts -> packages\/core\/test\/registry\.test\.ts:2/);
|
|
60
|
+
const rule = enumeratingBuildRule(list);
|
|
61
|
+
assert.match(rule, /one test-list edit per new symbol/);
|
|
62
|
+
assert.match(rule, /"not_members"/);
|
|
63
|
+
assert.match(rule, /registry\.test\.ts:2/);
|
|
64
|
+
assert.ok(!builderPlanPrompt(7).includes("Enumerating tests"));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("after implement: a new export missing from an enumerating test is reported; a listed one or a justified not-member is not", async () => {
|
|
68
|
+
const d = repo(FILES);
|
|
69
|
+
sh(d, "checkout", "-qb", "lane");
|
|
70
|
+
put(d, { "packages/core/src/index.ts": `${CORE}export function getProfile() {}\nexport function updateProfile() {}\n` });
|
|
71
|
+
put(d, { "packages/core/test/registry.test.ts": FILES["packages/core/test/registry.test.ts"].replace("listUsers: 1", "listUsers: 1, updateProfile: 1") });
|
|
72
|
+
put(d, { "locales/en/profile.json": "{}" });
|
|
73
|
+
sh(d, "add", "-A"); sh(d, "commit", "-qm", "lane");
|
|
74
|
+
const miss = await missingEntries({ git: gitIn(d), cwd: d, base: "main" });
|
|
75
|
+
const keys = miss.map((m) => `${m.symbol} -> ${m.test}`).sort();
|
|
76
|
+
assert.deepEqual(keys, [
|
|
77
|
+
"getProfile -> packages/core/test/registry.test.ts",
|
|
78
|
+
"getProfile -> packages/web/test/pkg.test.ts",
|
|
79
|
+
"profile -> tests/catalog.test.ts",
|
|
80
|
+
"updateProfile -> packages/web/test/pkg.test.ts",
|
|
81
|
+
]);
|
|
82
|
+
const left = unjustified(miss, [{ symbol: "getProfile", test: "packages/web/test/pkg.test.ts", why: "count test, not a list" }, { symbol: "profile", test: "tests/catalog.test.ts", why: "" }]);
|
|
83
|
+
assert.equal(left.length, 3, "a not-member needs a non-empty why");
|
|
84
|
+
assert.match(missingEntriesPrompt(miss), /getProfile \(packages\/core\/src\/index\.ts\) -> packages\/core\/test\/registry\.test\.ts:\d+[\s\S]*not_members/);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("a lane that adds no enumerable symbol gets nothing; a broken git never throws", async () => {
|
|
88
|
+
const d = repo(FILES);
|
|
89
|
+
sh(d, "checkout", "-qb", "lane");
|
|
90
|
+
put(d, { "packages/core/src/index.ts": `${CORE}// comment only\n` });
|
|
91
|
+
sh(d, "add", "-A"); sh(d, "commit", "-qm", "lane");
|
|
92
|
+
assert.deepEqual(await missingEntries({ git: gitIn(d), cwd: d, base: "main" }), []);
|
|
93
|
+
const bad = async () => { throw new Error("boom"); };
|
|
94
|
+
assert.deepEqual(await missingEntries({ git: bad, cwd: d, base: "main" }), []);
|
|
95
|
+
assert.deepEqual(await enumeratingTests({ git: bad, cwd: d, paths: ["x"] }), []);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* Explorer subagent (#4391): the builder does its discovery (greps, reads, call chains) through a cheap custom subagent
|
|
5
|
+
* (`claude --agents`) in a throwaway context that returns a bounded file/line digest, so the expensive main session keeps
|
|
6
|
+
* the conclusion instead of re-reading every discovered byte on each later turn. Opt-in via forge.yaml `lean.explore: on`
|
|
7
|
+
* (default off: builder argv and prompts are unchanged); RUN_TERMINAL carries `explore` so the on/off A/B is a query.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const EXPLORER_NAME = "explorer";
|
|
11
|
+
export const DEFAULT_EXPLORE_MODEL = "haiku";
|
|
12
|
+
const MODEL_RE = /^[A-Za-z0-9._:[\]-]+$/;
|
|
13
|
+
|
|
14
|
+
/** {mode, model} from forge.yaml lean.explore / lean.explore_model; anything but "on" is off, an invalid model is the default. */
|
|
15
|
+
export function parseExploreConfig(raw = {}) {
|
|
16
|
+
const mode = String(raw?.mode ?? "").trim().toLowerCase() === "on" ? "on" : "off";
|
|
17
|
+
const m = String(raw?.model ?? "").trim();
|
|
18
|
+
return { mode, model: MODEL_RE.test(m) ? m : DEFAULT_EXPLORE_MODEL };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const EXPLORER_PROMPT = `You explore a code repository for a developer who will edit it. You are read-only: never edit or write files, never commit, push or change GitHub state. Use Bash only for read commands (git log/show/diff/grep, ls, gh ... view).
|
|
22
|
+
|
|
23
|
+
Answer the question you were given with ONE digest of at most 60 lines (about 6 KB). Every claim carries path:line; never paste whole files or long excerpts. Use exactly these sections, writing "none" for an empty one:
|
|
24
|
+
### Files (path:start-end: why it is relevant)
|
|
25
|
+
### Call sites (path:line: caller -> callee)
|
|
26
|
+
### Tests to extend (test path and test name, and the exact command that runs only that test)
|
|
27
|
+
### Conventions to match (naming, error handling, helpers to reuse, each with a path:line example)
|
|
28
|
+
### Open questions (what you could not determine, and where to look)`;
|
|
29
|
+
|
|
30
|
+
/** The `--agents` object for the builder session, or null when off (argv unchanged). */
|
|
31
|
+
export function explorerAgents(cfg) {
|
|
32
|
+
if (cfg?.mode !== "on") return null;
|
|
33
|
+
return { [EXPLORER_NAME]: { description: "Read-only code explorer: answers one focused question about the repository with a bounded file/line digest (files with line ranges, call sites, tests to extend, conventions).",
|
|
34
|
+
prompt: EXPLORER_PROMPT, tools: ["Read", "Grep", "Glob", "Bash"], model: cfg.model } };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const RULE = `do discovery (greps, file reads, following call chains) by calling the Agent tool with subagent_type "${EXPLORER_NAME}" and one focused question per call, and keep its digest as your notes. Open a file yourself only to edit it or to verify a digest claim.`;
|
|
38
|
+
|
|
39
|
+
/** Plan-prompt rule; "" when off (prompt unchanged). */
|
|
40
|
+
export function explorePlanRule(cfg) {
|
|
41
|
+
return cfg?.mode === "on" ? `\n\nExploration: ${RULE} Verify any digest claim the contract relies on before citing it.` : "";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Implement-prompt rule; "" when off (prompt unchanged). */
|
|
45
|
+
export function exploreBuildRule(cfg) {
|
|
46
|
+
return cfg?.mode === "on" ? `\n\nExploration: for anything the plan's digests do not cover, ${RULE}` : "";
|
|
47
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 { writeFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { tmpDir } from "../tests/_tmp.mjs";
|
|
8
|
+
import { parseExploreConfig, explorerAgents, explorePlanRule, exploreBuildRule, EXPLORER_PROMPT, DEFAULT_EXPLORE_MODEL } from "./explore.mjs";
|
|
9
|
+
import { makeLeanRunner } from "./effects.mjs";
|
|
10
|
+
import { readExplore } from "../engine-cli.mjs";
|
|
11
|
+
|
|
12
|
+
describe("explorer subagent config (#4391)", () => {
|
|
13
|
+
it("parses on|off with a default haiku model; anything else is off, an invalid model is the default", () => {
|
|
14
|
+
assert.deepEqual(parseExploreConfig(), { mode: "off", model: DEFAULT_EXPLORE_MODEL });
|
|
15
|
+
assert.deepEqual(parseExploreConfig({ mode: " ON " }), { mode: "on", model: "haiku" });
|
|
16
|
+
assert.deepEqual(parseExploreConfig({ mode: "maybe", model: "sonnet" }), { mode: "off", model: "sonnet" });
|
|
17
|
+
assert.equal(parseExploreConfig({ mode: "on", model: "x; rm -rf /" }).model, "haiku");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("off yields no agents and empty rules; on yields a read-only explorer with the bounded digest format", () => {
|
|
21
|
+
const off = parseExploreConfig({ mode: "off" });
|
|
22
|
+
assert.equal(explorerAgents(off), null);
|
|
23
|
+
assert.equal(explorePlanRule(off), "");
|
|
24
|
+
assert.equal(exploreBuildRule(off), "");
|
|
25
|
+
const on = parseExploreConfig({ mode: "on", model: "sonnet" });
|
|
26
|
+
const a = explorerAgents(on).explorer;
|
|
27
|
+
assert.equal(a.model, "sonnet");
|
|
28
|
+
assert.deepEqual(a.tools, ["Read", "Grep", "Glob", "Bash"]);
|
|
29
|
+
assert.ok(a.description && a.prompt === EXPLORER_PROMPT);
|
|
30
|
+
for (const h of ["### Files", "### Call sites", "### Tests to extend", "### Conventions to match"]) assert.ok(EXPLORER_PROMPT.includes(h), h);
|
|
31
|
+
assert.match(EXPLORER_PROMPT, /read-only[\s\S]*at most 60 lines/);
|
|
32
|
+
for (const r of [explorePlanRule(on), exploreBuildRule(on)]) assert.match(r, /subagent_type "explorer"[\s\S]*Open a file yourself only to edit it or to verify a digest claim\./);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("makeLeanRunner passes --agents <json> only when agents are given (argv unchanged otherwise)", async () => {
|
|
36
|
+
const seen = [];
|
|
37
|
+
const runCli = async (o) => { seen.push(o.sessionFlags); return { text: "", usage: null, costUsd: 0, durationMs: 0, turns: 0, sessionId: "s" }; };
|
|
38
|
+
const base = { role: "builder", issue: 1, cwd: process.cwd(), prompt: "p", system: "" };
|
|
39
|
+
const agents = explorerAgents(parseExploreConfig({ mode: "on" }));
|
|
40
|
+
await makeLeanRunner({ runCli })({ ...base });
|
|
41
|
+
await makeLeanRunner({ runCli })({ ...base, agents });
|
|
42
|
+
const [plain, withAgents] = seen;
|
|
43
|
+
assert.ok(!plain.includes("--agents"));
|
|
44
|
+
const i = withAgents.indexOf("--agents");
|
|
45
|
+
assert.deepEqual(withAgents.slice(0, i), plain);
|
|
46
|
+
assert.deepEqual(JSON.parse(withAgents[i + 1]), agents);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("readExplore reads forge.yaml lean.explore / lean.explore_model; absent or invalid is undefined", () => {
|
|
50
|
+
const d = tmpDir("explore-yaml-");
|
|
51
|
+
assert.equal(readExplore(d), undefined, "no forge.yaml");
|
|
52
|
+
writeFileSync(join(d, "forge.yaml"), "engine:\n explore: on\n");
|
|
53
|
+
assert.equal(readExplore(d), undefined, "another section's key");
|
|
54
|
+
writeFileSync(join(d, "forge.yaml"), "lean:\n explore: maybe\n");
|
|
55
|
+
assert.equal(readExplore(d), undefined);
|
|
56
|
+
writeFileSync(join(d, "forge.yaml"), "lean:\n explore: on # A/B arm\n explore_model: claude-sonnet-5-5\n");
|
|
57
|
+
assert.deepEqual(readExplore(d), { mode: "on", model: "claude-sonnet-5-5" });
|
|
58
|
+
writeFileSync(join(d, "forge.yaml"), "lean:\n explore: off\n");
|
|
59
|
+
assert.deepEqual(readExplore(d), { mode: "off" });
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* #4401: the structured FORGE:FACTS record a lane posts next to its prose. The builder's judgment (decisions, rejected
|
|
5
|
+
* approaches with why, hot spots file:line with why, conventions matched) comes from an optional result.json `facts`
|
|
6
|
+
* key; baselines are the engine's own facts (result.json validation commands and exit codes); decisions fall back to
|
|
7
|
+
* the frozen contract's. `files` (the lane's changed files) is the path index the context pack matches later lanes on.
|
|
8
|
+
* Pure: no I/O. The same caps apply on write and on read, so a hand-edited or forged comment is bounded the same way.
|
|
9
|
+
*/
|
|
10
|
+
import { noComments } from "./render.mjs";
|
|
11
|
+
|
|
12
|
+
export const FACTS_MARKER = "FORGE:FACTS";
|
|
13
|
+
export const FACTS_TEXT_MAX = 160;
|
|
14
|
+
export const FACTS_LIST_MAX = 5;
|
|
15
|
+
export const FACTS_FILES_MAX = 20;
|
|
16
|
+
const KINDS = ["decisions", "rejected", "hotspots", "conventions", "baselines"];
|
|
17
|
+
const FACTS_BLOCK_RE = /```json\n([\s\S]*?)\n```/;
|
|
18
|
+
const AT_RE = /^[\w.@~+/-]+(?::\d+(?:-\d+)?)?$/;
|
|
19
|
+
|
|
20
|
+
const one = (v, max = FACTS_TEXT_MAX) => {
|
|
21
|
+
const t = typeof v === "string" ? noComments(v, " ").replace(/\s+/g, " ").trim() : "";
|
|
22
|
+
return t.length > max ? `${t.slice(0, max - 1)}…` : t;
|
|
23
|
+
};
|
|
24
|
+
const list = (v) => (Array.isArray(v) ? v : []);
|
|
25
|
+
const uniqBy = (rows, key) => { const seen = new Set(); return rows.filter((r) => { const k = key(r); if (seen.has(k)) return false; seen.add(k); return true; }); };
|
|
26
|
+
|
|
27
|
+
/** The bounded, one-lined record from a raw object; every list capped, entries without their reason dropped. */
|
|
28
|
+
function clean(raw) {
|
|
29
|
+
const r = raw && typeof raw === "object" ? raw : {};
|
|
30
|
+
const strs = (a) => uniqBy(list(a).map((x) => one(x)).filter(Boolean), (x) => x).slice(0, FACTS_LIST_MAX);
|
|
31
|
+
const files = uniqBy(list(r.files).map((f) => (typeof f === "string" ? f.trim().replace(/^\.\//, "") : ""))
|
|
32
|
+
.filter((f) => f && AT_RE.test(f) && !f.startsWith(".forge-lean/") && !f.split("/").includes("..")), (x) => x).slice(0, FACTS_FILES_MAX);
|
|
33
|
+
const rejected = uniqBy(list(r.rejected).map((x) => ({ approach: one(x?.approach), why: one(x?.why) })).filter((x) => x.approach && x.why), (x) => x.approach).slice(0, FACTS_LIST_MAX);
|
|
34
|
+
const hotspots = uniqBy(list(r.hotspots).map((x) => ({ at: one(x?.at, 200), why: one(x?.why) })).filter((x) => x.at && x.why && AT_RE.test(x.at) && !x.at.split("/").includes("..")), (x) => x.at).slice(0, FACTS_LIST_MAX);
|
|
35
|
+
const baselines = uniqBy(list(r.baselines).map((x) => ({ command: one(x?.command, 200), exit: x?.exit })).filter((x) => x.command && Number.isInteger(x.exit)), (x) => x.command).slice(0, FACTS_LIST_MAX);
|
|
36
|
+
return { v: 1, files, decisions: strs(r.decisions), rejected, hotspots, conventions: strs(r.conventions), baselines };
|
|
37
|
+
}
|
|
38
|
+
const hasContent = (f) => KINDS.some((k) => f[k].length > 0);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The lane's FORGE:FACTS record, or null when it would carry nothing. `result` is result.json (its `facts` and
|
|
42
|
+
* `validation`), `files` the lane's changed files, `contract` the frozen contract (decision fallback).
|
|
43
|
+
*/
|
|
44
|
+
export function normaliseFacts(result, { files = [], contract = null } = {}) {
|
|
45
|
+
const raw = result?.facts && typeof result.facts === "object" ? result.facts : {};
|
|
46
|
+
const decisions = list(raw.decisions).some((d) => one(d)) ? raw.decisions : list(contract?.decisions).map((d) => d?.choice);
|
|
47
|
+
const baselines = list(result?.validation).map((v) => ({ command: v?.command, exit: v?.exit }));
|
|
48
|
+
const f = clean({ ...raw, decisions, baselines, files });
|
|
49
|
+
return hasContent(f) ? f : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** JSON for a comment: `<` and backticks escaped, so builder text can never open a comment or close the fence. */
|
|
53
|
+
const factsJson = (f) => JSON.stringify(f).replace(/</g, "\\u003c").replace(/`/g, "\\u0060");
|
|
54
|
+
|
|
55
|
+
/** The FORGE:FACTS comment body (without the marker line): a count line plus the record as fenced JSON. */
|
|
56
|
+
export function renderFactsRecord(f) {
|
|
57
|
+
return `## Lane facts\n${f.rejected.length} rejected approach(es), ${f.hotspots.length} hot spot(s), ${f.decisions.length} decision(s), ${f.conventions.length} convention(s), ${f.baselines.length} baseline(s) on ${f.files.length} file(s); read by later lanes on the same files.\n\n\`\`\`json\n${factsJson(f)}\n\`\`\``;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The record from a FORGE:FACTS comment body, re-bounded with the same caps; null for any other or malformed body. */
|
|
61
|
+
export function parseFactsComment(body) {
|
|
62
|
+
const s = String(body ?? "");
|
|
63
|
+
if (!new RegExp(`^\\s*<!--\\s*${FACTS_MARKER}\\s*-->`).test(s)) return null;
|
|
64
|
+
const m = FACTS_BLOCK_RE.exec(s);
|
|
65
|
+
if (!m) return null;
|
|
66
|
+
let raw;
|
|
67
|
+
try { raw = JSON.parse(m[1]); } catch { return null; }
|
|
68
|
+
const f = clean(raw);
|
|
69
|
+
return hasContent(f) ? f : null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The one-line pack items of a record, by kind (`ref` names its provenance, e.g. "#33, PR #101"). */
|
|
73
|
+
export function factsLines(f, ref) {
|
|
74
|
+
const tag = ref ? ` (${ref})` : "";
|
|
75
|
+
return {
|
|
76
|
+
rejected: f.rejected.map((x) => `- rejected: ${x.approach} — ${x.why}${tag}`),
|
|
77
|
+
hotspots: f.hotspots.map((x) => `- hot spot ${x.at}: ${x.why}${tag}`),
|
|
78
|
+
decisions: f.decisions.map((x) => `- decision: ${x}${tag}`),
|
|
79
|
+
conventions: f.conventions.map((x) => `- convention: ${x}${tag}`),
|
|
80
|
+
baselines: f.baselines.map((x) => `- baseline: \`${x.command.replace(/`/g, "'")}\` exit ${x.exit}${tag}`),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Pack rank of the kinds: rejected approaches first (the knowledge most often lost), then hot spots, decisions, conventions, baselines. */
|
|
84
|
+
export const FACTS_RANK = Object.freeze(["rejected", "hotspots", "decisions", "conventions", "baselines"]);
|