ronantakizawa/codereview-bench huggingface dataset:
Repository: dolthub/dolt
File: go/store/nbs/archive_writer_test.go (Go)

Code before:
	"os"
	"testing"

	"github.com/stretchr/testify/require"

	"github.com/dolthub/dolt/go/store/chunks"
)

func CountFilesInDir(t *testing.T, path string) int {
	cnt := 0
	err := fs.WalkDir(os.DirFS(path), ".", func(path string, _ fs.DirEntry, err error) error {
		if err != nil {
			return err
		}
		cnt += 1
		return nil
	})
	require.NoError(t, err)
	return cnt
}

func TestArchiveStreamWriterRemove(t *testing.T) {
	t.Run("RemoveOnFinishedWriterRemovesFile", func(t *testing.T) {
		dir := t.TempDir()
		require.Equal(t, 1, CountFilesInDir(t, dir))
		asw, err := NewArchiveStreamWriter(dir)
		require.NoError(t, err)
		contents := make([]byte, 1024)
		_, err = io.ReadFull(rand.Reader, contents)
		require.NoError(t, err)
		_, err = asw.AddChunk(ChunkToCompressedChunk(chunks.NewChunk(contents)))
		require.NoError(t, err)
		_, _, err = asw.Finish()
		require.NoError(t, err)
		rdr, err := asw.Reader()
		require.NoError(t, err)
		require.NoError(t, rdr.Close())
		err = asw.Remove()
		require.NoError(t, err)
		require.Equal(t, 1, CountFilesInDir(t, dir))
	})
	t.Run("CancelOnWriterRemovesFile", func(t *testing.T) {
		dir := t.TempDir()
		require.Equal(t, 1, CountFilesInDir(t, dir))
		asw, err := NewArchiveStreamWriter(dir)
		require.NoError(t, err)
		contents := make([]byte, 1024)
		_, err = io.ReadFull(rand.Reader, contents)
		require.NoError(t, err)
		_, err = asw.AddChunk(ChunkToCompressedChunk(chunks.NewChunk(contents)))
		require.NoError(t, err)

Review comment (suggestion):
```suggestion
		// Empty Dir -> 1 for "." found by WalkDir.
		require.Equal(t, 1, CountFilesInDir(t, dir))
```

Code after:
	"os"
	"testing"

	"github.com/stretchr/testify/require"

	"github.com/dolthub/dolt/go/store/chunks"
)

func CountFilesInDir(t *testing.T, path string) int {
	cnt := 0
	err := fs.WalkDir(os.DirFS(path), ".", func(path string, _ fs.DirEntry, err error) error {
		if err != nil {
			return err
		}
		cnt += 1
		return nil
	})
	require.NoError(t, err)
	return cnt
}

func TestArchiveStreamWriterRemove(t *testing.T) {
	t.Run("RemoveOnFinishedWriterRemovesFile", func(t *testing.T) {
		dir := t.TempDir()
		// Empty Dir -> 1 for "." found by WalkDir.
		require.Equal(t, 1, CountFilesInDir(t, dir))
		asw, err := NewArchiveStreamWriter(dir)
		require.NoError(t, err)
		contents := make([]byte, 1024)
		_, err = io.ReadFull(rand.Reader, contents)
		require.NoError(t, err)
		_, err = asw.AddChunk(ChunkToCompressedChunk(chunks.NewChunk(contents)))
		require.NoError(t, err)
		_, _, err = asw.Finish()
		require.NoError(t, err)
		rdr, err := asw.Reader()
		require.NoError(t, err)
		require.NoError(t, rdr.Close())
		err = asw.Remove()
		require.NoError(t, err)
		require.Equal(t, 1, CountFilesInDir(t, dir))
	})
	t.Run("CancelOnWriterRemovesFile", func(t *testing.T) {
		dir := t.TempDir()
		require.Equal(t, 1, CountFilesInDir(t, dir))
		asw, err := NewArchiveStreamWriter(dir)
		require.NoError(t, err)
		contents := make([]byte, 1024)
		_, err = io.ReadFull(rand.Reader, contents)
		require.NoError(t, err)
		_, err = asw.AddChunk(ChunkToCompressedChunk(chunks.NewChunk(contents)))
Repository: dolthub/dolt
File: integration-tests/go-sql-server-driver/push_cleanup_test.go (Go)

Code before:
		Args:        []string{"--port", `{{get_port "server_one"}}`},
		DynamicPort: "server_one",
	}, &ports)
	require.NotNil(t, server)
	db, err := server.DB(driver.Connection{User: "root"})
	require.NoError(t, err)
	t.Cleanup(func() {
		db.Close()
	})
	conn, err := db.Conn(t.Context())
	require.NoError(t, err)
	_, err = conn.ExecContext(t.Context(), "USE db_one")
	require.NoError(t, err)
	_, err = conn.ExecContext(t.Context(), "CALL dolt_push('origin', 'main')")
	require.NoError(t, err)
	cnt := 0
	err = fs.WalkDir(os.DirFS(filepath.Join(dbOne.Dir, ".dolt/temptf")), ".", func(path string, _ fs.DirEntry, err error) error {
		if err != nil {
			return err
		}
		cnt += 1
		return nil
	})
	require.NoError(t, err)
	require.Equal(t, 1, cnt)
}


Review comment (suggestion):
```suggestion
	// Empty Dir -> for "." found by WalkDir
	require.Equal(t, 1, cnt)
```

Code after:
		Args:        []string{"--port", `{{get_port "server_one"}}`},
		DynamicPort: "server_one",
	}, &ports)
	require.NotNil(t, server)
	db, err := server.DB(driver.Connection{User: "root"})
	require.NoError(t, err)
	t.Cleanup(func() {
		db.Close()
	})
	conn, err := db.Conn(t.Context())
	require.NoError(t, err)
	_, err = conn.ExecContext(t.Context(), "USE db_one")
	require.NoError(t, err)
	_, err = conn.ExecContext(t.Context(), "CALL dolt_push('origin', 'main')")
	require.NoError(t, err)
	cnt := 0
	err = fs.WalkDir(os.DirFS(filepath.Join(dbOne.Dir, ".dolt/temptf")), ".", func(path string, _ fs.DirEntry, err error) error {
		if err != nil {
			return err
		}
		cnt += 1
		return nil
	})
	require.NoError(t, err)
	// Empty Dir -> for "." found by WalkDir
	require.Equal(t, 1, cnt)
}
Repository: dolthub/dolt
File: go/libraries/doltcore/servercfg/env_interpolate.go (Go)

Code before:
			out = append(out, '$')
			continue
		}

		ph, err := parseEnvPlaceholder(data, i)
		if err != nil {
			return nil, err
		}

		out, err = appendEnvExpansion(out, lookup, ph)
		if err != nil {
			return nil, err
		}

		// Skip to closing brace.
		i = ph.closingBrace
	}

	return out, nil
}

func parseEnvPlaceholder(data []byte, dollarIdx int) (envPlaceholder, error) {
	// data[dollarIdx] == '$' and data[dollarIdx+1] == '{' expected.
	start := dollarIdx + 2 // after ${

	closingBrace := start
	for ; closingBrace < len(data) && data[closingBrace] != '}'; closingBrace++ {
	}
	if closingBrace >= len(data) {
		return envPlaceholder{}, fmt.Errorf("unterminated environment placeholder starting at byte %d", dollarIdx)
	}

	expr := data[start:closingBrace]
	varName, def, hasDefault, err := parseEnvExpr(expr)
	if err != nil {
		return envPlaceholder{}, err
	}

	return envPlaceholder{
		varName:      varName,
		def:          def,
		hasDefault:   hasDefault,
		closingBrace: closingBrace,
	}, nil
}

func appendEnvExpansion(out []byte, lookup envLookupFunc, ph envPlaceholder) ([]byte, error) {
	val, ok := lookup(ph.varName)
	if ok && val != "" {
		return append(out, []byte(val)...), nil
	}

Review comment (suggestion):
This following is a little more idiomatic.

```
rel := strings.IndexByte(data[start:], '}')
if rel == -1 {
    return envPlaceholder{}, fmt.Errorf("unterminated environment placeholder starting at byte %d", dollarIdx)
}
closingBrace := start + rel
```

Code after:
			}

			// Continue after the closing brace.
			i = ph.closingBrace + 1
			continue
		}

		// Leave stray '$' untouched
		out = append(out, '$')
		i = dollarIdx + 1
	}

	return out, nil
}

func parseEnvPlaceholder(data []byte, dollarIdx int) (envPlaceholder, error) {
	// data[dollarIdx] == '$' and data[dollarIdx+1] == '{' expected.
	start := dollarIdx + 2 // after ${

	rest := data[start:]

	relBrace := bytes.IndexByte(rest, '}')
	relNL := bytes.IndexByte(rest, '\n')
	relCR := bytes.IndexByte(rest, '\r')

	relLineEnd := minPositive(relNL, relCR)
	if relLineEnd != -1 && (relBrace == -1 || relLineEnd < relBrace) {
		// Placeholders must be on a single line. This prevents bad/missing braces from
		// consuming the rest of the file and producing giant error messages.
		return envPlaceholder{}, envErrorAt(data, dollarIdx, "unterminated environment placeholder")
	}

	if relBrace == -1 {
		return envPlaceholder{}, envErrorAt(data, dollarIdx, "unterminated environment placeholder")
	}

	closingBrace := start + relBrace

	expr := data[start:closingBrace]
	varName, err := parseEnvExpr(expr)
	if err != nil {
		return envPlaceholder{}, envErrorAt(data, dollarIdx, err.Error())
	}

	return envPlaceholder{
		varName:      varName,
		closingBrace: closingBrace,
	}, nil
}

func minPositive(a, b int) int {
Repository: dolthub/dolt
File: go/libraries/doltcore/servercfg/env_interpolate.go (Go)

Code before:
	if closingBrace >= len(data) {
		return envPlaceholder{}, fmt.Errorf("unterminated environment placeholder starting at byte %d", dollarIdx)
	}

	expr := data[start:closingBrace]
	varName, def, hasDefault, err := parseEnvExpr(expr)
	if err != nil {
		return envPlaceholder{}, err
	}

	return envPlaceholder{
		varName:      varName,
		def:          def,
		hasDefault:   hasDefault,
		closingBrace: closingBrace,
	}, nil
}

func appendEnvExpansion(out []byte, lookup envLookupFunc, ph envPlaceholder) ([]byte, error) {
	val, ok := lookup(ph.varName)
	if ok && val != "" {
		return append(out, []byte(val)...), nil
	}

	if ph.hasDefault {
		expandedDef, err := interpolateEnv(ph.def, lookup)
		if err != nil {
			return nil, err
		}
		return append(out, expandedDef...), nil
	}

	return nil, fmt.Errorf("environment variable %q is not set", ph.varName)
}

func parseEnvExpr(expr []byte) (varName string, def []byte, hasDefault bool, err error) {
	// Split on the first occurrence of ":-"
	varPart := expr
	var defPart []byte
	for k := 0; k+1 < len(expr); k++ {
		if expr[k] == ':' && expr[k+1] == '-' {
			varPart = expr[:k]
			defPart = expr[k+2:]
			hasDefault = true
			break
		}
	}

	if len(varPart) == 0 {
		return "", nil, false, fmt.Errorf("invalid environment placeholder: empty variable name")
	}

Review comment (suggestion):
This recursive call is kind of strange. Are you saying that the default can be set as an env var too?

`port: ${DOLT_PORT:-${DOLT_DEFAULT}}`

I would think we'd just have `ph.def` as a string and use it directly.

Code after:
		// consuming the rest of the file and producing giant error messages.
		return envPlaceholder{}, envErrorAt(data, dollarIdx, "unterminated environment placeholder")
	}

	if relBrace == -1 {
		return envPlaceholder{}, envErrorAt(data, dollarIdx, "unterminated environment placeholder")
	}

	closingBrace := start + relBrace

	expr := data[start:closingBrace]
	varName, err := parseEnvExpr(expr)
	if err != nil {
		return envPlaceholder{}, envErrorAt(data, dollarIdx, err.Error())
	}

	return envPlaceholder{
		varName:      varName,
		closingBrace: closingBrace,
	}, nil
}

func minPositive(a, b int) int {
	if a == -1 {
		return b
	}
	if b == -1 {
		return a
	}
	if a < b {
		return a
	}
	return b
}

func appendEnvExpansion(out []byte, ph envPlaceholder) ([]byte, error) {
	val, ok := os.LookupEnv(ph.varName)
	if !ok || val == "" {
		return nil, fmt.Errorf("environment variable %q is not set or empty", ph.varName)
	}
	return append(out, []byte(val)...), nil
}

func parseEnvExpr(expr []byte) (varName string, err error) {
	// Default expressions are intentionally unsupported to avoid silently masking misconfiguration.
	if bytes.Contains(expr, []byte(":-")) {
		return "", fmt.Errorf("environment variable default expressions are not supported (found %q)", string(expr))
	}

	if len(expr) == 0 {
		return "", fmt.Errorf("invalid environment placeholder: empty variable name")
Repository: dolthub/dolt
File: go/libraries/doltcore/servercfg/env_interpolate.go (Go)

Code before:
func interpolateEnv(data []byte, lookup envLookupFunc) ([]byte, error) {
	if lookup == nil {
		lookup = os.LookupEnv
	}

	out := make([]byte, 0, len(data))
	for i := 0; i < len(data); i++ {
		b := data[i]
		if b != '$' {
			out = append(out, data[i])
			continue
		}

		// Escape sequence: $$ -> $
		if i+1 < len(data) && data[i+1] == '$' {
			out = append(out, '$')
			i++
			continue
		}

		// Placeholder: ${...}
		if i+1 >= len(data) || data[i+1] != '{' {
			// Leave stray '$' untouched
			out = append(out, '$')
			continue
		}

		ph, err := parseEnvPlaceholder(data, i)
		if err != nil {
			return nil, err
		}

		out, err = appendEnvExpansion(out, lookup, ph)
		if err != nil {
			return nil, err
		}

		// Skip to closing brace.
		i = ph.closingBrace
	}

	return out, nil
}

func parseEnvPlaceholder(data []byte, dollarIdx int) (envPlaceholder, error) {
	// data[dollarIdx] == '$' and data[dollarIdx+1] == '{' expected.
	start := dollarIdx + 2 // after ${

	closingBrace := start
	for ; closingBrace < len(data) && data[closingBrace] != '}'; closingBrace++ {
	}

Review comment (suggestion):
You could probably save some conditionals by using:

```
i := strings.Index(s, "$$")
j := strings.Index(s, "${")
```

up to you.

Code after:
			break
		}

		dollarIdx := i + relDollar
		out = append(out, data[i:dollarIdx]...)

		// Escape sequence: $$ -> $
		if dollarIdx+1 < len(data) && data[dollarIdx+1] == '$' {
			out = append(out, '$')
			i = dollarIdx + 2
			continue
		}

		// Placeholder: ${...}
		if dollarIdx+1 < len(data) && data[dollarIdx+1] == '{' {
			ph, err := parseEnvPlaceholder(data, dollarIdx)
			if err != nil {
				return nil, err
			}

			out, err = appendEnvExpansion(out, ph)
			if err != nil {
				return nil, err
			}

			// Continue after the closing brace.
			i = ph.closingBrace + 1
			continue
		}

		// Leave stray '$' untouched
		out = append(out, '$')
		i = dollarIdx + 1
	}

	return out, nil
}

func parseEnvPlaceholder(data []byte, dollarIdx int) (envPlaceholder, error) {
	// data[dollarIdx] == '$' and data[dollarIdx+1] == '{' expected.
	start := dollarIdx + 2 // after ${

	rest := data[start:]

	relBrace := bytes.IndexByte(rest, '}')
	relNL := bytes.IndexByte(rest, '\n')
	relCR := bytes.IndexByte(rest, '\r')

	relLineEnd := minPositive(relNL, relCR)
	if relLineEnd != -1 && (relBrace == -1 || relLineEnd < relBrace) {
		// Placeholders must be on a single line. This prevents bad/missing braces from
Repository: dolthub/dolt
File: go/libraries/doltcore/servercfg/env_interpolate.go (Go)

Code before:
	varPart := expr
	var defPart []byte
	for k := 0; k+1 < len(expr); k++ {
		if expr[k] == ':' && expr[k+1] == '-' {
			varPart = expr[:k]
			defPart = expr[k+2:]
			hasDefault = true
			break
		}
	}

	if len(varPart) == 0 {
		return "", nil, false, fmt.Errorf("invalid environment placeholder: empty variable name")
	}
	if !isValidEnvVarName(varPart) {
		return "", nil, false, fmt.Errorf("invalid environment variable name %q", string(varPart))
	}

	return string(varPart), defPart, hasDefault, nil
}

func isValidEnvVarName(b []byte) bool {
	if len(b) == 0 {
		return false
	}
	for i := range b {
		c := b[i]
		if i == 0 {
			if !((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') {
				return false
			}
		} else {
			if !((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_') {
				return false
			}
		}
	}
	return true
}


Review comment (suggestion):
Use a regex!

```
var envVarRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)

func isValidEnvVarName(b []byte) bool {
    return envVarRe.Match(b)
}
```

Code after:
	if !ok || val == "" {
		return nil, fmt.Errorf("environment variable %q is not set or empty", ph.varName)
	}
	return append(out, []byte(val)...), nil
}

func parseEnvExpr(expr []byte) (varName string, err error) {
	// Default expressions are intentionally unsupported to avoid silently masking misconfiguration.
	if bytes.Contains(expr, []byte(":-")) {
		return "", fmt.Errorf("environment variable default expressions are not supported (found %q)", string(expr))
	}

	if len(expr) == 0 {
		return "", fmt.Errorf("invalid environment placeholder: empty variable name")
	}
	if !isValidEnvVarName(expr) {
		return "", fmt.Errorf("invalid environment variable name %q", string(expr))
	}

	return string(expr), nil
}

var envVarRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)

func isValidEnvVarName(b []byte) bool {
	return envVarRe.Match(b)
}

func envErrorAt(data []byte, idx int, msg string) error {
	line, col := lineAndColAt(data, idx)
	return fmt.Errorf("%s (line %d, column %d)", msg, line, col)
}

func lineAndColAt(data []byte, idx int) (line int, col int) {
	if idx < 0 {
		idx = 0
	}
	if idx > len(data) {
		idx = len(data)
	}

	line = 1
	col = 1
	for i := 0; i < idx; i++ {
		switch data[i] {
		case '\n':
			line++
			col = 1
		case '\r':
			line++
			col = 1
Repository: dolthub/dolt
File: go/store/util/tempfiles/temp_files.go (Go)

Code before:
}

func (p *LazyTempFileProvider) Clean() {
	// Don't load if we haven't already been loaded.
	if p.provider != nil {
		p.provider.Clean()
	}
}

func (p *LazyTempFileProvider) GetTempDir() string {
	p.loadit()
	if p.perr != nil {
		return os.TempDir()
	}
	return p.provider.GetTempDir()
}

func (p *LazyTempFileProvider) NewFile(dir, pattern string) (*os.File, error) {
	p.loadit()
	if p.perr != nil {
		return nil, p.perr
	}
	return p.provider.NewFile(dir, pattern)
}

// MovableTemFile is an object that implements TempFileProvider that is used by the nbs to create temp files that
// ultimately will be renamed.  It is important to use this instance rather than using os.TempDir, or os.CreateTemp
// directly as those may have errors executing a rename against if the volume the default temporary directory lives on
// is different than the volume of the destination of the rename.
var MovableTempFileProvider TempFileProvider = NewTempFileProviderAt(os.TempDir())


Review comment (suggestion):
```suggestion
// MovableTempFile is an object that implements TempFileProvider that is used by the nbs to create temp files that
```

Code after:
}

func (p *LazyTempFileProvider) loadit() {
	p.once.Do(func() {
		p.provider, p.perr = p.loader()
	})
}

func (p *LazyTempFileProvider) Clean() {
	// Don't load if we haven't already been loaded.
	if p.provider != nil {
		p.provider.Clean()
	}
}

func (p *LazyTempFileProvider) GetTempDir() string {
	p.loadit()
	if p.perr != nil {
		return os.TempDir()
	}
	return p.provider.GetTempDir()
}

func (p *LazyTempFileProvider) NewFile(dir, pattern string) (*os.File, error) {
	p.loadit()
	if p.perr != nil {
		return nil, p.perr
	}
	return p.provider.NewFile(dir, pattern)
}

// MovableTempFile is an object that implements TempFileProvider that is used by the nbs to create temp files that
// ultimately will be renamed.  It is important to use this instance rather than using os.TempDir, or os.CreateTemp
// directly as those may have errors executing a rename against if the volume the default temporary directory lives on
// is different than the volume of the destination of the rename.
var MovableTempFileProvider TempFileProvider = NewTempFileProviderAt(os.TempDir())
Repository: dolthub/dolt
File: go/libraries/doltcore/env/actions/commit.go (Go)

Code before:
			return nil, err
		}
		if len(inConflict) > 0 {
			return nil, NewTblInConflictError(inConflict)
		}
		violatesConstraints, err := doltdb.TablesWithConstraintViolations(ctx, roots.Working)
		if err != nil {
			return nil, err
		}
		if len(violatesConstraints) > 0 {
			return nil, NewTblHasConstraintViolations(violatesConstraints)
		}

		if ws.MergeActive() {
			schConflicts := ws.MergeState().TablesWithSchemaConflicts()
			if len(schConflicts) > 0 {
				return nil, NewTblSchemaConflictError(schConflicts)
			}
		}

		fkChecks, err := ctx.GetSessionVariable(ctx, "foreign_key_checks")
		if err != nil {
			return nil, err
		}

		if fkChecks.(int8) == 1 {
			roots.Staged, err = doltdb.ValidateForeignKeysOnSchemas(ctx, tableResolver, roots.Staged)
			if err != nil {
				return nil, err
			}
		}
	}

	meta, err := datas.NewCommitMetaWithUserTS(props.Name, props.Email, props.Message, props.Date)
	if err != nil {
		return nil, err
	}

	return db.NewPendingCommit(ctx, roots, mergeParents, props.Amend, meta)
}


Review comment (bug):
In the past, I've seen session variables that get unexpected values, like of the wrong type. If this does happen here (e.g. @@foreign_key_checks somehow gets assigned a string value instead of an int), then it will cause a panic. We catch that panic, so it shouldn't crash the server, but still a good practice to do a panic-safe typecheck as part of the cast, instead of this unsafe cast. 

Change this to something like...
```
if intValue, ok := fkChecks.(int8); ok && intValue == 1 {
```

It's not a big deal, but it's a small detail that makes the code execute a little safer. 

Code after:
			return nil, err
		}
		if len(inConflict) > 0 {
			return nil, NewTblInConflictError(inConflict)
		}
		violatesConstraints, err := doltdb.TablesWithConstraintViolations(ctx, roots.Working)
		if err != nil {
			return nil, err
		}
		if len(violatesConstraints) > 0 {
			return nil, NewTblHasConstraintViolations(violatesConstraints)
		}

		if ws.MergeActive() {
			schConflicts := ws.MergeState().TablesWithSchemaConflicts()
			if len(schConflicts) > 0 {
				return nil, NewTblSchemaConflictError(schConflicts)
			}
		}

		fkChecks, err := ctx.GetSessionVariable(ctx, "foreign_key_checks")
		if err != nil {
			return nil, err
		}

		if intValue, ok := fkChecks.(int8); ok && intValue == 1 {
			roots.Staged, err = doltdb.ValidateForeignKeysOnSchemas(ctx, tableResolver, roots.Staged)
			if err != nil {
				return nil, err
			}
		}
	}

	meta, err := datas.NewCommitMetaWithUserTS(props.Name, props.Email, props.Message, props.Date)
	if err != nil {
		return nil, err
	}

	return db.NewPendingCommit(ctx, roots, mergeParents, props.Amend, meta)
}
Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/enginetest/dolt_queries_nonlocal.go (Go)

