Skip to content

feat: align all components to SemVer 2.0 for version comparison#521

Merged
JusterZhu merged 5 commits into
masterfrom
fix/semver2.0-alignment
Jun 19, 2026
Merged

feat: align all components to SemVer 2.0 for version comparison#521
JusterZhu merged 5 commits into
masterfrom
fix/semver2.0-alignment

Conversation

@JusterZhu

Copy link
Copy Markdown
Collaborator

Summary

Replace all System.Version usage across Core, Extension, and Drivelution with a unified Semver utility class following SemVer 2.0, aligned with GeneralUpdate.Infrastructure.Common/Utilitys/Semver.cs.

All NuGet packages are already versioned as 10.5.0-beta.2 (valid SemVer 2.0), but the SDK code could not compare such versions because System.Version.TryParse("10.5.0-beta.2") returns false, causing silent "no update" behavior. This PR fixes that.

Key changes

  • Core: DownloadPlanBuilder, OssStrategy, ClientStrategy — all Version.TryParse/new Version()Semver.TryParse + SemVersion operators
  • Extension: VersionCompatibilityChecker — same migration
  • Drivelution: VersionComparer[Obsolete] wrapper delegating to new Semver
  • Default: ClientVersion from "1.0.0.0""1.0.0"
  • 3 new files: Utilities/Semver.cs in each of Core, Extension, Drivelution

Bugs fixed incidentally

  1. CVP matching never worked — old fromVer == localVersion used reference equality on Version (class), always false
  2. OssStrategy NPE guardassets.Max()!.Value on empty parsed collection

Backward compatibility

  • Legacy 4-part versions ("1.0.0.0") accepted and normalized
  • 3-part SemVer comparisons produce identical results
  • VersionComparer preserved as [Obsolete] delegate

Closes #520

🤖 Generated with Claude Code

Replace all System.Version usage (Version.TryParse, new Version(string))
with a dedicated Semver utility class following SemVer 2.0, aligned with
GeneralUpdate.Infrastructure.Common/Utilitys/Semver.cs.

New files:
- GeneralUpdate.Core/Utilities/Semver.cs
- GeneralUpdate.Extension/Utilities/Semver.cs
- GeneralUpdate.Drivelution/Core/Utilities/Semver.cs

Modified:
- DownloadPlanBuilder, OssStrategy, ClientStrategy — switch to Semver.TryParse
- VersionCompatibilityChecker — Semver-based comparison
- VersionComparer — [Obsolete] wrapper delegating to Semver
- Default ClientVersion: "1.0.0.0" → "1.0.0"
- Updated tests for new default and Semver alignment

Bugs fixed incidentally:
1. CVP matching used reference equality on Version objects (never worked)
2. OssStrategy LastVersion NPE on empty parse results

Closes #520

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 19, 2026 12:02
- Replace range syntax (input[..]) with Substring for netstandard2.0
- Add missing using System.Linq for string.All() extension method
- Applied to all 3 copies: Core, Extension, Drivelution

Co-Authored-By: Claude <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request replaces System.Version-based version parsing/comparison across Core, Extension, and Drivelution with a SemVer 2.0-compatible Semver utility (including prerelease handling and legacy 4-part normalization), preventing “silent no update” behavior when versions include prerelease suffixes.

Changes:

  • Added SemVer 2.0 parsing/comparison utilities to Core, Extension, and Drivelution; updated comparison call-sites to use Semver/SemVersion.
  • Updated default ClientVersion to "1.0.0" and aligned examples/docs/tests accordingly.
  • Marked Drivelution VersionComparer as [Obsolete] and delegated implementation to Semver; updated Drivelution tests to match new behavior.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/DrivelutionTest/Utilities/VersionComparerAndRestartHelperTests.cs Updates expectations to match SemVer-based comparison behavior (invalid/overflow inputs return 0, legacy 4-part accepted).
