Skip to content

fix(utils): keep product type variant suffix when sorting devices - #1328

Open
askalf wants to merge 5 commits into
blacktop:masterfrom
sprayberry-code:fix/device-product-type-variant-suffix
Open

askalf wants to merge 5 commits into
blacktop:masterfrom
sprayberry-code:fix/device-product-type-variant-suffix

Conversation

@askalf

@askalf askalf commented Sep 15, 2026 •

Copy link
Copy Markdown

Summary

  • utils.DeconstructDevice parsed product types with the regex ^([a-zA-Z]+)([0-9]+),([0-9]+)$, which does not match the variant-suffixed product types Apple ships (iPad16,4-A). On no match it returns the zero Device.
  • utils.SortDevices rebuilds every name it is handed from the parsed struct via Device.String(), so an unparsed name does not pass through unchanged: it comes back as the literal string "0,0".
  • pkg/info feeds product types straight into SortDevices (info.go:629 for kernelcache device lists, info.go:479 for IPSW folder names), so an iPad Pro M4 kernelcache is written as kernelcache.release.0,0_0 instead of kernelcache.release.iPad16,3-A_4-A.
  • pkg/xcode's ByProductType.Less is the other caller: every variant-suffixed product type sorted as the zero Device, so ipsw device-list hoisted all 24 of them (iPad14,3-A/B through iPad17,4-A/B in device_traits.json) to the front of the list.
  • Fix: parse the optional suffix into a new Device.Variant field and carry it through String() and the sort key. Names that never matched the regex still collapse to the zero Device, unchanged.

Tests

TestSortDevicesPreservesVariantSuffix in internal/utils/sort_test.go fails on master (SortDevices returns "0,0" for each variant name) and passes with the fix. The package pulls in cgo dependencies that do not build here, so it was run against sort.go alone; go vet is clean.

AI assistance: this bug was found and the fix and tests were drafted with AI tooling in my workflow; the tests and checks above were run as described. I'm responsible for the change and will handle review feedback.

askalf and others added 4 commits September 15, 2026 03:21
Apple ships some product types with a trailing variant (iPad16,4-A),
which DeconstructDevice's regex did not match. SortDevices rebuilds every
name from the parsed Device, so those product types came back as 0,0 and
kernelcaches were written as kernelcache.release.0,0_0 instead of
kernelcache.release.iPad16,3-A_4-A.

Parse the optional suffix and carry it through Device.String and the sort
key. Names that never matched the regex still collapse to the zero Device.
…list

Adds the second DeconstructDevice caller (pkg/xcode ByProductType, which had
no test file) and the sort-key rows the first pass left unpinned: strict
ordering between two variants of one model, insertion-order independence, and
a round trip over the variant-suffixed product types the embedded Xcode
device_traits DB actually ships.

@beasetalk beasetalk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good direction

The other tests covered paths the fix does not change.
@askalf

askalf commented Oct 2, 2026

Copy link
Copy Markdown
Author

The push after the review (af34d1d) is test-only: internal/utils/sort.go is unchanged since 97b04c0. It reduces the tests to one table test, TestSortDevicesPreservesVariantSuffix in internal/utils/sort_test.go, which drives SortDevices through the parser, the sort and Device.String() with variant-suffixed product types; it returns "0,0" for every variant product type on master and passes with the change. The ordering, round-trip, kernelcache filename and xcode ByProductType tests from the earlier commits are removed so the PR carries one regression test sized to the bug. The branch merges clean against current master.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants