* fix(storage): CommitAll — explicit commits sweep the whole working set and report honestly
bd vc commit and bd dolt commit promise "any uncommitted changes in the
working set" but route through store.Commit, which in server mode excludes
config (GH#2455). A working set whose only dirt is out-of-band — written by
an external process or any path that bypasses bd's dirty-table tracking,
config above all — is silently skipped: nothing staged, no commit created,
dolt_status stays dirty. The doctor's dirty-working-set warning recommends
exactly these commands as the remedy, so the warning could never be cleared
by its own remedy. Reproduced on a server-mode database: dolt_status showed
config modified, bd vc commit exited 0, and manual DOLT_ADD('config') +
DOLT_COMMIT was the only cure.
Add VersionControl.CommitAll(ctx, message) (bool, error): one
DOLT_COMMIT('-Am') sweep of the entire working set (config included;
dolt_ignore'd wisp tables skipped by '-A'), returning an honest
(false, nil) when nothing was committable. This is the committed-bool
interface threading the vc.go comment tracked as bd mybd-z9h7j
("CommitPending already has the shape") — the embedded store's internal
commitAll already returns exactly this bool, so the embedded implementation
is a one-line export. Both explicit commands now use it, replacing their
HEAD-before/HEAD-after comparisons and the concurrent-writer
misattribution race those carried.
Per-op auto-commit paths (DirtyTableTracker staging, commitBeforePull) are
unchanged: GH#2455's protection against automatically sweeping a concurrent
writer's half-applied config change stands. An operator explicitly asking
to commit everything is the same trust level as CommitPending, which has
always included config. Server-mode CommitPending now delegates its tail to
CommitAll, which also fixes its (true, nil) report when Dolt said "nothing
to commit" despite the status pre-check.
Tests: server-mode Dolt-harness test (out-of-band config write swept, clean
set honestly reported, GH#2455 Commit-excludes-config precondition pinned)
+ embedded test (out-of-band raw-SQL write swept; honest no-op with HEAD
unmoved).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* docs(storage): reconcile CommitAll review notes
Clarify why pre-pull commits retain screened DOLT_ADD staging while CommitAll has current server-mode coverage, and document the explicit-commit behavior change under Unreleased.
Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Klas Hesselman
---------
Co-authored-by: Klas Hesselman <211416696+swedeinasia-flow@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
106 lines
3.5 KiB
Go
106 lines
3.5 KiB
Go
package dolt
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// TestCommitAllSweepsOutOfBandConfig is the regression test for the explicit
|
|
// commit commands' false success: a table modified out of band (the chronic
|
|
// config touch above all) never enters any transaction's dirty-table tracking,
|
|
// and plain Commit() excludes config (GH#2455) — so `bd vc commit` staged
|
|
// nothing, created no commit, and printed "Created commit <old HEAD>" while
|
|
// dolt_status stayed dirty. That also made the doctor's dirty-working-set
|
|
// warning unclearable by its own recommended remedy. CommitAll must sweep the
|
|
// whole working set, create a real commit, and report honestly that it did.
|
|
func TestCommitAllSweepsOutOfBandConfig(t *testing.T) {
|
|
store, cleanup := setupTestStore(t)
|
|
defer cleanup()
|
|
|
|
ctx, cancel := testContext(t)
|
|
defer cancel()
|
|
|
|
db := store.db
|
|
|
|
// Flush anything the harness left uncommitted so the assertions below are
|
|
// about this test's own out-of-band write only.
|
|
if _, err := store.CommitAll(ctx, "test: flush baseline"); err != nil {
|
|
t.Fatalf("baseline CommitAll: %v", err)
|
|
}
|
|
|
|
headBefore, err := store.GetCurrentCommit(ctx)
|
|
if err != nil {
|
|
t.Fatalf("GetCurrentCommit: %v", err)
|
|
}
|
|
|
|
// Out-of-band write: config modified with no bd transaction tracking it.
|
|
if _, err := db.ExecContext(ctx,
|
|
"INSERT INTO config (`key`, value) VALUES ('test.oob-commit-all', 'v1')"); err != nil {
|
|
t.Fatalf("insert out-of-band config row: %v", err)
|
|
}
|
|
|
|
// Precondition: plain Commit leaves config dirty (GH#2455). If this stops
|
|
// reproducing, the false-success scenario no longer exists and this test
|
|
// should be rethought.
|
|
if err := store.Commit(ctx, "commit excluding config"); err != nil {
|
|
t.Fatalf("Commit: %v", err)
|
|
}
|
|
if !configDirty(t, ctx, db) {
|
|
t.Fatalf("Commit() unexpectedly committed config; the false-success precondition no longer reproduces (did GH#2455's config exclusion change?)")
|
|
}
|
|
|
|
committed, err := store.CommitAll(ctx, "test: sweep out-of-band config")
|
|
if err != nil {
|
|
t.Fatalf("CommitAll: %v", err)
|
|
}
|
|
if !committed {
|
|
t.Fatalf("CommitAll reported nothing to commit while config was dirty")
|
|
}
|
|
if configDirty(t, ctx, db) {
|
|
t.Fatalf("CommitAll left config dirty; the doctor's dirty-working-set warning would persist")
|
|
}
|
|
|
|
headAfter, err := store.GetCurrentCommit(ctx)
|
|
if err != nil {
|
|
t.Fatalf("GetCurrentCommit: %v", err)
|
|
}
|
|
if headAfter == headBefore {
|
|
t.Fatalf("CommitAll reported committed=true but HEAD did not advance from %s", headBefore)
|
|
}
|
|
}
|
|
|
|
// TestCommitAllNothingToCommit pins the honest-no-op half of the fix: on a
|
|
// working set with nothing committable, CommitAll must return (false, nil)
|
|
// and leave HEAD alone, so `bd vc commit` prints "Nothing to commit" instead
|
|
// of fabricating "Created commit <existing HEAD>".
|
|
func TestCommitAllNothingToCommit(t *testing.T) {
|
|
store, cleanup := setupTestStore(t)
|
|
defer cleanup()
|
|
|
|
ctx, cancel := testContext(t)
|
|
defer cancel()
|
|
|
|
if _, err := store.CommitAll(ctx, "test: flush baseline"); err != nil {
|
|
t.Fatalf("baseline CommitAll: %v", err)
|
|
}
|
|
|
|
headBefore, err := store.GetCurrentCommit(ctx)
|
|
if err != nil {
|
|
t.Fatalf("GetCurrentCommit: %v", err)
|
|
}
|
|
|
|
committed, err := store.CommitAll(ctx, "test: nothing to commit")
|
|
if err != nil {
|
|
t.Fatalf("CommitAll on clean working set: %v", err)
|
|
}
|
|
if committed {
|
|
t.Fatalf("CommitAll reported a commit on a clean working set")
|
|
}
|
|
|
|
headAfter, err := store.GetCurrentCommit(ctx)
|
|
if err != nil {
|
|
t.Fatalf("GetCurrentCommit: %v", err)
|
|
}
|
|
if headAfter != headBefore {
|
|
t.Fatalf("CommitAll reported committed=false but HEAD advanced: %s -> %s", headBefore, headAfter)
|
|
}
|
|
}
|