From 61b8070626970ece53a01a52494d164d14410554 Mon Sep 17 00:00:00 2001 From: jubnl Date: Thu, 16 Apr 2026 14:58:38 +0200 Subject: [PATCH] fix(system-notices): coerce prerelease app version before semver comparison --- server/src/systemNotices/conditions.ts | 4 +++- server/tests/unit/systemNotices/conditions.test.ts | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/systemNotices/conditions.ts b/server/src/systemNotices/conditions.ts index 616301a3..97dd3eac 100644 --- a/server/src/systemNotices/conditions.ts +++ b/server/src/systemNotices/conditions.ts @@ -30,9 +30,11 @@ function evaluateOne(condition: NoticeCondition, ctx: ConditionContext): boolean const userVersion = semver.valid(ctx.user.first_seen_version) ?? '0.0.0'; const noticeVersion = semver.valid(condition.version); if (!noticeVersion) return false; + // Strip prerelease/build metadata so '3.0.0-pre.42' is treated as '3.0.0'. + const appVersion = semver.coerce(ctx.currentAppVersion)?.version ?? '0.0.0'; return ( semver.lt(userVersion, noticeVersion) && - semver.gte(semver.valid(ctx.currentAppVersion) ?? '0.0.0', noticeVersion) + semver.gte(appVersion, noticeVersion) ); } diff --git a/server/tests/unit/systemNotices/conditions.test.ts b/server/tests/unit/systemNotices/conditions.test.ts index 60f99fa2..de496180 100644 --- a/server/tests/unit/systemNotices/conditions.test.ts +++ b/server/tests/unit/systemNotices/conditions.test.ts @@ -40,6 +40,12 @@ describe('existingUserBeforeVersion', () => { it('fails when current app version < notice version', () => { expect(evaluate(notice, { ...baseCtx, currentAppVersion: '1.5.0' })).toBe(false); }); + it('passes when current app version is a prerelease of the notice version', () => { + expect(evaluate(notice, { ...baseCtx, currentAppVersion: '2.0.0-pre.42' })).toBe(true); + }); + it('passes when current app version is a prerelease beyond the notice version', () => { + expect(evaluate(notice, { ...baseCtx, currentAppVersion: '2.1.0-pre.1' })).toBe(true); + }); }); describe('dateWindow', () => {