Skip to content

Make OS and software version columns sortable by version - #50743

Open
kevinmcox wants to merge 4 commits into
fleetdm:mainfrom
kevinmcox:sortable-os-version-column
Open

Make OS and software version columns sortable by version#50743
kevinmcox wants to merge 4 commits into
fleetdm:mainfrom
kevinmcox:sortable-os-version-column

Conversation

@kevinmcox

@kevinmcox kevinmcox commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Related issue: Resolves #44057

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.

  • Timeouts are implemented and retries are limited to avoid infinite loops

  • If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes

Testing

  • Added/updated automated tests

  • Where appropriate, automated tests simulate multiple hosts and test for host isolation (N/A — no host-scoped data changes)

  • QA'd all new/changed functionality manually

Summary

Makes the Version column sortable (and the default sort) on:

  • The dashboard "Operating systems" card
  • The Software > OS page
  • The software title details page's versions table

Versions now sort numerically by segment instead of as plain strings, and Windows feature-update codenames (e.g. "21H2") sort by year/half. See the changes/os-versions-sortable-by-version file for the user-facing summary.

Summary by CodeRabbit

  • New Features

    • OS versions can now be sorted directly in dashboard and software tables.
    • Version sorting uses numeric segments and supports Windows feature-update formats such as 21H2.
    • OS version tables now default to sorting by version.
    • API requests can sort OS-version results by version.
  • Bug Fixes

    • Improved consistency for ascending and descending version sorting.
    • Added deterministic ordering for equivalent, unrecognized, and similarly formatted versions.

- Dashboard "Operating systems" card, Software > OS page, and the
  software title details page's versions table: the Version column is
  now sortable and is the default sort (descending, latest first),
  instead of sorting only by host count.
- Versions sort numerically by segment (e.g. "26.10" > "26.6") and
  Windows feature-update codenames (e.g. "22H1" > "21H2") sort by year
  and half, rather than as plain strings.
- Backend: added "version" as a valid order_key for
  GET /api/v1/fleet/os_versions.
