From 17f98e62b535202e5f481d1d55aa92024bbb9eb3 Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Thu, 5 Nov 2026 11:39:04 -0800 Subject: [PATCH] Let coverage read take a runner folder so relative lcov paths resolve, and fix Handoff's script path AI Assisted --- scripts/test-script-coverage.mjs | 11 +++++++++++ src/plan2code-handoff.md | 2 +- src/plan2code-test-scripts/coverage.mjs | 13 ++++++++++--- src/plan2code-test.md | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/scripts/test-script-coverage.mjs b/scripts/test-script-coverage.mjs index 72d0850..02cd2d5 100644 --- a/scripts/test-script-coverage.mjs +++ b/scripts/test-script-coverage.mjs @@ -168,3 +168,14 @@ test("coverage read: exactly one format flag is required", () => { assert.equal(C(dir, "read", "--lcov", "a", "--go-func", "b").code, 2); assert.equal(C(dir).code, 2); }); + +test("coverage read --lcov --cwd: a runner's relative paths get its folder in front", () => { + const dir = tmp("cov-cwd"); + write(dir, "lcov.info", "SF:src/x.ts\nDA:1,1\nLF:1\nLH:1\nend_of_record\nSF:D:/elsewhere/y.ts\nDA:1,0\nLF:1\nLH:0\nend_of_record\n"); + const r = C(dir, "read", "--lcov", "lcov.info", "--cwd", "./packages/api/"); + assert.equal(r.code, 0, r.stderr); + assert.deepEqual( + r.json.files.map((f) => f.file), + ["D:/elsewhere/y.ts", "packages/api/src/x.ts"] + ); +}); diff --git a/src/plan2code-handoff.md b/src/plan2code-handoff.md index 4ef4f21..cb668ed 100644 --- a/src/plan2code-handoff.md +++ b/src/plan2code-handoff.md @@ -52,7 +52,7 @@ The dashboard lists the handoff for this checkout until it is picked up, and old `specs/` is gitignored — Glob/Grep and file search silently skip it. If the conversation worked inside `specs//`, confirm the exact state before -writing with `node "/specs.mjs" status specs/`, which reads the disk: +writing with `node "/specs.mjs" status specs/` (`` is `scripts/` beside this SKILL.md: `~/.agents/skills/plan2code-handoff/scripts/` globally), which reads the disk: - Which `phase-X.md` is in progress, and which of its tasks are still open (each phase's `tasks` and `openTasks`: checkboxes are ground truth, not the diff --git a/src/plan2code-test-scripts/coverage.mjs b/src/plan2code-test-scripts/coverage.mjs index c993562..03fa0e4 100644 --- a/src/plan2code-test-scripts/coverage.mjs +++ b/src/plan2code-test-scripts/coverage.mjs @@ -14,7 +14,7 @@ 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 [--root ] + node coverage.mjs read --lcov [--root ] [--cwd ] node coverage.mjs read --go-func [--root ] Prints { ok, format, files: [{ file, lines, hit, pct }], total }, files sorted by path, pct with one decimal. @@ -22,7 +22,9 @@ coverage.mjs: per-file coverage from a coverage tool's output. JSON on stdout. 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 + an absolute path outside the root is kept as given. A relative + SF: path is relative to the runner's folder: pass it as --cwd + (relative to the root) to get project-relative paths. total sums every file. go-func "/.go:: %" lines, grouped by file: pct is the mean of the file's functions, @@ -149,7 +151,7 @@ function readGoFunc(text, root) { /* ------------------------------------------------------------------ main */ async function main(argv) { - const args = parseArgs(argv, { values: ["lcov", "go-func", "root"] }); + const args = parseArgs(argv, { values: ["lcov", "go-func", "root", "cwd"] }); 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."); @@ -166,6 +168,11 @@ async function main(argv) { 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); + const prefix = path.posix.normalize(slash(args.cwd || ".")).replace(/\/+$/, "").replace(/^\.$/, ""); + if (read && format === "lcov" && prefix) { + for (const f of read.files) if (!isAbs(f.file)) f.file = path.posix.join(prefix, f.file); + read.files.sort(byPath); + } if (!read) { fail( EXIT.INVALID, diff --git a/src/plan2code-test.md b/src/plan2code-test.md index 55d231d..cfb59e1 100644 --- a/src/plan2code-test.md +++ b/src/plan2code-test.md @@ -73,7 +73,7 @@ Run `test-match.mjs gaps --scope ` (with `--path

` for a nam **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 `` placeholder (already quoted), replace just `` 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 ` when the command wrote to ``, else `--lcov /coverage/lcov.info` (Jest's and Vitest's default); `--go-func ` 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. +- **Yes:** when `cmd` has an `` placeholder (already quoted), replace just `` 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 ` when the command wrote to ``, else `--lcov /coverage/lcov.info` (Jest's and Vitest's default), always with `--cwd ` so its relative paths line up with the project's; `--go-func ` 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.