Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,16 @@ The parity suite tracks behavior and API differences. Expand the list for detail
<details>
<summary>Show all</summary>

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.

</details>

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftData/Query/FetchDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct FetchDescriptor<Model: PersistentModel>: Equatable {
predicate: Predicate<Model>? = nil,
sortBy: [SortDescriptor<Model>] = [],
fetchLimit: Int? = nil,
fetchOffset: Int? = nil,
fetchOffset: Int? = 0,
includePendingChanges: Bool = true,
propertiesToFetch: [PartialKeyPath<Model>] = [],
relationshipKeyPathsForPrefetching: [PartialKeyPath<Model>] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApiCoverageGapThing>.Indices? = nil
let _: FetchResultsCollection<ApiCoverageGapThing>.SubSequence? = nil
#expect(true)
let indices: FetchResultsCollection<ApiCoverageGapThing>.Indices? = nil
let subSequence: FetchResultsCollection<ApiCoverageGapThing>.SubSequence? = nil
#expect(indices == nil)
#expect(subSequence == nil)
}

@Test func `DataStoreSnapshotCodingKey intValue is nil`() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import Testing
context.insert(thing)
try context.save()
let backing = thing.persistentBackingData
let _: any BackingData<BackingDataApiThing> = backing._generateCurrentClassBackingData()
#expect(true)
let generated: any BackingData<BackingDataApiThing> = backing._generateCurrentClassBackingData()
#expect(String(describing: generated).contains("BackingData"))
}

@Test func `_superClassBackingData returns a backing data`() throws {
let thing = BackingDataApiThing(name: "beta")
context.insert(thing)
try context.save()
let backing = thing.persistentBackingData
let _: any BackingData<BackingDataApiThing> = backing._superClassBackingData(of: BackingDataApiThing.self)
#expect(true)
let super_: any BackingData<BackingDataApiThing> = backing._superClassBackingData(of: BackingDataApiThing.self)
#expect(String(describing: super_).contains("BackingData"))
}
}
21 changes: 12 additions & 9 deletions Tests/OpenSwiftDataTests/Parity/CustomStoreApiParityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 15 additions & 14 deletions Tests/OpenSwiftDataTests/Parity/SchemaApiParityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Schema.Entity> = 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<SchemaApiThing>? = nil
#expect(true)
let codingKeys: Schema.Index.CodingKeys? = nil
let types: Schema.Index.Types<SchemaApiThing>? = nil
#expect(codingKeys == nil)
#expect(types == nil)
}

@Test func `Index Types binary and rtree cases are referable`() throws {
let binary: Schema.Index.Types<SchemaApiThing> = .binary([\.name])
let rtree: Schema.Index.Types<SchemaApiThing> = .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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
24 changes: 16 additions & 8 deletions Tests/SwiftDataParity/parity-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading