Skip to content

fix(migration): keep the call wrapping a response member in pm.sendRequest callbacks - #9162

Merged
sanish-bruno merged 7 commits into
usebruno:mainfrom
abhishekp-bruno:fix/pm-sendrequest-transform-wrapping-statements
Sep 15, 2026
Merged

sanish-bruno merged 7 commits into
usebruno:mainfrom
abhishekp-bruno:fix/pm-sendrequest-transform-wrapping-statements

Conversation

@abhishekp-bruno

@abhishekp-bruno abhishekp-bruno commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

BRU-4291

Description

When migrating a Postman script to Bruno, the pm.sendRequest callback rewriter maps Postman response access to its Bruno equivalent (response.coderesponse.status, response.json()response.data, ...). If a mapped response member sat inside a call as an argument, the rewriter replaced the entire wrapping call instead of just the member.

Example:

// Postman
console.log(response.code);

// Bruno (before this fix)
response.status;

// Bruno (expected)
console.log(response.status);

Problem

The rewrite was written with response.json() in mind. On Postman that is a method, on Bruno it is a plain property, so the call has to lose its parentheses. To do that, transformCallback checked whether the member's parent was a CallExpression and, if so, replaced the whole parent.

That check is too broad. A parent can be a CallExpression for two different reasons:

  • the member is the callee: response.json()
  • the member is an argument of some other call: console.log(response.code)

The old code treated both the same and replaced the parent in either case.

Fix

Before, the only check was "is the parent a CallExpression?". If yes, the whole parent was replaced.

Now we check two things: the parent is a CallExpression and the member is that call's callee. Only when both hold is the whole call replaced (response.json() → response.data). Otherwise just the member itself is replaced, so whatever wraps it is kept (console.log(response.code) → console.log(response.status)).

Statement Parent is a call? Member is the callee? Old code New code
response.json() yes yes replace whole call → response.data same
console.log(response.code) yes no replace whole call → response.status replace only the member → console.log(response.status)

Screenshots

Before After

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.
  • I've run the claude code review skill locally.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • Bug Fixes

    • Improved translation of response properties and methods in promise handlers and request callbacks.
    • Preserved correct behavior for nested and computed response access, shadowed variables, expressions, and template literals.
    • Improved conversion of response fields and methods to their Bruno equivalents across more Postman scripts.
  • Tests

    • Added coverage for nested expressions, comparisons, computed keys, bracket notation, template literals, and nested test assertions.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 46bdc0ce-b206-4eeb-a624-ef989778342e

📥 Commits

Reviewing files that changed from the base of the PR and between 5161eaf and 8b14c09.

📒 Files selected for processing (1)
  • packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/transformers/send-request.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/transformers/send-request.test.js

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The response-access transformer now uses shared, scope-aware rewriting for promise handlers and pm.sendRequest callbacks. Tests cover response members in expressions, computed access, nested callbacks, and Bruno API mappings.

Changes

Response rewriting

Layer / File(s) Summary
Shared response transformation
packages/bruno-converters/src/utils/send-request-transformer.js, packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/transformers/send-request.test.js
The transformer passes AST paths and response parameter names to shared rewriting logic. Tests cover assignments, calls, nested expressions, template literals, comparisons, computed keys, bracket access, and nested pm.test/pm.expect callbacks.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant PostmanScript
  participant sendRequestTransformer
  participant rewriteResponseAccess
  participant BrunoScript
  PostmanScript->>sendRequestTransformer: provide handler or callback AST path
  sendRequestTransformer->>rewriteResponseAccess: pass path and response parameter name
  rewriteResponseAccess->>sendRequestTransformer: rewrite scoped response members
  sendRequestTransformer->>BrunoScript: emit translated response access
Loading

Merge Risk: ⚪ Minimal · up to ffca7

No merge-blocking behavior risk remains from the reviewed change.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: preserving call wrapping for response members in pm.sendRequest callbacks during migration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Response paths now flow with care
Callbacks and promises share the air
Nested members change their name
Tests watch each expression frame
Bruno output lands fair

Comment @coderabbitai help to get the list of available commands.

Comment thread packages/bruno-converters/src/utils/send-request-transformer.js
@abhishekp-bruno
abhishekp-bruno force-pushed the fix/pm-sendrequest-transform-wrapping-statements branch from 37a240d to 5a1fa7d Compare September 9, 2026 11:43
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

sanish-bruno
sanish-bruno previously approved these changes Sep 11, 2026
@abhishekp-bruno
abhishekp-bruno force-pushed the fix/pm-sendrequest-transform-wrapping-statements branch from 5a1fa7d to 5161eaf Compare September 11, 2026 08:19
@sanish-bruno
sanish-bruno merged commit e14499c into usebruno:main Sep 15, 2026
26 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants