From 184876b437d329d09d447ef6e47fddbf782d4583 Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Fri, 6 Nov 2026 13:46:43 -0800 Subject: [PATCH] Check every file that carries the version, and run it in npm test AI Assisted --- .agents-docs/AGENTS-code-style.md | 2 +- AGENTS.md | 2 +- CHANGELOG.md | 4 +++ package.json | 2 +- scripts/check-versions.mjs | 40 +++++++++++++++++++------- scripts/test-check-versions.mjs | 48 +++++++++++++++++++++++++++++-- 6 files changed, 81 insertions(+), 17 deletions(-) diff --git a/.agents-docs/AGENTS-code-style.md b/.agents-docs/AGENTS-code-style.md index 34f00ec..616ac01 100644 --- a/.agents-docs/AGENTS-code-style.md +++ b/.agents-docs/AGENTS-code-style.md @@ -14,7 +14,7 @@ ## Gotchas / Pitfalls -- **Version sync:** When adding a new version to `CHANGELOG.md`, also update `version.json` and `package.json` (root) to match. `README.md` (the `Version X.Y.Z` line near the top) also carries the version, and `version.json`'s `releaseDate` moves with it. `version.json` is copied into every skill's `references/web-console/` (the console's Help shows it), so after a bump run `npm run build:skills` or `npm test` (`--verify-skills`) fails. The installer displays the version from `version.json` in its header. All three files (`CHANGELOG.md`, `version.json`, `package.json`) must always show the same version number. The desktop app carries it too (`plan2code-app/src-tauri/tauri.conf.json`, `plan2code-app/package.json`, `plan2code-app/src-tauri/Cargo.toml`, and `Cargo.lock`'s `plan2code-app` entry follows the build): `node scripts/check-versions.mjs [--tag vX.Y.Z]` compares all six, and the release workflow runs it before building. It reports a mismatch today because the app is at 3.0.0 while the rest is still 2.x; it is deliberately not part of `npm test`, so bump the app's files with the release that ships v3.0.0. +- **Version sync:** When adding a new version to `CHANGELOG.md`, also update `version.json` and `package.json` (root) to match. `README.md` (the `Version X.Y.Z` line near the top) also carries the version, and `version.json`'s `releaseDate` moves with it. `version.json` is copied into every skill's `references/web-console/` (the console's Help shows it), so after a bump run `npm run build:skills` or `npm test` (`--verify-skills`) fails. The installer displays the version from `version.json` in its header. All three files (`CHANGELOG.md`, `version.json`, `package.json`) must always show the same version number. The desktop app carries it too (under `plan2code-app/`: `package.json`, `package-lock.json` with two lines, `src-tauri/tauri.conf.json`, `src-tauri/Cargo.toml`, `fake-agent/Cargo.toml`, and `Cargo.lock`'s `plan2code-app` and `fake-agent` entries): `node scripts/check-versions.mjs [--tag vX.Y.Z]` compares those, `version.json`, `package.json`, `CHANGELOG.md` and README's line (twelve places in all), `npm test` runs it first on this tree, and the release workflow runs it before building. - **CHANGELOG ordering:** Entries in `CHANGELOG.md` must be in reverse-chronological order โ€” newest version at the top, oldest at the bottom. New entries are always inserted immediately after the file header. - **CHANGELOG house format is not Keep a Changelog:** version headings are `## vX.Y.Z` โ€” with a `v` prefix and **no date**. The release date is recorded only in `version.json`'s `releaseDate`. Category headings carry emoji: `### โœจ Added`, `### ๐Ÿ”ง Changed`, `### ๐Ÿ› Fixed`, `### ๐Ÿ’ฅ Breaking`, `### ๐Ÿ—‘๏ธ Removed`, `### ๐Ÿ“š Documentation`. Older entries contain one-off variants (`๐ŸŽ Added`, `๐Ÿ“ฆ Updated`, `๐Ÿ“ Documentation`, `๐ŸŽ๏ธ Improved`, `๐Ÿงช Testing`) โ€” do not introduce new ones. The `.claude/skills/plan2code-changelog/` skill automates version selection and formatting; use it rather than hand-rolling an entry. - **PowerShell mangles the CHANGELOG emoji:** `Get-Content` / `Select-String` render the `###` heading emoji as `?` under the default Windows console encoding, so a heading audit done that way reports garbage. Read `CHANGELOG.md` with a file-read or grep tool instead. diff --git a/AGENTS.md b/AGENTS.md index 069074a..e1482fb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -100,7 +100,7 @@ When you make a mistake, get corrected, or discover something about this codebas - When a new first-run dialog is added to the web console, set its seen flag in `scripts/capture-screenshots.mjs`'s `looks.json` too: the Welcome dialog once covered the regenerated dashboard screenshots until `welcomeSeen: true` was added. - Import `scripts/skill-script-helpers.mjs` in any test that builds git fixtures for a skill script or `git-repo.mjs`: it scrubs the whole test process's git config, so fixtures, imported modules and spawned scripts agree. Mixed configs broke `git plan switch` once (a global `core.autocrlf=true` checked fixtures out with CRLF the scrubbed script read as changed). It also rebuilds `skills/` and prunes any skill folder `install.js` does not list, so register a new skill in `SOURCE_PROMPTS` before running its `scripts/test-script-.mjs` or the script under test vanishes. - Before deleting a test file that upstream split or removed, diff plan2code's copy against the rebranded upstream base and port the plan2code-only tests: v2.7.0's split of the web console suite would otherwise have dropped seven hardening tests (now in `scripts/test-web-console-hardening.mjs`). -- When a `CHANGELOG.md` heading gets a version number, set the same number in `version.json` (with its `releaseDate`), the root `package.json` and README's `Version X.Y.Z` line in the same change, then run `npm run build:skills`. The changelog skill only touches `package.json`: v2.9.0 nearly shipped with `version.json` at 2.8.1, and README's line sat at 2.6.0 for three releases. +- When a `CHANGELOG.md` heading gets a version number, set the same number in every file that carries it in the same change, then run `npm run build:skills`: `version.json` (with its `releaseDate`), the root `package.json`, README's `Version X.Y.Z` line, and under `plan2code-app/`: `package.json`, `package-lock.json` (two lines), `src-tauri/tauri.conf.json`, `src-tauri/Cargo.toml`, `fake-agent/Cargo.toml` and `Cargo.lock` (the `plan2code-app` and `fake-agent` entries). `node scripts/check-versions.mjs` compares all of them and runs in `npm test`; widen its `SOURCES` when a new file carries the version. The changelog skill only touches `package.json`: v2.9.0 nearly shipped with `version.json` at 2.8.1, and README's line sat at 2.6.0 for three releases. - When a page test (`scripts/test-web-console-page-*.mjs`) fails only on CI or only in a full run, look for a race with a redraw before suspecting the change, and fix the test, not the timeout: read styles and set scrolls through `styleOf()`, `stylesOf()` and `scrollCard()` in `page-test-helpers.mjs` (a card a redraw replaced reads "" for every style and scrolls nothing; `test-web-console-shape.mjs` now fails a raw `locator.evaluate` that does either), and wait for the page to hold what the next step needs before acting (the workspace frame before typing `@`, the notepad's drawn marks, a newly selected tab). Keep `npm test`'s file concurrency under `scripts/node-test.mjs`'s cap of one file per spare core: a flat `--test-concurrency=8` ran 8 browsers on 3 and 4 core runners and failed a different page test on every CI run. On a busy local machine, rerun the failing files alone first; the chat stress test and the session suite's "no submitted frame within 5s" cascade still fail that way under load. - Run `npm test` and `cargo test` from a terminal outside the desktop app, or with `PLAN2CODE_IN_APP`, `PLAN2CODE_APP_TOKEN`, `PLAN2CODE_APP_VERSION`, `PLAN2CODE_APP_ANNOUNCE`, `PLAN2CODE_EMBED_ORIGIN` and `PLAN2CODE_CONSOLE_SID` unset (`env -u ... npm test`): inherited from the app they fail about 34 tests that check behavior outside the app (the update banner, the terminal line, cookies, open's browser launch), and a test console announces itself to the live window. A `cargo test` run mid-build once took the window over that way, then left an agent-less dashboard in it, and the build's question was never seen. The app now ignores sessions outside its console store (`take_announced` in `main.rs`), and the Rust console tests scrub the variables, but the JS suites do not. Before pushing a change under `plan2code-app/`, also run `cargo fmt --check` and `cargo clippy --workspace --all-targets -- -D warnings` there, not only `cargo test`: CI's `app` workflow fails on either, and the Rust code once reached a PR never formatted (20 files) with three clippy errors, one only macOS and Linux could see (see plan2code-app/README.md "Tests"). `loop_driver` tests failing with `never saw ... agent generations` and no `ARGS` line in the output mean `target/debug/fake-agent` is older than its source (a file restored with an old time, so Cargo never rebuilds it): `touch plan2code-app/fake-agent/src/main.rs` and rerun. A stale binary once read as 2 real failures in PR Prep. - Never fix CRLF by hand, one file at a time: run `npm run fix:eol` (`scripts/fix-line-endings.mjs`). Windows Python in text mode, among other tools, writes CRLF into files git keeps as LF; a whole session's edits once came out CRLF and 14 other files were found the same way. It now also runs as `pretest`, in the pre-commit hook and after every agent Write or Edit (see the LF gotcha in Code Style). diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a1f9c9..1babd24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ All notable changes to Plan2Code will be documented in this file. - **web console**: the dashboard has an **AGENTS.md** tab right after Dashboard, shown while the project has an `AGENTS.md`. It reads the file fresh from disk, read-only, and links into `.agents-docs/` open in place with a way back. +### ๐Ÿ”ง Changed + +- **releases**: `npm test` now runs `scripts/check-versions.mjs` first, and that check reads every place that carries the version (README's `Version` line, both `package-lock.json` lines, `fake-agent/Cargo.toml` and both `Cargo.lock` entries as well as the six it read before), so a release that leaves any of them behind fails the tests instead of shipping. + ## v3.0.2 ### โœจ Added diff --git a/package.json b/package.json index 0a0d7d0..5041436 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "fix:eol": "node scripts/fix-line-endings.mjs", "play": "node scripts/play.mjs", "pretest": "node scripts/fix-line-endings.mjs", - "test": "node scripts/validate-char-count.js && node install.js --build-skills && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node scripts/node-test.mjs scripts/test-line-endings.mjs scripts/test-us-english.mjs scripts/test-script-git.mjs scripts/test-git-repo.mjs scripts/test-skill-scripts.mjs scripts/test-script-test-map.mjs scripts/test-script-test-match.mjs scripts/test-script-test-commands.mjs scripts/test-script-run-check.mjs scripts/test-script-pr-prep.mjs scripts/test-script-coverage.mjs scripts/test-script-changelog.mjs scripts/test-web-console-git.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-pointers.mjs scripts/test-console-wire-budgets.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-workspace.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-activities.mjs scripts/test-web-console-activities-rapids.mjs scripts/test-web-console-activities-flock.mjs scripts/test-web-console-activities-bounce.mjs scripts/test-web-console-activities-bounce-game.mjs scripts/test-web-console-activities-ghoul.mjs scripts/test-web-console-activities-ghoul-graveyard.mjs scripts/test-web-console-activities-ghoul-grounds.mjs scripts/test-web-console-activities-ghoul-chapel.mjs scripts/test-web-console-activities-ghoul-sanatorium.mjs scripts/test-web-console-activities-ghoul-village.mjs scripts/test-web-console-activities-ghoul-mine.mjs scripts/test-web-console-activities-ghoul-carnival.mjs scripts/test-web-console-activities-ghoul-frozen.mjs scripts/test-web-console-activities-ghoul-bog.mjs scripts/test-web-console-activities-ghoul-lantern.mjs scripts/test-web-console-activities-ghoul-marrow.mjs scripts/test-web-console-activities-ghoul-mat.mjs scripts/test-web-console-activities-ghoul-eye.mjs scripts/test-web-console-activities-ghoul-bonestair.mjs scripts/test-web-console-activities-ghoul-heart.mjs scripts/test-web-console-activities-ghoul-ending.mjs scripts/test-web-console-activities-ghoul-ride.mjs scripts/test-web-console-activities-ghoul-cart.mjs scripts/test-web-console-activities-ghoul-sled.mjs scripts/test-web-console-activities-ghoul-banister.mjs scripts/test-web-console-activities-ghoul-gurney.mjs scripts/test-web-console-activities-ghoul-hearse.mjs scripts/test-web-console-activities-ghoul-wagon.mjs scripts/test-web-console-activities-ghoul-pew.mjs scripts/test-web-console-activities-ghoul-mower.mjs scripts/test-web-console-activities-ghoul-tray.mjs scripts/test-web-console-activities-ghoul-arms.mjs scripts/test-web-console-activities-ghoul-dice.mjs scripts/test-web-console-activities-ghoul-gameover.mjs scripts/test-web-console-activities-ghoul-intro.mjs scripts/test-web-console-activities-ghoul-bossintro.mjs scripts/test-web-console-activities-ghoul-story.mjs scripts/test-web-console-activities-ghoul-bones.mjs scripts/test-web-console-activities-ghoul-retry.mjs scripts/test-web-console-activities-bounce-cars.mjs scripts/test-web-console-tones.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-spec-states.mjs scripts/test-web-console-state.mjs scripts/test-web-console-send-state.mjs scripts/test-web-console-strengths.mjs scripts/test-web-console-shape.mjs scripts/test-script-pathfinder.mjs scripts/test-skill-test-runs.mjs scripts/test-launcher.mjs scripts/test-agents-file.mjs scripts/test-agent-lookup.mjs scripts/test-web-console-source.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-loop.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-notepad.mjs scripts/test-script-xray.mjs scripts/test-script-finalize.mjs scripts/test-getting-started.mjs scripts/test-install-update.mjs scripts/test-browser-helper.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-notepad.mjs scripts/test-web-console-page-send.mjs scripts/test-web-console-page-loop.mjs scripts/test-web-console-page-activities.mjs scripts/test-web-console-page-setup.mjs scripts/test-standalone-check.mjs scripts/test-check-versions.mjs scripts/test-app-meter.mjs" + "test": "node scripts/validate-char-count.js && node install.js --build-skills && node scripts/check-versions.mjs && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node scripts/node-test.mjs scripts/test-line-endings.mjs scripts/test-us-english.mjs scripts/test-script-git.mjs scripts/test-git-repo.mjs scripts/test-skill-scripts.mjs scripts/test-script-test-map.mjs scripts/test-script-test-match.mjs scripts/test-script-test-commands.mjs scripts/test-script-run-check.mjs scripts/test-script-pr-prep.mjs scripts/test-script-coverage.mjs scripts/test-script-changelog.mjs scripts/test-web-console-git.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-pointers.mjs scripts/test-console-wire-budgets.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-workspace.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-activities.mjs scripts/test-web-console-activities-rapids.mjs scripts/test-web-console-activities-flock.mjs scripts/test-web-console-activities-bounce.mjs scripts/test-web-console-activities-bounce-game.mjs scripts/test-web-console-activities-ghoul.mjs scripts/test-web-console-activities-ghoul-graveyard.mjs scripts/test-web-console-activities-ghoul-grounds.mjs scripts/test-web-console-activities-ghoul-chapel.mjs scripts/test-web-console-activities-ghoul-sanatorium.mjs scripts/test-web-console-activities-ghoul-village.mjs scripts/test-web-console-activities-ghoul-mine.mjs scripts/test-web-console-activities-ghoul-carnival.mjs scripts/test-web-console-activities-ghoul-frozen.mjs scripts/test-web-console-activities-ghoul-bog.mjs scripts/test-web-console-activities-ghoul-lantern.mjs scripts/test-web-console-activities-ghoul-marrow.mjs scripts/test-web-console-activities-ghoul-mat.mjs scripts/test-web-console-activities-ghoul-eye.mjs scripts/test-web-console-activities-ghoul-bonestair.mjs scripts/test-web-console-activities-ghoul-heart.mjs scripts/test-web-console-activities-ghoul-ending.mjs scripts/test-web-console-activities-ghoul-ride.mjs scripts/test-web-console-activities-ghoul-cart.mjs scripts/test-web-console-activities-ghoul-sled.mjs scripts/test-web-console-activities-ghoul-banister.mjs scripts/test-web-console-activities-ghoul-gurney.mjs scripts/test-web-console-activities-ghoul-hearse.mjs scripts/test-web-console-activities-ghoul-wagon.mjs scripts/test-web-console-activities-ghoul-pew.mjs scripts/test-web-console-activities-ghoul-mower.mjs scripts/test-web-console-activities-ghoul-tray.mjs scripts/test-web-console-activities-ghoul-arms.mjs scripts/test-web-console-activities-ghoul-dice.mjs scripts/test-web-console-activities-ghoul-gameover.mjs scripts/test-web-console-activities-ghoul-intro.mjs scripts/test-web-console-activities-ghoul-bossintro.mjs scripts/test-web-console-activities-ghoul-story.mjs scripts/test-web-console-activities-ghoul-bones.mjs scripts/test-web-console-activities-ghoul-retry.mjs scripts/test-web-console-activities-bounce-cars.mjs scripts/test-web-console-tones.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-spec-states.mjs scripts/test-web-console-state.mjs scripts/test-web-console-send-state.mjs scripts/test-web-console-strengths.mjs scripts/test-web-console-shape.mjs scripts/test-script-pathfinder.mjs scripts/test-skill-test-runs.mjs scripts/test-launcher.mjs scripts/test-agents-file.mjs scripts/test-agent-lookup.mjs scripts/test-web-console-source.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-loop.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-notepad.mjs scripts/test-script-xray.mjs scripts/test-script-finalize.mjs scripts/test-getting-started.mjs scripts/test-install-update.mjs scripts/test-browser-helper.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-notepad.mjs scripts/test-web-console-page-send.mjs scripts/test-web-console-page-loop.mjs scripts/test-web-console-page-activities.mjs scripts/test-web-console-page-setup.mjs scripts/test-standalone-check.mjs scripts/test-check-versions.mjs scripts/test-app-meter.mjs" }, "devDependencies": { "gpt-tokenizer": "2.9.0", diff --git a/scripts/check-versions.mjs b/scripts/check-versions.mjs index dac2a54..32d87c2 100644 --- a/scripts/check-versions.mjs +++ b/scripts/check-versions.mjs @@ -1,7 +1,9 @@ // Checks that every file carrying the product's version agrees, the desktop app's included: -// version.json, package.json, CHANGELOG.md's top heading, and the app's tauri.conf.json, -// package.json and Cargo.toml. The release-app workflow runs it before building, with -// --tag , so a release cannot ship an app that names another version. +// version.json, package.json, CHANGELOG.md's top heading, README's "Version X.Y.Z" line, and the +// app's tauri.conf.json, package.json, package-lock.json (two lines), src-tauri/Cargo.toml, +// fake-agent/Cargo.toml and Cargo.lock (the plan2code-app and fake-agent entries). `npm test` runs +// it on this tree, and the release-app workflow runs it before building, with --tag , so a release cannot ship a file that names another version. // // node scripts/check-versions.mjs [--tag v3.0.0] // @@ -16,19 +18,35 @@ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8")).version; const CARGO_VERSION = /^\s*version\s*=\s*"([^"]+)"/m; const CHANGELOG_HEADING = /^##\s+v?(\d+\.\d+\.\d+)\b/m; +const README_LINE = /^Version (\d+\.\d+\.\d+)\b/m; -/** Each file that carries the version, with how to read it. Paths are relative to the repo root. */ +// The first `version =` line is the [package] one; dependencies come after it. +const readCargoToml = (file) => fs.readFileSync(file, "utf8").match(CARGO_VERSION)?.[1]; +/** The version of the `[[package]]` called `name` in a Cargo.lock. */ +const lockEntry = (name) => (file) => + fs.readFileSync(file, "utf8").match(new RegExp(`^name = "${name}"\\r?\\nversion = "([^"]+)"`, "m"))?.[1]; + +/** + * Each place that carries the version, with how to read it. Paths are relative to the repo root; + * a file with two places gets a `label` so a mismatch says which one. + */ const SOURCES = [ { file: "version.json", read: readJson }, { file: "package.json", read: readJson }, { file: "CHANGELOG.md", read: (file) => fs.readFileSync(file, "utf8").match(CHANGELOG_HEADING)?.[1] }, + { file: "README.md", read: (file) => fs.readFileSync(file, "utf8").match(README_LINE)?.[1] }, { file: "plan2code-app/src-tauri/tauri.conf.json", read: readJson }, { file: "plan2code-app/package.json", read: readJson }, + { file: "plan2code-app/package-lock.json", label: "plan2code-app/package-lock.json (top)", read: readJson }, { - file: "plan2code-app/src-tauri/Cargo.toml", - // The first `version =` line is the [package] one; dependencies come after it. - read: (file) => fs.readFileSync(file, "utf8").match(CARGO_VERSION)?.[1], + file: "plan2code-app/package-lock.json", + label: "plan2code-app/package-lock.json (packages[\"\"])", + read: (file) => JSON.parse(fs.readFileSync(file, "utf8")).packages?.[""]?.version, }, + { file: "plan2code-app/src-tauri/Cargo.toml", read: readCargoToml }, + { file: "plan2code-app/fake-agent/Cargo.toml", read: readCargoToml }, + { file: "plan2code-app/Cargo.lock", label: "plan2code-app/Cargo.lock (plan2code-app)", read: lockEntry("plan2code-app") }, + { file: "plan2code-app/Cargo.lock", label: "plan2code-app/Cargo.lock (fake-agent)", read: lockEntry("fake-agent") }, ]; /** @@ -39,19 +57,19 @@ const SOURCES = [ export function checkVersions(root = ROOT, { tag } = {}) { const versions = []; const problems = []; - for (const { file, read } of SOURCES) { + for (const { file, label = file, read } of SOURCES) { let version; try { version = read(path.join(root, file)); } catch (error) { - problems.push(`${file}: cannot be read (${error.code || error.message})`); + problems.push(`${label}: cannot be read (${error.code || error.message})`); continue; } if (!version) { - problems.push(`${file}: no version found`); + problems.push(`${label}: no version found`); continue; } - versions.push({ file, version }); + versions.push({ file: label, version }); } const expected = versions.find((v) => v.file === "version.json")?.version; for (const { file, version } of versions) { diff --git a/scripts/test-check-versions.mjs b/scripts/test-check-versions.mjs index 26e3553..7f14c8b 100644 --- a/scripts/test-check-versions.mjs +++ b/scripts/test-check-versions.mjs @@ -1,6 +1,6 @@ // Tests for scripts/check-versions.mjs. Run with: node --test scripts/test-check-versions.mjs // -// Each test builds a small tree in a temp folder holding the six files that carry the version, +// Each test builds a small tree in a temp folder holding every file that carries the version, // so the check is exercised without depending on what the real repo says today. import test from "node:test"; @@ -14,6 +14,11 @@ import { checkVersions } from "./check-versions.mjs"; const SCRIPT = path.join(path.dirname(fileURLToPath(import.meta.url)), "check-versions.mjs"); +/** A Cargo.lock whose two workspace entries sit among others that carry their own versions. */ +function cargoLock(app, fake) { + return `[[package]]\nname = "chrono"\nversion = "0.4.0"\n\n[[package]]\nname = "fake-agent"\nversion = "${fake}"\n\n[[package]]\nname = "plan2code-app"\nversion = "${app}"\n`; +} + /** A tree with every version file at `version`, each overridable by its path in `over`. */ function tree(t, version = "3.0.0", over = {}) { const root = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-versions-")); @@ -23,8 +28,16 @@ function tree(t, version = "3.0.0", over = {}) { "package.json": JSON.stringify({ name: "plan2code", version }), "CHANGELOG.md": `# Changelog\n\n## v${version}\n\n### Added\n\n- something\n\n## v0.0.1\n`, "plan2code-app/src-tauri/tauri.conf.json": JSON.stringify({ productName: "Plan2Code", version }), + "README.md": `# Plan2Code\n\nVersion ${version} ยท MIT\n`, "plan2code-app/package.json": JSON.stringify({ name: "plan2code-app", version }), + "plan2code-app/package-lock.json": JSON.stringify({ + name: "plan2code-app", + version, + packages: { "": { name: "plan2code-app", version } }, + }), "plan2code-app/src-tauri/Cargo.toml": `[package]\nname = "plan2code-app"\nversion = "${version}"\n\n[dependencies]\nserde = { version = "1" }\n`, + "plan2code-app/fake-agent/Cargo.toml": `[package]\nname = "fake-agent"\nversion = "${version}"\n`, + "plan2code-app/Cargo.lock": cargoLock(version, version), ...over, }; for (const [file, content] of Object.entries(files)) { @@ -35,10 +48,10 @@ function tree(t, version = "3.0.0", over = {}) { return root; } -test("versions: six files at one version pass, and each is listed", (t) => { +test("versions: every file at one version passes, and each place is listed", (t) => { const result = checkVersions(tree(t)); assert.equal(result.ok, true, result.problems.join("; ")); - assert.equal(result.versions.length, 6); + assert.equal(result.versions.length, 12); assert.ok(result.versions.every((v) => v.version === "3.0.0")); }); @@ -58,6 +71,35 @@ test("versions: Cargo.toml's package version counts, a dependency's does not", ( assert.match(checkVersions(root).problems[0], /Cargo\.toml says 3\.1\.0/); }); +test("versions: README's line, a lockfile line and a fake-agent entry each disagree by name", (t) => { + const readme = checkVersions(tree(t, "3.0.0", { "README.md": "# Plan2Code\n\nVersion 2.6.0 ยท MIT\n" })); + assert.deepEqual(readme.problems, ["README.md says 2.6.0, version.json says 3.0.0"]); + + const lock = checkVersions( + tree(t, "3.0.0", { + "plan2code-app/package-lock.json": JSON.stringify({ version: "3.0.0", packages: { "": { version: "2.9.0" } } }), + }), + ); + assert.deepEqual(lock.problems, ['plan2code-app/package-lock.json (packages[""]) says 2.9.0, version.json says 3.0.0']); + + const fake = checkVersions( + tree(t, "3.0.0", { "plan2code-app/fake-agent/Cargo.toml": '[package]\nname = "fake-agent"\nversion = "2.9.0"\n' }), + ); + assert.deepEqual(fake.problems, ["plan2code-app/fake-agent/Cargo.toml says 2.9.0, version.json says 3.0.0"]); +}); + +test("versions: each Cargo.lock entry is read by its own name", (t) => { + const stale = checkVersions(tree(t, "3.0.0", { "plan2code-app/Cargo.lock": cargoLock("3.0.0", "2.9.0") })); + assert.deepEqual(stale.problems, ["plan2code-app/Cargo.lock (fake-agent) says 2.9.0, version.json says 3.0.0"]); + const other = checkVersions(tree(t, "3.0.0", { "plan2code-app/Cargo.lock": cargoLock("2.9.0", "3.0.0") })); + assert.deepEqual(other.problems, ["plan2code-app/Cargo.lock (plan2code-app) says 2.9.0, version.json says 3.0.0"]); + const gone = checkVersions( + tree(t, "3.0.0", { "plan2code-app/Cargo.lock": '[[package]]\nname = "chrono"\nversion = "0.4.0"\n' }), + ); + assert.equal(gone.problems.length, 2); + assert.match(gone.problems[0], /Cargo\.lock \(plan2code-app\): no version found/); +}); + test("versions: the changelog's top heading is the one read", (t) => { const root = tree(t, "3.0.0", { "CHANGELOG.md": "# Changelog\n\n## v3.1.0\n\n## v3.0.0\n" }); assert.match(checkVersions(root).problems[0], /CHANGELOG\.md says 3\.1\.0/);