Skip to content

Revert: Re-add post response vars#6307

Merged
sid-bruno merged 2 commits intousebruno:mainfrom
sid-bruno:revert/re-add-vars
Dec 4, 2025
Merged

Revert: Re-add post response vars#6307
sid-bruno merged 2 commits intousebruno:mainfrom
sid-bruno:revert/re-add-vars

Conversation

@sid-bruno
Copy link
Collaborator

@sid-bruno sid-bruno commented Dec 4, 2025

Description

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.

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

    • Post-Response Variables: support for defining and running variables that apply after API responses at collection, folder, and request levels.
    • UI: new "Pre Request" and "Post Response" sections and updated active-variable counts reflecting both sets.
  • Tests

    • Added/updated tests verifying persistence and handling of pre-request and post-response variables, including multi-line values.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 4, 2025

Walkthrough

This PR adds post-response (response-scoped) variables across UI, collection merging, CLI and Electron runners, and test coverage: UI shows "Pre Request" and "Post Response" tables; collection merge gathers response vars; runners execute post-response var processing and emit environment updates.

Changes

Cohort / File(s) Summary
UI - Vars panels
packages/bruno-app/src/components/CollectionSettings/Vars/index.js, packages/bruno-app/src/components/FolderSettings/Vars/index.js, packages/bruno-app/src/components/RequestPane/Vars/index.js
Add "Pre Request" and "Post Response" headings and render two VarsTable instances; compute responseVars alongside request vars; remove unused DeprecationWarning imports.
UI - Settings & active count
packages/bruno-app/src/components/CollectionSettings/index.js, packages/bruno-app/src/components/FolderSettings/index.js, packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js
Retrieve responseVars from drafts/items and include enabled response vars in activeVarsCount aggregation; minor JSX/formatting adjustments.
Collection merging (CLI & Electron)
packages/bruno-cli/src/utils/collection.js, packages/bruno-electron/src/utils/collection.js
Aggregate response-scoped vars (request.vars.res) across collection root and requestTreePath (folders/items), merging enabled entries with later scopes overriding earlier ones, and attach as request.vars.res.
Runners - post-response processing
packages/bruno-cli/src/runner/run-single-request.js, packages/bruno-electron/src/ipc/network/index.js
Before post-response script execution, invoke VarsRuntime.runPostResponseVars when request.vars.res exists; on Electron, emit IPC environment-update messages and update collection globals or display errors based on results.
Tests
tests/request/newlines/newlines-persistence.spec.ts
Add separate actions/locators for pre-request (first) and post-response (second) var tables; create a post-response var with newlines and verify persistence after restart.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant App as Bruno App (UI)
    participant Runner as Runner (CLI/Electron)
    participant VarsRT as VarsRuntime
    participant Env as Environment Store

    User->>App: Trigger request execution
    App->>Runner: Start request (includes vars.req & vars.res)
    Runner->>Runner: Run pre-request script
    Runner->>Runner: Send HTTP request
    Runner->>Runner: Receive HTTP response

    alt request.vars.res exists
        Runner->>VarsRT: runPostResponseVars(request, response, env, ctx)
        VarsRT->>VarsRT: Evaluate response variables
        VarsRT-->>Runner: Return env updates / errors
        Runner->>Env: Emit env updates (script, persistent, global) [IPC in Electron]
        Runner->>Env: Update collection global variables
    else no response vars
        Runner->>Runner: Skip post-response var processing
    end

    Runner->>Runner: Execute post-response script
    Runner-->>App: Return execution result
    App-->>User: Display response & state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review merge logic in packages/*/utils/collection.js for correct precedence and enabled filtering.
  • Verify VarsRuntime.runPostResponseVars invocation/order and error handling in run-single-request.js and Electron IPC handler.
  • Confirm UI activeVarsCount and table rendering accurately reflect both request and response vars.

Possibly related PRs

  • PR #6195: Modifies/removes responseVars handling in overlapping files — likely a direct conflict or reversal of these changes.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno

Poem

✨ Variables ripple, pre and post,

Prepares the call, then reads the host.
From folders, items, roots they stream,
Post-response breathes into the scheme.
Small changes stitched to make state gleam.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Revert: Re-add post response vars' clearly describes the main change—reintroducing post-response variables functionality across multiple components and the CLI/Electron layers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64ea4fa and 35b8102.

📒 Files selected for processing (1)
  • packages/bruno-electron/src/ipc/network/index.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-electron/src/ipc/network/index.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: CLI Tests
  • GitHub Check: Unit Tests
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: SSL Tests - macOS

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

This reverts commit 786a341 while keeping code related to presets deleted
@sid-bruno sid-bruno force-pushed the revert/re-add-vars branch 2 times, most recently from 04ecd89 to 64ea4fa Compare December 4, 2025 09:18
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-app/src/components/RequestPane/Vars/index.js (1)

7-8: Add safe array defaults for request/response vars to avoid undefined issues

get(item, 'draft.request.vars.req') / get(item, 'request.vars.req') (and the res equivalents) have no [] fallback. For requests created before vars were introduced, these paths may be missing, making requestVars / responseVars undefined and potentially breaking VarsTable when it iterates them.

To align with other components and harden this pane, default these to empty arrays:

-  const requestVars = item.draft ? get(item, 'draft.request.vars.req') : get(item, 'request.vars.req');
-  const responseVars = item.draft ? get(item, 'draft.request.vars.res') : get(item, 'request.vars.res');
+  const requestVars = item.draft ? get(item, 'draft.request.vars.req', []) : get(item, 'request.vars.req', []);
+  const responseVars = item.draft ? get(item, 'draft.request.vars.res', []) : get(item, 'request.vars.res', []);

The Pre Request / Post Response sections themselves look good once these defaults are in place.

Also applies to: 13-19

🧹 Nitpick comments (2)
tests/request/newlines/newlines-persistence.spec.ts (1)

50-62: Multi-table vars selectors look good; consider asserting cell values too

Targeting .btn-add-var.first()/last() and addressing table.first() vs table.nth(1) makes the test align with the new Pre Request / Post Response layout and is a solid improvement. To further harden the persistence check, you could also assert the actual cell contents (including newlines) for both tables after restart using getTableCell(...) instead of only checking row counts.

Based on learnings, this also keeps coverage aligned with the “add tests for new functionality” guideline.

Also applies to: 83-85

packages/bruno-electron/src/utils/collection.js (1)

99-132: Response-vars aggregation mirrors request-vars behavior correctly

The new resVars aggregation follows the same precedence and last-writer-wins semantics as reqVars, and safely writes to request.vars.res only when request.vars exists. This looks consistent and correct.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9ce97f and 64ea4fa.

📒 Files selected for processing (11)
  • packages/bruno-app/src/components/CollectionSettings/Vars/index.js (1 hunks)
  • packages/bruno-app/src/components/CollectionSettings/index.js (2 hunks)
  • packages/bruno-app/src/components/FolderSettings/Vars/index.js (1 hunks)
  • packages/bruno-app/src/components/FolderSettings/index.js (1 hunks)
  • packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js (1 hunks)
  • packages/bruno-app/src/components/RequestPane/Vars/index.js (1 hunks)
  • packages/bruno-cli/src/runner/run-single-request.js (1 hunks)
  • packages/bruno-cli/src/utils/collection.js (1 hunks)
  • packages/bruno-electron/src/ipc/network/index.js (1 hunks)
  • packages/bruno-electron/src/utils/collection.js (1 hunks)
  • tests/request/newlines/newlines-persistence.spec.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation, never tabs
Use single quotes for strings instead of double quotes
Always add semicolons at the end of statements
No trailing commas in code
Always use parentheses around parameters in arrow functions, even for single parameters
For multiline constructs, put opening braces on the same line with a minimum of 2 elements for multiline formatting
No newlines inside function parentheses
Space before and after the arrow in arrow functions: () => {}
No space between function name and parentheses: func() not func ()
Semicolons should go at the end of the line, not on a new line
Function names should be concise and descriptive
Add JSDoc comments to provide details to abstractions
Avoid single-line abstractions where all that is being done is increasing the call stack with one additional function
Add meaningful comments to explain complex code flow instead of obvious comments

Files:

  • packages/bruno-app/src/components/FolderSettings/Vars/index.js
  • packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js
  • packages/bruno-electron/src/ipc/network/index.js
  • packages/bruno-app/src/components/RequestPane/Vars/index.js
  • tests/request/newlines/newlines-persistence.spec.ts
  • packages/bruno-cli/src/runner/run-single-request.js
  • packages/bruno-app/src/components/FolderSettings/index.js
  • packages/bruno-cli/src/utils/collection.js
  • packages/bruno-app/src/components/CollectionSettings/Vars/index.js
  • packages/bruno-electron/src/utils/collection.js
  • packages/bruno-app/src/components/CollectionSettings/index.js
**/*.{test,spec}.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

Add tests for any new functionality or meaningful changes; update corresponding tests when code is added, removed, or significantly modified

Files:

  • tests/request/newlines/newlines-persistence.spec.ts
tests/**/**.*

⚙️ CodeRabbit configuration file

tests/**/**.*: Review the following e2e test code written using the Playwright test library. Ensure that:

  • Follow best practices for Playwright code and e2e automation

  • Try to reduce usage of page.waitForTimeout(); in code unless absolutely necessary and the locator cannot be found using existing expect() playwright calls

  • Avoid using page.pause() in code

  • Use locator variables for locators

  • Avoid using test.only

  • Use multiple assertions

  • Promote the use of test.step as much as possible so the generated reports are easier to read

  • Ensure that the fixtures like the collections are nested inside the fixtures folder

    Fixture Example*: Here's an example of possible fixture and test pair

    .
    ├── fixtures
    │   └── collection
    │       ├── base.bru
    │       ├── bruno.json
    │       ├── collection.bru
    │       ├── ws-test-request-with-headers.bru
    │       ├── ws-test-request-with-subproto.bru
    │       └── ws-test-request.bru
    ├── connection.spec.ts # <- Depends on the collection in ./fixtures/collection
    ├── headers.spec.ts
    ├── persistence.spec.ts
    ├── variable-interpolation
    │   ├── fixtures
    │   │   └── collection
    │   │       ├── environments
    │   │       ├── bruno.json
    │   │       └── ws-interpolation-test.bru
    │   ├── init-user-data
    │   └── variable-interpolation.spec.ts # <- Depends on the collection in ./variable-interpolation/fixtures/collection
    └── subproto.spec.ts
    

