mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
737b8595f2
## 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>
155 lines
5.0 KiB
TypeScript
155 lines
5.0 KiB
TypeScript
import { screen, waitFor } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { platformComponents } from 'api-types'
|
|
import { FeatureFlagContext } from 'common'
|
|
import { http, HttpResponse } from 'msw'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { LegacyLogsRewriteBanner } from './LegacyLogsRewriteBanner'
|
|
import { API_URL } from '@/lib/constants'
|
|
import { createMockOrganizationResponse } from '@/tests/helpers'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock, mswServer } from '@/tests/lib/msw'
|
|
|
|
type ProjectDetailResponse = platformComponents['schemas']['ProjectDetailResponse_Output']
|
|
|
|
const PROJECT_MOCK: ProjectDetailResponse = {
|
|
id: 1,
|
|
ref: 'default',
|
|
organization_id: 1,
|
|
name: 'Test Project',
|
|
status: 'ACTIVE_HEALTHY',
|
|
cloud_provider: 'AWS',
|
|
region: 'us-east-1',
|
|
db_host: 'db.default.supabase.co',
|
|
restUrl: 'https://default.supabase.co/rest/v1/',
|
|
inserted_at: '2024-01-01T00:00:00Z',
|
|
updated_at: '2024-01-01T00:00:00Z',
|
|
subscription_id: 'sub_123',
|
|
is_branch_enabled: false,
|
|
is_physical_backups_enabled: false,
|
|
high_availability: false,
|
|
integration_source: null,
|
|
connectionString: 'postgresql://postgres@localhost:5432/postgres',
|
|
is_hibernating: false,
|
|
}
|
|
|
|
const ORG_MOCK = createMockOrganizationResponse({ slug: 'test-org', name: 'Test Org' })
|
|
|
|
const LEGACY_SQL = 'select event_message from edge_logs limit 10'
|
|
|
|
const renderBanner = ({
|
|
sql = LEGACY_SQL,
|
|
isLogsSource = true,
|
|
isOtelLogsEnabled = true,
|
|
hidden = false,
|
|
onProposal = vi.fn(),
|
|
}: {
|
|
sql?: string
|
|
isLogsSource?: boolean
|
|
isOtelLogsEnabled?: boolean
|
|
hidden?: boolean
|
|
onProposal?: (proposal: { original: string; modified: string }) => void
|
|
} = {}) => {
|
|
const utils = customRender(
|
|
<FeatureFlagContext.Provider
|
|
value={{ configcat: { otelLegacyLogs: isOtelLogsEnabled }, posthog: {}, hasLoaded: true }}
|
|
>
|
|
<LegacyLogsRewriteBanner
|
|
isLogsSource={isLogsSource}
|
|
sql={sql}
|
|
readSql={() => sql}
|
|
onProposal={onProposal}
|
|
hidden={hidden}
|
|
/>
|
|
</FeatureFlagContext.Provider>
|
|
)
|
|
return { ...utils, onProposal }
|
|
}
|
|
|
|
describe('LegacyLogsRewriteBanner', () => {
|
|
beforeEach(() => {
|
|
addAPIMock({ method: 'get', path: '/platform/projects/:ref', response: PROJECT_MOCK })
|
|
addAPIMock({ method: 'get', path: '/platform/organizations', response: [ORG_MOCK] })
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/projects/:ref/analytics/endpoints/logs.all.otel',
|
|
response: () =>
|
|
HttpResponse.json<platformComponents['schemas']['AnalyticsResponse_Output']>({
|
|
result: [],
|
|
}),
|
|
})
|
|
})
|
|
|
|
it('offers a rewrite for legacy logs SQL when the source is logs and the flag is on', async () => {
|
|
renderBanner()
|
|
|
|
expect(
|
|
await screen.findByText('Logs now run on a ClickHouse-backed engine')
|
|
).toBeInTheDocument()
|
|
})
|
|
|
|
it('stays hidden when the source is not logs', () => {
|
|
renderBanner({ isLogsSource: false })
|
|
|
|
expect(screen.queryByText('Logs now run on a ClickHouse-backed engine')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('stays hidden when the SQL does not look legacy', () => {
|
|
renderBanner({ sql: 'select event_message from logs limit 10' })
|
|
|
|
expect(screen.queryByText('Logs now run on a ClickHouse-backed engine')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('stays hidden when the ClickHouse logs flag is off', () => {
|
|
renderBanner({ isOtelLogsEnabled: false })
|
|
|
|
expect(screen.queryByText('Logs now run on a ClickHouse-backed engine')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('stays hidden when a caller suppresses it via `hidden`, even for legacy SQL', () => {
|
|
renderBanner({ hidden: true })
|
|
|
|
expect(screen.queryByText('Logs now run on a ClickHouse-backed engine')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('hands an accepted rewrite to the caller via onProposal', async () => {
|
|
const rewritten = "select event_message from logs where source = 'edge_logs' limit 10"
|
|
mswServer.use(
|
|
http.post(`${API_URL}/ai/code/complete`, async () => HttpResponse.json(rewritten))
|
|
)
|
|
|
|
const { onProposal } = renderBanner()
|
|
|
|
await userEvent.click(await screen.findByRole('button', { name: 'Rewrite with Assistant' }))
|
|
|
|
await waitFor(() =>
|
|
expect(onProposal).toHaveBeenCalledWith({ original: LEGACY_SQL, modified: rewritten })
|
|
)
|
|
})
|
|
|
|
it('dismisses the offer', async () => {
|
|
renderBanner()
|
|
|
|
await userEvent.click(await screen.findByRole('button', { name: 'Dismiss' }))
|
|
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.queryByText('Logs now run on a ClickHouse-backed engine')
|
|
).not.toBeInTheDocument()
|
|
)
|
|
})
|
|
|
|
it('reports when the assistant found nothing to rewrite', async () => {
|
|
mswServer.use(
|
|
http.post(`${API_URL}/ai/code/complete`, async () => HttpResponse.json(LEGACY_SQL))
|
|
)
|
|
|
|
renderBanner()
|
|
|
|
await userEvent.click(await screen.findByRole('button', { name: 'Rewrite with Assistant' }))
|
|
|
|
expect(await screen.findByText('No rewrite needed')).toBeInTheDocument()
|
|
})
|
|
})
|