Skip to content

refactor(sql-editor): extract deriveSnippetIdentity, debug/completion/diff-key helpers - #48014

Merged
charislam merged 4 commits into
masterfrom
sql-editor-utils-snippet-identity
Jul 21, 2026
Merged

charislam merged 4 commits into
masterfrom
sql-editor-utils-snippet-identity

Conversation

@charislam

@charislam charislam commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pure-fn extraction pass across the SQL editor hooks.

  • Extracts deriveSnippetIdentity out of useSnippetIdentity's inline id + isLoading derivation into SQLEditor.utils.ts.
  • Extracts extractDebugContext (shared snippet/result/error extraction) and buildDebugChatArgs (the aiSnap.newChat(...) payload builder) out of useSqlEditorAi's buildDebugPrompt/onDebug into SQLEditor.utils.ts.
  • Extracts buildCompletionRequestBody (the AI completion endpoint's request body builder) and planDiffRequestApplication (the pending-diff-request application decision: replace vs. open a diff, depending on whether the editor is currently empty) out of useSqlEditorAi into SQLEditor.utils.ts. The drainDiffRequest effect now just applies the plan instead of branching inline.
  • Extracts resolveDiffKeyAction out of useSqlEditorShortcuts's window-keydown Enter/Escape branch into SQLEditor.utils.ts.

Test plan

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

@charislam
charislam requested a review from a team as a code owner July 16, 2026 18:56
@vercel

vercel Bot commented Jul 16, 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 4:34pm
studio-staging Ready Ready Preview, Comment Jul 21, 2026 4:34pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 21, 2026 4:34pm
design-system Skipped Skipped Jul 21, 2026 4:34pm
docs Skipped Skipped Jul 21, 2026 4:34pm
ui-library Skipped Skipped Jul 21, 2026 4:34pm
zone-www-dot-com Skipped Skipped Jul 21, 2026 4:34pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

SQL Editor utilities now centralize snippet identity, completion request construction, debug context and chat payload creation, diff application planning, and keyboard action resolution. The snippet identity and AI hooks delegate to these helpers, with unit tests covering the updated behavior.

Changes

SQL Editor utility extraction

Layer / File(s) Summary
Shared utilities and coverage
apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.ts, apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts
Adds helpers for snippet identity, completion requests, debug context, chat arguments, diff planning, and diff key actions, with unit tests for normal and fallback cases.
Snippet identity integration
apps/studio/components/interfaces/SQLEditor/useSnippetIdentity.ts
Delegates snippet ID and loading-state calculation to deriveSnippetIdentity.
AI, diff, and shortcut integration
apps/studio/components/interfaces/SQLEditor/useSqlEditorAi.ts, apps/studio/components/interfaces/SQLEditor/useSqlEditorShortcuts.ts
Uses shared helpers for debug prompts, chat payloads, completion requests, pending diff application, and Enter/Escape handling.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: awaseem

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and tests, but it omits required template sections like CONTRIBUTING confirmation, current behavior, and additional context. Add the missing template sections: CONTRIBUTING confirmation, current behavior with linked issues, new behavior, and additional context.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 clearly summarizes the main change: extracting SQL editor helper functions into a refactor.
✨ 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-utils-snippet-identity

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.

@supabase

supabase Bot commented Jul 16, 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 ↗︎.

@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  239 passed
skipped  5 skipped

Details

stats  244 tests across 29 suites
duration  32 minutes, 15 seconds
commit  8fd75f5

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 force-pushed the sql-editor-utils-execute-title branch from dd7b26e to caebe4f Compare July 16, 2026 20:47
Base automatically changed from sql-editor-utils-execute-title to master July 16, 2026 21:08
Pulls the id + isLoading derivation out of useSnippetIdentity into a pure,
unit-testable function in SQLEditor.utils.ts. Behavior-preserving.
Pulls the shared snippet/result/error extraction and the newChat payload
builder out of useSqlEditorAi's buildDebugPrompt/onDebug into pure,
unit-testable functions in SQLEditor.utils.ts.

Minor behavior normalization: onDebug previously assumed snippet/result
were defined and would throw (caught by its own try/catch, surfacing a
generic toast) if the debug button was somehow clicked before a result
existed. It now shares buildDebugPrompt's defensive fallbacks (empty sql /
'Unknown error') instead of relying on the catch block for that case.
@charislam
charislam force-pushed the sql-editor-utils-snippet-identity branch from 468678f to 8c8f3e7 Compare July 21, 2026 15:48
@charislam charislam changed the title refactor(sql-editor): extract deriveSnippetIdentity refactor(sql-editor): extract deriveSnippetIdentity + extractDebugContext/buildDebugChatArgs Jul 21, 2026
…estApplication

