mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 11:25:06 +03:00
## Context > [!IMPORTANT] > Will open up for review once CLI PR is merged and deployed so that it's easier to test Related PR: https://github.com/supabase/cli/pull/5230 Adding support for vector buckets for local CLI - will need to be tested locally via `pnpm run dev:studio-local` ## To test There's a bit of testing instructions in the linear ticket [here](https://linear.app/supabase/issue/FE-3474/show-vector-buckets-in-local-admin-studio) as it involves using a branch of CLI - otherwise do reach out to Fabrizio if any help might be needed, but generally: ### Local CLI You might need to manually set `isCli` to `true` in `StorageMenuV2` if the "Vectors" nav item isn't showing up on the storage UI given we're testing via `pnpm run dev:studio-local` - [x] Can create bucket - [x] Can delete bucket - [x] Can create indexes - [x] Can insert data into indexes (via FDW) - [x] Can delete indexes Known issues (that aren't directly solvable from FE end) Reach out to Fabrizio for context as we were both investigating this - PG database needs to be on 17.6 (otherwise there's no S3 vectors FDW) - Storage version needs to be on 1.59.0 ### Self-hosted (This might be tricky to actually test, but just ensure that the code satisfies this) - [x] Cannot see vector buckets ### Hosted - [x] Everything works status quo <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Vector bucket management UI and platform APIs (create/list/delete buckets & indexes) * Local S3 credentials endpoint and client-side hook for self‑hosted/CLI use * **Bug Fixes** * Improved S3 vector setup notifications and clearer error guidance for manual installation * **Refactor** * Deployment-mode gating: platform vs CLI/self‑hosted now controls feature visibility and page behavior * **Tests** * Added suites covering deployment-mode gates and vector bucket error/usage scenarios * **Chores** * Build env updated to expose local S3 credential vars <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46381?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Ali Waseem <waseema393@gmail.com>
114 lines
3.8 KiB
TypeScript
114 lines
3.8 KiB
TypeScript
import { waitFor } from '@testing-library/react'
|
|
import { HttpResponse } from 'msw'
|
|
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
|
|
import {
|
|
useIsVectorBucketsEnabled,
|
|
type ProjectStorageConfigData,
|
|
} from './project-storage-config-query'
|
|
import type { DeploymentMode } from '@/hooks/misc/useDeploymentMode'
|
|
import { customRenderHook } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
const { mockIsPlatform, mockUseDeploymentMode } = vi.hoisted(() => ({
|
|
mockIsPlatform: { value: false },
|
|
mockUseDeploymentMode: vi.fn<() => DeploymentMode>(),
|
|
}))
|
|
|
|
// `useProjectStorageConfigQuery` (same module as the hook under test) gates its
|
|
// fetch on the build-time `IS_PLATFORM` constant — mock it so the query fires in
|
|
// the platform cases.
|
|
vi.mock('@/lib/constants', async () => {
|
|
const actual = await vi.importActual<Record<string, unknown>>('@/lib/constants')
|
|
return {
|
|
...actual,
|
|
get IS_PLATFORM() {
|
|
return mockIsPlatform.value
|
|
},
|
|
}
|
|
})
|
|
|
|
vi.mock('@/hooks/misc/useDeploymentMode', () => ({
|
|
useDeploymentMode: mockUseDeploymentMode,
|
|
}))
|
|
|
|
const createStorageConfig = (vectorBucketsEnabled: boolean): ProjectStorageConfigData =>
|
|
({
|
|
capabilities: { iceberg_catalog: false, list_v2: false },
|
|
databasePoolMode: 'transaction',
|
|
external: { upstreamTarget: 'main' },
|
|
features: {
|
|
icebergCatalog: { enabled: false, maxCatalogs: 0, maxNamespaces: 0, maxTables: 0 },
|
|
imageTransformation: { enabled: false },
|
|
s3Protocol: { enabled: false },
|
|
vectorBuckets: { enabled: vectorBucketsEnabled, maxBuckets: 0, maxIndexes: 0 },
|
|
},
|
|
fileSizeLimit: 0,
|
|
migrationVersion: 'v1',
|
|
}) as ProjectStorageConfigData
|
|
|
|
const deploymentMode = (overrides: Partial<DeploymentMode>): DeploymentMode => ({
|
|
isPlatform: false,
|
|
isCli: false,
|
|
isSelfHosted: false,
|
|
...overrides,
|
|
})
|
|
|
|
describe('useIsVectorBucketsEnabled', () => {
|
|
beforeEach(() => {
|
|
mockIsPlatform.value = false
|
|
mockUseDeploymentMode.mockReset()
|
|
})
|
|
|
|
test('platform + storage config flag enabled: true', async () => {
|
|
mockIsPlatform.value = true
|
|
mockUseDeploymentMode.mockReturnValue(deploymentMode({ isPlatform: true }))
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/config/storage',
|
|
response: () => HttpResponse.json<ProjectStorageConfigData>(createStorageConfig(true)),
|
|
})
|
|
|
|
const { result } = customRenderHook(() => useIsVectorBucketsEnabled({ projectRef: 'default' }))
|
|
|
|
await waitFor(() => expect(result.current).toBe(true))
|
|
})
|
|
|
|
test('platform + storage config flag disabled: false', async () => {
|
|
mockIsPlatform.value = true
|
|
mockUseDeploymentMode.mockReturnValue(deploymentMode({ isPlatform: true }))
|
|
|
|
let configRequested = false
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/config/storage',
|
|
response: () => {
|
|
configRequested = true
|
|
return HttpResponse.json<ProjectStorageConfigData>(createStorageConfig(false))
|
|
},
|
|
})
|
|
|
|
const { result } = customRenderHook(() => useIsVectorBucketsEnabled({ projectRef: 'default' }))
|
|
|
|
await waitFor(() => expect(configRequested).toBe(true))
|
|
expect(result.current).toBe(false)
|
|
})
|
|
|
|
test('CLI: true regardless of the storage config flag', () => {
|
|
// Query is disabled off-platform, so no storage config endpoint is needed.
|
|
mockUseDeploymentMode.mockReturnValue(deploymentMode({ isCli: true }))
|
|
|
|
const { result } = customRenderHook(() => useIsVectorBucketsEnabled({ projectRef: 'default' }))
|
|
|
|
expect(result.current).toBe(true)
|
|
})
|
|
|
|
test('self-hosted: false', () => {
|
|
mockUseDeploymentMode.mockReturnValue(deploymentMode({ isSelfHosted: true }))
|
|
|
|
const { result } = customRenderHook(() => useIsVectorBucketsEnabled({ projectRef: 'default' }))
|
|
|
|
expect(result.current).toBe(false)
|
|
})
|
|
})
|