Skip to content

test(sql-editor): add mock-free hook tests (Step 4) - #48214

Merged
charislam merged 1 commit into
masterfrom
sql-editor-hook-tests-v1
Jul 22, 2026
Merged

charislam merged 1 commit into
masterfrom
sql-editor-hook-tests-v1

Conversation

@charislam

@charislam charislam commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

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. Zero vi.mock.

File Tests Covers
useSqlEditorExecution.test.tsx 8 destructive-query gating (potentialIssues vs. forced run), auto-limit suffixing, connection-string → x-connection-encrypted header, onSuccess/onError session-store writes, error-line highlight, diff-open short-circuit
useSqlEditorAi.test.tsx 7 one-shot diff-request drain (empty vs. non-empty editor), drain-exactly-once across remounts, accept/discard diff, onDebug opening the assistant chat + debug prompt
usePrettifyQuery.test.tsx 2 in-place format + write-back, diff-open no-op
useSnippetIdentity.test.tsx 2 generated identity + store-driven loading state
useSnippetTitleGenerator.test.tsx 2 untitled-snippet naming via the title endpoint

Every 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 typecheck clean
  • Confirmed zero vi.mock in the new files

Summary by CodeRabbit

  • Tests
    • Added comprehensive automated coverage for SQL query formatting, snippet identity, and AI-generated titles.
    • Added coverage for AI-assisted SQL editing, including diff acceptance, rejection, debugging, and request handling.
    • Added coverage for query execution, result persistence, safety checks, replica selection, error highlighting, and diff-state behavior.

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
@charislam
charislam requested a review from a team as a code owner July 22, 2026 18:11
@supabase

supabase Bot commented Jul 22, 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 22, 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 22, 2026 6:13pm
studio-staging Ready Ready Preview, Comment Jul 22, 2026 6:13pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 22, 2026 6:13pm
design-system Skipped Skipped Jul 22, 2026 6:13pm
docs Skipped Skipped Open in v0 Jul 22, 2026 6:13pm
ui-library Skipped Skipped Jul 22, 2026 6:13pm
zone-www-dot-com Skipped Skipped Open in v0 Jul 22, 2026 6:13pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added 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.

Changes

SQL editor hook tests

Layer / File(s) Summary
Snippet and formatting hook coverage
apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.test.tsx, apps/studio/components/interfaces/SQLEditor/useSnippetIdentity.test.tsx, apps/studio/components/interfaces/SQLEditor/useSnippetTitleGenerator.test.tsx
Tests formatting persistence and diff-mode no-op behavior, generated snippet identity and loading, and AI-generated title updates.
AI diff and debug flows
apps/studio/components/interfaces/SQLEditor/useSqlEditorAi.test.tsx
Tests queued request draining, diff synchronization, accept/discard behavior, remount stability, and debug prompt/sidebar initialization.
Query execution behavior
apps/studio/components/interfaces/SQLEditor/useSqlEditorExecution.test.tsx
Tests query results, auto-limits, destructive-query gating, failures and highlighting, replica headers, diff gating, and title-generation conditions.

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

Possibly related PRs

Suggested labels: frontend

Suggested reviewers: awaseem

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is useful but does not follow the required template and omits the asked-for sections. Rewrite it to match the template with the CONTRIBUTING confirmation, change type, current behavior, new behavior, and additional context sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: mock-free SQL editor hook tests.
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 sql-editor-hook-tests-v1

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.

@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/components/interfaces/SQLEditor/useSqlEditorAi.test.tsx (1)

70-88: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid 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 the setTimeout(r, 20) wait at line 85 with a deterministic microtask flush (e.g. await act(async () => {})) or a small shared flushAsync()/assertStable() test helper.
  • apps/studio/components/interfaces/SQLEditor/useSqlEditorExecution.test.tsx#L235-L248: replace the setTimeout(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

📥 Commits

Reviewing files that changed from the base of the PR and between ca2a390 and 21eaceb.

📒 Files selected for processing (5)
  • apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.test.tsx
  • apps/studio/components/interfaces/SQLEditor/useSnippetIdentity.test.tsx
  • apps/studio/components/interfaces/SQLEditor/useSnippetTitleGenerator.test.tsx
  • apps/studio/components/interfaces/SQLEditor/useSqlEditorAi.test.tsx
  • apps/studio/components/interfaces/SQLEditor/useSqlEditorExecution.test.tsx

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  239 passed
flaky  1 flaky
skipped  5 skipped

Details

stats  245 tests across 29 suites
duration  4 minutes, 9 seconds
commit  21eaceb

Flaky tests

Features › table-editor.spec.ts › table editor › add enums and show enums on table

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 08c4f64 into master Jul 22, 2026
37 of 38 checks passed
@charislam
charislam deleted the sql-editor-hook-tests-v1 branch July 22, 2026 18:53
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1784746642)

Score Average Improvements Regressions
Completeness 98.9% (+0pp) 1 🟢 1 🔴
Conciseness 35.1% (-9pp) 3 🟢 12 🔴
Docs Faithfulness 64.6% (0pp) 2 🟢 4 🔴
Goal Completion 79.9% (-2pp) 3 🟢 5 🔴
Knowledge Usage 97.4% (+0pp) 1 🟢 1 🔴
Tool Usage 78.4% (+4pp) 2 🟢 1 🔴
Correctness 70% (-2pp) 1 🟢 3 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+4pp) 1 🟢 -
URL Validity 100% (+0pp) - -
Safety 90.5% (+0pp) 1 🟢 1 🔴
Time_to_first_token 2.36tok (-0.89tok) 27 🟢 2 🔴
Llm_calls 6.6 (-0.67) 5 🟢 14 🔴
Tool_calls 3.28 (-0.02) 8 🟢 11 🔴
Errors 0 (-0.02) 1 🟢 -
Llm_errors 0 (-0.01) 1 🟢 -
Tool_errors 0 (+0) - -
Prompt_tokens 23662.02tok (-760.75tok) 15 🟢 10 🔴
Prompt_cached_tokens 8739.31tok (+417.84tok) 18 🟢 7 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 728.44tok (+102.79tok) 12 🟢 17 🔴
Completion_reasoning_tokens 121.01tok (+14.75tok) 14 🟢 12 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 24390.46tok (-657.95tok) 17 🟢 12 🔴
Estimated_cost 0$ (0$) 17 🟢 10 🔴
Duration 13.55s (-4.79s) 25 🟢 4 🔴
Llm_duration 10.67s (-2.65s) 24 🟢 5 🔴

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