Conversation
|
| yield this.direction === 'backward' | ||
| ? [...result.data].reverse() | ||
| : result.data; |
There was a problem hiding this comment.
Backward pages reverse requested order If the API returns a page in the requested descending order,
autoPagination() reverses that page and emits its items ascending instead. The new test requests order: 'desc' but mocks ascending page data, so it does not catch this result-order failure.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/common/utils/pagination.ts
Line: 43-45
Comment:
**Backward pages reverse requested order** If the API returns a page in the requested descending order, `autoPagination()` reverses that page and emits its items ascending instead. The new test requests `order: 'desc'` but mocks ascending page data, so it does not catch this result-order failure.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| const result = await paginatable.autoPagination(); | ||
|
|
||
| expect(result).toEqual(initialData.data); | ||
| expect(mockApiCall).not.toHaveBeenCalled(); |
There was a problem hiding this comment.
Limited backward results differ With both
before and limit, autoPagination() returns the initial page unchanged, while the new backward-pagination path reverses its pages. This test locks in different result orders for the same kind of request depending on whether a limit is set, making callers handle two ordering behaviors.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/common/utils/pagination.spec.ts
Line: 53-56
Comment:
**Limited backward results differ** With both `before` and `limit`, `autoPagination()` returns the initial page unchanged, while the new backward-pagination path reverses its pages. This test locks in different result orders for the same kind of request depending on whether a limit is set, making callers handle two ordering behaviors.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| const { before, after, ...options } = this.options; | ||
| const result = await this.apiCall({ | ||
| ...this.options, | ||
| ...options, | ||
| limit: 100, | ||
| after: params.after, | ||
| ...(this.direction === 'backward' | ||
| ? { before: params.before } | ||
| : { after: params.after }), |
There was a problem hiding this comment.
Conflicting cursor is silently dropped If a caller supplies both
before and after, the new direction check selects forward pagination and this request drops before. The caller gets results for after alone instead of the API error for conflicting cursors, making the invalid request harder to diagnose.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/common/utils/pagination.ts
Line: 34-40
Comment:
**Conflicting cursor is silently dropped** If a caller supplies both `before` and `after`, the new direction check selects forward pagination and this request drops `before`. The caller gets results for `after` alone instead of the API error for conflicting cursors, making the invalid request harder to diagnose.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
I hit this with
autoPagination()on a list fetched withbefore: page 2 sends bothbeforeandafter, and the API rejects it withPlease provide either "after" or "before" parameters.beforenow keeps paging backward throughlistMetadata.before, and every request sends only that one cursor.listUsers({ before: 'u21' })yieldsu20, u19, …, u1.Test plan
paginates backward when a before cursor is specifiedfails — results come back unreversed in forward stream order ([u3,u4,u1,u2]instead of[u4,u3,u2,u1]); the run aborts on that assertion before the request-param checks.npm test -- src/common/utils/pagination.spec.ts --runInBand— 6/6 pass, proving the reversed result order and the exact params of every API call (onlybeforesent, never both cursors).