Add the PR Prep skill: check plan, readiness verdict and PR description

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-03 21:26:10 -08:00
1 parent 82298d256c
commit 88c72dc2ce
20 files changed
+932 -85

No files matched your search

+2 -1
View File
@@ -64,10 +64,11 @@ export function scrubbedEnv(extra = {}) {
for (const k of AMBIENT_GIT_ENV) delete process.env[k];
Object.assign(process.env, { GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: EMPTY_GITCONFIG });
export function runScript(skill, script, args, { cwd, env } = {}) {
export function runScript(skill, script, args, { cwd, env, input } = {}) {
const r = spawnSync(process.execPath, [path.join(SKILLS, skill, "scripts", script), ...args], {
cwd: cwd || ROOT,
encoding: "utf8",
input,
env: scrubbedEnv({ PLAN2CODE_NOW: NOW, ...env }),
});
let json = null;
+266
View File
@@ -0,0 +1,266 @@
// Tests for plan2code-pr-prep's scripts/pr-prep.mjs: the template lookup, the
// pull-request link and the branch's spec folder. See skill-script-helpers.mjs
// for how these run.
import { test, after } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { execFileSync } from "node:child_process";
import { runScript, tmp, write, gitInit, gitIn, slashed, fixtureCleanup } from "./skill-script-helpers.mjs";
after(fixtureCleanup);
// The console home holds pr-hosts.json; keep the real one out of every run.
const HOME = tmp("pr-prep-console-home");
const P = (cwd, ...a) => runScript("plan2code-pr-prep", "pr-prep.mjs", a, { cwd, env: { PLAN2CODE_CONSOLE_HOME: HOME } });
/* --------------------------------------------------------------- template */
const LOOKUP = [
".github/pull_request_template.md",
".github/PULL_REQUEST_TEMPLATE.md",
"PULL_REQUEST_TEMPLATE.md",
"docs/pull_request_template.md",
".github/PULL_REQUEST_TEMPLATE/feature.md",
"docs/PULL_REQUEST_TEMPLATE/feature.md",
".gitlab/merge_request_templates/Default.md",
];
test("pr-prep template: each place in the lookup order is found on its own", () => {
for (const rel of LOOKUP) {
const dir = tmp("pr-tpl");
write(dir, rel, "## Summary\n");
const r = P(dir, "template");
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json, { ok: true, found: true, path: rel, headings: ["Summary"], hasTesting: false, others: [] }, rel);
}
});
test("pr-prep template: the first in order wins and the rest are others", () => {
const dir = tmp("pr-tpl-order");
write(dir, "PULL_REQUEST_TEMPLATE.md", "## Root\n");
write(dir, "docs/pull_request_template.md", "## Docs\n");
write(dir, ".github/PULL_REQUEST_TEMPLATE/feature.md", "## Feature\n");
write(dir, ".github/PULL_REQUEST_TEMPLATE/bug.md", "## Bug\n");
write(dir, ".github/PULL_REQUEST_TEMPLATE/notes.txt", "not a template\n");
write(dir, ".gitlab/merge_request_templates/Default.md", "## GitLab\n");
const r = P(dir, "template");
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.path, "PULL_REQUEST_TEMPLATE.md");
assert.deepEqual(r.json.headings, ["Root"]);
assert.deepEqual(r.json.others, [
"docs/pull_request_template.md",
".github/PULL_REQUEST_TEMPLATE/bug.md",
".github/PULL_REQUEST_TEMPLATE/feature.md",
".gitlab/merge_request_templates/Default.md",
]);
});
test("pr-prep template: names are compared case-insensitively", () => {
const dir = tmp("pr-tpl-case");
write(dir, ".GitHub/Pull_Request_Template.MD", "## What\n");
const r = P(dir, "template");
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.found, true);
assert.equal(r.json.path, ".GitHub/Pull_Request_Template.MD");
});
test("pr-prep template: headings outside code fences only, # to ###, and hasTesting", () => {
const dir = tmp("pr-tpl-headings");
write(
dir,
".github/pull_request_template.md",
"# Title\n\n<!-- describe it -->\n## Summary ##\n\n```markdown\n## Not a heading\n```\n\n~~~\n# Also not\n~~~\n\n### How was this tested?\n#### Too deep\n ## indented code\n#No space\n"
);
const r = P(dir, "template");
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json.headings, ["Title", "Summary", "How was this tested?"]);
assert.equal(r.json.hasTesting, true);
for (const [heading, expected] of [["## Verification", true], ["## QA notes", true], ["## How it was checked", true], ["## Summary\n## Risks", false]]) {
write(dir, ".github/pull_request_template.md", `${heading}\n`);
assert.equal(P(dir, "template").json.hasTesting, expected, heading);
}
});
test("pr-prep template: none found", () => {
const dir = tmp("pr-tpl-none");
write(dir, "README.md", "# Project\n");
write(dir, ".github/workflows/ci.yml", "on: push\n");
const r = P(dir, "template");
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json, { ok: true, found: false, path: null, headings: [], hasTesting: false, others: [] });
});
/* ----------------------------------------------------------------- pr-url */
function repoOnMain(name) {
const repo = tmp(name);
const g = gitInit(repo);
write(repo, "a.txt", "a\n");
g("add", "a.txt");
g("commit", "-q", "-m", "init");
return { repo, g };
}
test("pr-prep pr-url: a pushed branch gives the link, an unpushed one pushed: false with exit 0", () => {
const { repo, g } = repoOnMain("pr-url");
const bare = tmp("pr-url-origin");
execFileSync("git", ["init", "-q", "--bare", "-b", "main", bare], { stdio: "pipe" });
g("remote", "add", "origin", slashed(bare));
g("push", "-q", "-u", "origin", "main");
g("switch", "-q", "-c", "feature/x");
write(repo, "b.txt", "b\n");
g("add", "b.txt");
g("commit", "-q", "-m", "b");
const unpushed = P(repo, "pr-url");
assert.equal(unpushed.code, 0, unpushed.stderr);
assert.equal(unpushed.json.ok, true);
assert.equal(unpushed.json.pushed, false);
assert.equal(unpushed.json.branch, "feature/x");
assert.match(unpushed.json.next, /plan2code-git/);
g("push", "-q", "-u", "origin", "feature/x");
// The pushed copy lives in the local bare repo; the link comes from the
// remote's address, so point it at a forge host once the push is done.
g("remote", "set-url", "origin", "git@github.com:owner/repo.git");
write(repo, "c.txt", "c\n");
g("add", "c.txt");
g("commit", "-q", "-m", "c");
const pushed = P(repo, "pr-url");
assert.equal(pushed.code, 0, pushed.stderr);
assert.deepEqual(pushed.json, {
ok: true,
pushed: true,
url: "https://github.com/owner/repo/compare/main...feature/x?quick_pull=1",
host: "github.com",
kind: "github",
needsKind: false,
branch: "feature/x",
base: "main",
ahead: 1,
});
});
test("pr-prep pr-url: a detached HEAD fails as git.mjs does; outside a repo is exit 3", () => {
const { repo, g } = repoOnMain("pr-url-detached");
g("checkout", "-q", "--detach");
const mine = P(repo, "pr-url");
const git = runScript("plan2code-git", "git.mjs", ["pr-url"], { cwd: repo, env: { PLAN2CODE_CONSOLE_HOME: HOME } });
assert.equal(mine.code, 5);
assert.equal(mine.code, git.code);
assert.deepEqual(mine.json, git.json);
assert.equal(mine.json.error, "detached");
const plain = tmp("pr-url-plain");
const r = P(plain, "pr-url");
assert.equal(r.code, 3);
assert.equal(r.json.error, "not-a-repo");
});
/* ------------------------------------------------------------------- spec */
const EARLY = new Date("2026-06-01T12:00:00Z");
const LATE = new Date("2026-07-15T12:00:00Z");
/** Every file under `dir` stamped with `when`. */
function stamp(dir, when) {
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
const p = path.join(dir, e.name);
if (e.isDirectory()) stamp(p, when);
else fs.utimesSync(p, when, when);
}
}
/** A repo whose main commit is dated 2026-07-01, on `branch` from it, with the given spec folders (each stamped EARLY). */
function specRepo(name, branch, folders) {
const repo = tmp(name);
const g = gitInit(repo);
write(repo, "a.txt", "a\n");
g("add", "a.txt");
const env = { ...process.env, GIT_AUTHOR_DATE: "2026-07-01T12:00:00Z", GIT_COMMITTER_DATE: "2026-07-01T12:00:00Z" };
execFileSync("git", ["commit", "-q", "-m", "init"], { cwd: repo, env, stdio: "pipe" });
if (branch !== "main") g("switch", "-q", "-c", branch);
for (const f of folders) write(repo, `${f}/overview.md`, "# Spec\n");
for (const d of ["specs", "specs--completed"]) if (fs.existsSync(path.join(repo, d))) stamp(path.join(repo, d), EARLY);
return repo;
}
test("pr-prep spec: the branch name matches a folder in specs/", () => {
const repo = specRepo("spec-branch", "feature/pr-prep-and-test-skills", ["specs/pr-prep-and-test-skills", "specs/other-thing", "specs--completed/pr-prep-and-test-skills"]);
const r = P(repo, "spec");
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json, { ok: true, branch: "feature/pr-prep-and-test-skills", match: "specs/pr-prep-and-test-skills", candidates: [], how: "branch" });
});
test("pr-prep spec: a match only in specs--completed/, a user segment, and --branch", () => {
const repo = specRepo("spec-completed", "jane/Lunch_Vote", ["specs--completed/lunch-vote", "specs/unrelated"]);
const r = P(repo, "spec");
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.match, "specs--completed/lunch-vote");
assert.equal(r.json.how, "branch");
assert.equal(P(repo, "spec", "--branch", "fix/unrelated-crash").json.match, "specs/unrelated");
});
test("pr-prep spec: two names in the branch is ask", () => {
const repo = specRepo("spec-ask", "feature/auth-and-billing", ["specs/auth", "specs/billing", "specs/search"]);
const r = P(repo, "spec");
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json, { ok: true, branch: "feature/auth-and-billing", match: null, candidates: ["specs/auth", "specs/billing"], how: "ask" });
});
test("pr-prep spec: no name match, one folder touched since the branch began, is recent; several is ask", () => {
const repo = specRepo("spec-recent", "feature/something-else", ["specs/old-work", "specs/new-work", "specs--completed/done-work"]);
stamp(path.join(repo, "specs", "new-work"), LATE);
const r = P(repo, "spec");
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json, { ok: true, branch: "feature/something-else", match: "specs/new-work", candidates: [], how: "recent" });
write(repo, "specs--completed/done-work/deep/a/b/c/notes.md", "x\n");
stamp(path.join(repo, "specs--completed", "done-work"), EARLY);
fs.utimesSync(path.join(repo, "specs--completed/done-work/deep/a/b/c/notes.md"), LATE, LATE);
assert.equal(P(repo, "spec").json.how, "recent", "a file five levels down is past the walk");
fs.utimesSync(path.join(repo, "specs--completed/done-work/overview.md"), LATE, LATE);
const two = P(repo, "spec").json;
assert.equal(two.how, "ask");
assert.deepEqual(two.candidates, ["specs/new-work", "specs--completed/done-work"]);
});
test("pr-prep spec: --branch measures the recent rule from that branch's start, not HEAD's", () => {
const repo = specRepo("spec-branch-start", "feature/side-work", ["specs/tracker"]);
const g = gitIn(repo);
g("switch", "-q", "main");
write(repo, "b.txt", "b\n");
g("add", "b.txt");
const env = { ...process.env, GIT_AUTHOR_DATE: "2026-08-01T12:00:00Z", GIT_COMMITTER_DATE: "2026-08-01T12:00:00Z" };
execFileSync("git", ["commit", "-q", "-m", "later on main"], { cwd: repo, env, stdio: "pipe" });
stamp(path.join(repo, "specs", "tracker"), LATE);
assert.equal(P(repo, "spec").json.how, "none", "on main the start is main's own tip, after the folder changed");
const r = P(repo, "spec", "--branch", "feature/side-work");
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json, { ok: true, branch: "feature/side-work", match: "specs/tracker", candidates: [], how: "recent" });
});
test("pr-prep spec: nothing fits is none; outside a repo is exit 3", () => {
const repo = specRepo("spec-none", "feature/something-else", ["specs/old-work"]);
const r = P(repo, "spec");
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json, { ok: true, branch: "feature/something-else", match: null, candidates: [], how: "none" });
const bare = specRepo("spec-empty", "main", []);
assert.equal(P(bare, "spec").json.how, "none");
const plain = tmp("spec-plain");
const out = P(plain, "spec");
assert.equal(out.code, 3);
assert.equal(out.json.error, "not-a-repo");
});
test("pr-prep: bad arguments exit 2", () => {
const dir = tmp("pr-args");
assert.equal(P(dir).code, 2);
assert.equal(P(dir, "nope").code, 2);
assert.equal(P(dir, "template", "extra").code, 2);
assert.equal(P(dir, "spec", "--bogus").code, 2);
});
+14 -24
View File
@@ -1,26 +1,16 @@
// run-check.mjs: the four outcomes, the process-tree kill on timeout, the log
// and the tail cap. Runs src/skill-scripts/run-check.mjs directly until a
// skill ships it. See skill-script-helpers.mjs for the fixtures.
// and the tail cap, run from the built plan2code-pr-prep skill, which ships
// it. See skill-script-helpers.mjs for the fixtures.
import { test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { ROOT, NOW, scrubbedEnv, tmp, write } from "./skill-script-helpers.mjs";
import { ROOT, runScript, scrubbedEnv, tmp, write } from "./skill-script-helpers.mjs";
const SCRIPT = path.join(ROOT, "src", "skill-scripts", "run-check.mjs");
const NODE = `"${process.execPath}"`;
function runShared(args, { cwd } = {}) {
const r = spawnSync(process.execPath, [SCRIPT, ...args], { cwd: cwd || ROOT, encoding: "utf8", env: scrubbedEnv({ PLAN2CODE_NOW: NOW }) });
let json = null;
try {
json = JSON.parse(r.stdout);
} catch {}
return { code: r.status, json, stdout: r.stdout, stderr: r.stderr };
}
const alive = (pid) => {
try {
process.kill(pid, 0);
@@ -31,7 +21,7 @@ const alive = (pid) => {
};
test("run-check: passed on exit 0", () => {
const r = runShared(["--cmd", `${NODE} -e "process.exit(0)"`]);
const r = runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", `${NODE} -e "process.exit(0)"`]);
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.outcome, "passed");
assert.equal(r.json.exit, 0);
@@ -43,7 +33,7 @@ test("run-check: passed on exit 0", () => {
test("run-check: failed on exit 1, with the printed lines in the tail", () => {
const dir = tmp("check-fail");
write(dir, "fail.js", "console.log('first line');\nconsole.error('second line');\nprocess.exit(1);\n");
const r = runShared(["--cmd", `${NODE} fail.js`, "--cwd", dir]);
const r = runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", `${NODE} fail.js`, "--cwd", dir]);
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.outcome, "failed");
assert.equal(r.json.exit, 1);
@@ -52,11 +42,11 @@ test("run-check: failed on exit 1, with the printed lines in the tail", () => {
});
test("run-check: not-started for a made-up command and for a missing --cwd", () => {
const r = runShared(["--cmd", "p2c-no-such-command-xyz --flag"]);
const r = runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", "p2c-no-such-command-xyz --flag"]);
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.outcome, "not-started");
assert.equal(r.json.reason, "command-not-found");
const c = runShared(["--cmd", `${NODE} -e "process.exit(0)"`, "--cwd", path.join(tmp("check-cwd"), "missing")]);
const c = runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", `${NODE} -e "process.exit(0)"`, "--cwd", path.join(tmp("check-cwd"), "missing")]);
assert.equal(c.code, 0, c.stderr);
assert.equal(c.json.outcome, "not-started");
assert.equal(c.json.reason, "cwd-missing");
@@ -66,7 +56,7 @@ test("run-check: timeout kills the whole process tree", async () => {
const dir = tmp("check-timeout");
write(dir, "grandchild.js", "require('fs').writeFileSync(require('path').join(__dirname, 'pid.txt'), String(process.pid));\nsetInterval(() => {}, 1000);\n");
write(dir, "parent.js", "require('child_process').spawn(process.execPath, [require('path').join(__dirname, 'grandchild.js')], { stdio: 'inherit' });\nsetInterval(() => {}, 1000);\n");
const r = runShared(["--cmd", `${NODE} parent.js`, "--cwd", dir, "--timeout", "2"]);
const r = runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", `${NODE} parent.js`, "--cwd", dir, "--timeout", "2"]);
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.outcome, "timeout");
const pidFile = path.join(dir, "pid.txt");
@@ -81,7 +71,7 @@ test("run-check: --log holds the full output and the tail keeps 60 lines of at m
const dir = tmp("check-log");
write(dir, "many.js", "for (let i = 1; i <= 100; i++) console.log('line ' + i);\nconsole.log('x'.repeat(500));\n");
const log = path.join(dir, "logs", "deep", "run.log");
const r = runShared(["--cmd", `${NODE} many.js`, "--cwd", dir, "--log", log]);
const r = runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", `${NODE} many.js`, "--cwd", dir, "--log", log]);
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.outcome, "passed");
assert.equal(r.json.log, log);
@@ -95,11 +85,11 @@ test("run-check: --log holds the full output and the tail keeps 60 lines of at m
});
test("run-check: bad arguments exit 2", () => {
assert.equal(runShared([]).code, 2);
assert.equal(runShared(["--cmd", "x", "--timeout", "soon"]).code, 2);
assert.equal(runShared(["--cmd", "x", "--timeout", "0"]).code, 2);
assert.equal(runShared(["--cmd", "x", "--timeout", "86401"]).code, 2, "past one day the timer would overflow");
assert.equal(runShared(["--cmd", "x", "extra"]).code, 2);
assert.equal(runScript("plan2code-pr-prep", "run-check.mjs", []).code, 2);
assert.equal(runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", "x", "--timeout", "soon"]).code, 2);
assert.equal(runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", "x", "--timeout", "0"]).code, 2);
assert.equal(runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", "x", "--timeout", "86401"]).code, 2, "past one day the timer would overflow");
assert.equal(runScript("plan2code-pr-prep", "run-check.mjs", ["--cmd", "x", "extra"]).code, 2);
});
test("run-check and test-commands do nothing when imported", () => {
+29 -43
View File
@@ -1,29 +1,15 @@
// Tests for the shared test-match.mjs.
//
// No skill ships test-match.mjs yet, so these run it from src/skill-scripts/,
// where common.mjs, glob.mjs, test-map.mjs and review-scope.mjs sit beside it.
// See skill-script-helpers.mjs for the fixtures and the scrubbed git config.
// Tests for the shared test-match.mjs, run from the built plan2code-pr-prep
// skill, which ships it beside common.mjs, glob.mjs, test-map.mjs and
// review-scope.mjs. See skill-script-helpers.mjs for the fixtures and the
// scrubbed git config.
import { test, after } from "node:test";
import assert from "node:assert/strict";
import path from "node:path";
import { spawnSync, execFileSync } from "node:child_process";
import { ROOT, NOW, scrubbedEnv, tmp, write, gitInit, gitIn, copyFixture, fixtureCleanup } from "./skill-script-helpers.mjs";
import { execFileSync } from "node:child_process";
import { runScript, tmp, write, gitInit, gitIn, copyFixture, fixtureCleanup } from "./skill-script-helpers.mjs";
after(fixtureCleanup);
const SCRIPT = path.join(ROOT, "src", "skill-scripts", "test-match.mjs");
const SCOPE = path.join(ROOT, "src", "skill-scripts", "review-scope.mjs");
function runShared(args, { cwd, input } = {}) {
const r = spawnSync(process.execPath, [SCRIPT, ...args], { cwd: cwd || ROOT, encoding: "utf8", input, env: scrubbedEnv({ PLAN2CODE_NOW: NOW }) });
let json = null;
try {
json = JSON.parse(r.stdout);
} catch {}
return { code: r.status, json, stdout: r.stdout, stderr: r.stderr };
}
// A commit with pinned author and committer dates.
function commitAt(dir, date, msg, files = {}) {
for (const [rel, content] of Object.entries(files)) write(dir, rel, content);
@@ -83,7 +69,7 @@ function matchRepo() {
test("test-match covers: map rows, shared hits, hints and the fallback rules", () => {
const dir = matchRepo();
const files = ["src/launcher/a.js", "src/launcher/shared.js", "src/web-console/x.js", "src/app/util.js", "src/widget/button.js", "src/lib/math.js", "src/pkgdir/index.js", "src/lib/alias.js", "pkg/mod.py", "gosrc/util/u.go", "package.json", "fixtures/sample.json", "test/helpers/setup.js"];
const r = runShared(["covers", "--files", files.join(",")], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["covers", "--files", files.join(",")], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.mapFound, true);
assert.deepEqual(r.json.matched, [
@@ -110,7 +96,7 @@ test("test-match covers: map rows, shared hits, hints and the fallback rules", (
test("test-match covers: Windows-style --files input", () => {
const dir = matchRepo();
const r = runShared(["covers", "--files", "src\\launcher\\a.js"], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["covers", "--files", "src\\launcher\\a.js"], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json.matched[0].files, ["src/launcher/a.js"]);
});
@@ -120,21 +106,21 @@ test("test-match covers --stdin: real review-scope.mjs output", () => {
gitIn(dir)("checkout", "-q", "-b", "feature");
commitAt(dir, "2026-07-02T12:00:00Z", "Change", { "src/launcher/a.js": "a2\n" });
write(dir, "src/app/util.js", "u2\n");
const scope = spawnSync(process.execPath, [SCOPE], { cwd: dir, encoding: "utf8", env: scrubbedEnv() });
assert.equal(scope.status, 0, scope.stderr);
const r = runShared(["covers", "--stdin"], { cwd: dir, input: scope.stdout });
const scope = runScript("plan2code-pr-prep", "review-scope.mjs", [], { cwd: dir });
assert.equal(scope.code, 0, scope.stderr);
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["covers", "--stdin"], { cwd: dir, input: scope.stdout });
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json.matched.map((m) => m.area), ["Launcher"]);
assert.deepEqual(r.json.unmatched, [{ file: "src/app/util.js", tests: ["src/app/util.test.js"], method: "name" }]);
assert.equal(runShared(["covers", "--stdin"], { cwd: dir, input: "not json" }).code, 2);
assert.equal(runShared(["covers"], { cwd: dir }).code, 2);
assert.equal(runScript("plan2code-pr-prep", "test-match.mjs", ["covers", "--stdin"], { cwd: dir, input: "not json" }).code, 2);
assert.equal(runScript("plan2code-pr-prep", "test-match.mjs", ["covers"], { cwd: dir }).code, 2);
});
test("test-match covers: no test map leaves every file unmatched, still exit 0", () => {
const dir = tmp("match-nomap");
write(dir, "a.js", "a\n");
write(dir, "a.test.js", "t\n");
const r = runShared(["covers", "--files", "a.js,b.js"], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["covers", "--files", "a.js,b.js"], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.mapFound, false);
assert.deepEqual(r.json.matched, []);
@@ -160,7 +146,7 @@ function gapsRepo() {
test("test-match gaps --scope all: untested source files ranked by last change, then churn", () => {
const dir = gapsRepo();
const r = runShared(["gaps", "--scope", "all"], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["gaps", "--scope", "all"], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json.gaps, [
{ file: "src/sub/c.js", area: null, runner: null, commits90d: 1, lastTouched: "2026-07-25" },
@@ -176,15 +162,15 @@ test("test-match gaps --scope all: untested source files ranked by last change,
test("test-match gaps --scope path and --scope branch", () => {
const dir = gapsRepo();
const p = runShared(["gaps", "--scope", "path", "--path", "src/sub"], { cwd: dir });
const p = runScript("plan2code-pr-prep", "test-match.mjs", ["gaps", "--scope", "path", "--path", "src/sub"], { cwd: dir });
assert.equal(p.code, 0, p.stderr);
assert.deepEqual(p.json.gaps.map((x) => x.file), ["src/sub/c.js"]);
assert.equal(runShared(["gaps", "--scope", "path"], { cwd: dir }).code, 2, "--scope path needs --path");
assert.equal(runScript("plan2code-pr-prep", "test-match.mjs", ["gaps", "--scope", "path"], { cwd: dir }).code, 2, "--scope path needs --path");
gitIn(dir)("checkout", "-q", "-b", "feature");
commitAt(dir, "2026-07-30T12:00:00Z", "Feature", { "src/feat.js": "f\n", "src/feat2.js": "g\n" });
write(dir, "src/new.js", "n\n");
const b = runShared(["gaps", "--scope", "branch"], { cwd: dir });
const b = runScript("plan2code-pr-prep", "test-match.mjs", ["gaps", "--scope", "branch"], { cwd: dir });
assert.equal(b.code, 0, b.stderr);
assert.deepEqual(b.json.gaps, [
{ file: "src/feat.js", area: null, runner: null, commits90d: 1, lastTouched: "2026-07-30" },
@@ -197,13 +183,13 @@ test("test-match gaps: a non-git folder walks the tree; --scope branch is exit 3
const dir = tmp("match-nogit");
write(dir, "src/a.js", "a\n");
write(dir, "node_modules/x/i.js", "x\n");
const r = runShared(["gaps", "--scope", "all"], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["gaps", "--scope", "all"], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json.gaps, [{ file: "src/a.js", area: null, runner: null, commits90d: null, lastTouched: null }]);
const b = runShared(["gaps", "--scope", "branch"], { cwd: dir });
const b = runScript("plan2code-pr-prep", "test-match.mjs", ["gaps", "--scope", "branch"], { cwd: dir });
assert.equal(b.code, 3);
assert.equal(b.json.error, "not-a-repo");
assert.equal(runShared(["gaps"], { cwd: dir }).code, 2);
assert.equal(runScript("plan2code-pr-prep", "test-match.mjs", ["gaps"], { cwd: dir }).code, 2);
});
test("test-match gaps: any matching row with a run covers a file; a row without one only names its area", () => {
@@ -213,7 +199,7 @@ test("test-match gaps: any matching row with a run covers a file; a row without
write(dir, "src/y.js", "y\n");
write(dir, "src/m.ts", "m\n");
write(dir, "src/m.test.mts", "t\n");
const r = runShared(["gaps", "--scope", "all"], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["gaps", "--scope", "all"], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json.gaps, [{ file: "src/y.js", area: "Source", runner: null, commits90d: null, lastTouched: null }]);
assert.equal(r.json.covered, 2, "x.js by the second row, m.ts by its .mts test");
@@ -222,7 +208,7 @@ test("test-match gaps: any matching row with a run covers a file; a row without
test("test-match gaps: capped at 2,000 source files", () => {
const dir = tmp("match-cap");
for (let i = 0; i < 2005; i++) write(dir, `src/f${String(i).padStart(4, "0")}.js`, "x\n");
const r = runShared(["gaps", "--scope", "all"], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["gaps", "--scope", "all"], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.capped, true);
assert.equal(r.json.scanned, 2000);
@@ -234,21 +220,21 @@ test("test-match gaps: capped at 2,000 source files", () => {
test("test-match nearest: own tests, then the same folder, then the mirrored folder, at most 3", () => {
const dir = matchRepo();
const r = runShared(["nearest", "--file", "src/app/util.js"], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["nearest", "--file", "src/app/util.js"], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json, { ok: true, file: "src/app/util.js", tests: ["src/app/util.test.js", "src/app/other.test.js", "tests/app/mirror.test.js"] });
const m = runShared(["nearest", "--file", "src/app/new.js"], { cwd: dir });
const m = runScript("plan2code-pr-prep", "test-match.mjs", ["nearest", "--file", "src/app/new.js"], { cwd: dir });
assert.deepEqual(m.json.tests, ["src/app/other.test.js", "src/app/util.test.js", "tests/app/mirror.test.js"]);
assert.equal(runShared(["nearest"], { cwd: dir }).code, 2);
assert.equal(runScript("plan2code-pr-prep", "test-match.mjs", ["nearest"], { cwd: dir }).code, 2);
});
test("test-match nearest: the area's run path, then the nearest by shared folders", () => {
const dir = matchRepo();
const r = runShared(["nearest", "--file", "src/web-console/x.js"], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["nearest", "--file", "src/web-console/x.js"], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json.tests.slice(0, 2), ["tests/console/page.test.js", "tests/console/server.test.js"], "the Console row's run names tests/console");
assert.equal(r.json.tests.length, 3);
const deep = runShared(["nearest", "--file", "src/widget/deep/z.js"], { cwd: dir });
const deep = runScript("plan2code-pr-prep", "test-match.mjs", ["nearest", "--file", "src/widget/deep/z.js"], { cwd: dir });
assert.equal(deep.json.tests[0], "src/widget/__tests__/button.js", "the test file sharing the most folders");
});
@@ -281,7 +267,7 @@ test("test-match covers: AGENTS.md's Targeted tests first table, saved as a test
"Workflow prompt": "src/plan2code-3-implement.md",
Docs: ".readme/web-console.md",
};
const r = runShared(["covers", "--files", Object.values(samples).join(",")], { cwd: dir });
const r = runScript("plan2code-pr-prep", "test-match.mjs", ["covers", "--files", Object.values(samples).join(",")], { cwd: dir });
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json.unmatched, []);
for (const [area, file] of Object.entries(samples)) {
+2 -1
View File
@@ -47,7 +47,7 @@ test("Document writes Targeted, Quick checks and Full suite lines and reads test
assert.match(doc, /no Full Suite row: ask/);
});
test("test-runs.md ships in the six skills that run, write or offer tests, and in no other", () => {
test("test-runs.md ships in the seven skills that run, write or offer tests, and in no other", () => {
// npm test has just built skills/; a direct run builds it so the check never reads a stale tree.
if (process.env.npm_lifecycle_event !== "test") {
execFileSync(process.execPath, [path.join(ROOT, "install.js"), "--build-skills"], { stdio: "ignore" });
@@ -59,6 +59,7 @@ test("test-runs.md ships in the six skills that run, write or offer tests, and i
"plan2code-3-implement",
"plan2code-3-implement-review",
"plan2code-4-finalize",
"plan2code-pr-prep",
"plan2code-quick-task",
"plan2code-review",
]);
+2 -1
View File
@@ -399,7 +399,7 @@ test("Implement's card launches Implement + Review when Review is ticked", () =>
assert.equal(launchVariant(quick, true), quick, "a card with no Review box is unchanged");
});
test("helper-strength.md ships in the thirteen skills that start helpers, and in no other", () => {
test("helper-strength.md ships in the fourteen skills that start helpers, and in no other", () => {
// npm test has just built skills/; a direct run builds it so the check never reads a stale tree.
if (process.env.npm_lifecycle_event !== "test") {
execFileSync(process.execPath, [path.join(ROOT, "install.js"), "--build-skills"], { stdio: "ignore" });
@@ -417,6 +417,7 @@ test("helper-strength.md ships in the thirteen skills that start helpers, and in
"plan2code-diagnose",
"plan2code-init",
"plan2code-init-update",
"plan2code-pr-prep",
"plan2code-quick-task",
"plan2code-review",
"plan2code-xray",
+33
View File
@@ -275,6 +275,18 @@ const CARDS = {
built: { on: true },
unrecognized: { on: true },
},
"plan2code-pr-prep": {
"none": { on: true },
diagnosed: { on: true },
fixed: { on: true },
exploring: { on: true },
mapped: { on: true },
planned: { on: true },
documented: { on: true },
building: { on: true },
built: { on: true },
unrecognized: { on: true },
},
"plan2code-changelog": {
"none": { on: true },
diagnosed: { on: true },
@@ -418,6 +430,27 @@ test("the scan: every state it can return is in the table, and a fixture reaches
assert.deepEqual(scanProblems(FIXTURES, known), ["the scan returns unrecognized, which spec-states.js lacks"]);
});
test("the scan: a PR-READINESS report changes no spec's state, and alone it stays unrecognized", () => {
const scanOf = (fixtures) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-spec-readiness-"));
try {
for (const [name, files] of Object.entries(fixtures))
for (const [rel, text] of Object.entries(files)) {
const file = path.join(root, "specs", name, rel);
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, text);
}
return Object.fromEntries(scanProject(root).specs.map((sp) => [sp.name, [sp.state, sp.detail]]));
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
};
const REPORT = { "PR-READINESS-20261103.md": "# PR readiness\n\n**Verdict:** Ready\n\n- [x] Unit tests\n- [ ] Lint (trimmed)\n" };
const withReport = Object.fromEntries(Object.entries(FIXTURES).map(([name, files]) => [name, { ...files, ...REPORT }]));
assert.deepEqual(scanOf(withReport), scanOf(FIXTURES));
assert.equal(scanOf({ only: REPORT }).only[0], "unrecognized");
});
test("the scan: an assumed task counts as done and is named, and numbered task lines count", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-spec-assumed-"));
const specs = {