Skip to content

Commit c15f26c

Browse files
authored
fix(native): strip pre-release suffix in semverCompare (#898)
`semverCompare('3.9.3-dev.6', '3.9.1')` returned -1 (less than) because `Number('3-dev')` is NaN, which the `|| 0` fallback turned into 0, making the comparison `0 < 1`. This caused `shouldSkipNativeOrchestrator` to flag all pre-release builds as "buggy", disabling the native orchestrator fast path introduced in #897. Strip `-<prerelease>` before splitting on `.` so the numeric comparison sees `3.9.3` vs `3.9.1` correctly.
1 parent 4a44d5e commit c15f26c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/infrastructure/update-check.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ interface UpdateCache {
1818

1919
/**
2020
* Minimal semver comparison. Returns -1, 0, or 1.
21-
* Only handles numeric x.y.z (no pre-release tags).
21+
* Strips pre-release suffixes (e.g. "3.9.3-dev.6" → "3.9.3") before comparing.
2222
*/
2323
export function semverCompare(a: string, b: string): -1 | 0 | 1 {
24-
const pa = a.split('.').map(Number);
25-
const pb = b.split('.').map(Number);
24+
const pa = a.replace(/-.*$/, '').split('.').map(Number);
25+
const pb = b.replace(/-.*$/, '').split('.').map(Number);
2626
for (let i = 0; i < 3; i++) {
2727
const na = pa[i] || 0;
2828
const nb = pb[i] || 0;

tests/unit/update-check.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ describe('semverCompare', () => {
5151
it('major takes priority over minor and patch', () => {
5252
expect(semverCompare('1.9.9', '2.0.0')).toBe(-1);
5353
});
54+
55+
it('strips pre-release suffixes before comparing', () => {
56+
// 3.9.3-dev.6 should be treated as 3.9.3, which is > 3.9.1
57+
expect(semverCompare('3.9.3-dev.6', '3.9.1')).toBe(1);
58+
expect(semverCompare('3.9.3-dev.6', '3.9.3')).toBe(0);
59+
expect(semverCompare('3.9.3-dev.6', '3.9.4')).toBe(-1);
60+
// Both sides with pre-release
61+
expect(semverCompare('2.0.0-beta.1', '1.9.9-alpha.3')).toBe(1);
62+
});
5463
});
5564

5665
// ─── checkForUpdates ────────────────────────────────────────────────

0 commit comments

Comments
 (0)