mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem
Following the Compute "copy as AI prompt" snippet word for word fails
against the current CLI (3.2.0):
1. `size = "2gb-1vcpu"` → `UnknownComputeSizeError`. config.toml takes
`2gb` / `4gb`; the CLI maps those to the API's `2gb-1vcpu` itself
(`apiSizeFor` in `apps/cli/src/shared/compute/compute-runtimes.ts`).
2. Nothing says to enable `[experimental] compute = true` /
`SUPABASE_EXPERIMENTAL_COMPUTE=1`, so the CLI fails with `Unknown
subcommand "compute"`. SupaSquad testers have hit the same error.
3. For the Dockerfile runtime the prompt read "a Dockerfile entrypoint
(Dockerfile)" and never mentioned the port.
5. Every prompt asked for an HTTP "Hello, world!" server, including
private instances. Private exposure has no inbound network access: a
private instance is a background worker (for example, a loop polling a
pgmq queue) and doesn't listen on any port. Deploying an HTTP server as
private is what produced the `listen tcp :8080: bind: address already in
use` error I hit. The call snippets also sent an `Authorization` header,
but public instances don't verify API keys.
4. The instance CLI commands suggest `supabase compute pull` (doesn't
exist) and `supabase compute logs --follow` (deprecated; there's no
`--follow` on the replacement).
I hit these deploying a Dockerfile hello-world from the snippet.
## Solution
- Write the CLI size (`2gb`) into the config.toml block. The API size
still drives the `# 2 GB · 1 vCPU` comment, and the deploy dialog is
unchanged.
- The prompt says to set `compute = true` under `[experimental]`, and to
link the project before `push`. The CLI snippet exports
`SUPABASE_EXPERIMENTAL_COMPUTE=1`, and the config.toml snippet has a
comment about it.
- The prompt branches on access. Public: serve plain HTTP on `$PORT`
(defaults to 8080) and add your own auth if needed. Private: run a
background worker and don't start an HTTP server. Dockerfile prompts say
"a Dockerfile" instead of the garbled entrypoint.
- Overview tab: "Listening port" shows `$PORT → 8080` for public and
"None (background worker)" for private, and "How to call" only renders
for public instances. The JS and Python call snippets drop the
`Authorization` header.
- The deploy dialog's access description explains both modes instead of
mentioning a publishable key.
- Drop `pull` and switch logs to `supabase logs --remote --service
compute --resource <name>` in both the overview and logs tabs.
Tests cover each of these in `computeInstanceSnippets.test.ts`.
Not in this PR: Studio's `RUNTIMES.node.entrypoint` is `node index.js`,
while the CLI scaffolds `index.mjs` exporting `{ fetch }` (same for deno
`main.ts`). The node/deno prompt may need a similar pass.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
3.3 KiB
TypeScript
90 lines
3.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
buildComputeInstanceCliCommands,
|
|
buildComputeInstanceSnippets,
|
|
computeLogsCommand,
|
|
EXAMPLE_COMPUTE_INSTANCE,
|
|
} from './computeInstanceSnippets'
|
|
|
|
const input = (overrides: Partial<Parameters<typeof buildComputeInstanceSnippets>[0]> = {}) => ({
|
|
...EXAMPLE_COMPUTE_INSTANCE,
|
|
endpoint: 'abcdefgh.supabase.co',
|
|
...overrides,
|
|
})
|
|
|
|
describe('buildComputeInstanceSnippets', () => {
|
|
it('passes private exposure to the CLI and config', () => {
|
|
const { cli, configToml } = buildComputeInstanceSnippets(input({ access: 'private' }))
|
|
|
|
expect(cli).toContain('--exposure private')
|
|
expect(configToml).toContain('exposure = "private"')
|
|
})
|
|
|
|
it('writes the CLI size name to config.toml, not the API one', () => {
|
|
const { configToml, aiPrompt } = buildComputeInstanceSnippets(input({ size: '4gb-2vcpu' }))
|
|
|
|
expect(configToml).toContain('size = "4gb" # 4 GB · 2 vCPU')
|
|
expect(aiPrompt).toContain('size = "4gb"')
|
|
})
|
|
|
|
it('tells the reader to enable the experimental compute commands', () => {
|
|
const { aiPrompt, cli, configToml } = buildComputeInstanceSnippets(input())
|
|
|
|
expect(aiPrompt).toContain('`compute = true` under the `[experimental]` table')
|
|
expect(configToml).toContain('compute = true under [experimental]')
|
|
expect(cli).toContain('export SUPABASE_EXPERIMENTAL_COMPUTE=1')
|
|
})
|
|
|
|
it('points Dockerfile apps at $PORT instead of a garbled entrypoint', () => {
|
|
const { aiPrompt } = buildComputeInstanceSnippets(input({ runtime: 'dockerfile' }))
|
|
|
|
expect(aiPrompt).toContain('serves plain HTTP on the port in $PORT')
|
|
expect(aiPrompt).not.toContain('entrypoint (Dockerfile)')
|
|
})
|
|
|
|
it('asks for a background worker, not an HTTP server, for private instances', () => {
|
|
const { aiPrompt } = buildComputeInstanceSnippets(input({ access: 'private' }))
|
|
|
|
expect(aiPrompt).toContain('background worker')
|
|
expect(aiPrompt).not.toContain('serves plain HTTP')
|
|
})
|
|
|
|
it('calls public instances without an API key', () => {
|
|
const { javascript, python } = buildComputeInstanceSnippets(input())
|
|
|
|
expect(javascript).not.toContain('Authorization')
|
|
expect(python).not.toContain('Authorization')
|
|
})
|
|
})
|
|
|
|
describe('buildComputeInstanceCliCommands', () => {
|
|
it('targets the requested instance in every management command', () => {
|
|
const commands = buildComputeInstanceCliCommands('embed')
|
|
|
|
expect(commands).toHaveLength(3)
|
|
expect(commands.every(({ command }) => command.includes('embed'))).toBe(true)
|
|
expect(commands.some(({ command }) => command.includes(' pull '))).toBe(false)
|
|
expect(commands).toContainEqual({
|
|
comment: 'View logs',
|
|
command: 'supabase logs --remote --service compute --resource embed --since 24h',
|
|
})
|
|
})
|
|
|
|
it('passes the log kind when given one', () => {
|
|
expect(computeLogsCommand('embed', 'app')).toBe(
|
|
'supabase logs --remote --service compute --resource embed --since 24h --kind app'
|
|
)
|
|
})
|
|
|
|
it('sets exposure on compute new so a plain push keeps it', () => {
|
|
const { cli, aiPrompt } = buildComputeInstanceSnippets(input({ access: 'private' }))
|
|
|
|
expect(cli).toContain(
|
|
'new my-instance --runtime node --size 2gb --exposure private --instances 1'
|
|
)
|
|
expect(cli).toMatch(/push my-instance$/m)
|
|
expect(aiPrompt).toContain('push my-instance --yes')
|
|
})
|
|
})
|