Skip to content

[Hackathon] fix(pagination): reject blank starting tokens and history cursors before API calls #663

Closed as not planned

Description

@sandman-sh

Verified against (commit SHA or released version)

a18d37c

Discord Username / User ID

sandman.sh

What does this improvement do?

Reject empty and whitespace-only pagination cursors before making an API request.

Details / implementation notes

What is broken?

The CLI accepts empty pagination cursor values instead of rejecting them as invalid input.

Affected flags include:

--starting-token ""
--cursor ""

Relevant code:

  • src/lib/pagination.ts
  • src/commands/test.ts

The shared pagination validation checks numeric flags such as --page-size and --max-items, but does not validate that an explicitly supplied cursor is non-empty.

Reproduction

Run:

testsprite project list --starting-token "" --output json

Also run:

testsprite test list --project <PROJECT_ID> --starting-token "" --output json

And:

testsprite test result <TEST_ID> --history --cursor "" --output json

The commands accept the empty cursor instead of returning a local validation error.

Expected behavior

An explicitly supplied empty or whitespace-only cursor should fail before any API request:

VALIDATION_ERROR
exit code 5

The error should identify the relevant flag, for example:

--starting-token must be a non-empty cursor

Omitting the flag entirely should continue to mean “start from the first page.”

Actual behavior

The empty cursor is accepted and can be forwarded to the API as an empty cursor value.

This makes an explicitly empty cursor behave differently from an omitted cursor.

Impact

Shell variables often expand to empty strings:

testsprite project list --starting-token "$NEXT_TOKEN"

If NEXT_TOKEN is empty, the CLI should reject the input instead of sending an invalid cursor.

This can cause inconsistent behavior between API endpoints and makes pagination scripts harder to debug.

Suggested fix

Add shared validation for explicitly supplied cursor values:

  • reject empty strings;
  • reject whitespace-only values;
  • preserve valid opaque cursor values unchanged;
  • keep omitted cursors as undefined.

Apply the validation consistently to:

  • project list --starting-token;
  • test list --starting-token;
  • test result --history --cursor;
  • other commands using the shared pagination helper.

Add unit tests confirming:

  • empty cursors exit with code 5;
  • whitespace-only cursors exit with code 5;
  • omitted cursors remain valid;
  • non-empty opaque cursors are forwarded unchanged;
  • no API request occurs for invalid input.

Related work checked

Issue #603 covers pagination flags being skipped on the test steps --run-id path. This issue concerns blank cursor values on active pagination paths.

Issue #376 covers flags being used without --history. This issue concerns an explicitly supplied blank cursor while history is active.

I searched existing issues and pull requests for blank cursors, empty cursors, --starting-token, and --cursor. I found no existing issue or PR specifically covering this problem.

Confirmations

  • I have searched existing issues and this is not a duplicate.
  • I have provided my Discord identity above for reward coordination.

Activity

  1. added
    needs-triage
    hackathon
    on Oct 25, 2026
  2. sandman-sh commented on Oct 25, 2026

    @sandman-sh
    ContributorAuthor

    /assign

  3. testsprite-hob commented on Oct 25, 2026

    @testsprite-hob

    Thanks for the interest, @sandman-sh! This issue hasn't been accepted for implementation yet — see the triage comment (a maintainer will label it accepted once it is). Feel free to check back, or ping us on Discord if it's been quiet.

  4. removed
    needs-triage
    on Oct 31, 2026
  5. ruili-testsprite commented on Oct 31, 2026

    @ruili-testsprite
    Contributor

    Thanks @sandman-sh, confirmed: a blank --starting-token or --cursor is read as the first page. #577, #582, #604, #646 and #663 all come from the same place, a blank option value read as an omitted one, so we'll fix it once for every option ourselves instead of flag by flag. Closing as not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hackathon

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions