Skip to content

feat(variables): persist scripted variable changes by default + re-enable disabled scripting APIs - #8315

Merged
bijin-bruno merged 27 commits into
usebruno:mainfrom
sanish-bruno:feat/variable-persistence
Jun 26, 2026
Merged

bijin-bruno merged 27 commits into
usebruno:mainfrom
sanish-bruno:feat/variable-persistence

Conversation

@sanish-bruno

@sanish-bruno sanish-bruno commented Jun 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Jira: BRU-3096

TL;DR

This PR makes all scripted variable changes persist to disk by default. Previously, bru.setEnvVar() was ephemeral (in-memory only) unless you passed { persist: true }. Now every call to bru.setEnvVar(), bru.setCollectionVar(), or bru.setGlobalEnvVar() automatically writes back to the environment/collection file. Several previously disabled scripting APIs (setCollectionVar, deleteCollectionVar, deleteGlobalEnvVar, etc.) are fully re-enabled because the UI sync problem they depended on is now solved.

Problem

Before this PR:

  1. Env vars set by scripts were ephemeral by default. Users had to write bru.setEnvVar("key", "val", { persist: true }) to make changes stick — most users expected the default behavior to persist.
  2. Many scripting APIs were disabled (setCollectionVar, deleteCollectionVar, deleteGlobalEnvVar, deleteAllGlobalEnvVars, etc.) because they modified the Bru object in the script runtime but the changes never propagated back to Redux / UI / filesystem.
  3. Draft-vs-saved conflict. When a user had unsaved edits open in the environment editor and a script modified variables, the two changes could clobber each other.

Solution

Always Persist + Dirty Flags

Removed the persistentEnvVariables / ephemeral flag model. The Bru class now tracks three dirty flags (_envDirty, _globalEnvDirty, _collVarsDirty) set whenever a scripting API mutates that scope. Script/test runtimes return null for clean scopes, and the Electron main process skips IPC sends for null scopes — most scripts only touch one scope, so we go from 3 IPC sends + 3 Redux dispatches + 3 potential disk writes per script execution down to one.

Content-Comparison Guards

Both renderer:save-environment and renderer:save-collection-root IPC handlers now compare serialized content against the existing file and skip the write if identical. Avoids triggering chokidar -> collection tree rebuild -> UI re-render cascade on idempotent script re-runs.

Baseline Diffing (Draft Awareness)

The trickiest part. Scripts run against the saved state, not any in-progress draft. If the script changes variable A and the user's draft changes variable B, naive application would clobber the user's draft of B.

The fix: when a script update arrives and a draft exists, snapshot the saved state as a baseline, flush the draft into the active env, then compare script output to baseline:

  • Variable changed relative to baseline -> apply script's value (script wins)
  • Variable unchanged from baseline -> keep draft value (user edit preserved)
  • Variable new -> add it
  • Variable deleted by script -> remove it

The baseline persists across pre-request + post-response of the same request, and is cleared at the start of the next request. Same pattern applied to all three scopes (env, global env, collection vars). Baselines are explicitly cleared in initRunRequestEvent, runFolderEvent (on testrun-started), wsConnectOnly, and sendCollectionOauth2Request to cover every request path.

Re-enabled Scripting APIs

With UI sync now working end-to-end, the following are un-commented and exposed in both the Node and QuickJS sandboxes, plus added to CodeMirror autocomplete:

  • bru.setCollectionVar(), bru.deleteCollectionVar(), bru.deleteAllCollectionVars(), bru.getAllCollectionVars()
  • bru.deleteGlobalEnvVar(), bru.deleteAllGlobalEnvVars()

Breaking Changes

  1. bru.setEnvVar(key, value, { persist: true }) — third argument removed. Passing it won't error (JS ignores extra args) but { persist: true } is no longer meaningful — all calls persist by default.
  2. Ephemeral variable concept removed. Variables no longer have ephemeral or persistedValue metadata. Any code relying on these internal properties will break.
  3. main:persistent-env-variables-update IPC event removed. Replaced by the existing main:script-environment-update triggering persistActiveEnvironment().
  4. New IPC events: main:collection-variables-update, main:runtime-variables-update.

Test Coverage

New unit tests (~2000 lines):

  • draft-env-merge.spec.js — scriptEnvironmentUpdateEvent reducer: direct apply, draft merge with baseline diffing, add/delete, disabled var preservation, multi-event sequences, cleanup
  • draft-collection-vars-merge.spec.js — collection vars draft-aware baseline diffing
  • draft-collection-vars-isolation.spec.js — script-driven saves do NOT persist draft headers/auth/scripts to disk
  • global-environments.spec.js — globalEnvironmentsUpdateEvent baseline diffing
  • bruno-js/tests/collectionVar.spec.js, globalEnvVar.spec.js — re-enabled API coverage

Updated unit tests:

  • setEnvVar.spec.js — removed all persist option tests
  • runtime.spec.js — collectionVariables in expected results, dirty-flag behavior

New E2E tests (Playwright):

  • variable-persistence.spec.ts + safe-mode variant
  • draft-merge-with-script.spec.ts (env, collection vars, global env variants)
  • global-env-var-persistence.spec.ts
  • collection-vars-draft-isolation.spec.ts

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 (see Breaking Changes above)
  • 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. (BRU-3096)

Summary by CodeRabbit

  • New Features
    • Expanded scripting variable APIs for collection variables and global environment variables (set/get/delete/delete-all).
    • Improved autocomplete for additional collection/global variable entries.
  • Bug Fixes
    • Script-driven variable updates now merge safely with in-progress drafts (including preserving disabled variables) and keep correct data-type labels.
    • Script variable persistence to disk is more reliable across subsequent requests; unchanged environment/collection files no longer rewrite.
    • bru.setEnvVar now uses only setEnvVar(key, value) (persist option removed).
  • Tests
    • Added/expanded draft-isolation and typed-variable persistence coverage (UI + on-disk).

@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Replaces opt-in { persist: true } env persistence with always-persist semantics across all variable scopes. Introduces dirty flags in Bru to gate script result serialization, re-enables previously stubbed collection/global env var APIs, rewrites Redux reducers with baseline-snapshot draft-merge logic, consolidates Electron IPC variable update events, and adds guards to skip redundant disk writes. Comprehensive unit and Playwright E2E tests included.

Changes

Script Variable Persistence with Draft-Aware Merge

