Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions apps/cli/docs/go-cli-porting-status.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/cli/src/legacy/commands/db/dump/dump.layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { commandRuntimeLayer } from "../../../../shared/runtime/command-runtime.
/**
* Runtime layer for `supabase db dump`.
*
* Mirrors `test db`'s composition (`commands/test/test.layers.ts`): the
* Mirrors `test db`'s composition (`legacy/shared/legacy-test-db.layers.ts`): the
* Management API stack is built lazily inside the resolver's `--linked` branch,
* so this layer only exposes the always-needed, auth-free services. The dump
* handler reaches the database through a pg_dump container (`LegacyDockerRun`),
Expand Down
99 changes: 69 additions & 30 deletions apps/cli/src/legacy/commands/db/test/SIDE_EFFECTS.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,94 @@
# `supabase db test`
# `supabase db test [path...]`

`db test` is a **hidden Go-parity alias** for `supabase test db` — Go itself
defines `db test`'s `RunE` first (`apps/cli-go/cmd/db.go:422-429`, `Hidden:
true`) and then has `test db` borrow it verbatim
(`apps/cli-go/cmd/test.go:19-20`: `RunE: dbTestCmd.RunE`). The native TS port
mirrors that shape: `test.command.ts` reuses `test db`'s flag config and
assembled handler verbatim (`../../../shared/legacy-test-db.command-handler.ts`'s
`legacyTestDbConfig` / `legacyRunTestDbCommand`) rather than re-implementing
pgTAP enable/disable and the `pg_prove` docker invocation a second time
(CLI-1962).

**Every side effect below is identical to `supabase test db`** — see
[`../../test/db/SIDE_EFFECTS.md`](../../test/db/SIDE_EFFECTS.md) for the full
inventory (docker bind-mount rules, network selection, TLS/DNS resolver
behavior, pooler-URL handling, etc.). This file exists per the "every legacy
command needs its own `SIDE_EFFECTS.md`" mandate and only calls out what is
genuinely different for this entry point.

## Files Read

| Path | Format | When |
| -------------------------- | ---------- | ------------------------------------------------- |
| `~/.supabase/access-token` | plain text | when `SUPABASE_ACCESS_TOKEN` unset and `--linked` |
| `[path] ...` (positional) | SQL (TAP) | test files specified as positional arguments |
Identical to `test db`. See
[`../../test/db/SIDE_EFFECTS.md`](../../test/db/SIDE_EFFECTS.md#files-read).

## Files Written

| Path | Format | When |
| ---- | ------ | ---- |
| — | — | — |

## API Routes
## Database

| Method | Path | Auth | Request body | Response (used fields) |
| ------ | ---- | ---- | ------------ | ---------------------- |
| — | — | — | — | — |
Identical to `test db`. See
[`../../test/db/SIDE_EFFECTS.md`](../../test/db/SIDE_EFFECTS.md#database).

## Environment Variables
## Docker

| Variable | Purpose | Required? |
| ----------------------- | --------------------------------------- | ------------------------------------------------------- |
| `SUPABASE_ACCESS_TOKEN` | auth token for `--linked` mode | no (falls back to keyring → `~/.supabase/access-token`) |
| `DB_PASSWORD` | password for direct database connection | no |
Identical to `test db`. See
[`../../test/db/SIDE_EFFECTS.md`](../../test/db/SIDE_EFFECTS.md#docker).

## Exit Codes
## API Routes (`--linked` only)

| Code | Condition |
| ---- | --------------------------- |
| `0` | all tests pass |
| `1` | database connection failure |
| `1` | one or more tests fail |
Identical to `test db`. See
[`../../test/db/SIDE_EFFECTS.md`](../../test/db/SIDE_EFFECTS.md#api-routes---linked-only).

## Output
## Environment Variables

### `--output-format text` (Go CLI compatible)
Identical to `test db`. See
[`../../test/db/SIDE_EFFECTS.md`](../../test/db/SIDE_EFFECTS.md#environment-variables).

Prints pgTAP test output (TAP format) to stdout.
## Exit Codes

Identical to `test db`. See
[`../../test/db/SIDE_EFFECTS.md`](../../test/db/SIDE_EFFECTS.md#exit-codes).

### `--output-format json`
## Telemetry Events Fired

Not applicable.
| Event | When | Notable properties / groups |
| ---------------------- | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------- |
| `cli_command_executed` | post-run, success or failure (via wrapper) | `exit_code`, `duration_ms`, `flags`, **`command: "db test"`** — NOT `"test db"`, despite the identical handler |

### `--output-format stream-json`
The recorded `command` property is the only observable difference between
the two entry points. Go's `cli_command_executed` telemetry records
`strings.TrimSpace(cmd.CommandPath())` (`apps/cli-go/cmd/root_analytics.go:33`),
which differs between the two `cobra.Command` registrations even though
`RunE` is the literal same function reference. The TS port matches this via
`legacyTestDbRuntimeLayer(["db", "test"])` in `test.command.ts` (vs
`legacyTestDbRuntimeLayer(["test", "db"])` for `test db`'s own command file) —
see `../../../shared/legacy-test-db.layers.ts`'s doc comment.

## Output

Not applicable.
Identical to `test db`. See
[`../../test/db/SIDE_EFFECTS.md`](../../test/db/SIDE_EFFECTS.md#output).

## Notes

- Accepts optional path arguments to specify test files; runs all tests if none given.
- `--db-url`, `--linked`, and `--local` (default true) are mutually exclusive.
- This is a hidden command in the Go CLI (`db test`, not the top-level `test` command).
- Native TypeScript port (Phase 1+); no Go proxy (CLI-1962). Hidden command —
registered with `.pipe(Command.withHidden)` in `../db.command.ts`, matching
cobra's `Hidden: true` on `dbTestCmd`.
- `--local` defaults to `true` on both `db test` and `test db`
(`apps/cli-go/cmd/db.go:739`, `apps/cli-go/cmd/test.go:43`), matching cobra's
`MarkFlagsMutuallyExclusive("db-url", "linked", "local")` group — bare
`supabase db test` always targets the local stack. This resolves the
proxy-only `--local` default-modelling caveat that existed while this
command still forwarded to the Go binary (the previous proxy's
`if (flags.local) args.push("--local")` never actually forwarded the
default, since Effect CLI's own `Flag.boolean` default is `false`; now that
the flag drives `resolveLegacyDbTargetFlags`'s presence-based selection
directly — same mechanism `test db` already used — Go's true default is
reflected exactly, with no proxy-only quirk to carry over).
- Shares every intentional divergence documented on `test db`
(pg_prove image pin, `pg_extension`-based "already exists" detection instead
of pgx's `OnNotice`, `--network-id` global-flag override, etc.).
60 changes: 33 additions & 27 deletions apps/cli/src/legacy/commands/db/test/test.command.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import { Argument, Command, Flag } from "effect/unstable/cli";
import type * as CliCommand from "effect/unstable/cli/Command";
import { legacyDbTest } from "./test.handler.ts";
import { Command } from "effect/unstable/cli";

const config = {
dbUrl: Flag.string("db-url").pipe(
Flag.withDescription(
"Tests the database specified by the connection string (must be percent-encoded).",
),
Flag.optional,
),
linked: Flag.boolean("linked").pipe(
Flag.withDescription("Runs pgTAP tests on the linked project."),
),
local: Flag.boolean("local").pipe(
Flag.withDescription("Runs pgTAP tests on the local database."),
),
paths: Argument.string("path").pipe(
Argument.withDescription("Paths to test files or directories."),
Argument.variadic(),
),
} as const;
import {
LEGACY_TEST_DB_DESCRIPTION,
LEGACY_TEST_DB_SHORT,
legacyRunTestDbCommand,
legacyTestDbConfig,
} from "../../../shared/legacy-test-db.command-handler.ts";
import { legacyTestDbRuntimeLayer } from "../../../shared/legacy-test-db.layers.ts";

export type LegacyDbTestFlags = CliCommand.Command.Config.Infer<typeof config>;

export const legacyDbTestCommand = Command.make("test", config).pipe(
Command.withDescription("Tests local database with pgTAP."),
Command.withShortDescription("Tests local database with pgTAP"),
Command.withHandler((flags) => legacyDbTest(flags)),
/**
* `db test` is a hidden Go-parity alias for `test db` (registered hidden by
* the parent, `../db.command.ts`'s `legacyDbTestCommand.pipe(Command.withHidden)`,
* matching cobra's `Hidden: true` on `dbTestCmd`, `apps/cli-go/cmd/db.go:423`).
*
* Go itself defines `db test`'s `RunE` first (`cmd/db.go:422-429`, calling
* `test.Run` directly) and then has `test db` borrow it verbatim
* (`cmd/test.go:19-20`: `RunE: dbTestCmd.RunE`) — one implementation, two
* cobra.Command registrations with identical flags and Short text. The native
* TS port mirrors that: both this file and `../../test/db/db.command.ts`
* import the shared config/handler/runtime-layer from
* `legacy/shared/legacy-test-db.*` instead of either command owning the
* implementation directly — `legacy/commands/<family>/` files may not import
* another family's internals (`code-structure.unit.test.ts`), so the
* implementation lives outside `legacy/commands/` entirely (CLI-1962).
*/
export const legacyDbTestCommand = Command.make("test", legacyTestDbConfig).pipe(
Command.withDescription(LEGACY_TEST_DB_DESCRIPTION),
Command.withShortDescription(LEGACY_TEST_DB_SHORT),
Command.withHandler(legacyRunTestDbCommand),
// `["db", "test"]`, not `["test", "db"]`: Go's `cli_command_executed`
// telemetry records the actual invoked `cmd.CommandPath()`
// (`cmd/root_analytics.go:33`), which differs by entry point even though
// `RunE` is identical — see `legacyTestDbRuntimeLayer`'s doc comment.
Command.provide(legacyTestDbRuntimeLayer(["db", "test"])),
);
15 changes: 0 additions & 15 deletions apps/cli/src/legacy/commands/db/test/test.handler.ts

This file was deleted.

Loading
Loading