Repository navigation
fix(updater): compare semver prereleases by numeric core #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
VickyXAI
merged 2 commits into
BlockRunAI:main
from
Tyagiquamar:fix/w2-updater-semver-prerelease
Nov 18, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { compareSemver } from "./updater.js"; | ||
| import { VERSION } from "./version.js"; | ||
|
|
||
| describe("compareSemver", () => { | ||
| it("orders numeric releases", () => { | ||
| expect(compareSemver("0.12.315", "0.12.314")).toBe(1); | ||
| expect(compareSemver("0.12.314", "0.12.315")).toBe(-1); | ||
| expect(compareSemver("1.0.0", "0.99.99")).toBe(1); | ||
| expect(compareSemver("0.12.315", "0.12.315")).toBe(0); | ||
| }); | ||
|
|
||
| it("compares a prerelease by its numeric core", () => { | ||
| expect(compareSemver("0.12.316-rc.1", "0.12.315")).toBe(1); | ||
| expect(compareSemver("1.2.0-beta.3", "1.1.9")).toBe(1); | ||
| expect(compareSemver("0.12.316+build.7", "0.12.315")).toBe(1); | ||
| expect(compareSemver("0.12.315-rc.1", "0.12.315")).toBe(0); | ||
| }); | ||
|
|
||
| it("treats missing segments as zero", () => { | ||
| expect(compareSemver("1.2", "1.2.0")).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| /** | ||
| * The startup update hint compares the npm `latest` version with the installed | ||
| * one. A version carrying a prerelease suffix (for example 0.12.316-rc.1) used | ||
| * to be parsed as patch 0, so a newer prerelease looked older than the installed | ||
| * stable release and no hint was printed. | ||
| */ | ||
| describe("checkForUpdates version comparison", () => { | ||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| async function runWithLatest(latest: string): Promise<string[]> { | ||
| const lines: string[] = []; | ||
| vi.spyOn(console, "log").mockImplementation((...args: unknown[]) => { | ||
| lines.push(args.map(String).join(" ")); | ||
| }); | ||
| vi.stubGlobal( | ||
| "fetch", | ||
| vi.fn().mockResolvedValue({ | ||
| ok: true, | ||
| json: async () => ({ version: latest }), | ||
| }), | ||
| ); | ||
| const { checkForUpdates } = await import("./updater.js"); | ||
| await checkForUpdates(); | ||
| return lines; | ||
| } | ||
|
|
||
| it("prints a hint for a newer stable release", async () => { | ||
| const [major, minor, patch] = (VERSION.split(/[+-]/, 1)[0] ?? "").split(".").map(Number); | ||
| const newer = `${major}.${minor}.${patch + 1}`; | ||
| const lines = await runWithLatest(newer); | ||
| expect(lines.some((line) => line.includes(`${newer} available`))).toBe(true); | ||
| }); | ||
|
|
||
| it("prints a hint for a newer prerelease instead of treating its patch as zero", async () => { | ||
| const [major, minor, patch] = (VERSION.split(/[+-]/, 1)[0] ?? "").split(".").map(Number); | ||
| const newerPrerelease = `${major}.${minor}.${patch + 1}-rc.1`; | ||
| const lines = await runWithLatest(newerPrerelease); | ||
| expect(lines.some((line) => line.includes(`${newerPrerelease} available`))).toBe(true); | ||
| }); | ||
|
|
||
| it("prints no hint for the installed version", async () => { | ||
| const lines = await runWithLatest(VERSION); | ||
| expect(lines.some((line) => line.includes("available"))).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decide whether a stable release that matches the installed prerelease core should show the update hint.
This change removes the hint for one case that the base code printed. When the installed version is
0.12.315-rc.1and npmlatestis0.12.315, both versions reduce to the core0.12.315.compareSemverreturns0, socheckForUpdatesdoes not print the hint. The base code printed it. Under SemVer precedence, the stable0.12.315is newer than the prerelease, so users on the prerelease no longer receive the upgrade prompt.The new test at
src/updater.semver.test.ts:18asserts the equality result for this pair. If equality is the intended behavior, keep the assertion and document the case. If the hint must appear, the comparison needs a tie-break that ranks a stable release above a prerelease with the same core. In that case, update the assertion at line 18 with the new behavior and add a startup test for the installed-prerelease direction.