Layer / File(s) Summary
Bru dirty-tracking flags and re-enabled variable APIs
packages/bruno-js/src/bru.js
Adds _envDirty, _globalEnvDirty, _collVarsDirty, _runtimeVarsDirty flags to constructor; removes options from setEnvVar; re-enables deleteGlobalEnvVar, deleteAllGlobalEnvVars, setCollectionVar, deleteCollectionVar, deleteAllCollectionVars, getAllCollectionVars with dirty-flag tracking.
QuickJS shim and runtime result dirty-flag gating
packages/bruno-js/src/sandbox/quickjs/shims/bru.js, packages/bruno-js/src/runtime/script-runtime.js, packages/bruno-js/src/runtime/test-runtime.js, packages/bruno-js/src/runtime/vars-runtime.js
Updates QuickJS shim to drop options from setEnvVar and expose global/collection var APIs. All runtimes now conditionally return envVariables, collectionVariables, globalEnvironmentVariables only when dirty; removes persistentEnvVariables from all result shapes.
Environment utilities and persistence dedup
packages/bruno-app/src/utils/environments.js, packages/bruno-app/src/utils/environments.spec.js, packages/bruno-app/src/utils/collections/index.js
Rewrites buildPersistedEnvVariables to strip ephemeral metadata without mode options. Adds applyScriptEnvVars with optional baseline-diff mode preserving draft edits while applying script changes. Removes { mode: 'save' } call-site in collection export.
Electron variable dispatch and file write guards
packages/bruno-electron/src/ipc/network/index.js, packages/bruno-electron/src/ipc/collection.js
Introduces sendVariableUpdates replacing per-script multi-IPC-send sequences across all execution phases. Adds content-comparison early returns in renderer:save-collection-root and renderer:save-environment to skip redundant writes. Supports nested bru.runRequest calls via parentRequestUid.
Redux collections slice: environment baseline merge and collection persistence
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js, packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
Rewrites scriptEnvironmentUpdateEvent with draft-flush and baseline capture via applyScriptEnvVars. Adds scriptUpdateCollectionVars, setScriptCollVarBaseline, _clearScriptCollectionBaselines reducers. Replaces mergeAndPersistEnvironment with new persistActiveEnvironment and collectionVariablesUpdateEvent thunks with baseline cleanup on request lifecycle events.
Redux global-environments slice: baseline capture and merge
packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js
Adds _scriptGlobalEnvBaseline state and _setScriptGlobalEnvBaseline/_clearScriptGlobalEnvBaseline reducers. Rewrites globalEnvironmentsUpdateEvent to flush/snapshot draft, apply applyScriptEnvVars, infer dataType, and persist with error logging. Remaps activeGlobalEnvironmentUid after reloads.
IPC listener wiring and baseline clearing
packages/bruno-app/src/providers/App/useIpcEvents.js
Adds main:runtime-variables-update and main:collection-variables-update listeners; extends main:script-environment-update to call persistActiveEnvironment when collectionUid present; clears global env baseline on testrun-started and request-queued.
Redux unit tests: draft-aware merge semantics
packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-env-merge.spec.js, draft-collection-vars-merge.spec.js, draft-collection-vars-isolation.spec.js, global-environments.spec.js
Jest suites validate draft-flush, baseline initialization, baseline-diff merge, deletion semantics, disabled-variable preservation, dataType inference and lifecycle, stale-request gating, and baseline cleanup across all variable scopes.
Bru API and utility unit tests
packages/bruno-js/tests/collectionVar.spec.js, globalEnvVar.spec.js, runtime.spec.js, setEnvVar.spec.js, packages/bruno-app/src/utils/environments.spec.js
Adds collection/global env var API unit tests with dirty-flag assertions; updates script-runtime and setEnvVar tests to remove persist-option expectations and verify dirty-flag gating; expands applyScriptEnvVars baseline and direct-apply mode coverage.
Bruno test fixtures, UI hooks, and test IDs
packages/bruno-tests/collection/scripting/api/bru/*, packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js, packages/bruno-app/src/utils/codemirror/autocomplete.js, tests/utils/page/locators.ts, tests/variable-datatypes/parsed-from-fixture.spec.ts
Removes bru.runner.skipRequest() early exits from fixtures; adds deleteEnvVar.bru and setGlobalEnvVar.bru; adds empty-scope no-throw test assertions; adds data-testid to unsaved-changes modal buttons; enables collection/global var API autocomplete hints; extends environment locators with variable row/value helpers and unsaved-modal actions; hardens datatype label assertions with attachment checks.
Playwright E2E: env persistence, draft merge, and isolation
tests/environments/*/, tests/scripting/bru-api/collection-vars-draft-isolation/, tests/scripting/bru-api/global-env-var-persistence/
E2E suites cover default env persistence across app restart, environment/collection/global draft-merge-with-script scenarios, collection draft-isolation with header preservation, and global environment variable set/delete persistence. Includes fixture definitions, user preferences, and on-disk .bru file assertions.
Playwright E2E: variable persistence in safe/developer modes and typed serialization
tests/scripting/bru-api/variable-persistence*/, tests/scripting/bru-api/global-env-var-persistence-typed/
E2E specs validate environment variable persistence in safe and developer sandbox modes, typed variable serialization with @number/@boolean/@object annotations in .bru files, and environment editor UI type labels (number, boolean, object) for persisted variables.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

  • usebruno/bruno#8046: Modifies datatype inference and environment merging in the same collections and global-environments reducer paths touched by this PR.
  • usebruno/bruno#8115: Updates Electron IPC variable event wiring, removing main:persistent-env-variables-update and adding main:runtime-variables-update and main:collection-variables-update listeners.
  • usebruno/bruno#7069: Implements Bru variable-scope APIs (collection/global env setters/deleters and dirty-flag plumbing) that this PR builds upon for persistence.

Poem

🗃️ No more { persist: true } to remember,
Scripts now save by default, come September.
Draft edits survive—a baseline snapshot guards,
Dirty flags skip the untouched regards.
Every var, every scope, safely to disk—🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: automatic persistence of scripted variable modifications and re-enabling previously disabled scripting APIs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 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

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

@sanish-bruno
sanish-bruno force-pushed the feat/variable-persistence branch from acf0c8e to cfb6333 Compare June 19, 2026 16:42
@sanish-bruno sanish-bruno changed the title Feat/variable persistence feat(variables): persist scripted variable changes by default + re-enable disabled scripting APIs Jun 19, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 13

🧹 Nitpick comments (5)
tests/utils/page/locators.ts (1)

89-90: ⚡ Quick win

Harden variable-name locators against selector-breaking characters

Lines 89-90 interpolate raw names into CSS (input[value="${name}"]), which can break for values containing quotes/brackets and cause false test failures.

Suggested minimal refactor
-    variableRowByName: (name: string) => page.locator('tbody tr').filter({ has: page.locator(`input[value="${name}"]`) }),
-    variableValue: (name: string) => page.locator('tbody tr').filter({ has: page.locator(`input[value="${name}"]`) }).locator('.CodeMirror-line').first(),
+    variableRowByName: (name: string) => page.locator('tbody tr').filter({ has: page.getByDisplayValue(name, { exact: true }) }),
+    variableValue: (name: string) =>
+      page
+        .locator('tbody tr')
+        .filter({ has: page.getByDisplayValue(name, { exact: true }) })
+        .locator('.CodeMirror-line')
+        .first(),
🤖 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 `@tests/utils/page/locators.ts` around lines 89 - 90, The variableRowByName and
variableValue methods in the locators object are using raw string interpolation
to build CSS attribute selectors with the name parameter, which breaks when the
name contains special characters like quotes or brackets. Replace the template
literal interpolation in both methods with a properly escaped version of the
name parameter that safely handles CSS attribute selector syntax, or use
Playwright's filter method with a safer attribute matching approach that handles
special characters automatically. This will prevent selector injection and
ensure the locators work correctly regardless of variable names.
tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/bruno.json (1)

1-9: ⚡ Quick win

Move this fixture tree to fixtures/collection/.

This suite only has one collection directory, so the singular fixture root is the expected layout. Based on learnings, reserve fixtures/collections/ for cases with multiple collection directories.

🤖 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
`@tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/bruno.json`
around lines 1 - 9, Move the entire fixture directory structure from the plural
form collections root to the singular form collection root. Since this test
suite contains only one collection directory, reorganize the fixture layout to
use the singular fixture root directory instead of the plural one, maintaining
the same internal structure (collection-vars-draft-merge-test and its contents).

Source: Learnings

tests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.ts (1)

27-28: ⚡ Quick win

Replace the fixed debounce sleep.

waitForTimeout(500) makes this test flaky and slower; wait on the draft state or a locator condition instead. As per coding guidelines, avoid hardcoded waits in E2E tests.

🤖 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
`@tests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.ts`
around lines 27 - 28, The test is using a hardcoded page.waitForTimeout(500)
which creates flakiness and unnecessary delays; replace this fixed timeout with
a proper wait condition that checks for the draft state update or a specific
locator condition. Use Playwright's conditional wait methods such as
waitForFunction to wait for the draft debounce to complete by checking the
actual state or UI element that indicates the draft has finished processing,
rather than sleeping for an arbitrary duration.

Source: Coding guidelines

tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/bruno.json (1)

1-9: ⚡ Quick win

Keep the fixture tree singular for one collection.

tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test only contains one collection, so fixtures/collection/ would match the repo convention and avoid layout drift.

Based on learnings, use fixtures/collection when there is a single collection, and fixtures/collections only when there are multiple collection directories inside the fixtures folder.

