Repository navigation
fix(safety): gate every destructive write on production, not just the editor's - #595
Merged
Merged
Conversation
… editor's resultStore has held the production confirmation since #393, but only statements routed through resultStore.executeQuery ever reached it. Grid cell edits, the admin panel, import and restore all call api.executeQuery directly, so editing a cell on a connection marked production wrote to it with no confirmation at all (#588). The reason they went direct is that the store's gate cannot be awaited: it raises a dialog and returns, leaving the caller no way to learn whether the user agreed. A caller with work to do afterwards — refresh the grid, advance an import loop, close a dialog — could not use it. #393 fixed one call site by restructuring it around that limitation rather than removing the limitation. confirmDestructive answers. It resolves true when there is nothing to ask about, so a caller gates unconditionally without deciding for itself what counts as dangerous, and false when the user declines, so the caller stops. A second question while one is open declines the first rather than stranding its promise. Wired into the four bypassing paths. Batches ask once: prompting per statement through a thousand-line dump would be held down rather than read. The grid asks about every write, not only the destructive verbs. isDestructiveStatement deliberately excludes UPDATE and INSERT because typing one is the ordinary business of a SQL client — but nobody composes a statement to edit a grid cell. A stray keystroke and a click on Save is the whole gesture, so direct manipulation gets a lower bar. isProductionConnection tolerates an absent connection list rather than throwing. A read landing before connections have loaded is the same situation as a connection that is not in the list, and both already answer "not production"; throwing would abort the caller's save instead of gating it. The grid's test mock omitted those fields, which is how this surfaced. Closes #588 Co-Authored-By: Claude Opus 5 <[email protected]>
The unit test was updated for the production guard's dialog; its browser counterpart was not, and it is the browser suite that CI runs. `npx vitest run` uses the unit config, which excludes *.browser.test.tsx, so this passed locally and failed in CI — my mistake for not running `npm run test:browser` before pushing. Also covers the guard dialog starting closed, which nothing asserted. Co-Authored-By: Claude Opus 5 <[email protected]>
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.
Closes #588.
The hole
resultStorehas held the production confirmation since #393, but only statements routed throughresultStore.executeQueryreach it. These callapi.executeQuerydirectly:ResultsGrid.tsx:449)Editing a cell on a connection marked production wrote to it with no confirmation at all.
Why they bypassed it
The store's gate can't be awaited: it raises a dialog and returns, leaving the caller no way to learn whether the user agreed. Any caller with work to do afterwards — refresh the grid, advance an import loop — couldn't use it. #393 fixed one call site by restructuring it around that limitation instead of removing the limitation, which is why the pattern was never swept.
confirmDestructiveanswers.truewhen there's nothing to ask about (so callers gate unconditionally without judging danger themselves),falsewhen declined (so they stop). A second question while one is open declines the first rather than stranding its promise.Two judgement calls
isDestructiveStatementexcludes UPDATE/INSERT because typing one is ordinary work — but nobody composes a statement to edit a cell. A stray keystroke and a click on Save is the whole gesture, so direct manipulation gets a lower bar (alwaysAsk).Incidental
isProductionConnectiontolerates an absent connection list rather than throwing — a read landing before connections load is the same situation as a connection not in the list, and both already answer "not production". Throwing would abort the caller's save instead of gating it. The grid's test mock omitting those fields is how this surfaced.That led to #594: nine
vi.mockpaths across five test files resolve to nothing (../../stores/xfrom a__tests__dir lands insrc/components/stores/x). Vitest silently no-ops an unresolvable mock, so those suites have been running against the real modules and passing anyway.RestoreDialog.test.tsxmocks nothing it thinks it does. Filed rather than folded in here — fixing the paths will surface assertions that only passed by accident, and that deserves its own diff.Verification
12 tests on the guard, 4 on the grid. 3 of the 4 fail against the ungated grid; the 4th is a guard (non-production must not ask) that correctly passes either way. Full suite green, 0 lint errors.