mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem In self-hosted and local Studio, `FileSystemFunctionsArtifactStore` reads the folder set by `EDGE_FUNCTIONS_MANAGEMENT_FOLDER` with `readdir`. When that folder does not exist yet (for example, a fresh project before any function is created), `readdir` throws `ENOENT`, the `/api/v1/projects/[ref]/functions` route returns a 500, and the Edge Functions page shows "Failed to retrieve edge functions" instead of its empty state. ## Solution - Add a private `readFunctionsFolder()` helper that returns an empty list when the folder is missing (`ENOENT`) and rethrows every other error. - `getFunctions()` now returns `[]` and `getFunctionBySlug()` returns `undefined` for a missing folder. - Add `fileSystemStore.test.ts`, which uses real temp folders to cover the missing folder, a non-ENOENT error (path is a file), and the normal listing (skips `main` and folders without an `index` entrypoint). No change to the hosted platform path. ## Review instructions This only affects self-hosted Studio, so the Vercel preview cannot show it. Check it with: 1. `cd apps/studio && pnpm exec vitest run lib/api/self-hosted/functions/`: all tests pass. 2. Optional, locally: run self-hosted Studio with `EDGE_FUNCTIONS_MANAGEMENT_FOLDER` pointing to a folder that does not exist, open Edge Functions, and see the empty state instead of a 500. Checks run: the Vitest command above, `pnpm turbo run typecheck --filter='...[origin/master]'`, ESLint and Prettier on the changed files. ## Checklist - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] 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) [FE-4923](https://linear.app/supabase/issue/FE-4923/fix-studio-edge-functions-500-error-when-local-functions-folder-does) --------- Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com> Co-authored-by: Ali Waseem <waseema393@gmail.com>
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import * as util from '../util'
|
|
import * as fileSystemStore from './fileSystemStore'
|
|
import { getFunctionsArtifactStore } from './index'
|
|
|
|
vi.mock('../util', () => ({
|
|
assertSelfHosted: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('./fileSystemStore', () => ({
|
|
FileSystemFunctionsArtifactStore: vi.fn(),
|
|
}))
|
|
|
|
describe('api/self-hosted/functions/index', () => {
|
|
let originalEdgeFunctionsFolder: string | undefined
|
|
|
|
beforeEach(() => {
|
|
originalEdgeFunctionsFolder = process.env.EDGE_FUNCTIONS_MANAGEMENT_FOLDER
|
|
vi.resetAllMocks()
|
|
})
|
|
|
|
afterEach(() => {
|
|
if (originalEdgeFunctionsFolder !== undefined) {
|
|
process.env.EDGE_FUNCTIONS_MANAGEMENT_FOLDER = originalEdgeFunctionsFolder
|
|
} else {
|
|
delete process.env.EDGE_FUNCTIONS_MANAGEMENT_FOLDER
|
|
}
|
|
})
|
|
|
|
describe('getFunctionsArtifactStore', () => {
|
|
it('should call assertSelfHosted', () => {
|
|
process.env.EDGE_FUNCTIONS_MANAGEMENT_FOLDER = '/tmp/functions'
|
|
|
|
getFunctionsArtifactStore()
|
|
|
|
expect(util.assertSelfHosted).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should create a store without a folder if EDGE_FUNCTIONS_MANAGEMENT_FOLDER is not set', () => {
|
|
delete process.env.EDGE_FUNCTIONS_MANAGEMENT_FOLDER
|
|
|
|
getFunctionsArtifactStore()
|
|
|
|
expect(fileSystemStore.FileSystemFunctionsArtifactStore).toHaveBeenCalledWith(undefined)
|
|
})
|
|
|
|
it('should create FileSystemFunctionsArtifactStore with correct path', () => {
|
|
process.env.EDGE_FUNCTIONS_MANAGEMENT_FOLDER = '/var/lib/functions'
|
|
|
|
getFunctionsArtifactStore()
|
|
|
|
expect(fileSystemStore.FileSystemFunctionsArtifactStore).toHaveBeenCalledWith(
|
|
'/var/lib/functions'
|
|
)
|
|
})
|
|
|
|
it('should return FileSystemFunctionsArtifactStore instance', () => {
|
|
const mockInstance = {
|
|
folderPath: '/tmp/test',
|
|
getFunctions: vi.fn(),
|
|
getFunctionBySlug: vi.fn(),
|
|
getFileEntriesBySlug: vi.fn(),
|
|
}
|
|
vi.mocked(fileSystemStore.FileSystemFunctionsArtifactStore).mockImplementation(function () {
|
|
return mockInstance as any
|
|
})
|
|
process.env.EDGE_FUNCTIONS_MANAGEMENT_FOLDER = '/tmp/test'
|
|
|
|
const result = getFunctionsArtifactStore()
|
|
|
|
expect(result).toBe(mockInstance)
|
|
})
|
|
})
|
|
})
|