Repository navigation
test(sql-editor): add mock-free hook tests (Step 4) - #48214
Conversation
Colocated, vi.mock-free tests for the extracted SQL editor hooks, built on the Step 3 renderHook harness (in-memory editor port + real stores + MSW): - useSqlEditorExecution: destructive-query gating, auto-limit suffixing, connection-string resolution, onSuccess/onError session-store writes, error-line highlight, diff-open short-circuit - useSqlEditorAi: one-shot diff-request drain (empty vs non-empty editor), accept/discard diff, onDebug opening the assistant chat + debug prompt - usePrettifyQuery: in-place format + write-back, diff-open no-op - useSnippetIdentity: generated identity + store-driven loading state - useSnippetTitleGenerator: untitled-snippet naming via the title endpoint
|
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
|
📝 WalkthroughWalkthroughAdded Vitest coverage for SQL editor hooks, including formatting, snippet metadata, AI diff/debug workflows, query execution safeguards, error handling, replica selection, and session-store updates. ChangesSQL editor hook tests
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: 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.
🧹 Nitpick comments (1)
apps/studio/components/interfaces/SQLEditor/useSqlEditorAi.test.tsx (1)
70-88: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid fixed-sleep "prove a negative" assertions in async tests.
Both sites use a bare
setTimeout(20ms)to assert that nothing happened, rather than a deterministic flush. This is a common flaky-test smell: the window is unenforced by any contract and can be too short under CI load, or mask a delayed re-application bug.
apps/studio/components/interfaces/SQLEditor/useSqlEditorAi.test.tsx#L70-L88: replace thesetTimeout(r, 20)wait at line 85 with a deterministic microtask flush (e.g.await act(async () => {})) or a small sharedflushAsync()/assertStable()test helper.apps/studio/components/interfaces/SQLEditor/useSqlEditorExecution.test.tsx#L235-L248: replace thesetTimeout(r, 20)wait at line 245 with the same deterministic flush helper instead of an arbitrary timer.🤖 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/components/interfaces/SQLEditor/useSqlEditorAi.test.tsx` around lines 70 - 88, Replace the arbitrary 20ms waits used for negative async assertions with the same deterministic microtask flush or shared flushAsync/assertStable helper. Update the request-remount test around sqlEditorDiffRequestState in apps/studio/components/interfaces/SQLEditor/useSqlEditorAi.test.tsx#L70-L88 and the corresponding execution test in apps/studio/components/interfaces/SQLEditor/useSqlEditorExecution.test.tsx#L235-L248; preserve both tests’ existing assertions and behavior.
🤖 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/components/interfaces/SQLEditor/useSqlEditorAi.test.tsx`:
- Around line 70-88: Replace the arbitrary 20ms waits used for negative async
assertions with the same deterministic microtask flush or shared
flushAsync/assertStable helper. Update the request-remount test around
sqlEditorDiffRequestState in
apps/studio/components/interfaces/SQLEditor/useSqlEditorAi.test.tsx#L70-L88 and
the corresponding execution test in
apps/studio/components/interfaces/SQLEditor/useSqlEditorExecution.test.tsx#L235-L248;
preserve both tests’ existing assertions and behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6cb18347-3ff8-44b8-9493-83475dcb8f92
📒 Files selected for processing (5)
apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.test.tsxapps/studio/components/interfaces/SQLEditor/useSnippetIdentity.test.tsxapps/studio/components/interfaces/SQLEditor/useSnippetTitleGenerator.test.tsxapps/studio/components/interfaces/SQLEditor/useSqlEditorAi.test.tsxapps/studio/components/interfaces/SQLEditor/useSqlEditorExecution.test.tsx
🎭 Playwright Test Results (tanstack)Details
Flaky testsFeatures › table-editor.spec.ts › table editor › add enums and show enums on table Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
Braintrust eval report
|
What
Step 4 of the SQL editor testability plan: mock-free hook tests for the extracted SQL editor hooks, built on the Step 3 renderHook harness (
tests/lib/sql-editor-test-utils.tsx) — in-memory editor port + real valtio stores + MSW. Zerovi.mock.useSqlEditorExecution.test.tsxpotentialIssuesvs. forced run), auto-limit suffixing, connection-string →x-connection-encryptedheader,onSuccess/onErrorsession-store writes, error-line highlight, diff-open short-circuituseSqlEditorAi.test.tsxonDebugopening the assistant chat + debug promptusePrettifyQuery.test.tsxuseSnippetIdentity.test.tsxuseSnippetTitleGenerator.test.tsxEvery test exercises real dependencies at the seam where they're real: network via MSW, stores used real and reset per test, Monaco via the in-memory editor port.
Test plan
pnpm test:studio -- SQLEditor→ 286/286 passing (21 new tests included)pnpm --filter studio typecheckcleanvi.mockin the new filesSummary by CodeRabbit