Skip to content

test(sql-editor): characterization tests for SQLEditor (decompose 1/6) - #47820

Merged
charislam merged 3 commits into
masterfrom
charislam/sql-editor-decompose-1-tests
Jul 10, 2026
Merged

charislam merged 3 commits into
masterfrom
charislam/sql-editor-decompose-1-tests

Conversation

@charislam

@charislam charislam commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add some tests for the SQL editor so I can refactor it without regressions. Tests are not best practice because they are intended to be temporary and improving them would require refactoring first (currently they are over-mocking and asserting on internal details).

Stacked on top of #47792 (charislam/sql-editor-top-bar-controls).

What this adds

apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx (11 tests):

  • Run success → addResult + Results tab; EXPLAIN-shaped result auto-switches to the explain tab; a non-EXPLAIN run switches back.
  • Run error with position → error-highlight line math + deltaDecorations + revealLineInCenter; the next run clears the highlight.
  • Run button refocuses the editor; disabled + short-circuits while a diff is open.
  • Diff request queued before mount drains exactly once (one-shot; no re-apply on remount).
  • Ask-AI widget renders only while the prompt is open (render-time editorRef.current read).
  • Destructive query → warning modal → confirm forces the re-run; confirm-with-RLS appends enable-RLS statements.

Test approach

Real Monaco / DiffEditor are replaced with lightweight fakes exposing a controllable editor; child panels + orthogonal context hooks are stubbed; the execute mutation runs for real against an MSW-mocked /platform/pg-meta/:ref/query. Tests assert on public behavior so they survive the internal refactor unchanged.

Verification

  • pnpm --filter studio exec vitest run tests/components/SQLEditor/SQLEditor.test.tsx — 11/11 pass (stable across repeated runs)
  • pnpm --filter studio typecheck — clean
  • eslint — 0 errors

Summary by CodeRabbit

  • Tests
    • Added comprehensive coverage for SQL editor behavior, including query execution, result and explain views, error highlighting, editor focus, and diff mode.
    • Added validation for destructive-query confirmations, including RLS confirmation flows.
    • Added coverage for queued diff requests and conditional AI prompt display.

charislam added 2 commits July 9, 2026 13:46
Move all SQL editor controls (run, save, database selector, role impersonation, limit, prettify, intellisense, favorite) into a single top bar above the editor. The bar between the editor and results now holds only result-relevant info: the Results/Explain/Chart tabs, row-count summary, and Export button.
Locks the fragile ref/closure/effect behaviors of the SQLEditor monolith (run success/error highlighting, EXPLAIN tab switching, refocus-after-run, one-shot diff-request drain, ask-ai widget gating, destructive-query warning modal) with mocked Monaco/DiffEditor and MSW. This is the behavior-equivalence gate (PR1) for the upcoming SQLEditor decomposition stack.
@charislam
charislam requested a review from a team as a code owner July 10, 2026 14:02
@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a comprehensive SQLEditor characterization suite with mocked Monaco editors, seeded stores, MSW query responses, and coverage for execution tabs, error highlighting, diff handling, AI prompts, and destructive-query confirmation.

Changes

SQLEditor characterization tests

Layer / File(s) Summary
Editor and API test harness
apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx
Sets up deterministic editor mocks, dependent hook stubs, seeded SQL editor stores, MSW responses, lifecycle cleanup, and rendering helpers.
Query execution and editor flows
apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx
Covers Results/Explain tab switching, query-error line decorations, editor refocusing, diff-mode run blocking, and one-time queued diff application.
Prompt and destructive-query flows
apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx
Verifies conditional AI widget visibility and destructive-query confirmation, including RLS-enabled execution.

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

Possibly related PRs

Suggested labels: frontend

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: characterization tests for SQLEditor.
Description check ✅ Passed The description is detailed and covers purpose, behavior, test approach, and verification, even if it doesn't use the exact template headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 charislam/sql-editor-decompose-1-tests

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 10, 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 ↗︎.

