Microsoft Store sync: don't send an empty collections ID key

The Store returns an empty string, not an error, when it can't make one
(seen on an unpackaged Windows build).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jonas Acker
2026-11-25 17:07:19 +01:00
parent eac04bc348
commit bb3e5d5ce8
2 changed files with 23 additions and 0 deletions

View File

@@ -46,6 +46,9 @@ class MsStoreCollectionsSync {
serviceTicket: ticket.serviceTicket,
publisherUserId: ticket.publisherUserId,
);
// The Store answers an empty key instead of an error when it can't
// make one (e.g. an unpackaged build).
if (key.isEmpty) throw StateError('Microsoft Store returned no collections ID key');
final base = await submitKey(key);
if (base != 'none') await writeFlag(_flagFor(userId), base);
await refreshEntitlements();

View File

@@ -74,4 +74,24 @@ void main() {
await sync.sync();
expect(errors.single, isA<StateError>());
});
test('an empty Store key (unpackaged build, Store unavailable) is never sent', () async {
final errors = <Object>[];
final sync = MsStoreCollectionsSync(
currentUserId: () => 'user-1',
requestTicket: () async => (serviceTicket: 'T', publisherUserId: 'user-1'),
collectionsIdKey: ({required serviceTicket, required publisherUserId}) async => '',
submitKey: (_) async {
calls.add('sync');
return 'active';
},
refreshEntitlements: () async {},
readFlag: (_) async => null,
writeFlag: (_, _) async {},
onError: (e, s) => errors.add(e),
);
await sync.sync();
expect(calls, isEmpty);
expect(errors.single, isA<StateError>());
});
}