beads/internal/storage/embeddeddolt/commit_all_cgo_test.go
swedeinasia-flow e021cf1a25
fix(storage): CommitAll — explicit commits sweep the whole working set and report honestly (#5830)
* 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>
2026-08-20 05:31:33 -07:00

66 lines
2.3 KiB
Go

//go:build cgo
package embeddeddolt_test
import (
"testing"
)
// TestCommitAllOutOfBandChangeAndHonestNoOp covers the embedded half of the
// explicit-commit fix. Embedded Commit already stages everything via
// DOLT_COMMIT('-Am'), so the staging gap is server-mode-only; what CommitAll
// adds here is the honest report: (true, nil) exactly when a commit was
// created, (false, nil) when there was nothing to commit — so `bd vc commit`
// can print "Nothing to commit" instead of "Created commit <existing HEAD>".
func TestCommitAllOutOfBandChangeAndHonestNoOp(t *testing.T) {
ctx := t.Context()
te := newTestEnv(t, "cat")
// Flush anything setup left uncommitted, then pin the honest no-op.
if _, err := te.store.CommitAll(ctx, "test: flush baseline"); err != nil {
t.Fatalf("baseline CommitAll: %v", err)
}
headBefore, err := te.store.GetCurrentCommit(ctx)
if err != nil {
t.Fatalf("GetCurrentCommit: %v", err)
}
committed, err := te.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 := te.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)
}
// Out-of-band write: a config row inserted through a raw SQL connection,
// bypassing the store's transaction tracking entirely.
te.exec(t, ctx, "INSERT INTO config (`key`, value) VALUES ('test.oob-commit-all', 'v1')")
committed, err = te.store.CommitAll(ctx, "test: sweep out-of-band config")
if err != nil {
t.Fatalf("CommitAll with out-of-band config change: %v", err)
}
if !committed {
t.Fatalf("CommitAll reported nothing to commit while config was dirty")
}
var dirty int
te.queryScalar(t, ctx,
"SELECT COUNT(*) FROM dolt_status WHERE table_name = 'config'", nil, &dirty)
if dirty != 0 {
t.Fatalf("CommitAll left config dirty (%d dolt_status rows)", dirty)
}
headSwept, err := te.store.GetCurrentCommit(ctx)
if err != nil {
t.Fatalf("GetCurrentCommit: %v", err)
}
if headSwept == headAfter {
t.Fatalf("CommitAll reported committed=true but HEAD did not advance from %s", headAfter)
}
}