Skip to content

Commit cabf4d4

Browse files
authored
Continue encoding value for deprecated property in runner plan snapshot to avoid decoding error in clients (#1023)
This fixes a regression in the encoding of the `Runner.Plan` snapshot types, which can manifest when using Xcode 16. ### Motivation: The `isParallelizationEnabled` property was deprecated and changed from a stored property to a derived one in #901. That caused the value to no longer be encoded in `Runner.Plan.Action.RunOptions`, which can cause decoding errors in versions of Xcode which expect it to still be present. ### Modifications: - Manually implement `Codable` conformance for the affected type to begin including a hardcoded value. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated. Fixes rdar://146284519
1 parent db50ace commit cabf4d4

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Sources/Testing/Running/Runner.Plan.swift

+24-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension Runner {
1515
public enum Action: Sendable {
1616
/// A type describing options to apply to actions of case
1717
/// ``Runner/Plan/Action/run(options:)`` when they are run.
18-
public struct RunOptions: Sendable, Codable {
18+
public struct RunOptions: Sendable {
1919
/// Whether or not this step should be run in parallel with other tests.
2020
///
2121
/// By default, all steps in a runner plan are run in parallel if the
@@ -347,6 +347,29 @@ extension Runner.Plan {
347347
}
348348
}
349349

350+
extension Runner.Plan.Action.RunOptions: Codable {
351+
private enum CodingKeys: CodingKey {
352+
case isParallelizationEnabled
353+
}
354+
355+
public init(from decoder: any Decoder) throws {
356+
// No-op. This initializer cannot be synthesized since `CodingKeys` includes
357+
// a case representing a non-stored property. See comment about the
358+
// `isParallelizationEnabled` property in `encode(to:)`.
359+
self.init()
360+
}
361+
362+
public func encode(to encoder: any Encoder) throws {
363+
var container = encoder.container(keyedBy: CodingKeys.self)
364+
365+
// The `isParallelizationEnabled` property was removed after this type was
366+
// first introduced. Its value was never actually used in a meaningful way
367+
// by known clients, but its absence can cause decoding errors, so to avoid
368+
// such problems, continue encoding a hardcoded value.
369+
try container.encode(false, forKey: .isParallelizationEnabled)
370+
}
371+
}
372+
350373
#if !SWT_NO_SNAPSHOT_TYPES
351374
// MARK: - Snapshotting
352375

0 commit comments

Comments
 (0)