Skip to content

feat(backend): allow version_expr to post-process version_regex results#10302

Merged
jdx merged 4 commits into
jdx:mainfrom
konono:fix/http-version-expr-pipeline
Jun 11, 2026
Merged

feat(backend): allow version_expr to post-process version_regex results#10302
jdx merged 4 commits into
jdx:mainfrom
konono:fix/http-version-expr-pipeline

Conversation

@konono

@konono konono commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Allow version_expr and version_regex to work together as a pipeline: regex extracts versions, then expr post-processes them (e.g. sorting)
  • Previously these were mutually exclusive in an if/else if chain (feat(http): add version_expr support and Tera templating #7723). This PR allows combining them, but if there was a reason for keeping them separate, happy to take a different approach.
  • Fix oc and openshift-install version sorting by adding sortVersions(versions) to their registry entries

Motivation

The upstream HTML directory at mirror.openshift.com lists versions lexicographically. find_match_in_list returns the last element assuming ascending order, so latest resolves to 4.9.9 instead of 4.22.0.

A registry-side fix was the only option because:

  • These tools are distributed via mirror.openshift.com, not GitHub Releases, so switching to aqua: or github: is not possible
  • version_expr alone can't extract from HTML — expr-lang has no regex capture function, and version_regex / version_expr were mutually exclusive

Changes

  • src/backend/version_list.rs: Move version_expr evaluation to run after extraction. When both version_regex and version_expr are specified, the regex results are passed as a versions variable into the expr context. When
    version_expr is used alone, it operates on body as before. No existing registry entries combine the two, so this is a no-op for all current tools.
  • registry/oc.toml, registry/openshift-install.toml: Add version_expr = 'sortVersions(versions)'

Test plan

  • cargo test backend::version_list — 24 tests pass (including new pipeline test)
  • mise ls-remote oc returns versions in ascending semantic order
  • mise latest oc resolves to 4.22.0 (not 4.9.9)

Before (current release)

  $ mise ls-remote oc | tail -5
  4.9.59
  4.9.6
  4.9.7
  4.9.8
  4.9.9

  $ mise latest oc
  4.9.9

After (this PR)

  $ target/debug/mise ls-remote oc | tail -5
  4.21.16
  4.21.17
  4.21.18
  4.21.19
  4.22.0

  $ target/debug/mise latest oc
  4.22.0

Summary by CodeRabbit

  • Improvements
    • oc client now applies explicit sorting when selecting available versions.
    • OpenShift installer now applies explicit sorting when selecting installer versions.
    • Version-processing pipeline can apply configurable post-processing expressions to extracted version lists.
  • Tests
    • Added unit coverage for version extraction plus post-processing workflows.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a0d39e9f-8828-44eb-973f-c9c568eae252

📥 Commits

Reviewing files that changed from the base of the PR and between e5e5c31 and 5c7d576.

📒 Files selected for processing (2)
  • registry/oc.toml
  • registry/openshift-install.toml
✅ Files skipped from review due to trivial changes (1)
  • registry/oc.toml

📝 Walkthrough

Walkthrough

This PR adds post-processing support for version lists via a version_expr configuration option. Backend version extractors (regex, JSON-path, auto-detection) can now apply an expression to transform extracted versions. The evaluator context injects both the original response body and the extracted versions array, enabling operations like sortVersions(versions). Two registry configs demonstrate the feature, and a new test validates the end-to-end pipeline.

Changes

Version Expression Post-Processing

Layer / File(s) Summary
Version expression evaluator enhancement
src/backend/version_list.rs
eval_version_expr signature now accepts extracted versions and injects them into expr-lang context alongside body, enabling expressions that reference and transform the version list.
Version list parsing with expression post-processing
src/backend/version_list.rs
After regex/JSON-path/auto extraction, parse_version_list conditionally applies version_expr to the extracted versions, passing both the response body and version list to the evaluator.
Configuration and test examples
registry/oc.toml, registry/openshift-install.toml, src/backend/version_list.rs
Registry configs set version_expr = sortVersions(versions) to sort extracted versions. A new unit test validates a regex+expr pipeline on HTML-like listings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble on bytes where versions lie in rows,
I pluck the hrefs, then line them up in rows.
With expr and a sort the list becomes neat,
A hop, a twist — the versions march in beat.
🍃

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: enabling version_expr to post-process version_regex results, which matches the core feature added in the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes incorrect latest version resolution for oc and openshift-install by enabling version_regex and version_expr to work as a pipeline: the regex extracts versions first, then the expression post-processes them. Previously these two options were mutually exclusive in an if/else chain; now version_expr always runs last and receives the extracted versions as a context variable.

  • src/backend/version_list.rs: version_expr moved from first-priority to post-processor; versions (previously extracted by regex/json-path/auto-detect) is always injected into the expression context (as an empty array when no prior extraction matched), and a sortVersions helper is added for semver-aware ordering.
  • registry/oc.toml and registry/openshift-install.toml: version_expr = 'sortVersions(versions)' added to re-sort the lexicographically-ordered directory listing into proper semver order, fixing mise latest oc returning 4.9.9 instead of 4.22.0.

Confidence Score: 5/5

Safe to merge. The change is well-scoped, backward-compatible, and all existing tests pass alongside a new pipeline test.

The core logic change — moving version_expr to a post-processing step and always injecting versions (including as an empty array when regex finds nothing) — is clean and handles edge cases correctly. No existing registry entries combine version_regex and version_expr, making the functional delta a no-op for all current tools outside oc and openshift-install. The sortVersions function is well-guarded, and the new test directly exercises the regex-then-sort pipeline. Concerns raised in prior review threads are addressed in the current code.

No files require special attention.

Important Files Changed

Filename Overview
src/backend/version_list.rs Moves version_expr from first-priority extractor to post-processor; adds versions variable to expr context and new sortVersions function; includes pipeline test. No new logic bugs found.
registry/oc.toml Adds version_expr = 'sortVersions(versions)' to post-process regex-extracted versions in semver order, fixing latest resolution from 4.9.9 to 4.22.0.
registry/openshift-install.toml Same fix as oc.toml: adds sortVersions(versions) expression to correct lexicographic-to-semver ordering from mirror.openshift.com.

Reviews (3): Last reviewed commit: "chore(registry): fix taplo formatting fo..." | Re-trigger Greptile

Comment thread src/backend/version_list.rs Outdated
Comment thread src/backend/version_list.rs

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/backend/version_list.rs`:
- Around line 135-140: The code currently only inserts "versions" into the
template context when the local `versions` Vec is non-empty, causing expression
errors like `sortVersions(versions)` when no matches occur; change the logic in
the block around `versions` / `ctx.insert` so that the "versions" key is always
bound in `ctx` (insert a Value::Array of the mapped strings even if `versions`
is empty, or insert an explicit empty Value::Array in the else branch) so
downstream expressions receive an empty array instead of being missing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 127447e3-0ef6-44c3-b4dc-cad6fa40165f

📥 Commits

Reviewing files that changed from the base of the PR and between ecc7213 and de5dcf5.

📒 Files selected for processing (3)
  • registry/oc.toml
  • registry/openshift-install.toml
  • src/backend/version_list.rs

Comment thread src/backend/version_list.rs Outdated

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/backend/version_list.rs (1)

144-164: ⚠️ Potential issue | 🟠 Major

Fix guideline violation in sortVersions: remove versions::Versioning::new(...)-based sorting

  • src/backend/version_list.rs implements sortVersions by calling versions.sort_by_cached_key(|v| Versioning::new(v)), which reorders a version list using a semver comparator and conflicts with the guideline to avoid Versioning::new/semver comparators at new call sites for version-list sorting.
  • Delegate ordering back to the backend/tool resolution flow (e.g., via Backend::latest_version, Backend::latest_installed_version, Backend::list_versions_matching, or ToolRequest::resolve) instead of sorting here.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/backend/version_list.rs` around lines 144 - 164, The sortVersions host
function must not perform semver-based sorting using Versioning::new; remove the
versions.sort_by_cached_key(|v| Versioning::new(v)) call and any direct uses of
Versioning::new inside the sortVersions closure. Instead, return the input array
unchanged (preserving caller order) or delegate sorting/resolution to the
backend/tool resolution APIs (e.g., Backend::latest_version,
Backend::latest_installed_version, Backend::list_versions_matching, or
ToolRequest::resolve) so that the backend controls ordering; ensure the closure
no longer references Versioning::new and add a short comment stating that
ordering is delegated to the backend.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/backend/version_list.rs`:
- Around line 144-164: The sortVersions host function must not perform
semver-based sorting using Versioning::new; remove the
versions.sort_by_cached_key(|v| Versioning::new(v)) call and any direct uses of
Versioning::new inside the sortVersions closure. Instead, return the input array
unchanged (preserving caller order) or delegate sorting/resolution to the
backend/tool resolution APIs (e.g., Backend::latest_version,
Backend::latest_installed_version, Backend::list_versions_matching, or
ToolRequest::resolve) so that the backend controls ordering; ensure the closure
no longer references Versioning::new and add a short comment stating that
ordering is delegated to the backend.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 838b8998-0f1a-4213-855a-8dd564439df1

📥 Commits

Reviewing files that changed from the base of the PR and between de5dcf5 and e5e5c31.

📒 Files selected for processing (1)
  • src/backend/version_list.rs

@jdx jdx merged commit fa0ec9d into jdx:main Jun 11, 2026
34 checks passed
@jdx

jdx commented Jun 11, 2026

Copy link
Copy Markdown
Owner

nice solution!

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