Repository navigation
feat: auto-save untitled request drafts - #8864
Max-Reisinger wants to merge 3 commits into
Conversation
WalkthroughTransient requests now autosave as drafts, persist before application quit, restore through workspace snapshots, and save with collision-safe filenames. Shared utilities manage transient directories, and saved requests open from Electron-returned paths. ChangesTransient draft lifecycle
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant AutosaveMiddleware
participant ReduxStore
participant ElectronIPC
participant Snapshot
User->>ReduxStore: edit transient request
ReduxStore->>AutosaveMiddleware: schedule persistent save
AutosaveMiddleware->>ElectronIPC: save transient request
ElectronIPC->>ElectronIPC: choose collision-free filename
ElectronIPC-->>AutosaveMiddleware: return resolved pathname
AutosaveMiddleware->>Snapshot: persist draft state
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/bruno-electron/src/ipc/collection.js (1)
609-638: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winMake collision-safe creation atomic.
Two concurrent saves can both observe that the same pathname is free. Both handlers then await serialization and write the same file. The later write overwrites the earlier draft instead of receiving the next suffix.
Create the target with exclusive creation and retry on
EEXIST. Add a concurrent-save regression test.🤖 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 `@packages/bruno-electron/src/ipc/collection.js` around lines 609 - 638, The collision check around targetPathname is not atomic, allowing concurrent saves to overwrite one another. Update the save flow using writeFile to create the target exclusively, retrying the serialization/write operation with the next filename when an EEXIST error occurs; preserve the existing suffix naming behavior and add a regression test covering concurrent saves.
🤖 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/middlewares/autosave/middleware.js`:
- Around line 289-294: Preserve pending transient saves scheduled by the
persistAlways branch in the autosave middleware when the app/updatePreferences
disable branch clears ordinary timers. Track persistent timers separately or
exclude them from cancellation, and add coverage that disables autosave
immediately after editing a transient request and still verifies the deferred
save executes.
In
`@packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.js`:
- Around line 186-190: Update the filtering condition in serializeSnapshot so
scratch collections are retained only when collection.uid matches
activeWorkspace?.scratchCollectionUid; continue applying
activeWorkspaceCollectionPaths to non-scratch collections. Add a regression test
covering snapshots with scratch collections from two workspaces and verify only
the active workspace scratch collection is serialized.
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 291-294: Update the save-operation handling around Promise.all and
flushSnapshotNow so every operation settles before the snapshot is flushed by
replacing Promise.all with Promise.allSettled. Preserve
flushSnapshotNow(getState) in the finally path, then propagate a rejection after
all saves have settled if any operation failed.
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 630-635: Update both syncExampleUidsCache calls in the save flow
to use targetPathname instead of sourcePathname, so cache entries are created
under the pathname where the request is written; leave the mergedRequest and
serialization logic unchanged.
In `@tests/snapshots/basic.spec.ts`:
- Around line 7-11: Remove the trailing comma from the final imported symbol,
saveTransientViaModal, in the import declaration while preserving the existing
import list and formatting.
---
Outside diff comments:
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 609-638: The collision check around targetPathname is not atomic,
allowing concurrent saves to overwrite one another. Update the save flow using
writeFile to create the target exclusively, retrying the serialization/write
operation with the next filename when an EEXIST error occurs; preserve the
existing suffix naming behavior and add a regression test covering concurrent
saves.
🪄 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 Plus
Run ID: 6d1b8b98-880e-4b23-b29a-719cf4a4305b
📒 Files selected for processing (14)
packages/bruno-app/src/components/SaveTransientRequest/index.jspackages/bruno-app/src/providers/App/ConfirmAppClose/SaveRequestsModal.jspackages/bruno-app/src/providers/App/ConfirmAppClose/index.jspackages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.jspackages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.jspackages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.jspackages/bruno-app/src/utils/snapshot/index.jspackages/bruno-electron/src/app/collection-watcher.jspackages/bruno-electron/src/ipc/collection.jspackages/bruno-electron/src/services/mount/manager.jspackages/bruno-electron/src/utils/transient-directory.jstests/snapshots/basic.spec.ts
| createTransientRequest, | ||
| fillRequestUrl, | ||
| openRequest, | ||
| openCollection, | ||
| saveTransientViaModal, |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Remove the trailing comma from this import.
The project rule does not allow trailing commas.
As per coding guidelines, "Do not use trailing commas".
🤖 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/snapshots/basic.spec.ts` around lines 7 - 11, Remove the trailing comma
from the final imported symbol, saveTransientViaModal, in the import declaration
while preserving the existing import list and formatting.
Source: Coding guidelines
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/middlewares/snapshot/serializeSnapshot.spec.js`:
- Around line 137-168: Update the test fixtures around serializeSnapshot to
build workspace and scratch collection path values with path.join(os.tmpdir(),
...) instead of hardcoded /tmp paths. Reuse the same generated scratch path
values in the collectionPaths assertions, and ensure the required path and os
utilities are available.
In `@packages/bruno-electron/src/utils/write-file-with-suffix.js`:
- Around line 8-14: Constrain the path built in the filename-generation flow
before the writeFile call: validate or sanitize basename and extension so they
cannot contain path separators, absolute paths, or traversal segments, and
ensure path.join(dirname, filename) remains inside dirname. Preserve the
existing suffix generation and exclusive write behavior, and reject invalid
inputs rather than allowing writes outside the target directory.
🪄 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 Plus
Run ID: 7f76601f-cd4d-4aa3-854f-050b0064f6e3
📒 Files selected for processing (8)
packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.jspackages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.spec.jspackages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.jspackages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-electron/src/ipc/collection.jspackages/bruno-electron/src/utils/write-file-with-suffix.jspackages/bruno-electron/src/utils/write-file-with-suffix.spec.js
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.js
- packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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-electron/src/utils/write-file-with-suffix.spec.js`:
- Around line 33-51: Add Windows drive-letter absolute-path cases to the
existing parameterized test for both basename and extension, using values such
as C:\\temp\\Login and C:\\temp\\bru. Keep the assertions verifying rejection
with the appropriate Invalid basename/extension message and ensure createContent
is not called, covering the validatePathSegment path.win32.isAbsolute branch.
🪄 Autofix
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 Plus
Run ID: c01d8b0c-8cdb-4d2e-8e3f-f3d084e3e785
📒 Files selected for processing (4)
packages/bruno-app/src/components/SaveTransientRequest/index.jspackages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.spec.jspackages/bruno-electron/src/utils/write-file-with-suffix.jspackages/bruno-electron/src/utils/write-file-with-suffix.spec.js
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/bruno-app/src/providers/ReduxStore/middlewares/snapshot/serializeSnapshot.spec.js
| it.each([ | ||
| ['basename', '../Login', 'bru'], | ||
| ['basename', '..\\Login', 'bru'], | ||
| ['basename', '/tmp/Login', 'bru'], | ||
| ['extension', 'Login', '../bru'], | ||
| ['extension', 'Login', '..\\bru'] | ||
| ])('rejects an unsafe %s before creating content', async (label, basename, extension) => { | ||
| const createContent = jest.fn(async () => { | ||
| throw new Error('createContent should not run'); | ||
| }); | ||
|
|
||
| await expect(writeFileWithSuffix({ | ||
| dirname, | ||
| basename, | ||
| extension, | ||
| createContent | ||
| })).rejects.toThrow(`Invalid ${label}`); | ||
| expect(createContent).not.toHaveBeenCalled(); | ||
| }); |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Cover Windows absolute paths.
validatePathSegment checks path.win32.isAbsolute(), but these cases do not include a drive-letter path. Add basename and extension cases such as C:\\temp\\Login so this validation branch cannot regress.
As per coding guidelines, “Cover successful behavior as well as realistic errors, edge cases, and degraded-mode behavior.” As per path instructions, “Bruno is a cross-platform Electron desktop app that runs on macOS, Windows, and Linux.”
🤖 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 `@packages/bruno-electron/src/utils/write-file-with-suffix.spec.js` around
lines 33 - 51, Add Windows drive-letter absolute-path cases to the existing
parameterized test for both basename and extension, using values such as
C:\\temp\\Login and C:\\temp\\bru. Keep the assertions verifying rejection with
the appropriate Invalid basename/extension message and ensure createContent is
not called, covering the validatePathSegment path.win32.isAbsolute branch.
Sources: Coding guidelines, Path instructions
Description
Auto-saves new Untitled request drafts to stable application-managed transient storage and restores their tabs after Bruno restarts. Saving a draft whose requested name already exists now selects the next numeric suffix.
Problem
Closing Bruno with unsaved Untitled requests currently prompts the user and the drafts are not restored on the next launch.
Fixes #8849
Fix
Login (1)and use the resolved pathname in the renderer.Testing
npm run build:web— passed.git diff --check— passed.canvasnative module is missingcanvas.node.EMFILEfile-descriptor limit.Screenshots
Not applicable; this changes persistence behavior without changing the UI.
Contribution Checklist:
Summary by CodeRabbit