Repository navigation
refactor(sql-editor): extract pure SQL helpers + tighten safe-SQL boundary (decompose 2/6) - #47831
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe SQL editor now uses typed untrusted and safe SQL fragments, promotes SQL at execution boundaries, centralizes editor and EXPLAIN helpers, and adds utility coverage for extraction, diagnostics, completion, debugging, and execution formatting. ChangesSQL editor execution and utility refactor
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant MonacoEditor
participant handleRunShortcut
participant executeQuery
MonacoEditor->>handleRunShortcut: editor SQL
handleRunShortcut->>handleRunShortcut: acceptUntrustedSql(sql)
handleRunShortcut->>executeQuery: SafeSqlFragment
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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: 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 `@apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx`:
- Around line 875-886: Update onConfirmWithRLS to resolve the base SQL through
readEditorSql(), matching onConfirm and the run path, instead of directly
calling getEditorSql(editor). Preserve the snippet unchecked_sql fallback before
passing the result to appendEnableRLSStatements.
🪄 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: 0c6ddfad-b85c-481e-a035-3c75581f36fb
📒 Files selected for processing (3)
apps/studio/components/interfaces/SQLEditor/SQLEditor.tsxapps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.tsapps/studio/components/interfaces/SQLEditor/SQLEditor.utils.ts
🎭 Playwright Test Results (tanstack)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
972ddfa to
d11dfe3
Compare
…QL boundary Extracts getEditorSql, computeErrorHighlightLine, assembleCompletionDiff, buildExplainSql, and buildDebugPromptText out of the SQLEditor monolith into SQLEditor.utils, with unit tests. Also removes rawSql() from the SQL editor. getEditorSql now returns an UntrustedSqlFragment so editor/snippet SQL keeps its untrusted provenance through the destructive-query checks. The execute helpers (executeQuery/executeExplainQuery) now require a SafeSqlFragment, so they are safe by construction and can never auto-run untrusted SQL; acceptUntrustedSql promotion happens only in the small run/explain gesture handlers. Runtime-identical (identity casts); the characterization suite stays green.
d11dfe3 to
0a9430f
Compare
Braintrust eval report
|
Summary
SQLEditor.tsxmonolith into unit-tested functions inSQLEditor.utils.ts.rawSql()from the SQL editor and tighten the untrusted→safe boundary per thesafe-sql-executionmodel.Extracted functions (+ tests)
getEditorSql(editor, snippetContent?)— selection → full value → snippet fallback. Returns anUntrustedSqlFragmentso editor/snippet SQL keeps its provenance.computeErrorHighlightLine(error, startLineNumber)— parses theLINE n:marker + selection offset.assembleCompletionDiff(meta, text)— before/selection/after assembly for the AI completion diff.buildExplainSql(sql, impersonatedRoleState)— takes an already-safe fragment; EXPLAIN ANALYZE + role impersonation + rollback wrapping.buildDebugPromptText(sql, errorMessage)— the assistant debug prompt string.Safe-SQL boundary
rawSql()is no longer used anywhere in the SQL editor.executeQuery/executeExplainQuerynow require aSafeSqlFragment— safe by construction, so they can never auto-run untrusted SQL.acceptUntrustedSqlpromotion happens only in the small run/explain gesture handlers (executeQueryFromButton,handleRunShortcut,handleRunExplain, and the warning-modal confirm handlers), never buried in the long helpers.Verification
vitest— 156 pass (11 characterization + 145 utils, incl. new cases)pnpm --filter studio typecheck— clean for all SQL editor files (two unrelated@sentry/tanstackstart-reactmodule-resolution errors exist on current master pre-install; not touched by this PR)eslint— 0 errorsSummary by CodeRabbit
Enhancements
Bug Fixes