Skip to content

test(sqllab): add SQL Lab SDK API contract tests#38860

Open
sadpandajoe wants to merge 3 commits intomasterfrom
test-sql-lab-sdk
Open

test(sqllab): add SQL Lab SDK API contract tests#38860
sadpandajoe wants to merge 3 commits intomasterfrom
test-sql-lab-sdk

Conversation

@sadpandajoe
Copy link
Member

@sadpandajoe sadpandajoe commented Mar 25, 2026

User description

SUMMARY

Add 22 Jest contract tests for the SQL Lab SDK API surface (src/core/sqlLab/index.ts) that extensions depend on. This is a companion to #38776 (host-wiring tests) and covers the Redux listener middleware + module-level singleton surface.

Test breakdown:

  • 11 event listener tests (onDidQueryRun, onDidQuerySuccess, onDidQueryStop, onDidQueryFail, onDidChangeEditorDatabase, onDidChangeEditorSchema, onDidChangeActivePanel, onDidChangeTabTitle, onDidCloseTab, onDidChangeActiveTab, onDidCreateTab)
  • 3 predicate scoping tests (editor-scoped filtering via query immutableId, editor-scoped filtering via queryEditor lookup, globalPredicate fires for non-active tabs)
  • 1 disposable pattern test (dispose stops listener from receiving events)
  • 7 imperative function tests (getCurrentTab, getActivePanel, getTabs, getDatabases, createTab, setActiveTab, setActivePanel)

Architecture: Real configureStore + real createListenerMiddleware with sqlLabReducer — no over-mocking. Store reset + clearListeners() in afterEach ensures no test-to-test state leaks (verified with --randomize).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — test-only change.

TESTING INSTRUCTIONS

cd superset-frontend
npx jest src/core/sqlLab/sqlLab.test.ts --maxWorkers=2
npx jest src/core/sqlLab/sqlLab.test.ts --maxWorkers=2 --randomize

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

CodeAnt-AI Description

Add contract coverage for the SQL Lab SDK behavior that extensions rely on

What Changed

  • Added tests that verify SQL Lab events return the expected tab, query, result, error, database, schema, title, and panel details
  • Added coverage for editor-scoped event filtering so callbacks ignore actions from other tabs and still fire for non-active tabs when expected
  • Added a disposal check to confirm listeners stop receiving updates after they are removed
  • Added coverage for the main SDK actions that create tabs, switch tabs, switch panels, and read the current SQL Lab state

Impact

✅ Safer SQL Lab extensions
✅ Fewer regressions in tab and query events
✅ Clearer confidence in SQL Lab listener behavior

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Add predicate Path B negative test (queryEditor lookup filtering) and
strengthen assertions in onDidQueryStop and onDidChangeActiveTab for
consistency with other context/tab-emitting tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sadpandajoe sadpandajoe marked this pull request as draft March 25, 2026 21:35
@dosubot dosubot bot added the sqllab Namespace | Anything related to the SQL Lab label Mar 25, 2026
@codeant-ai-for-open-source codeant-ai-for-open-source bot added the size:XL This PR changes 500-999 lines, ignoring generated files label Mar 25, 2026
@codeant-ai-for-open-source
Copy link
Contributor

Sequence Diagram

This PR adds contract tests that validate the SQL Lab SDK against a real Redux store and listener middleware. The tests verify listener predicate scoping and disposal behavior, and confirm imperative SDK methods mutate and read SQL Lab state correctly.

sequenceDiagram
    participant Tests
    participant SqlLabSDK
    participant Store
    participant Middleware
    participant Extension

    Tests->>SqlLabSDK: Register listener for active editor
    SqlLabSDK->>Middleware: Attach predicate based listener
    Tests->>Store: Dispatch query action for active editor
    Middleware-->>Extension: Emit query context
    Tests->>Store: Dispatch query action for different editor
    Middleware-->>Extension: Skip callback for non matching editor
    Tests->>SqlLabSDK: Call createTab and getTabs
    SqlLabSDK-->>Tests: Return updated tabs from store state
    Tests->>SqlLabSDK: Dispose listener and dispatch again
    Middleware-->>Extension: No callback after dispose
Loading

Generated by CodeAnt AI

@netlify
Copy link

netlify bot commented Mar 25, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 7275d4b
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69c473d99d93710008a63c7a
😎 Deploy Preview https://deploy-preview-38860--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Jest contract tests to validate the SQL Lab SDK API surface (src/core/sqlLab/index.ts) that extensions depend on, focusing on listener middleware behavior and imperative accessors against a real configureStore + createListenerMiddleware setup.

Changes:

  • Introduces 22 contract tests covering SQL Lab event listeners, predicate scoping, and disposal behavior.
  • Adds coverage for imperative SQL Lab SDK functions (tab/panel switching, tab creation, and state getters).
  • Uses a real reducer + listener middleware test harness with per-test cleanup to avoid state/listener leaks.

Addresses PR feedback: nanoid mock now returns unique values
(mock-nanoid-1, mock-nanoid-2, ...) instead of a static string,
preventing id/immutableId collisions in addQueryEditor calls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@sadpandajoe sadpandajoe marked this pull request as ready for review March 25, 2026 23:46
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Mar 26, 2026

Code Review Agent Run #b9a8dd

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 9d49db9..7275d4b
    • superset-frontend/src/core/sqlLab/sqlLab.test.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL size:XL This PR changes 500-999 lines, ignoring generated files sqllab Namespace | Anything related to the SQL Lab

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants