Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
feat(shared): support shorthand (major-only) versions in the semver helpers (#5027)
Arham Amin063ed7120a17
diff --git a/packages/shared/src/semver.test.ts b/packages/shared/src/semver.test.tsindex 8cbbc150f..ed3e1896a 100644--- a/packages/shared/src/semver.test.ts+++ b/packages/shared/src/semver.test.ts@@ -1,6 +1,11 @@import { describe, expect, it } from "vite-plus/test";-import { compareSemverVersions, normalizeSemverVersion, satisfiesSemverRange } from "./semver.ts";+import {+ compareSemverVersions,+ normalizeSemverVersion,+ parseSemver,+ satisfiesSemverRange,+} from "./semver.ts";describe("semver helpers", () => {it("matches supported range groups", () => {@@ -18,6 +23,25 @@ describe("semver helpers", () => {expect(normalizeSemverVersion("2.1")).toBe("2.1.0");});+ it("normalizes and parses shorthand major-only versions", () => {+ expect(normalizeSemverVersion("20")).toBe("20.0.0");+ expect(normalizeSemverVersion("v18")).toBe("v18.0.0");+ expect(normalizeSemverVersion("20-rc.1")).toBe("20.0.0-rc.1");+ expect(parseSemver("20")).toEqual({ major: 20, minor: 0, patch: 0, prerelease: [] });+ });++ it("compares shorthand versions numerically instead of lexically", () => {+ // Regression: "20" vs "9" previously fell back to string comparison, which+ // ordered "20" before "9" ("2" < "9").+ expect(compareSemverVersions("20", "9")).toBeGreaterThan(0);+ expect(compareSemverVersions("18", "18.0.0")).toBe(0);+ });++ it("still rejects non-numeric shorthand and keeps empty input empty", () => {+ expect(parseSemver("abc")).toBeNull();+ expect(normalizeSemverVersion("")).toBe("");+ });+it("compares prerelease versions before stable versions", () => {expect(compareSemverVersions("2.1.111-beta.1", "2.1.111")).toBeLessThan(0);});diff --git a/packages/shared/src/semver.ts b/packages/shared/src/semver.tsindex 1a73e3304..a765b065f 100644--- a/packages/shared/src/semver.ts+++ b/packages/shared/src/semver.ts@@ -17,7 +17,12 @@ export function normalizeSemverVersion(version: string): string {}}- if (segments.length === 2) {+ // Pad shorthand versions ("20" or "20.1") up to three segments so major-only+ // and minor-only inputs parse and compare numerically. This matches+ // satisfiesSemverRange, which already treats a missing minor/patch as 0. The+ // length > 0 guard keeps empty/garbage input empty (parseSemver still+ // rejects it), and inputs with more than three segments are left untouched.+ while (segments.length > 0 && segments.length < 3) {segments.push("0");}