Repository navigation
feat(variables): persist scripted variable changes by default + re-enable disabled scripting APIs - #8315
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughReplaces opt-in ChangesScript Variable Persistence with Draft-Aware Merge
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
acf0c8e to
cfb6333
Compare
There was a problem hiding this comment.
Actionable comments posted: 13
🧹 Nitpick comments (5)
tests/utils/page/locators.ts (1)
89-90: ⚡ Quick winHarden 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 winMove 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 winReplace 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 winKeep the fixture tree singular for one collection.
tests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-testonly contains one collection, sofixtures/collection/would match the repo convention and avoid layout drift.Based on learnings, use
fixtures/collectionwhen there is a single collection, andfixtures/collectionsonly 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 winKeep the fixture tree singular for one collection.
tests/environments/draft-merge-with-script/fixtures/collections/draft-merge-testonly contains one collection, sofixtures/collection/would match the repo convention and avoid layout drift.Based on learnings, use
fixtures/collectionwhen there is a single collection, andfixtures/collectionsonly 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
📒 Files selected for processing (92)
packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.jspackages/bruno-app/src/providers/App/useIpcEvents.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-isolation.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-merge.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/draft-env-merge.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/global-environments.jspackages/bruno-app/src/providers/ReduxStore/slices/global-environments.spec.jspackages/bruno-app/src/utils/codemirror/autocomplete.jspackages/bruno-app/src/utils/collections/index.jspackages/bruno-app/src/utils/environments.jspackages/bruno-app/src/utils/environments.spec.jspackages/bruno-electron/src/ipc/collection.jspackages/bruno-electron/src/ipc/network/index.jspackages/bruno-js/src/bru.jspackages/bruno-js/src/runtime/script-runtime.jspackages/bruno-js/src/runtime/test-runtime.jspackages/bruno-js/src/runtime/vars-runtime.jspackages/bruno-js/src/sandbox/quickjs/shims/bru.jspackages/bruno-js/tests/collectionVar.spec.jspackages/bruno-js/tests/globalEnvVar.spec.jspackages/bruno-js/tests/runtime.spec.jspackages/bruno-js/tests/setEnvVar.spec.jspackages/bruno-tests/collection/ping.brupackages/bruno-tests/collection/scripting/api/bru/deleteAllCollectionVars.brupackages/bruno-tests/collection/scripting/api/bru/deleteAllEnvVars.brupackages/bruno-tests/collection/scripting/api/bru/deleteAllGlobalEnvVars.brupackages/bruno-tests/collection/scripting/api/bru/deleteCollectionVar.brupackages/bruno-tests/collection/scripting/api/bru/deleteEnvVar.brupackages/bruno-tests/collection/scripting/api/bru/deleteGlobalEnvVar.brupackages/bruno-tests/collection/scripting/api/bru/getAllCollectionVars.brupackages/bruno-tests/collection/scripting/api/bru/setCollectionVar.brupackages/bruno-tests/collection/scripting/api/bru/setGlobalEnvVar.brutests/environments/api-setEnvVar/api-setEnvVar-default-persistence.spec.tstests/environments/api-setEnvVar/api-setEnvVar-with-persist.spec.tstests/environments/api-setEnvVar/api-setEnvVar-without-persist.spec.tstests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-default-persistence.brutests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-with-persist.brutests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-1.brutests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-2.brutests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.tstests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/bruno.jsontests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/collection.brutests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/environments/Test.brutests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/set-collection-var.brutests/environments/collection-vars-draft-merge-with-script/init-user-data/collection-security.jsontests/environments/collection-vars-draft-merge-with-script/init-user-data/preferences.jsontests/environments/datatype-preservation/datatype-preservation.spec.tstests/environments/draft-merge-with-script/draft-merge-with-script.spec.tstests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/bruno.jsontests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/environments/Test.brutests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/set-env-var.brutests/environments/draft-merge-with-script/init-user-data/collection-security.jsontests/environments/draft-merge-with-script/init-user-data/preferences.jsontests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/bruno.jsontests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/set-global-env-var.brutests/environments/global-env-draft-merge-with-script/global-env-draft-merge-with-script.spec.tstests/environments/global-env-draft-merge-with-script/init-user-data/collection-security.jsontests/environments/global-env-draft-merge-with-script/init-user-data/global-environments.jsontests/environments/global-env-draft-merge-with-script/init-user-data/preferences.jsontests/scripting/bru-api/collection-vars-draft-isolation/collection-vars-draft-isolation.spec.tstests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/bruno.jsontests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/collection.brutests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/environments/Test.brutests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/set-collection-var.brutests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/collection-security.jsontests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/preferences.jsontests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/bruno.jsontests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/delete-global-env-var.brutests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/set-global-env-var.brutests/scripting/bru-api/global-env-var-persistence/global-env-var-persistence.spec.tstests/scripting/bru-api/global-env-var-persistence/init-user-data/collection-security.jsontests/scripting/bru-api/global-env-var-persistence/init-user-data/global-environments.jsontests/scripting/bru-api/global-env-var-persistence/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/bruno.jsontests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/environments/Test.brutests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-collection-var.brutests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-env-var.brutests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/collection-security.jsontests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-safe-mode/variable-persistence-safe-mode.spec.tstests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/bruno.jsontests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/environments/Test.brutests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-collection-var.brutests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-env-var.brutests/scripting/bru-api/variable-persistence/init-user-data/collection-security.jsontests/scripting/bru-api/variable-persistence/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence/variable-persistence.spec.tstests/utils/page/locators.tstests/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
There was a problem hiding this comment.
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 winAlign fixture path convention (
collectionvscollections) for single-collection setup.This fixture appears to represent a single collection case but is under
fixtures/collections. Consider moving tofixtures/collectionfor 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
📒 Files selected for processing (44)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-merge.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/draft-env-merge.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.jspackages/bruno-app/src/providers/ReduxStore/slices/global-environments.jspackages/bruno-app/src/providers/ReduxStore/slices/global-environments.spec.jspackages/bruno-app/src/utils/environments.spec.jspackages/bruno-js/src/bru.jspackages/bruno-js/tests/collectionVar.spec.jspackages/bruno-js/tests/globalEnvVar.spec.jspackages/bruno-js/tests/runtime.spec.jspackages/bruno-js/tests/setEnvVar.spec.jstests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.tstests/environments/collection-vars-draft-merge-with-script/init-user-data/preferences.jsontests/environments/draft-merge-with-script/draft-merge-with-script.spec.tstests/environments/draft-merge-with-script/init-user-data/preferences.jsontests/environments/global-env-draft-merge-with-script/global-env-draft-merge-with-script.spec.tstests/environments/global-env-draft-merge-with-script/init-user-data/preferences.jsontests/scripting/bru-api/collection-vars-draft-isolation/collection-vars-draft-isolation.spec.tstests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/preferences.jsontests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/bruno.jsontests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/set-typed-global-env-vars.brutests/scripting/bru-api/global-env-var-persistence-typed/global-env-var-persistence-typed.spec.tstests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/collection-security.jsontests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/global-environments.jsontests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/preferences.jsontests/scripting/bru-api/global-env-var-persistence/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/bruno.jsontests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/environments/Test.brutests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-collection-vars.brutests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-env-vars.brutests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/collection-security.jsontests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-typed-safe-mode/variable-persistence-typed-safe-mode.spec.tstests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/bruno.jsontests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/environments/Test.brutests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-collection-vars.brutests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-env-vars.brutests/scripting/bru-api/variable-persistence-typed/init-user-data/collection-security.jsontests/scripting/bru-api/variable-persistence-typed/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-typed/variable-persistence-typed.spec.tstests/scripting/bru-api/variable-persistence/init-user-data/preferences.jsontests/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
b4d5a80 to
e6cf433
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (112)
packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.jspackages/bruno-app/src/providers/App/useIpcEvents.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-isolation.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/draft-collection-vars-merge.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/draft-env-merge.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/global-environments.jspackages/bruno-app/src/providers/ReduxStore/slices/global-environments.spec.jspackages/bruno-app/src/utils/codemirror/autocomplete.jspackages/bruno-app/src/utils/collections/index.jspackages/bruno-app/src/utils/environments.jspackages/bruno-app/src/utils/environments.spec.jspackages/bruno-electron/src/ipc/collection.jspackages/bruno-electron/src/ipc/network/index.jspackages/bruno-js/src/bru.jspackages/bruno-js/src/runtime/script-runtime.jspackages/bruno-js/src/runtime/test-runtime.jspackages/bruno-js/src/runtime/vars-runtime.jspackages/bruno-js/src/sandbox/quickjs/shims/bru.jspackages/bruno-js/tests/collectionVar.spec.jspackages/bruno-js/tests/globalEnvVar.spec.jspackages/bruno-js/tests/runtime.spec.jspackages/bruno-js/tests/setEnvVar.spec.jspackages/bruno-tests/collection/ping.brupackages/bruno-tests/collection/scripting/api/bru/deleteAllCollectionVars.brupackages/bruno-tests/collection/scripting/api/bru/deleteAllEnvVars.brupackages/bruno-tests/collection/scripting/api/bru/deleteAllGlobalEnvVars.brupackages/bruno-tests/collection/scripting/api/bru/deleteCollectionVar.brupackages/bruno-tests/collection/scripting/api/bru/deleteEnvVar.brupackages/bruno-tests/collection/scripting/api/bru/deleteGlobalEnvVar.brupackages/bruno-tests/collection/scripting/api/bru/getAllCollectionVars.brupackages/bruno-tests/collection/scripting/api/bru/setCollectionVar.brupackages/bruno-tests/collection/scripting/api/bru/setGlobalEnvVar.brutests/environments/api-setEnvVar/api-setEnvVar-default-persistence.spec.tstests/environments/api-setEnvVar/api-setEnvVar-with-persist.spec.tstests/environments/api-setEnvVar/api-setEnvVar-without-persist.spec.tstests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-default-persistence.brutests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-with-persist.brutests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-1.brutests/environments/api-setEnvVar/fixtures/collection/multiple-persist-vars-folder/multiple-persist-vars-2.brutests/environments/collection-vars-draft-merge-with-script/collection-vars-draft-merge-with-script.spec.tstests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/bruno.jsontests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/collection.brutests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/environments/Test.brutests/environments/collection-vars-draft-merge-with-script/fixtures/collections/collection-vars-draft-merge-test/set-collection-var.brutests/environments/collection-vars-draft-merge-with-script/init-user-data/collection-security.jsontests/environments/collection-vars-draft-merge-with-script/init-user-data/preferences.jsontests/environments/datatype-preservation/datatype-preservation.spec.tstests/environments/draft-merge-with-script/draft-merge-with-script.spec.tstests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/bruno.jsontests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/environments/Test.brutests/environments/draft-merge-with-script/fixtures/collections/draft-merge-test/set-env-var.brutests/environments/draft-merge-with-script/init-user-data/collection-security.jsontests/environments/draft-merge-with-script/init-user-data/preferences.jsontests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/bruno.jsontests/environments/global-env-draft-merge-with-script/fixtures/collections/global-env-draft-merge-test/set-global-env-var.brutests/environments/global-env-draft-merge-with-script/global-env-draft-merge-with-script.spec.tstests/environments/global-env-draft-merge-with-script/init-user-data/collection-security.jsontests/environments/global-env-draft-merge-with-script/init-user-data/global-environments.jsontests/environments/global-env-draft-merge-with-script/init-user-data/preferences.jsontests/scripting/bru-api/collection-vars-draft-isolation/collection-vars-draft-isolation.spec.tstests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/bruno.jsontests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/collection.brutests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/environments/Test.brutests/scripting/bru-api/collection-vars-draft-isolation/fixtures/collections/draft-isolation-test/set-collection-var.brutests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/collection-security.jsontests/scripting/bru-api/collection-vars-draft-isolation/init-user-data/preferences.jsontests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/bruno.jsontests/scripting/bru-api/global-env-var-persistence-typed/fixtures/collections/global-env-var-persistence-typed-test/set-typed-global-env-vars.brutests/scripting/bru-api/global-env-var-persistence-typed/global-env-var-persistence-typed.spec.tstests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/collection-security.jsontests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/global-environments.jsontests/scripting/bru-api/global-env-var-persistence-typed/init-user-data/preferences.jsontests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/bruno.jsontests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/delete-global-env-var.brutests/scripting/bru-api/global-env-var-persistence/fixtures/collections/global-env-var-persistence-test/set-global-env-var.brutests/scripting/bru-api/global-env-var-persistence/global-env-var-persistence.spec.tstests/scripting/bru-api/global-env-var-persistence/init-user-data/collection-security.jsontests/scripting/bru-api/global-env-var-persistence/init-user-data/global-environments.jsontests/scripting/bru-api/global-env-var-persistence/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/bruno.jsontests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/environments/Test.brutests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-collection-var.brutests/scripting/bru-api/variable-persistence-safe-mode/fixtures/collections/variable-persistence-safe-test/set-env-var.brutests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/collection-security.jsontests/scripting/bru-api/variable-persistence-safe-mode/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-safe-mode/variable-persistence-safe-mode.spec.tstests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/bruno.jsontests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/environments/Test.brutests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-collection-vars.brutests/scripting/bru-api/variable-persistence-typed-safe-mode/fixtures/collections/variable-persistence-typed-safe-test/set-typed-env-vars.brutests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/collection-security.jsontests/scripting/bru-api/variable-persistence-typed-safe-mode/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-typed-safe-mode/variable-persistence-typed-safe-mode.spec.tstests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/bruno.jsontests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/environments/Test.brutests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-collection-vars.brutests/scripting/bru-api/variable-persistence-typed/fixtures/collections/variable-persistence-typed-test/set-typed-env-vars.brutests/scripting/bru-api/variable-persistence-typed/init-user-data/collection-security.jsontests/scripting/bru-api/variable-persistence-typed/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence-typed/variable-persistence-typed.spec.tstests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/bruno.jsontests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/environments/Test.brutests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-collection-var.brutests/scripting/bru-api/variable-persistence/fixtures/collections/variable-persistence-test/set-env-var.brutests/scripting/bru-api/variable-persistence/init-user-data/collection-security.jsontests/scripting/bru-api/variable-persistence/init-user-data/preferences.jsontests/scripting/bru-api/variable-persistence/variable-persistence.spec.tstests/utils/page/locators.tstests/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
4de4ccd to
8f6dc77
Compare
vijayh-bruno
left a comment
There was a problem hiding this comment.
Concerns around avoiding collection deep cloning wherever not required were addressed.
LGTM!
|
@bijin-bruno - can you take a final pass at this one and merge if its good for it? |
20b2f7e to
fef586c
Compare
…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.
6d2c1c3 to
9ca8372
Compare
…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.
…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.
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 tobru.setEnvVar(),bru.setCollectionVar(), orbru.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:
bru.setEnvVar("key", "val", { persist: true })to make changes stick — most users expected the default behavior to persist.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.Solution
Always Persist + Dirty Flags
Removed the
persistentEnvVariables/ephemeralflag model. TheBruclass now tracks three dirty flags (_envDirty,_globalEnvDirty,_collVarsDirty) set whenever a scripting API mutates that scope. Script/test runtimes returnnullfor 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-environmentandrenderer:save-collection-rootIPC 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
Aand the user's draft changes variableB, naive application would clobber the user's draft ofB.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:
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(ontestrun-started),wsConnectOnly, andsendCollectionOauth2Requestto 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
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.ephemeralorpersistedValuemetadata. Any code relying on these internal properties will break.main:persistent-env-variables-updateIPC event removed. Replaced by the existingmain:script-environment-updatetriggeringpersistActiveEnvironment().main:collection-variables-update,main:runtime-variables-update.Test Coverage
New unit tests (~2000 lines):
draft-env-merge.spec.js—scriptEnvironmentUpdateEventreducer: direct apply, draft merge with baseline diffing, add/delete, disabled var preservation, multi-event sequences, cleanupdraft-collection-vars-merge.spec.js— collection vars draft-aware baseline diffingdraft-collection-vars-isolation.spec.js— script-driven saves do NOT persist draft headers/auth/scripts to diskglobal-environments.spec.js—globalEnvironmentsUpdateEventbaseline diffingbruno-js/tests/collectionVar.spec.js,globalEnvVar.spec.js— re-enabled API coverageUpdated unit tests:
setEnvVar.spec.js— removed allpersistoption testsruntime.spec.js—collectionVariablesin expected results, dirty-flag behaviorNew E2E tests (Playwright):
variable-persistence.spec.ts+ safe-mode variantdraft-merge-with-script.spec.ts(env, collection vars, global env variants)global-env-var-persistence.spec.tscollection-vars-draft-isolation.spec.tsContribution Checklist:
Summary by CodeRabbit
bru.setEnvVarnow uses onlysetEnvVar(key, value)(persist option removed).