From 42d0d39849eec14c0dfb30f79c90f0ffb1e925c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Eizedev?= <6794362+eizedev@users.noreply.github.com> Date: Wed, 25 Nov 2026 23:12:24 +0100 Subject: [PATCH 1/2] ci: require a whole-change check in pull requests that change docs or code The growth guards count lines, and a number cannot judge sense: pages and functions grew by appending, and a failing guard was passed by squeezing lines or cutting words. The guard stays an alarm. A pull request that changes docs or code now says in its description what its author read whole and how the change reshaped it, and the review judges that. - PULL_REQUEST_TEMPLATE.md: a "Whole-change check" section with its prompts in a comment, so the untouched template does not pass - build/whole-change-check.js and whole-change-check.yml: fail a pull request that changes docs/, a README, root Markdown, a module's Components/, Public/, Private/ or .psm1, shared/ or build/ without text in that section; runs again on an edited description; the description reaches the script only through env; Dependabot and release pull requests are exempt - growth.js: a function, file or page that grew says to stop and check the whole, then reshape or raise the baseline with a reason - AGENTS.md, CONTRIBUTING.md: the raised baseline's reason and the check Co-Authored-By: Claude Opus 5.5 --- .github/PULL_REQUEST_TEMPLATE.md | 20 ++++++ .github/workflows/whole-change-check.yml | 45 +++++++++++++ AGENTS.md | 3 +- CONTRIBUTING.md | 4 +- build/growth.js | 19 ++++-- build/whole-change-check.js | 86 ++++++++++++++++++++++++ tests/js/ci.test.js | 29 ++++++++ tests/js/growth.test.js | 6 +- tests/js/whole-change-check.test.js | 66 ++++++++++++++++++ 9 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/whole-change-check.yml create mode 100644 build/whole-change-check.js create mode 100644 tests/js/whole-change-check.test.js diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 99b473d..7b181b8 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,6 +2,26 @@ +## Whole-change check + + + ## Checklist - [ ] Linked issue diff --git a/.github/workflows/whole-change-check.yml b/.github/workflows/whole-change-check.yml new file mode 100644 index 0000000..3ff1787 --- /dev/null +++ b/.github/workflows/whole-change-check.yml @@ -0,0 +1,45 @@ +name: Whole-change check + +# A pull request that changes docs or code says in its description what its author read whole and how +# the change reshaped it (build/whole-change-check.js says what counts and who is exempt). It runs +# again when the description is edited, so fixing the description turns it green; a workflow of its +# own, so an edit does not run all of CI again. +# +# The description, title and author reach the script only through env: whoever opens the pull request +# writes them, and an expression inside `run` would become part of the shell script. +on: + # pull requests to main, as ci.yml + pull_request: + branches: ["main"] + types: [opened, synchronize, reopened, edited] + +permissions: + contents: read + +concurrency: + group: whole-change-check-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + # the merge commit and its first parent, the base: their difference is what the pull request changes + fetch-depth: 2 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: "22" + - name: Whole-change check + env: + PR_BODY: ${{ github.event.pull_request.body }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + run: | + # quotepath off: a path with non-ASCII letters as it is, not quoted and escaped + CHANGED_FILES="$(git -c core.quotepath=off diff --name-only HEAD^1 HEAD)" + export CHANGED_FILES + node build/whole-change-check.js diff --git a/AGENTS.md b/AGENTS.md index 357a986..ef12c20 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -84,7 +84,8 @@ The limits and their reasons are in that file. Each guard is a CI step: - `docs`: lines per docs page and README by kind of page, and of all of them together. The offenders over a limit are in `build/growth-baseline.json`. A new or grown one fails. A smaller one -fails until `node build/growth.js --update` lowers the baseline in the same pull request. +fails until `node build/growth.js --update` lowers the baseline in the same pull request. A raised +baseline needs its reason in the pull request's whole-change check. A change to a component is checked on a PSU test instance in a browser (light and dark theme, a narrow and a wide window, the events it fires) before it is called done; unit tests do not cover diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d1bf3ba..7c83dc7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,6 +22,8 @@ Thanks for helping. 4. Update the pages in `docs/` and add an entry under `[Unreleased]` in the `CHANGELOG.md` of each module you changed. 5. Open a pull request. Use Conventional Commits with the module as scope: `fix(pivot): ...`. + A change to docs or code fills in the template's whole-change check: what you read whole, and how + you reshaped it instead of appending. CI fails without it; editing the description runs it again. ## Check your change @@ -37,7 +39,7 @@ pwsh -c 'Invoke-Pester -Path tests/powershell' ``` When `npm run growth` reports that something shrank, lower the baseline in the same pull request with -`node build/growth.js --update`. +`node build/growth.js --update`. When something grew, its message says what to do. Then, depending on what you changed: diff --git a/build/growth.js b/build/growth.js index fd3f5e1..e4d82ea 100644 --- a/build/growth.js +++ b/build/growth.js @@ -13,7 +13,8 @@ // build/growth-baseline.json with their numbers. A check fails when an offender grows or a new one // appears. It also fails when an offender shrank or went: the baseline must follow in the same pull // request (--update), or the room it left could be filled again unseen. --update never raises an -// entry by itself. Raising one is --accept-growth, and the pull request says why. +// entry by itself. Raising one is --accept-growth, and the pull request's whole-change check says +// why (.github/PULL_REQUEST_TEMPLATE.md). // eizedev/pivotkit has the same guards in scripts/growth.js; both work alike. import { spawnSync } from "node:child_process"; import { existsSync, readFileSync, writeFileSync } from "node:fs"; @@ -57,16 +58,22 @@ export const DOCS_LIMITS = Object.freeze({ overview: 150, topic: 200, reference: /** How far the lines of all pages together may drift from the baseline, in percent, before it is updated. */ export const DOCS_TOTAL_MARGIN = 2; +/** + * What to do when a function or a page grew. A number cannot judge sense: the guard is an alarm to + * look at the whole, and squeezing lines or cutting words to pass it makes the code or page worse. + */ +const STOP = `Stop and read the whole of it; write what you found in the pull request's whole-change check (.github/PULL_REQUEST_TEMPLATE.md, "Whole-change check").`; + /** What to do when a guard fails, said once per guard. */ const ADVICE = { - powershell: `Split the function into smaller ones, one job each, and the file into one file per function (AGENTS.md, "Small units"). Limits: ${POWERSHELL_LIMITS.function} code lines per function, ${POWERSHELL_LIMITS.file} per file; blank lines and comments do not count.`, - javascript: `Split the function into smaller ones, one job each (AGENTS.md, "Small units"). Limits: ${FUNCTION_LIMITS.lines} lines without blank lines and comments, complexity ${FUNCTION_LIMITS.complexity}.`, + powershell: `The function or file grew. ${STOP} Then reshape it for real: extract the jobs it does beside its own, one function per file (AGENTS.md, "Small units"). Limits: ${POWERSHELL_LIMITS.function} code lines per function, ${POWERSHELL_LIMITS.file} per file; blank lines and comments do not count.`, + javascript: `The function grew. ${STOP} Then reshape it for real: extract the jobs it does beside its own (AGENTS.md, "Small units"). Limits: ${FUNCTION_LIMITS.lines} lines without blank lines and comments, complexity ${FUNCTION_LIMITS.complexity}.`, duplication: "Move the copied code into one function or module that both places import (AGENTS.md, \"One place per fact\"; shared/js once a second module needs it). The threshold is in .jscpd.json.", - docs: "Shorten the page, or split it into pages with one topic each; rewrite instead of appending (AGENTS.md, \"Shape what exists\"). When all pages together grew, make room in the pages the change touches.", + docs: `The page grew. ${STOP} Then reshape it for real: move detail to a sub-page and link it, write a list or a table instead of prose, or move a section to the page that owns its topic (AGENTS.md, "Shape what exists"). When all pages together grew, make room in the pages the change touches.`, }; /** The way out when the growth is right, said under every guard that grew. */ -const ACCEPT = `If the growth is right, raise the baseline with ${UPDATE} --accept-growth and say why in the pull request.`; +const ACCEPT = `Or raise the baseline with ${UPDATE} --accept-growth, with the reason in the whole-change check and the maintainer's approval. Never merge lines or cut words only to pass the number.`; const posix = (path, base = root) => relative(base, path).split(sep).join("/"); @@ -320,7 +327,7 @@ export async function main(argv, { dir = root, baselineFile = fileURLToPath(BASE writeFileSync(baselineFile, formatBaseline(next)); console.log(`wrote ${posix(baselineFile)}`); } else if (update) { - console.error(`\nThe baseline was not written: something grew. Fix that, or raise the baseline with ${UPDATE} --accept-growth and say why in the pull request.`); + console.error(`\nThe baseline was not written: something grew. Reshape it, or raise the baseline with ${UPDATE} --accept-growth and give the reason in the pull request's whole-change check.`); } process.exitCode = failed ? 1 : 0; } diff --git a/build/whole-change-check.js b/build/whole-change-check.js new file mode 100644 index 0000000..046d26b --- /dev/null +++ b/build/whole-change-check.js @@ -0,0 +1,86 @@ +// Whole-change check: a pull request that changes docs or code has a "## Whole-change check" section +// with text in its description. There its author says what they read whole and how the change +// reshaped it instead of appending (.github/PULL_REQUEST_TEMPLATE.md). The growth guards (growth.js) +// count lines; a number cannot judge sense, so this asks for the judgement, and the review judges it. +// +// .github/workflows/whole-change-check.yml runs it on every pull request, also when the description +// is edited. It reads everything from environment variables, never from the command line, because +// the description and title are written by whoever opens the pull request: +// +// PR_BODY, PR_TITLE, PR_AUTHOR the description, the title and the author's login +// CHANGED_FILES the changed paths, one per line +// +// Exempt are Dependabot's pull requests and release pull requests (docs/development/release.md), +// known by their title: "chore(release): ..." or "chore(): release ...", the scope optional. +// eizedev/pivotkit has the same check in scripts/whole-change-check.js; both work alike. +import { fileURLToPath } from "node:url"; + +/** The heading the description needs, without its "## ". */ +export const HEADING = "Whole-change check"; + +/** + * The paths whose change needs the check: Markdown of the docs site, READMEs and the root, and code: + * a module's components, functions and .psm1 (some modules keep their functions there), shared/ and build/. + */ +const SCOPE = [/^docs\/.*\.md$/, /(^|\/)README\.md$/, /^[^/]+\.md$/, /^modules\/[^/]+\/(Components|Public|Private)\//, /^modules\/[^/]+\/[^/]+\.psm1$/, /^shared\//, /^build\//]; + +/** + * The changed paths that need the check. + * @param {string[]} files + */ +export const inScope = (files) => files.filter((file) => SCOPE.some((re) => re.test(file))); + +/** + * The text of the description's whole-change check, without HTML comments (the template's prompts), + * up to the next heading of level 1 or 2; null when the description has no such heading. + * @param {string | null | undefined} body + */ +export function sectionText(body) { + // an unclosed comment hides the rest of the description, on GitHub as here + const lines = String(body ?? "").replace(/|$)/g, "").split(/\r?\n/); + const start = lines.findIndex((line) => /^ {0,3}##\s+whole-change check\s*#*\s*$/i.test(line)); + if (start === -1) return null; + const end = lines.findIndex((line, i) => i > start && /^ {0,3}#{1,2}\s/.test(line)); + return lines.slice(start + 1, end === -1 ? undefined : end).join("\n").trim(); +} + +/** + * Why a pull request needs no whole-change check whatever it changes, or null. + * @param {{ author?: string, title?: string }} pr + */ +export function exemption({ author = "", title = "" }) { + if (author === "dependabot[bot]") return "a Dependabot pull request"; + if (/^chore(?:\(release\)!?:|(?:\([^)]*\))?!?:\s*release\b)/i.test(title)) return "a release pull request"; + return null; +} + +/** + * The verdict on a pull request, with the text to print. + * @param {{ body?: string | null, title?: string, author?: string, files: string[] }} pr + * @returns {{ ok: boolean, message: string }} + */ +export function check({ body, title, author, files }) { + const exempt = exemption({ author, title }); + if (exempt) return { ok: true, message: `Whole-change check: not needed for ${exempt}.` }; + const touched = inScope(files); + if (touched.length === 0) return { ok: true, message: "Whole-change check: not needed, no docs or code changed." }; + if (/[\p{L}\p{N}]/u.test(sectionText(body) ?? "")) return { ok: true, message: "Whole-change check: found in the description." }; + const shown = touched.slice(0, 10).join("\n ") + (touched.length > 10 ? `\n and ${touched.length - 10} more` : ""); + return { + ok: false, + message: [ + `This pull request changes docs or code:\n ${shown}`, + `Its description needs a "## ${HEADING}" section with text: what you read whole, and how you`, + "reshaped it instead of appending. The prompts are in .github/PULL_REQUEST_TEMPLATE.md.", + "Edit the description; the check runs again.", + ].join("\n"), + }; +} + +if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) { + const { PR_BODY, PR_TITLE, PR_AUTHOR, CHANGED_FILES = "" } = process.env; + const files = CHANGED_FILES.split("\n").map((line) => line.trim()).filter(Boolean); + const { ok, message } = check({ body: PR_BODY, title: PR_TITLE, author: PR_AUTHOR, files }); + (ok ? console.log : console.error)(message); + process.exitCode = ok ? 0 : 1; +} diff --git a/tests/js/ci.test.js b/tests/js/ci.test.js index 3384132..266dc11 100644 --- a/tests/js/ci.test.js +++ b/tests/js/ci.test.js @@ -159,3 +159,32 @@ test("the docs workflow checks the README links against the built site, after bu const upload = steps.findIndex((step) => String(step.uses ?? "").startsWith("actions/upload-pages-artifact@")); assert.ok(check < upload, "docs.yml uploads the site before checking the README links"); }); + +// The whole-change check (build/whole-change-check.js) runs again when the description is edited, +// reads only, and gets the description, title and author through env: an expression in a `run` would +// put text whoever opens the pull request wrote into the shell script +test("the whole-change check runs on every pull request event that can fix it, reads only, and takes the pull request only through env", () => { + const check = workflow("whole-change-check.yml"); + assert.deepEqual(Object.keys(check.on), ["pull_request"], "the check runs on another event than pull_request (pull_request_target would hold a write token)"); + assert.deepEqual([...check.on.pull_request.types].sort(), ["edited", "opened", "reopened", "synchronize"]); + assert.equal(check.on.pull_request.paths ?? check.on.pull_request["paths-ignore"], undefined, "the script decides what needs the check"); + assert.deepEqual(check.on.pull_request.branches, workflow("ci.yml").on.pull_request.branches, "the check runs for other base branches than ci.yml"); + assert.deepEqual(check.permissions, { contents: "read" }); + assert.notEqual(check.concurrency.group, workflow("ci.yml").concurrency.group, "an edit of the description cancels CI"); + const steps = Object.values(check.jobs).flatMap((job) => { + assert.equal(job.permissions, undefined, "a job of the check asks for more permissions"); + return job.steps; + }); + for (const step of steps) assert.doesNotMatch(String(step.run ?? ""), /\$\{\{/, `"${step.name ?? step.uses}" has an expression in its run`); + const run = steps.find((step) => commandsOf(step).includes("node build/whole-change-check.js")); + assert.ok(run, "no step runs build/whole-change-check.js"); + assert.deepEqual(run.env, { + PR_BODY: "${{ github.event.pull_request.body }}", + PR_TITLE: "${{ github.event.pull_request.title }}", + PR_AUTHOR: "${{ github.event.pull_request.user.login }}", + }); + assert.ok(commandsOf(run).some((line) => /^CHANGED_FILES="\$\(git -c core\.quotepath=off diff --name-only HEAD\^1 HEAD\)"$/.test(line)), "the changed files are not the merge commit's difference to its base"); + const checkout = steps.find((step) => String(step.uses).startsWith("actions/checkout@")); + assert.equal(checkout.with["persist-credentials"], false); + assert.equal(checkout.with["fetch-depth"], 2, "without the merge commit's parent there is nothing to compare with"); +}); diff --git a/tests/js/growth.test.js b/tests/js/growth.test.js index e8e4100..e5a5cfc 100644 --- a/tests/js/growth.test.js +++ b/tests/js/growth.test.js @@ -133,8 +133,10 @@ test("the command fails on growth and on a stale baseline, and --update writes o let run = await runDocsGuard(dir); assert.equal(run.exitCode, 1); assert.ok(run.output.includes(`docs: grew\n docs/page.md: ${DOCS_LIMITS.topic + 10} lines, new`), run.output); - assert.match(run.output, /Shorten the page/); - assert.match(run.output, /--accept-growth and say why/); + assert.match(run.output, /The page grew\. Stop and read the whole of it/); + assert.match(run.output, /PULL_REQUEST_TEMPLATE\.md, "Whole-change check"/); + assert.match(run.output, /--accept-growth, with the reason in the whole-change check/); + assert.match(run.output, /Never merge lines or cut words only to pass the number/); run = await runDocsGuard(dir, "--update"); assert.equal(run.exitCode, 1, "--update alone never raises the baseline"); run = await runDocsGuard(dir, "--update", "--accept-growth"); diff --git a/tests/js/whole-change-check.test.js b/tests/js/whole-change-check.test.js new file mode 100644 index 0000000..5d65bdc --- /dev/null +++ b/tests/js/whole-change-check.test.js @@ -0,0 +1,66 @@ +// build/whole-change-check.js: which changes need the description's whole-change check, what counts +// as one, and who is exempt. The workflow that runs it is checked in tests/js/ci.test.js. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { check, exemption, inScope, sectionText } from "../../build/whole-change-check.js"; + +const template = readFileSync(new URL("../../.github/PULL_REQUEST_TEMPLATE.md", import.meta.url), "utf8"); +const pr = (body, files = ["docs/echarts/themes.md"], more = {}) => check({ body, title: "docs: themes", author: "someone", files, ...more }); + +test("docs, READMEs, root Markdown, module code, shared/ and build/ need the check; the rest does not", () => { + const M = "modules/PowerShellUniversal.Component.Pivot"; + const needed = ["docs/echarts/themes.md", "docs/development/index.md", "README.md", `${M}/README.md`, "AGENTS.md", "CONTRIBUTING.md", `${M}/Components/pivot.jsx`, `${M}/Public/New-UDPivotReport.ps1`, `${M}/Private/Settings/Limits.ps1`, `${M}/Private/RowConverter.cs`, "modules/PowerShellUniversal.Component.Perspective/PowerShellUniversal.Component.Perspective.psm1", "shared/js/columns.js", "shared/powershell/ConvertTo-PSUComponentData.ps1", "build/growth.js"]; + const not = ["docs/site/examples.ps1", "docs/site/src/charts.jsx", `${M}/CHANGELOG.md`, `${M}/package.json`, `${M}/${M.split("/")[1]}.psd1`, `${M}/examples/app.ps1`, "tests/js/ci.test.js", ".github/workflows/ci.yml", "package-lock.json"]; + assert.deepEqual(inScope([...needed, ...not]), needed); +}); + +test("the template as it is fails: its prompts are a comment", () => { + assert.equal(sectionText(template), ""); + assert.equal(pr(template).ok, false); +}); + +test("the template with an answer under the heading passes", () => { + const filled = template.replace(/(## Whole-change check\s*)/, "$1\n\nthemes.md: read whole; moved the token table to the reference page."); + assert.equal(pr(filled).ok, true); +}); + +test("a missing, empty or only-comment section fails, and the message says what to add", () => { + for (const body of [null, undefined, "", "## Summary\n\nText.", "## Whole-change check\n\n## Test plan\n\nRan it.", "## Whole-change check\n\n", "## Whole-change check\n\n- [ ]\n"]) { + const result = pr(body); + assert.equal(result.ok, false, JSON.stringify(body)); + assert.match(result.message, /docs\/echarts\/themes\.md/); + assert.match(result.message, /"## Whole-change check" section with text/); + assert.match(result.message, /PULL_REQUEST_TEMPLATE\.md/); + } +}); + +test("the section ends at the next heading of level 1 or 2, not at a sub-heading", () => { + assert.equal(sectionText("## Whole-change check\r\nRead it whole.\r\n## Test plan\r\nRan."), "Read it whole."); + assert.equal(sectionText("## Summary\n\nx\n\n## Whole-change check\n\n### Docs\nRead it whole."), "### Docs\nRead it whole."); + assert.equal(sectionText("# Title\n## whole-change check ##\nok\n# Next"), "ok"); + // a heading inside a comment or within a line does not count + assert.equal(sectionText(""), null); + assert.equal(sectionText("Text about ## Whole-change check"), null); +}); + +test("an unclosed comment hides the rest, as GitHub renders it", () => { + assert.equal(sectionText("## Whole-change check\n|$)/g, "").split(/\r?\n/); - const start = lines.findIndex((line) => /^ {0,3}##\s+whole-change check\s*#*\s*$/i.test(line)); + // the level of each heading line, 0 for other lines; a "#" inside a code fence is no heading + let fenced = false; + const levels = lines.map((line) => { + if (/^ {0,3}(?:```|~~~)/.test(line)) fenced = !fenced; + return fenced ? 0 : (/^ {0,3}(#{1,6})\s/.exec(line)?.[1].length ?? 0); + }); + const start = lines.findIndex((line, i) => levels[i] === 2 && /^ {0,3}##\s+whole-change check\s*#*\s*$/i.test(line)); if (start === -1) return null; - const end = lines.findIndex((line, i) => i > start && /^ {0,3}#{1,2}\s/.test(line)); + const end = levels.findIndex((level, i) => i > start && level > 0 && level <= 2); return lines.slice(start + 1, end === -1 ? undefined : end).join("\n").trim(); } @@ -50,7 +57,7 @@ export function sectionText(body) { */ export function exemption({ author = "", title = "" }) { if (author === "dependabot[bot]") return "a Dependabot pull request"; - if (/^chore(?:\(release\)!?:|(?:\([^)]*\))?!?:\s*release\b)/i.test(title)) return "a release pull request"; + if (/^chore(?:\(release\)!?:|(?:\([^)]*\))?!?:\s*release\b).*\s\d+\.\d+\.\d+$/i.test(title)) return "a release pull request"; return null; } diff --git a/tests/js/ci.test.js b/tests/js/ci.test.js index 266dc11..a4dfca5 100644 --- a/tests/js/ci.test.js +++ b/tests/js/ci.test.js @@ -183,7 +183,7 @@ test("the whole-change check runs on every pull request event that can fix it, r PR_TITLE: "${{ github.event.pull_request.title }}", PR_AUTHOR: "${{ github.event.pull_request.user.login }}", }); - assert.ok(commandsOf(run).some((line) => /^CHANGED_FILES="\$\(git -c core\.quotepath=off diff --name-only HEAD\^1 HEAD\)"$/.test(line)), "the changed files are not the merge commit's difference to its base"); + assert.ok(commandsOf(run).some((line) => /^CHANGED_FILES="\$\(git -c core\.quotepath=off diff --no-renames --name-only HEAD\^1 HEAD\)"$/.test(line)), "the changed files are not the merge commit's difference to its base"); const checkout = steps.find((step) => String(step.uses).startsWith("actions/checkout@")); assert.equal(checkout.with["persist-credentials"], false); assert.equal(checkout.with["fetch-depth"], 2, "without the merge commit's parent there is nothing to compare with"); diff --git a/tests/js/whole-change-check.test.js b/tests/js/whole-change-check.test.js index 5d65bdc..165acc6 100644 --- a/tests/js/whole-change-check.test.js +++ b/tests/js/whole-change-check.test.js @@ -8,9 +8,9 @@ import { check, exemption, inScope, sectionText } from "../../build/whole-change const template = readFileSync(new URL("../../.github/PULL_REQUEST_TEMPLATE.md", import.meta.url), "utf8"); const pr = (body, files = ["docs/echarts/themes.md"], more = {}) => check({ body, title: "docs: themes", author: "someone", files, ...more }); -test("docs, READMEs, root Markdown, module code, shared/ and build/ need the check; the rest does not", () => { +test("docs, READMEs, root Markdown, module code and showcase apps, shared/ and build/ need the check; the rest does not", () => { const M = "modules/PowerShellUniversal.Component.Pivot"; - const needed = ["docs/echarts/themes.md", "docs/development/index.md", "README.md", `${M}/README.md`, "AGENTS.md", "CONTRIBUTING.md", `${M}/Components/pivot.jsx`, `${M}/Public/New-UDPivotReport.ps1`, `${M}/Private/Settings/Limits.ps1`, `${M}/Private/RowConverter.cs`, "modules/PowerShellUniversal.Component.Perspective/PowerShellUniversal.Component.Perspective.psm1", "shared/js/columns.js", "shared/powershell/ConvertTo-PSUComponentData.ps1", "build/growth.js"]; + const needed = ["docs/echarts/themes.md", "docs/development/index.md", "README.md", `${M}/README.md`, "AGENTS.md", "CONTRIBUTING.md", `${M}/Components/pivot.jsx`, `${M}/Public/New-UDPivotReport.ps1`, `${M}/Private/Settings/Limits.ps1`, `${M}/Private/RowConverter.cs`, "modules/PowerShellUniversal.Component.Perspective/PowerShellUniversal.Component.Perspective.psm1", "modules/PowerShellUniversal.Component.Pivot.Demo/Apps/Showcase.ps1", "shared/js/columns.js", "shared/powershell/ConvertTo-PSUComponentData.ps1", "build/growth.js"]; const not = ["docs/site/examples.ps1", "docs/site/src/charts.jsx", `${M}/CHANGELOG.md`, `${M}/package.json`, `${M}/${M.split("/")[1]}.psd1`, `${M}/examples/app.ps1`, "tests/js/ci.test.js", ".github/workflows/ci.yml", "package-lock.json"]; assert.deepEqual(inScope([...needed, ...not]), needed); }); @@ -42,6 +42,9 @@ test("the section ends at the next heading of level 1 or 2, not at a sub-heading // a heading inside a comment or within a line does not count assert.equal(sectionText(""), null); assert.equal(sectionText("Text about ## Whole-change check"), null); + // a heading inside a code fence is text + assert.equal(sectionText("```\n## Whole-change check\nfake\n```"), null); + assert.equal(sectionText("## Whole-change check\n```\n## not a heading\n```\nRead it whole.\n## Test plan"), "```\n## not a heading\n```\nRead it whole."); }); test("an unclosed comment hides the rest, as GitHub renders it", () => { @@ -58,7 +61,7 @@ test("Dependabot and release pull requests are exempt; other titles and authors for (const title of ["chore(pivot): release Pivot 0.10.1", "chore(pivot): release Pivot.Demo 0.3.0", "chore(release): ECharts 0.2.0", "chore: release 0.1.0"]) { assert.equal(exemption({ author: "someone", title }), "a release pull request", title); } - for (const [author, title] of [["dependabot", "x"], ["someone", "ci(release): release only commits that are on main"], ["someone", "feat: release notes page"], ["someone", "chore: released files"]]) { + for (const [author, title] of [["dependabot", "x"], ["someone", "ci(release): release only commits that are on main"], ["someone", "feat: release notes page"], ["someone", "chore: released files"], ["someone", "chore(release): fold the unreleased entries into the 0.9.0 sections"], ["someone", "chore(docs): release notes page"]]) { assert.equal(exemption({ author, title }), null, `${author} ${title}`); } assert.equal(pr("", ["build/growth.js"], { author: "dependabot[bot]" }).ok, true);