Skip to content

fix: IsCompatible returns false for invalid semver inputs#34312

Merged
pelikhan merged 3 commits into
mainfrom
copilot/fix-iscompatible-bug
May 23, 2026
Merged

fix: IsCompatible returns false for invalid semver inputs#34312
pelikhan merged 3 commits into
mainfrom
copilot/fix-iscompatible-bug

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 23, 2026

IsCompatible silently returned true when both inputs were invalid semver strings — semver.Major returns "" for unparseable input, so "" == "" evaluated to true, causing garbage versions to be reported as compatible.

Changes

  • pkg/semverutil/semverutil.go — Add semver.IsValid guard before comparing majors; return false immediately if either version is invalid
  • pkg/semverutil/semverutil_test.go / spec_test.go — Add invalid-input cases ("", "not-a-version", "vfoo", mixed valid/invalid)
// Before
IsCompatible("not-a-version", "also-not-a-version") // → true ❌

// After
IsCompatible("not-a-version", "also-not-a-version") // → false ✅
IsCompatible("", "")                                 // → false ✅
IsCompatible("v5.0.0", "v5")                        // → true  ✅ (unchanged)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix IsCompatible to handle invalid semver strings correctly fix: IsCompatible returns false for invalid semver inputs May 23, 2026
Copilot AI requested a review from pelikhan May 23, 2026 23:09
@pelikhan pelikhan marked this pull request as ready for review May 23, 2026 23:09
Copilot AI review requested due to automatic review settings May 23, 2026 23:09
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

⚠️ PR Code Quality Reviewer failed during code quality review.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

Design Decision Gate 🏗️ failed during design decision gate check.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

🧠 Matt Pocock Skills Reviewer failed during the skills-based review.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

Test Quality Sentinel failed during test quality analysis.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a correctness bug in pkg/semverutil where IsCompatible could return true for two invalid semver strings due to semver.Major returning "" for unparseable inputs.

Changes:

  • Add a validity guard in IsCompatible to return false when either version is not valid semver.
  • Add test coverage for invalid/empty version inputs in both unit tests and spec tests.
Show a summary per file
File Description
pkg/semverutil/semverutil.go Adds semver.IsValid guard to prevent invalid inputs from being treated as compatible.
pkg/semverutil/semverutil_test.go Adds unit tests covering invalid/empty semver inputs for IsCompatible.
pkg/semverutil/spec_test.go Extends public API spec tests with invalid/empty input compatibility cases.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment thread pkg/semverutil/semverutil.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@pelikhan pelikhan merged commit 51f3e71 into main May 23, 2026
22 of 23 checks passed
@pelikhan pelikhan deleted the copilot/fix-iscompatible-bug branch May 23, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: IsCompatible returns true for two invalid/unparseable semver strings

3 participants