Skip to content

fix(cli): match Go path.Match character-class negation in legacy seed globbing#5856

Merged
Coly010 merged 2 commits into
developfrom
columferry/cli-1880-legacymatchpattern-match-go-pathmatch-character-class
Jul 10, 2026
Merged

fix(cli): match Go path.Match character-class negation in legacy seed globbing#5856
Coly010 merged 2 commits into
developfrom
columferry/cli-1880-legacymatchpattern-match-go-pathmatch-character-class

Conversation

@Coly010

@Coly010 Coly010 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Current Behavior

legacyMatchPattern (the glob matcher backing [db.seed].sql_paths and db reset --version) treated a leading ! inside a [...] bracket class the same as ^ — shell/fnmatch-style negation. Go's path.Match (which apps/cli-go's fs.Glob/afero.Glob actually use for this) only negates on ^; ! is an ordinary literal class member. So a pattern like [!a].sql matched b.sql in the TS port where the Go CLI would not, meaning db push --include-seed / db reset could read, hash, and execute seed SQL outside the set the user's Go-compatible config intended.

Verified directly against the real Go stdlib source ($GOROOT/src/path/match.go) available on this machine, and against apps/cli-go/pkg/config/config.go (fs.Glob) and apps/cli-go/internal/migration/repair/repair.go (GetMigrationFile / afero.Glob) — both go through the same path.Match grammar.

New Behavior

Rather than patching the bug in place, this fixes it by deleting the duplicate: apps/cli/src/legacy/shared/legacy-path-match.ts (legacyPathMatch) is already a byte-faithful, already-tested port of Go's path.Match — introduced earlier for the sibling db new/migration seed pipeline (legacy-seed.ts) — with correct ^-only negation, escapes, and malformed-pattern (ErrBadPattern) detection. legacyMatchPattern and its matchClass/match helpers are removed, and both call sites are rewired onto legacyPathMatch:

  • legacy-seed-ops.ts's own seed glob (globOne)
  • reset.handler.ts's --version migration-file glob (behavior-identical here — v is validated as digits-only before the glob ever runs, so no bracket syntax is reachable on this path)

A follow-up commit closes a related gap all four review-changes reviewers independently flagged: legacyGlobSeedFiles was discarding legacyPathMatch's badPattern signal, so a malformed pattern (e.g. an unterminated [ class) fell through to the generic no files matched pattern warning instead of Go's failed to glob files: syntax error in pattern (fs.Glob's up-front Match(pattern, "") validation). The sibling pipeline (legacy-seed.ts:resolveSeedFiles) already did this correctly — mirrored it here now that both pipelines share legacyPathMatch.

Behavior change worth calling out for release notes: any existing [db.seed].sql_paths config relying on [!x] as shell-style negation will now select a different (Go-correct) set of seed files with no error — e.g. [!0-9] now means "the literal characters !, 0-9", not "not a digit". Use [^x] for negation, matching Go/the real Go CLI. This is a correctness fix (the legacy shell's contract is strict Go parity), but it is a silent behavior change for anyone who had unknowingly depended on the old, non-Go-compatible negation.

Related Issue(s)

Fixes https://linear.app/supabase/issue/CLI-1880

Notes for reviewers

review-changes (architect/engineer/security/DX, run against the first commit) all returned APPROVE/SHIP IT. Judgement calls deliberately left open rather than expanded into this PR:

  • The two seed pipelines (legacy-seed-ops.ts and legacy-seed.ts) still duplicate the outer fs.Glob-style directory-walk/dedup logic (both now delegate the leaf matcher to legacyPathMatch, but the surrounding glob-resolution code is still two separate ports). Flagged by the architect reviewer as a good candidate for a follow-up consolidation, out of scope for this fix.
  • sql_paths' glob dialect (Go path.Match semantics, ^-only negation, no POSIX classes) isn't documented anywhere user-facing (packages/config/src/db.ts). Flagged by the DX reviewer as worth a docs follow-up, not blocking.

Coly010 added 2 commits July 10, 2026 10:16
… globbing (CLI-1880)

legacyMatchPattern (apps/cli/src/legacy/commands/db/shared/legacy-seed-ops.ts)
treated a leading `!` inside a `[...]` class the same as `^` (shell/fnmatch
negation), but Go's path.Match grammar only negates on `^` -- `!` is an
ordinary literal class member. A [db.seed].sql_paths entry like `[!a].sql`
therefore matched `b.sql` in TS where the Go CLI would not, letting
`db push --include-seed` / remote reset apply files outside the
Go-compatible seed set.

apps/cli/src/legacy/shared/legacy-path-match.ts already ports Go's
path.Match byte-for-byte (correct ^-only negation, escapes, malformed-
pattern detection) for the sibling db-new/migration seed pipeline. Delete
the duplicate, buggy matcher and rewire both legacyMatchPattern callers
(db/shared/legacy-seed-ops.ts's seed glob, db/reset/reset.handler.ts's
--version glob) onto the shared, already-tested legacyPathMatch instead of
patching the copy in place.
…CLI-1880 follow-up)

legacyGlobSeedFiles discarded legacyPathMatch's badPattern signal, so a
malformed [db.seed].sql_paths entry (e.g. an unterminated `[` class) fell
through to the generic "no files matched pattern" warning instead of Go's
"failed to glob files: syntax error in pattern" (fs.Glob's up-front
Match(pattern, "") validation). The sibling seed pipeline
(legacy-seed.ts:resolveSeedFiles) already handled this; mirror it here now
that both pipelines share legacyPathMatch. Flagged independently by all
four review-changes reviewers as a same-scope, cheap parity win.
@Coly010

Coly010 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 5ca135233e

ℹ️ 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 10, 2026
@Coly010 Coly010 marked this pull request as ready for review July 10, 2026 09:56
@Coly010 Coly010 requested a review from a team as a code owner July 10, 2026 09:56
@github-actions

Copy link
Copy Markdown
Contributor

Supabase CLI preview

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

Preview package for commit 5ca1352.

@Coly010 Coly010 added this pull request to the merge queue Jul 10, 2026
Merged via the queue into develop with commit 3fa4bb0 Jul 10, 2026
29 checks passed
@Coly010 Coly010 deleted the columferry/cli-1880-legacymatchpattern-match-go-pathmatch-character-class branch July 10, 2026 14:30
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