test(auto-paginate): fix over-strict cursor contract at exact page boundary#1060
Merged
Merged
Conversation
…undary The "drops nextCursor whenever the result is trimmed to limit" property test was flaky (~per-seed): it asserted that `total > limit` always implies `nextCursor === undefined`. That conflates two cases with opposite, correct contracts in the multi-page path of autoPaginate(): - True overshoot (a page pushes accumulation strictly past `limit`): rows are trimmed and the server cursor points past the trimmed tail, so it is dropped. Preserving it would skip rows — the original skip-bug guard. - Exact boundary (`limit % effectivePageSize === 0`): accumulation lands exactly on `limit`, nothing is trimmed, and the last page's cursor points at index `limit` — the first unreturned row. It MUST be preserved so callers can page forward; dropping it strands the tail (the regression pinned by events-overshoot.test.ts). The counterexample [total=393, limit=392, pageSize=98] is the exact-boundary case (392 % 98 === 0): the implementation correctly returns nextCursor="392", but the test demanded undefined. This is a test-only fix — the implementation is correct. Verified by an exhaustive sweep of all (total, limit, pageSize) combinations in the test's arbitrary ranges: 0 violations against the new contract.
Contributor
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 4420 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 81.85% 81.85% —%
==========================================
Files 341 341 —
Lines 24358 24358 —
Branches 15912 15912 —
==========================================
+ Hits 19937 19938 +1
- Misses 4421 4420 -1
- Partials 1665 1664 -1Generated by Codecov Action |
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 a flaky property test,
auto-paginate.property.test.ts→"drops nextCursor whenever the result is trimmed to limit", which failed on
seeds that hit an exact page-boundary input (e.g. counterexample
[total=393, limit=392, pageSize=98], since392 % 98 === 0).This is a test-only fix — the
autoPaginate()implementation is correct.Root cause
The test asserted that whenever
total > limit,nextCursormust beundefined. That predicate conflates two cases with opposite, correctcontracts in the multi-page path:
limit. Rows aretrimmed and the server cursor points past the trimmed tail, so it is dropped.
Preserving it would skip rows (the original skip-bug guard). ✅
limit % effectivePageSize === 0) — accumulation landsexactly on
limit, nothing is trimmed, and the last page's cursor points atindex
limit(the first unreturned row). It must be preserved so callerscan page forward; dropping it strands the tail — the regression explicitly
pinned by
events-overshoot.test.ts. ✅In the counterexample,
autoPaginatecorrectly returnsnextCursor="392"(following it yields row 392 — contiguous, no skip), but the test demanded
undefined.Fix
Split the assertion by the page-boundary discriminator:
limit % effectivePageSize === 0(exact boundary) → assertnextCursor === String(limit)(positively verifies the cursor resumescontiguously).
nextCursor === undefined(skip-bugguard, unchanged).
Also updated the file header to document the boundary nuance.
Why not change the implementation?
Dropping the cursor at the exact boundary would reintroduce the stranding
regression that
events-overshoot.test.tsguards against (-c nextcould neveradvance past
limit). The implementation's two-branch logic is correct.Verification
(total, limit, pageSize)combinations in thetest's arbitrary ranges (103,171 cases): 0 violations against the new
contract.
auto-paginate.property.test.ts+events-overshoot.test.ts: pass.failing).
pnpm run lint: clean.pnpm exec tsc --noEmit: exit 0.Context
This flake was spotted during the full-suite run while fixing the response-cache
torn-read bug (#1056) and noted there as a follow-up.