🤖 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
`@tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/bruno.json`
around lines 1 - 9, The directory naming convention is inconsistent with the
repository standards. Since this fixture contains only a single collection
(global-env-draft-merge-test), rename the parent directory from
`fixtures/collections/` to `fixtures/collection/` (singular). Keep the
bruno.json file and all its contents unchanged in the renamed directory. This
aligns with the convention where `fixtures/collection/` is used for single
collections and `fixtures/collections/` is reserved for fixtures containing
multiple collection directories.

Source: Learnings

tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/bruno.json (1)

1-9: ⚡ Quick win

Keep the fixture tree singular for one collection.

tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test only contains one collection, so fixtures/collection/ would match the repo convention and avoid layout drift.

Based on learnings, use fixtures/collection when there is a single collection, and fixtures/collections only when there are multiple collection directories inside the fixtures folder.

🤖 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
`@tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/bruno.json`
around lines 1 - 9, The fixture directory structure uses the plural form
`collections` in the path when there is only one collection present, which
deviates from the repository convention. Rename the directory from `collections`
to `collection` (singular) in the fixture path for draft-merge-test, as the
convention specifies that `fixtures/collection/` should be used for single
collections and `fixtures/collections/` should only be used when there are
multiple collection directories inside the fixtures folder.

Source: Learnings

🤖 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-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 2378-2402: Remove the duplicate code block that infers dataType
from collectionVariables. In the collection variables actions file, there are
two identical Object.entries loops that iterate over collectionVariables and
call getDataTypeFromValue to infer and assign the dataType property. Delete the
second occurrence of this entire loop (the one that comes after the first
dataType inference block) as it is an exact duplicate and serves no purpose.

