Skip to content

Fixed pagination on the host software page incorrectly disabling the "Next" button when a software title has multiple installer versions#41271

Merged
getvictor merged 2 commits intomainfrom
victor/41233-host-software
Mar 9, 2026
Merged

Fixed pagination on the host software page incorrectly disabling the "Next" button when a software title has multiple installer versions#41271
getvictor merged 2 commits intomainfrom
victor/41233-host-software

Conversation

@getvictor
Copy link
Copy Markdown
Member

@getvictor getvictor commented Mar 9, 2026

Related issue: Resolves #41233

Checklist for submitter

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

Testing

  • Added/updated automated tests

  • QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

  • Confirmed that the fix is not expected to adversely impact load test results

Summary by CodeRabbit

Bug Fixes

  • Fixed pagination on the host software page to prevent the "Next" button from being incorrectly disabled when a software title has multiple installer versions.

…"Next" button when a software title has multiple installer versions
@getvictor
Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 9, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes pagination metadata for Host Details → Software inventory when a single software title has multiple installer versions, which previously caused the UI “Next” button to be disabled incorrectly.

Changes:

  • Updates ListHostSoftware pagination to compute HasNextResults from the total unique title count rather than the post-deduped page length.
  • Adjusts the host software count query to count distinct title IDs.
  • Adds a regression test covering pagination with multiple installers for the same software title.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
server/datastore/mysql/software.go Fixes pagination metadata logic to avoid false “no next page” when installers create duplicate rows.
server/datastore/mysql/software_test.go Adds a regression test reproducing the duplicate-installer pagination scenario.
changes/41233-host-software-has-results Adds a user-visible changelog entry for the pagination fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/datastore/mysql/software.go
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 9, 2026

Walkthrough

