From ddd58f628ffa70fbd2bb6c4c06e2082ad083a54e Mon Sep 17 00:00:00 2001 From: Mac Date: Fri, 1 May 2026 12:03:24 -0600 Subject: [PATCH] feat(protocol): add current_patch_number to PatchCheckRequest (#3702) --- .../patch_check/patch_check_request.dart | 15 +++++++- .../patch_check/patch_check_request_test.dart | 38 +++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/patch_check/patch_check_request.dart b/packages/shorebird_code_push_protocol/lib/src/messages/patch_check/patch_check_request.dart index 88688cd1..393ced9c 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/patch_check/patch_check_request.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/patch_check/patch_check_request.dart @@ -17,6 +17,7 @@ class PatchCheckRequest { this.patchNumber, this.patchHash, this.clientId, + this.currentPatchNumber, }); /// Converts a `Map` to a [PatchCheckRequest]. @@ -33,6 +34,7 @@ class PatchCheckRequest { appId: json['app_id'] as String, channel: json['channel'] as String, clientId: json['client_id'] as String?, + currentPatchNumber: json['current_patch_number'] as int?, ), ); } @@ -73,6 +75,14 @@ class PatchCheckRequest { /// unique per app. Optional for backward compatibility. final String? clientId; + /// The number of the patch currently running on the device, if any. + /// + /// Supersedes [patchNumber] for newer updater clients. Unlike + /// [patchNumber], this does not affect the server's response; + /// [patchNumber] is retained for compatibility with legacy clients that + /// rely on the server's short-circuit path. + final int? currentPatchNumber; + /// Converts a [PatchCheckRequest] to a `Map`. Map toJson() { return { @@ -84,6 +94,7 @@ class PatchCheckRequest { 'app_id': appId, 'channel': channel, 'client_id': clientId, + 'current_patch_number': currentPatchNumber, }; } @@ -97,6 +108,7 @@ class PatchCheckRequest { appId, channel, clientId, + currentPatchNumber, ]); @override @@ -110,6 +122,7 @@ class PatchCheckRequest { arch == other.arch && appId == other.appId && channel == other.channel && - clientId == other.clientId; + clientId == other.clientId && + currentPatchNumber == other.currentPatchNumber; } } diff --git a/packages/shorebird_code_push_protocol/test/src/messages/patch_check/patch_check_request_test.dart b/packages/shorebird_code_push_protocol/test/src/messages/patch_check/patch_check_request_test.dart index 620f0d53..747b70bd 100644 --- a/packages/shorebird_code_push_protocol/test/src/messages/patch_check/patch_check_request_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/messages/patch_check/patch_check_request_test.dart @@ -3,8 +3,27 @@ import 'package:test/test.dart'; void main() { group(PatchCheckRequest, () { + const request = PatchCheckRequest( + releaseVersion: '1', + patchNumber: 2, + patchHash: '3', + platform: ReleasePlatform.android, + arch: 'arm64', + appId: 'app_123', + channel: 'channel_123', + clientId: 'client_123', + currentPatchNumber: 4, + ); + test('can be (de)serialized', () { - const request = PatchCheckRequest( + expect( + PatchCheckRequest.fromJson(request.toJson()).toJson(), + equals(request.toJson()), + ); + }); + + test('is equatable', () { + const copy = PatchCheckRequest( releaseVersion: '1', patchNumber: 2, patchHash: '3', @@ -13,11 +32,22 @@ void main() { appId: 'app_123', channel: 'channel_123', clientId: 'client_123', + currentPatchNumber: 4, ); - expect( - PatchCheckRequest.fromJson(request.toJson()).toJson(), - equals(request.toJson()), + const different = PatchCheckRequest( + releaseVersion: '1', + patchNumber: 2, + patchHash: '3', + platform: ReleasePlatform.android, + arch: 'arm64', + appId: 'app_123', + channel: 'channel_123', + clientId: 'client_123', + currentPatchNumber: 5, ); + + expect(request, equals(copy)); + expect(request, isNot(equals(different))); }); }); }