Files
mirror-3x-ui/frontend/src/test/panel-version.test.ts
T
Kuzz007 814369da38 fix(panel): recognize this fork's -awg.N tags in version comparison
internal/config/version was never bumped past 3.5.0 when v3.5.0-awg.1 was
tagged, so a freshly-updated panel kept reporting its own version as the
plain upstream base. On top of that, parseVersionParts (Go and its
TypeScript mirror) required exactly 3 dot-separated numeric parts, so it
rejected the -awg.N suffix entirely and fell back to a raw string
inequality that reports "update available" any time the strings merely
differ -- which they always do here, even when already on the latest tag.

Bump the embedded version to 3.5.0-awg.1 and extend both parsers to treat
"-awg.N" as an optional 4th, lower-priority component (defaulting to 0 for
a plain tag), so e.g. 3.5.0-awg.2 > 3.5.0-awg.1 > 3.5.0 and a matching tag
compares equal instead of always looking outdated.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-26 12:42:20 +03:00

69 lines
2.8 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { formatPanelVersion, isPanelUpdateAvailable } from '@/lib/panel-version';
// Parity with web/service/panel.go isNewerVersion.
describe('isPanelUpdateAvailable', () => {
it('flags a strictly newer latest', () => {
expect(isPanelUpdateAvailable('2.6.5', '2.6.4')).toBe(true);
expect(isPanelUpdateAvailable('v2.7.0', 'v2.6.9')).toBe(true);
expect(isPanelUpdateAvailable('3.0.0', '2.9.9')).toBe(true);
});
it('returns false when equal or the node is ahead', () => {
expect(isPanelUpdateAvailable('2.6.4', '2.6.4')).toBe(false);
expect(isPanelUpdateAvailable('v2.6.4', '2.6.4')).toBe(false);
expect(isPanelUpdateAvailable('2.6.4', '2.6.5')).toBe(false);
});
it('ignores a leading v on either side', () => {
expect(isPanelUpdateAvailable('v2.6.5', '2.6.4')).toBe(true);
expect(isPanelUpdateAvailable('2.6.5', 'v2.6.4')).toBe(true);
});
it('never flags when a version is unknown', () => {
expect(isPanelUpdateAvailable('', '2.6.4')).toBe(false);
expect(isPanelUpdateAvailable('2.6.5', '')).toBe(false);
});
it('falls back to string inequality for non-semver tags', () => {
expect(isPanelUpdateAvailable('nightly-2', 'nightly-1')).toBe(true);
expect(isPanelUpdateAvailable('nightly-1', 'nightly-1')).toBe(false);
});
// Parity with web/service/panel.go TestIsNewerVersionAwgSuffix -- this
// fork's own "-awg.N" release tags (see internal/config/version).
it('handles this fork\'s -awg.N release tags', () => {
expect(isPanelUpdateAvailable('v3.5.0-awg.1', '3.5.0-awg.1')).toBe(false);
expect(isPanelUpdateAvailable('v3.5.0-awg.2', '3.5.0-awg.1')).toBe(true);
expect(isPanelUpdateAvailable('v3.5.0-awg.1', '3.5.0-awg.2')).toBe(false);
expect(isPanelUpdateAvailable('v3.5.0-awg.1', '3.5.0')).toBe(true);
expect(isPanelUpdateAvailable('v3.5.0', '3.5.0-awg.1')).toBe(false);
expect(isPanelUpdateAvailable('v3.6.0', '3.5.0-awg.1')).toBe(true);
expect(isPanelUpdateAvailable('v3.5.0-awg.1', '3.6.0')).toBe(false);
});
});
describe('formatPanelVersion', () => {
it('adds a single v prefix to bare semantic versions', () => {
expect(formatPanelVersion('3.4.0')).toBe('v3.4.0');
expect(formatPanelVersion('2.6.5')).toBe('v2.6.5');
});
it('does not double up the v on already-prefixed tags', () => {
expect(formatPanelVersion('v3.4.0')).toBe('v3.4.0');
expect(formatPanelVersion('V3.4.0')).toBe('v3.4.0');
});
it('shows dev builds verbatim without a v prefix', () => {
expect(formatPanelVersion('dev+1a2b3c4d')).toBe('dev+1a2b3c4d');
expect(formatPanelVersion('dev')).toBe('dev');
});
it('returns empty for blank input and leaves unknown markers untouched', () => {
expect(formatPanelVersion('')).toBe('');
expect(formatPanelVersion(undefined)).toBe('');
expect(formatPanelVersion('?')).toBe('?');
});
});