fix(storage): factory-reset must not uninstall the CLI or erase the local Convex DB - #87
Merged
Merged
Conversation
…ocal Convex DB wipeLocalBrigadeState() did a blunt `rm -rf ~/.brigade`. But a no-Node install puts Brigade's own Node runtime + the `brigade` binary UNDER ~/.brigade (the Unix installer -> ~/.brigade/runtime), so "Clear it" / "Start fresh" / `store reset --purge-local` deleted the running interpreter, leaving `brigade`/`node`/`npm` "command not found" in every new shell. A global install also keeps the local Convex database at ~/.brigade/convex/data, so the same wipe was silent, irreversible data loss -- and on Windows an EPERM crash mid-wipe while the backend holds its sqlite open. Clear state CONTENTS while preserving, name-agnostically, whatever entry holds the running node (process.execPath) or the installed package -- so the guard holds whether the installer named the dir `runtime` (Unix) or `node` (Windows) -- plus the local `convex/` store. Route `store reset --purge-local` through the same primitive. Stop a running gateway before the onboard wizard wipes, honoring the factory-reset "gateway must be stopped first" contract (a live daemon's open handles otherwise EPERM-abort the wizard on Windows).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
wipeLocalBrigadeState()did a bluntrm -rf ~/.brigade. But two things live under that dir that must not be destroyed by a state reset:brigadebinary under~/.brigade/runtime(Unix installer), so "Clear it" / "Start fresh" /store reset --purge-localdeleted the interpreter that was running →brigade/node/npmbecomecommand not foundin every new shell.~/.brigade/convex/data. The same wipe was silent, irreversible data loss — and on Windows an EPERM crash mid-wipe while the backend held its sqlite open.Fix
wipeLocalBrigadeStatenow clears state contents while preserving, name-agnostically, whatever top-level entry holds the runningnode(process.execPath) or the installed package — so it holds whether the installer named the dirruntime(Unix) ornode(Windows), and is a no-op when the runtime lives outside the state dir. Plus the localconvex/store.store reset --purge-localrouted through the same primitive (it had its own rawrm -rf).onboardstops a running gateway before the wizard wipes — honoring the factory-reset "gateway must be stopped first" contract (a live daemon's open handles otherwise EPERM-abort the wizard on Windows).Tests
factory-reset.test.ts: replaced the old "removes the entire dir" assertion (which pinned the bug); added runtime-preservation, convex-preservation, and name-agnostic detection tests — including the Windowsnode-named layout. 12/12 storage tests pass.