mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 03:15:06 +03:00
Upgrade vite and vitest to their latest major versions across the
monorepo, along with related packages.
**Changed:**
- `vite` catalog: `^7.3.2` → `^8.0.8` (Rolldown replaces esbuild/Rollup)
- `vitest` catalog: `^3.2.0` → `^4.1.4`
- `@vitejs/plugin-react`: `^4.3.4` → `^6.0.1`
- `@vitest/coverage-v8`: `^3.2.0` → `^4.1.4`
- `@vitest/ui`: `^3.2.0` → `^4.1.4`
- `vite-tsconfig-paths`: `^4.3.2` / `^5.1.4` → `^6.1.1`
**Pinned to vite 7:**
- `apps/lite-studio` — `@react-router/dev` hasn't declared vite 8
support yet
- `blocks/vue` — Nuxt plugins (`vite-plugin-inspect`, `vite-dev-rpc`,
`vite-hot-client`, `vite-plugin-vue-tracer`) haven't declared vite 8
support yet
**Test fixes for vitest 4 breaking changes:**
- **`apps/studio/lib/api/snippets.utils.test.ts`** — Replaced
`vi.mock('fs/promises')` automock with an explicit factory. Vitest 4's
automocking doesn't create mock functions for getter-based exports on
Node built-ins, so `mockedFS.access.mockResolvedValue` etc. were
`undefined`.
- **`apps/studio/lib/api/self-hosted/functions/index.test.ts`** —
Changed `mockReturnValue` to `mockImplementation(function() { ... })`
for a constructor mock. Vitest 4 no longer allows `mockReturnValue` when
the mock is called with `new`.
- **`apps/studio/tests/pages/api/mcp/index.test.ts`** — Changed arrow
function to regular `function` in `mockImplementation` for
`StreamableHTTPServerTransport`. Arrow functions can't be constructors,
and vitest 4 now enforces this.
- **`packages/ui-patterns/vitest.setup.ts`** — Changed `ResizeObserver`
mock from arrow function to regular `function` for the same constructor
enforcement reason. This was crashing Radix popover rendering in jsdom.
## To test
- `pnpm test:studio` — all 226 test files should pass
- `pnpm --filter ui-patterns vitest run` — all 183 tests should pass
- `pnpm --filter www test -- --run` — all 19 tests should pass
- `pnpm --filter ui vitest run` — all tests should pass
- `pnpm --filter dev-tools vitest run` — all tests should pass
- `pnpm --filter ai-commands vitest run` — all tests should pass
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Chores**
* Standardized and updated development tooling versions and version
sources for consistent installs across the repo (Vite, Vitest,
vite-tsconfig-paths and related plugins/catalog entries).
* **Tests**
* Improved test mocks and typings (updated mock
factories/implementations and tightened spy/type assertions) to increase
test reliability and compatibility with updated tooling.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
221 lines
7.3 KiB
TypeScript
221 lines
7.3 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { getIncidentTools } from './incident-tools'
|
|
|
|
// Mock IS_PLATFORM
|
|
vi.mock('common', () => ({
|
|
IS_PLATFORM: true,
|
|
}))
|
|
|
|
describe('ai/tools/incident-tools', () => {
|
|
let mockFetch: ReturnType<typeof vi.fn>
|
|
let mockAbortSignal: AbortSignal
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockFetch = vi.fn()
|
|
global.fetch = mockFetch as typeof fetch
|
|
|
|
// Mock AbortSignal.timeout
|
|
mockAbortSignal = new AbortController().signal
|
|
if (!AbortSignal.timeout) {
|
|
AbortSignal.timeout = vi.fn(() => mockAbortSignal) as any
|
|
}
|
|
})
|
|
|
|
describe('getIncidentTools', () => {
|
|
it('should return an object with get_active_incidents tool', () => {
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
|
|
expect(tools).toBeDefined()
|
|
expect(tools.get_active_incidents).toBeDefined()
|
|
})
|
|
|
|
it('should have correct description for get_active_incidents', () => {
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
|
|
expect(tools.get_active_incidents.description).toContain('Check for active incidents')
|
|
expect(tools.get_active_incidents.description).toContain('Supabase service')
|
|
})
|
|
|
|
it('should have empty input schema', () => {
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
const schema = tools.get_active_incidents.inputSchema
|
|
|
|
// The schema is a Zod object that accepts empty object
|
|
expect(schema).toBeDefined()
|
|
expect((schema as any)._def.typeName).toBe('ZodObject')
|
|
})
|
|
|
|
describe('execute function', () => {
|
|
it('should return empty incidents when not on platform', async () => {
|
|
const common = await import('common')
|
|
vi.spyOn(common, 'IS_PLATFORM', 'get').mockReturnValue(false)
|
|
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
const result = await (tools.get_active_incidents.execute as any)({})
|
|
|
|
expect(result).toEqual({
|
|
incidents: [],
|
|
message: 'Incident checking is only available on Supabase platform.',
|
|
})
|
|
expect(mockFetch).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should fetch incidents from correct URL', async () => {
|
|
const common = await import('common')
|
|
vi.spyOn(common, 'IS_PLATFORM', 'get').mockReturnValue(true)
|
|
|
|
mockFetch.mockResolvedValue({
|
|
ok: true,
|
|
json: async () => [],
|
|
})
|
|
|
|
const tools = getIncidentTools({ baseUrl: 'https://example.com/dashboard' })
|
|
if (!tools.get_active_incidents.execute) throw new Error('execute is undefined')
|
|
await tools.get_active_incidents.execute({}, { toolCallId: 'test', messages: [] })
|
|
|
|
expect(mockFetch).toHaveBeenCalledWith(
|
|
'https://example.com/dashboard/api/incident-status',
|
|
{
|
|
signal: expect.any(AbortSignal),
|
|
}
|
|
)
|
|
})
|
|
|
|
it('should return message when no incidents', async () => {
|
|
const common = await import('common')
|
|
vi.spyOn(common, 'IS_PLATFORM', 'get').mockReturnValue(true)
|
|
|
|
mockFetch.mockResolvedValue({
|
|
ok: true,
|
|
json: async () => [],
|
|
})
|
|
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
const result = await (tools.get_active_incidents.execute as any)({})
|
|
|
|
expect(result).toEqual({
|
|
incidents: [],
|
|
message: expect.stringContaining('No active incidents'),
|
|
})
|
|
})
|
|
|
|
it('should return incident summaries when incidents exist', async () => {
|
|
const common = await import('common')
|
|
vi.spyOn(common, 'IS_PLATFORM', 'get').mockReturnValue(true)
|
|
|
|
const mockIncidents = [
|
|
{
|
|
name: 'Database slowness',
|
|
status: 'investigating',
|
|
impact: 'minor',
|
|
active_since: '2024-01-01T10:00:00Z',
|
|
extra_field: 'should be filtered',
|
|
},
|
|
]
|
|
|
|
mockFetch.mockResolvedValue({
|
|
ok: true,
|
|
json: async () => mockIncidents,
|
|
})
|
|
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
const result = await (tools.get_active_incidents.execute as any)({})
|
|
|
|
expect((result as any).incidents).toEqual([
|
|
{
|
|
name: 'Database slowness',
|
|
status: 'investigating',
|
|
impact: 'minor',
|
|
active_since: '2024-01-01T10:00:00Z',
|
|
},
|
|
])
|
|
expect((result as any).message).toContain('1 active incident')
|
|
expect((result as any).message).toContain('status.supabase.com')
|
|
})
|
|
|
|
it('should handle multiple incidents', async () => {
|
|
const common = await import('common')
|
|
vi.spyOn(common, 'IS_PLATFORM', 'get').mockReturnValue(true)
|
|
|
|
const mockIncidents = [
|
|
{
|
|
name: 'Database issue',
|
|
status: 'investigating',
|
|
impact: 'major',
|
|
active_since: '2024-01-01T10:00:00Z',
|
|
},
|
|
{
|
|
name: 'Storage issue',
|
|
status: 'identified',
|
|
impact: 'minor',
|
|
active_since: '2024-01-01T11:00:00Z',
|
|
},
|
|
]
|
|
|
|
mockFetch.mockResolvedValue({
|
|
ok: true,
|
|
json: async () => mockIncidents,
|
|
})
|
|
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
const result = await (tools.get_active_incidents.execute as any)({})
|
|
|
|
expect((result as any).incidents).toHaveLength(2)
|
|
expect((result as any).message).toContain('2 active incidents')
|
|
})
|
|
|
|
it('should handle fetch errors', async () => {
|
|
const common = await import('common')
|
|
vi.spyOn(common, 'IS_PLATFORM', 'get').mockReturnValue(true)
|
|
|
|
mockFetch.mockRejectedValue(new Error('Network error'))
|
|
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
const result = await (tools.get_active_incidents.execute as any)({})
|
|
|
|
expect(result).toEqual({
|
|
incidents: [],
|
|
error: 'Unable to check incident status at this time.',
|
|
})
|
|
})
|
|
|
|
it('should handle non-ok responses', async () => {
|
|
const common = await import('common')
|
|
vi.spyOn(common, 'IS_PLATFORM', 'get').mockReturnValue(true)
|
|
|
|
mockFetch.mockResolvedValue({
|
|
ok: false,
|
|
status: 500,
|
|
})
|
|
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
const result = await (tools.get_active_incidents.execute as any)({})
|
|
|
|
expect(result).toEqual({
|
|
incidents: [],
|
|
error: 'Unable to check incident status at this time.',
|
|
})
|
|
})
|
|
|
|
it('should use timeout signal', async () => {
|
|
const common = await import('common')
|
|
vi.spyOn(common, 'IS_PLATFORM', 'get').mockReturnValue(true)
|
|
|
|
mockFetch.mockResolvedValue({
|
|
ok: true,
|
|
json: async () => [],
|
|
})
|
|
|
|
const tools = getIncidentTools({ baseUrl: 'https://supabase.com/dashboard' })
|
|
if (!tools.get_active_incidents.execute) throw new Error('execute is undefined')
|
|
await tools.get_active_incidents.execute({}, { toolCallId: 'test', messages: [] })
|
|
|
|
const callArgs = mockFetch.mock.calls[0]
|
|
expect(callArgs[1].signal).toBeInstanceOf(AbortSignal)
|
|
})
|
|
})
|
|
})
|
|
})
|