Skip to content

fix: consistently match platforms by canonical target - #630

Merged
eitsupi merged 3 commits into
mainfrom
fix/platform-alias-lookup
Dec 2, 2026
Merged

eitsupi merged 3 commits into
mainfrom
fix/platform-alias-lookup

Conversation

@eitsupi

@eitsupi eitsupi commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Match registry packages by canonical target so a macos_arm64 host can find a build listed as darwin_arm64.

  • Lookup. Version listings also recognize aliases. Generated archive URLs and PkgInfo.PlatformTuple use the original tuple from the index. Package lookups reject invalid platform tuples. Driver.Versions returns an empty list for invalid input.
  • Ambiguity. A package is taken only from the selected version record. If that record lists multiple packages for the requested target, including aliases or exact duplicates, the lookup reports an ambiguity error naming the canonical target. A version split across several records is not supported: the CLI rejects duplicate records of the selected full version instead of combining their builds.
  • Lock. When migration keeps the locked version, dbc checks the v1 library checksum if the recorded platform and host have the same canonical target. A platform rename accompanied by a change to the library now causes a checksum failure.

Closes #612.

@eitsupi eitsupi changed the title fix: match platform aliases when looking up packages fix: match platform aliases in package lookups Dec 1, 2026
@eitsupi
eitsupi marked this pull request as ready for review December 1, 2026 01:24
@eitsupi
eitsupi requested review from amoeba and zeroshade December 1, 2026 01:31
@eitsupi eitsupi changed the title fix: match platform aliases in package lookups fix: consistently match platforms by canonical target Dec 1, 2026
@eitsupi
eitsupi added this pull request to stack #632 December 1, 2026 01:50

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks correct overall: every consumer of PkgInfo.PlatformTuple parses it to a canonical target, and installed manifests/receipts stay keyed by the host tuple, so installing an aliased build doesn't affect reuse or cleanup. A few comments:

  1. Ignored parse errors (drivers.go: latestPackage, Versions, GetPackage use target, _ := resolution.TargetFromPlatformTuple(...)). This works because a zero Target never matches, but that's implicit. It also changes behavior slightly: an unparseable requested platform passed through internal/api Resolve (e.g. linux-amd64 or uppercase) used to match an identical raw index entry and now always reports "no package found". The CLI is unaffected since the host tuple is always valid. Either return the parse error or add a one-line comment that a zero target matches nothing by design.

  2. Ambiguity messages differ. packageForVersion names the caller's spelling (platformTuple), while cmd/dbc/platforms.go:platformPackage names targetTuple(t), so the same condition reads ... for linux_amd64_gnu in one place and ... for linux_amd64 in the other.

  3. Stricter v1 lock behavior. A v1 checksum recorded under darwin_arm64 is now verified against the macos_arm64 archive. If a registry renamed the platform and also rebuilt the archive, dbc sync now fails with a checksum mismatch instead of warning and ignoring the checksum. That's the right behavior for a lock, but it's worth calling out in the release notes.

  4. internal/api/api_test.go coverage. Dropping url: test-driver/1.0.0/linux.tar.gz removes this test's check of relative package url resolution through the API. It's still covered in dbc_api_test.go, so this is fine, but consider keeping a second package entry with the URL.

  5. Perf (non-blocking). hasBuildFor/packageForVersion re-parse every tuple per lookup instead of a string compare; negligible at current index sizes.

Also worth mentioning in the description: packageForVersion now scans every record with the same version string, so a version split across records (host build in the second record) now resolves via GetPackage where it previously failed.

A version split across several records is not supported: the package
lookup now uses only the record that was selected, and the CLI rejects a
selected version listed in more than one record instead of combining
their builds. Invalid platform tuples are reported as errors instead of
matching nothing, and ambiguity messages spell the canonical target the
same way in the CLI and the Go API.
@eitsupi

eitsupi commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