In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js`:
- Around line 2663-2680: The scriptUpdateCollectionVars reducer is not
preserving the dataType property when mapping collection variables, even though
the corresponding action in actions.js explicitly sets this field. In the map
function that destructures each variable object, add dataType to the
destructuring parameters, and include dataType in the returned mapped object
alongside uid, name, value, and enabled to ensure typed values round-trip
correctly through the script-to-disk path as intended by the action.

In `@packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js`:
- Around line 326-346: The dataType inference block that iterates through
variables using forEach and calls getDataTypeFromValue is duplicated immediately
after itself. Remove the second occurrence of this entire forEach loop (the one
checking if inferred === 'string', deleting v.dataType, and setting v.dataType
to the inferred value) as it performs the exact same operation on the same
variables collection that was already processed in the first loop, resulting in
unnecessary duplicate processing.

In `@packages/bruno-app/src/utils/environments.spec.js`:
- Line 6: The applyScriptEnvVars function lacks unit test coverage despite
containing complex branching logic for baseline vs non-baseline modes and
filtering logic that is actively used in three production locations. Add
comprehensive test cases to the environments.spec.js file that cover both the
baseline and non-baseline code paths of applyScriptEnvVars, validate the
filtering behavior, and ensure the function handles edge cases properly. Import
the applyScriptEnvVars function in the import statement and create describe
blocks with multiple it test cases that exercise each branch of the conditional
logic and verify the output for different input scenarios.

In `@packages/bruno-js/src/bru.js`:
- Around line 262-269: The deleteAllGlobalEnvVars method directly calls
.hasOwnProperty() on the user-controlled this.globalEnvironmentVariables object,
which can be shadowed if a user sets a variable with that name, causing a crash.
Replace the for-in loop with Object.keys() iteration to safely delete all keys
without relying on the potentially shadowed method. Apply this same fix to the
other bulk-delete methods (deleteAllEnvVars, deleteAllVars,
deleteAllCollectionVars) for consistency with how single-key check methods
already handle this safely.

In
`@tests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.ts`:
- Around line 23-25: The keyboard shortcut Meta+a in the test is
platform-specific and only works on macOS, causing the text replacement to fail
on Windows and Linux. Replace the Meta+a keyboard press with a platform-aware
shortcut that uses Control+a on Windows/Linux and Meta+a on macOS. You can
achieve this by checking the platform using process.platform or using
Playwright's built-in platform detection to determine the correct modifier key
before calling page.keyboard.press() in the test scenario where existingCollVar
value is being edited.

In `@tests/environments/draft-merge-with-script/draft-merge-with-script.spec.ts`:
- Around line 26-27: Replace the hard-coded page.waitForTimeout(500) call in the
draft merge test with a more robust waiting mechanism that observes changes to
the draft state or value instead of using a fixed timeout. Use
page.waitForFunction or a similar observable-based approach to wait for the
draft to stabilize after the debounce period, making the test more reliable
across different CI environments and avoiding flakiness on slower machines.
- Around line 22-24: The keyboard shortcut Meta+a used in the
page.keyboard.press() call is platform-specific and only works on macOS. Replace
the hardcoded Meta+a with a platform-agnostic approach by checking
process.platform to determine if the platform is darwin (macOS), then use Meta+a
for macOS or Control+a for Windows and Linux. This pattern is already used
elsewhere in the test suite such as in editable-table.spec.ts, so follow the
same approach for consistency.

In
`@tests/environments/global-env-draft-merge-with-script/global-env-draft-merge-with-script.spec.ts`:
- Around line 20-21: The test at line 20 uses `Meta+a` keyboard shortcut which
is macOS-specific and will fail on Windows/Linux CI environments. Replace the
`page.keyboard.press('Meta+a')` call with a cross-platform select-all shortcut
that works on all operating systems. Use `Control+a` which is the standard
select-all shortcut that works consistently across macOS, Windows, and Linux
platforms.
- Line 24: The hardcoded `page.waitForTimeout(500)` call in the test is brittle
and may fail in slower or faster environments. Replace this fixed sleep with an
event-driven wait that waits for the actual draft synchronization to complete,
such as waiting for a specific element to appear, a network request to finish,
or a particular state change that indicates the draft has been synchronized. Use
appropriate Playwright methods like waitForSelector, waitForLoadState, or
waitForFunction to detect when the synchronization is actually complete rather
than relying on an arbitrary timeout value.

In
`@tests/scripting/bru-api/collection-vars-draft-isolation/collection-vars-draft-isolation.spec.ts`:
- Around line 33-39: Replace the `Meta+a` keyboard shortcut with a
cross-platform approach by using either `Ctrl+a` with a platform detection or by
calling `selectText()` method directly on the valueCellEditor locator. Then
remove the hardcoded `waitForTimeout(500)` sleep and instead wait for a concrete
UI state signal that indicates the draft has been saved or the debounce has
completed, such as waiting for a specific element to appear, a class to be
applied, or an API response.

In
`@tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/bruno.json`:
- Around line 1-9: The parent directory for the draft-isolation-test collection
is currently named collections (plural) but should be singular since it contains
only one collection. Rename the fixtures/collections directory to
fixtures/collection to align with the established naming convention for fixture
directories. This affects the entire directory structure containing the
bruno.json file for draft-isolation-test, so ensure all references and paths are
updated accordingly.

In
`@tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/bruno.json`:
- Around line 1-9: This fixture tree for the global-env-var-persistence-test is
incorrectly placed under fixtures/collections (plural) when it only contains a
single collection. Move the entire directory structure containing bruno.json
from fixtures/collections/global-env-var-persistence-test/ to
fixtures/collection/global-env-var-persistence-test/ to align with the repo
convention of using fixtures/collection (singular) for single-collection test
suites and fixtures/collections (plural) for multi-collection fixtures. Ensure
all references to this fixture path in test configuration files are updated
accordingly.

---

Nitpick comments:
In
`@tests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.ts`:
- Around line 27-28: The test is using a hardcoded page.waitForTimeout(500)
which creates flakiness and unnecessary delays; replace this fixed timeout with
a proper wait condition that checks for the draft state update or a specific
locator condition. Use Playwright's conditional wait methods such as
waitForFunction to wait for the draft debounce to complete by checking the
actual state or UI element that indicates the draft has finished processing,
rather than sleeping for an arbitrary duration.

In
`@tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/bruno.json`:
- Around line 1-9: Move the entire fixture directory structure from the plural
form collections root to the singular form collection root. Since this test
suite contains only one collection directory, reorganize the fixture layout to
use the singular fixture root directory instead of the plural one, maintaining
the same internal structure (collection-vars-draft-merge-test and its contents).

In
`@tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/bruno.json`:
- Around line 1-9: The fixture directory structure uses the plural form
`collections` in the path when there is only one collection present, which
deviates from the repository convention. Rename the directory from `collections`
to `collection` (singular) in the fixture path for draft-merge-test, as the
convention specifies that `fixtures/collection/` should be used for single
collections and `fixtures/collections/` should only be used when there are
multiple collection directories inside the fixtures folder.

In
`@tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/bruno.json`:
- Around line 1-9: The directory naming convention is inconsistent with the
repository standards. Since this fixture contains only a single collection
(global-env-draft-merge-test), rename the parent directory from
`fixtures/collections/` to `fixtures/collection/` (singular). Keep the
bruno.json file and all its contents unchanged in the renamed directory. This
aligns with the convention where `fixtures/collection/` is used for single
collections and `fixtures/collections/` is reserved for fixtures containing
multiple collection directories.

In `@tests/utils/page/locators.ts`:
- Around line 89-90: The variableRowByName and variableValue methods in the
locators object are using raw string interpolation to build CSS attribute
selectors with the name parameter, which breaks when the name contains special
characters like quotes or brackets. Replace the template literal interpolation
in both methods with a properly escaped version of the name parameter that
safely handles CSS attribute selector syntax, or use Playwright's filter method
with a safer attribute matching approach that handles special characters
automatically. This will prevent selector injection and ensure the locators work
correctly regardless of variable names.
🪄 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: 2c0723a4-6758-4bc7-82cc-4fa614c1a9fc

📥 Commits

Reviewing files that changed from the base of the PR and between 6136d3a and cfb6333.

📒 Files selected for processing (92)
  • packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js
  • packages/bruno-app/src/providers/App/useIpcEvents.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-isolation.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-merge.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-env-merge.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js
  • packages/bruno-app/src/providers/ReduxStore/slices/global-environments.spec.js
  • packages/bruno-app/src/utils/codemirror/autocomplete.js
  • packages/bruno-app/src/utils/collections/index.js
  • packages/bruno-app/src/utils/environments.js
  • packages/bruno-app/src/utils/environments.spec.js
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/ipc/network/index.js
  • packages/bruno-js/src/bru.js
  • packages/bruno-js/src/runtime/script-runtime.js
  • packages/bruno-js/src/runtime/test-runtime.js
  • packages/bruno-js/src/runtime/vars-runtime.js
  • packages/bruno-js/src/sandbox/quickjs/shims/bru.js
  • packages/bruno-js/tests/collectionVar.spec.js
  • packages/bruno-js/tests/globalEnvVar.spec.js
  • packages/bruno-js/tests/runtime.spec.js
  • packages/bruno-js/tests/setEnvVar.spec.js
  • packages/bruno-tests/collection/ping.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteAllCollectionVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteAllEnvVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteAllGlobalEnvVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteCollectionVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteEnvVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteGlobalEnvVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/getAllCollectionVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/setCollectionVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/setGlobalEnvVar.bru
  • tests/environments/api-setEnvVar/api-setEnvVar-default-persistence.spec.ts
  • tests/environments/api-setEnvVar/api-setEnvVar-with-persist.spec.ts
  • tests/environments/api-setEnvVar/api-setEnvVar-without-persist.spec.ts
  • tests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-default-persistence.bru
  • tests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-with-persist.bru
  • tests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-1.bru
  • tests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-2.bru
  • tests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.ts
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/bruno.json
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/collection.bru
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/environments/Test.bru
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/set-collection-var.bru
  • tests/environments/collection-vars-draft-merge-with-script/init-user-data/collection-security.json
  • tests/environments/collection-vars-draft-merge-with-script/init-user-data/preferences.json
  • tests/environments/datatype-preservation/datatype-preservation.spec.ts
  • tests/environments/draft-merge-with-script/draft-merge-with-script.spec.ts
  • tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/bruno.json
  • tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/environments/Test.bru
  • tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/set-env-var.bru
  • tests/environments/draft-merge-with-script/init-user-data/collection-security.json
  • tests/environments/draft-merge-with-script/init-user-data/preferences.json
  • tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/bruno.json
  • tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/set-global-env-var.bru
  • tests/environments/global-env-draft-merge-with-script/global-env-draft-merge-with-script.spec.ts
  • tests/environments/global-env-draft-merge-with-script/init-user-data/collection-security.json
  • tests/environments/global-env-draft-merge-with-script/init-user-data/global-environments.json
  • tests/environments/global-env-draft-merge-with-script/init-user-data/preferences.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/collection-vars-draft-isolation.spec.ts
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/bruno.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/collection.bru
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/environments/Test.bru
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/set-collection-var.bru
  • tests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/collection-security.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/preferences.json
  • tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/bruno.json
  • tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/delete-global-env-var.bru
  • tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/set-global-env-var.bru
  • tests/scripting/bru-api/global-env-var-persistence/global-env-var-persistence.spec.ts
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/collection-security.json
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/global-environments.json
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-collection-var.bru
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-env-var.bru
  • tests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/variable-persistence-safe-mode.spec.ts
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/bruno.json
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-collection-var.bru
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-env-var.bru
  • tests/scripting/bru-api/variable-persistence/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence/variable-persistence.spec.ts
  • tests/utils/page/locators.ts
  • tests/variable-datatypes/parsed-from-fixture.spec.ts
💤 Files with no reviewable changes (4)
  • tests/environments/api-setEnvVar/api-setEnvVar-without-persist.spec.ts
  • packages/bruno-tests/collection/scripting/api/bru/setCollectionVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/getAllCollectionVars.bru
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.spec.js

Comment thread packages/bruno-js/src/bru.js Resolved

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/bruno.json (1)

1-10: ⚡ Quick win

Align fixture path convention (collection vs collections) for single-collection setup.

This fixture appears to represent a single collection case but is under fixtures/collections. Consider moving to fixtures/collection for consistency with the repo’s E2E fixture convention.

Based on learnings: "use fixtures/collection (singular) when there is a single collection, and fixtures/collections (plural) when there are multiple collection directories inside the fixtures folder."

🤖 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
`@tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/bruno.json`
around lines 1 - 10, This fixture represents a single collection but is
currently placed under a plural directory name (collections). Reorganize the
fixture structure to follow the repository's naming convention: move the
variable-persistence-typed-safe-test fixture directory from the plural
collections folder to a singular collection folder to align with the established
pattern of using collection (singular) for single-collection setups and
collections (plural) for multiple-collection setups.

Source: Learnings

🤖 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-app/src/utils/environments.spec.js`:
- Around line 172-179: The test for applyScriptEnvVars has a key naming mismatch
where draftVars uses 'was-saved' (kebab-case) but the baseline object and the
assertion use 'wasSaved' (camelCase). This inconsistency causes the test to pass
without properly validating the intended behavior of removing variables present
in baseline but missing from scriptVars. Fix this by making the variable names
consistent across draftVars, baseline, and the assertion in the expect statement
- either change 'was-saved' to 'wasSaved' in draftVars, or change 'wasSaved' to
'was-saved' in both the baseline object and the find assertion.

In
`@tests/scripting/bru-api/variable-persistence-typed-safe-mode/variable-persistence-typed-safe-mode.spec.ts`:
- Around line 71-72: The code at lines 71-72 is duplicating a close pattern that
should be encapsulated in the existing `closeEnvironmentPanel()` helper function
from `tests/utils/page/actions.ts`. Replace the inline
`locators.environment.collectionEnvTab().hover()` and
`locators.environment.collectionEnvTab().getByTestId('request-tab-close-icon').click({
force: true })` calls with a single call to `closeEnvironmentPanel()`.
Additionally, add an assertion immediately after to verify the environment tab
is closed by checking that `locators.environment.collectionEnvTab()` is not
visible using `await
expect(locators.environment.collectionEnvTab()).not.toBeVisible();` to confirm
the behavioural outcome.

