From 61ba8f05c9ae94d162a9c83d75d7dcf1dd765c9e Mon Sep 17 00:00:00 2001 From: Aaron Lippold Date: Fri, 12 Jun 2026 00:59:37 -0400 Subject: [PATCH] =?UTF-8?q?feat(storage):=20add=20CommitConfigOnly=20?= =?UTF-8?q?=E2=80=94=20scoped=20config-table=20commit=20(GH#4078)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generic Commit() excludes the config table by design (GH#2455) and CommitWithConfig stages everything via '-Am' — neither can commit an intentional config write without sweeping concurrent operations' dirty tables in server mode. CommitConfigOnly stages ONLY config (via the existing doltAddAndCommit helper) and commits it. - VersionControl interface method with GH#4078/GH#2455 rationale - DoltStore: scoped DOLT_ADD('config') + DOLT_COMMIT - EmbeddedDoltStore: aliases Commit — single-process, so '-Am' cannot sweep concurrent work (same rationale as its CommitWithConfig alias) - Tests against a real dolt-sql-server container: scoped commit lands, concurrent dirty issues row survives uncommitted, and generic Commit()'s config exclusion is pinned as a regression guard --- internal/storage/dolt/commit_config_test.go | 156 ++++++++++++++++++ internal/storage/dolt/store.go | 9 + .../storage/embeddeddolt/version_control.go | 9 + internal/storage/version_control.go | 7 + 4 files changed, 181 insertions(+) create mode 100644 internal/storage/dolt/commit_config_test.go diff --git a/internal/storage/dolt/commit_config_test.go b/internal/storage/dolt/commit_config_test.go new file mode 100644 index 000000000..aa0f3f64f --- /dev/null +++ b/internal/storage/dolt/commit_config_test.go @@ -0,0 +1,156 @@ +package dolt + +import ( + "testing" +) + +// dirtyTables returns the set of table names currently in dolt_status. +func dirtyTables(t *testing.T, store *DoltStore) map[string]bool { + t.Helper() + ctx, cancel := testContext(t) + defer cancel() + + rows, err := store.db.QueryContext(ctx, "SELECT table_name FROM dolt_status") + if err != nil { + t.Fatalf("query dolt_status: %v", err) + } + defer rows.Close() + + tables := make(map[string]bool) + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + t.Fatalf("scan dolt_status: %v", err) + } + tables[name] = true + } + if err := rows.Err(); err != nil { + t.Fatalf("iterate dolt_status: %v", err) + } + return tables +} + +// GH#4078: a config-only working set must be committable. Generic Commit() +// excludes config by design (GH#2455), so intentional config writes +// (bd remember, bd config set) need a scoped commit that stages ONLY the +// config table and creates a real Dolt commit. +func TestCommitConfigCommitsConfigOnlyWorkingSet(t *testing.T) { + store, cleanup := setupTestStore(t) + defer cleanup() + + ctx, cancel := testContext(t) + defer cancel() + + // Start from a clean working set so the only dirty table is config. + if err := store.CommitWithConfig(ctx, "test: baseline"); err != nil { + t.Fatalf("baseline commit: %v", err) + } + before, err := store.GetCurrentCommit(ctx) + if err != nil { + t.Fatalf("get baseline commit: %v", err) + } + + if err := store.SetConfig(ctx, "test_gh4078_marker", "config-only write"); err != nil { + t.Fatalf("SetConfig: %v", err) + } + if !dirtyTables(t, store)["config"] { + t.Fatal("precondition failed: SetConfig did not leave config dirty") + } + + if err := store.CommitConfigOnly(ctx, "test: scoped config commit"); err != nil { + t.Fatalf("CommitConfigOnly: %v", err) + } + + after, err := store.GetCurrentCommit(ctx) + if err != nil { + t.Fatalf("get commit after CommitConfigOnly: %v", err) + } + if after == before { + t.Fatalf("CommitConfigOnly created no commit: HEAD still %s", before) + } + if dirtyTables(t, store)["config"] { + t.Fatal("config table still dirty after CommitConfigOnly") + } +} + +// GH#2455 must survive GH#4078: the scoped commit stages ONLY config. +// Dirty rows in other tables (e.g. a concurrent operation's half-written +// issue) must remain in the working set, not get swept into the commit. +func TestCommitConfigDoesNotSweepOtherDirtyTables(t *testing.T) { + store, cleanup := setupTestStore(t) + defer cleanup() + + ctx, cancel := testContext(t) + defer cancel() + + if err := store.CommitWithConfig(ctx, "test: baseline"); err != nil { + t.Fatalf("baseline commit: %v", err) + } + + // Dirty the issues table directly, bypassing any commit machinery — + // simulates a concurrent operation's uncommitted write. + if _, err := store.db.ExecContext(ctx, + "INSERT INTO issues (id, title, description, design, acceptance_criteria, notes, status, priority, issue_type)"+ + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", + "testdb-gh4078", "concurrent dirty row", "", "", "", "", "open", 2, "task"); err != nil { + t.Fatalf("dirty issues table: %v", err) + } + if err := store.SetConfig(ctx, "test_gh4078_scoped", "scoped"); err != nil { + t.Fatalf("SetConfig: %v", err) + } + + pre := dirtyTables(t, store) + if !pre["config"] || !pre["issues"] { + t.Fatalf("precondition failed: want config+issues dirty, got %v", pre) + } + + if err := store.CommitConfigOnly(ctx, "test: scoped config commit"); err != nil { + t.Fatalf("CommitConfigOnly: %v", err) + } + + post := dirtyTables(t, store) + if post["config"] { + t.Fatal("config table still dirty after CommitConfigOnly") + } + if !post["issues"] { + t.Fatal("CommitConfigOnly swept the dirty issues table — GH#2455 regression") + } +} + +// Pin the GH#2455 contract that motivates CommitConfigOnly's existence: the +// generic Commit() must keep EXCLUDING config. If this ever changes, the +// scoped-commit call sites should be revisited. +func TestCommitExcludesConfigOnlyWorkingSet(t *testing.T) { + store, cleanup := setupTestStore(t) + defer cleanup() + + ctx, cancel := testContext(t) + defer cancel() + + if err := store.CommitWithConfig(ctx, "test: baseline"); err != nil { + t.Fatalf("baseline commit: %v", err) + } + before, err := store.GetCurrentCommit(ctx) + if err != nil { + t.Fatalf("get baseline commit: %v", err) + } + + if err := store.SetConfig(ctx, "test_gh2455_excluded", "stays dirty"); err != nil { + t.Fatalf("SetConfig: %v", err) + } + + if err := store.Commit(ctx, "test: generic commit must skip config"); err != nil { + t.Fatalf("Commit: %v", err) + } + + after, err := store.GetCurrentCommit(ctx) + if err != nil { + t.Fatalf("get commit after Commit: %v", err) + } + if after != before { + t.Fatal("generic Commit() committed a config-only working set — GH#2455 regression") + } + if !dirtyTables(t, store)["config"] { + t.Fatal("config table no longer dirty after generic Commit()") + } +} diff --git a/internal/storage/dolt/store.go b/internal/storage/dolt/store.go index a367380cf..dc30c0345 100644 --- a/internal/storage/dolt/store.go +++ b/internal/storage/dolt/store.go @@ -1793,6 +1793,15 @@ func (s *DoltStore) CommitWithConfig(ctx context.Context, message string) error return nil } +// CommitConfigOnly commits ONLY the config table (GH#4078). Use after +// intentional config writes (bd remember, bd config set) in server mode, +// where generic Commit() excludes config (GH#2455) and nothing else ever +// commits it. Scoped staging means a concurrent operation's dirty tables +// are never swept — the same guarantee that motivated GH#2455. +func (s *DoltStore) CommitConfigOnly(ctx context.Context, message string) error { + return s.doltAddAndCommit(ctx, []string{"config"}, message) +} + // doltAddAndCommit stages the specified tables and commits on a pinned // connection. This prevents DOLT_COMMIT('-Am') from sweeping up stale // working set changes from concurrent operations (GH#2455). diff --git a/internal/storage/embeddeddolt/version_control.go b/internal/storage/embeddeddolt/version_control.go index 140729b74..323d78809 100644 --- a/internal/storage/embeddeddolt/version_control.go +++ b/internal/storage/embeddeddolt/version_control.go @@ -113,6 +113,15 @@ func (s *EmbeddedDoltStore) CommitWithConfig(ctx context.Context, message string return s.Commit(ctx, message) } +// CommitConfigOnly commits the config table (GH#4078). Embedded mode is +// single-process, so the '-Am' Commit cannot sweep a concurrent operation's +// working set — the scoped-staging concern that exists in server mode +// (GH#2455) does not apply here, and this aliases Commit for the same +// reason CommitWithConfig does. +func (s *EmbeddedDoltStore) CommitConfigOnly(ctx context.Context, message string) error { + return s.Commit(ctx, message) +} + func (s *EmbeddedDoltStore) AddRemote(ctx context.Context, name, url string) error { return s.withMutatingDBConn(ctx, func(db versioncontrolops.DBConn) error { _, err := db.ExecContext(ctx, "CALL DOLT_REMOTE('add', ?, ?)", name, url) diff --git a/internal/storage/version_control.go b/internal/storage/version_control.go index eaf924785..e46aba4f0 100644 --- a/internal/storage/version_control.go +++ b/internal/storage/version_control.go @@ -38,6 +38,13 @@ type VersionControl interface { // Use after intentional config writes (bd init, bd config set, bd rename-prefix). // GH#3216: bootstrap paths must use this to commit issue_prefix. CommitWithConfig(ctx context.Context, message string) error + // CommitConfigOnly commits ONLY the config table — the scoped commit for + // intentional config writes (bd remember, bd config set) in server mode. + // Unlike CommitWithConfig ('-Am'), it never stages other tables, so a + // concurrent operation's dirty working set is not swept (GH#2455). + // GH#4078: without this, server-mode config writes strand the working + // set dirty — generic Commit() excludes config and silently no-ops. + CommitConfigOnly(ctx context.Context, message string) error CommitPending(ctx context.Context, actor string) (bool, error) CommitExists(ctx context.Context, commitHash string) (bool, error) GetCurrentCommit(ctx context.Context) (string, error)