From 4274815c6c5bb97f42a48ef376c8f1604eea316e Mon Sep 17 00:00:00 2001 From: Jim Wordelman Date: Wed, 19 Aug 2026 08:51:07 -0700 Subject: [PATCH] Fix E2BIG when runDoltSQL passes large schema SQL as a single argv (#5846) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test(dolt): red — Fix: runDoltSQL passes 134KB of schema SQL in one argv, past Linux MAX_ARG_STRLEN (E2BIG) - 10 dolt tests red (refs be-go6d) * feat(dolt): green — Fix: runDoltSQL passes 134KB of schema SQL in one argv, past Linux MAX_ARG_STRLEN (E2BIG) - 10 dolt tests red (refs be-go6d) * test(dolt): wire TestRunDoltSQLHandlesLargeScript into the default lane (refs be-wq49) Reviewer follow-up on be-go6d (runDoltSQL argv E2BIG fix): the regression test proving it lived in git_remote_test.go under //go:build integration, gated by skipIfNoDolt — which checks for the shared containerized Dolt SQL server (testServerPort). That test never touches the server, only the local dolt CLI, so the gate was wrong and the test only ever ran on the non-blocking nightly cron, never in the PR-gating/merge-gating lane. Extract TestRunDoltSQLHandlesLargeScript + its runDoltSQL helper into a new file, dolt_sql_large_script_test.go, with no tag and gated on testutil.RequireDoltBinary(t) instead. Remove the originals from git_remote_test.go (kept as a same-package call site — setupGitRemote still calls runDoltSQL) to avoid duplicate symbols when both files compile together under -tags=integration. No production code changes: runDoltSQL's fix was already proven correct in be-go6d's own tdd_red/tdd_green (cc407e186/fceb1c69a). This closes the CI-wiring gap only. Verified: test absent from the default lane before (mechanically-verified red state via a targeted -run + -v check), present and passing after; default and integration-tagged compiles both stay duplicate-symbol free; full ./internal/storage/dolt/... default-lane suite still green with no regression. * test(feat): red — Fix: runDoltSQL passes 134KB of schema SQL in one argv, past Linux MAX_ARG_STRLEN (E2BIG) - 10 dolt tests red (refs be-wq49) TestRunDoltSQLHandlesLargeScript now calls testutil.RequireDoltCLIOnly, which does not exist yet. This fails the build (RED), proving the test is not currently gated correctly. Root cause: RequireDoltBinary conflates "needs containerized dolt-sql-server" with "needs local dolt CLI only" by honoring BEADS_TEST_SKIP=dolt before checking for the CLI binary. That env var is unconditionally set by scripts/ci/lib/test-env.sh's beads_test_env_enter(), so this test silently SKIPs instead of running PASS/FAIL in the required pr-core-wrapper CI job — even though it has no containerized-server dependency. * feat: green — Fix: runDoltSQL passes 134KB of schema SQL in one argv, past Linux MAX_ARG_STRLEN (E2BIG) - 10 dolt tests red (refs be-wq49) Add RequireDoltCLIOnly, which checks for the dolt CLI binary but does NOT honor BEADS_TEST_SKIP=dolt. Extract the shared binary-presence check into requireDoltBinaryPresent so RequireDoltBinary's existing behavior (skip on BEADS_TEST_SKIP=dolt, fail under GITHUB_ACTIONS if missing) is unchanged for its other 20 call sites. TestRunDoltSQLHandlesLargeScript now gates on RequireDoltCLIOnly instead of RequireDoltBinary, so it actually runs PASS/FAIL in the required pr-core-wrapper CI job instead of silently SKIPping — it has no dependency on the shared containerized dolt-sql-server that BEADS_TEST_SKIP=dolt exists to exclude. Verified under bash (matching scripts/ci/pr-core.sh's real shebang and trap semantics — sourcing test-env.sh into an interactive zsh session instead triggers zsh's function-local EXIT-trap behavior, which tears the hermetic env down early; not a bug in the script): source .buildflags && source scripts/ci/lib/test-env.sh && \ beads_test_env_enter && \ go test -run ^TestRunDoltSQLHandlesLargeScript$ -v ./internal/storage/dolt/... --- PASS: TestRunDoltSQLHandlesLargeScript (1.03s) * release-gate: PASS record for runDoltSQL E2BIG fix (deploy/be-al8j-gate) --- .../dolt/dolt_sql_large_script_test.go | 56 ++++++++ internal/storage/dolt/git_remote_test.go | 13 +- internal/testutil/testdoltcommon.go | 28 +++- .../be-al8j-dolt-sql-argv-e2big-gate.md | 134 ++++++++++++++++++ 4 files changed, 218 insertions(+), 13 deletions(-) create mode 100644 internal/storage/dolt/dolt_sql_large_script_test.go create mode 100644 release-gates/be-al8j-dolt-sql-argv-e2big-gate.md diff --git a/internal/storage/dolt/dolt_sql_large_script_test.go b/internal/storage/dolt/dolt_sql_large_script_test.go new file mode 100644 index 000000000..27736b0d0 --- /dev/null +++ b/internal/storage/dolt/dolt_sql_large_script_test.go @@ -0,0 +1,56 @@ +package dolt + +import ( + "os/exec" + "strings" + "testing" + + "github.com/steveyegge/beads/internal/storage/schema" + "github.com/steveyegge/beads/internal/testutil" +) + +// runDoltSQL executes SQL via `dolt sql` CLI in the given directory. The +// script is piped over stdin rather than passed as a `-q` argv element: +// schema.AllMigrationsSQL() is ~134KB, past Linux's per-argv MAX_ARG_STRLEN +// (131072 bytes), which fails execve with E2BIG when passed as an argument. +func runDoltSQL(t *testing.T, dir, query string) { + t.Helper() + cmd := exec.Command("dolt", "sql") + cmd.Dir = dir + cmd.Stdin = strings.NewReader(query) + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("dolt sql failed in %s: %v\nQuery: %.200s...\nOutput: %s", dir, err, query, output) + } +} + +// TestRunDoltSQLHandlesLargeScript proves runDoltSQL can execute a SQL +// script larger than Linux's per-argv MAX_ARG_STRLEN (128KiB = 131072 +// bytes). Passing the script as a single argv element (`dolt sql -q +//