In
`@tests/scripting/bru-api/variable-persistence-typed/variable-persistence-typed.spec.ts`:
- Around line 71-72: The click action on the 'request-tab-close-icon' element
uses force: true which can mask visibility issues and make test failures harder
to diagnose. Since the close icon is visible after the hover action on
collectionEnvTab, remove the { force: true } parameter from the click call and
use a normal click instead to allow proper visibility validation.

---

Nitpick comments:
In
`@tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/bruno.json`:
- Around line 1-10: This fixture represents a single collection but is currently
placed under a plural directory name (collections). Reorganize the fixture
structure to follow the repository's naming convention: move the
variable-persistence-typed-safe-test fixture directory from the plural
collections folder to a singular collection folder to align with the established
pattern of using collection (singular) for single-collection setups and
collections (plural) for multiple-collection setups.
🪄 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: dff3499a-3202-4692-aa45-48aed9f2e8a3

📥 Commits

Reviewing files that changed from the base of the PR and between cfb6333 and b7af3bc.

📒 Files selected for processing (44)
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-merge.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-env-merge.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js
  • packages/bruno-app/src/providers/ReduxStore/slices/global-environments.spec.js
  • packages/bruno-app/src/utils/environments.spec.js
  • packages/bruno-js/src/bru.js
  • packages/bruno-js/tests/collectionVar.spec.js
  • packages/bruno-js/tests/globalEnvVar.spec.js
  • packages/bruno-js/tests/runtime.spec.js
  • packages/bruno-js/tests/setEnvVar.spec.js
  • tests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.ts
  • tests/environments/collection-vars-draft-merge-with-script/init-user-data/preferences.json
  • tests/environments/draft-merge-with-script/draft-merge-with-script.spec.ts
  • tests/environments/draft-merge-with-script/init-user-data/preferences.json
  • tests/environments/global-env-draft-merge-with-script/global-env-draft-merge-with-script.spec.ts
  • tests/environments/global-env-draft-merge-with-script/init-user-data/preferences.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/collection-vars-draft-isolation.spec.ts
  • tests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/preferences.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/bruno.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/set-typed-global-env-vars.bru
  • tests/scripting/bru-api/global-env-var-persistence-typed/global-env-var-persistence-typed.spec.ts
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/collection-security.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/global-environments.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/preferences.json
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-collection-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-env-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/variable-persistence-typed-safe-mode.spec.ts
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-collection-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-env-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence-typed/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-typed/variable-persistence-typed.spec.ts
  • tests/scripting/bru-api/variable-persistence/init-user-data/preferences.json
  • tests/utils/page/locators.ts
💤 Files with no reviewable changes (1)
  • packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js
✅ Files skipped from review due to trivial changes (18)
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence-typed/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-env-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-env-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/environments/Test.bru
  • tests/environments/global-env-draft-merge-with-script/init-user-data/preferences.json
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/preferences.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/global-env-var-persistence-typed.spec.ts
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/preferences.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/global-environments.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-collection-vars.bru
  • tests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/bruno.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/preferences.json
  • tests/environments/draft-merge-with-script/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-typed/init-user-data/collection-security.json
🚧 Files skipped from review as they are similar to previous changes (12)
  • tests/environments/global-env-draft-merge-with-script/global-env-draft-merge-with-script.spec.ts
  • tests/environments/draft-merge-with-script/draft-merge-with-script.spec.ts
  • tests/scripting/bru-api/variable-persistence/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/preferences.json
  • tests/environments/collection-vars-draft-merge-with-script/init-user-data/preferences.json
  • tests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.ts
  • packages/bruno-js/tests/globalEnvVar.spec.js
  • tests/scripting/bru-api/collection-vars-draft-isolation/collection-vars-draft-isolation.spec.ts
  • tests/utils/page/locators.ts
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-js/src/bru.js

@sanish-bruno
sanish-bruno force-pushed the feat/variable-persistence branch from b4d5a80 to e6cf433 Compare June 21, 2026 06:39

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 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-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 628-629: The sendRequest function is inconsistent with other
request-dispatching functions like sendCollectionOauth2Request and
wsConnectOnly. Replace the dispatch(_clearScriptGlobalEnvBaseline()) call with
dispatch(clearScriptVariableBaselines(collectionUid)) to ensure all baseline
clearing paths (both collection-scope and global-scope) are cleared
consistently. This aligns sendRequest with the pattern used in the other request
functions and matches the intended behavior of the clearScriptVariableBaselines
function which clears both scopes.

In `@packages/bruno-js/src/bru.js`:
- Around line 270-272: The getAllGlobalEnvVars method uses Object.assign which
creates only a shallow copy, allowing consumers to mutate nested objects without
triggering the dirty flag mechanism. Replace the shallow copy with a deep copy
implementation (such as JSON.parse(JSON.stringify()) or a proper deep cloning
utility) to ensure that nested mutations are properly tracked and dirty flags
are set correctly. Apply the same deep copy approach to the similar method at
line 400-402 that also returns a shallow copy.

In
`@tests/environments/global-env-draft-merge-with-script/global-env-draft-merge-with-script.spec.ts`:
- Around line 42-43: The test directly clicks the global environment tab without
ensuring it's in a stable, properly opened state after prior modal or navigation
operations, which can cause flakiness. Replace the direct click on
locators.environment.globalEnvTab().click() with a call to the
openEnvironmentSelector(page, 'global') helper function from
tests/utils/page/actions.ts. This ensures the global environment selector is
properly reopened and in a stable visible state before performing the final
assertions.
🪄 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: 977aec3c-d84d-4997-9639-d434f3b59b5d

📥 Commits

Reviewing files that changed from the base of the PR and between b4d5a80 and e6cf433.

