beads/internal/storage/versioncontrolops/backup_test.go
Robin Carswell a097723f28
fix: suppress auto-backup address conflict warning (#2927)
* fix: suppress auto-backup address conflict warning when default backup is configured

When a user runs `bd backup init <path>` it registers a Dolt backup named
"default". The auto-backup system also calls BackupDatabase() which registers
its own remote named "backup_export" pointing to the same .beads/backup/
directory. Dolt returns "Error 1105: address conflict with a remote: 'default'"
because two remotes cannot share a URL, causing a noisy warning on every write:

  Warning: auto-backup failed: register backup remote: add backup backup_export: \
  Error 1105: address conflict with a remote: 'default' -> file://.../backup

Fix: when BackupAdd fails with an address conflict, extract the name of the
already-registered remote from the error message and sync using that name
instead. The backup still runs — it just reuses the existing remote.

Adds ExtractAddressConflictName() to versioncontrolops for parsing the
conflicting name out of the Dolt error. Applies the fix to both the
EmbeddedDoltStore and DoltStore implementations of BackupDatabase().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: add table-driven tests for ExtractAddressConflictName

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 20:28:47 -07:00

47 lines
987 B
Go

package versioncontrolops
import (
"fmt"
"testing"
)
func TestExtractAddressConflictName(t *testing.T) {
tests := []struct {
name string
err error
want string
}{
{
name: "nil error",
err: nil,
want: "",
},
{
name: "unrelated error",
err: fmt.Errorf("connection refused"),
want: "",
},
{
name: "standard conflict",
err: fmt.Errorf("Error 1105: address conflict with a remote: 'default' -> file:///backup"),
want: "default",
},
{
name: "full dolt error format from doc comment",
err: fmt.Errorf("Error 1105: address conflict with a remote: 'backup_export' -> file:///some/path"),
want: "backup_export",
},
{
name: "missing closing quote",
err: fmt.Errorf("address conflict with a remote: 'oops"),
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ExtractAddressConflictName(tt.err); got != tt.want {
t.Errorf("got %q, want %q", got, tt.want)
}
})
}
}