Code before:
			{
				Query:    "show tables;",
				Expected: []sql.Row{{"foo"}},
			},
		},
	},
	// https://github.com/dolthub/dolt/issues/10462
	{
		Name: "nonlocal table is not affected by dolt_clean()",
		SetUpScript: []string{
			"CREATE TABLE global_test (id int auto_increment primary key, name varchar(100));",
			"INSERT INTO global_test (id, name) VALUES (1, 'one');",
			"CREATE TABLE foo (id int auto_increment primary key);",
			"INSERT INTO dolt_nonlocal_tables (table_name, target_ref, options) VALUES ('global_*', 'main', 'immediate');",
			"CALL dolt_add('dolt_nonlocal_tables');",
			"CALL dolt_commit('-m', 'set up dolt_nonlocal_tables');",
		},
		Assertions: []queries.ScriptTestAssertion{
			{
				Query:    "SELECT * FROM global_test;",
				Expected: []sql.Row{{1, "one"}},
			},
			{
				Query:    "CALL dolt_clean();",
				Expected: []sql.Row{{0}},
			},
			{
				Query:    "SELECT * FROM global_test;",
				Expected: []sql.Row{{1, "one"}},
			},
			{
				Query:    "SHOW TABLES;",
				Expected: []sql.Row{{"global_test"}},
			},
		},
	},
}


Review comment (suggestion):
Probably good to also test with explicitly using `call dolt-clean('-x');` just to assert that `-x` won't affect nonlocal tables, like the docs call out. 

Code after:
			{
				Query:    "show tables;",
				Expected: []sql.Row{{"foo"}},
			},
		},
	},
	{
		// https://github.com/dolthub/dolt/issues/10462
		Name: "nonlocal table is not affected by dolt_clean()",
		SetUpScript: []string{
			"CREATE TABLE global_test (id int auto_increment primary key, name varchar(100));",
			"INSERT INTO global_test (id, name) VALUES (1, 'one');",
			"CREATE TABLE foo (id int auto_increment primary key);",
			"INSERT INTO dolt_nonlocal_tables (table_name, target_ref, options) VALUES ('global_*', 'main', 'immediate');",
			"CALL dolt_add('dolt_nonlocal_tables');",
			"CALL dolt_commit('-m', 'set up dolt_nonlocal_tables');",
		},
		Assertions: []queries.ScriptTestAssertion{
			{
				Query:    "SELECT * FROM global_test;",
				Expected: []sql.Row{{1, "one"}},
			},
			{
				Query:    "CALL dolt_clean();",
				Expected: []sql.Row{{0}},
			},
			{
				Query:    "SELECT * FROM global_test;",
				Expected: []sql.Row{{1, "one"}},
			},
			{
				Query:    "SHOW TABLES;",
				Expected: []sql.Row{{"global_test"}},
			},
			{
				Query:    "CALL dolt_clean('-x')",
				Expected: []sql.Row{{0}},
			},
			{
				Query:    "SELECT * FROM global_test;",
				Expected: []sql.Row{{1, "one"}},
			},
			{
				Query:    "SHOW TABLES;",
				Expected: []sql.Row{{"global_test"}},
			},
		},
	},
}