Treat a pre-release server as below its release

This commit is contained in:
Roland Geider
2026-09-08 08:59:16 +02:00
parent 9128ddad41
commit 104b4ee71b
3 changed files with 40 additions and 16 deletions

View File

@@ -24,6 +24,20 @@ import 'package:material_ui/material_ui.dart';
/// Bump this value whenever you depend on API changes that are only available
/// in a newer server release. The check is performed during login and
/// auto-login and mirrors what the server does with MIN_APP_VERSION.
///
/// A pre-release is lower than its release, so the spelling decides the
/// meaning:
///
/// '2.8.0-dev.3' at least that point of the 2.8 development cycle
/// '2.8.0' the finished 2.8 or newer, no development server
/// '2.8' the same as '2.8.0'
///
/// While 2.8 is unreleased, only the first form is safe. wger runs master
/// and reports as e.g. 2.8.0-dev.N, so '2.8' would lock the app out of it
/// and out of every self hosted instance following latest, for the whole cycle.
///
/// Count with a dot: '2.8.0-dev.10' is above '2.8.0-dev.9', while
/// '2.8.0-dev10' would sort below '2.8.0-dev9'.
const MIN_SERVER_VERSION = '2.7';
/// Size for the "smaller" icons, e.g. when they belong to less important items

View File

@@ -247,8 +247,14 @@ class ServerGating {
/// equivalent so [Version] can parse it: '2.7.0a2' becomes '2.7.0-a2'.
/// Without this a pre-release below the minimum fails to parse and gets
/// waved through by the lenient fallback.
///
/// A post release carries everything its final release has, so that segment
/// is removed rather than turned into a pre-release, which would sort it
/// below the release it follows.
String _toSemver(String rawVersion) {
final trimmed = rawVersion.replaceFirst(RegExp(r'\s.*$'), ''); // '2.7.0 (git-abc1234)'
final trimmed = rawVersion
.replaceFirst(RegExp(r'\s.*$'), '') // '2.7.0 (git-abc1234)'
.replaceFirst(RegExp(r'[.-]post\d*'), '');
final match = RegExp(r'^(\d+(?:\.\d+)*)(.*)$').firstMatch(trimmed);
if (match == null) {
@@ -261,8 +267,9 @@ String _toSemver(String rawVersion) {
}
/// Checks whether the connected server meets the minimum version required
/// by this build of the app. A pre-release counts as its release, since the
/// reference server runs master and reports 2.7.0a2 for the whole 2.7 cycle.
/// by this build of the app. A pre-release is below its release, so a server
/// in the middle of the 2.8 cycle does not satisfy a minimum of 2.8.0. See
/// [MIN_SERVER_VERSION] for how to spell the constant.
///
/// Returns false (lenient) when the version cannot be read or parsed, so
/// users aren't locked out on unexpected server configurations.
@@ -286,8 +293,7 @@ bool serverUpdateRequired(String? rawVersion) {
return false;
}
final required = Version.parse(MIN_SERVER_VERSION);
final currentRelease = Version(current.major, current.minor, current.patch);
final needUpdate = currentRelease < required;
final needUpdate = current < required;
if (needUpdate) {
logger.fine('Server update required: server $current < minimum $required');
}

View File

@@ -89,27 +89,31 @@ void main() {
expect(serverUpdateRequired('$belowMin.0 (git-abc1234)'), true);
});
test('alpha of the min version counts as that version, no update needed', () {
expect(serverUpdateRequired('$atMin.0a2'), false);
test('alpha of the min version is below it, update needed', () {
expect(serverUpdateRequired('$atMin.0a2'), true);
});
test('dev release of the min version counts as that version, no update needed', () {
expect(serverUpdateRequired('$atMin.0.dev0'), false);
test('dev release of the min version is below it, update needed', () {
expect(serverUpdateRequired('$atMin.0.dev0'), true);
});
test('release candidate of the min version counts as that version, no update needed', () {
expect(serverUpdateRequired('$atMin.0rc1'), false);
test('counted dev release of the min version is below it, update needed', () {
expect(serverUpdateRequired('$atMin.0-dev.3'), true);
});
test('semver spelled pre-release of the min version, no update needed', () {
expect(serverUpdateRequired('$atMin.0-alpha2'), false);
test('release candidate of the min version is below it, update needed', () {
expect(serverUpdateRequired('$atMin.0rc1'), true);
});
test('pre-release with git build metadata, no update needed', () {
expect(serverUpdateRequired('$atMin.0a2+git1234567'), false);
test('semver spelled pre-release of the min version, update needed', () {
expect(serverUpdateRequired('$atMin.0-alpha2'), true);
});
test('post release of the min version, no update needed', () {
test('pre-release with git build metadata, update needed', () {
expect(serverUpdateRequired('$atMin.0a2+git1234567'), true);
});
test('post release of the min version is not below it, no update needed', () {
expect(serverUpdateRequired('$atMin.0.post1'), false);
});