@vercel

vercel Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview, Comment Jul 10, 2026 2:45pm
docs Ready Ready Preview, Comment, Open in v0 Jul 10, 2026 2:45pm
studio-self-hosted Ready Ready Preview, Comment Jul 10, 2026 2:45pm
studio-staging Ready Ready Preview, Comment Jul 10, 2026 2:45pm
ui-library Ready Ready Preview, Comment Jul 10, 2026 2:45pm
zone-www-dot-com Ready Ready Preview, Comment, Open in v0 Jul 10, 2026 2:45pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 10, 2026 2:45pm

Request Review

@github-actions

github-actions Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  237 passed
flaky  1 flaky
skipped  5 skipped

Details

stats  243 tests across 28 suites
duration  4 minutes, 36 seconds
commit  08d7c11

Flaky tests

Features › table-editor.spec.ts › table editor › should show rls accordingly

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

Base automatically changed from charislam/sql-editor-top-bar-controls to master July 10, 2026 14:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx (1)

417-462: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Consider increasing the setTimeout delay if CI flakiness appears.

The await new Promise((r) => setTimeout(r, 20)) pattern at lines 439 and 460 is a reasonable approach for negative assertions (give async work time to not happen, then assert it didn't). However, 20ms may be tight on heavily loaded CI runners. If these tests ever flake, bumping to 50–100ms or using waitFor with a short timeout around a positive assertion (e.g., asserting the diff editor is visible) before the negative check would add a safety margin.

This is a minor observation — the current approach is acceptable for characterization tests.

🤖 Prompt for 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.

In `@apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx` around lines 417 -
462, Increase the negative-assertion delays in the tests “run button is disabled
and short-circuits while a diff is open” and “a diff request queued before mount
drains exactly once” from 20ms to a more reliable 50–100ms value, or replace
them with an appropriate waitFor-based synchronization.
🤖 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.

Nitpick comments:
In `@apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx`:
- Around line 417-462: Increase the negative-assertion delays in the tests “run
button is disabled and short-circuits while a diff is open” and “a diff request
queued before mount drains exactly once” from 20ms to a more reliable 50–100ms
value, or replace them with an appropriate waitFor-based synchronization.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7db8ce10-0761-43e5-bd92-e8aab8e9a448

📥 Commits

Reviewing files that changed from the base of the PR and between 0747af0 and 08d7c11.

📒 Files selected for processing (1)
  • apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx

@charislam
charislam merged commit d453e57 into master Jul 10, 2026
37 checks passed
@charislam
charislam deleted the charislam/sql-editor-decompose-1-tests branch July 10, 2026 14:47
@github-actions

github-actions Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1783695015)

Score Average Improvements Regressions
Knowledge Usage 97.4% (+0pp) 1 🟢 1 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+0pp) - -
Tool Usage 74.5% (+0pp) 2 🟢 2 🔴
Time_to_first_token 3.26tok (+0.36tok) 10 🟢 19 🔴
Llm_calls 2.9 (-0.17) 8 🟢 14 🔴
Tool_calls 3.23 (-0.05) 9 🟢 13 🔴
Errors 5.26 (+0.02) 2 🟢 5 🔴
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 23871.68tok (-917.34tok) 13 🟢 12 🔴
Prompt_cached_tokens 9545.56tok (+806.25tok) 11 🟢 10 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 626.15tok (+13.4tok) 14 🟢 15 🔴
Completion_reasoning_tokens 107.01tok (+1.16tok) 16 🟢 10 🔴
Total_tokens 24497.83tok (-903.94tok) 15 🟢 14 🔴
Estimated_cost 0$ (0$) 13 🟢 13 🔴
Duration 17.08s (+0.9s) 13 🟢 16 🔴
Llm_duration 11.68s (+0.34s) 13 🟢 16 🔴

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