Continues extracting useSqlEditorAi's decision logic into pure,
unit-testable functions: the AI completion endpoint's request body builder,
and the pending-diff-request application decision (replace vs. open a diff,
depending on whether the editor is currently empty). The effect
(drainDiffRequest) now just applies the plan instead of branching inline.
Behavior-preserving.
@charislam charislam changed the title refactor(sql-editor): extract deriveSnippetIdentity + extractDebugContext/buildDebugChatArgs refactor(sql-editor): extract deriveSnippetIdentity, debug/completion, diff-request helpers Jul 21, 2026
Pulls the window-keydown Enter/Escape branch out of useSqlEditorShortcuts
into a pure, unit-testable function in SQLEditor.utils.ts. Behavior-
preserving.

This completes the Step 1 pure-fn extraction pass across the SQL editor
hooks.
@charislam charislam changed the title refactor(sql-editor): extract deriveSnippetIdentity, debug/completion, diff-request helpers refactor(sql-editor): extract deriveSnippetIdentity, debug/completion/diff-key helpers Jul 21, 2026
@charislam
charislam merged commit cdc843d into master Jul 21, 2026
36 of 39 checks passed
@charislam
charislam deleted the sql-editor-utils-snippet-identity branch July 21, 2026 17:47
@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1784656277)

Score Average Improvements Regressions
Completeness 96.6% (-3pp) - 3 🔴
Conciseness 41.4% (+1pp) 10 🟢 7 🔴
Docs Faithfulness 62.8% (-4pp) 2 🟢 4 🔴
Goal Completion 78.2% (-5pp) 3 🟢 7 🔴
Tool Usage 72.5% (+2pp) 2 🟢 1 🔴
Knowledge Usage 97.4% (+3pp) 1 🟢 -
Correctness 71.1% (+10pp) 7 🟢 1 🔴
Safety 76.2% (-10pp) 1 🟢 2 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+17pp) 1 🟢 -
URL Validity 100% (+0pp) - -
Time_to_first_token 4.27tok (+0.78tok) 18 🟢 11 🔴
Llm_calls 7.33 (+0.15) 14 🟢 10 🔴
Tool_calls 3.05 (+0.01) 10 🟢 9 🔴
Errors 0.02 (+0) 1 🟢 1 🔴
Llm_errors 0.01 (+0) 1 🟢 1 🔴
Tool_errors 0 (+0) - -
Prompt_tokens 26756.47tok (+3978.28tok) 10 🟢 15 🔴
Prompt_cached_tokens 7968.37tok (+1106.39tok) 14 🟢 11 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 611.71tok (+1.76tok) 15 🟢 13 🔴
Completion_reasoning_tokens 100.84tok (+2.7tok) 8 🟢 18 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 27368.18tok (+3980.03tok) 13 🟢 15 🔴
Estimated_cost 0$ (+0$) 15 🟢 14 🔴
Duration 22.18s (+3.67s) 18 🟢 11 🔴
Llm_duration 18.26s (+6.11s) 14 🟢 15 🔴

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