mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 11:55:05 +03:00
## Problem platform, v1 and v2 have been already completely migrated and introduced some changes. Some types have been renamed, some outputs and inputs updated. ## Solution - Update the API types - Fix the TS errors ## Update Taking this over to unblock #50134, which needs the new scoped token permission ids from the regenerated types. - Merged `master`. - Regenerated `api-v2.d.ts` from the production spec. The previous files came from a local API that exposed a webhook events endpoint production doesn't have yet. Production has since added standardized 400 error responses on the v2 organization endpoints. `api-v1.d.ts` and `platform.d.ts` already matched production. - Fixed `verify-production-types`. It formatted the regenerated files in a temp directory outside the repository, so Prettier fell back to its defaults and the comparison could never match the committed files. It now passes the repository config explicitly. `pnpm api:verify-types` passes on this branch. - Verified locally: `pnpm typecheck`, `pnpm api:verify-types`, Studio unit tests. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Preserved descriptions when saving, sharing, moving, or unsharing notebooks, reports, SQL snippets, and saved queries. * Improved handling of empty or null values across notebook descriptions, billing usage, pooler settings, and infrastructure fields. * Improved read-replica connection handling, including read-only connection strings. * Updated storage configuration and capability handling to match current settings. * **API and Compatibility** * Updated organization, project, storage, OAuth, billing, and infrastructure data handling to match current API responses. * OAuth app creation and updates now require scopes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
190 lines
7.1 KiB
TypeScript
190 lines
7.1 KiB
TypeScript
import { screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { HttpResponse } from 'msw'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { AssistantNotebookPreview } from './AssistantNotebookPreview'
|
|
import type { components } from '@/data/api'
|
|
import type { NotebookCellDiffEntry } from '@/data/content/notebooks/notebook-operations'
|
|
import type { AgentCell, CellWire } from '@/data/content/notebooks/notebook-schema'
|
|
import { customRender as render } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
const wireMarkdownCell = (id: string, text: string): CellWire => ({
|
|
_tag: 'markdown_cell',
|
|
_id: id,
|
|
text,
|
|
})
|
|
|
|
const agentMarkdownCell = (text: string): AgentCell => ({ _tag: 'markdown_cell', text })
|
|
|
|
const wireDatabaseCell = (id: string, database_identifier?: string): CellWire => ({
|
|
_tag: 'database_cell',
|
|
_id: id,
|
|
sql: 'select 1',
|
|
row_limit: 100,
|
|
database_identifier,
|
|
})
|
|
|
|
const agentDatabaseCell = (database_identifier?: string): AgentCell => ({
|
|
_tag: 'database_cell',
|
|
sql: 'select 1',
|
|
row_limit: 100,
|
|
database_identifier,
|
|
})
|
|
|
|
describe('AssistantNotebookPreview', () => {
|
|
// The whole safety argument for this feature reduces to this: agent-authored markdown text
|
|
// is rendered as literal source (via CodeBlock), never interpreted into real DOM nodes. A
|
|
// future refactor that swaps in <Markdown> would break this silently.
|
|
it('never renders agent-authored cell content as real img/link/src DOM nodes', async () => {
|
|
const user = userEvent.setup()
|
|
const adversarialText =
|
|
' [y](https://evil.example/) <img src=x onerror=1>'
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'added', cell: agentMarkdownCell(adversarialText), operationIndex: 0 },
|
|
]
|
|
|
|
const { container } = render(<AssistantNotebookPreview entries={entries} mode="update" />)
|
|
await user.click(screen.getByRole('button', { name: 'Added Markdown cell' }))
|
|
|
|
expect(container.querySelectorAll('img')).toHaveLength(0)
|
|
expect(container.querySelectorAll('[href]')).toHaveLength(0)
|
|
expect(container.querySelectorAll('[src]')).toHaveLength(0)
|
|
})
|
|
|
|
it('renders the create-mode header summary', () => {
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'unchanged', cell: wireMarkdownCell('a', 'one') },
|
|
{ _tag: 'unchanged', cell: wireMarkdownCell('b', 'two') },
|
|
]
|
|
|
|
const { container } = render(<AssistantNotebookPreview entries={entries} mode="create" />)
|
|
|
|
expect(screen.getByRole('toolbar', { name: 'Notebook toolbar' })).toBeInTheDocument()
|
|
expect(screen.getByText('2 cells')).toBeInTheDocument()
|
|
expect(screen.getByText('New notebook')).toBeInTheDocument()
|
|
expect(container.firstElementChild).toHaveClass('max-w-6xl')
|
|
})
|
|
|
|
it('surfaces a metadata-only database change after resolving the target', async () => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/databases',
|
|
response: () =>
|
|
HttpResponse.json<components['schemas']['DatabaseDetailResponse_Output'][]>([
|
|
{
|
|
identifier: 'default',
|
|
region: 'us-east-1',
|
|
status: 'ACTIVE_HEALTHY',
|
|
cloud_provider: 'AWS',
|
|
db_host: 'db.default.supabase.co',
|
|
db_name: 'postgres',
|
|
db_port: 5432,
|
|
db_user: 'postgres',
|
|
inserted_at: '2026-01-01T00:00:00.000Z',
|
|
restUrl: 'https://default.supabase.co/rest/v1',
|
|
size: 't4g.micro',
|
|
connectionString: '',
|
|
connection_string_read_only: '',
|
|
},
|
|
{
|
|
identifier: 'default-replica-3',
|
|
region: 'us-east-1',
|
|
status: 'ACTIVE_HEALTHY',
|
|
cloud_provider: 'AWS',
|
|
db_host: 'db.default-replica-3.supabase.co',
|
|
db_name: 'postgres',
|
|
db_port: 5432,
|
|
db_user: 'postgres',
|
|
inserted_at: '2026-01-01T00:00:00.000Z',
|
|
restUrl: 'https://default-replica-3.supabase.co/rest/v1',
|
|
size: 't4g.micro',
|
|
connectionString: '',
|
|
connection_string_read_only: '',
|
|
},
|
|
]),
|
|
})
|
|
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{
|
|
_tag: 'replaced',
|
|
before: wireDatabaseCell('cell-1', 'default'),
|
|
after: agentDatabaseCell('default-replica-3'),
|
|
operationIndex: 0,
|
|
},
|
|
]
|
|
|
|
render(<AssistantNotebookPreview entries={entries} mode="update" />)
|
|
|
|
expect(screen.getByText('Loading database…')).toBeInTheDocument()
|
|
const metadata = await screen.findByText('Database: Primary → Database: Replica')
|
|
expect(metadata).toBeInTheDocument()
|
|
expect(
|
|
screen.getByRole('button', { name: 'Replaced Query: Untitled query' })
|
|
).toHaveTextContent('Database: Primary → Database: Replica')
|
|
})
|
|
|
|
it('hides entries past the limit behind a "Show N more" button', async () => {
|
|
const entries: NotebookCellDiffEntry[] = Array.from({ length: 7 }, (_, index) => ({
|
|
_tag: 'unchanged' as const,
|
|
cell: wireMarkdownCell(`cell-${index}`, `text-${index}`),
|
|
}))
|
|
|
|
render(<AssistantNotebookPreview entries={entries} mode="create" />)
|
|
|
|
expect(screen.getByText('Show 2 more cells')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders run results inside their matching minified notebook cell', () => {
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'unchanged', cell: wireDatabaseCell('cell-1') },
|
|
]
|
|
|
|
const { container } = render(
|
|
<AssistantNotebookPreview
|
|
entries={entries}
|
|
mode="run"
|
|
title="Signup funnel"
|
|
results={{ 'cell-1': { rows: [] } }}
|
|
/>
|
|
)
|
|
|
|
expect(screen.getByText('Signup funnel')).toBeInTheDocument()
|
|
expect(screen.getByText('1 cell')).toBeInTheDocument()
|
|
expect(screen.getByText('Success. No rows returned')).toBeInTheDocument()
|
|
expect(screen.getByText('0 rows')).toBeInTheDocument()
|
|
expect(container.querySelector('[data-slot="explorer-query-results"]')).toBeInTheDocument()
|
|
})
|
|
|
|
it('bases result rendering and layout on supplied results rather than preview mode', () => {
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'unchanged', cell: wireDatabaseCell('cell-1') },
|
|
]
|
|
|
|
const { container } = render(
|
|
<AssistantNotebookPreview
|
|
entries={entries}
|
|
mode="create"
|
|
results={{ 'cell-1': { rows: [{ value: 1 }] } }}
|
|
/>
|
|
)
|
|
|
|
expect(screen.getByText('1 row')).toBeInTheDocument()
|
|
expect(container.querySelector('[data-slot="explorer-query-results"]')).toBeInTheDocument()
|
|
expect(container.querySelector('.flex.flex-col.gap-2')).toBeInTheDocument()
|
|
expect(container.querySelector('.divide-y.divide-border')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('keeps a run preview without results in the grouped cell layout', () => {
|
|
const entries: NotebookCellDiffEntry[] = [
|
|
{ _tag: 'unchanged', cell: wireDatabaseCell('cell-1') },
|
|
]
|
|
|
|
const { container } = render(<AssistantNotebookPreview entries={entries} mode="run" />)
|
|
|
|
expect(container.querySelector('[data-slot="explorer-query-results"]')).not.toBeInTheDocument()
|
|
expect(container.querySelector('.divide-y.divide-border')).toBeInTheDocument()
|
|
})
|
|
})
|