Repository navigation
fix(migration): reattach mountv2 watcher after yml migration - #8567
bijin-bruno merged 2 commits into
Conversation
|
Caution Review failedFailed to post review comments. We encountered an issue with GitHub. Use ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout. (6)
|
| Layer / File(s) | Summary |
|---|---|
Centralized mount lifecycle and validation packages/bruno-electron/src/services/mount/manager.js, packages/bruno-electron/src/services/mount/manager.spec.js |
Mount startup delegates to #coldLoad; remounting updates metadata, removes the prior watcher, reloads state, reconciles files, emits the tree, and restores watchers. Tests cover success, missing mounts, and watcher-removal failures. |
IPC remount integration packages/bruno-electron/src/ipc/mount.js, packages/bruno-electron/src/ipc/collection.js |
The mount IPC exports remount, and collection migration invokes it before conditionally falling back to direct watcher attachment or displaying an error. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Sequence Diagram(s)
sequenceDiagram
participant CollectionIPC
participant MountIPC
participant MountManager
participant Watcher
CollectionIPC->>MountIPC: remount migrated collection
MountIPC->>MountManager: delegate remount(params)
MountManager->>Watcher: remove and reattach watchers
MountManager-->>CollectionIPC: return remount result
CollectionIPC->>Watcher: fallback watcher attachment when needed
Possibly related PRs
- usebruno/bruno#8424: Both modify the YML collection migration flow and migrated
brunoConfighandling. - usebruno/bruno#8514: Both modify the
MountManagermount pipeline and reconciliation behavior exercised by remounting. - usebruno/bruno#8553: Both modify the end-to-end YML collection migration flow.
Suggested reviewers: helloanoop, lohit-bruno, naman-bruno, bijin-bruno, sid-bruno
Poem
A watcher sleeps, then wakes anew,
The mount path finds its rhythm too.
Files reconcile, trees arise,
Live sync returns beneath bright skies.
Remount flows where old paths flew.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly matches the main change: reattaching the mountv2 watcher after YML migration. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
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 @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/bruno-electron/src/services/mount/manager.js (1)
104-118: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
remountupdatesentry.winbut never refreshesentry.emit.
entry.emit(used inside#coldLoadforloading/tree events) is only ever set once, at initialmount()time, and its callbacks are closures bound to the window/webContents captured at that point (seeipc/mount.js'smount-collection-v2handler).remount({ win, ... })updatesentry.winbut has no way to updateentry.emit— so if a caller ever passes awindifferent from the one the collection was originally mounted with (e.g. after a window reload/recreate), tree/loading events would keep firing against a stale/possibly-destroyed window whileentry.win(used for the actual fs watcher) points to the new one.Currently the single call site (
collection.jsmigration handler) reuses the samemainWindowfor both, so this isn't user-visible today, but the API shape invites future misuse. Consider either accepting/refreshingemitalongsidewin, or dropping thewinparam fromremountif it's never expected to differ from the mount-time window.🤖 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/services/mount/manager.js` around lines 104 - 118, Update remount() and its callers so entry.emit is refreshed whenever a new win is supplied, ensuring `#coldLoad` emits through the current window rather than stale mount-time callbacks; alternatively remove the win parameter if remount must always reuse the original window. Keep entry.win and entry.emit synchronized across remounts, including the mount-collection-v2 callback setup.
🤖 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/ipc/collection.js`:
- Around line 2783-2793: Ensure the remount failure path in the migration
handler also attempts watcher recovery when appropriate: in the catch around
remountCollectionV2, distinguish genuine remount errors from an unavailable
remount and invoke watcher.addWatcher with the same arguments and ignoreInitial
option used by the !remounted branch when safe. Preserve the error logging and
user notification for genuine failures, and coordinate with
remountCollectionV2’s removeWatcher error handling so recovery does not mask the
original error.
In `@packages/bruno-electron/src/services/mount/manager.js`:
- Around line 104-136: Add tests covering the new remount lifecycle in
MountManager: verify successful remount tears down and reattaches watchers while
reconciling and emitting the tree, unknown collectionUid returns false without
lifecycle work, and errors from collectionWatcher.removeWatcher are propagated
with loading state restored. Use the remount and `#coldLoad` methods with mocked
watcher, index, reconciliation, and emit dependencies.
---
Nitpick comments:
In `@packages/bruno-electron/src/services/mount/manager.js`:
- Around line 104-118: Update remount() and its callers so entry.emit is
refreshed whenever a new win is supplied, ensuring `#coldLoad` emits through the
current window rather than stale mount-time callbacks; alternatively remove the
win parameter if remount must always reuse the original window. Keep entry.win
and entry.emit synchronized across remounts, including the mount-collection-v2
callback setup.
🪄 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: f2d9f384-4be5-4f67-a0f0-7d0a6f049e39
📒 Files selected for processing (3)
packages/bruno-electron/src/ipc/collection.jspackages/bruno-electron/src/ipc/mount.jspackages/bruno-electron/src/services/mount/manager.js
The migrate-to-yml handler tore down the collection watcher and re-attached it the v1 way (no fileIndex, no temp-dir watcher), so a collection mounted via mountv2 lost cache-backed live sync after migration and the file cache kept stale .bru entries. Add MountManager.remount, which re-reconciles the cache against disk and re-attaches the watcher through the shared cold-load path while preserving the existing transient directory. The migrate handler now delegates to it when the collection is v2-mounted and falls back to the v1 watcher otherwise.
- Drop the unused win param from MountManager.remount; it always reuses the mount-time win/emit (a real window swap goes through mount()'s reload branch, which refreshes both). - Migration success path now falls back to a plain watcher when remount throws, not only when it returns false; the reopen-collection toast is the last resort. - Migration rollback path prefers remount for v2-mounted collections too, falling back to the v1 watcher. - Add unit tests for remount: successful reattach + tree re-emit, unknown collection returns false, watcher-removal failure propagates.
2febdb6 to
4daf0ff
Compare
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/ipc/collection.js`:
- Around line 2814-2822: Update the rollback handling around remountCollectionV2
so a remount failure still re-attaches the watcher via watcher.addWatcher when
available. Make the parsed bruno.json configuration accessible to the catch
block by hoisting its declaration or otherwise preserving/reusing it, and ensure
the fallback does not depend on rereading a file that may have been deleted
during migration.
🪄 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: fab20b37-c2c5-4f15-85ad-da05ca813e2e
📒 Files selected for processing (4)
packages/bruno-electron/src/ipc/collection.jspackages/bruno-electron/src/ipc/mount.jspackages/bruno-electron/src/services/mount/manager.jspackages/bruno-electron/src/services/mount/manager.spec.js
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/bruno-electron/src/ipc/mount.js
- packages/bruno-electron/src/services/mount/manager.spec.js
- packages/bruno-electron/src/services/mount/manager.js
Problem
When a collection is migrated from
.bruto.ymlvia the migrate-to-yml action, therenderer:migrate-collection-to-ymlhandler tears down the collection watcher and re-attaches it the v1 way — without afileIndexand without a temp-directory watcher.For a collection mounted via mountv2 (file cache enabled), this breaks live sync: file changes no longer write through to the cache, and the cache keeps stale
.bruentries while the new.ymlfiles are never indexed (the watcher re-attaches withignoreInitial: true).Fix
MountManager.remount(...), which re-reconciles the file-index cache against disk (evicting stale.bruentries, indexing the new.ymlfiles), re-emits the tree, and re-attaches the watcher through the shared cold-load path — preserving the existing transient directory so the renderer's tracked path stays valid.#coldLoadreused by bothmountandremount.remountwhen the collection is v2-mounted, and falls back to the v1 watcher otherwise. The v1/v2 branch is driven by whether the collection is present inMountManager's mount map, so it can't drift from thecache.file.enabledpreference.Notes
Reload fast-path in
mount()is unchanged; only the cold path is shared.Summary by CodeRabbit
.bruto.ymlto more reliably restore live synchronization.