Files
Jordi Enric c2edb29076 fix(studio): explain Supavisor session pool limits DEBUG-43 (#53930)
## Problem

When Supavisor rejects a session because its connection pool is full,
Studio shows the error without explaining how to recover.

## Fix

Show a troubleshooting step for the session-mode limit that explains how
pool size limits concurrent clients and links to the configuration
guide.

## Screenshot

The Table Editor’s troubleshooting step, rendered locally with a sample
session-pool error.

<img width="660" alt="Expanded Supavisor session pool limit guidance in
the Table Editor"
src="https://github.com/user-attachments/assets/6072eec4-e243-4d53-a40f-30fb14d21d05"
/>

## How to test

- Display a classified MaxClientsInSessionMode error in Studio and
expand its troubleshooting step. The link should open the pool size
section of the database connection management guide.
- Display a generic transaction-mode connection limit error. It should
keep its usual fallback.
- The pattern, classification and ErrorMatcher suites exercise these
paths (144 tests passed locally).

Fixes [DEBUG-43](https://linear.app/supabase/issue/DEBUG-43).
2026-11-30 16:49:05 +01:00

152 lines
5.3 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { ErrorMatcher } from './ErrorMatcher'
import {
ConnectionTimeoutError,
SupavisorSessionPoolError,
UnexpectedError,
} from '@/lib/errors/studio-errors'
vi.mock('@/lib/telemetry/track', () => ({ useTrack: () => vi.fn() }))
vi.mock('@/state/ai-assistant-state', () => ({
useAiAssistantStateSnapshot: () => ({ newChat: vi.fn() }),
}))
vi.mock('@/state/sidebar-manager-state', () => ({
useSidebarManagerSnapshot: () => ({ openSidebar: vi.fn() }),
}))
vi.mock('@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider', () => ({
SIDEBAR_KEYS: { AI_ASSISTANT: 'ai-assistant' },
}))
vi.mock('./RestartProjectDialog', () => ({
RestartProjectDialog: () => null,
}))
describe('ErrorMatcher', () => {
it('renders the provided title and error message', () => {
render(
<ErrorMatcher
title="Failed to load tables"
error="ERROR: FAILED TO RUN SQL QUERY: CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT."
supportFormParams={{}}
/>
)
expect(screen.getByText('Failed to load tables')).toBeInTheDocument()
expect(
screen.getByText(
'ERROR: FAILED TO RUN SQL QUERY: CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT.'
)
).toBeInTheDocument()
})
it('renders troubleshooting steps for classified errors', () => {
const error = new ConnectionTimeoutError({
message: 'CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT',
})
render(<ErrorMatcher title="Failed to load tables" error={error} supportFormParams={{}} />)
expect(screen.getByText('Try restarting your project')).toBeInTheDocument()
expect(screen.getByText('Try our troubleshooting guide')).toBeInTheDocument()
expect(screen.getByText('Debug with AI')).toBeInTheDocument()
})
it('renders fallback for non-timeout error class carrying a timeout message', () => {
render(
<ErrorMatcher
title="Failed to load tables"
error={new UnexpectedError({ message: 'CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT' })}
supportFormParams={{}}
/>
)
expect(screen.getByText('Failed to load tables')).toBeInTheDocument()
expect(screen.queryByText('Try restarting your project')).not.toBeInTheDocument()
})
it('renders the Supavisor session pool size guidance for the session limit error', () => {
const error = new SupavisorSessionPoolError({
message:
'MaxClientsInSessionMode: max clients reached - in Session mode max clients are limited to pool_size',
})
render(<ErrorMatcher title="Failed to connect" error={error} supportFormParams={{}} />)
expect(screen.getByText('Increase the Supavisor pool size')).toBeInTheDocument()
expect(
screen.getByText(
'In session mode, each client holds a database connection, so the maximum number of clients is limited by pool_size. Increase the pool size in Database Settings.'
)
).toBeInTheDocument()
expect(screen.getByRole('link', { name: 'View troubleshooting guide' })).toHaveAttribute(
'href',
'https://supabase.com/docs/guides/database/connection-management#configuring-supavisors-pool-size'
)
})
it('renders fallback with provided title for unmatched errors', () => {
render(
<ErrorMatcher title="Failed to load tables" error="UNKNOWN ERROR" supportFormParams={{}} />
)
expect(screen.getByText('Failed to load tables')).toBeInTheDocument()
expect(screen.getByText('UNKNOWN ERROR')).toBeInTheDocument()
})
it('renders the caller-provided fallback when the error is unclassified', () => {
render(
<ErrorMatcher
title="Failed to load tables"
error="UNKNOWN ERROR"
supportFormParams={{}}
fallback={<div>Custom fallback</div>}
/>
)
expect(screen.getByText('Custom fallback')).toBeInTheDocument()
})
it('ignores the caller-provided fallback when the error is classified', () => {
const error = new ConnectionTimeoutError({
message: 'CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT',
})
render(
<ErrorMatcher
title="Failed to load tables"
error={error}
supportFormParams={{}}
fallback={<div>Custom fallback</div>}
/>
)
expect(screen.queryByText('Custom fallback')).not.toBeInTheDocument()
expect(screen.getByText('Try restarting your project')).toBeInTheDocument()
})
it('accepts error as object with message property', () => {
render(
<ErrorMatcher
title="Failed to load tables"
error={{ message: 'UNKNOWN ERROR' }}
supportFormParams={{}}
/>
)
expect(screen.getByText('UNKNOWN ERROR')).toBeInTheDocument()
})
it('builds support link with projectRef param', () => {
render(
<ErrorMatcher
title="Failed to load tables"
error="UNKNOWN ERROR"
supportFormParams={{ projectRef: 'my-project' }}
/>
)
expect(screen.getByRole('link', { name: /contact support/i })).toHaveAttribute(
'href',
'/support/new?projectRef=my-project'
)
})
it('builds support link with no params when supportFormParams is omitted', () => {
render(<ErrorMatcher title="Failed to load tables" error="UNKNOWN ERROR" />)
expect(screen.getByRole('link', { name: /contact support/i })).toHaveAttribute(
'href',
'/support/new'
)
})
})