Skip to content

Fix auto-pagination undercounting pages when the API caps page size - #91

Merged
homotechsual merged 1 commit into
homotechsual:developfrom
Robbie-Renada:fix/pagination-page-size-cap
Sep 14, 2026
Merged

homotechsual merged 1 commit into
homotechsual:developfrom
Robbie-Renada:fix/pagination-page-size-cap

Conversation

@Robbie-Renada

@Robbie-Renada Robbie-Renada commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • New-HaloGETRequest's auto-pagination works out how many pages to fetch as Ceiling(record_count / <requested page_size>). The Halo API can silently cap the number of records actually returned per page below the requested page_size (e.g. asking for page_size=1000 but only ever getting 100 back), so that calculation is frequently wrong and every Get-Halo* multi-mode cmdlet ends up silently returning only the first page of results whenever the real result set is bigger than the API's true per-page cap — no error, just fewer records than actually exist.
  • Fix: capture the actual size of the first page returned and use that consistently for every later page-count calculation, instead of trusting the requested page size. A short final page (the normal end-of-results case) no longer skews the page count computed for earlier pages.
  • Added a regression test (keeps paginating when the API returns fewer records per page than requested) that reproduces the bug: requests page_size=1000 against a mocked 250-record endpoint that only ever returns 100 per page, and asserts all 250 records come back across 3 requests.

Confirmed empirically against a real Halo tenant before writing the fix: Get-HaloTicket (no -PageSize) returned only 100 of 717 real tickets; requesting page_size=1000 directly against api/tickets still only returned 100 records per page even though record_count correctly reported 717.

Fixes #90

Test plan

  • Invoke-Pester on Tests/HaloAPI.Unit.Tests.ps1 — all 452 tests pass (451 existing + 1 new), no regressions.
  • DevOps/Quality/run-pssa.ps1 — no new PSScriptAnalyzer findings introduced by either changed file.

🤖 Generated with Claude Code

New-HaloGETRequest calculated the number of pages to fetch as
Ceiling(record_count / <requested page_size>). The Halo API can silently
cap the number of records returned per page below what was requested
(e.g. asking for page_size=1000 but only ever getting 100 records back),
which meant that calculation was frequently wrong and caused every
Get-Halo* multi-mode cmdlet to silently return only the first page of
results on any endpoint with more matching records than the API's real
per-page cap - no error, just fewer results than actually exist.

Capture the actual size of the first page returned and use that
consistently for every subsequent page-count calculation instead of
trusting the requested page size. A short final page no longer skews
the count for pages before it.

Fixes homotechsual#90

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI 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.

🟢 Approval recommended

The implementation directly addresses the undercount and includes focused regression coverage.

Pull request overview

Fixes silent result truncation when Halo caps API page sizes below the requested value.

Changes:

  • Calculates page count using the first response’s actual item count.
  • Adds regression coverage for a 250-record, three-page response.
File summaries
File Description
Private/New-HaloGETRequest.ps1 Uses the effective API page size for pagination.
Tests/HaloAPI.Unit.Tests.ps1 Verifies capped pages are fully retrieved.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.92%. Comparing base (9ee9190) to head (a48ad98).

Files with missing lines Patch % Lines
Private/New-HaloGETRequest.ps1 88.88% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #91      +/-   ##
===========================================
+ Coverage    69.88%   69.92%   +0.04%     
===========================================
  Files          229      229              
  Lines         3712     3717       +5     
===========================================
+ Hits          2594     2599       +5     
  Misses        1118     1118              
Flag Coverage Δ
meta 0.40% <0.00%> (-0.01%) ⬇️
unit 69.92% <88.88%> (+0.04%) ⬆️

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.

@homotechsual

Copy link
Copy Markdown
Owner

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review. ✅ Project coverage is 69.92%. Comparing base (9ee9190) to head (a48ad98).

Files with missing lines Patch % Lines
Private/New-HaloGETRequest.ps1 88.88% 1 Missing ⚠️
Additional details and impacted files

@@             Coverage Diff             @@
##           develop      #91      +/-   ##
===========================================
+ Coverage    69.88%   69.92%   +0.04%     
===========================================
  Files          229      229              
  Lines         3712     3717       +5     
===========================================
+ Hits          2594     2599       +5     
  Misses        1118     1118              

Flag Coverage Δ
meta 0.40% <0.00%> (-0.01%) ⬇️
unit 69.92% <88.88%> (+0.04%) ⬆️
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.

False positive due to assignment of do-while loop. Coverage is good.

@homotechsual

Copy link
Copy Markdown
Owner

Fixes #90

@homotechsual
homotechsual merged commit be853a2 into homotechsual:develop Sep 14, 2026
7 checks passed
@Robbie-Renada
Robbie-Renada deleted the fix/pagination-page-size-cap branch September 14, 2026 12:04
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.

3 participants