- Fixed compareVersions (frontend/utilities/helpers.tsx) to stop
  silently tying non-numeric versions (e.g. Arch Linux's "rolling")
  against numeric ones when segment counts happened to match.
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.67089% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.54%. Comparing base (e6f1abe) to head (39ae34c).
⚠️ Report is 69 commits behind head on main.

Files with missing lines Patch % Lines
frontend/pages/SoftwarePage/SoftwarePage.tsx 16.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #50743      +/-   ##
==========================================
+ Coverage   68.36%   68.54%   +0.17%     
==========================================
  Files        3953     3977      +24     
  Lines      252918   256238    +3320     
  Branches    13488    13630     +142     
==========================================
+ Hits       172899   175627    +2728     
- Misses      64557    64996     +439     
- Partials    15462    15615     +153     
Flag Coverage Δ
backend 69.63% <100.00%> (+0.02%) ⬆️
frontend 62.72% <80.76%> (+1.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

golangci-lint (gocritic ifElseChain, modernize) flagged the
version/hosts_count sort selection and the segment-count comparison in
compareOSVersions. No behavior change.
@kevinmcox

Copy link
Copy Markdown
Contributor Author

Heads up — the lint check is red on server/datastore/mysql/teams_test.go:1209 (File is not properly formatted (gofmt)), but this PR doesn't touch that file at all. Dug into it a bit, and I think it's just flaky on main rather than anything this PR caused — I found the exact same error failing on main itself (here), right between two green runs on nearby commits where nothing changed in that file. So it looks like it comes and goes on its own.

lint-incremental and lint-js are both green here, for what it's worth.

@kevinmcox
kevinmcox marked this pull request as ready for review August 7, 2026 15:42
@kevinmcox
kevinmcox requested review from a team and rachaelshaw as code owners August 7, 2026 15:42
@coderabbitai

coderabbitai Bot commented Aug 7, 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ae70f5fb-68dd-427d-b91a-fa24f1f6e176

📥 Commits

Reviewing files that changed from the base of the PR and between 1c64be7 and 39ae34c.

📒 Files selected for processing (1)
  • server/service/hosts_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/service/hosts_test.go

Walkthrough

The change adds semantic version sorting for numeric segments and Windows feature-update codenames. The OS versions API accepts version as an order_key. Dashboard, Software > OS, and software title version tables expose sortable Version headers. These tables use version sorting as their default where specified. Frontend and backend tests cover ordering, unsupported formats, pagination, and comparator behavior.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: sortable OS and software version columns.
Description check ✅ Passed The description includes the related issue, change summary, testing updates, and user-visible changes; manual QA remains unchecked.
Linked Issues check ✅ Passed The PR implements the direct requirement in #44057 by making the software details Version column sortable with version-based ordering.
Out of Scope Changes check ✅ Passed The dashboard, Software > OS, API, comparator, and test changes support the stated version-sorting objective and are not out of scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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.

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 `@server/service/hosts.go`:
- Around line 3575-3645: Update versionSegments and compareOSVersions to
preserve numeric ordering for version segments exceeding int capacity; avoid
strconv.Atoi overflow by comparing normalized decimal segments using
significant-digit length and lexical order or arbitrary-precision integers.
Ensure distinct oversized segments do not compare equal and retain OSVersionID
as the tie-breaker only for genuinely equal versions. Add a regression case
covering values above math.MaxInt.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1fb94a1d-edc8-4717-b412-48eea93eebe0

📥 Commits

Reviewing files that changed from the base of the PR and between 779704d and 258924c.

⛔ Files ignored due to path filters (1)
  • docs/REST API/rest-api.md is excluded by !**/*.md
📒 Files selected for processing (13)
  • changes/os-versions-sortable-by-version
  • frontend/components/TableContainer/DataTable/DataTable.tsx
  • frontend/pages/DashboardPage/cards/OperatingSystems/OSTable.tsx
  • frontend/pages/DashboardPage/cards/OperatingSystems/OSTableConfig.tsx
  • frontend/pages/SoftwarePage/SoftwarePage.tsx
  • frontend/pages/SoftwarePage/SoftwareTitleDetailsPage/TitleVersionsTable/TitleVersionsTable.tsx
  • frontend/pages/SoftwarePage/SoftwareTitleDetailsPage/TitleVersionsTable/TitleVersionsTableConfig.tsx
  • frontend/utilities/helpers.tests.tsx
  • frontend/utilities/helpers.tsx
  • frontend/utilities/sort/sort_functions.tests.ts
  • frontend/utilities/sort/sort_functions.ts
  • server/service/hosts.go
  • server/service/hosts_test.go

Comment thread server/service/hosts.go
versionSegments now returns digit strings instead of parsing each
segment with strconv.Atoi, so a segment larger than int can hold (e.g.
one past math.MaxInt) compares correctly by significant-digit count
instead of silently overflowing and tying. Added regression cases,
including leading-zero and all-zero edge cases.

@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)
server/service/hosts_test.go (1)

3308-3390: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Add equal-version rows to cover the deterministic tie-break path.

TestOSVersionsOrderByVersion uses only unique Version values, so it does not exercise the OSVersionID tie-breaker or tied-version pagination stability. Add fixtures where two rows share the same parsed version but have different OSVersionIDs, and assert they appear in a stable order across ascending/descending and page boundaries.

🤖 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 `@server/service/hosts_test.go` around lines 3308 - 3390, Update
TestOSVersionsOrderByVersion by adding fixture rows with identical parsed
Version values and distinct OSVersionID values, then adjust expected counts and
ordering assertions to verify OSVersionID is the deterministic tie-breaker in
both ascending and descending sorts. Extend the pagination assertions so a tied
pair is split across page boundaries and retains the same stable order across
pages.
🤖 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 `@server/service/hosts_test.go`:
- Around line 3308-3390: Update TestOSVersionsOrderByVersion by adding fixture
rows with identical parsed Version values and distinct OSVersionID values, then
adjust expected counts and ordering assertions to verify OSVersionID is the
deterministic tie-breaker in both ascending and descending sorts. Extend the
pagination assertions so a tied pair is split across page boundaries and retains
the same stable order across pages.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f2069567-df9b-4a71-b4d9-1694a89a6fd8

📥 Commits

Reviewing files that changed from the base of the PR and between 258924c and 1c64be7.

📒 Files selected for processing (2)
  • server/service/hosts.go
  • server/service/hosts_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/service/hosts.go

TestOSVersionsOrderByVersion previously used only unique Version
values, so the OSVersionID tie-break path was never exercised. Added a
genuine tie (three rows sharing "22H1" across different editions) and
asserted stable ordering in both directions and across a pagination
boundary that splits the tied group.
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.

Sort software versions by version number on the software details page

2 participants