tests/CoreTest/Configuration/UpdateConfigurationTests.cs Adjusts assertion for new default client version string (1.0.0).
src/c#/GeneralUpdate.Extension/Utilities/Semver.cs Adds SemVer 2.0 parsing/normalization/comparison implementation for Extension.
src/c#/GeneralUpdate.Extension/Examples/ExtensionExample.cs Updates example host version to 3-part SemVer.
src/c#/GeneralUpdate.Extension/Compatibility/VersionCompatibilityChecker.cs Migrates host/version constraint checks and “latest compatible” selection to SemVer comparisons.
src/c#/GeneralUpdate.Drivelution/Core/Utilities/VersionComparer.cs Converts existing comparer into an obsolete wrapper delegating to Semver.
src/c#/GeneralUpdate.Drivelution/Core/Utilities/Semver.cs Adds SemVer 2.0 parsing/normalization/comparison implementation for Drivelution.
src/c#/GeneralUpdate.Core/Utilities/Semver.cs Adds SemVer 2.0 parsing/normalization/comparison implementation for Core.
src/c#/GeneralUpdate.Core/Strategy/OssStrategy.cs Switches OSS version filtering and LastVersion computation to SemVer parsing/comparison.
src/c#/GeneralUpdate.Core/Strategy/ClientStrategy.cs Updates failed-version guard logic to use SemVer parsing/comparison.
src/c#/GeneralUpdate.Core/Download/DownloadPlanBuilder.cs Migrates update planning/version filtering to SemVer; adjusts CVP matching logic.
src/c#/GeneralUpdate.Core/Configuration/VersionIdentity.cs Updates version string documentation example to SemVer 3-part format.
src/c#/GeneralUpdate.Core/Configuration/VersionEntry.cs Updates version string documentation example to SemVer 3-part format.
src/c#/GeneralUpdate.Core/Configuration/UpdateRequestBuilder.cs Updates JSON example to use "1.0.0" for ClientVersion.
src/c#/GeneralUpdate.Core/Configuration/UpdateConfiguration.cs Changes default ClientVersion from "1.0.0.0" to "1.0.0".
src/c#/GeneralUpdate.Core/Configuration/AppMetadataDiscoverer.cs Updates comment examples to reflect the new default client version format.

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

Comment thread src/c#/GeneralUpdate.Core/Download/DownloadPlanBuilder.cs
Comment thread src/c#/GeneralUpdate.Core/Utilities/Semver.cs
Comment thread src/c#/GeneralUpdate.Extension/Utilities/Semver.cs
Comment thread src/c#/GeneralUpdate.Drivelution/Core/Utilities/Semver.cs
Comment thread src/c#/GeneralUpdate.Core/Download/DownloadPlanBuilder.cs
JusterZhu and others added 3 commits June 19, 2026 20:09
- Extract .Value from SemVersion? before comparison in Where lambda
- Use .Value in IsCompatible to avoid SemVersion? >= SemVersion? → bool?
- Keep non-nullable local copies (cv, uv) for the rest of the method

Co-Authored-By: Claude <noreply@anthropic.com>
The previous implementation split the full version string (including
prerelease/build metadata) on '.'/'-'/'+', causing false positives for
legitimate build-metadata timestamps like 1.0.0+20130313144700.

Now only the core triplet (everything before '-' or '+') is checked.
Update Drivelution test accordingly: remove 999999999999* cases from
valid-versions (they exceed int range).

Co-Authored-By: Claude <noreply@anthropic.com>
SysNumOverflow no longer scans prerelease/build metadata tokens,
so prerelease identifiers like 999999999999 are valid and compare
correctly as long. Test assertion updated to match.

Co-Authored-By: Claude <noreply@anthropic.com>
@JusterZhu JusterZhu enabled auto-merge (squash) June 19, 2026 12:28
@JusterZhu JusterZhu self-assigned this Jun 19, 2026
@JusterZhu JusterZhu added the refactor Refactor some existing code. label Jun 19, 2026
@JusterZhu

Copy link
Copy Markdown
Collaborator Author

All 5 Copilot review suggestions have been addressed across 4 fix commits:

# Suggestion Fix commit Status
1 SemVersion? lifted > operator → bool? in Where(...) e8832c32 — extracted .Value before comparison
2 Missing using System.Linq for string.All() 840fe535 — added using System.Linq to all 3 Semver.cs
3 Same as #2 for Extension copy 840fe535
4 Same as #2 for Drivelution copy 840fe535
5 SemVersion? >= SemVersion?bool? in IsCompatible e8832c32 — used .Value on both sides

Additional fixes:

  • SysNumOverflow only checks MAJOR.MINOR.PATCH triplet (not prerelease/build metadata) — 3a4c9672
  • Drivelution tests updated for aligned Semver semantics — 32bd4533

CI is now ✅ green.

@JusterZhu JusterZhu disabled auto-merge June 19, 2026 12:34
@JusterZhu JusterZhu merged commit ce75818 into master Jun 19, 2026
3 checks passed
@JusterZhu JusterZhu deleted the fix/semver2.0-alignment branch June 19, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactor some existing code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: align all components to SemVer 2.0 for version comparison

2 participants