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 +//