Repository navigation
test(sql-editor): characterization tests for SQLEditor (decompose 1/6) - #47820
Conversation
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.
📝 WalkthroughWalkthroughAdds 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. ChangesSQLEditor characterization tests
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
|
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.
|
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › table-editor.spec.ts › table editor › should show rls accordingly Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx (1)
417-462: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueConsider increasing the
setTimeoutdelay 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 usingwaitForwith 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
📒 Files selected for processing (1)
apps/studio/tests/components/SQLEditor/SQLEditor.test.tsx
Braintrust eval report
|
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):addResult+ Results tab; EXPLAIN-shaped result auto-switches to the explain tab; a non-EXPLAIN run switches back.position→ error-highlight line math +deltaDecorations+revealLineInCenter; the next run clears the highlight.editorRef.currentread).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— cleaneslint— 0 errorsSummary by CodeRabbit