Files:

  • tests/request/newlines/newlines-persistence.spec.ts
🧠 Learnings (1)
📚 Learning: 2025-12-03T08:09:57.124Z
Learnt from: CR
Repo: usebruno/bruno PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2025-12-03T08:09:57.124Z
Learning: Applies to **/*.{test,spec}.{js,jsx,ts,tsx} : Add tests for any new functionality or meaningful changes; update corresponding tests when code is added, removed, or significantly modified

Applied to files:

  • tests/request/newlines/newlines-persistence.spec.ts
🧬 Code graph analysis (7)
packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js (2)
packages/bruno-app/src/components/RequestPane/Vars/index.js (2)
  • responseVars (8-8)
  • requestVars (7-7)
packages/bruno-app/src/components/RequestPane/Settings/index.js (1)
  • getPropertyFromDraftOrRequest (24-25)
packages/bruno-electron/src/ipc/network/index.js (3)
packages/bruno-cli/src/runner/run-single-request.js (7)
  • postResponseVars (595-595)
  • request (122-122)
  • request (464-464)
  • result (173-184)
  • result (614-626)
  • result (662-674)
  • response (486-486)
packages/bruno-app/src/utils/network/index.js (1)
  • result (255-255)
packages/bruno-electron/src/ipc/network/ws-event-handlers.js (2)
  • envVars (65-65)
  • processEnvVars (66-66)
packages/bruno-app/src/components/RequestPane/Vars/index.js (3)
packages/bruno-app/src/components/CollectionSettings/Vars/index.js (2)
  • requestVars (10-10)
  • responseVars (11-11)
packages/bruno-app/src/components/FolderSettings/Vars/index.js (2)
  • requestVars (10-10)
  • responseVars (11-11)
packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js (2)
  • requestVars (101-101)
  • responseVars (102-102)
tests/request/newlines/newlines-persistence.spec.ts (1)
tests/utils/page/locators.ts (1)
  • getTableCell (79-79)
packages/bruno-cli/src/runner/run-single-request.js (2)
packages/bruno-js/tests/runtime.spec.js (1)
  • VarsRuntime (5-5)
packages/bruno-cli/src/commands/run.js (2)
  • runtimeVariables (334-334)
  • processEnvVars (466-468)
packages/bruno-cli/src/utils/collection.js (5)
packages/bruno-electron/src/utils/collection.js (8)
  • collectionRoot (54-54)
  • collectionRoot (154-154)
  • collectionRoot (620-620)
  • folderRoot (24-24)
  • folderRoot (67-67)
  • folderRoot (108-108)
  • folderRoot (164-164)
  • folderRoot (628-628)
packages/bruno-cli/src/runner/prepare-request.js (3)
  • get (1-1)
  • collectionRoot (51-51)
  • request (16-16)
packages/bruno-electron/src/ipc/network/index.js (2)
  • collectionRoot (324-324)
  • request (325-325)
packages/bruno-app/src/components/ResponsePane/Timeline/index.js (1)
  • collectionRoot (12-12)
packages/bruno-app/src/components/FolderSettings/index.js (1)
  • folderRoot (23-23)
packages/bruno-app/src/components/CollectionSettings/Vars/index.js (2)
packages/bruno-app/src/components/CollectionSettings/index.js (2)
  • responseVars (43-45)
  • requestVars (40-42)
packages/bruno-app/src/utils/collections/index.js (1)
  • requestVars (1527-1527)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: Unit Tests
  • GitHub Check: CLI Tests
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: Playwright E2E Tests
🔇 Additional comments (7)
packages/bruno-app/src/components/CollectionSettings/Vars/index.js (1)

11-23: Post-response vars wiring and UI look consistent

responseVars uses the same draft/root resolution pattern and safe [] default as requestVars, and the Pre Request / Post Response sections with separate VarsTable instances are consistent with Folder and Request panes. No issues from a data-flow or UX perspective.

packages/bruno-cli/src/utils/collection.js (1)

202-235: Response vars merge mirrors request vars correctly

The new resVars merge follows the same pattern as req vars: safe get(..., []), folder vs item handling, and last-writer-wins semantics across the tree, then normalizing into request.vars.res with enabled: true and type: 'response'. No correctness concerns here.

packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js (1)

102-111: Vars badge now correctly counts both pre- and post-response vars

Including responseVars in activeVarsLength via the same draft/request resolver keeps the badge in sync with both tables and is safe due to the [] default. Implementation is sound.

packages/bruno-app/src/components/CollectionSettings/index.js (1)

35-60: Collection-level vars/auth/proxy wiring is consistent and safe

The refactor to resolve headers, request/response vars, auth, proxy, client certs, and protobuf via draft/root with explicit get defaults is consistent with other components; activeVarsCount correctly sums enabled request and response vars. No functional issues spotted.

packages/bruno-app/src/components/FolderSettings/Vars/index.js (1)

11-23: Folder-level Pre/Post vars implementation is consistent

responseVars reuse of the existing draft/root pattern plus the new Pre Request / Post Response sections and varType flags matches the collection and request panes; no functional issues observed.

packages/bruno-cli/src/runner/run-single-request.js (1)

594-607: CLI may need to await post-response vars and should confirm response var source

Two points to verify:

  1. Source of postResponseVars — You're aggregating response vars into request.vars.res in mergeVars, but this reads from item:
const postResponseVars = get(item, 'request.vars.res');

Confirm whether merged collection/folder-level request.vars.res should be included here, and if so, update to read from the prepared request with a fallback:

-    const postResponseVars = get(item, 'request.vars.res');
+    const postResponseVars = get(request, 'vars.res', get(item, 'request.vars.res', []));
  1. Sync vs async execution — Verify whether VarsRuntime.runPostResponseVars is asynchronous. If it returns a Promise, add await to ensure vars are fully processed before post-response scripts and tests run.
packages/bruno-app/src/components/FolderSettings/index.js (1)

31-32: Correctly including post-response vars in active count

Using a separate responseVars array and summing enabled entries from both request and response scopes is clear, null-safe, and aligns with the existing pattern for requestVars.

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.

1 participant