From 6089ef4c9bb7be33b9d07f2538de56bfe2850cf4 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov <92646230+Slava-Shchipunov@users.noreply.github.com> Date: Tue, 12 May 2026 23:31:43 +0700 Subject: [PATCH] Fix/fix version check (#278) --- .../src/helpers/removeVersionPrefix.ts | 3 + .../diagnostic/helpers/getPodkopVersionRow.ts | 52 ++++++++++++ .../podkop/tabs/diagnostic/initController.ts | 48 +---------- .../tests/getPodkopVersionRow.test.ts | 69 +++++++++++++++ .../luci-static/resources/view/podkop/main.js | 83 ++++++++++--------- 5 files changed, 170 insertions(+), 85 deletions(-) create mode 100644 fe-app-podkop/src/helpers/removeVersionPrefix.ts create mode 100644 fe-app-podkop/src/podkop/tabs/diagnostic/helpers/getPodkopVersionRow.ts create mode 100644 fe-app-podkop/src/podkop/tabs/diagnostic/tests/getPodkopVersionRow.test.ts diff --git a/fe-app-podkop/src/helpers/removeVersionPrefix.ts b/fe-app-podkop/src/helpers/removeVersionPrefix.ts new file mode 100644 index 0000000..6a4d7d8 --- /dev/null +++ b/fe-app-podkop/src/helpers/removeVersionPrefix.ts @@ -0,0 +1,3 @@ +export function removeVersionPrefix(version: string) { + return version.replace(/^v/, ''); +} diff --git a/fe-app-podkop/src/podkop/tabs/diagnostic/helpers/getPodkopVersionRow.ts b/fe-app-podkop/src/podkop/tabs/diagnostic/helpers/getPodkopVersionRow.ts new file mode 100644 index 0000000..32b0688 --- /dev/null +++ b/fe-app-podkop/src/podkop/tabs/diagnostic/helpers/getPodkopVersionRow.ts @@ -0,0 +1,52 @@ +import { normalizeCompiledVersion } from '../../../../helpers/normalizeCompiledVersion'; +import { removeVersionPrefix } from '../../../../helpers/removeVersionPrefix'; +import type { StoreType } from '../../../services/store.service'; +import type { IRenderSystemInfoRow } from '../partials'; + +function isUnknownVersion(version?: string | null): boolean { + return version === 'unknown' || version === _('unknown'); +} + +export function getPodkopVersionRow( + diagnosticsSystemInfo: StoreType['diagnosticsSystemInfo'], +): IRenderSystemInfoRow { + const loading = diagnosticsSystemInfo.loading; + const unknown = isUnknownVersion(diagnosticsSystemInfo.podkop_version); + const hasActualVersion = + Boolean(diagnosticsSystemInfo.podkop_latest_version) && + !isUnknownVersion(diagnosticsSystemInfo.podkop_latest_version); + const version = normalizeCompiledVersion( + diagnosticsSystemInfo.podkop_version, + ); + const isDevVersion = version === 'dev'; + + if (loading || unknown || !hasActualVersion || isDevVersion) { + return { + key: 'Podkop', + value: version, + }; + } + + if ( + removeVersionPrefix(version) !== + removeVersionPrefix(diagnosticsSystemInfo.podkop_latest_version) + ) { + return { + key: 'Podkop', + value: version, + tag: { + label: _('Outdated'), + kind: 'warning', + }, + }; + } + + return { + key: 'Podkop', + value: version, + tag: { + label: _('Latest'), + kind: 'success', + }, + }; +} diff --git a/fe-app-podkop/src/podkop/tabs/diagnostic/initController.ts b/fe-app-podkop/src/podkop/tabs/diagnostic/initController.ts index 305168e..7ef08cd 100644 --- a/fe-app-podkop/src/podkop/tabs/diagnostic/initController.ts +++ b/fe-app-podkop/src/podkop/tabs/diagnostic/initController.ts @@ -6,7 +6,6 @@ import { runFakeIPCheck } from './checks/runFakeIPCheck'; import { loadingDiagnosticsChecksStore } from './diagnostic.store'; import { logger, store, StoreType } from '../../services'; import { - IRenderSystemInfoRow, renderAvailableActions, renderCheckSection, renderRunAction, @@ -20,6 +19,7 @@ import { PODKOP_LUCI_APP_VERSION } from '../../../constants'; import { showToast } from '../../../helpers/showToast'; import { renderWikiDisclaimer } from './partials/renderWikiDisclaimer'; import { runSectionsCheck } from './checks/runSectionsCheck'; +import { getPodkopVersionRow } from './helpers/getPodkopVersionRow'; async function fetchSystemInfo() { const systemInfo = await PodkopShellMethods.getSystemInfo(); @@ -415,53 +415,9 @@ function renderDiagnosticSystemInfoWidget() { const container = document.getElementById('pdk_diagnostic-page-system-info'); - function getPodkopVersionRow(): IRenderSystemInfoRow { - const loading = diagnosticsSystemInfo.loading; - const unknown = diagnosticsSystemInfo.podkop_version === _('unknown'); - const hasActualVersion = - Boolean(diagnosticsSystemInfo.podkop_latest_version) && - diagnosticsSystemInfo.podkop_latest_version !== 'unknown'; - const version = normalizeCompiledVersion( - diagnosticsSystemInfo.podkop_version, - ); - const isDevVersion = version === 'dev'; - - if (loading || unknown || !hasActualVersion || isDevVersion) { - return { - key: 'Podkop', - value: version, - }; - } - - if (version !== diagnosticsSystemInfo.podkop_latest_version) { - logger.debug( - '[DIAGNOSTIC]', - 'diagnosticsSystemInfo', - diagnosticsSystemInfo, - ); - return { - key: 'Podkop', - value: version, - tag: { - label: _('Outdated'), - kind: 'warning', - }, - }; - } - - return { - key: 'Podkop', - value: version, - tag: { - label: _('Latest'), - kind: 'success', - }, - }; - } - const renderedSystemInfo = renderSystemInfo({ items: [ - getPodkopVersionRow(), + getPodkopVersionRow(diagnosticsSystemInfo), { key: 'Luci App', value: normalizeCompiledVersion(PODKOP_LUCI_APP_VERSION), diff --git a/fe-app-podkop/src/podkop/tabs/diagnostic/tests/getPodkopVersionRow.test.ts b/fe-app-podkop/src/podkop/tabs/diagnostic/tests/getPodkopVersionRow.test.ts new file mode 100644 index 0000000..88642f4 --- /dev/null +++ b/fe-app-podkop/src/podkop/tabs/diagnostic/tests/getPodkopVersionRow.test.ts @@ -0,0 +1,69 @@ +import { describe, expect, it } from 'vitest'; +import { getPodkopVersionRow } from '../helpers/getPodkopVersionRow'; +import type { StoreType } from '../../../services/store.service'; + +function makeDiagnosticsSystemInfo( + patch: Partial = {}, +): StoreType['diagnosticsSystemInfo'] { + return { + loading: false, + podkop_version: '1.2.3', + podkop_latest_version: '1.2.3', + luci_app_version: '1.0.0', + sing_box_version: '1.11.0', + openwrt_version: 'OpenWrt 25.12', + device_model: 'Test Router', + ...patch, + }; +} + +describe('getPodkopVersionRow', () => { + it('returns Latest when versions differ only by leading v', () => { + const row = getPodkopVersionRow( + makeDiagnosticsSystemInfo({ + podkop_version: 'v1.2.3', + podkop_latest_version: '1.2.3', + }), + ); + + expect(row).toEqual({ + key: 'Podkop', + value: 'v1.2.3', + tag: { + label: 'Latest', + kind: 'success', + }, + }); + }); + + it('returns Outdated when versions differ', () => { + const row = getPodkopVersionRow( + makeDiagnosticsSystemInfo({ + podkop_version: '1.2.2', + podkop_latest_version: '1.2.3', + }), + ); + + expect(row).toEqual({ + key: 'Podkop', + value: '1.2.2', + tag: { + label: 'Outdated', + kind: 'warning', + }, + }); + }); + + it('returns plain row without tag for dev build', () => { + const row = getPodkopVersionRow( + makeDiagnosticsSystemInfo({ + podkop_version: 'COMPILED_VERSION', + }), + ); + + expect(row).toEqual({ + key: 'Podkop', + value: 'dev', + }); + }); +}); diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js index ad34948..f7b9eab 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js @@ -3925,6 +3925,49 @@ async function runSectionsCheck() { } } +// src/helpers/removeVersionPrefix.ts +function removeVersionPrefix(version) { + return version.replace(/^v/, ""); +} + +// src/podkop/tabs/diagnostic/helpers/getPodkopVersionRow.ts +function isUnknownVersion(version) { + return version === "unknown" || version === _("unknown"); +} +function getPodkopVersionRow(diagnosticsSystemInfo) { + const loading = diagnosticsSystemInfo.loading; + const unknown = isUnknownVersion(diagnosticsSystemInfo.podkop_version); + const hasActualVersion = Boolean(diagnosticsSystemInfo.podkop_latest_version) && !isUnknownVersion(diagnosticsSystemInfo.podkop_latest_version); + const version = normalizeCompiledVersion( + diagnosticsSystemInfo.podkop_version + ); + const isDevVersion = version === "dev"; + if (loading || unknown || !hasActualVersion || isDevVersion) { + return { + key: "Podkop", + value: version + }; + } + if (removeVersionPrefix(version) !== removeVersionPrefix(diagnosticsSystemInfo.podkop_latest_version)) { + return { + key: "Podkop", + value: version, + tag: { + label: _("Outdated"), + kind: "warning" + } + }; + } + return { + key: "Podkop", + value: version, + tag: { + label: _("Latest"), + kind: "success" + } + }; +} + // src/podkop/tabs/diagnostic/initController.ts async function fetchSystemInfo() { const systemInfo = await PodkopShellMethods.getSystemInfo(); @@ -4272,47 +4315,9 @@ function renderDiagnosticSystemInfoWidget() { logger.debug("[DIAGNOSTIC]", "renderDiagnosticSystemInfoWidget"); const diagnosticsSystemInfo = store.get().diagnosticsSystemInfo; const container = document.getElementById("pdk_diagnostic-page-system-info"); - function getPodkopVersionRow() { - const loading = diagnosticsSystemInfo.loading; - const unknown = diagnosticsSystemInfo.podkop_version === _("unknown"); - const hasActualVersion = Boolean(diagnosticsSystemInfo.podkop_latest_version) && diagnosticsSystemInfo.podkop_latest_version !== "unknown"; - const version = normalizeCompiledVersion( - diagnosticsSystemInfo.podkop_version - ); - const isDevVersion = version === "dev"; - if (loading || unknown || !hasActualVersion || isDevVersion) { - return { - key: "Podkop", - value: version - }; - } - if (version !== diagnosticsSystemInfo.podkop_latest_version) { - logger.debug( - "[DIAGNOSTIC]", - "diagnosticsSystemInfo", - diagnosticsSystemInfo - ); - return { - key: "Podkop", - value: version, - tag: { - label: _("Outdated"), - kind: "warning" - } - }; - } - return { - key: "Podkop", - value: version, - tag: { - label: _("Latest"), - kind: "success" - } - }; - } const renderedSystemInfo = renderSystemInfo({ items: [ - getPodkopVersionRow(), + getPodkopVersionRow(diagnosticsSystemInfo), { key: "Luci App", value: normalizeCompiledVersion(PODKOP_LUCI_APP_VERSION)