Skip to content

test: support recording REST API requests in acceptance tests [ENG-9440] - #268

Merged
albertodonato merged 2 commits into
mainfrom
ack/test-recordings-rest
Oct 26, 2026
Merged

albertodonato merged 2 commits into
mainfrom
ack/test-recordings-rest

Conversation

@albertodonato

@albertodonato albertodonato commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

ENG-9440

what

Extend the recorded transport to support REST requests, in addition to
GraphQL ones. GraphQL requests are detected by the query field in the
request body, and keep the existing recordings format. REST requests are
recorded with method, path and body, and responses with status code and body.

Also handle requests without a body.

why

Allow writing acceptance tests for resources and data sources based on the
IaC API.

testing

Existing acceptance tests pass in replay mode with unchanged recordings.

docs

n/a

### what

Extend the recorded transport to support REST requests, in addition to
GraphQL ones. GraphQL requests are detected by the `query` field in the
request body, and keep the existing recordings format. REST requests are
recorded with method, path and body, and responses with status code and body.

Also handle requests without a body.

### why

Allow writing acceptance tests for resources and data sources based on the
IaC API.

### testing

Existing acceptance tests pass in replay mode with unchanged recordings.

### docs

n/a
@albertodonato
albertodonato requested a review from a team as a code owner October 26, 2026 12:18
@albertodonato albertodonato changed the title test: support recording REST API requests in acceptance tests test: support recording REST API requests in acceptance tests [ENG-9440] Oct 26, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file

Architecture diagram
sequenceDiagram
    participant Client as HTTP Client
    participant RT as RecordedTransport
    participant Recorder as Recorder/Player
    participant RealAPI as Real API (record mode)
    
    Note over Client,Recorder: Runtime flow for acceptance tests
    
    Client->>RT: RoundTrip(request)
    
    alt Request has body
        RT->>RT: Read request body
    else Request has no body
        RT->>RT: Proceed without body
    end
    
    RT->>RT: newRecordedRequest() classify request
    alt GraphQL request (query field present)
        RT->>RT: Extract query + variables
    else REST request
        RT->>RT: Capture method + path + body
    end
    
    alt Record mode
        RT->>RealAPI: Forward original request
        RealAPI-->>RT: Response with status + body
        RT->>RT: Parse response
        alt GraphQL request
            RT->>RT: Extract data + errors
        else REST request
            RT->>RT: Extract status code + body
        end
        RT->>Recorder: Save recording (request + response)
        Recorder-->>RT: Recording stored
        RT-->>Client: Return real response
    else Replay mode
        RT->>RT: Build request key
        alt GraphQL request
            RT->>RT: Key = query + variables
        else REST request
            RT->>RT: Key = method + path + compact body
        end
        
        RT->>Recorder: getRecording(key)
        alt Recording found
            Recorder-->>RT: Matching recording
            alt REST request
                RT->>RT: Construct response from status + body
            else GraphQL request
                RT->>RT: Verify query + variables match
                RT->>RT: Construct GraphQL response
            end
            RT-->>Client: Return recorded response
        else No recording found
            Recorder-->>RT: Error
            RT-->>Client: Return empty response + error
        end
    end
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@fwereade fwereade left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks

@albertodonato
albertodonato merged commit 06d07e5 into main Oct 26, 2026
4 checks passed
@albertodonato
albertodonato deleted the ack/test-recordings-rest branch October 26, 2026 12:37
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.

2 participants