test(scripts): cover the release package helpers and the pr-policy GitHub layer
What and why
The scripts that guard this repository's releases and its community pull request policy run with no unit tests today. Two of the modules under scripts/ carry logic whose failure is quiet and expensive. scripts/public-packages.ts is the peer-range core that check-peer-ranges.ts, restore-peer-ranges.ts, and canary-changeset.ts share: it decides which packages under packages/ publish, builds the >=<version> <next major> range every public package keeps on another, and recognizes that shape again, which is what notices when a canary pin survived a publish and landed on main. scripts/pr-policy/github.ts is the API layer check.ts and sweep.ts call to label, comment, and close pull requests, and the sweep closes up to 20 community PRs per day at its cap, so a regression in its request shapes or its comment matching lands on someone else's repository before anyone sees a red build.
The test suite under scripts/ covers ten files already, and the policy's own rules are tested in scripts/pr-policy/rules.test.ts, but nothing covers the range shape or the GitHub layer underneath it. This PR adds the two missing test files and changes no production code, so the checks the scripts already run in CI are also what exercises the new tests.
What changed
scripts/public-packages.test.tscoverswidePeerRange, the floor with the prerelease suffix dropped and a non-semver version refused;isWidePeerRange, the produced shape at any floor and the refusals, a caret, a bare floor, an exact pin, a dotted ceiling, a ceiling that is not the next major, and a prerelease floor;siblingPeers, only peers that name another public package, with their ranges; andpublicPackagesagainst the repository's real manifests.scripts/pr-policy/github.test.tsstubsfetchthroughnode:test'smock.methodand covers whatcheck.tsandsweep.tsactually do to a pull request.graphqlposts to/graphqlwithownerandnamebound fromGITHUB_REPOSITORY, joins GraphQL error messages, and refuses a response without data.policyCommentpages 100 at a time until a short page and finds only the bot's marker comment.flagrewrites the comment in place on a labeled PR, sends nothing when the comment already matches, and deletes a stale comment, posts a new one, and labels an unlabeled PR.cleardeletes the comment and the label, tolerates a 404 on the label, and still fails on a real API error.closeWithCommentcomments before it closes.- No production file changed, and
scripts/ships in no package, so the PR carries no changeset.
Issue
Fixes #1415
Verified
Ran it locally: yes
- The two new files pass under the scripts runner:
node --test scripts/public-packages.test.ts scripts/pr-policy/github.test.ts
tests 17 pass 17 fail 0
- The full scripts suite splits on this machine. The two
scripts/oxlint-plugin/rule-tester files cannot run here, the test runner asks for an allocation this box cannot provide, and their 49 failures are this machine's baseline, green in CI. Every other scripts test file passes, 67 tests including the new 17. tsc -p scripts --noEmitreports one error on this machine,@sindresorhus/slugifyunresolved, whichpackage.jsondeclares and a CI install provides.oxlintreports 0 warnings and 0 errors on the new files.- The change is tests only, so there is no behavior to show besides the runs above: the new files join the existing
pnpm test:scriptsglob, and the scripts' own--dry-runpaths are untouched.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.