Updated.

  1. The lookups that can return an error now return the parse error, and internal/api Resolve rejects an invalid platform before fetching any index. Driver.Versions returns an empty list, as its doc now says.
  2. Both messages now use Target.PlatformTuple(), so the same condition reads the same way.
  3. Agreed; the description now calls this out.
  4. TestResolveUsesRequestedPlatform now has the API select a build with a relative url and checks the resolved URL.
  5. Left as is.

Split records are not supported, since one version record can already list every platform. packageForVersion now reads only the selected record, and the CLI rejects duplicate records for the selected full version. See #631 and #634 for the selection rules.

@eitsupi
eitsupi requested a review from zeroshade December 1, 2026 23:13

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, all earlier points are addressed. checkUniqueVersionRecord runs before any package lookup in fromLock, relock and selectProjectVersion, and a split pin is still reported through coversPlatforms/newestCoveringVersion rather than silently falling back to an older version. The error is not ErrPackageMiss, so registry fallback doesn't hide it.

One description note: "the CLI rejects duplicate records of the selected full version" holds for dbc sync, dbc lock and dbc add. dbc install (install.go), Client install (client_methods.go) and api.Resolve still go through GetLatestPackage/GetWithConstraint, which take the first record at the newest version with a host build, so a split version still installs there. #631/#634 close this; consider narrowing the wording or referencing them.

Minor inline notes below, none blocking.

Comment thread dbc_api_test.go
}
}

func TestDriverPackageLookupUsesOnlySelectedRecord(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This pins interim behaviour: GetLatestPackage succeeds from the second record while GetPackage(2.0.0, ...) reports "no package found". #634 turns the latter into an ambiguity error and removes GetLatestPackage, so this test will need rewriting there. Fine if intentional.

Comment thread cmd/dbc/platforms.go

// targetTuple spells t as a platform tuple. The libc of Linux is left out
// when it is the default.
func targetTuple(t resolution.Target) string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: targetTuple is now just t.PlatformTuple(). Callers could use the method directly and this wrapper could go.

Comment thread cmd/dbc/sync_plan.go
case !pinned:
reason = "the locked version no longer satisfies the version constraint"
case info.Platform != p.target:
case err != nil || !host.MatchesPlatformTuple(info.Platform):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: a host tuple that fails to parse is reported as "not recorded for this platform". Unreachable in practice since plan() already rejects an invalid p.target, but the reason would be misleading if it ever happened.

@eitsupi
eitsupi merged commit b922529 into main Dec 2, 2026
35 of 36 checks passed
@eitsupi
eitsupi deleted the fix/platform-alias-lookup branch December 2, 2026 23:22
eitsupi added a commit that referenced this pull request Dec 4, 2026
Follow-ups to the non-blocking review notes on #630, #631, #634 and
#635.

`dbc sync` saves the lock file before installing. It already warned on
install failure, but could exit without a warning after Ctrl-C or
SIGINT. It now warns once on stderr if it saved the lock file and
installation did not finish or could not be confirmed.

On an install error, the warning asks you to fix it and rerun `dbc
sync`. On interruption, it says installation "may be incomplete" and
asks you to rerun, since the last install may have finished before sync
received its result. Both warnings say the lock file "has been saved" to
avoid implying that its contents changed.

SIGINT stops the CLI program without canceling sync's worker context. On
exit, sync prevents a preparation worker from starting a lock-file write
and waits for any write already in progress before deciding whether to
warn.

Smaller follow-ups:

- Call `Target.PlatformTuple()` directly (#630).
- Explain why the ambiguity check uses registry pointers to distinguish
configurations that share a URL (#631).
- Clarify that `GetWithConstraint` ignores build metadata when selecting
a record (#634).

This branch was previously deployed

1 inactive deployment
snapshot — 30cd2f97 Deployed Dec 1, 2026 by eitsupi via snapshot #1437
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.

Match platform aliases when looking up packages for a platform

2 participants