test(connections): cover the delete persist-before-notify sync invariant#1506
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12436eabbf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| func failedPersistenceRecordsNoTombstone() { | ||
| let connection = TestFixtures.makeConnection() | ||
| storage.addConnection(connection) | ||
| try? FileManager.default.removeItem(at: storageDirectory) |
There was a problem hiding this comment.
Use a per-test temp directory before deleting it
When the Swift Testing runner executes storage tests concurrently, this removes the shared temporaryDirectory/tablepro-tests directory rather than only this test's fixture, because storageDirectory is just fileURL.deletingLastPathComponent(). Other tests in the repo create their own temp databases/files under the same parent (for example QueryHistoryStorageTests and SQLFavoriteStorageTests), so this test can nondeterministically delete another test's live file and cause unrelated failures; make the UUID a directory component and delete only that unique directory.
Useful? React with 👍 / 👎.
Summary
Phase 8 / R-008: make the documented sync invariant executable. CLAUDE.md records that
SyncChangeTracker.markDeleted()must run aftersaveConnections()— persist before notify, or a sync can re-upload a just-deleted record.ConnectionStorage.deleteConnectionimplements this (persist behind aguard, thenmarkDeletedfor non-local/non-sample connections), but it had no test.Adds two regression tests against a real
ConnectionStoragewired to a test-backedSyncChangeTracker/SyncMetadataStorageand a temp file:saveConnectionswrite to fail) records no tombstone — pinning the persist-before-notify guard.Risk Addressed
Verification
xcodebuild test -only-testing:TableProTests/ConnectionStorageSyncDeleteTests— both tests pass.Notes
UserDefaults(suiteName:)!matches the existing storage-test convention (force_unwrapping is warning-level).DatabaseTypeadoption, and is tracked separately.