commit ff6eb3c23d0a9d4a230d9054034f1b271abde00a
parent 78c8e221f7c5c086398af6b5772e880a8c008528
Author: Michael Camilleri <[email protected]>
Date: Mon, 13 Apr 2026 04:42:13 +0900
Add write probe as part of iCloud debugging support
Diffstat:
1 file changed, 42 insertions(+), 0 deletions(-)
diff --git a/Crossmate/Sync/SyncEngine.swift b/Crossmate/Sync/SyncEngine.swift
@@ -561,6 +561,48 @@ actor SyncEngine {
results.append(("allRecordZones", describe(error)))
}
+ // Real write probe: push a throwaway Game record to the default zone via
+ // CKModifyRecordsOperation. Unlike CKModifyRecordZonesOperation (which
+ // can report phantom success), this hits the real record-write path and
+ // surfaces whatever the server actually returns.
+ let probeRecordID = CKRecord.ID(
+ recordName: "probe-\(UUID().uuidString)",
+ zoneID: CKRecordZone.ID(zoneName: CKRecordZone.ID.defaultZoneName, ownerName: CKCurrentUserDefaultName)
+ )
+ let probeRecord = CKRecord(recordType: "Game", recordID: probeRecordID)
+ probeRecord["title"] = "probe" as NSString
+
+ let writeOp = CKModifyRecordsOperation(recordsToSave: [probeRecord], recordIDsToDelete: nil)
+ writeOp.savePolicy = .allKeys
+ writeOp.isAtomic = false
+ writeOp.qualityOfService = .userInitiated
+
+ let writeResult: String = await withCheckedContinuation { continuation in
+ var perRecord: [(CKRecord.ID, Result<CKRecord, Error>)] = []
+ writeOp.perRecordSaveBlock = { id, result in
+ perRecord.append((id, result))
+ }
+ writeOp.modifyRecordsResultBlock = { result in
+ switch result {
+ case .success:
+ if let first = perRecord.first {
+ switch first.1 {
+ case .success(let saved):
+ continuation.resume(returning: "saved \(saved.recordID.recordName) etag=\(saved.recordChangeTag ?? "nil")")
+ case .failure(let err):
+ continuation.resume(returning: "perRecord FAILURE: \(self.describe(err))")
+ }
+ } else {
+ continuation.resume(returning: "operation success but no per-record result")
+ }
+ case .failure(let err):
+ continuation.resume(returning: "operation FAILURE: \(self.describe(err))")
+ }
+ }
+ privateDatabase.add(writeOp)
+ }
+ results.append(("writeProbe(default zone)", writeResult))
+
return results
}