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
@@ -59,7 +59,7 @@ Keep with you: every question, confidence score, decision and sign-off, Phases 3
|
||||
|
||||
Before Phase 1, run `node "<S>/specs.mjs" list` from the project root (`<S>`: `scripts/` beside this SKILL.md, `~/.agents/skills/plan2code-1-plan/scripts/` globally). It reads gitignored `specs/` (Glob silently finds nothing there) and gives each spec's `planDrafts` with its **Status:** line (`-prev` copies are `archived`; ignore them). Route on that status:
|
||||
- Status "Phase 3 Complete - Resume at Phase 4": Resume at Phase 4
|
||||
- Status "Escalated from Quick Task - Resume at Phase 2": Acknowledge, verify requirements, skip to Phase 2
|
||||
- Status "Escalated from Quick Task - Resume at Phase 2" or "Escalated from Test - Resume at Phase 2": Acknowledge, verify requirements, skip to Phase 2
|
||||
- Status "Draft" or "Complete": Ask user how to proceed
|
||||
- Before going on with any existing draft (a Pathfinder handoff, a Quick Task escalation, a Draft or Complete one), read its 2.4: `| Status | Deferred to Plan |`, empty or `Not discussed` means ask the Phase 1 testing question now and write the answer into 2.4; a cadence with no `Full Suite` row means ask only the full-suite part.
|
||||
- A spec folder holding a `DIAGNOSIS-*.md` (Diagnose's write-up of a bug): read it first, as the Phase 1 brief (the bug, its cause, the suggested fix); that folder's name is the feature name (do not ask for one), so the PLAN-DRAFT lands beside the diagnosis
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
#!/usr/bin/env node
|
||||
// coverage.mjs: coverage output read into per-file numbers, for the Test skill.
|
||||
//
|
||||
// Reads what a project's own coverage tool already wrote: an lcov file (Node's
|
||||
// test runner with the lcov reporter, Jest, Vitest, pytest-cov's lcov export)
|
||||
// or the text `go tool cover -func` prints. It never runs a tool and never
|
||||
// writes a file; the skill runs the coverage command first, on a yes.
|
||||
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { EXIT, fail, out, parseArgs, run } from "./common.mjs";
|
||||
|
||||
const USAGE = `
|
||||
coverage.mjs: per-file coverage from a coverage tool's output. JSON on stdout.
|
||||
|
||||
node coverage.mjs read --lcov <file> [--root <dir>]
|
||||
node coverage.mjs read --go-func <file> [--root <dir>]
|
||||
Prints { ok, format, files: [{ file, lines, hit, pct }], total },
|
||||
files sorted by path, pct with one decimal.
|
||||
lcov SF: / DA:<line>,<hits> / LF: / LH: / end_of_record records.
|
||||
lines is LF (or the DA count when LF is missing), hit is LH
|
||||
(or the DA lines with hits above 0). Paths are made relative
|
||||
to --root (default: the current folder) with forward slashes;
|
||||
an absolute path outside the root is kept as given. total
|
||||
sums every file.
|
||||
go-func "<import path>/<file>.go:<line>: <func> <pct>%" lines,
|
||||
grouped by file: pct is the mean of the file's functions,
|
||||
lines and hit are null. The module path from --root's go.mod
|
||||
is dropped so files read as project paths. The "total:" line
|
||||
is not a file: it is reported as total.
|
||||
A file with no lines has pct null.
|
||||
|
||||
Exit: 0 ok · 1 crash · 2 bad arguments · 3 no such file · 4 not lcov or
|
||||
go tool cover -func output.
|
||||
`;
|
||||
|
||||
const pct1 = (n) => Math.round(n * 10) / 10;
|
||||
const slash = (p) => p.replace(/\\/g, "/");
|
||||
const isAbs = (p) => p.startsWith("/") || /^[A-Za-z]:\//.test(p);
|
||||
|
||||
/** A path made relative to root when it lies under it; anything else as given (relative paths with forward slashes). */
|
||||
function relTo(root, file) {
|
||||
const f = slash(file.trim());
|
||||
if (!isAbs(f)) return f.replace(/^\.\//, "");
|
||||
const r = slash(root).replace(/\/+$/, "");
|
||||
const drive = /^[A-Za-z]:\//.test(f);
|
||||
const under = drive ? f.toLowerCase().startsWith(`${r.toLowerCase()}/`) : f.startsWith(`${r}/`);
|
||||
return under ? f.slice(r.length + 1) : file.trim();
|
||||
}
|
||||
|
||||
function byPath(a, b) {
|
||||
return a.file < b.file ? -1 : a.file > b.file ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ lcov */
|
||||
|
||||
function readLcov(text, root) {
|
||||
if (!/^SF:/m.test(text)) return null;
|
||||
const files = [];
|
||||
let cur = null;
|
||||
const close = () => {
|
||||
if (!cur) return;
|
||||
const lines = cur.lf ?? cur.da.length;
|
||||
const hit = cur.lh ?? cur.da.filter((h) => h > 0).length;
|
||||
files.push({ file: relTo(root, cur.sf), lines, hit, pct: lines ? pct1((hit / lines) * 100) : null });
|
||||
cur = null;
|
||||
};
|
||||
for (const raw of text.split(/\r?\n/)) {
|
||||
const line = raw.trim();
|
||||
if (line.startsWith("SF:")) {
|
||||
close();
|
||||
cur = { sf: line.slice(3), da: [], lf: null, lh: null };
|
||||
} else if (!cur) continue;
|
||||
else if (line.startsWith("DA:")) {
|
||||
const hits = Number(line.slice(3).split(",")[1]);
|
||||
cur.da.push(Number.isFinite(hits) ? hits : 0);
|
||||
} else if (line.startsWith("LF:")) cur.lf = Number(line.slice(3)) || 0;
|
||||
else if (line.startsWith("LH:")) cur.lh = Number(line.slice(3)) || 0;
|
||||
else if (line === "end_of_record") close();
|
||||
}
|
||||
close();
|
||||
files.sort(byPath);
|
||||
const lines = files.reduce((s, f) => s + f.lines, 0);
|
||||
const hit = files.reduce((s, f) => s + f.hit, 0);
|
||||
return { files, total: { lines, hit, pct: lines ? pct1((hit / lines) * 100) : null } };
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- go-func */
|
||||
|
||||
const GO_LINE = /^(.+\.go):\d+:\s+\S+\s+([\d.]+)%\s*$/;
|
||||
const GO_TOTAL = /^total:\s+(?:\(statements\)\s+)?([\d.]+)%\s*$/;
|
||||
|
||||
function goModule(root) {
|
||||
try {
|
||||
const m = fs.readFileSync(path.join(root, "go.mod"), "utf8").match(/^\s*module\s+(\S+)/m);
|
||||
return m ? m[1].replace(/^"|"$/g, "") : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function readGoFunc(text, root) {
|
||||
const lines = text.split(/\r?\n/).map((l) => l.trim());
|
||||
if (!lines.some((l) => GO_LINE.test(l))) return null;
|
||||
const mod = goModule(root);
|
||||
const groups = new Map();
|
||||
let total = null;
|
||||
for (const line of lines) {
|
||||
const t = line.match(GO_TOTAL);
|
||||
if (t) {
|
||||
total = { lines: null, hit: null, pct: pct1(Number(t[1])) };
|
||||
continue;
|
||||
}
|
||||
const m = line.match(GO_LINE);
|
||||
if (!m) continue;
|
||||
let file = slash(m[1]);
|
||||
if (mod && file.startsWith(`${mod}/`)) file = file.slice(mod.length + 1);
|
||||
else file = relTo(root, m[1]);
|
||||
(groups.get(file) || groups.set(file, []).get(file)).push(Number(m[2]));
|
||||
}
|
||||
const files = [...groups].map(([file, pcts]) => ({ file, lines: null, hit: null, pct: pct1(pcts.reduce((s, p) => s + p, 0) / pcts.length) }));
|
||||
files.sort(byPath);
|
||||
return { files, total };
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ main */
|
||||
|
||||
run(USAGE, async (argv) => {
|
||||
const args = parseArgs(argv, { values: ["lcov", "go-func", "root"] });
|
||||
const [cmd, ...extra] = args._;
|
||||
if (!cmd) fail(EXIT.USAGE, "missing-command", "A subcommand is required: read.", "Run with --help for usage.");
|
||||
if (cmd !== "read") fail(EXIT.USAGE, "unknown-command", `Unknown subcommand "${cmd}".`, "Use: read.");
|
||||
if (extra.length) fail(EXIT.USAGE, "stray-argument", `Unexpected argument(s): ${extra.join(" ")}.`, "Run with --help for usage.");
|
||||
if (!args.lcov === !args["go-func"]) fail(EXIT.USAGE, "one-format", "Give exactly one of --lcov <file> or --go-func <file>.", "Run with --help for usage.");
|
||||
const format = args.lcov ? "lcov" : "go-func";
|
||||
const file = args.lcov || args["go-func"];
|
||||
const rootArg = args.root || process.cwd();
|
||||
const root = isAbs(slash(rootArg)) ? rootArg : path.resolve(rootArg);
|
||||
let text;
|
||||
try {
|
||||
text = fs.readFileSync(file, "utf8");
|
||||
} catch {
|
||||
fail(EXIT.NOT_FOUND, "no-file", `Cannot read ${file}.`, "Run the coverage command first, then pass the file it wrote.");
|
||||
}
|
||||
const read = format === "lcov" ? readLcov(text, root) : readGoFunc(text, root);
|
||||
if (!read) {
|
||||
fail(
|
||||
EXIT.INVALID,
|
||||
"unreadable-format",
|
||||
`${file} is not ${format === "lcov" ? "lcov output (no SF: lines)" : "go tool cover -func output (no .go: lines)"}.`,
|
||||
"Check the coverage command's reporter writes lcov, or pass go tool cover -func output with --go-func."
|
||||
);
|
||||
}
|
||||
out({ ok: true, format, ...read });
|
||||
});
|
||||
@@ -0,0 +1,201 @@
|
||||
# 🧪 TEST MODE
|
||||
|
||||
Start all TEST MODE responses with '🧪 [TEST]'
|
||||
|
||||
## Role
|
||||
|
||||
Finds code no test covers and writes the missing tests. Asks where to look, finds the gaps, shows a test plan in the project's own style, writes unit and integration tests and runs them with the project's runner. **Never changes source code**: a test that exposes a real bug is handed to Diagnose, never "fixed" by editing the code under test. **Never reads, edits or ticks a spec's phase files**, and writes under `specs/` only when escalating an oversized job to Plan. No browser or end-to-end tests.
|
||||
|
||||
## Interface
|
||||
|
||||
The FIRST thing you do, before anything else in this file, before reading the code: ask **web console** (browser page, suggested) or **terminal**? Console → run `node "<D>/console.mjs" open --workflow test` before reading (<D>: references/web-console/ beside this SKILL.md (~/.agents/skills/plan2code-test/references/web-console/ globally) or the dir in ~/.plan2code/console/console-dir), then read <D>/console.md and <D>/notes/test.md. Every question, the plan and the results go through it. Switchable anytime. If the argument already says which (`--web` or `Use the web console for this session.`), take it and do not ask; drop the flag. Launched by the dashboard? Its session is already open: resume it (console-launches.md), then Project Context.
|
||||
|
||||
## Project Context
|
||||
|
||||
Read `./AGENTS.md` when it exists: its commands, its `## Test map` and anything it says about tests, helpers or slow suites. Test still works without one: the scripts find the project's runners from its config files, and nothing here needs Plan2Code's specs.
|
||||
|
||||
## Scripts
|
||||
|
||||
`<S>` is `scripts/` beside this SKILL.md (`~/.agents/skills/plan2code-test/scripts/` globally). Run from the project root. Each prints one JSON object; on a non-zero exit read `message` and do what `next` says.
|
||||
|
||||
- `node "<S>/test-map.mjs" read`: the project test map (`found`, `rows` of `area`, `paths`, `run`, `shared`, and `problems`). `write --rows <file.json>` saves one, only on a yes.
|
||||
- `node "<S>/test-commands.mjs" discover`: the project's commands from its config files: `suite`, `runners` (`cmd`, `cwd`, `covers`), `checks`, `coverage` (`runner`, `cmd`, some with an `<out>` placeholder, `cwd`, `reads`: `lcov` or `go-func`), `builtin` (the language's own runner, only when nothing else was found).
|
||||
- `node "<S>/test-match.mjs" gaps --scope branch|path|all [--path <p>]`: source files no test covers (`file`, `area`, `runner`, `commits90d`, `lastTouched`), ranked newest first, then by recent commits; `capped` when it stopped at 2,000 files.
|
||||
- `node "<S>/test-match.mjs" nearest --file <f>`: up to three existing test files to read for the project's style.
|
||||
- `node "<S>/run-check.mjs" --cmd <c> --cwd <d> --timeout <s> --log <file>`: runs one command and prints `outcome` (`passed`, `failed`, `timeout`, `not-started` with a `reason`), `exit`, `seconds` and `tail`.
|
||||
- `node "<S>/coverage.mjs" read --lcov <file> | --go-func <file>`: coverage output as per-file `lines`, `hit` and `pct`, plus `total`.
|
||||
- `node "<S>/review-scope.mjs" [--base <branch>]`: the branch's changed files, when you need the list itself (`gaps --scope branch` already reads it).
|
||||
|
||||
## References
|
||||
|
||||
- `references/test-runs.md`: which tests cover a file, and what counts as shared ground.
|
||||
- `references/building-habits.md`: how to write and run tests, and what to do when one fails unexpectedly.
|
||||
- `references/helper-strength.md`: helper strength and effort.
|
||||
|
||||
## Rules
|
||||
|
||||
- Follow `./AGENTS.md` when it exists.
|
||||
- **Never change source code.** Write test files, and test helpers or fixtures only inside the project's test folders. The one config change allowed is adding the built-in runner's command (Step 2), on a yes.
|
||||
- **Never read, edit or tick a spec's phase files.** Write under `specs/` only for an escalation PLAN-DRAFT.
|
||||
- **Never install anything**: no runner, no coverage tool, no package, no service.
|
||||
- **Nothing runs before the person confirms it.** A command found by a script is shown before it runs; coverage is offered, never run silently.
|
||||
- Unit and integration tests only: no browser, end-to-end or load tests.
|
||||
- Follow the project's own style: its folders, file names, runner, helpers and assertions. Never add a test framework.
|
||||
- **Record honestly.** Say which tests ran and which did not; never report a run that did not happen.
|
||||
- Never run `git commit`, `git push` or `git add`: the person commits the new tests.
|
||||
- Plain words: name the file, the runner and the command.
|
||||
|
||||
## Helpers
|
||||
|
||||
When your tool can start helpers (subagents) and they are not switched off for this run (on the web console a `Subagents:` block says which, console-subagents.md): helpers may read the nearest tests and runner configs per runner group (Step 4). Keep the gaps, the plan, the style block, every question and the writing of tests with you. Light strength, low effort, per references/helper-strength.md. No helpers? Do the same work yourself.
|
||||
|
||||
## Process
|
||||
|
||||
### Step 1: Scope
|
||||
|
||||
Every run, ask where to look, on one card:
|
||||
|
||||
1. **The branch's changes**: files changed on this branch (`--scope branch`).
|
||||
2. **A named area**: a folder or file the person names; ask for it as a follow-up (`--scope path --path <p>`).
|
||||
3. **The whole project** (`--scope all`).
|
||||
|
||||
### Step 2: Runner
|
||||
|
||||
Run `test-map.mjs read` and `test-commands.mjs discover`. With a map (`found: true`), its rows are the project's runners; mention any `problems` in one line.
|
||||
|
||||
- **No map:** list every command `discover` found with the folders each covers (`suite`, each of `runners` with its `cwd` and `covers`), and confirm them on one card before anything runs. A correction from the person replaces what the script found.
|
||||
- **No runner at all, `builtin` set:** offer that runner, naming it and the command it would add (for Node, a `"test": "node --test"` script in `package.json`; for Python `python -m unittest`, Go `go test ./...`, Rust `cargo test`). Go ahead only on a yes; on a yes add that one command and nothing else.
|
||||
- **No runner and no `builtin`:** stop. Say the project has no test runner and none built into its language, so there is nothing to write tests for here; end the run.
|
||||
|
||||
### Step 3: Gaps
|
||||
|
||||
Run `test-match.mjs gaps --scope <branch|path|all>` (with `--path <p>` for a named area). `capped: true` → say only the first 2,000 source files were read.
|
||||
|
||||
**Coverage, only when the project already has it.** When `discover` lists a `coverage` entry for a runner in scope, offer it on one card naming the command and what it covers. Never run it without a yes.
|
||||
|
||||
- **Yes:** when `cmd` has an `<out>` placeholder, fill it with a file in the session folder (`open` printed it; in the terminal, the OS temp folder). Run it with `run-check.mjs` in its `cwd`, with a `--log` file. Then read the output with `coverage.mjs read`, per `reads`: `--lcov <out>` when the command wrote to `<out>`, else `--lcov <cwd>/coverage/lcov.info` (Jest's and Vitest's default); `--go-func <log>` for Go, whose `go tool cover -func` table is printed into the run's log. Files at 0% or under 50% that matching called covered become extra gaps, method `coverage`. A coverage run that fails or times out, or a `coverage.mjs read` that fails (exit 3 or 4, as for .NET's Cobertura output): say so in one line, and matching alone continues.
|
||||
- **No:** matching alone continues, and the plan says coverage was skipped.
|
||||
|
||||
Every gap carries the method that found it (`matching` or `coverage`), ranked as `gaps` ranks them; coverage gaps follow the matching ones, lowest percent first. No gaps at all → say every source file in scope has a test, offer the test map (Step 8) when the run had none, and end.
|
||||
|
||||
### Step 3b: Size check
|
||||
|
||||
Count the source files to cover, the new test files the plan would add, and the runners involved. When any one passes its limit, post one card naming the counts:
|
||||
|
||||
> This is a big job for one run:
|
||||
> - Source files: [X]/8
|
||||
> - New test files: [X]/8
|
||||
> - Runners: [X]/2
|
||||
>
|
||||
> 1. **Continue**: a lighter plan this run only, the top 8 gaps by rank
|
||||
> 2. **Escalate**: write a PLAN-DRAFT and plan it properly
|
||||
|
||||
**Continue:** keep the top 8 gaps by rank; name the rest as left for a later run.
|
||||
|
||||
**Escalate:**
|
||||
1. Ask for a kebab-case name (e.g. `billing-tests`).
|
||||
2. Write `specs/<name>/PLAN-DRAFT-<YYYYMMDD>.md`:
|
||||
|
||||
```markdown
|
||||
# PLAN-DRAFT: [Name]
|
||||
|
||||
**Status:** Escalated from Test - Resume at Phase 2
|
||||
**Created:** [YYYYMMDD]
|
||||
**Source:** Test escalation
|
||||
|
||||
## 1. Executive Summary
|
||||
Write the missing tests for [scope]: [N] source files with no test, across [runners].
|
||||
|
||||
## 2. Requirements (Gathered)
|
||||
|
||||
### Functional Requirements
|
||||
- FR-1: Tests for `[file]` ([method], [area], [runner])
|
||||
- FR-2: ...
|
||||
|
||||
### Non-Functional Requirements
|
||||
- NFR-1: Tests follow the project's own style; no source changes; nothing installed
|
||||
|
||||
### Testing Strategy
|
||||
[The "How this project writes tests" notes gathered so far, per runner]
|
||||
|
||||
## 3. Scope Assessment
|
||||
| Indicator | Value | Threshold |
|
||||
|-----------|-------|-----------|
|
||||
| Source files | X | 8 |
|
||||
| New test files | X | 8 |
|
||||
| Runners | X | 2 |
|
||||
|
||||
**Escalation reason:** [the limits passed]
|
||||
|
||||
## 4. Context Gathered
|
||||
[Commands confirmed, coverage run or skipped, nearest tests read]
|
||||
|
||||
---
|
||||
**Next:** New conversation with `/plan2code-1-plan --web`, attach this file.
|
||||
Resume at Phase 2 (System Context).
|
||||
```
|
||||
|
||||
3. Say: "Created `specs/<name>/PLAN-DRAFT-<date>.md`. Start a new conversation with `/plan2code-1-plan --web` to continue." End the run (Session End, escalated).
|
||||
|
||||
### Step 4: Style
|
||||
|
||||
For each runner in the plan: run `test-match.mjs nearest --file <gap>` for its gaps, read those tests (two or three per runner is enough) and the runner's config. Note:
|
||||
|
||||
- **Folder:** where tests live (beside the source, a `test/` or `tests/` folder, `__tests__/`).
|
||||
- **File naming:** `x.test.js`, `test_x.py`, `x_test.go` and the like.
|
||||
- **Runner and command:** the command that runs one file or folder.
|
||||
- **Helpers reused:** fixtures, factories, setup files, mocks the project already has.
|
||||
- **Assertion style:** `assert`, `expect`, table-driven cases, the describe/it shape.
|
||||
|
||||
No test exists near a gap: use the closest tests for that runner anywhere in the project, and say so.
|
||||
|
||||
### Step 5: Plan
|
||||
|
||||
The plan opens with a **How this project writes tests** block per runner (the five notes above). Then, per runner group, each gap with its method, the test file to add or extend, and the cases, each marked unit or integration. Every gap follows its own area's runner.
|
||||
|
||||
Show it for approval; the person approves or corrects the style and the plan together. A correction to the style changes every test in that group. Nothing is written before they approve.
|
||||
|
||||
### Step 6: Write and run
|
||||
|
||||
Write the tests following `references/building-habits.md`, one runner group at a time, matching the approved style. Reuse the project's helpers; add a new helper only inside the test folders, and only when two or more new tests need it.
|
||||
|
||||
Run each group's new tests with `run-check.mjs`: the map row's `run`, or the runner command narrowed to the new files when the runner allows it (the whole group's command when it does not). The timeout is 600 seconds by default, longer when `AGENTS.md` says a suite is slow. On the console the log goes in `<session>/runs/<n>.log`; in the terminal, the OS temp folder. Before each run post one `activity` line ("Running the new launcher tests").
|
||||
|
||||
A new test that fails: read the failure.
|
||||
- **The test is wrong** (a wrong expectation, a missing setup, a typo): fix the test and run again.
|
||||
- **The source is wrong** (the test asks for what the code clearly means to do, and the code does not): Step 7.
|
||||
- `timeout` or `not-started`: say so with its `reason` and the end of its `tail`; never call it passed.
|
||||
|
||||
Never weaken, skip or delete a test to make it pass.
|
||||
|
||||
### Step 7: Real bug
|
||||
|
||||
A new test that fails because the source is wrong is never "fixed" by changing the source. Ask, per bug:
|
||||
|
||||
> `[test file]` › `[case]` fails because `[source file]` [does X instead of Y]. Keep it as the reproduction and hand it to Diagnose, or remove it?
|
||||
|
||||
- **Keep:** leave the failing test in place; name the file and the failing case in the finish, with `/plan2code-diagnose` as the next step.
|
||||
- **Remove:** delete that case (or the file when it held only that case) and say so.
|
||||
|
||||
### Step 8: Test map offer
|
||||
|
||||
When the run had no map, or found runners or areas the map lacks, offer to write or update it (one table under `## Test map` in `AGENTS.md`, columns `Area`, `Paths`, `Run`, `Shared`). On a yes, write the rows to a JSON file in the session folder (or the OS temp folder) and run `test-map.mjs write --rows <file>`. Never without a yes.
|
||||
|
||||
## Session End
|
||||
|
||||
Work summary: the scope, how gaps were found (matching, and coverage run or skipped), the tests added (file, cases, unit or integration), each run's outcome, any bug kept for Diagnose, any gap left for later, and any file written outside the tests (the built-in runner's command, the test map, a PLAN-DRAFT).
|
||||
|
||||
**Next step**, as the closing line:
|
||||
- A bug was kept: "NEXT STEP (NEW conversation): `/plan2code-diagnose` with `[test file]` › `[case]` as the reproduction."
|
||||
- Escalated: "NEXT STEP (NEW conversation): `/plan2code-1-plan --web` with `specs/<name>/PLAN-DRAFT-<date>.md`."
|
||||
- Otherwise: "Commit the new tests with `/plan2code-git`."
|
||||
|
||||
On the console, post `finish` with the tests added and their results in `headline`, `"dashboard": true`, and `command` `/plan2code-diagnose` when a bug was kept (`/plan2code-1-plan` when escalated), else no `command`. No `commit` field: `body` says to commit the new tests with `/plan2code-git`.
|
||||
|
||||
```
|
||||
⋅
|
||||
╭───╮
|
||||
╲│ ★ │╱
|
||||
│ ◡ │ Tests written!
|
||||
╰┬─┬╯
|
||||
```
|
||||
+2
-1
@@ -68,6 +68,7 @@ Ground truth for menu notes and Ask-tab answers. For anything beyond this table,
|
||||
| xray | the codebase, `git` history, `gh` when present | an answer; `ARCHITECTURE-BRIEF-<date>.md` or `XRAY-<area>-<date>.md` when asked |
|
||||
| diagnose | the bug, the codebase, `references/building-habits.md` | `DIAGNOSIS-<date>.md`; no code changes |
|
||||
| pr-prep | git diff and status, the `AGENTS.md` test map, the project's config files, the PR template | the page report and description; `PR-READINESS-<date>.md` on a yes; the `AGENTS.md` test map on a yes; no commits, no push |
|
||||
| test | the codebase, the `AGENTS.md` test map, nearby tests, coverage output when offered | new test files; the `AGENTS.md` test map on a yes; `PLAN-DRAFT-<date>.md` when escalated; no source changes |
|
||||
|
||||
## A pick arrives
|
||||
|
||||
@@ -103,7 +104,7 @@ If `skill` is not in the table below, say so on the page and stay the dashboard.
|
||||
| plan2code-quick-task | quick-task | | plan2code-handoff | handoff |
|
||||
| plan2code-git | git | | plan2code-changelog | changelog |
|
||||
| plan2code-xray | xray | | plan2code-diagnose | diagnose |
|
||||
| plan2code-pr-prep | pr-prep | | | |
|
||||
| plan2code-pr-prep | pr-prep | | plan2code-test | test |
|
||||
|
||||
## A pick-up arrives
|
||||
|
||||
|
||||
@@ -828,7 +828,7 @@ async function cmdCheck(args) {
|
||||
checkReport("check", { spec: spec.rel, checked: names.map(at) }, problems);
|
||||
}
|
||||
|
||||
const DRAFT_STATUSES = ["Draft", "Phase 3 Complete - Resume at Phase 4", "Escalated from Quick Task - Resume at Phase 2", "Complete"];
|
||||
const DRAFT_STATUSES = ["Draft", "Phase 3 Complete - Resume at Phase 4", "Escalated from Quick Task - Resume at Phase 2", "Escalated from Test - Resume at Phase 2", "Complete"];
|
||||
// The headings Document reads out of a Complete draft.
|
||||
const DRAFT_SECTIONS = [
|
||||
{ name: "## 1. Executive Summary", re: /^##\s+1\.\s+Executive Summary\b/im },
|
||||
|
||||
@@ -6,7 +6,7 @@ A local page where the person answers your questions, reads your drafts and appr
|
||||
|
||||
## Start
|
||||
|
||||
`node "<CONSOLE>" open --workflow <w>` (add `--spec specs/<idea>` when known). `<w>` is one of `dashboard`, `init`, `init-update`, `pathfinder`, `quick-task`, `plan`, `revise-plan`, `document`, `implement`, `implement-review`, `review`, `finalize`, `handoff`, `git`, `changelog`, `xray`, `diagnose`, `pr-prep`. Launched from the dashboard? The session is open: run the `resume` command the launch carried instead.
|
||||
`node "<CONSOLE>" open --workflow <w>` (add `--spec specs/<idea>` when known). `<w>` is one of `dashboard`, `init`, `init-update`, `pathfinder`, `quick-task`, `plan`, `revise-plan`, `document`, `implement`, `implement-review`, `review`, `finalize`, `handoff`, `git`, `changelog`, `xray`, `diagnose`, `pr-prep`, `test`. Launched from the dashboard? The session is open: run the `resume` command the launch carried instead.
|
||||
|
||||
Keep `sid`: every later command takes `--session <sid>`. `open` failing: carry on in the terminal. When `open` adds `remote` and a `note`, give the link, ask whether it opened, and move to the terminal if not. Tell the person the link (with `"inApp":true`, never print it: only how many questions are waiting) and end every terminal message with the latest `terminalLine`, verbatim.
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
# Test
|
||||
|
||||
## Scope
|
||||
|
||||
Every run, one `choice`, `--wait`:
|
||||
|
||||
```jsonc
|
||||
{"title":"Write missing tests","headline":{"stage":"Scope","cleared":0,"total":5},"items":[{"id":"scope","kind":"choice","title":"Where to look","allowOther":false,"body":"Which code should I look for missing tests in?","options":[{"text":"This branch's changes","recommended":true},{"text":"A folder or file","detail":"You name it next."},{"text":"The whole project"}]}]}
|
||||
```
|
||||
|
||||
"A folder or file" gets a follow-up `text`, `--wait`: `{"id":"scope-path","kind":"text","title":"Which folder","body":"Which folder or file should I look in?","placeholder":"src/billing"}`.
|
||||
|
||||
## Commands and the built-in runner
|
||||
|
||||
With no test map: one `confirm` listing each command found and the folders it covers, `--wait`, before anything runs. A "Not right" answer carries the corrections in its note; with none, ask for them as a `text` card:
|
||||
|
||||
```jsonc
|
||||
{"id":"commands","kind":"confirm","title":"Commands found","body":"| Command | Folder | Covers |\n| --- | --- | --- |\n| `npm test` | . | everything |\n\nWrite and run tests with these?","yesLabel":"Use these","noLabel":"Not right"}
|
||||
```
|
||||
|
||||
No runner at all and a `builtin` found: one `confirm` naming the runner and the command it adds, `--wait`: `{"id":"builtin","kind":"confirm","title":"No test runner","body":"This project has no test runner. Node has one built in: I would add `\"test\": \"node --test\"` to `package.json` and nothing else. Use it?","yesLabel":"Add it","noLabel":"No"}`. No runner and no `builtin`: no card; the finish says why nothing was written.
|
||||
|
||||
## Coverage
|
||||
|
||||
Only when `discover` lists a `coverage` entry for a runner in scope. One `confirm`, `--wait`, naming the command and what it covers; never run without a yes:
|
||||
|
||||
```jsonc
|
||||
{"headline":{"stage":"Gaps","cleared":2},"items":[{"id":"coverage","kind":"confirm","title":"Run coverage","body":"This project already has coverage: `npx jest --coverage --coverageReporters=lcov` in `.` covers every Jest test. Run it to find files the tests barely touch? Without it I match files to tests by name, folder and imports only.","yesLabel":"Run it","noLabel":"Skip it"}]}
|
||||
```
|
||||
|
||||
The output file goes in the `session` folder `open` printed.
|
||||
|
||||
## Size
|
||||
|
||||
Only past a limit (8 source files, 8 new test files, 2 runners). One `choice`, `--wait`, the counts in `body`:
|
||||
|
||||
```jsonc
|
||||
{"id":"size","kind":"choice","title":"A big job","allowOther":false,"body":"- Source files: 14/8\n- New test files: 11/8\n- Runners: 1/2\n\nContinue with the top 8 gaps this run, or write a plan draft and plan it properly?","options":[{"text":"Continue","detail":"The top 8 gaps by rank, this run only.","recommended":true},{"text":"Escalate","detail":"Writes a PLAN-DRAFT for Plan."}]}
|
||||
```
|
||||
|
||||
Escalate: a `text` card for the kebab-case name (`pattern` `^[a-z0-9]+(-[a-z0-9]+)*$`, `patternHint` "kebab-case, like billing-tests"), then the finish below.
|
||||
|
||||
## The plan
|
||||
|
||||
Doc `plan`: one `md` block per runner group (`id` `group-1`, `group-2` ...), each opening with its "How this project writes tests" notes, then its gaps (method, test file, cases marked unit or integration). Then one `review` over it, `--wait`:
|
||||
|
||||
```jsonc
|
||||
{"headline":{"stage":"Plan","cleared":3},"docs":[{"id":"plan","title":"Test plan","blocks":[{"id":"group-1","md":"## node --test\n\n### How this project writes tests\n\n- Folder: `scripts/`\n- ...\n\n### Gaps\n\n| File | Found by | Test file | Cases |\n| --- | --- | --- | --- |\n| `src/a.js` | matching | `scripts/test-a.mjs` (new) | unit: ... |"}]}],"items":[{"id":"plan-ok","kind":"review","title":"Approve the plan","doc":"plan","body":"Check the style notes and the plan together. Nothing is written until you approve.","verdicts":[{"id":"approve","label":"Write these tests"},{"id":"changes","label":"I want changes"}],"nothingYet":"Nothing is written until you approve."}]}
|
||||
```
|
||||
|
||||
`changes`: revise the doc, reopen the item with a `thread` reply.
|
||||
|
||||
## Writing and running
|
||||
|
||||
One progress post per runner group's run, no `--wait`, with `quietMinutes` sized to its timeout (600 s is 10 minutes, plus a margin):
|
||||
|
||||
```jsonc
|
||||
{"headline":{"stage":"Running","cleared":4},"agent":{"status":"working","activity":"Running the new launcher tests","quietMinutes":12}}
|
||||
```
|
||||
|
||||
Logs go in `<session>/runs/<n>.log`. Run the `chat` check between runs, as a build does.
|
||||
|
||||
## A real bug
|
||||
|
||||
Per bug, one `confirm`, `--wait`: `{"id":"bug-1","kind":"confirm","title":"Found a bug","body":"`scripts/test-a.mjs` › *rounds totals* fails because `src/a.js` truncates instead of rounding. Keep the test as the reproduction for Diagnose, or remove it?","yesLabel":"Keep it","noLabel":"Remove it"}`.
|
||||
|
||||
## Test map
|
||||
|
||||
`confirm`, `--wait`: `title` "Save a test map", the rows as a table in `body`, `yesLabel` "Save it", `noLabel` "No".
|
||||
|
||||
## The finish
|
||||
|
||||
`headline` the tests added and their results ("6 tests added, all passing"); `body` the summary (scope, coverage run or skipped, files written, gaps left), ending "Commit the new tests with `/plan2code-git`."; `"dashboard":true`; no `commit`. `command` `/plan2code-diagnose` when a bug was kept (its file and case in `body`), `/plan2code-1-plan` when escalated (the PLAN-DRAFT's path in `body`), else none.
|
||||
|
||||
A stop before anything was written: `body` says no tests were written, `"command":"/plan2code-test"`.
|
||||
@@ -428,6 +428,12 @@
|
||||
<path d="M9 2.5h6a1 1 0 0 1 1 1V5a1 1 0 0 1-1 1H9a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1z" />
|
||||
<path d="m9 13.5 2 2 4-4.5" />
|
||||
</symbol>
|
||||
<!-- Write missing tests: a test tube. -->
|
||||
<symbol id="ci-test" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M9 3h6" />
|
||||
<path d="M10 3v14.5a2 2 0 0 0 4 0V3" />
|
||||
<path d="M10 12h4" />
|
||||
</symbol>
|
||||
<!-- Changelog: a version tag. -->
|
||||
<symbol id="ci-changelog" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M3 4a1 1 0 0 1 1-1h7.6a2 2 0 0 1 1.4.6l7.4 7.4a2 2 0 0 1 0 2.8l-5.6 5.6a2 2 0 0 1-2.8 0L4.6 12a2 2 0 0 1-.6-1.4z" />
|
||||
@@ -866,6 +872,33 @@
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
<!-- Test: writing the missing tests. He holds up a test tube, bubbles
|
||||
rise through its liquid and a star bubble floats out of the top,
|
||||
his star looking up after it before the next one forms. -->
|
||||
<svg class="pose pose-test" data-pose="test" viewBox="0 4 240 216" aria-hidden="true" focusable="false">
|
||||
<ellipse class="shadow" cx="126" cy="198" rx="44" ry="5" />
|
||||
<g class="bob">
|
||||
<g class="ts-tube">
|
||||
<path class="ac" d="M189 116 L189 146 A7 7 0 0 0 203 146 L203 116 Z" />
|
||||
<circle class="ts-bub ts-b1" cx="194" cy="146" r="2" />
|
||||
<circle class="ts-bub ts-b2" cx="199" cy="144" r="1.6" />
|
||||
<circle class="ts-bub ts-b3" cx="196" cy="148" r="1.4" />
|
||||
<path class="lt" d="M186 76 L186 146 A10 10 0 0 0 206 146 L206 76" />
|
||||
<line class="lt" x1="181" y1="76" x2="211" y2="76" />
|
||||
<g class="ts-star"><path class="ac" transform="translate(196 60) scale(0.45) translate(-126 -99)" d="M126 86 L129.64 94.98 L139.31 95.67 L131.9 101.92 L134.23 111.33 L126 106.2 L117.77 111.33 L120.1 101.92 L112.69 95.67 L122.36 94.98 Z" /></g>
|
||||
</g>
|
||||
<g transform="translate(-14 0)">
|
||||
<rect class="fl foot f1" x="94" y="179" width="20" height="10" rx="5" />
|
||||
<rect class="fl foot f2" x="126" y="179" width="20" height="10" rx="5" />
|
||||
<rect class="sh" x="80" y="72" width="80" height="108" rx="16" />
|
||||
<path class="ln" d="M80 126 L66 150" /><circle class="fl" cx="66" cy="150" r="5.5" />
|
||||
<g class="ts-look"><path class="ey blink" d="M126 86 L129.64 94.98 L139.31 95.67 L131.9 101.92 L134.23 111.33 L126 106.2 L117.77 111.33 L120.1 101.92 L112.69 95.67 L122.36 94.98 Z" /></g>
|
||||
<path class="es" d="M110 120 Q122 129 134 120" />
|
||||
<line class="ln" x1="160" y1="126" x2="198" y2="134" />
|
||||
<circle class="fl" cx="200" cy="134" r="5.5" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
<!-- Agent setup: waving hello at a terminal window, its prompt waiting
|
||||
for the command line that brings an agent. -->
|
||||
<svg class="pose pose-setup" data-pose="setup" viewBox="0 4 240 216" aria-hidden="true" focusable="false">
|
||||
|
||||
@@ -404,6 +404,28 @@ export const SKILLS = Object.freeze([
|
||||
"Before you open a pull request. PR Prep reads what changed on the branch and picks the checks that cover it from the project's test map (or from its config files when there is no map), each with a reason. You untick what to skip, then it runs the rest and says Ready, Ready with notes or Not ready. It writes a PR description to copy, following the repo's template when there is one, and gives the link to open the PR. It never commits, pushes or opens the PR for you.",
|
||||
},
|
||||
}),
|
||||
skill({
|
||||
skill: "plan2code-test",
|
||||
workflow: "test",
|
||||
label: "Testing",
|
||||
name: "Test",
|
||||
pose: "test",
|
||||
builds: false, phased: false, metered: true, templates: false,
|
||||
weight: 1, started: "Test started", ran: "Test run", resume: null,
|
||||
subagents: "Use helpers to read the nearest tests and runner configs for each runner group. Keep the gaps, the plan, the style block, every question and the writing of tests with you. Light strength, low effort.",
|
||||
states: "any",
|
||||
greyed: null,
|
||||
card: {
|
||||
group: "extra",
|
||||
chip: "Utility",
|
||||
title: "Write missing tests",
|
||||
icon: "test",
|
||||
blurb: "Finds code with no tests and writes them in your project's own style.",
|
||||
help: "Finds untested files, shows a test plan in the project's style, then writes and runs unit and integration tests.",
|
||||
about:
|
||||
"When parts of the code have no tests. Test asks where to look (the branch's changes, one folder or the whole project) and finds the files no test covers, and offers a real coverage run when the project already has a coverage tool. It shows a plan that opens with how this project writes tests, so the new tests match the old ones, then writes and runs unit and integration tests. It never changes source code: a test that finds a real bug is handed to Diagnose.",
|
||||
},
|
||||
}),
|
||||
skill({
|
||||
skill: "plan2code-changelog",
|
||||
workflow: "changelog",
|
||||
|
||||
@@ -449,6 +449,30 @@
|
||||
50%, 88% { transform: translate(4px, 2px); }
|
||||
}
|
||||
|
||||
/* Test -- bubbles rise through the tube's liquid, then a star bubble floats
|
||||
out of the top and fades; his star looks up after it. */
|
||||
.pose .ts-bub { fill: var(--panel-2); }
|
||||
.pose .ts-b1 { animation: ts-rise 2.4s ease-in infinite; }
|
||||
.pose .ts-b2 { animation: ts-rise 2.4s ease-in 0.8s infinite; }
|
||||
.pose .ts-b3 { animation: ts-rise 2.4s ease-in 1.6s infinite; }
|
||||
@keyframes ts-rise {
|
||||
0% { transform: translateY(0); opacity: 0; }
|
||||
15%, 80% { opacity: 1; }
|
||||
100% { transform: translateY(-26px); opacity: 0; }
|
||||
}
|
||||
.pose .ts-star { animation: ts-float 4.8s ease-out infinite; }
|
||||
@keyframes ts-float {
|
||||
0%, 30% { transform: translateY(14px) scale(0.4); opacity: 0; }
|
||||
40% { opacity: 1; }
|
||||
85% { transform: translateY(-26px) scale(1); opacity: 1; }
|
||||
100% { transform: translateY(-34px) scale(1); opacity: 0; }
|
||||
}
|
||||
.pose .ts-look { animation: ts-look 4.8s ease-in-out infinite; }
|
||||
@keyframes ts-look {
|
||||
0%, 30%, 100% { transform: translate(4px, 0); }
|
||||
60%, 85% { transform: translate(4px, -4px); }
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.dash { padding-top: 0; }
|
||||
.launch-stage { height: 140px; }
|
||||
|
||||
Reference in new issue
Block a user