Make OS and software version columns sortable by version - #50743
Make OS and software version columns sortable by version#50743kevinmcox wants to merge 4 commits into
Conversation
- 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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
golangci-lint (gocritic ifElseChain, modernize) flagged the version/hosts_count sort selection and the segment-count comparison in compareOSVersions. No behavior change.
|
Heads up — the
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe change adds semantic version sorting for numeric segments and Windows feature-update codenames. The OS versions API accepts Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
docs/REST API/rest-api.mdis excluded by!**/*.md
📒 Files selected for processing (13)
changes/os-versions-sortable-by-versionfrontend/components/TableContainer/DataTable/DataTable.tsxfrontend/pages/DashboardPage/cards/OperatingSystems/OSTable.tsxfrontend/pages/DashboardPage/cards/OperatingSystems/OSTableConfig.tsxfrontend/pages/SoftwarePage/SoftwarePage.tsxfrontend/pages/SoftwarePage/SoftwareTitleDetailsPage/TitleVersionsTable/TitleVersionsTable.tsxfrontend/pages/SoftwarePage/SoftwareTitleDetailsPage/TitleVersionsTable/TitleVersionsTableConfig.tsxfrontend/utilities/helpers.tests.tsxfrontend/utilities/helpers.tsxfrontend/utilities/sort/sort_functions.tests.tsfrontend/utilities/sort/sort_functions.tsserver/service/hosts.goserver/service/hosts_test.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.
There was a problem hiding this comment.
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 winAdd equal-version rows to cover the deterministic tie-break path.
TestOSVersionsOrderByVersionuses only uniqueVersionvalues, so it does not exercise theOSVersionIDtie-breaker or tied-version pagination stability. Add fixtures where two rows share the same parsed version but have differentOSVersionIDs, 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
📒 Files selected for processing (2)
server/service/hosts.goserver/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.
Related issue: Resolves #44057
Checklist for submitter
Changes file added for user-visible changes in
changes/,orbit/changes/oree/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:
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-versionfile for the user-facing summary.Summary by CodeRabbit
New Features
Bug Fixes