From b5c1ed6f9e959c4475d07500f8956ff78748df1d Mon Sep 17 00:00:00 2001 From: Neil Kakkar Date: Thu, 19 Oct 2023 16:00:51 +0100 Subject: [PATCH] fix(version-checker): Use latest semantic version (#18085) * fix(version-checker): Use latest semantic version * elaborate * more version nums for funsies --- .../versionCheckerLogic.test.ts | 42 +++++++++++++++++++ .../VersionChecker/versionCheckerLogic.ts | 14 +++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts index 52cfe0740f596..22431153935d2 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts @@ -105,4 +105,46 @@ describe('versionCheckerLogic', () => { await expectLogic(logic).toFinishAllListeners() expectLogic(logic).toMatchValues({ versionWarning: options.expectation }) }) + + it.each([ + { + usedVersions: [ + { version: '1.9.0', timestamp: '2023-01-01T12:00:00Z' }, + { version: '1.83.1', timestamp: '2023-01-01T10:00:00Z' }, + ], + expectation: { + currentVersion: '1.83.1', + latestVersion: '1.84.0', + diff: 1, + level: 'info', + }, + }, + { + usedVersions: [ + { version: '1.80.0', timestamp: '2023-01-01T12:00:00Z' }, + { version: '1.83.1', timestamp: '2023-01-01T10:00:00Z' }, + { version: '1.20.1', timestamp: '2023-01-01T10:00:00Z' }, + { version: '1.0.890', timestamp: '2023-01-01T10:00:00Z' }, + { version: '0.89.5', timestamp: '2023-01-01T10:00:00Z' }, + { version: '0.0.5', timestamp: '2023-01-01T10:00:00Z' }, + { version: '1.84.0', timestamp: '2023-01-01T08:00:00Z' }, + ], + expectation: null, + }, + { + 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' }, + ], + expectation: { currentVersion: '1.84.0-delta', diff: 1, latestVersion: '1.84.0', level: 'info' }, + }, + ])('when having multiple versions used, should match with the latest one', async (options) => { + useMockedVersions([{ version: '1.84.0' }], options.usedVersions) + + logic.mount() + + await expectLogic(logic).toFinishAllListeners() + expectLogic(logic).toMatchValues({ versionWarning: options.expectation }) + }) }) diff --git a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts index e08b5c26da4cf..acc1897bc78f2 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts @@ -88,18 +88,24 @@ export const versionCheckerLogic = kea([ } const latestVersion = values.availableVersions[0].version - const currentVersion = values.usedVersions[0].version - if (latestVersion === currentVersion) { + // reverse sort, hence reversed arguments to localeCompare. + // We want the highest semantic version to be the latest used one, rather than + // the one with the latest timestamp, because secondary installations can spew old versions + const latestUsedVersion = [...values.usedVersions].sort((a, b) => + b.version.localeCompare(a.version, undefined, { numeric: true }) + )[0].version + + if (latestVersion === latestUsedVersion) { actions.setVersionWarning(null) return } - let diff = values.availableVersions.findIndex((v) => v.version === currentVersion) + let diff = values.availableVersions.findIndex((v) => v.version === latestUsedVersion) diff = diff === -1 ? values.availableVersions.length : diff const warning: SDKVersionWarning = { - currentVersion, + currentVersion: latestUsedVersion, latestVersion, diff, level: diff > 20 ? 'error' : diff > 10 ? 'warning' : 'info',