fix(ios): keep connection Safe Mode across iCloud sync#1435
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On iOS, a connection's Safe Mode does not survive relaunch. Set it to Confirm Writes, save, quit, reopen: it's back to Off.
Root cause
Safe Mode persists to disk fine, but iCloud sync (on by default) round-trips connections through CloudKit, and the iOS package's
SyncRecordMappernever wrote or readsafeModeLevel. On relaunch the pull rebuilds the connection with the field defaulted to.off; the connection is no longer dirty, somergeConnectionstreats remote as newer, overwrites the saved.confirmWrites, and persists.offback to disk.The macOS app already syncs
safeModeLevel; only the iOS/package mapper dropped it. macOS and iOS keep separateDatabaseConnection/SafeModeLevel/SyncRecordMapperimplementations and meet only at the CloudKit field names.Fix
SyncRecordMappernow round-tripssafeModeLevel:toRecordandupdateRecordwrite the field.toConnectionreads it viasafeModeLevel(fromWire:isReadOnly:), which:off/confirmWrites/readOnly) directly, which also covers macOSreadOnlyso write protection round-trips cross-device;silent->.off,alert/safeModevariants ->.confirmWrites) so a connection protected on the Mac reads correctly on iPhone;isReadOnly ? .readOnly : .offfor legacy/absent records, matchingDatabaseConnection's Codable decoder.No macOS, model, or PluginKit-ABI changes. No new user-facing strings, so no localization or docs changes.
Tests
New
TableProSyncTeststarget (none existed) withSyncRecordMapperTests:updateRecordcarries the new levelsafeModeLevelfalls back toisReadOnlyswift test --filter SyncRecordMapperTestspasses (13 cases).