📒 Files selected for processing (112)
  • packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js
  • packages/bruno-app/src/providers/App/useIpcEvents.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-isolation.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-merge.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-env-merge.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js
  • packages/bruno-app/src/providers/ReduxStore/slices/global-environments.spec.js
  • packages/bruno-app/src/utils/codemirror/autocomplete.js
  • packages/bruno-app/src/utils/collections/index.js
  • packages/bruno-app/src/utils/environments.js
  • packages/bruno-app/src/utils/environments.spec.js
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/ipc/network/index.js
  • packages/bruno-js/src/bru.js
  • packages/bruno-js/src/runtime/script-runtime.js
  • packages/bruno-js/src/runtime/test-runtime.js
  • packages/bruno-js/src/runtime/vars-runtime.js
  • packages/bruno-js/src/sandbox/quickjs/shims/bru.js
  • packages/bruno-js/tests/collectionVar.spec.js
  • packages/bruno-js/tests/globalEnvVar.spec.js
  • packages/bruno-js/tests/runtime.spec.js
  • packages/bruno-js/tests/setEnvVar.spec.js
  • packages/bruno-tests/collection/ping.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteAllCollectionVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteAllEnvVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteAllGlobalEnvVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteCollectionVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteEnvVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteGlobalEnvVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/getAllCollectionVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/setCollectionVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/setGlobalEnvVar.bru
  • tests/environments/api-setEnvVar/api-setEnvVar-default-persistence.spec.ts
  • tests/environments/api-setEnvVar/api-setEnvVar-with-persist.spec.ts
  • tests/environments/api-setEnvVar/api-setEnvVar-without-persist.spec.ts
  • tests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-default-persistence.bru
  • tests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-with-persist.bru
  • tests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-1.bru
  • tests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-2.bru
  • tests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.ts
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/bruno.json
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/collection.bru
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/environments/Test.bru
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/set-collection-var.bru
  • tests/environments/collection-vars-draft-merge-with-script/init-user-data/collection-security.json
  • tests/environments/collection-vars-draft-merge-with-script/init-user-data/preferences.json
  • tests/environments/datatype-preservation/datatype-preservation.spec.ts
  • tests/environments/draft-merge-with-script/draft-merge-with-script.spec.ts
  • tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/bruno.json
  • tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/environments/Test.bru
  • tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/set-env-var.bru
  • tests/environments/draft-merge-with-script/init-user-data/collection-security.json
  • tests/environments/draft-merge-with-script/init-user-data/preferences.json
  • tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/bruno.json
  • tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/set-global-env-var.bru
  • tests/environments/global-env-draft-merge-with-script/global-env-draft-merge-with-script.spec.ts
  • tests/environments/global-env-draft-merge-with-script/init-user-data/collection-security.json
  • tests/environments/global-env-draft-merge-with-script/init-user-data/global-environments.json
  • tests/environments/global-env-draft-merge-with-script/init-user-data/preferences.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/collection-vars-draft-isolation.spec.ts
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/bruno.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/collection.bru
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/environments/Test.bru
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/set-collection-var.bru
  • tests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/collection-security.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/preferences.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/bruno.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/set-typed-global-env-vars.bru
  • tests/scripting/bru-api/global-env-var-persistence-typed/global-env-var-persistence-typed.spec.ts
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/collection-security.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/global-environments.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/preferences.json
  • tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/bruno.json
  • tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/delete-global-env-var.bru
  • tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/set-global-env-var.bru
  • tests/scripting/bru-api/global-env-var-persistence/global-env-var-persistence.spec.ts
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/collection-security.json
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/global-environments.json
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-collection-var.bru
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-env-var.bru
  • tests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/variable-persistence-safe-mode.spec.ts
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-collection-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-env-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/variable-persistence-typed-safe-mode.spec.ts
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-collection-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-env-vars.bru
  • tests/scripting/bru-api/variable-persistence-typed/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence-typed/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-typed/variable-persistence-typed.spec.ts
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/bruno.json
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-collection-var.bru
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-env-var.bru
  • tests/scripting/bru-api/variable-persistence/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence/variable-persistence.spec.ts
  • tests/utils/page/locators.ts
  • tests/variable-datatypes/parsed-from-fixture.spec.ts
💤 Files with no reviewable changes (4)
  • packages/bruno-tests/collection/scripting/api/bru/setCollectionVar.bru
  • tests/environments/api-setEnvVar/api-setEnvVar-without-persist.spec.ts
  • packages/bruno-tests/collection/scripting/api/bru/getAllCollectionVars.bru
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.spec.js
✅ Files skipped from review due to trivial changes (42)
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/bruno.json
  • tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/bruno.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/collection-security.json
  • tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/bruno.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/bruno.json
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/environments/Test.bru
  • tests/environments/draft-merge-with-script/init-user-data/preferences.json
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/bruno.json
  • packages/bruno-tests/collection/ping.bru
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/global-environments.json
  • tests/scripting/bru-api/variable-persistence/init-user-data/preferences.json
  • tests/environments/global-env-draft-merge-with-script/init-user-data/preferences.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/preferences.json
  • packages/bruno-tests/collection/scripting/api/bru/deleteEnvVar.bru
  • tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/delete-global-env-var.bru
  • tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/preferences.json
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/global-environments.json
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/environments/Test.bru
  • tests/environments/draft-merge-with-script/init-user-data/collection-security.json
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/preferences.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/environments/Test.bru
  • tests/environments/global-env-draft-merge-with-script/init-user-data/global-environments.json
  • tests/scripting/bru-api/variable-persistence-typed/init-user-data/collection-security.json
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/preferences.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/bruno.json
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/collection.bru
  • tests/environments/api-setEnvVar/api-setEnvVar-with-persist.spec.ts
  • tests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/collection-security.json
  • tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/environments/Test.bru
  • tests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/collection-security.json
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-env-vars.bru
  • tests/environments/collection-vars-draft-merge-with-script/init-user-data/preferences.json
  • tests/environments/collection-vars-draft-merge-with-script/init-user-data/collection-security.json
  • tests/environments/global-env-draft-merge-with-script/init-user-data/collection-security.json
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/collection.bru
  • tests/scripting/bru-api/variable-persistence-typed/init-user-data/preferences.json
  • tests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-default-persistence.bru
🚧 Files skipped from review as they are similar to previous changes (55)
  • tests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-2.bru
  • tests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-with-persist.bru
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/environments/Test.bru
  • tests/scripting/bru-api/variable-persistence-typed/variable-persistence-typed.spec.ts
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-collection-var.bru
  • tests/scripting/bru-api/variable-persistence-safe-mode/variable-persistence-safe-mode.spec.ts
  • tests/scripting/bru-api/variable-persistence/variable-persistence.spec.ts
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-collection-var.bru
  • tests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/set-typed-global-env-vars.bru
  • tests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-1.bru
  • tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/set-global-env-var.bru
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-env-var.bru
  • tests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/set-global-env-var.bru
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-collection-vars.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteCollectionVar.bru
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/collection-security.json
  • tests/environments/datatype-preservation/datatype-preservation.spec.ts
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/variable-persistence-typed-safe-mode.spec.ts
  • packages/bruno-js/src/sandbox/quickjs/shims/bru.js
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/preferences.json
  • packages/bruno-tests/collection/scripting/api/bru/setGlobalEnvVar.bru
  • tests/scripting/bru-api/collection-vars-draft-isolation/collection-vars-draft-isolation.spec.ts
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/bruno.json
  • tests/environments/draft-merge-with-script/draft-merge-with-script.spec.ts
  • packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js
  • tests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/bruno.json
  • tests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-env-vars.bru
  • packages/bruno-electron/src/ipc/collection.js
  • tests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/set-collection-var.bru
  • tests/scripting/bru-api/global-env-var-persistence-typed/global-env-var-persistence-typed.spec.ts
  • tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/set-env-var.bru
  • tests/scripting/bru-api/global-env-var-persistence/global-env-var-persistence.spec.ts
  • tests/environments/api-setEnvVar/api-setEnvVar-default-persistence.spec.ts
  • packages/bruno-js/tests/collectionVar.spec.js
  • tests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-env-var.bru
  • packages/bruno-js/tests/setEnvVar.spec.js
  • tests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/set-collection-var.bru
  • tests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-collection-vars.bru
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-isolation.spec.js
  • tests/variable-datatypes/parsed-from-fixture.spec.ts
  • packages/bruno-app/src/providers/App/useIpcEvents.js
  • packages/bruno-app/src/utils/collections/index.js
  • packages/bruno-tests/collection/scripting/api/bru/deleteAllGlobalEnvVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteGlobalEnvVar.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteAllCollectionVars.bru
  • packages/bruno-tests/collection/scripting/api/bru/deleteAllEnvVars.bru
  • tests/scripting/bru-api/global-env-var-persistence/init-user-data/collection-security.json
  • packages/bruno-js/tests/globalEnvVar.spec.js
  • tests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.ts
  • packages/bruno-app/src/utils/codemirror/autocomplete.js
  • packages/bruno-app/src/utils/environments.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js
  • tests/utils/page/locators.ts
  • packages/bruno-app/src/utils/environments.spec.js

Comment thread packages/bruno-js/src/bru.js Resolved
vijayh-bruno
vijayh-bruno previously approved these changes Jun 23, 2026

@vijayh-bruno vijayh-bruno left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Concerns around avoiding collection deep cloning wherever not required were addressed.

LGTM!

@vijayh-bruno

Copy link
Copy Markdown
Collaborator

@bijin-bruno - can you take a final pass at this one and merge if its good for it?

Comment thread packages/bruno-js/src/bru.js Resolved
…eractions

