Skip to content

sort search results by version - #24240

Merged
MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
adamv:feature/sort-version-tags
Oct 12, 2026
Merged

MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
adamv:feature/sort-version-tags

Conversation

@adamv

@adamv adamv commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

For consideration:

Sort search results by version, so that "python@3.9" sorts ahead of "python@3.12".


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Exact search results are now sorted by formula name and version, rather than lexicographically.
📝 Summary

Walkthrough

search_formulae now sorts initial exact-search results by formula base name and parsed version. Names without a version suffix use version 0. Fuzzy-search additions and result filtering remain unchanged.

Changes

Formula Search

Layer / File(s) Summary
Sort exact-search results
Library/Homebrew/search.rb
Exact-search results are sorted by the name before @, then by parsed version. Names without a version suffix use version 0.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Feature

Suggested reviewers: mikemcquaid


Merge Risk: ⚪ Minimal · up to bc572

Exact formula results use the requested numeric version order. A regression test is recommended, but no current behavior issue prevents merging.

Pre-merge checks | Passed 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly describes the main change: sorting search results by version.
Description check Passed The description explains the intended version-based ordering and matches the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Library/Homebrew/search.rb (1)

97-101: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a regression assertion for numeric version ordering.

The #search_formulae examples only use testball and assert annotations or installed status. A revert to lexical .sort would pass them while placing python@3.12 before python@3.9. Add a focused ordering example.

Suggested fix
     it "does not annotate normal formulae" do
       expect(described_class.search_formulae(/testball/)).to eq(["testball"])
     end
 
+    it "sorts versioned formulae by numeric version" do
+      formula_312 = instance_double(Formula, full_name: "python@3.12", any_version_installed?: false,
+                                             valid_platform?: true, deprecated?: false, disabled?: false,
+                                             pinned?: false, requirements: [], deps: [],
+                                             runtime_installed_formula_dependents: [], stable: nil, head: nil,
+                                             pour_bottle?: true)
+      formula_39 = instance_double(Formula, full_name: "python@3.9", any_version_installed?: false,
+                                            valid_platform?: true, deprecated?: false, disabled?: false,
+                                            pinned?: false, requirements: [], deps: [],
+                                            runtime_installed_formula_dependents: [], stable: nil, head: nil,
+                                            pour_bottle?: true)
+      allow(Formula).to receive_messages(full_names: ["python@3.12", "python@3.9"], alias_full_names: [])
+      allow(Formulary).to receive(:factory).with("python@3.12").and_return(formula_312)
+      allow(Formulary).to receive(:factory).with("python@3.9").and_return(formula_39)
+      allow(Tab).to receive(:for_formula).with(formula_312).and_return(tab)
+      allow(Tab).to receive(:for_formula).with(formula_39).and_return(tab)
+
+      expect(described_class.search_formulae(/python/)).to eq(["python@3.9", "python@3.12"])
+    end
+
     it "shows only the installed icon for installed formulae" do
       allow(formula).to receive_messages(any_version_installed?: true, pinned?: true)

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 78f18557-b8d9-494b-8f72-787bb5dbe476
📥 Commits

Reviewing files that changed from the base of the PR and between 1397358 and bc5728b.

📒 Files selected for processing (1)
  • Library/Homebrew/search.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📜 Review details
⏰ Context from checks skipped due to timeout. (19)
  • GitHub Check: docker (arm64 Ubuntu 24.04)
  • GitHub Check: docker (x86_64 Ubuntu 26.04)
  • GitHub Check: docker (arm64 Ubuntu 26.04)
  • GitHub Check: docker (x86_64 Ubuntu 24.04)
  • GitHub Check: tests (Linux, 2/2)
  • GitHub Check: tests (load-only Linux)
  • GitHub Check: tests (load-only macOS)
  • GitHub Check: tests (generic OS, 1/2)
  • GitHub Check: tests (Linux, 1/2)
  • GitHub Check: tests (no Sorbet)
  • GitHub Check: tests (online, 1/2)
  • GitHub Check: tests (macOS, 2/2)
  • GitHub Check: tests (generic OS, 2/2)
  • GitHub Check: tests (online, 2/2)
  • GitHub Check: tests (macOS, 1/2)
  • GitHub Check: syntax
  • GitHub Check: workflow_syntax
  • GitHub Check: docs
  • GitHub Check: Analyze
🔇 Additional comments (1)
Library/Homebrew/search.rb (1)

97-101: LGTM!

Sort search results by version, so that "python@3.9" sorts ahead of "python@3.12".
@adamv
adamv force-pushed the feature/sort-version-tags branch from bc5728b to 04a6532 Compare October 12, 2026 17:38
@adamv adamv closed this Oct 12, 2026
@MikeMcQuaid MikeMcQuaid reopened this Oct 12, 2026

@MikeMcQuaid MikeMcQuaid 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.

Nice idea, makes sense to me, thanks @adamv!

@MikeMcQuaid
MikeMcQuaid enabled auto-merge October 12, 2026 20:12
@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Oct 12, 2026
Merged via the queue into Homebrew:main with commit b10a7c3 Oct 12, 2026
101 checks passed
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

⌂ 换网址