beads/cmd/bd/dolt_autocommit_test.go
Julian Knutsen a59e753258
Triage and clean up an unreviewed automated commit stream on main (#4418)
* Revert "test(cmd/bd): Seam B cross-mode list parity — embedded vs proxied CLI (bd-6dnrw.45)"

This reverts commit 93b186dcf9.

* Revert "test(ci): restore test-proxied-server-cmd lane behind a test-only init ungate (bd-6dnrw.44)"

This reverts commit 1425e7338e.

* Revert "fix(cli): keep the autocommit sweep off read-only and inspection commands; attribute sweeps distinctly (bd-578h9.7)"

This reverts commit 81489b8c15.

* Revert "fix(autocommit): dirty-working-set safety net behind commandDidWrite (bd-6dnrw.11)"

This reverts commit d2b6cc5250.

* test: add proven born-failing regression tests for kept fixes

For kept fixes whose shipped tests were characterization-only or absent, add
born-failing regression tests (verified RED when the defect is reintroduced,
GREEN with the fix in place):

- internal/lockfile: IsLocked must detect a *wrapped* ErrLocked — guards the
  errors.Is fix (was pointer-equality). (orig 1a83cb08c)
- internal/storage/domain/db: GetDescendants with a level filter across edge
  and dotted-ID branches — guards the dolt 2.1.6 named-CTE analyzer workaround;
  the pre-existing dotted-orphans test used an empty filter and never built the
  predicate. (orig 341c7a5a4)
- cmd/bd: GOMODCACHE must be pinned outside the temp test HOME — guards the
  testMainInner module-cache fix. (orig bc909834c)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* revert(serverv2): restore the gated proxied-server layer to BASE

The proxied / external-dolt-server subsystem (serverV2) is gated off and not
running yet. This reverts the unreviewed changes to its schema-independent
layers back to BASE 9a1c88b63, while keeping the parts welded to the published
schema.

Reverted to BASE (26 files):
- internal/storage/dbproxy/*  (proxy/socket process mgmt: orphan-dolt reaping,
  pidfile discovery, endpoint/shutdown hardening)
- internal/storage/uow/*      (uow tx lifecycle, warmup-retry classification,
  provider changes)
- cmd/bd proxied glue: proxied_server, init_proxied_server, list_proxied_server,
  uow_factory, store_factory(+nocgo), and main.go proxied-mode dispatch hunks

Kept at HEAD (welded to the published migration 0051 / required by the data
layer, consistent with the keep-the-schema-stack decision):
- internal/storage/domain/db/* (mints app-side ids because 0051 dropped the DB
  default; queries the live migrated schema) -- left identical to HEAD
- the issueops Runner/DBTX widening + scan changes that HEAD domain/db requires

A strict serverV2->BASE revert is impossible without breaking main: domain/db is
welded to the published 0051 (BASE domain/db inserts without an id and relies on
the DEFAULT(UUID()) that 0051 removed). This reverts everything that is NOT so
welded.

Verified: full `make test` green (60 ok packages, 0 failures); domain/db, uow,
and dbproxy all ok.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: CI Bot <ci@beads.test>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 20:24:57 -07:00

80 lines
2.1 KiB
Go

package main
import (
"errors"
"testing"
)
func TestFormatDoltAutoCommitMessage(t *testing.T) {
msg := formatDoltAutoCommitMessage("update", "alice", []string{"bd-2", "bd-1", "bd-2", "", "bd-3"})
if msg != "bd: update (auto-commit) by alice [bd-1, bd-2, bd-3]" {
t.Fatalf("unexpected message: %q", msg)
}
// Caps IDs (max 5) and sorts
msg = formatDoltAutoCommitMessage("create", "bob", []string{"z-9", "a-1", "m-3", "b-2", "c-4", "d-5", "e-6"})
if msg != "bd: create (auto-commit) by bob [a-1, b-2, c-4, d-5, e-6]" {
t.Fatalf("unexpected capped message: %q", msg)
}
// Empty command/actor fallbacks
msg = formatDoltAutoCommitMessage("", "", nil)
if msg != "bd: write (auto-commit) by unknown" {
t.Fatalf("unexpected fallback message: %q", msg)
}
}
func TestIsDoltNothingToCommit(t *testing.T) {
if isDoltNothingToCommit(nil) {
t.Fatal("nil error should not be treated as nothing-to-commit")
}
if !isDoltNothingToCommit(errors.New("nothing to commit")) {
t.Fatal("expected nothing-to-commit to be detected")
}
if !isDoltNothingToCommit(errors.New("No changes to commit")) {
t.Fatal("expected no-changes-to-commit to be detected")
}
if isDoltNothingToCommit(errors.New("permission denied")) {
t.Fatal("unexpected classification")
}
}
func TestGetDoltAutoCommitMode_Batch(t *testing.T) {
old := doltAutoCommit
defer func() { doltAutoCommit = old }()
doltAutoCommit = "batch"
mode, err := getDoltAutoCommitMode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if mode != doltAutoCommitBatch {
t.Fatalf("expected batch, got %q", mode)
}
// Also verify the other modes still work
doltAutoCommit = "on"
mode, err = getDoltAutoCommitMode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if mode != doltAutoCommitOn {
t.Fatalf("expected on, got %q", mode)
}
doltAutoCommit = "off"
mode, err = getDoltAutoCommitMode()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if mode != doltAutoCommitOff {
t.Fatalf("expected off, got %q", mode)
}
// Invalid mode
doltAutoCommit = "invalid"
_, err = getDoltAutoCommitMode()
if err == nil {
t.Fatal("expected error for invalid mode")
}
}