Repository navigation
feat: Implement isSafeMode() API - #5760
Conversation
Add `isSafeMode()` to Bru API that returns `true` in
case the runtime is a sandbox.
This allows for scripts to test for and handle whether
running in sandbox or not:
```javascript
if (bru.isSafeMode()) {
throw new Error('This script requires Developer mode')
}
```
|
Thanks for the PR @datag ! |
WalkthroughThis pull request introduces a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/bruno-js/src/bru.js (1)
9-21: Critical:runtimeparameter isn't stored in the constructor, soisSafeMode()will always return false.Add
this.runtime = runtime;as the first line in the constructor. The method currently comparesundefined === 'quickjs', which is never true. Given that the codebase supports both'quickjs'(safe/sandboxed) and'nodevm'(non-safe) runtimes, this bug completely breaks runtime-aware safe-mode detection.class Bru { constructor(runtime, envVariables, runtimeVariables, processEnvVars, collectionPath, collectionVariables, folderVariables, requestVariables, globalEnvironmentVariables, oauth2CredentialVariables, collectionName, promptVariables) { + this.runtime = runtime; this.envVariables = envVariables || {}; this.runtimeVariables = runtimeVariables || {}; this.promptVariables = promptVariables || {}; this.processEnvVars = cloneDeep(processEnvVars || {}); this.collectionVariables = collectionVariables || {}; this.folderVariables = folderVariables || {}; this.requestVariables = requestVariables || {}; this.globalEnvironmentVariables = globalEnvironmentVariables || {}; this.oauth2CredentialVariables = oauth2CredentialVariables || {}; this.collectionPath = collectionPath; this.collectionName = collectionName;
🧹 Nitpick comments (3)
packages/bruno-js/tests/setEnvVar.spec.js (1)
4-21: Constructor update is correct; consider a runtime constant to avoid typos.describe('Bru.setEnvVar', () => { + const RUNTIME = 'quickjs'; const makeBru = () => new Bru( - /* runtime */ 'quickjs', + /* runtime */ RUNTIME, /* envVariables */ {}, /* runtimeVariables */ {}, /* processEnvVars */ {}, /* collectionPath */ '/', /* historyLogger */ undefined, /* setVisualizations */ undefined, /* secretVariables */ {}, /* collectionVariables */ {}, /* folderVariables */ {}, /* requestVariables */ {}, /* globalEnvironmentVariables */ {}, /* oauth2CredentialVariables */ {}, /* iterationDetails */ {}, /* collectionName */ 'Test' );packages/bruno-js/src/runtime/vars-runtime.js (1)
38-41: Runtime arg pass-through is correct; consider formatting this constructor call like other runtimes.- const bru = new Bru(this.runtime, envVariables, runtimeVariables, processEnvVars, undefined, collectionVariables, folderVariables, requestVariables, globalEnvironmentVariables, oauth2CredentialVariables, undefined, promptVariables); + const bru = new Bru( + this.runtime, + envVariables, + runtimeVariables, + processEnvVars, + undefined, + collectionVariables, + folderVariables, + requestVariables, + globalEnvironmentVariables, + oauth2CredentialVariables, + undefined, + promptVariables + );packages/bruno-js/src/runtime/script-runtime.js (1)
35-37: Both Bru instantiation updates look consistent; +1 to the existing “single options object” TODO. Addingruntimeas another positional arg makes the call even more fragile—refactoring to an options object would reduce future churn.Also applies to: 130-132
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
packages/bruno-app/src/utils/codemirror/autocomplete.js(1 hunks)packages/bruno-js/src/bru.js(2 hunks)packages/bruno-js/src/runtime/assert-runtime.js(1 hunks)packages/bruno-js/src/runtime/script-runtime.js(2 hunks)packages/bruno-js/src/runtime/test-runtime.js(1 hunks)packages/bruno-js/src/runtime/vars-runtime.js(1 hunks)packages/bruno-js/src/sandbox/quickjs/shims/bru.js(1 hunks)packages/bruno-js/tests/setEnvVar.spec.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (CODING_STANDARDS.md)
**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions.() => {}is good
No space between function name and parentheses.func()notfunc ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly
Files:
packages/bruno-app/src/utils/codemirror/autocomplete.jspackages/bruno-js/src/runtime/script-runtime.jspackages/bruno-js/src/runtime/test-runtime.jspackages/bruno-js/src/sandbox/quickjs/shims/bru.jspackages/bruno-js/src/runtime/vars-runtime.jspackages/bruno-js/src/bru.jspackages/bruno-js/src/runtime/assert-runtime.jspackages/bruno-js/tests/setEnvVar.spec.js
🧠 Learnings (1)
📚 Learning: 2025-12-03T06:32:11.738Z
Learnt from: sanish-bruno
Repo: usebruno/bruno PR: 6090
File: packages/bruno-js/src/runtime/hooks-runtime.js:8-135
Timestamp: 2025-12-03T06:32:11.738Z
Learning: vm2 runtime is being removed from the Bruno application and QuickJS will become the default runtime for script execution.
Applied to files:
packages/bruno-js/src/runtime/script-runtime.jspackages/bruno-js/src/runtime/test-runtime.jspackages/bruno-js/src/sandbox/quickjs/shims/bru.jspackages/bruno-js/src/runtime/vars-runtime.jspackages/bruno-js/src/bru.jspackages/bruno-js/tests/setEnvVar.spec.js
🧬 Code graph analysis (3)
packages/bruno-js/src/runtime/script-runtime.js (5)
packages/bruno-js/src/runtime/assert-runtime.js (1)
Bru(4-4)packages/bruno-js/src/runtime/test-runtime.js (1)
Bru(2-2)packages/bruno-js/src/runtime/vars-runtime.js (1)
Bru(2-2)packages/bruno-js/tests/runtime.spec.js (1)
Bru(4-4)packages/bruno-js/tests/setEnvVar.spec.js (1)
Bru(1-1)
packages/bruno-js/src/runtime/test-runtime.js (6)
packages/bruno-js/src/runtime/assert-runtime.js (1)
Bru(4-4)packages/bruno-js/src/runtime/script-runtime.js (1)
Bru(2-2)packages/bruno-js/src/runtime/vars-runtime.js (1)
Bru(2-2)packages/bruno-js/tests/runtime.spec.js (1)
Bru(4-4)packages/bruno-cli/src/commands/run.js (2)
processEnvVars(466-468)collectionPath(295-295)packages/bruno-electron/src/ipc/network/prepare-grpc-request.js (1)
processEnvVars(88-88)
packages/bruno-js/src/sandbox/quickjs/shims/bru.js (1)
packages/bruno-js/src/sandbox/quickjs/utils/index.js (1)
marshallToVm(1-31)
🔇 Additional comments (4)
packages/bruno-app/src/utils/codemirror/autocomplete.js (1)
55-100: API hint addition looks good. The new'bru.isSafeMode()'entry is consistent with existing hint strings and coding style.packages/bruno-js/src/sandbox/quickjs/shims/bru.js (1)
26-31: QuickJS shim wiring forbru.isSafeMode()looks correct. Wrapper/marshalling and disposal are consistent with the rest of this file.packages/bruno-js/src/runtime/assert-runtime.js (1)
242-272: Call-site update is correct; will be effective onceBrustoresruntime. This aligns with the new constructor signature, butbru.isSafeMode()will be broken untilthis.runtimeis assigned inpackages/bruno-js/src/bru.js.packages/bruno-js/src/runtime/test-runtime.js (1)
33-37: Call-site update to passthis.runtimeis consistent with the newBruAPI. (Will work as intended onceBruassignsthis.runtime.)
|
I fixed the PR conflicts. Changes look fine to me. |
| class Bru { | ||
| constructor(envVariables, runtimeVariables, processEnvVars, collectionPath, collectionVariables, folderVariables, requestVariables, globalEnvironmentVariables, oauth2CredentialVariables, collectionName, promptVariables) { | ||
| constructor(runtime, envVariables, runtimeVariables, processEnvVars, collectionPath, collectionVariables, folderVariables, requestVariables, globalEnvironmentVariables, oauth2CredentialVariables, collectionName, promptVariables) { | ||
| this.envVariables = envVariables || {}; |
There was a problem hiding this comment.
runtime parameter is received but never assigned to this.runtime, so isSafeMode() always returns false.
There was a problem hiding this comment.
@pooja-bruno In my original commit 96655e6 it has been assigned. I guess it was lost on rebase conflict resolving.
Unfortunately I won't find the time in the next weeks to do any changes on this PR.
|
@datag, Thanks for raising this PR! One small issue runtime is passed to the constructor but never assigned to this.runtime, so isSafeMode() always returns false. Could you fix that? Also, if possible, could you add a test for isSafeMode() to verify it returns the correct value? |
|
Merging this in for it to be refined and polished by the internal team, Thanks @datag for the contribution. |
Add `isSafeMode()` to Bru API that returns `true` in
case the runtime is a sandbox.
This allows for scripts to test for and handle whether
running in sandbox or not:
```javascript
if (bru.isSafeMode()) {
throw new Error('This script requires Developer mode')
}
```
Co-authored-by: Anoop M D <[email protected]>
feat: Implement `isSafeMode()` API (#5760)
Add `isSafeMode()` to Bru API that returns `true` in
case the runtime is a sandbox.
This allows for scripts to test for and handle whether
running in sandbox or not:
```javascript
if (bru.isSafeMode()) {
throw new Error('This script requires Developer mode')
}
```
Co-authored-by: Anoop M D <[email protected]>
Add `isSafeMode()` to Bru API that returns `true` in
case the runtime is a sandbox.
This allows for scripts to test for and handle whether
running in sandbox or not:
```javascript
if (bru.isSafeMode()) {
throw new Error('This script requires Developer mode')
}
```
Co-authored-by: Anoop M D <[email protected]>
feat: Implement `isSafeMode()` API (usebruno#5760)
Add
isSafeMode()to Bru API that returnstruein case the runtime is a sandbox.This allows for scripts to test for and handle whether running in sandbox or not:
Resolves #4238, JIRA
Summary by CodeRabbit
bru.isSafeMode()API method that returns a boolean indicating whether the script is executing in safe mode, with autocomplete support.✏️ Tip: You can customize this high-level summary in your review settings.