Skip to content

fix(cli): comma-split network-bans and network-restrictions slice flags like pflag (CLI-1983) - #5975

Open
Coly010 wants to merge 4 commits into
developfrom
columferry/cli-1983--db-unban-ip-and-db-allow-cidr-dont-comma-split-like-gos
Open

fix(cli): comma-split network-bans and network-restrictions slice flags like pflag (CLI-1983)#5975
Coly010 wants to merge 4 commits into
developfrom
columferry/cli-1983--db-unban-ip-and-db-allow-cidr-dont-comma-split-like-gos

Conversation

@Coly010

@Coly010 Coly010 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What changed

Go declares both --db-unban-ip (network-bans remove, cmd/bans.go:48) and --db-allow-cidr (network-restrictions update, cmd/restrictions.go:40) with pflag's StringSliceVar, which CSV-splits every occurrence (--db-unban-ip=1.2.3.4,5.6.7.8 → two IPs) and appends across repeated flags. The TS legacy ports used plain Flag.string(...).pipe(Flag.atLeast(0)) with no splitting, so a comma-separated value stayed one token and failed validation (invalid IP address: 1.2.3.4,5.6.7.8 / failed to parse IP: 1.2.3.0/24,5.6.7.0/24) where the Go CLI accepts both values.

Both flags now route through the existing parity-reviewed legacyParseStringSliceFlag helper (the same encoding/csv-faithful pipeline already used by sso --domains, postgres-config --config, start, and status), using the established Flag.mapTryCatch pattern. This restores Go-identical semantics: comma-split per occurrence, append across repeats, CSV quoting for embedded commas, no trimming, and parse-time rejection of malformed CSV (which, as in Go, precedes the --experimental gate and handler validation).

Scope check: these are the only two StringSliceVar flags in either command family (--bypass-cidr-checks and --append are booleans, --project-ref is a plain string), so no sibling flags needed the same fix. Flag names, defaults, and help text are unchanged, so docs/go-cli-porting-status.md needs no update.

New coverage: flag-parse unit tests per command (comma split, quoted embedded comma, unset default, malformed-CSV rejection) plus integration scenarios that run the real flag pipeline into the handler and assert the resulting request bodies (comma form, repeated append, mixed, single-value regression, and an invalid post-split element failing before any API call). The new tests fail without the fix.

Review notes (deliberately left open)

  • The rendered flag-error wording for malformed CSV (Go's invalid argument "..." for "--db-unban-ip" flag: parse error ... wrapper) is asserted nowhere in the repo — a pre-existing gap shared with the sso/postgres-config slice-flag tests; this PR matches the existing pattern rather than solving it unilaterally.
  • In the pathological double-error case (-o bad plus malformed CSV in one invocation), TS surfaces the CSV parse error while Go's winner depends on argv order; both exit non-zero. No action taken.

Fixes CLI-1983
https://linear.app/supabase/issue/CLI-1983/db-unban-ip-and-db-allow-cidr-dont-comma-split-like-gos-stringslicevar

@Coly010

Coly010 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 09ab038073

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Coly010 Coly010 self-assigned this Jul 29, 2026
@Coly010
Coly010 marked this pull request as ready for review July 29, 2026 09:46
@Coly010
Coly010 requested a review from a team as a code owner July 29, 2026 09:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09ab038073

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/cli/src/legacy/commands/network-bans/remove/remove.command.ts Outdated
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@b75ed7276c474280e4589824757c2e1d8f570714

Preview package for commit b75ed72.

@Coly010

Coly010 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f46eb3b27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/cli/src/legacy/commands/network-bans/remove/remove.command.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4caf575ef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/cli/src/legacy/shared/legacy-string-slice-flag.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b75ed7276c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/cli/src/legacy/shared/legacy-string-slice-flag.ts

@kanadgupta kanadgupta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two asks before merge (but I'll approve so as to unblock this):

  1. The PR description is stale: the "Review notes" still say the rendered flag-error wording is asserted nowhere and that the PR "matches the existing pattern rather than solving it unilaterally" — the later commits (a4caf57, b75ed72) do solve it, assert it, and replace the plain Flag.mapTryCatch pattern with a new builder plus a renderer passthrough. Please update the body so it describes what is actually being merged.
  2. See the inline comment about migrating the seven remaining hand-rolled slice-flag sites to legacyStringSliceFlag in a follow-up.

The unresolved %q-vs-JSON.stringify quoting thread (U+2028/NBSP/DEL residual) is a reasonable accepted divergence given the Bun argv lossy-decode ceiling; fine to leave as-is with a human sign-off on that thread.

* including `\n`/`\r` escapes in multiline values (same precedent as
* `sso.format.ts`).
*/
export function legacyStringSliceFlag(name: string, description: string) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY follow-up: this builder now supersedes the hand-rolled Flag.mapTryCatch((raw) => legacyParseStringSliceFlag(raw), err => err.message) pattern still used by the seven other slice-flag sites (sso add/update x4, postgres-config update/delete, start, status). Those sites map only err.message, so their malformed-CSV stderr misses the pflag invalid argument %q for %q flag: ... framing this PR establishes as the Go-parity contract — and the parser rewrite in this file also silently changed their multiline/blank-line semantics (first-record-only, EOF on blank-only values). Keeping the migration out of this PR is the right call for diff size, but it might be worthwhile to file a follow-up to move those consumers onto legacyStringSliceFlag so the near-duplicate pattern (and the parity gap it carries) does not persist.


// Go declares `--db-unban-ip` with pflag's `StringSliceVar` (`cmd/bans.go:48`),
// which CSV-splits each occurrence and appends across repeats.
describe("legacy network-bans remove --db-unban-ip flag (pflag StringSlice parity)", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional diff-trim: these four tests (and the mirror file in network-restrictions/update) mostly re-cover behavior that already has stronger homes — comma split / quoted comma / malformed CSV live in the parser suite (legacy-string-slice-flag.unit.test.ts), the integration tests run the same .parse wiring via parseDbUnbanIp, and the experimental-gate integration test asserts the full rendered pflag diagnostic through the real command path. Per the repo testing pyramid (flag parsing coverage belongs in integration by default), the two *.command.unit.test.ts files could be dropped without losing any unique assertion. Fine to keep if you want the flag-level anchor, but they are ~140 lines of duplicate coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants