Skip to content

feat: enforce single-statement contract in translator.Parse - #31

Merged
h3n4l merged 3 commits into
mainfrom
byt-9950-omni-bump
Jul 30, 2026
Merged

feat: enforce single-statement contract in translator.Parse#31
h3n4l merged 3 commits into
mainfrom
byt-9950-omni-bump

Conversation

@h3n4l

@h3n4l h3n4l commented Jul 30, 2026

Copy link
Copy Markdown
Member

What

Why

BYT-9950: Bytebase migrations silently skipped MongoDB statements that failed to parse. The fix chain makes every layer strict — omni's Parse never drops statements, and gomongo never silently ignores trailing input. Bytebase always passes exactly one split statement per Execute call, so this contract matches the real caller.

Arithmetic expressions such as expireAfterSeconds: 90 * 24 * 60 * 60 remain unsupported by design (folding was reverted in omni#396): they now surface as a ParseError instead of being silently skipped.

Testing

  • New internal/translator unit tests pin the single-statement contract (valid single, comment-only no-op, invalid rejected, valid+invalid rejected, two-valid rejected) and that the BYT-9950 arithmetic statement returns a ParseError.
  • New TestCreateIndexArithmeticTTL container test asserts Execute returns a ParseError for the BYT-9950 statement on mongo 4.4, mongo 8.0, and DocumentDB.
  • Full suite: go test ./... green locally (containers included); golangci-lint clean.

🤖 Generated with Claude Code

h3n4l and others added 2 commits July 29, 2026 18:23
With omni's mongo.Parse now strict (any statement parse error fails the
whole input), translator.Parse no longer silently ignores content after
the first statement: extra statements are rejected with a ParseError
instead of being dropped. Comment-only input remains a no-op.

Also pins the BYT-9950 statement: createIndex with a constant arithmetic
expireAfterSeconds (90 * 24 * 60 * 60) folds to an int32 TTL and creates
the index end to end.

Requires bumping github.com/bytebase/omni to a version with strict
mongo.Parse (folding landed in omni#393); the bump lands in this PR once
the omni change merges.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Picks up bytebase/omni#395 (Parse fails on any statement parse error)
and bytebase/omni#393 (constant arithmetic folding), which the new
single-statement contract and TTL-index tests rely on.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 30, 2026 02:21
@h3n4l
h3n4l requested a review from a team as a code owner July 30, 2026 02:21

Copilot AI 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.

Pull request overview

This PR makes internal/translator.Parse strict about consuming exactly one executable MongoDB shell statement, preventing trailing statements from being silently ignored and aligning gomongo’s behavior with Bytebase’s “one statement per Execute” contract. It also updates the bytebase/omni dependency to pick up stricter parsing behavior and constant-expression folding needed for TTL arithmetic expressions.

Changes:

  • Enforced a single-executable-statement contract in translator.Parse, returning a ParseError when multiple executable statements are present.
  • Added unit tests to pin the single-statement/no-op behavior and to validate TTL arithmetic folding in translation.
  • Added an end-to-end container test asserting expireAfterSeconds arithmetic is folded to the expected TTL value, and bumped github.com/bytebase/omni to the required version.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/translator/translator.go Enforces “exactly one executable statement” semantics and errors on multiple statements.
internal/translator/translator_test.go Adds unit tests covering strict single-statement parsing and TTL arithmetic folding.
admin_test.go Adds container-level integration test verifying TTL arithmetic folding is preserved end-to-end.
go.mod Bumps github.com/bytebase/omni to a newer pseudo-version containing the required parsing/folding changes.
go.sum Updates checksums for the github.com/bytebase/omni dependency bump.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

omni#393 (constant arithmetic folding) was reverted in omni#396:
arithmetic expressions in mongosh statements are intentionally
unsupported. The BYT-9950 tests now assert that translator.Parse and
Execute return a ParseError instead of silently skipping the statement.
Bumps omni past the revert.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@h3n4l
h3n4l enabled auto-merge (squash) July 30, 2026 03:29
@h3n4l
h3n4l merged commit 67ba6e2 into main Jul 30, 2026
2 checks passed
@h3n4l
h3n4l deleted the byt-9950-omni-bump branch July 30, 2026 03:33
h3n4l added a commit to bytebase/bytebase that referenced this pull request Jul 30, 2026
Picks up bytebase/gomongo#31: translator.Parse rejects multi-statement
input instead of silently executing only the first statement, and its
omni pin aligns with this repo's post-revert version.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
rebelice pushed a commit to bytebase/bytebase that referenced this pull request Jul 30, 2026
Picks up bytebase/gomongo#31: translator.Parse rejects multi-statement
input instead of silently executing only the first statement, and its
omni pin aligns with this repo's post-revert version.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

3 participants