Skip to content
Open
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
9 changes: 8 additions & 1 deletion Sources/ContainerizationOCI/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,14 @@ extension Platform: Hashable {
}

public func hash(into hasher: inout Swift.Hasher) {
hasher.combine(description)
hasher.combine(os)
hasher.combine(architecture)
// arm64 with no variant is equivalent to arm64/v8 per the == implementation
if architecture == "arm64" {
hasher.combine(variant ?? "v8")
} else {
hasher.combine(variant)
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions Tests/ContainerizationOCITests/OCIPlatformTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,19 @@ struct OCIPlatformTests {
let rhs = Platform(arch: "arm64", os: "linux", variant: nil)
#expect(lhs == rhs, "Both nil variants => variantEqual is true => overall equal")
}

@Test func arm64_nilAndV8_sameHashValue() {
let withoutVariant = Platform(arch: "arm64", os: "linux", variant: nil)
let withV8 = Platform(arch: "arm64", os: "linux", variant: "v8")
// Equal platforms must produce the same hash — violating this breaks Set/Dictionary lookups
#expect(withoutVariant.hashValue == withV8.hashValue, "arm64 nil variant and v8 must hash identically")
}

@Test func arm64_nilAndV8_setLookup() {
let withoutVariant = Platform(arch: "arm64", os: "linux", variant: nil)
let withV8 = Platform(arch: "arm64", os: "linux", variant: "v8")
var set = Set<Platform>()
set.insert(withoutVariant)
#expect(set.contains(withV8), "arm64/v8 must be found in a Set that contains arm64 with nil variant")
}
}