Skip to content

Conversation

@jsklan
Copy link
Contributor

@jsklan jsklan commented Jan 9, 2026

Description

Fixes wire test failures for pagination endpoints where getNextPage() sends a different cursor value than the original request.

Link to Devin run: https://app.devin.ai/sessions/569f5162819c47c4ba95afbfde8313de
Requested by: @jsklan

Root Cause

When pagination tests call getNextPage(), the SDK correctly sends the cursor from the response (e.g., "next_cursor_value"), but the mock server was rejecting the request because it expected the original request's cursor value (e.g., "cursor_value"). The mock server already filtered out pagination.* mismatches but not top-level cursor mismatches.

Changes Made

  • Added WithJsonOptions interface to withJson.ts with optional ignoredFields parameter
  • Updated mockEndpointBuilder.ts to pass ignoredFields through the jsonBody method
  • Modified TestGenerator.ts to extract pagination cursor field names from the IR and pass them to the mock server at code generation time
  • Added cursor pagination example to the existing pagination test fixture
  • Updated versions.yml with changelog entry for version 3.43.7
  • Updated IR generator test snapshot for pagination fixture

Approach

Instead of hardcoding field names to ignore (like key !== "cursor"), the solution uses IR metadata to determine which fields are pagination cursors. The TestGenerator extracts the cursor field name from endpoint.pagination.page.property.name.wireValue for cursor pagination endpoints and passes it to the mock server's jsonBody method. This approach:

  • Uses IR metadata to determine which fields are pagination cursors
  • Avoids false positives from legitimate fields named "cursor"
  • Makes the ignored fields explicit in the generated test code

Note: Nested cursor fields (e.g., pagination.cursor) are already handled by the existing !key.startsWith("pagination.") filter.

Testing

  • Verified fix against customer's generated SDK (Square) - all 659 tests passed
  • Added cursor pagination example to pagination fixture
  • Pagination seed tests pass (2/2)
  • Lint checks pass

Review Checklist

  • Verify the WithJsonOptions interface and ignoredFields parameter in withJson.ts
  • Confirm TestGenerator.ts correctly extracts cursor field names from IR for top-level cursor pagination
  • Verify the pagination example in users.yml is valid

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration bot changed the title fix(ts-sdk): ignore cursor mismatches in wire test mock server fix(typescript): ignore cursor mismatches in wire test mock server Jan 9, 2026

const mismatches = findMismatches(actualBody, expectedBody);
if (Object.keys(mismatches).filter((key) => !key.startsWith("pagination.")).length > 0) {
if (Object.keys(mismatches).filter((key) => !key.startsWith("pagination.") && key !== "cursor").length > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the key seems like it could lead to issues. Instead, is there a way for us to determine whether a field corresponds to a cursor used by the pagination feature? Isn't there metadata in the IR that specifies how the request/response fields correspond to pagination metadata that we could use to determine this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You raise a valid concern. The withJson.ts file is a static "as-is" file that gets copied into the generated SDK at build time, so it doesn't have access to IR metadata at runtime.

To use IR metadata for determining pagination cursor fields, we'd need to either:

  1. Pass pagination field names to withJson: Modify withJson to accept an optional list of fields to ignore, and have TestGenerator pass the pagination cursor field name(s) when generating tests. This would require changes to both withJson.ts and the test generation code.

  2. Generate endpoint-specific matchers: Instead of a generic withJson, generate custom matchers per endpoint that know which fields are pagination-related based on the IR.

The current approach follows the same pattern as the existing pagination.* filter (which also makes assumptions about field naming). However, I agree that a more robust solution using IR metadata would be better.

Would you prefer I implement option 1 (passing pagination field names to withJson)? This would involve:

  • Adding an optional ignoredFields?: string[] parameter to withJson
  • Modifying TestGenerator.buildExampleTest to extract pagination cursor field names from endpoint.pagination and pass them to the mock server setup

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, if possible it would make more sense to have the invoker of withJson tell it which fields to ignore rather than have withJson assume it can ignore any field called "cursor". Go ahead and implement this more robust approach.

devin-ai-integration bot and others added 2 commits January 9, 2026 20:19
…ection

Instead of hardcoding 'cursor' as an ignored field, the mock server now
accepts an optional ignoredFields parameter. The TestGenerator extracts
pagination cursor field names from the IR and passes them to the mock
server at code generation time.

This is a more robust approach that:
- Uses IR metadata to determine which fields are pagination cursors
- Avoids false positives from legitimate fields named 'cursor'
- Makes the ignored fields explicit in the generated test code

Co-Authored-By: [email protected] <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants