From 4e1e418c5c17440d2aded1205446ec19188ac2ee Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Tue, 17 Dec 2024 09:27:25 +0100 Subject: [PATCH] fix: fewer version warnings (#26942) --- .../versionCheckerLogic.test.ts | 41 +++++++++++-------- .../VersionChecker/versionCheckerLogic.ts | 19 ++++----- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts index 103e89b2bfed9..77e7e0e9eb52e 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts @@ -73,35 +73,41 @@ describe('versionCheckerLogic', () => { { versionCount: 1, expectation: null }, { versionCount: 11, + expectation: null, + }, + { + versionCount: 51, expectation: { latestUsedVersion: '1.0.0', - latestAvailableVersion: '1.0.10', - numVersionsBehind: 10, - level: 'info', + latestAvailableVersion: '1.0.50', + numVersionsBehind: 50, + level: 'error', }, }, { - versionCount: 15, + minorUsedVersion: 40, + versionCount: 1, expectation: { latestUsedVersion: '1.0.0', - latestAvailableVersion: '1.0.14', - numVersionsBehind: 14, - level: 'info', + latestAvailableVersion: '1.40.0', + numVersionsBehind: 40, + level: 'warning', }, }, { - versionCount: 25, + majorUsedVersion: 2, + versionCount: 1, expectation: { latestUsedVersion: '1.0.0', - latestAvailableVersion: '1.0.24', - numVersionsBehind: 24, - level: 'error', + latestAvailableVersion: '2.0.0', + numVersionsBehind: 1, + level: 'info', }, }, ])('return a version warning if diff is great enough', async (options) => { // TODO: How do we clear the persisted value? const versionsList = Array.from({ length: options.versionCount }, (_, i) => ({ - version: `1.0.${i}`, + version: `${options.majorUsedVersion || 1}.${options.minorUsedVersion || 0}.${i}`, })).reverse() useMockedVersions( @@ -143,13 +149,14 @@ describe('versionCheckerLogic', () => { }, { usedVersions: [ - { version: '1.80.0', timestamp: '2023-01-01T12:00:00Z' }, - { version: '1.83.1-beta', timestamp: '2023-01-01T10:00:00Z' }, - { version: '1.84.0-delta', timestamp: '2023-01-01T08:00:00Z' }, + { version: '1.40.0', timestamp: '2023-01-01T12:00:00Z' }, + { version: '1.41.1-beta', timestamp: '2023-01-01T10:00:00Z' }, + { version: '1.42.0', timestamp: '2023-01-01T08:00:00Z' }, + { version: '1.42.0-delta', timestamp: '2023-01-01T08:00:00Z' }, ], expectation: { - latestUsedVersion: '1.84.0-delta', - numVersionsBehind: 1, + latestUsedVersion: '1.42.0', + numVersionsBehind: 42, latestAvailableVersion: '1.84.0', level: 'warning', }, diff --git a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts index 7ffecbbf89c82..4c6067adf4afc 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts @@ -174,6 +174,7 @@ export const versionCheckerLogic = kea([ if (!warning && sdkVersions && latestAvailableVersion) { const diff = diffVersions(latestAvailableVersion, latestUsedVersion) + if (diff && diff.diff > 0) { // there's a difference between the latest used version and the latest available version @@ -188,18 +189,14 @@ export const versionCheckerLogic = kea([ } let level: 'warning' | 'info' | 'error' | undefined - if (diff.kind === 'major' || numVersionsBehind >= 20) { + if (diff.kind === 'major') { + level = 'info' // it is desirable to be on the latest major version, but not critical + } else if (diff.kind === 'minor') { + level = numVersionsBehind >= 40 ? 'warning' : undefined + } + + if (level === undefined && numVersionsBehind >= 50) { level = 'error' - } else if (diff.kind === 'minor' && diff.diff >= 15) { - level = 'warning' - } else if ((diff.kind === 'minor' && diff.diff >= 10) || numVersionsBehind >= 10) { - level = 'info' - } else if (latestUsedVersion.extra) { - // if we have an extra (alpha/beta/rc/etc.) version, we should always show a warning if they aren't on the latest - level = 'warning' - } else { - // don't warn for a small number of patch versions behind - level = undefined } // we check if there is a "latest user version string" to avoid returning odd data in unexpected cases