mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Add the Test skill: find untested code and write tests in the project's style
AI Assisted
This commit is contained in:
1 parent
88c72dc2ce
commit
6cd7a7ff80
21 files changed
+753
-16
No files matched your search
@@ -0,0 +1,160 @@
|
||||
// Tests for plan2code-test's scripts/coverage.mjs: lcov and go tool cover -func
|
||||
// output read into per-file numbers. See skill-script-helpers.mjs for how these
|
||||
// run.
|
||||
|
||||
import { test, after } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { runScript, tmp, write, fixtureCleanup } from "./skill-script-helpers.mjs";
|
||||
|
||||
after(fixtureCleanup);
|
||||
|
||||
const C = (cwd, ...a) => runScript("plan2code-test", "coverage.mjs", a, { cwd });
|
||||
|
||||
// What `node --test --experimental-test-coverage --test-reporter=lcov` writes:
|
||||
// FN/FNDA/BRDA lines around the DA lines, relative paths, one file never run.
|
||||
const NODE_LCOV = `TN:
|
||||
SF:src/math.js
|
||||
FN:1,add
|
||||
FNDA:3,add
|
||||
FNF:1
|
||||
FNH:1
|
||||
BRDA:2,0,0,1
|
||||
BRF:1
|
||||
BRH:1
|
||||
DA:1,1
|
||||
DA:2,3
|
||||
DA:3,3
|
||||
DA:4,1
|
||||
LH:4
|
||||
LF:4
|
||||
end_of_record
|
||||
TN:
|
||||
SF:src/unused.js
|
||||
FN:1,never
|
||||
FNDA:0,never
|
||||
FNF:1
|
||||
FNH:0
|
||||
DA:1,0
|
||||
DA:2,0
|
||||
DA:3,0
|
||||
LH:0
|
||||
LF:3
|
||||
end_of_record
|
||||
`;
|
||||
|
||||
test("coverage read --lcov: Node's lcov reporter, two files, one at 0 hits", () => {
|
||||
const dir = tmp("cov-node");
|
||||
write(dir, "lcov.info", NODE_LCOV);
|
||||
const r = C(dir, "read", "--lcov", "lcov.info");
|
||||
assert.equal(r.code, 0, r.stderr);
|
||||
assert.deepEqual(r.json, {
|
||||
ok: true,
|
||||
format: "lcov",
|
||||
files: [
|
||||
{ file: "src/math.js", lines: 4, hit: 4, pct: 100 },
|
||||
{ file: "src/unused.js", lines: 3, hit: 0, pct: 0 },
|
||||
],
|
||||
total: { lines: 7, hit: 4, pct: 57.1 },
|
||||
});
|
||||
});
|
||||
|
||||
test("coverage read --lcov: Jest's absolute Windows paths under the root become relative", () => {
|
||||
const dir = tmp("cov-jest");
|
||||
const lcov = [
|
||||
"TN:",
|
||||
"SF:C:\\work\\app\\src\\b\\view.ts",
|
||||
"DA:1,1",
|
||||
"DA:2,0",
|
||||
"DA:3,1",
|
||||
"LF:3",
|
||||
"LH:2",
|
||||
"end_of_record",
|
||||
"TN:",
|
||||
"SF:c:\\work\\app\\src\\a.ts",
|
||||
"DA:1,1",
|
||||
"LF:1",
|
||||
"LH:1",
|
||||
"end_of_record",
|
||||
"TN:",
|
||||
"SF:D:\\other\\lib.ts",
|
||||
"DA:1,0",
|
||||
"LF:1",
|
||||
"LH:0",
|
||||
"end_of_record",
|
||||
"",
|
||||
].join("\r\n");
|
||||
write(dir, "coverage/lcov.info", lcov);
|
||||
const r = C(dir, "read", "--lcov", "coverage/lcov.info", "--root", "C:\\work\\app");
|
||||
assert.equal(r.code, 0, r.stderr);
|
||||
assert.deepEqual(
|
||||
r.json.files.map((f) => [f.file, f.pct]),
|
||||
[
|
||||
["D:\\other\\lib.ts", 0],
|
||||
["src/a.ts", 100],
|
||||
["src/b/view.ts", 66.7],
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
test("coverage read --lcov: a record without LF or LH counts its DA lines", () => {
|
||||
const dir = tmp("cov-nolf");
|
||||
write(dir, "lcov.info", "SF:lib/x.py\nDA:1,2\nDA:2,0\nDA:5,1\nend_of_record\nSF:lib/empty.py\nend_of_record\n");
|
||||
const r = C(dir, "read", "--lcov", "lcov.info");
|
||||
assert.equal(r.code, 0, r.stderr);
|
||||
assert.deepEqual(r.json.files, [
|
||||
{ file: "lib/empty.py", lines: 0, hit: 0, pct: null },
|
||||
{ file: "lib/x.py", lines: 3, hit: 2, pct: 66.7 },
|
||||
]);
|
||||
assert.deepEqual(r.json.total, { lines: 3, hit: 2, pct: 66.7 });
|
||||
});
|
||||
|
||||
test("coverage read --go-func: functions grouped by file, the module path dropped, total reported", () => {
|
||||
const dir = tmp("cov-go");
|
||||
write(dir, "go.mod", "module example.com/shop\n\ngo 1.22\n");
|
||||
write(
|
||||
dir,
|
||||
"cover.txt",
|
||||
[
|
||||
"example.com/shop/cart/cart.go:12:\t\tAdd\t\t100.0%",
|
||||
"example.com/shop/cart/cart.go:30:\t\tRemove\t\t33.4%",
|
||||
"example.com/shop/pay/pay.go:8:\t\tCharge\t\t0.0%",
|
||||
"total:\t\t\t\t(statements)\t\t52.6%",
|
||||
"",
|
||||
].join("\n")
|
||||
);
|
||||
const r = C(dir, "read", "--go-func", "cover.txt");
|
||||
assert.equal(r.code, 0, r.stderr);
|
||||
assert.deepEqual(r.json, {
|
||||
ok: true,
|
||||
format: "go-func",
|
||||
files: [
|
||||
{ file: "cart/cart.go", lines: null, hit: null, pct: 66.7 },
|
||||
{ file: "pay/pay.go", lines: null, hit: null, pct: 0 },
|
||||
],
|
||||
total: { lines: null, hit: null, pct: 52.6 },
|
||||
});
|
||||
});
|
||||
|
||||
test("coverage read: a missing file is exit 3", () => {
|
||||
const dir = tmp("cov-missing");
|
||||
const r = C(dir, "read", "--lcov", "nope.info");
|
||||
assert.equal(r.code, 3);
|
||||
assert.equal(r.json.error, "no-file");
|
||||
});
|
||||
|
||||
test("coverage read: a file in neither format is exit 4", () => {
|
||||
const dir = tmp("cov-garbage");
|
||||
write(dir, "junk.txt", "PASS src/a.test.js\nAll files | 80 | 70 |\n");
|
||||
for (const flag of ["--lcov", "--go-func"]) {
|
||||
const r = C(dir, "read", flag, "junk.txt");
|
||||
assert.equal(r.code, 4, flag);
|
||||
assert.equal(r.json.error, "unreadable-format", flag);
|
||||
}
|
||||
});
|
||||
|
||||
test("coverage read: exactly one format flag is required", () => {
|
||||
const dir = tmp("cov-usage");
|
||||
assert.equal(C(dir, "read").code, 2);
|
||||
assert.equal(C(dir, "read", "--lcov", "a", "--go-func", "b").code, 2);
|
||||
assert.equal(C(dir).code, 2);
|
||||
});
|
||||
@@ -719,6 +719,23 @@ test("specs check-draft: a pathfinder draft at Resume at Phase 4 is checked ligh
|
||||
assert.deepEqual(bad.json.problems.map((p) => p.code).sort(), ["loop-token", "metric-word"]);
|
||||
});
|
||||
|
||||
test("specs check-draft: a Test escalation draft passes like a Quick Task one", () => {
|
||||
const root = specFixture();
|
||||
for (const from of ["Quick Task", "Test"]) {
|
||||
write(root, "specs/idea-only/PLAN-DRAFT-20260801.md", `# PLAN-DRAFT: Tests\n\n**Status:** Escalated from ${from} - Resume at Phase 2\n**Source:** ${from} escalation\n\n## 1. Executive Summary\n\nWrite the tests.\n`);
|
||||
const r = runScript("plan2code-1-plan", "specs.mjs", ["check-draft", "idea-only", "--root", root]);
|
||||
assert.equal(r.code, 0, r.stdout);
|
||||
assert.equal(r.json.status, `Escalated from ${from} - Resume at Phase 2`);
|
||||
}
|
||||
});
|
||||
|
||||
test("the skills that run test-match.mjs ship glob.mjs and test-map.mjs beside it", () => {
|
||||
for (const s of ["plan2code-pr-prep", "plan2code-test"]) {
|
||||
for (const f of ["test-match.mjs", "glob.mjs", "test-map.mjs"]) assert.ok(fs.existsSync(path.join(SKILLS, s, "scripts", f)), `${s}/scripts/${f}`);
|
||||
}
|
||||
assert.ok(fs.existsSync(path.join(SKILLS, "plan2code-test", "scripts", "coverage.mjs")), "plan2code-test ships its own coverage.mjs");
|
||||
});
|
||||
|
||||
test("common.mjs exports the shared loop-token and scrape patterns", async () => {
|
||||
const common = await import(new URL(`file:///${path.join(SKILLS, "plan2code-2-document", "scripts", "common.mjs").replace(/\\/g, "/")}`).href);
|
||||
assert.ok(common.LOOP_TOKENS instanceof RegExp);
|
||||
|
||||
@@ -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 seven skills that run, write or offer tests, and in no other", () => {
|
||||
test("test-runs.md ships in the eight 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" });
|
||||
@@ -62,6 +62,7 @@ test("test-runs.md ships in the seven skills that run, write or offer tests, and
|
||||
"plan2code-pr-prep",
|
||||
"plan2code-quick-task",
|
||||
"plan2code-review",
|
||||
"plan2code-test",
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -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 fourteen skills that start helpers, and in no other", () => {
|
||||
test("helper-strength.md ships in the fifteen 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" });
|
||||
@@ -420,6 +420,7 @@ test("helper-strength.md ships in the fourteen skills that start helpers, and in
|
||||
"plan2code-pr-prep",
|
||||
"plan2code-quick-task",
|
||||
"plan2code-review",
|
||||
"plan2code-test",
|
||||
"plan2code-xray",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -287,6 +287,18 @@ const CARDS = {
|
||||
built: { on: true },
|
||||
unrecognized: { on: true },
|
||||
},
|
||||
"plan2code-test": {
|
||||
"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 },
|
||||
|
||||
Reference in new issue
Block a user