This pull request fixes pagination logic in the host software listing feature. The ListHostSoftware query now uses COUNT(DISTINCT id) instead of COUNT(id) to accurately count unique software titles when duplicate rows are produced by joins involving multiple installer versions. The HasNextResults flag is recalculated based on the distinct count, and the returned list is properly truncated to the configured page size instead of unconditionally removing the last item.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive All changes are directly related to fixing the pagination issue in host software listing. The test duplicate and core fixes are tightly scoped to the stated objectives. The test file contains a duplicate identical test function which appears unintentional; verify if this is a merge artifact or should be removed to keep changes clean.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: pagination button incorrectly disabled for software titles with multiple installer versions.
Description check ✅ Passed The description covers key requirements including related issue (#41233), changes file added, automated tests added, and manual QA. However, it omits several checklist items applicable to this PR.
Linked Issues check ✅ Passed The code changes directly address issue #41233 by fixing pagination logic: COUNT(DISTINCT id) ensures accurate result counts, and HasNextResults computation now correctly reflects available pages when titles have multiple installer versions.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch victor/41233-host-software

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
server/datastore/mysql/software_test.go (1)

11597-11605: Assert the actual page-0 titles as well.

This only checks len(sw) and metadata. A regression that still returns 5 rows but duplicates pagsw-04 would pass even though dedup/pagination is wrong.

Suggested test hardening
 	// Page 0: 5 unique titles, HasNextResults must be true (there are 10 total).
 	opts.ListOptions.Page = 0
 	sw, meta, err := ds.ListHostSoftware(ctx, host, opts)
 	require.NoError(t, err)
 	require.Len(t, sw, perPage, "page 0 should have %d items", perPage)
+	gotNames := make([]string, 0, len(sw))
+	for _, s := range sw {
+		gotNames = append(gotNames, s.Name)
+	}
+	require.Equal(t, []string{
+		"pagsw-00",
+		"pagsw-01",
+		"pagsw-02",
+		"pagsw-03",
+		"pagsw-04",
+	}, gotNames)
 	require.NotNil(t, meta)
 	assert.Equal(t, uint(totalTitles), meta.TotalResults, "total results should reflect unique titles, not duplicated rows")
 	assert.True(t, meta.HasNextResults, "page 0 of %d items with perPage=%d should have next results", totalTitles, perPage)
 	assert.False(t, meta.HasPreviousResults)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/datastore/mysql/software_test.go` around lines 11597 - 11605, Add
assertions to verify the actual page-0 titles returned by ListHostSoftware
instead of only checking lengths and metadata: after calling ListHostSoftware
(variables sw, meta), extract the Title field from each entry, assert the set
size equals perPage and that all titles are unique (no duplicates like
"pagsw-04"), and assert the set equals the expected first-page title list (or
contains the known expected titles). This ensures the ListHostSoftware
pagination/dedup logic (sw slice) returns the correct unique titles for page 0.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@server/datastore/mysql/software.go`:
- Around line 6070-6073: HasNextResults is computed from the distinct title
count but SQL pagination is still applied to raw rows (hostSoftwareList) before
deduplication, causing overlap/short pages; change the query flow so you first
page the distinct software_titles.id set (use software_titles.id as the
pagination key) to fetch only the titles for the requested page, then hydrate
installer/app details for those title ids to build hostSoftwareList and set
HasNextResults from the distinct count; update code paths around HasNextResults,
hostSoftwareList population, and the query that currently slices
hostSoftwareList (the pre-deduplication pagination) so pagination is done
against the deduplicated title ids before fetching installers.

---

Nitpick comments:
In `@server/datastore/mysql/software_test.go`:
- Around line 11597-11605: Add assertions to verify the actual page-0 titles
returned by ListHostSoftware instead of only checking lengths and metadata:
after calling ListHostSoftware (variables sw, meta), extract the Title field
from each entry, assert the set size equals perPage and that all titles are
unique (no duplicates like "pagsw-04"), and assert the set equals the expected
first-page title list (or contains the known expected titles). This ensures the
ListHostSoftware pagination/dedup logic (sw slice) returns the correct unique
titles for page 0.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3af2bd60-7e19-487a-b161-2c618a3f7bff

📥 Commits

Reviewing files that changed from the base of the PR and between eec2ce1 and a832f5b.

📒 Files selected for processing (3)
  • changes/41233-host-software-has-results
  • server/datastore/mysql/software.go
  • server/datastore/mysql/software_test.go

Comment on lines +6070 to +6073
HasNextResults: titleCount > (opts.ListOptions.Page+1)*perPage,
}
if len(hostSoftwareList) > int(perPage) { //nolint:gosec // dismiss G115
metaData.HasNextResults = true
hostSoftwareList = hostSoftwareList[:len(hostSoftwareList)-1]
hostSoftwareList = hostSoftwareList[:perPage]
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.

⚠️ Potential issue | 🟠 Major

Page boundaries are still based on pre-deduped rows.

HasNextResults is now computed from the distinct title count, but the SQL pagination is still applied earlier at Line 5687, before Lines 5771-6059 collapse duplicate installer rows into one item per title. That means this change makes later pages reachable, but those pages can still overlap or come back short whenever one title expands into multiple raw rows. Page the distinct software_titles.id set first, then hydrate installer/app details for just that page.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/datastore/mysql/software.go` around lines 6070 - 6073, HasNextResults
is computed from the distinct title count but SQL pagination is still applied to
raw rows (hostSoftwareList) before deduplication, causing overlap/short pages;
change the query flow so you first page the distinct software_titles.id set (use
software_titles.id as the pagination key) to fetch only the titles for the
requested page, then hydrate installer/app details for those title ids to build
hostSoftwareList and set HasNextResults from the distinct count; update code
paths around HasNextResults, hostSoftwareList population, and the query that
currently slices hostSoftwareList (the pre-deduplication pagination) so
pagination is done against the deduplicated title ids before fetching
installers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Filed: #41277

@getvictor getvictor marked this pull request as ready for review March 9, 2026 18:30
@getvictor getvictor requested a review from a team as a code owner March 9, 2026 18:30
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.36%. Comparing base (e4412ca) to head (ce87838).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #41271      +/-   ##
==========================================
+ Coverage   66.34%   66.36%   +0.01%     
==========================================
  Files        2477     2477              
  Lines      198439   198459      +20     
  Branches     8740     8740              
==========================================
+ Hits       131660   131699      +39     
+ Misses      54877    54862      -15     
+ Partials    11902    11898       -4     
Flag Coverage Δ
backend 68.14% <100.00%> (+0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@getvictor getvictor merged commit f7595ba into main Mar 9, 2026
48 checks passed
@getvictor getvictor deleted the victor/41233-host-software branch March 9, 2026 21:43
getvictor added a commit that referenced this pull request Mar 9, 2026
…"Next" button when a software title has multiple installer versions (#41271)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #41233

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.

## Testing

- [x] Added/updated automated tests

- [x] QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

- [x] Confirmed that the fix is not expected to adversely impact load
test results

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Bug Fixes
* Fixed pagination on the host software page to prevent the "Next"
button from being incorrectly disabled when a software title has
multiple installer versions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

(cherry picked from commit f7595ba)
getvictor added a commit that referenced this pull request Mar 9, 2026
#41298)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #41233 

Cherry pick for #41271
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.

Next is greyed out even though there are more software records

4 participants