feat(converters): re-enable variable scripting translations#8388
feat(converters): re-enable variable scripting translations#8388sanish-bruno wants to merge 1 commit into
Conversation
WalkthroughPostman and Bruno variable translation tables now cover additional global and collection helper calls in both directions. Matching tests were re-enabled and expanded for direct assertions and transpiler scenarios. ChangesPostman↔Bruno variable translations
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
…ble methods - Reintroduced translations for `setCollectionVar`, `deleteCollectionVar`, `deleteAllCollectionVars`, and their global counterparts in the Postman to Bruno and Bruno to Postman translators. - Updated tests to validate the translations for these methods, ensuring accurate functionality and consistency across variable management. - Removed outdated comments regarding UI updates, reflecting the current state of the implementation.
8bf8ff6 to
62ee62e
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/variables.test.js`:
- Around line 109-136: Add a regression test for the newly restored
pm.globals.toObject mapping in the variables translation suite. In
variables.test.js, extend the existing translateCode coverage alongside
pm.globals.unset, pm.globals.clear, and pm.collectionVariables.toObject to
assert that pm.globals.toObject() translates to bru.getAllGlobalEnvVars(). This
should exercise the postman-to-bruno-translator.js behavior so the restored
global toObject mapping stays covered.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0530a85f-18fb-47e9-a77e-636a8654d43d
📒 Files selected for processing (11)
packages/bruno-converters/src/postman/postman-translations.jspackages/bruno-converters/src/utils/bruno-to-postman-translator.jspackages/bruno-converters/src/utils/postman-to-bruno-translator.jspackages/bruno-converters/tests/bruno/bruno-to-postman-translations/variables.test.jspackages/bruno-converters/tests/postman/postman-translations/postman-comments.spec.jspackages/bruno-converters/tests/postman/postman-translations/postman-variables.spec.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/combined.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/multiline-syntax.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/response.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/testing-framework.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/variables.test.js
| it('should translate pm.globals.unset', () => { | ||
| const code = 'pm.globals.unset("token");'; | ||
| const translatedCode = translateCode(code); | ||
|
|
||
| expect(translatedCode).toBe('bru.deleteGlobalEnvVar("token");'); | ||
| }); | ||
|
|
||
| it('should translate pm.globals.clear', () => { | ||
| const code = 'pm.globals.clear();'; | ||
| const translatedCode = translateCode(code); | ||
|
|
||
| expect(translatedCode).toBe('bru.deleteAllGlobalEnvVars();'); | ||
| }); | ||
|
|
||
| it('should translate pm.collectionVariables.clear', () => { | ||
| const code = 'pm.collectionVariables.clear();'; | ||
| const translatedCode = translateCode(code); | ||
|
|
||
| expect(translatedCode).toBe('bru.deleteAllCollectionVars();'); | ||
| }); | ||
|
|
||
| it('should translate pm.collectionVariables.toObject', () => { | ||
| const code = 'const vars = pm.collectionVariables.toObject();'; | ||
| const translatedCode = translateCode(code); | ||
|
|
||
| expect(translatedCode).toBe('const vars = bru.getAllCollectionVars();'); | ||
| }); | ||
|
|
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add the missing pm.globals.toObject regression test.
Line 15 in packages/bruno-converters/src/utils/postman-to-bruno-translator.js now restores pm.globals.toObject, but this new block only covers unset and clear for globals. That leaves one newly re-enabled mapping unguarded.
🧪 Suggested test
+ it('should translate pm.globals.toObject', () => {
+ const code = 'const globals = pm.globals.toObject();';
+ const translatedCode = translateCode(code);
+
+ expect(translatedCode).toBe('const globals = bru.getAllGlobalEnvVars();');
+ });As per coding guidelines, "Add tests for any new functionality or meaningful changes. If code is added, removed, or significantly modified, corresponding tests should be updated or created."
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('should translate pm.globals.unset', () => { | |
| const code = 'pm.globals.unset("token");'; | |
| const translatedCode = translateCode(code); | |
| expect(translatedCode).toBe('bru.deleteGlobalEnvVar("token");'); | |
| }); | |
| it('should translate pm.globals.clear', () => { | |
| const code = 'pm.globals.clear();'; | |
| const translatedCode = translateCode(code); | |
| expect(translatedCode).toBe('bru.deleteAllGlobalEnvVars();'); | |
| }); | |
| it('should translate pm.collectionVariables.clear', () => { | |
| const code = 'pm.collectionVariables.clear();'; | |
| const translatedCode = translateCode(code); | |
| expect(translatedCode).toBe('bru.deleteAllCollectionVars();'); | |
| }); | |
| it('should translate pm.collectionVariables.toObject', () => { | |
| const code = 'const vars = pm.collectionVariables.toObject();'; | |
| const translatedCode = translateCode(code); | |
| expect(translatedCode).toBe('const vars = bru.getAllCollectionVars();'); | |
| }); | |
| it('should translate pm.globals.unset', () => { | |
| const code = 'pm.globals.unset("token");'; | |
| const translatedCode = translateCode(code); | |
| expect(translatedCode).toBe('bru.deleteGlobalEnvVar("token");'); | |
| }); | |
| it('should translate pm.globals.clear', () => { | |
| const code = 'pm.globals.clear();'; | |
| const translatedCode = translateCode(code); | |
| expect(translatedCode).toBe('bru.deleteAllGlobalEnvVars();'); | |
| }); | |
| it('should translate pm.globals.toObject', () => { | |
| const code = 'const globals = pm.globals.toObject();'; | |
| const translatedCode = translateCode(code); | |
| expect(translatedCode).toBe('const globals = bru.getAllGlobalEnvVars();'); | |
| }); | |
| it('should translate pm.collectionVariables.clear', () => { | |
| const code = 'pm.collectionVariables.clear();'; | |
| const translatedCode = translateCode(code); | |
| expect(translatedCode).toBe('bru.deleteAllCollectionVars();'); | |
| }); | |
| it('should translate pm.collectionVariables.toObject', () => { | |
| const code = 'const vars = pm.collectionVariables.toObject();'; | |
| const translatedCode = translateCode(code); | |
| expect(translatedCode).toBe('const vars = bru.getAllCollectionVars();'); | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/variables.test.js`
around lines 109 - 136, Add a regression test for the newly restored
pm.globals.toObject mapping in the variables translation suite. In
variables.test.js, extend the existing translateCode coverage alongside
pm.globals.unset, pm.globals.clear, and pm.collectionVariables.toObject to
assert that pm.globals.toObject() translates to bru.getAllGlobalEnvVars(). This
should exercise the postman-to-bruno-translator.js behavior so the restored
global toObject mapping stays covered.
Source: Coding guidelines
Description
Re-enables Postman ↔ Bruno script translations that were previously commented out because the underlying runtime APIs would not propagate variable mutations to the UI tables. With variable persistence landing in #8315, these APIs now update both the request lifecycle and the UI, so the translations can be turned back on.
JIRA: BRU-3096
Important
Depends on #8315 — that PR must be merged first, otherwise the re-enabled translations will silently fail to update the UI.
Re-enabled translations
pm.globals.unsetbru.deleteGlobalEnvVarpm.globals.clearbru.deleteAllGlobalEnvVarspm.collectionVariables.setbru.setCollectionVarpm.collectionVariables.unsetbru.deleteCollectionVarpm.collectionVariables.clearbru.deleteAllCollectionVarspm.collectionVariables.toObjectbru.getAllCollectionVarsApplied in both directions and to both transformer paths:
packages/bruno-converters/src/utils/postman-to-bruno-translator.js(AST/jscodeshift)packages/bruno-converters/src/postman/postman-translations.js(regex fallback)packages/bruno-converters/src/utils/bruno-to-postman-translator.js(AST/jscodeshift)Tests
it.skip/test.skipblocks across 8 spec files covering the collection-variable APIs.pm.globals.unset,pm.globals.clear,pm.collectionVariables.clear,pm.collectionVariables.toObject, and theirbru.*reverse mappings).npm run test --workspace=packages/bruno-converters→ 71/71 suites pass, 1104 tests pass.Contribution Checklist:
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
New Features
Tests