test(scripts): cover the release package helpers and the pr-policy GitHub layer

Merged
DE
19d ago
+240-0

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.ts covers widePeerRange, 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; and publicPackages against the repository's real manifests.
  • scripts/pr-policy/github.test.ts stubs fetch through node:test's mock.method and covers what check.ts and sweep.ts actually do to a pull request. graphql posts to /graphql with owner and name bound from GITHUB_REPOSITORY, joins GraphQL error messages, and refuses a response without data. policyComment pages 100 at a time until a short page and finds only the bot's marker comment. flag rewrites 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. clear deletes the comment and the label, tolerates a 404 on the label, and still fails on a real API error. closeWithComment comments 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 --noEmit reports one error on this machine, @sindresorhus/slugify unresolved, which package.json declares and a CI install provides. oxlint reports 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:scripts glob, and the scripts' own --dry-run paths 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/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.