Skip to content

test(pagination): cover offsets across short pages - #118

Merged
betegon merged 1 commit into
mainfrom
bt/sdk-pagination-short-page-tests
Oct 30, 2026
Merged

betegon merged 1 commit into
mainfrom
bt/sdk-pagination-short-page-tests

Conversation

@betegon

@betegon betegon commented Oct 30, 2026

Copy link
Copy Markdown
Member

A saved continuation can cross pages shorter than its remaining offset, including an empty page. Cover consumePage and paginateUpTo carrying an offset of five through [1, 2], [], and [3, 4, 5, 6], returning only [6] while following opaque cursors.

This keeps the generic continuation contract alongside its SDK implementation as consumer test duplication is reduced in Toolkit #1659. Only test coverage changes; no runtime, public API, or version changes.

Build, typecheck, all 254 Bun tests, and both Node cancellation tests pass.

betegon added a commit to getsentry/toolkit that referenced this pull request Oct 30, 2026
`sentry api --json` discarded pagination metadata, leaving agents
without a way to continue a successful query. It now exposes
continuation metadata and uses the CLI's shared cursor history for
`next`, `prev`, and `first`.

### Before

```sh
sentry api organizations/ -f per_page=1 --json
```

Even when another page existed, the output had no continuation (bodies
abbreviated):

```json
{"status":200,"statusText":"OK","body":[{"slug":"example-org"}]}
```

### After

The same command includes navigation metadata:

```json
{"status":200,"statusText":"OK","body":[{"slug":"example-org"}],"pagination":{"nextCursor":"1:1:0","hasPrev":false}}
```

Repeat the endpoint and filters to navigate:

```sh
sentry api organizations/ -f per_page=1 --cursor next --json
sentry api organizations/ -f per_page=1 --cursor prev --json
sentry api organizations/ -f per_page=1 --cursor first --json
```

Raw cursors and shared custom bookmarks are accepted, including legacy
`cli1~` bookmarks. Resuming restores the required page size and skips
rows already read; forward/back navigation retains that exact bookmark.
Arrays and Events `{data, meta}` envelopes are supported, preserving
envelope metadata.

### Shared SDK ownership

Uses published `@sentry/api@0.428.0`, including
getsentry/sentry-api-schema#116 and getsentry/sentry-api-schema#117. The
SDK owns generic URL, header, and body preparation through
`client.prepareRequest()`, plus partial-page consumption and bounded
traversal through `consumePage` and `paginateUpTo`. The API command uses
the same prepared `Request` for preview and dispatch, removing its
duplicate URL/header builders.

Toolkit keeps authentication and trusted-host checks, raw response
decoding, request/identity fingerprints, bookmark encoding, page-sizing
policy, and navigation history. The SDK accepts decoded server cursors
and offsets without depending on CLI storage or cursor formats. Existing
MCP and frontend consumers do not need to opt into request preparation.

Each `api` invocation still fetches one server page, and the endpoint
remains required. History is scoped to the request and identity;
dry-runs and failed requests do not advance it. `hasPrev` describes
local navigation, while `prevCursor` is server-provided. `--fields`
filters only the body. Raw text, binary downloads, explicit Content-Type
headers, and non-2xx response bodies retain their behavior. URL
fragments are excluded without losing encoded `#` characters. Command
help, docs, and the generated skill reference are updated.

Continuing without an endpoint is stacked in #1691. Native logs
pagination remains a separate follow-up.

Generic request preparation is tested in `@sentry/api`. Additional
coverage for continuation across short and empty pages is in
getsentry/sentry-api-schema#118, a tests-only follow-up that requires no
SDK release. The consumer tests concentrate on CLI navigation/history,
identity isolation, raw response policy, and bookmark adaptation.

### Validation

- Workspace typecheck and lint pass with published
`@sentry/api@0.428.0`.
- API and library E2E pass against the bundled CLI. Consolidated flows
retain navigation, dry-run/error recovery, raw-file preview and
dispatch, shared/legacy bookmarks, Events metadata, and request/identity
isolation. The silent request starts without JSON mode, then resumes
through the same saved history.
- Full workspace `pnpm run test` passes on Linux x64 on the final
source: 12,669 CLI tests, 337 shared tests, and all MCP, Cloudflare,
frontend, and remaining workspace suites. Existing skips remain
unchanged.
- Review and cleanup completed with no remaining findings. Production
code is unchanged by the test consolidation.
@betegon
betegon marked this pull request as ready for review October 30, 2026 12:29
@betegon
betegon merged commit 2722fa5 into main Oct 30, 2026
10 checks passed
@betegon
betegon deleted the bt/sdk-pagination-short-page-tests branch October 30, 2026 12:29
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.

1 participant