Skip to content

test(version): pin the prerelease fix in positionAgainstRange so it cannot silently regress #1255

Description

@sonukapoor

Good first issue, and a genuinely small one. This is first-timers-only, so if you have contributed here before please leave it for someone who has not.

The problem

positionAgainstRange in src/utils/version.ts classifies a version as satisfies, below, above or outside a semver range. It was recently fixed (#1240) so that it agrees with satisfiesRange on prerelease versions. The fix is correct, but nothing tests it, so a future change could silently undo it.

Specifically: the function passes the raw range to semver's satisfies/ltr/gtr, and uses validRange only as a guard. If someone "tidies" that by comparing against validRange's normalized output instead, prerelease handling breaks again and every existing test still passes.

Reproduce the gap

On main, change positionAgainstRange so the three semver calls receive semver.validRange(trimmedRange, { loose: true }) instead of trimmedRange. Then:

npm test -- tests/utils/version-extensions.test.ts

All 60 tests pass, even though the behaviour has regressed:

input correct with the regression
positionAgainstRange("3.0.0-rc.1", "3.x") "satisfies" "below"
positionAgainstRange("3.0.0-rc.1", "1.x || 3.x") "satisfies" "outside"

What to change

Add a test to tests/utils/version-extensions.test.ts asserting the correct values above. Either input works; both is better.

Please verify it actually catches the problem: make the regression above, confirm your new test fails, then revert and confirm it passes. A test that passes either way is worse than no test, because it looks like coverage.

Getting started

  • npm install, then npm test to confirm a clean start (currently 2127 tests)
  • branch as test/issue-NNN-short-description
  • Closes #NNN in the PR body

Ask here if anything is unclear.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    first-timers-onlyReserved for contributors making their first contribution to this projectgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions