Repository navigation
Conversation
…sebruno#6209) When jsonwebtoken throws errors inside the NodeVM context, those errors were instances of the VM's isolated Error class, which caused instanceOf(Error) checks in tests to fail. By adding Error constructors (Error, TypeError, ReferenceError, SyntaxError, RangeError) from the global scope to the scriptContext, errors thrown by jsonwebtoken and other modules now use the same Error class that tests check against, ensuring instanceOf checks pass correctly. This fixes jsonwebtoken test failures when using the NodeVM runtime.
…ebruno#6212) * feat: add deprecation warnings for presets and post response vars * refactor: update deprecation warnings for presets and post response vars to include version
* add: opencollection --------- Co-authored-by: Anoop M D <[email protected]>
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
WalkthroughThis PR introduces an Auto Save feature allowing users to enable automatic persistence of draft changes. The implementation spans preferences UI configuration, Redux middleware for intercepting and debouncing save actions, updated action signatures to support silent notifications, theme styling additions, and comprehensive end-to-end test coverage validating the feature across multiple scenarios. Changes
Sequence DiagramsequenceDiagram
actor User
participant UI as Preferences UI
participant Redux as Redux Store
participant Middleware as AutoSave Middleware
participant Action as Collection Actions
participant Disk as File System
User->>UI: Enable Auto Save + Set Interval
UI->>Redux: Dispatch updatePreferences(autoSave)
Redux->>Middleware: dispatch app/updatePreferences
Middleware->>Middleware: saveExistingDrafts()
Middleware->>Action: Trigger save actions (silent: true)
Action->>Disk: Persist existing drafts
User->>UI: Edit Request URL
UI->>Redux: Dispatch collection/setActiveRequestDraft
Redux->>Middleware: Intercept action
Middleware->>Middleware: scheduleAutoSave() (debounce)
Note over Middleware: Wait (interval ms)
Middleware->>Action: Trigger saveRequest(silent: true)
Action->>Disk: Persist draft changes
UI->>UI: Clear draft indicator
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (1)
113-113: Simplify theonSavecallback.Since
onSaveno longer accepts parameters, you can simplify this:- onSave={(finalValue) => onSave(finalValue)} + onSave={onSave}tests/preferences/autosave/autosave.spec.ts (3)
50-66: Consider using Playwright's built-in waiting mechanisms.At line 62,
page.waitForTimeout(1000)is used to wait for autosave. While this works for time-based behavior, consider using Playwright'sexpect()with a timeout option for better reliability:- // Wait for autosave to trigger (interval + some buffer) - await page.waitForTimeout(1000); - - // Verify draft indicator disappears after autosave - await expect(requestTab.locator('.has-changes-icon')).not.toBeVisible(); + // Verify draft indicator disappears after autosave (with timeout for autosave interval) + await expect(requestTab.locator('.has-changes-icon')).not.toBeVisible({ timeout: 2000 });This approach waits for the condition rather than a fixed time, making the test more robust and potentially faster.
As per coding guidelines, reduce usage of
page.waitForTimeout()where possible.
101-121: Optional: Reduce timeout for negative assertion.At line 113, the timeout of 1500ms could be reduced slightly since we're testing that autosave doesn't trigger. Consider 1200ms (interval + 20% buffer) for a faster test while still providing sufficient validation time.
- // Wait a bit (longer than autosave interval would be) - await page.waitForTimeout(1500); + // Wait longer than autosave interval to verify it doesn't trigger + await page.waitForTimeout(1200);As per coding guidelines, minimize timeout durations where practical.
159-182: Consider using Playwright's built-in waiting mechanisms.At line 177,
page.waitForTimeout(1000)is used to wait for autosave of the existing draft. Similar to the first test, consider using Playwright'sexpect()with a timeout:- // Wait for autosave to trigger for existing draft - await page.waitForTimeout(1000); - - // Verify draft indicator disappears (existing draft was auto-saved) + // Verify draft indicator disappears after autosave of existing draft (with timeout) const requestTab = page.locator('.request-tab').filter({ has: page.locator('.tab-label', { hasText: 'Draft Request' }) }); - await expect(requestTab.locator('.has-changes-icon')).not.toBeVisible(); + await expect(requestTab.locator('.has-changes-icon')).not.toBeVisible({ timeout: 2000 });As per coding guidelines, reduce usage of
page.waitForTimeout()where possible.packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (1)
77-90: Consider adding error handling for save operations.The scheduleAutoSave function implements debouncing correctly, but the
save()call at line 87 lacks error handling. If a save operation fails, it could result in an unhandled promise rejection.const scheduleAutoSave = (key, save, interval) => { // Clear any existing timer for this entity clearTimeout(pendingTimers[key]); // Schedule a new save pendingTimers[key] = setTimeout(() => { - save(); + save().catch((err) => { + console.error('Autosave failed:', err); + // Error is already handled in save actions (toast.error), but log for debugging + }); delete pendingTimers[key]; }, interval); };Note: The save actions already handle errors with toasts, but catching here prevents unhandled promise rejections in the console.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
packages/bruno-app/src/components/Preferences/General/index.js(4 hunks)packages/bruno-app/src/components/RequestPane/QueryUrl/index.js(1 hunks)packages/bruno-app/src/providers/ReduxStore/index.js(1 hunks)packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js(1 hunks)packages/bruno-app/src/providers/ReduxStore/slices/app.js(1 hunks)packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js(6 hunks)packages/bruno-app/src/themes/dark.js(1 hunks)packages/bruno-app/src/themes/light.js(1 hunks)packages/bruno-electron/src/store/preferences.js(2 hunks)tests/preferences/autosave/autosave.spec.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{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
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single parameters
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses. Keep 'em tight
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
Avoid single line abstractions where all that's being done is increasing the call stack with one additional function
Add in meaningful comments instead of obvious ones where complex code flow is explained properly
Files:
tests/preferences/autosave/autosave.spec.tspackages/bruno-app/src/components/RequestPane/QueryUrl/index.jspackages/bruno-app/src/themes/light.jspackages/bruno-app/src/providers/ReduxStore/slices/app.jspackages/bruno-electron/src/store/preferences.jspackages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.jspackages/bruno-app/src/components/Preferences/General/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/themes/dark.jspackages/bruno-app/src/providers/ReduxStore/index.js
tests/**/**.*
⚙️ CodeRabbit configuration file
tests/**/**.*: Review the following e2e test code written using the Playwright test library. Ensure that:
Follow best practices for Playwright code and e2e automation
Try to reduce usage of
page.waitForTimeout();in code unless absolutely necessary and the locator cannot be found using existingexpect()playwright callsAvoid using
page.pause()in codeUse locator variables for locators
Avoid using test.only
Use multiple assertions
Promote the use of
test.stepas much as possible so the generated reports are easier to readEnsure that the
fixtureslike the collections are nested inside thefixturesfolderFixture Example*: Here's an example of possible fixture and test pair
. ├── fixtures │ └── collection │ ├── base.bru │ ├── bruno.json │ ├── collection.bru │ ├── ws-test-request-with-headers.bru │ ├── ws-test-request-with-subproto.bru │ └── ws-test-request.bru ├── connection.spec.ts # <- Depends on the collection in ./fixtures/collection ├── headers.spec.ts ├── persistence.spec.ts ├── variable-interpolation │ ├── fixtures │ │ └── collection │ │ ├── environments │ │ ├── bruno.json │ │ └── ws-interpolation-test.bru │ ├── init-user-data │ └── variable-interpolation.spec.ts # <- Depends on the collection in ./variable-interpolation/fixtures/collection └── subproto.spec.ts
Files:
tests/preferences/autosave/autosave.spec.ts
🧬 Code graph analysis (5)
tests/preferences/autosave/autosave.spec.ts (1)
tests/utils/page/actions.ts (2)
closeAllCollections(130-130)createRequest(130-130)
packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (7)
packages/bruno-app/src/components/RequestPane/GrpcBody/index.js (1)
onSave(56-56)packages/bruno-app/src/components/CollectionSettings/Vars/VarsTable/index.js (1)
onSave(31-31)packages/bruno-app/src/components/FolderSettings/Vars/VarsTable/index.js (1)
onSave(28-28)packages/bruno-app/src/components/RequestPane/RequestHeaders/index.js (1)
onSave(35-35)packages/bruno-app/src/components/RequestPane/Vars/VarsTable/index.js (1)
onSave(30-30)packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js (1)
onSave(48-48)packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js (1)
onSave(52-52)
packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (6)
saveCollectionSettings(2133-2172)saveCollectionSettings(2133-2172)saveRequest(97-135)saveRequest(97-135)saveFolderRoot(199-242)saveFolderRoot(199-242)
packages/bruno-app/src/components/Preferences/General/index.js (3)
packages/bruno-app/src/components/Sidebar/CreateCollection/index.js (1)
formik(32-65)packages/bruno-app/src/components/GlobalEnvironments/EnvironmentSettings/CreateEnvironment/index.js (1)
formik(21-49)packages/bruno-app/src/components/Preferences/Display/Theme/index.js (1)
formik(10-21)
packages/bruno-app/src/providers/ReduxStore/index.js (2)
packages/bruno-app/src/providers/App/useTelemetry.js (1)
isDevEnv(21-23)packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (2)
autosaveMiddleware(119-161)autosaveMiddleware(119-161)
🔇 Additional comments (19)
packages/bruno-app/src/providers/ReduxStore/slices/app.js (1)
31-35: LGTM!The
autoSavedefaults align with the Electron store'sdefaultPreferences. Initial state is correctly structured.packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (1)
36-38: LGTM!The parameterless
onSavesignature is consistent with other components in the codebase (e.g.,GrpcBody,QueryParams,RequestHeaders, etc.).packages/bruno-app/src/components/Preferences/General/index.js (4)
75-78: LGTM!Initial values correctly default to
falseand1000, matching the Redux store's initial state.
109-118: LGTM!The
autoSaveobject is correctly structured for persistence and the semicolon addition aligns with coding guidelines.
280-313: LGTM!UI controls are well-structured with proper accessibility attributes, disabled state handling, and error display logic.
321-321: LGTM!Adding the
idattribute improves accessibility by properly linking the label to the input.packages/bruno-electron/src/store/preferences.js (2)
52-56: LGTM!Default values are consistent with the Redux store's initial state.
100-104: Note: Validation minimum differs from frontend.As noted in the frontend review, this schema allows
min(100)while the UI enforces>= 500. Align these values for consistency.packages/bruno-app/src/providers/ReduxStore/index.js (2)
12-12: LGTM!Import correctly references the named export from the autosave middleware module.
18-18: LGTM!Middleware ordering is correct. The
autosaveMiddlewareis positioned afterdraftDetectMiddleware, ensuring it observes draft state changes properly.packages/bruno-app/src/themes/light.js (1)
490-494: LGTM!The addition of the preferences sidebar border color follows the existing theme structure and naming conventions. The color value is appropriate for the light theme.
packages/bruno-app/src/themes/dark.js (1)
483-487: LGTM!The dark theme preferences sidebar border addition mirrors the light theme structure with an appropriate darker color value.
tests/preferences/autosave/autosave.spec.ts (1)
4-198: Well-structured test suite with good use of test.step.The test structure follows best practices:
- Excellent use of
test.stepfor readable test reports- Consistent locator variable usage
- Multiple assertions per test
- Proper cleanup in
afterEach- No
test.onlyorpage.pause()detectedThe tests comprehensively cover the autosave feature including enabling/disabling, persistence, and existing drafts scenarios.
As per coding guidelines, the test structure promotes readability and maintainability.
packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (3)
4-75: LGTM! Comprehensive action interception list.The actionsToIntercept array is well-organized with clear categorization (request-level, folder-level, collection-level). The list covers all relevant mutation actions that should trigger autosave.
92-117: LGTM! Comprehensive existing drafts detection.The saveExistingDrafts function correctly:
- Iterates through all collections, requests, and folders
- Detects drafts at all levels
- Schedules appropriate save actions with the silent flag
- Uses utility functions (flattenItems, isItemARequest, isItemAFolder) properly
119-161: LGTM! Well-structured middleware implementation.The autosaveMiddleware correctly:
- Updates state before processing (calling
next(action)first)- Checks autosave enabled status
- Handles existing drafts when autosave is enabled
- Filters for relevant actions
- Determines the correct save operation based on payload structure
- Uses debouncing via scheduleAutoSave
The if-else logic at lines 142-154 correctly prioritizes the most specific entity type (request > folder > collection).
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (3)
97-135: LGTM! Clean implementation of silent parameter.The saveRequest function correctly:
- Adds silent parameter with default value false (backward compatible)
- Conditionally displays success toast only when not silent
- Maintains error toast visibility regardless of silent flag
This enables autosave to save requests without showing success notifications while preserving error visibility for debugging.
199-242: LGTM! Consistent implementation of silent parameter.The saveFolderRoot function follows the same pattern as saveRequest:
- Silent parameter added with default false
- Success toast conditional on silent flag
- Error toast always visible
The implementation is consistent and correct.
2133-2172: LGTM! Consistent silent parameter implementation.The saveCollectionSettings function completes the pattern:
- Silent parameter with default false
- Conditional success toast
- Unconditional error toast
All three save actions (saveRequest, saveFolderRoot, saveCollectionSettings) now consistently support silent mode for autosave functionality.
| autoSave: Yup.object({ | ||
| enabled: Yup.boolean(), | ||
| interval: Yup.mixed() | ||
| .transform((value, originalValue) => { | ||
| return originalValue === '' ? undefined : value; | ||
| }) | ||
| .test('isNumber', 'Save Delay must be a number', (value) => { | ||
| return value === undefined || !isNaN(value); | ||
| }) | ||
| .test('isValidInterval', 'Save Delay must be at least 500ms', (value) => { | ||
| return value === undefined || Number(value) >= 500; | ||
| }) | ||
| }).test('intervalRequired', 'Save Delay is required when Auto Save is enabled', (value) => { | ||
| // If autosave is enabled, interval must be provided | ||
| if (value.enabled && (value.interval === undefined || value.interval === '')) { | ||
| return false; | ||
| } | ||
| return true; | ||
| }), |
There was a problem hiding this comment.
Validation mismatch: Frontend requires 500ms minimum, backend allows 100ms.
The frontend schema enforces >= 500 (line 50), but packages/bruno-electron/src/store/preferences.js allows min(100). This inconsistency could cause confusion or allow values saved via other means to fail frontend validation on reload.
Consider aligning both to the same minimum threshold.
🤖 Prompt for AI Agents
In packages/bruno-app/src/components/Preferences/General/index.js around lines
40 to 58 the Yup schema enforces a minimum autoSave.interval of 500ms which
conflicts with the backend preference
(packages/bruno-electron/src/store/preferences.js) that allows 100ms; update the
frontend validation to match the backend by changing the isValidInterval test to
require Number(value) >= 100 (or alternatively update the backend to 500 if you
intend to raise the global minimum) so both sides use the same minimum
threshold.
Description
JIRA
Contribution Checklist:
Screen.Recording.2025-11-27.at.5.23.33.PM.mov
Summary by CodeRabbit
Release Notes
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.