Files
yay/pkg
Pujitha PaladuguandPujitha Paladugu ce6bcbd775 fix(query): keep pacman.conf repo order for exact name matches (#2987)
Motivation
With separatesources enabled (the default), a package with the exact
searched name that exists in several sync repos can be listed in the
wrong order. For example, if [cachyos-extra-v3] comes before [extra] in
pacman.conf, extra/chromium can still show up as the top pick instead of
cachyos-extra-v3/chromium. pacman prefers the repo listed first.

separateSourceScore returned a flat 50 for every exact match, whatever
its source. As a result, all exact matches got the same metric
(50 + 1.0). The unstable slices.SortFunc then left their relative order
unspecified, so the ordering added for non-exact results did not apply
to exact ones.

Approach
Move the repo-order scoring into a repoOrderScore helper (same logic and
cache as before). For exact matches, add repoOrderScore/separateSourceMax
to the 50: a bonus between 0 and 1. Exact matches still outrank every
non-exact result (which scores at most 45 + a metric below 1). Among
exact matches, repos earlier in pacman.conf now come first. Exact AUR
matches keep 50, so an exact sync-repo match now ranks strictly above an
exact AUR match instead of tying with it. Scoring for non-exact results
is unchanged, and nothing changes when separatesources is disabled.

Validation
- go test -race ./pkg/query/... -count=1: passes.
- New tests TestSourceQueryBuilderExactMatchSortsByRepoOrder (top-down
  and bottom-up) and TestSeparateSourceScore_ExactMatchKeepsRepoOrder
  fail with the previous metric.go and pass with this change.
- golangci-lint run ./pkg/query/...: 0 issues; gofmt clean.
- go test ./... on macOS has failures that also occur on the unchanged
  base: Linux-only syscall fields in pkg/settings/exe, and a
  timezone-dependent test in pkg/text. Not tested against a real
  pacman setup with custom repos.

Report: https://github.com/Jguer/yay/issues/2986

Assisted-by: claude-opus-5-5 (via Claude Code)

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Co-authored-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
2026-09-26 23:56:01 +02:00
..