Files
supabase/apps/studio/components/ui/AlertError.test.tsx
T
Anthony LioandJoshen Lim c3fd259904 fix(ai): assistant sql row cap (#51608)
## Problem

attempt to [fix this
ticket](https://supabase.frontapp.com/inboxes/teams/folders/27650590/unassigned/116845868830):
when the studio ai assistant runs a query with previously set database
opt-in, `execute_sql` returns every row while the query cell's footer
says "Limit 100 rows" causing in case of large amount of returned rows
browser to freeze

+ the chat fails with "Sorry, I'm having trouble responding right now"
until the user clears it

## Solution

- `execute_sql` now keeps the first 100 rows using the cell's existing
`DEFAULT_CELL_ROW_LIMIT`
- uses in history sanitizer the same `toModelRows` helper
- chats saved before this change have no `totalRows` so the helper falls
back to `rows.length` and cuts them to 100 too

<!--
## Preview links

If relevant, include links to changed pages for easy review access.

Copy the preview base URL from the Vercel bot comment on this PR. Use
the following table as an example template.

| Site | Live | Preview | Search for |
| -------------- |
-------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
| ----------------------------- |
| WWW | [/blog/your-post](https://supabase.com/blog/your-post) |
[/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post)
| unique phrase from the change |
| Docs |
[/docs/guides/your-page](https://supabase.com/docs/guides/your-page) |
[/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page)
| unique phrase from the change |
| Studio | [/dashboard](https://supabase.com/dashboard) |
[/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard)
| unique phrase from the change |
| Design system | [/design-system](https://supabase.com/design-system) |
[/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system)
| unique phrase from the change |
| UI library | [/library](https://supabase.com/library) |
[/library](https://ui-library-git-branch-name-supabase.vercel.app/library)
| unique phrase from the change |
| Knowledge base |
[/kb/guides/your-page](https://supabase.com/kb/guides/your-page) |
[/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page)
| unique phrase from the change |
-->

<!-- ## Additional context

Optionally add any other context or screenshots.

-->

## Review instructions

1. In a test project, run this in the SQL editor:
   ```sql
create table "emailSubscriber" (id bigint generated always as identity
primary key, email text);
create table "stripeCustomer" (id bigint generated always as identity
primary key, email text);
insert into "emailSubscriber" (email) select md5(g::text) ||
'@example.com' from generate_series(1, 50000) g;
insert into "stripeCustomer" (email) select md5(g::text) ||
'@example.com' from generate_series(1, 1000) g;
2. on the live dashboard, open the assistant in a new chat and send "i
want all the emails in emailSubscriber where the email is not in the
stripeCustomer table"
3. in the opt in requested settings choose "Schema, Logs & Database
Data"
4. then click run query, the cell should show 100 rows (vs 50000 rows in
prod)

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-10-15 12:22:16 +03:00

77 lines
3.4 KiB
TypeScript

import { SupportCategories } from '@supabase/shared-types/out/constants'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Button } from 'ui'
import { expect, test, vi } from 'vitest'
import { AlertError } from './AlertError'
import { createSupportFormUrl } from '@/components/interfaces/Support/SupportForm.utils'
import { takeBreadcrumbSnapshot } from '@/lib/breadcrumbs'
import { customRender } from '@/tests/lib/custom-render'
vi.mock('@/lib/telemetry/track', () => ({ useTrack: () => vi.fn() }))
vi.mock('@/lib/breadcrumbs', () => ({ takeBreadcrumbSnapshot: vi.fn() }))
test('explicit responsive layout survives additional actions', () => {
customRender(<AlertError layout="responsive" additionalActions={<Button>Retry</Button>} />)
expect(screen.getByRole('alert')).toHaveClass('@container')
expect(screen.getByRole('button', { name: 'Retry' })).toBeInTheDocument()
})
test('hiding support removes its wording from the default instructions', () => {
customRender(<AlertError hideContactSupport />)
expect(screen.getByText('Try refreshing your browser.')).toBeInTheDocument()
expect(screen.queryByText(/contact support/i)).not.toBeInTheDocument()
})
test('support is an inline link with the error context, not an action button', async () => {
const user = userEvent.setup()
customRender(
<AlertError projectRef="default" subject="Failed to load" error={{ message: 'Test error' }} />
)
expect(screen.getByRole('link', { name: 'contact support' })).toHaveAttribute(
'href',
createSupportFormUrl({
category: SupportCategories.DASHBOARD_BUG,
projectRef: 'default',
subject: 'Failed to load',
errorMessage: 'Test error',
})
)
expect(screen.queryByRole('button', { name: /contact support/i })).not.toBeInTheDocument()
await user.click(screen.getByRole('link', { name: 'contact support' }))
expect(takeBreadcrumbSnapshot).toHaveBeenCalledOnce()
})
test('custom support prose links unless support is hidden', () => {
const { rerender } = customRender(
<AlertError description="Please contact support for assistance." />
)
expect(screen.getByRole('link', { name: 'contact support' })).toBeInTheDocument()
rerender(<AlertError description="Please contact support for assistance." hideContactSupport />)
expect(screen.queryByRole('link', { name: 'contact support' })).not.toBeInTheDocument()
expect(screen.getByText('Please contact support for assistance.')).toBeInTheDocument()
})
test.each([false, true])(
'keeps support available with custom instructions (hidden: %s)',
(hidden) => {
const { rerender } = customRender(
<AlertError description="Refresh the page." showInstructions={!hidden} />
)
expect(screen.getByRole('link', { name: 'Contact support' })).toBeInTheDocument()
rerender(
<AlertError description="Refresh the page." showInstructions={!hidden} hideContactSupport />
)
expect(screen.queryByRole('link', { name: /contact support/i })).not.toBeInTheDocument()
}
)
test('support continues the error message inline when instructions are hidden', () => {
customRender(
<AlertError showInstructions={false} showErrorPrefix={false} error={{ message: 'oh no' }} />
)
const link = screen.getByRole('link', { name: 'contact support' })
expect(link.closest('p')).toHaveTextContent('oh no. If the issue persists, contact support.')
expect(screen.queryByRole('link', { name: 'Contact support' })).not.toBeInTheDocument()
})