Skip to content

fix: align pagination with API semantics and make it configurable#279

Merged
bradhe merged 6 commits into
developfrom
fix/pagination-flags
May 14, 2026
Merged

fix: align pagination with API semantics and make it configurable#279
bradhe merged 6 commits into
developfrom
fix/pagination-flags

Conversation

@socksy
Copy link
Copy Markdown
Contributor

@socksy socksy commented May 13, 2026

Summary

The CLI pagination loop added in #275 was 0-indexed, but the real API treats page=0 (or null) as "return everything in one response" and uses 1-indexed pages otherwise. The loop happened to work against prod only because the first request asked for "all" and immediately exited the loop after one iteration. The mock server, meanwhile, was 0-indexed and diverged from the real API.

This PR:

  • Adds four hidden global flags for paginated list commands, modeled on the AWS CLI's pagination knobs but matched to our page-number API (no cursor / --starting-token since our API doesn't expose cursors):
    • --page-size N — page size to request from the server
    • --page N — page to start at; 0 means "no pagination, return all in one response"
    • --no-paginate — fetch only the first response
    • --max-items N — hard ceiling on total items returned
  • Threads page_size / paginate / page / max_items through Config so the flags are honored by every api::list_* call (CLI and MCP tools alike).
  • Fixes fetch_all_pages to match real API semantics: page=0 returns everything in one shot and stops; page>=1 iterates 1..=num_pages.
  • Aligns the mock server's paginate() helper to the same semantics so behavior is identical against mock and prod.
  • Rewrites cli_pagination.feature to create apps via the real CLI (and delete them in after_scenario) so the test exercises real pagination against any backend. With --page 1 --page-size 2 against three apps, the loop genuinely walks two pages.
  • Drops the mock-only /test/seed-apps and /test/reset endpoints that the previous pagination test relied on — they only worked against the mock and would silently fail against prod.

Test plan

  • cargo build clean
  • ./tests/integration/run_tests.py — all 43 scenarios pass
  • Manual: tower --page-size 5 apps list against staging shows pages-of-five behavior
  • Manual: tower --no-paginate apps list returns only the first response
  • Manual: tower --max-items 3 apps list caps the output at 3

The CLI pagination loop added in #275 was 0-indexed but the API treats
page=0 (or null) as 'return everything in one response' and uses
1-indexed pages otherwise. The loop happened to work against real prod
only because the first request asked for 'all' and immediately exited
the loop. The mock server was 0-indexed and so diverged from the real
API's semantics.

Changes:

- Add four hidden global flags for paginated list commands:
  --page-size, --page, --no-paginate, --max-items. Modeled on the AWS
  CLI's pagination knobs but matched to our page-number API
  (--starting-token would be cursor-shaped, which our API does not use).
- Thread page_size / paginate / page / max_items through Config.
- Fix fetch_all_pages: page=0 means 'all in one response and stop';
  page>=1 iterates 1..=num_pages.
- Align the mock /v1/apps/etc. pagination to the same semantics so the
  mock and prod behave the same way.
- Rewrite cli_pagination.feature to create apps via the real CLI and
  delete them in after_scenario. With --page 1 --page-size 2 against
  three apps, the test forces a real two-page traversal against any
  backend.
- Drop the mock-only /test/seed-apps and /test/reset endpoints that the
  old pagination feature relied on.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 39c760c4-0565-464b-a25f-acb06828d96c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pagination-flags

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

@bradhe bradhe merged commit 275b156 into develop May 14, 2026
30 checks passed
@bradhe bradhe deleted the fix/pagination-flags branch May 14, 2026 11:31
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