From 5809a390e371386ce42853976d25dc0773cfef1a Mon Sep 17 00:00:00 2001 From: Neil Kakkar Date: Thu, 19 Oct 2023 11:56:47 +0100 Subject: [PATCH 1/3] fix(version-checker): Use latest semantic version --- .../versionCheckerLogic.test.ts | 38 +++++++++++++++++++ .../VersionChecker/versionCheckerLogic.ts | 12 ++++-- 2 files changed, 46 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..f397aa27ced78 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts @@ -105,4 +105,42 @@ 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.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..9401d5bb3aa29 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts @@ -88,18 +88,22 @@ 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 + 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', From 468d3e2215940386ef932105a1030bfd524d4407 Mon Sep 17 00:00:00 2001 From: Neil Kakkar Date: Thu, 19 Oct 2023 12:00:07 +0100 Subject: [PATCH 2/3] elaborate --- .../src/lib/components/VersionChecker/versionCheckerLogic.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts index 9401d5bb3aa29..acc1897bc78f2 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts @@ -89,7 +89,9 @@ export const versionCheckerLogic = kea([ const latestVersion = values.availableVersions[0].version - // reverse sort, hence reversed arguments to localeCompare + // 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 From 8d03dfd31727abe1b8e3f4b4c33c7b4ac3323b92 Mon Sep 17 00:00:00 2001 From: Neil Kakkar Date: Thu, 19 Oct 2023 12:07:11 +0100 Subject: [PATCH 3/3] more version nums for funsies --- .../lib/components/VersionChecker/versionCheckerLogic.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts index f397aa27ced78..22431153935d2 100644 --- a/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts +++ b/frontend/src/lib/components/VersionChecker/versionCheckerLogic.test.ts @@ -123,6 +123,10 @@ describe('versionCheckerLogic', () => { 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,