- Updated test cases to reflect the correct variable name 'wasSaved' instead of 'was-saved'.
- Modified environment panel interaction to remove forced click, enhancing test reliability.
- Added a utility function to close the environment panel in safe mode tests for better readability and maintainability.
- Introduced a new method to clear script-driven variable baselines for collections, ensuring no stale data leaks into new requests.
- Updated the handling of runtime variables in the Bru class to track changes with a new dirty flag, improving state management.
- Refactored the application of script environment variables to prevent direct mutations, ensuring immutability and cleaner state updates.
- Enhanced the response handling in the script runtime to conditionally include runtime variables based on their dirty state.
…llections and environments

- Enhanced event listeners to clear global environment baselines on both 'testrun-started' and 'request-queued' events, preventing stale data issues.
- Updated global environment and collection variable update events to ignore stale updates from superseded requests, ensuring accurate state management.
- Refactored the Bru class to optimize variable management, including checks for existing keys before updates and deletions, improving performance and reliability.
- Introduced request UID tracking to maintain consistency across variable updates during concurrent requests.
- Replaced the dispatch of `_clearScriptGlobalEnvBaseline` with `clearScriptVariableBaselines` to improve clarity and maintainability in the Redux action handling for collections.
…ved variable management

- Added a new utility function, `getScriptModifiedKeys`, to identify keys modified by scripts relative to a baseline, enhancing the handling of data types during variable updates.
- Updated the application of script environment variables to prevent overwriting user-defined draft changes during no-op writes.
- Refactored related logic in collections and global environments to utilize the new utility, ensuring accurate state management and improved clarity in the Redux slices.
…n updateGlobalEnvironments reducer

- Streamlined the logic for resolving the active global environment UID by consolidating conditions into a more concise format.
- Removed outdated comments to enhance code clarity and maintainability.
- Updated tests to ensure accurate resolution of active UIDs based on incoming environment data.
…variable row expectations

- Eliminated comments related to state sync and inference issues to enhance code clarity.
- Adjusted expectations for environment variable row rendering in tests, focusing on relevant assertions.
…in environments

- Introduced new test cases to validate the preservation of secret variables when updated via scripts in both collection and global environments.
- Implemented tests to ensure that secret values are encrypted before storage and can be correctly decrypted for subsequent requests.
- Added fixtures and environment configurations for testing secret variable behavior in both bru and yml formats.
- Enhanced utility functions for managing environment configurations and interactions within the test suite.
…le persistence

- Updated MultiLineEditor and SingleLineEditor components to include data-testid for secret reveal toggle buttons, improving testability.
- Introduced new tests for global environment variable persistence, ensuring non-secret variables survive app restarts and are correctly interpolated.
- Added fixtures for workspace and collections to support the new global variable tests, enhancing the overall test coverage for environment management.
- Refactored utility functions to streamline interactions with environment variables in tests.
- Simplified the persistence logic for active environments by directly constructing the environment copy, reducing unnecessary cloning.
- Updated the collection saving process to utilize the fresh collection state, ensuring accurate data is saved without drafts.
- Enhanced error handling during the save operations to improve reliability and maintainability.
- Added multiple test cases to validate the persistence of collection variables across app restarts, including typed values and multiple variable settings.
- Created new fixtures for collection variables to support the tests, ensuring accurate simulation of variable management scenarios.
- Enhanced the existing collection management logic to ensure that variables are correctly set and deleted as per the test requirements.
- Introduced a new test suite to validate the persistence of typed global environment variables across app restarts, ensuring correct data types are maintained.
- Created a fixture for the test collection to simulate setting global variables with various data types, including number, boolean, object, and string.
- Enhanced the test logic to verify that the environment file reflects the correct state before and after application restarts.
…r tests

- Updated the hover logic for revealing collection actions to handle sidebar re-renders more reliably.
- Replaced one-shot hover with a polling mechanism to ensure visibility of actions, enhancing test stability.
…remove ephemeral metadata logic

- Simplified the comparison logic for environment variables by removing unnecessary ephemeral metadata handling.
- Updated the saving process to directly use the environment variables without stripping metadata, enhancing clarity and maintainability.
- Removed outdated comments and unused utility functions related to ephemeral variables, improving code cleanliness.
…ale updates

- Modified the persistActiveEnvironment function to accept a requestUid parameter, allowing for better management of stale updates.
- Enhanced the logic to prevent disk writes for superseded requests, improving data integrity during environment persistence.
- Eliminated the envName variable from the deleteAllEnvVars method, simplifying the logic for deleting environment variables.
- Cleaned up the method by removing unnecessary checks related to the envName, enhancing code clarity and maintainability.
…Var method

- Added a check in the deleteEnvVar method to silently ignore attempts to delete the internal __name__ variable, preserving its integrity.
- Updated tests to verify that the __name__ variable remains unchanged when deleteEnvVar is called with this key.
- Enhanced runtime tests to ensure compatibility with QuickJS by confirming that environment variables set with persist options are handled correctly.
…ence

- Introduced a new test suite to validate that the legacy argument for setting environment variables with persistence is still functional in version 4.
- Created a fixture to simulate the legacy syntax, ensuring that the variable is correctly persisted on disk without errors.
- Enhanced integration testing to confirm that the legacy behavior aligns with the current implementation, maintaining backward compatibility.
…r safe and developer modes

- Updated the test suite for `bru.setEnvVar` to verify that the legacy persist flag is correctly handled in both safe and developer modes.
- Introduced a helper function to streamline the verification process and ensure consistent behavior across different execution contexts.
- Adjusted the test logic to reset the environment state between mode switches, maintaining test integrity.
- Improved hover interaction in multiple persistent variable tests to ensure reliable visibility of actions during execution.
@sanish-bruno
sanish-bruno force-pushed the feat/variable-persistence branch from 6d2c1c3 to 9ca8372 Compare June 26, 2026 10:24
…vironment variables

- Updated the logic for determining changes in environment variables to compare active current and saved values instead of previously used variablesToSave and savedValues.
- This change ensures accurate detection of modifications before saving, improving user feedback when no changes are present.
…t configurations

