diff --git a/README.md b/README.md index 09b2ce4..35d3527 100644 --- a/README.md +++ b/README.md @@ -93,17 +93,16 @@ The parity suite tracks behavior and API differences. Expand the list for detail
Show all -1. Fetch descriptor defaults, `fetchOffsetAbsent`: Apple's offset is present; OpenSwiftData's is absent. -2. Erase, `lastCompletedStep`: Apple's probe checkpoints step 2 before its post-erase save traps; OpenSwiftData completes step 4. -3. Erase, `pendingFetchReturned`: the Apple probe does not complete the fetch after its save trap; OpenSwiftData completes it. -4. Erase, `pendingNamesAfterSave`: the Apple probe has no fetched names after its save trap; OpenSwiftData fetches `[\"pending\"]`. -5. Erase, `pendingSaveReturned`: the Apple probe does not complete the save after `erase()`; OpenSwiftData completes it. -6. Saved optional `flatMap`, `nick.empty.false`: OpenSwiftData matches `délta`; Apple returns no matches. -7. Saved optional `flatMap`, `nick.isEmpty.direct`: OpenSwiftData matches `délta`; Apple returns no matches. -8. Saved `String.count`, `length.4`: OpenSwiftData matches `beta`; Apple returns no matches. -9. Saved `String.count`, `length.5`: OpenSwiftData matches `Alpha`, `Gamma`, and `délta`; Apple returns no matches. -10. Saved `String.count`, `length.gt5`: OpenSwiftData matches `Épsilon`; Apple matches every row. -11. Duplicate inserts in one save, `survivorsObserved`: OpenSwiftData deterministically keeps the last insert as the survivor; Apple's survivor is non-deterministic (Set iteration order), so either insert may win. +1. Erase, `lastCompletedStep`: Apple's probe checkpoints step 2 before its post-erase save traps; OpenSwiftData completes step 4. +2. Erase, `pendingFetchReturned`: the Apple probe does not complete the fetch after its save trap; OpenSwiftData completes it. +3. Erase, `pendingNamesAfterSave`: the Apple probe has no fetched names after its save trap; OpenSwiftData fetches `[\"pending\"]`. +4. Erase, `pendingSaveReturned`: the Apple probe does not complete the save after `erase()`; OpenSwiftData completes it. +5. Saved optional `flatMap`, `nick.empty.false`: OpenSwiftData matches `délta`; Apple returns no matches. +6. Saved optional `flatMap`, `nick.isEmpty.direct`: OpenSwiftData matches `délta`; Apple returns no matches. +7. Saved `String.count`, `length.4`: OpenSwiftData matches `beta`; Apple returns no matches. +8. Saved `String.count`, `length.5`: OpenSwiftData matches `Alpha`, `Gamma`, and `délta`; Apple returns no matches. +9. Saved `String.count`, `length.gt5`: OpenSwiftData matches `Épsilon`; Apple matches every row. +10. Duplicate inserts in one save, `survivorsObserved`: OpenSwiftData deterministically keeps the last insert as the survivor; Apple's survivor is non-deterministic (Set iteration order), so either insert may win.
diff --git a/Sources/OpenSwiftData/Query/FetchDescriptor.swift b/Sources/OpenSwiftData/Query/FetchDescriptor.swift index df4c514..1e6a9c9 100644 --- a/Sources/OpenSwiftData/Query/FetchDescriptor.swift +++ b/Sources/OpenSwiftData/Query/FetchDescriptor.swift @@ -32,7 +32,7 @@ public struct FetchDescriptor: Equatable { predicate: Predicate? = nil, sortBy: [SortDescriptor] = [], fetchLimit: Int? = nil, - fetchOffset: Int? = nil, + fetchOffset: Int? = 0, includePendingChanges: Bool = true, propertiesToFetch: [PartialKeyPath] = [], relationshipKeyPathsForPrefetching: [PartialKeyPath] = [] diff --git a/Tests/OpenSwiftDataTests/Parity/ApiCoverageGapParityTests.swift b/Tests/OpenSwiftDataTests/Parity/ApiCoverageGapParityTests.swift index 5ac6905..ec516a8 100644 --- a/Tests/OpenSwiftDataTests/Parity/ApiCoverageGapParityTests.swift +++ b/Tests/OpenSwiftDataTests/Parity/ApiCoverageGapParityTests.swift @@ -110,9 +110,10 @@ import Testing @Test func `FetchResultsCollection Indices and SubSequence typealiases are referable`() throws { // `Indices`/`SubSequence` are MemberTypeSyntax nodes covering the // synthesized RandomAccessCollection conformance typealiases. - let _: FetchResultsCollection.Indices? = nil - let _: FetchResultsCollection.SubSequence? = nil - #expect(true) + let indices: FetchResultsCollection.Indices? = nil + let subSequence: FetchResultsCollection.SubSequence? = nil + #expect(indices == nil) + #expect(subSequence == nil) } @Test func `DataStoreSnapshotCodingKey intValue is nil`() throws { diff --git a/Tests/OpenSwiftDataTests/Parity/BackingDataApiParityTests.swift b/Tests/OpenSwiftDataTests/Parity/BackingDataApiParityTests.swift index 12f5b08..76f619f 100644 --- a/Tests/OpenSwiftDataTests/Parity/BackingDataApiParityTests.swift +++ b/Tests/OpenSwiftDataTests/Parity/BackingDataApiParityTests.swift @@ -24,8 +24,8 @@ import Testing context.insert(thing) try context.save() let backing = thing.persistentBackingData - let _: any BackingData = backing._generateCurrentClassBackingData() - #expect(true) + let generated: any BackingData = backing._generateCurrentClassBackingData() + #expect(String(describing: generated).contains("BackingData")) } @Test func `_superClassBackingData returns a backing data`() throws { @@ -33,7 +33,7 @@ import Testing context.insert(thing) try context.save() let backing = thing.persistentBackingData - let _: any BackingData = backing._superClassBackingData(of: BackingDataApiThing.self) - #expect(true) + let super_: any BackingData = backing._superClassBackingData(of: BackingDataApiThing.self) + #expect(String(describing: super_).contains("BackingData")) } } diff --git a/Tests/OpenSwiftDataTests/Parity/CustomStoreApiParityTests.swift b/Tests/OpenSwiftDataTests/Parity/CustomStoreApiParityTests.swift index fcaea34..72ec6be 100644 --- a/Tests/OpenSwiftDataTests/Parity/CustomStoreApiParityTests.swift +++ b/Tests/OpenSwiftDataTests/Parity/CustomStoreApiParityTests.swift @@ -30,20 +30,23 @@ private struct ConcreteRelationshipCollection: RelationshipCollection { } @Test func `DefaultStore type and historyType static member are referable`() throws { - let _: DefaultStore.Type = DefaultStore.self - let _: DefaultHistoryTransaction.Type = DefaultStore.historyType - #expect(true) + let storeType: DefaultStore.Type = DefaultStore.self + let historyType: DefaultHistoryTransaction.Type = DefaultStore.historyType + #expect(storeType == DefaultStore.self) + #expect(historyType == DefaultHistoryTransaction.self) } @Test func `HistoryProviding protocol and HistoryType associatedtype are referable`() throws { - let _: (any HistoryProviding.Type)? = nil - let _: DefaultStore.HistoryType.Type? = nil - #expect(true) + let provider: (any HistoryProviding.Type)? = nil + let historyType: DefaultStore.HistoryType.Type? = nil + #expect(provider == nil) + #expect(historyType == nil) } @Test func `RelationshipCollection protocol and PersistentElement associatedtype are referable`() throws { - let _: (any RelationshipCollection.Type)? = nil - let _: ConcreteRelationshipCollection.PersistentElement.Type? = nil - #expect(true) + let collection: (any RelationshipCollection.Type)? = nil + let element: ConcreteRelationshipCollection.PersistentElement.Type? = nil + #expect(collection == nil) + #expect(element == nil) } } diff --git a/Tests/OpenSwiftDataTests/Parity/DataStoreNoOpDefaultsParityTests.swift b/Tests/OpenSwiftDataTests/Parity/DataStoreNoOpDefaultsParityTests.swift index 6e7b2fc..2ea3984 100644 --- a/Tests/OpenSwiftDataTests/Parity/DataStoreNoOpDefaultsParityTests.swift +++ b/Tests/OpenSwiftDataTests/Parity/DataStoreNoOpDefaultsParityTests.swift @@ -53,13 +53,13 @@ extension NoOpDefaultsConfiguration: Equatable, Hashable { let store = try NoOpDefaultsDataStore(NoOpDefaultsConfiguration(name: "no-op"), migrationPlan: nil) let editingState = EditingState(id: UUID(), author: nil) store.initializeState(for: editingState) - #expect(true) + #expect(store.identifier == "no-op") } @Test func `invalidateState returns without throwing`() throws { let store = try NoOpDefaultsDataStore(NoOpDefaultsConfiguration(name: "no-op"), migrationPlan: nil) let editingState = EditingState(id: UUID(), author: nil) store.invalidateState(for: editingState) - #expect(true) + #expect(store.identifier == "no-op") } } diff --git a/Tests/OpenSwiftDataTests/Parity/ModelContextParityTests.swift b/Tests/OpenSwiftDataTests/Parity/ModelContextParityTests.swift index 53f2287..01e8f3b 100644 --- a/Tests/OpenSwiftDataTests/Parity/ModelContextParityTests.swift +++ b/Tests/OpenSwiftDataTests/Parity/ModelContextParityTests.swift @@ -119,7 +119,7 @@ import Testing #expect(descriptor.predicate == nil) #expect(descriptor.sortBy.isEmpty) #expect(descriptor.fetchLimit == nil) - #expect(descriptor.fetchOffset == nil) + #expect(descriptor.fetchOffset == 0) #expect(descriptor.includePendingChanges) #expect(descriptor.propertiesToFetch.isEmpty) #expect(descriptor.relationshipKeyPathsForPrefetching.isEmpty) diff --git a/Tests/OpenSwiftDataTests/Parity/SchemaApiParityTests.swift b/Tests/OpenSwiftDataTests/Parity/SchemaApiParityTests.swift index 6887f2e..ca08b14 100644 --- a/Tests/OpenSwiftDataTests/Parity/SchemaApiParityTests.swift +++ b/Tests/OpenSwiftDataTests/Parity/SchemaApiParityTests.swift @@ -15,30 +15,31 @@ struct SchemaApiParityTests { @Test func `Entity computed properties are referable`() throws { let entity = try #require(schema.entity(forName: "SchemaApiThing")) - let _: [any SchemaProperty] = entity.inheritedProperties - let _: [String: any SchemaProperty] = entity.inheritedPropertiesByName - let _: [any SchemaProperty] = entity.storedProperties - let _: [String: any SchemaProperty] = entity.storedPropertiesByName - let _: Set = entity.subentities - #expect(true) + #expect(entity.inheritedProperties.isEmpty) + #expect(entity.inheritedPropertiesByName.isEmpty) + #expect(entity.storedProperties.isEmpty) + #expect(entity.storedPropertiesByName.isEmpty) + #expect(entity.subentities.isEmpty) } @Test func `Index CodingKeys and Types enums are referable`() throws { - let _: Schema.Index.CodingKeys? = nil - let _: Schema.Index.Types? = nil - #expect(true) + let codingKeys: Schema.Index.CodingKeys? = nil + let types: Schema.Index.Types? = nil + #expect(codingKeys == nil) + #expect(types == nil) } @Test func `Index Types binary and rtree cases are referable`() throws { let binary: Schema.Index.Types = .binary([\.name]) let rtree: Schema.Index.Types = .rtree([\.name]) - _ = (binary, rtree) - #expect(true) + if case .binary = binary {} else { Issue.record("expected .binary") } + if case .rtree = rtree {} else { Issue.record("expected .rtree") } } @Test func `Schema encodingVersion and schemaEncodingVersion are referable`() throws { - let _: Schema.Version = schema.encodingVersion - let _: Schema.Version = Schema.schemaEncodingVersion - #expect(true) + let version: Schema.Version = schema.encodingVersion + let staticVersion: Schema.Version = Schema.schemaEncodingVersion + #expect(version == Schema.Version(1, 0, 0)) + #expect(staticVersion == Schema.Version(1, 0, 0)) } } diff --git a/Tests/SwiftDataParity/Contracts/Sources/ParityContracts/NonComparableScenarios.swift b/Tests/SwiftDataParity/Contracts/Sources/ParityContracts/NonComparableScenarios.swift index 849cc83..a2caf83 100644 --- a/Tests/SwiftDataParity/Contracts/Sources/ParityContracts/NonComparableScenarios.swift +++ b/Tests/SwiftDataParity/Contracts/Sources/ParityContracts/NonComparableScenarios.swift @@ -9,17 +9,15 @@ public enum NonComparableScenarios { /// One matrix rationale per declared scenario. public static let declared: [ScenarioID: (reasonCategory: String, rationale: String)] = [ // Deferred behavior gaps — Apple bugs not replicated. - ScenarioID(suite: "FetchDescriptorParityTests", test: "defaults match SwiftData"): deferred( - "OpenSwiftData's FetchDescriptor leaves fetchOffset nil by default; Apple's is non-nil."), ScenarioID(suite: "ModelContainerParityTests", test: "erasing removes stored models and keeps the store usable"): deferred( - "Apple traps during its post-erase save probe; OpenSwiftData completes the probe."), + "Apple's ModelContext.save() after ModelContainer.erase() triggers an abnormal termination that stops the checkpointed probe process at step 2 (lastCompletedStep == 2, pendingSaveReturned == false); OpenSwiftData's erase() keeps the store usable so the save completes (lastCompletedStep == 4, pendingNamesAfterSave == [\"pending\"]), which is the documented intent of erase(). OpenSwiftData intentionally does not replicate Apple's crash, so the two outcomes cannot be compared."), ScenarioID(suite: "UniqueConstraintParityTests", test: "duplicates inserted in one save collapse into one row"): deferred( - "Apple's survivor is non-deterministic (Set iteration order); OpenSwiftData deterministically keeps the last insert."), + "Apple's surviving row is selected non-deterministically (its conflict resolver iterates a Set, whose order is not guaranteed), so the survivorsObserved set varies run to run; OpenSwiftData deterministically keeps the last insert (z/2/nil), so the survivorsObserved sets cannot be compared. The parity harness has no per-field non-comparable mechanism, so the comparable everyTrialHasOneRow field is necessarily dropped along with survivorsObserved."), // Variants inside otherwise-compared entries. ScenarioID(suite: "StringPredicateParityTests", test: "string count counts characters/saved"): deferred( - "Apple's saved-model String.count predicates match no rows or every row; OpenSwiftData counts characters."), + "Apple's saved-model String.count predicate translation matches no rows for counts that should match and every row for counts that should not, contradicting Swift semantics; OpenSwiftData evaluates String.count per Swift semantics (grapheme cluster count), so the saved-model outputs cannot be compared."), ScenarioID(suite: "StringPredicateParityTests", test: "optional flatMap over a string/saved"): deferred( - "Apple's saved-model optional flatMap and isEmpty predicates match no rows; OpenSwiftData matches."), + "Apple's saved-model Optional.flatMap and String.isEmpty predicate translation matches no rows, contradicting Swift semantics; OpenSwiftData evaluates Optional.flatMap and String.isEmpty per Swift semantics, so the saved-model outputs cannot be compared."), ] /// Returns the disposition for a scenario, or `nil` when the scenario is comparable. diff --git a/Tests/SwiftDataParity/Contracts/Sources/ParityContracts/ParityContracts.swift b/Tests/SwiftDataParity/Contracts/Sources/ParityContracts/ParityContracts.swift index 07c347e..a844e00 100644 --- a/Tests/SwiftDataParity/Contracts/Sources/ParityContracts/ParityContracts.swift +++ b/Tests/SwiftDataParity/Contracts/Sources/ParityContracts/ParityContracts.swift @@ -1782,10 +1782,6 @@ public enum ModelContextParityScenarioCatalog { "predicateAbsent": .bool(true), "sortEmpty": .bool(true), "fetchLimitAbsent": .bool(true), "fetchOffsetAbsent": .bool(false), "includePendingChanges": .bool(true), "propertiesToFetchEmpty": .bool(true), "prefetchRelationshipsEmpty": .bool(true), - ], expectedOSDObservations: [ - "predicateAbsent": .bool(true), "sortEmpty": .bool(true), "fetchLimitAbsent": .bool(true), - "fetchOffsetAbsent": .bool(true), "includePendingChanges": .bool(true), - "propertiesToFetchEmpty": .bool(true), "prefetchRelationshipsEmpty": .bool(true), ]) public static let fetchDescriptorProperties = scenario( "FetchDescriptorParityTests", "properties to fetch is a mutable array", .fetchDescriptorProperties, diff --git a/Tests/SwiftDataParity/Contracts/Tests/ParityContractsTests/ParityContractsTests.swift b/Tests/SwiftDataParity/Contracts/Tests/ParityContractsTests/ParityContractsTests.swift index f12f63b..24f3c28 100644 --- a/Tests/SwiftDataParity/Contracts/Tests/ParityContractsTests/ParityContractsTests.swift +++ b/Tests/SwiftDataParity/Contracts/Tests/ParityContractsTests/ParityContractsTests.swift @@ -559,27 +559,20 @@ import Testing #expect(ModelContextParityExpectationValidator.validate(apple, against: specification, implementation: "openswiftdata")) } - @Test func fetchDescriptorDefaultsDivergenceUsesExactPerImplementationValues() { + @Test func fetchDescriptorDefaultsMatchAcrossImplementations() { let specification = ModelContextParityScenarioCatalog.fetchDescriptorDefaults - let appleValues: [String: ObservedValue] = [ + let values: [String: ObservedValue] = [ "predicateAbsent": .bool(true), "sortEmpty": .bool(true), "fetchLimitAbsent": .bool(true), "fetchOffsetAbsent": .bool(false), "includePendingChanges": .bool(true), "propertiesToFetchEmpty": .bool(true), "prefetchRelationshipsEmpty": .bool(true), ] - let osdValues: [String: ObservedValue] = [ - "predicateAbsent": .bool(true), "sortEmpty": .bool(true), "fetchLimitAbsent": .bool(true), - "fetchOffsetAbsent": .bool(true), "includePendingChanges": .bool(true), - "propertiesToFetchEmpty": .bool(true), "prefetchRelationshipsEmpty": .bool(true), - ] - let apple = ScenarioResult(id: specification.id, observations: appleValues.map { field, value in - ParityObservation(step: 0, field: field, value: value) - }) - let osd = ScenarioResult(id: specification.id, observations: osdValues.map { field, value in + let result = ScenarioResult(id: specification.id, observations: values.map { field, value in ParityObservation(step: 0, field: field, value: value) }) - #expect(ModelContextParityExpectationValidator.validate(apple, against: specification)) - #expect(ModelContextParityExpectationValidator.validate(osd, against: specification, implementation: "openswiftdata")) + #expect(ModelContextParityExpectationValidator.validate(result, against: specification)) + #expect(ModelContextParityExpectationValidator.validate( + result, against: specification, implementation: "openswiftdata")) } @Test func fetchDescriptorEqualityUsesExactPerImplementationValues() { diff --git a/Tests/SwiftDataParity/parity-matrix.json b/Tests/SwiftDataParity/parity-matrix.json index 458b332..9ce162b 100644 --- a/Tests/SwiftDataParity/parity-matrix.json +++ b/Tests/SwiftDataParity/parity-matrix.json @@ -105,7 +105,7 @@ "StringPredicateParityTests/string count counts characters/saved": "non-comparable" }, "reasonCategory": "deferred-behavior-gap", - "rationale": "Apple's saved-model String.count predicates match no rows or every row; OpenSwiftData counts characters." + "rationale": "Apple's saved-model String.count predicate translation matches no rows for counts that should match and every row for counts that should not, contradicting Swift semantics; OpenSwiftData evaluates String.count per Swift semantics (grapheme cluster count), so the saved-model outputs cannot be compared." }, { "sourceCase": "StringPredicateParityTests/optional flatMap over a string", @@ -126,7 +126,7 @@ "StringPredicateParityTests/optional flatMap over a string/saved": "non-comparable" }, "reasonCategory": "deferred-behavior-gap", - "rationale": "Apple's saved-model optional flatMap and isEmpty predicates match no rows; OpenSwiftData matches." + "rationale": "Apple's saved-model Optional.flatMap and String.isEmpty predicate translation matches no rows, contradicting Swift semantics; OpenSwiftData evaluates Optional.flatMap and String.isEmpty per Swift semantics, so the saved-model outputs cannot be compared." }, { "sourceCase": "SchemaIntrospectionParityTests/entities are found by model type", @@ -1423,11 +1423,19 @@ "FetchDescriptorParityTests/defaults match SwiftData" ], "outcomes": { - "FetchDescriptorParityTests/defaults match SwiftData": "non-comparable" + "FetchDescriptorParityTests/defaults match SwiftData": "compared" }, - "observations": {}, - "reasonCategory": "deferred-behavior-gap", - "rationale": "OpenSwiftData's FetchDescriptor leaves fetchOffset nil by default; Apple's is non-nil." + "observations": { + "FetchDescriptorParityTests/defaults match SwiftData": [ + "predicateAbsent", + "sortEmpty", + "fetchLimitAbsent", + "fetchOffsetAbsent", + "includePendingChanges", + "propertiesToFetchEmpty", + "prefetchRelationshipsEmpty" + ] + } }, { "sourceCase": "FetchDescriptorParityTests/properties to fetch is a mutable array", @@ -1619,7 +1627,7 @@ }, "observations": {}, "reasonCategory": "deferred-behavior-gap", - "rationale": "Apple's survivor is non-deterministic (Set iteration order); OpenSwiftData deterministically keeps the last insert." + "rationale": "Apple's surviving row is selected non-deterministically (its conflict resolver iterates a Set, whose order is not guaranteed), so the survivorsObserved set varies run to run; OpenSwiftData deterministically keeps the last insert (z/2/nil), so the survivorsObserved sets cannot be compared. The parity harness has no per-field non-comparable mechanism, so the comparable everyTrialHasOneRow field is necessarily dropped along with survivorsObserved." }, { "sourceCase": "UniqueConstraintParityTests/updating into a conflict merges the changed values and removes the updated row", @@ -1760,7 +1768,7 @@ }, "observations": {}, "reasonCategory": "deferred-behavior-gap", - "rationale": "Apple traps during its post-erase save probe; OpenSwiftData completes the probe." + "rationale": "Apple's ModelContext.save() after ModelContainer.erase() triggers an abnormal termination that stops the checkpointed probe process at step 2 (lastCompletedStep == 2, pendingSaveReturned == false); OpenSwiftData's erase() keeps the store usable so the save completes (lastCompletedStep == 4, pendingNamesAfterSave == [\"pending\"]), which is the documented intent of erase(). OpenSwiftData intentionally does not replicate Apple's crash, so the two outcomes cannot be compared." }, { "sourceCase": "ModelContainerParityTests/erasing also clears history",