truncated: only report it when items beyond the returned set were available
Fixes #513.
SPEC §8 always mandated the precise form — steps 4a and 6g both read has_more = parseNextLink(...) ≠ null OR collected > max_items — and every SDK implemented it correctly in its first-page early return, then diverged to an unconditional truncated: true in its follow-loop cap check. A maxItems landing exactly on the final item of a Link-less last page misreported a complete result as truncated. Six commits, one per surface; every behavioral fix proven red-first.
| SDK | What happened | Red proof |
|---|---|---|
| TypeScript | Both follow-loop cap checks fixed; 5 new tests | expected true to be false ×2 (bare + wrapped exact-boundary), 2 failed / 20 passed pre-fix |
| Kotlin | Both mid-loop cap checks fixed (currentResponse Link); 4 new tests | AssertionFailedError: Expected value to be false ×2, 33 tests completed, 2 failed pre-fix |
| Swift | Both follow loops fixed — consulting nextResponse, not the loop var response which updates only after the cap check; 5 new tests (Swift has no conformance runner, XCTest is the only pin) | XCTAssertFalse failed - Cap met exactly with no next Link ×2 pre-fix |
| Go | No reachable bug — the flagged pre-fetch check is provably dead (first-page guard + post-append break keep the loop below the limit; the loop condition guarantees a live next Link regardless). Deleted the dead block; two exact-boundary pin tests green before and after, proving the deletion behavior-preserving | pins, not reds — the PR makes the honest claim |
| Python | Latent same-shape bug fixed in _paginate sync+async (no public caller passes max_items yet — SPEC compliance), plus a real false negative: _paginate_key/_paginate_wrapped never computed truncated at all, so max_pages exhaustion with a live next Link returned truncated=False. 14 respx tests | assert True is False (boundary) and assert False is True (page-cap false negative) — 6 failed / 8 passed pre-fix |
| Ruby | Out of scope — lazy Enumerator pagination has no truncated flag by documented waiver (2C.2/2C.4/2C.6); #513's claim that Ruby carries the flag was wrong |
Conformance + SPEC
No existing fixture could catch this: both truncated: true pagination cases hold under precise and imprecise semantics alike. New boundary case (maxItems: 4, pages 2+2, last page Link-less → truncated: false, requestCount: 2):
- Proven to bite: with
typescript/src/services/base.tsreverted to HEAD,make conformance-typescriptfails exactly on the new case (expected meta.truncated = false, got true). - Full matrix after the fixes: TS 118 passed, Go 100 passed (
PASS: maxItems landing exactly on the final item is not truncated), Kotlin 93 passed; Ruby and Python SKIP it via their existing skip conventions.
SPEC edits: sharpen the loose one-line field doc at :589 ("capped by" → available-beyond-returned), Appendix D row for the new fixture, and the missing Python row in Appendix F's pagination table. The algorithm itself needed no change — the implementations diverged from it.
Docs
README/doc-comment wording in TS/Kotlin/Swift now states the precise contract, phrased as "items beyond those returned were available" (an advertised-but-unfetched next page still reads true — the flag doesn't fetch page N+1 to find out; false still means definitely complete).
Full suites green: TS 984 (vitest, local count), Kotlin jvmTest 379, Swift 252, Go ./pkg/basecamp ok, Python 679 + ruff + mypy. CI is authoritative for counts.
Summary by cubic
Fixes #513. Aligns the pagination truncated flag across SDKs so it’s only true when more items were available beyond those returned, preventing false positives when maxItems lands exactly on the last item of a final, link‑less page.
-
Bug Fixes
- TypeScript, Kotlin, Swift: follow-loop maxItems checks now mark
truncatedonly when items were dropped or the just-fetched page had a next Link; added boundary and cap tests. - Python:
_paginate(sync/async) uses the same rule;_paginate_keyand_paginate_wrappednow settruncatedonmax_pagesexhaustion if a next Link remains; addedrespxtests. Public list methods still don’t exposemax_items. - Go: removed unreachable pre-fetch limit check; added exact-boundary pin tests. No behavior change.
- TypeScript, Kotlin, Swift: follow-loop maxItems checks now mark
-
Conformance
- Added case “maxItems landing exactly on the final item is not truncated.” TS/Kotlin/Go pass; Python/Ruby runners skip per existing conventions.
- SPEC clarifies
ListMeta.truncated; SDK docs updated to “items beyond those returned were available.”