- Updated the test suites for `bru.setEnvVar` and `bru.setGlobalEnvVar` to include interactions with the secrets tab, ensuring visibility of secret variables during various states of the environment.
- Added checks to confirm that the eye toggle functionality correctly reveals the values of secret variables after setting and overwriting them.
- Improved test coverage for secret variable persistence, validating that the expected values are displayed in both collection and global environment contexts.
@bijin-bruno
bijin-bruno merged commit 87f7426 into usebruno:main Jun 26, 2026
23 of 26 checks passed
abhishekp-bruno pushed a commit to abhishekp-bruno/bruno that referenced this pull request Jun 29, 2026
…able disabled scripting APIs (usebruno#8315)

* feat(variables): add variable persistence with scripting

feat(collections): implement script-driven update for collection variables, ensuring direct root modification and draft synchronization

feat(collections): enhance script variable management with baseline tracking and draft preservation

* feat(variables): add runtime variable updates and optimize disk writes by implementing dirty flags

fix(collections): handle errors during environment persistence in script execution

feat(collections): implement baseline clearing for script execution and optimize variable update handling

feat(tests): add default persistence tests for environment variables and update runtime variable handling

refactor(collections): streamline variable update handling and improve draft management by removing redundant comments and optimizing code clarity

test(collection-vars): add verification for draft edits and script variable visibility in collection settings UI

refactor(collection-vars): update header value selection logic for improved clarity and accuracy in draft isolation tests

* feat(global-environments): enhance global environment updates to resolve stale active UIDs and improve persistence logic

- Updated the `updateGlobalEnvironments` reducer to handle stale active UIDs by matching against environment names.
- Improved the logic for setting global environments and active UIDs to ensure consistency after disk reloads.
- Removed outdated tests related to persisted values in favor of more relevant assertions for environment variable handling.

* feat(variables): enhance typed value handling and persistence in global and collection environments

- Added tests to infer data types (number, boolean, object) when setting environment and collection variables.
- Updated the logic to preserve existing data types when variables are not modified by scripts.
- Implemented dirty flags to track changes in typed variables, ensuring accurate persistence across sessions.
- Refactored related tests to verify the correct behavior of typed variables in various scenarios.

* refactor(variables): streamline data type inference and enhance deletion methods

- Removed redundant data type inference logic from global and collection variable updates to simplify the codebase.
- Updated deletion methods in the Bru class to use Object.keys for improved resilience against user-defined properties.
- Added tests to ensure deletion methods function correctly even when properties are shadowed.
- Enhanced clarity in draft merge tests by standardizing keyboard shortcuts for selecting all text.

* fix(tests): correct variable naming and improve environment panel interactions

- Updated test cases to reflect the correct variable name 'wasSaved' instead of 'was-saved'.
- Modified environment panel interaction to remove forced click, enhancing test reliability.
- Added a utility function to close the environment panel in safe mode tests for better readability and maintainability.

* feat(runtime): enhance variable management and cleanup logic

- Introduced a new method to clear script-driven variable baselines for collections, ensuring no stale data leaks into new requests.
- Updated the handling of runtime variables in the Bru class to track changes with a new dirty flag, improving state management.
- Refactored the application of script environment variables to prevent direct mutations, ensuring immutability and cleaner state updates.
- Enhanced the response handling in the script runtime to conditionally include runtime variables based on their dirty state.

* feat(variables): improve request handling and state management for collections and environments

- Enhanced event listeners to clear global environment baselines on both 'testrun-started' and 'request-queued' events, preventing stale data issues.
- Updated global environment and collection variable update events to ignore stale updates from superseded requests, ensuring accurate state management.
- Refactored the Bru class to optimize variable management, including checks for existing keys before updates and deletions, improving performance and reliability.
- Introduced request UID tracking to maintain consistency across variable updates during concurrent requests.

* refactor(collections): update action to clear script variable baselines

- Replaced the dispatch of `_clearScriptGlobalEnvBaseline` with `clearScriptVariableBaselines` to improve clarity and maintainability in the Redux action handling for collections.

* feat(environments): introduce getScriptModifiedKeys utility for improved variable management

- Added a new utility function, `getScriptModifiedKeys`, to identify keys modified by scripts relative to a baseline, enhancing the handling of data types during variable updates.
- Updated the application of script environment variables to prevent overwriting user-defined draft changes during no-op writes.
- Refactored related logic in collections and global environments to utilize the new utility, ensuring accurate state management and improved clarity in the Redux slices.

* refactor(global-environments): simplify active UID resolution logic in updateGlobalEnvironments reducer

- Streamlined the logic for resolving the active global environment UID by consolidating conditions into a more concise format.
- Removed outdated comments to enhance code clarity and maintainability.
- Updated tests to ensure accurate resolution of active UIDs based on incoming environment data.

* refactor(tests): remove outdated comments and streamline environment variable row expectations

- Eliminated comments related to state sync and inference issues to enhance code clarity.
- Adjusted expectations for environment variable row rendering in tests, focusing on relevant assertions.

* feat(tests): add comprehensive tests for secret variable persistence in environments

- Introduced new test cases to validate the preservation of secret variables when updated via scripts in both collection and global environments.
- Implemented tests to ensure that secret values are encrypted before storage and can be correctly decrypted for subsequent requests.
- Added fixtures and environment configurations for testing secret variable behavior in both bru and yml formats.
- Enhanced utility functions for managing environment configurations and interactions within the test suite.

* feat(tests): enhance environment variable tests and add global variable persistence

- Updated MultiLineEditor and SingleLineEditor components to include data-testid for secret reveal toggle buttons, improving testability.
- Introduced new tests for global environment variable persistence, ensuring non-secret variables survive app restarts and are correctly interpolated.
- Added fixtures for workspace and collections to support the new global variable tests, enhancing the overall test coverage for environment management.
- Refactored utility functions to streamline interactions with environment variables in tests.

* refactor(collections): optimize environment and collection saving logic

- Simplified the persistence logic for active environments by directly constructing the environment copy, reducing unnecessary cloning.
- Updated the collection saving process to utilize the fresh collection state, ensuring accurate data is saved without drafts.
- Enhanced error handling during the save operations to improve reliability and maintainability.

* feat(tests): implement collection variable persistence tests

- Added multiple test cases to validate the persistence of collection variables across app restarts, including typed values and multiple variable settings.
- Created new fixtures for collection variables to support the tests, ensuring accurate simulation of variable management scenarios.
- Enhanced the existing collection management logic to ensure that variables are correctly set and deleted as per the test requirements.

* feat(tests): add tests for typed global environment variable persistence

- Introduced a new test suite to validate the persistence of typed global environment variables across app restarts, ensuring correct data types are maintained.
- Created a fixture for the test collection to simulate setting global variables with various data types, including number, boolean, object, and string.
- Enhanced the test logic to verify that the environment file reflects the correct state before and after application restarts.

* fix(tests): update request tab close interaction in variable persistence tests

* fix(tests): improve hover interaction for collection actions in runner tests

- Updated the hover logic for revealing collection actions to handle sidebar re-renders more reliably.
- Replaced one-shot hover with a polling mechanism to ensure visibility of actions, enhancing test stability.

* refactor(environments): streamline environment variable handling and remove ephemeral metadata logic

- Simplified the comparison logic for environment variables by removing unnecessary ephemeral metadata handling.
- Updated the saving process to directly use the environment variables without stripping metadata, enhancing clarity and maintainability.
- Removed outdated comments and unused utility functions related to ephemeral variables, improving code cleanliness.

* fix(ipc): update persistActiveEnvironment to handle requestUid for stale updates

- Modified the persistActiveEnvironment function to accept a requestUid parameter, allowing for better management of stale updates.
- Enhanced the logic to prevent disk writes for superseded requests, improving data integrity during environment persistence.

* refactor(bru): remove unused envName variable in deleteAllEnvVars method

- Eliminated the envName variable from the deleteAllEnvVars method, simplifying the logic for deleting environment variables.
- Cleaned up the method by removing unnecessary checks related to the envName, enhancing code clarity and maintainability.

* fix(bru): prevent deletion of internal __name__ variable in deleteEnvVar method

- Added a check in the deleteEnvVar method to silently ignore attempts to delete the internal __name__ variable, preserving its integrity.
- Updated tests to verify that the __name__ variable remains unchanged when deleteEnvVar is called with this key.
- Enhanced runtime tests to ensure compatibility with QuickJS by confirming that environment variables set with persist options are handled correctly.

* feat(tests): add legacy support test for environment variable persistence

- Introduced a new test suite to validate that the legacy argument for setting environment variables with persistence is still functional in version 4.
- Created a fixture to simulate the legacy syntax, ensuring that the variable is correctly persisted on disk without errors.
- Enhanced integration testing to confirm that the legacy behavior aligns with the current implementation, maintaining backward compatibility.

* test(tests): enhance legacy environment variable persistence tests for safe and developer modes

- Updated the test suite for `bru.setEnvVar` to verify that the legacy persist flag is correctly handled in both safe and developer modes.
- Introduced a helper function to streamline the verification process and ensure consistent behavior across different execution contexts.
- Adjusted the test logic to reset the environment state between mode switches, maintaining test integrity.
- Improved hover interaction in multiple persistent variable tests to ensure reliable visibility of actions during execution.

* fix(EnvironmentVariablesTable): correct change detection logic for environment variables

- Updated the logic for determining changes in environment variables to compare active current and saved values instead of previously used variablesToSave and savedValues.
- This change ensures accurate detection of modifications before saving, improving user feedback when no changes are present.

* test(tests): enhance secret variable persistence tests for environment configurations

- Updated the test suites for `bru.setEnvVar` and `bru.setGlobalEnvVar` to include interactions with the secrets tab, ensuring visibility of secret variables during various states of the environment.
- Added checks to confirm that the eye toggle functionality correctly reveals the values of secret variables after setting and overwriting them.
- Improved test coverage for secret variable persistence, validating that the expected values are displayed in both collection and global environment contexts.
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