Skip to content

refactor(sql-editor): finish EditorController/DiffController port (Step 2) - #48166

Merged
charislam merged 1 commit into
masterfrom
sql-editor-editor-controller-port
Jul 21, 2026
Merged

charislam merged 1 commit into
masterfrom
sql-editor-editor-controller-port

Conversation

@charislam

@charislam charislam commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Step 2 of the SQL Editor testability plan.

SQLEditorContext already wrapped the Monaco refs and exposed a few semantic imperative helpers (getEditorSql, clearHighlights, applyErrorHighlight, refocusEditor, …). This finishes that abstraction so no hook or controller touches editorRef.current/diffEditorRef.current directly anymore — they only call the port. The port is what will let Step 3's test harness inject a real in-memory editor adapter instead of mocking Monaco; production wires it to the real Monaco refs, unchanged.

  • Extends the context value with two semantic controllers, backed by the existing refs:
    • editor: EditorController — isReady, getValue, getSelectionStartLine, getSql (today's getEditorSql), replaceAll (wraps the repeated executeEdits(...) pattern), focus, revealLineInCenter, highlightErrorLine (today's applyErrorHighlight), clearHighlights.
    • diff: DiffController — isMounted, getModifiedValue, setDiff (the diff-sync effect body), attach (today's handleDiffEditorMount).
  • Migrates every touch point off raw refs onto the port: useSqlEditorExecution, usePrettifyQuery, useSqlEditorShortcuts, SQLEditorControllers' readEditorSql, and useSqlEditorAi's acceptAiHandler/drainDiffRequest/handleDiffEditorMount/diff-sync effect.
  • SQLEditorEditorPanel.tsx is intentionally left untouched — it wires the raw refs into the real Monaco/DiffEditor React components for rendering, which isn't decision logic to abstract.

Behavior-preserving.

Test plan

  • pnpm --filter studio typecheck
  • pnpm test:studio -- SQLEditor (265 tests passing)
  • pnpm --filter studio run lint:ratchet

…troller/DiffController port

Extends SQLEditorContext with two semantic, Monaco-agnostic controllers —
editor: EditorController and diff: DiffController — backed by the existing
editorRef/diffEditorRef in production. Migrates every hook/controller that
used to read editorRef.current/diffEditorRef.current directly onto the port:
useSqlEditorExecution, usePrettifyQuery, useSqlEditorShortcuts,
SQLEditorControllers' readEditorSql, and useSqlEditorAi's acceptAiHandler,
drainDiffRequest, handleDiffEditorMount, and the diff-sync effect.

The diff-sync effect now wraps its body in useEffectEvent (matching
resetDiff/drainDiffRequest right below it): its real trigger is "the diff
content changed" (selectedDiffType/sourceSqlDiff), while isDiffOpen,
diffController, defaultSqlDiff, and promptState.startLineNumber should be
read fresh without retriggering the effect on unrelated changes (e.g. the
prompt's start line moving without a new diff).

SQLEditorEditorPanel.tsx is intentionally left untouched: it wires the raw
refs into the real Monaco/DiffEditor React components, which is genuine
production rendering, not decision logic to abstract.

This is the seam that lets Step 3's test harness inject a real in-memory
editor instead of mocking Monaco. Behavior-preserving.
@charislam
charislam requested a review from a team as a code owner July 21, 2026 18:09
@vercel

vercel Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment Jul 21, 2026 6:14pm
studio-staging Ready Ready Preview, Comment Jul 21, 2026 6:14pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 21, 2026 6:14pm
design-system Skipped Skipped Jul 21, 2026 6:14pm
docs Skipped Skipped Open in v0 Jul 21, 2026 6:14pm
ui-library Skipped Skipped Jul 21, 2026 6:14pm
zone-www-dot-com Skipped Skipped Open in v0 Jul 21, 2026 6:14pm

Request Review

@supabase

supabase Bot commented Jul 21, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The SQL editor context now exposes editor and diff controllers. SQL retrieval, formatting, execution, shortcuts, and AI diff workflows use controller methods instead of direct Monaco references and standalone context helpers.

Changes

SQL editor controller migration

Layer / File(s) Summary
Controller contracts and context wiring
apps/studio/components/interfaces/SQLEditor/SQLEditor.types.ts, apps/studio/components/interfaces/SQLEditor/SQLEditorContext.tsx
Defines EditorController and DiffController, composes their editor and diff operations, and exposes them through the context.
Editor API consumer migration
apps/studio/components/interfaces/SQLEditor/SQLEditorControllers.tsx, apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.ts, apps/studio/components/interfaces/SQLEditor/useSqlEditorExecution.ts, apps/studio/components/interfaces/SQLEditor/useSqlEditorShortcuts.ts
Routes SQL reading, formatting, readiness checks, error highlighting, highlight clearing, and focus actions through editor.
AI diff lifecycle migration
apps/studio/components/interfaces/SQLEditor/useSqlEditorAi.ts
Routes diff attachment, synchronization, modified SQL retrieval, readiness checks, mounting checks, and replacement application through diffController and editor.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AI diff workflow
  participant DiffController
  participant EditorController
  AI diff workflow->>DiffController: setDiff(diff, revealLine)
  AI diff workflow->>DiffController: getModifiedValue()
  AI diff workflow->>EditorController: replaceAll(modifiedSql)
Loading

Possibly related PRs

Suggested reviewers: awaseem

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is concise and accurately summarizes the main refactor to finish the SQL editor controller port.
Description check ✅ Passed The description covers the change, current/new behavior, context, and test plan, though it doesn't mirror the template exactly.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sql-editor-editor-controller-port

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  237 passed
flaky  2 flaky
skipped  5 skipped

Details

stats  244 tests across 29 suites
duration  6 minutes, 34 seconds
commit  d4a76da

Flaky tests

Features › database.spec.ts › Database › Schema Visualizer › table actions work as expected
Features › realtime-inspector.spec.ts › Realtime Inspector › Basic Inspector UI › can join and leave a channel

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@charislam
charislam merged commit 3d83e02 into master Jul 21, 2026
42 of 45 checks passed
@charislam
charislam deleted the sql-editor-editor-controller-port branch July 21, 2026 20:22
@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1784665560)

Score Average Improvements Regressions
Completeness 96.6% (+1pp) 4 🟢 3 🔴
Conciseness 47.7% (+4pp) 10 🟢 9 🔴
Goal Completion 80.5% (+0pp) 5 🟢 4 🔴
Knowledge Usage 92.3% (-3pp) 1 🟢 2 🔴
Tool Usage 70.6% (-2pp) - 1 🔴
Correctness 68.9% (+2pp) 2 🟢 2 🔴
Docs Faithfulness 70.7% (+5pp) 3 🟢 2 🔴
Safety 85% (+4pp) 2 🟢 1 🔴
URL Validity 100% (+0pp) - -
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+11pp) 1 🟢 -
Time_to_first_token 3.64tok (+0.61tok) 5 🟢 24 🔴
Llm_calls 7.25 (+0.23) 14 🟢 11 🔴
Tool_calls 2.86 (-0.14) 11 🟢 12 🔴
Errors 0.02 (+0.02) - 1 🔴
Llm_errors 0.01 (+0.01) - 1 🔴
Tool_errors 0 (+0) - -
Prompt_tokens 24932.51tok (+2297.43tok) 14 🟢 12 🔴
Prompt_cached_tokens 8380.32tok (+5.89tok) 8 🟢 18 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 581.93tok (-12.76tok) 14 🟢 15 🔴
Completion_reasoning_tokens 88.99tok (-2.01tok) 14 🟢 13 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 25514.44tok (+2284.67tok) 14 🟢 15 🔴
Estimated_cost 0$ (+0$) 13 🟢 16 🔴
Duration 17.47s (-0.65s) 14 🟢 15 🔴
Llm_duration 13.09s (-0.08s) 16 🟢 13 🔴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants