fix(paginate): break loop on empty items with non-null nextToken#48
Open
aldorizona10-glitch wants to merge 2 commits into
Open
Conversation
paginate() in pagination.ts entered an infinite loop when the API
returned { items: [], nextToken: 'cursor' }. The loop only checked
nextToken !== null, never whether items was empty. Any filtered list
command returning zero results would hang indefinitely.
Add an early-exit guard: if the page contains zero items, break
regardless of nextToken. Includes 5 unit tests covering the bug
reproduction, maxItems cap, single-page, and consecutive empty pages.
Closes TestSprite#35
Signed-off-by: Aldo Rizona <aldorizona10@gmail.com>
Author
|
Hi maintainers 👋 First-time contributor here — CI runs are awaiting approval (). Quick summary of this PR:
Coverage impact: this PR adds tests to Happy to make any changes if needed. Thanks for reviewing! |
…ck gate
Pure mechanical prettier reflow of two vi.fn(async () => ({...})) callbacks in
test/pagination.test.ts. No logic change — only line wrapping to satisfy the
format:check CI gate (npm run format:check). All other gates already pass.
Coverage remains >=80% on all 4 metrics (lines/statements/functions/branches).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an infinite loop in
paginate()(issue #35) where the CLI hangs indefinitely when a filtered list endpoint returns{ items: [], nextToken: 'cursor' }.Problem
paginate()insrc/lib/pagination.tscheckednextToken !== nullto decide whether to keep looping, but never checked whetheritemswas actually empty. Without--max-itemsset, the loop had no way to stop for this edge case, causingtestsprite test list --project <id>with a zero-result filter to hang forever.Fix
Added an early-exit guard after processing each page:
This breaks the loop when the API returns zero items, regardless of what
nextTokensays. ThenextTokenfrom the server is still returned to the caller for potential resume.Changes
src/lib/pagination.ts: Added empty-items guard inpaginate()looptest/pagination.test.ts: New file with 5 unit tests:Testing
npm run typecheck— cleannpm run lint— cleannpm run format:check— all files pass Prettiernpm test— all existing tests + 5 new tests passCloses #35
Signed-off-by: Aldo Rizona aldorizona10@gmail.com