-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(variables): correct scripted-variable persistence races and cross-request propagation #8406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sanish-bruno
wants to merge
6
commits into
usebruno:main
Choose a base branch
from
sanish-bruno:feat/variable-persistence-file-lock
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+578
−76
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c9eb4e9
feat(collections): implement sliding window for script request UIDs t…
sanish-bruno 9cc618f
refactor(tests): remove outdated test for persistentEnvVariables in r…
sanish-bruno d402f28
refactor(collections): simplify environment persistence logic and rem…
sanish-bruno 332f8ac
refactor(filesystem): remove unused hasJsExtension function
sanish-bruno e9fe814
test(network): add unit tests for applyCollectionVarsToCollectionRoot
sanish-bruno 7a95d42
refactor(ipc, environments): implement file locking for environment u…
sanish-bruno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/bruno-electron/src/ipc/network/apply-collection-vars.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| const { uuid } = require('../../utils/common'); | ||
|
|
||
| // Mutates `collection.root.request.vars.req` (and draft.root.request.vars.req if | ||
| // present) to reflect a script's collection-variable changes, so the next request | ||
| // in a folder/collection run's iteration picks them up through mergeVars(). | ||
| // Without this, bru.setCollectionVar() inside request N would be invisible to | ||
| // request N+1 in the same iteration (envVars/globalEnvironmentVariables already | ||
| // propagate because they're mutated in place by reference). | ||
| // | ||
| // TODO: this is a write-back patch, not the structural fix. The root cause | ||
| // is that mergeVars (utils/collection.js) rebuilds `collectionVariables` fresh | ||
| // from `collection.root.request.vars.req` on every iteration, while envVars is | ||
| // built once at runner scope and passed by reference. May need a re-wire. | ||
| const applyCollectionVarsToCollectionRoot = (collection, collectionVariables) => { | ||
| if (!collectionVariables || typeof collectionVariables !== 'object') return; | ||
|
|
||
| const writeBack = (root) => { | ||
| if (!root) return; | ||
| if (!root.request) root.request = {}; | ||
| if (!root.request.vars) root.request.vars = {}; | ||
| const existing = Array.isArray(root.request.vars.req) ? root.request.vars.req : []; | ||
|
|
||
| const disabled = existing.filter((v) => !v.enabled); | ||
| const enabledByName = new Map(existing.filter((v) => v.enabled).map((v) => [v.name, v])); | ||
| const scriptNames = Object.keys(collectionVariables); | ||
|
|
||
| // Rebuild the enabled slice from the script's output. Keys present here are | ||
| // kept (with updated value); previously-enabled keys missing from the script | ||
| // output are treated as `bru.deleteCollectionVar` and dropped. Disabled vars | ||
| // (user-disabled in the UI) are preserved untouched. | ||
| const updatedEnabled = scriptNames.map((name) => { | ||
| const existingVar = enabledByName.get(name); | ||
| if (existingVar) { | ||
| return { ...existingVar, value: collectionVariables[name] }; | ||
| } | ||
| return { uid: uuid(), name, value: collectionVariables[name], type: 'text', enabled: true }; | ||
| }); | ||
|
|
||
| root.request.vars.req = [...updatedEnabled, ...disabled]; | ||
| }; | ||
|
|
||
| writeBack(collection.root); | ||
| if (collection.draft?.root) writeBack(collection.draft.root); | ||
| }; | ||
|
|
||
| module.exports = { applyCollectionVarsToCollectionRoot }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.