Extend #4847's rollback to the last alternative backend: bd now ships a single storage engine (Dolt, embedded and server mode). - Delete internal/storage/{sqlite,sqlitedialect} and the packages the removal orphans: sqlkit (sole importer was the sqlite store), unsupportedgen (sole go:generate consumer), the NonCommitGraphBackend marker and its two dead consumer checks, and the domain-db parity test that used sqlite as its harness. Drop modernc.org/sqlite from go.mod and regenerate the nix vendorHash. - Tombstone backend="sqlite" exactly like postgres/mysql: recognized in metadata (never silently aliased to a fresh Dolt DB), rejected before any open with its own rationale and the export -> re-init -> import guidance. The fail-closed guarantee now also covers never creating the beads.db file the removed backend would have provisioned. - bd init: --backend=sqlite reaches removed-backend guidance; --sqlite-path becomes a hidden parser tombstone like the pg/mysql flags; help text and supported-backend enumerations say Dolt only. - Doctor: sqlite workspaces fail closed like the other tombstones; the modern sqlite stub payloads are gone. The legacy pre-Dolt surface (artifact scans, migration validation, migrate-sqlite-to-current.sh, the migration-test harness) is untouched; genuine pre-Dolt workspaces carry no backend field and never hit the tombstone. - Conformance: drop the sqlite profile; the CLI differential runner idles (skip, not fail) until another backend profile is registered, and the export/import round-trip keeps running against the embedded Dolt reference. Tier-1 oracle legs are unchanged. Backend selection has never shipped in a release (v1.1.0 predates it), so released workflows are unaffected and the pinned CLI docs already describe the resulting behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
122 lines
4.5 KiB
Go
122 lines
4.5 KiB
Go
package beads_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads"
|
|
)
|
|
|
|
func writeBackendMetadata(t *testing.T, backend string) string {
|
|
t.Helper()
|
|
beadsDir := filepath.Join(t.TempDir(), ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
|
t.Fatalf("create .beads: %v", err)
|
|
}
|
|
metadata := `{"backend":"` + backend + `"}`
|
|
if backend == "sqlite" {
|
|
// Workspaces created by the removed SQLite backend carry an explicit
|
|
// path marker; a bare backend:"sqlite" can also be stale metadata from
|
|
// the earlier SQLite era (see PR #4740). Both must hit the tombstone.
|
|
metadata = `{"backend":"sqlite","sqlite_path":"beads.db"}`
|
|
}
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte(metadata), 0o600); err != nil {
|
|
t.Fatalf("write metadata: %v", err)
|
|
}
|
|
return beadsDir
|
|
}
|
|
|
|
func TestOpenBestAvailableRejectsSQLite(t *testing.T) {
|
|
beadsDir := writeBackendMetadata(t, "sqlite")
|
|
store, err := beads.OpenBestAvailable(context.Background(), beadsDir)
|
|
if store != nil {
|
|
_ = store.Close()
|
|
t.Fatal("removed SQLite backend returned a store")
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), "no longer supported") {
|
|
t.Fatalf("SQLite backend error = %v, want rollback explanation", err)
|
|
}
|
|
if !strings.Contains(err.Error(), "single engine") || !strings.Contains(err.Error(), "export") {
|
|
t.Fatalf("SQLite backend error lacks rationale or migration guidance: %v", err)
|
|
}
|
|
// The fail-closed guarantee includes never provisioning the SQLite file the
|
|
// removed backend would have created.
|
|
for _, name := range []string{"embeddeddolt", "dolt", "beads.db"} {
|
|
if _, statErr := os.Stat(filepath.Join(beadsDir, name)); !os.IsNotExist(statErr) {
|
|
t.Fatalf("removed SQLite backend created %s (stat error: %v)", name, statErr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestOpenBestAvailableRejectsRemovedBackends(t *testing.T) {
|
|
for _, backend := range []string{"postgres", "mysql", "sqlite"} {
|
|
t.Run(backend, func(t *testing.T) {
|
|
beadsDir := writeBackendMetadata(t, backend)
|
|
store, err := beads.OpenBestAvailable(context.Background(), beadsDir)
|
|
if store != nil {
|
|
_ = store.Close()
|
|
t.Fatalf("removed backend %q returned a store", backend)
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), "no longer supported") {
|
|
t.Fatalf("removed backend error = %v, want rollback explanation", err)
|
|
}
|
|
rationale := "resource-light"
|
|
if backend == "sqlite" {
|
|
rationale = "single engine"
|
|
}
|
|
if !strings.Contains(err.Error(), rationale) || !strings.Contains(err.Error(), "export") {
|
|
t.Fatalf("removed backend error lacks rationale or migration guidance: %v", err)
|
|
}
|
|
for _, name := range []string{"embeddeddolt", "dolt", "beads.db"} {
|
|
if _, statErr := os.Stat(filepath.Join(beadsDir, name)); !os.IsNotExist(statErr) {
|
|
t.Fatalf("removed backend created %s (stat error: %v)", name, statErr)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestOpenBestAvailableRejectsUnknownBackend(t *testing.T) {
|
|
beadsDir := writeBackendMetadata(t, "mystery")
|
|
store, err := beads.OpenBestAvailable(context.Background(), beadsDir)
|
|
if store != nil {
|
|
_ = store.Close()
|
|
t.Fatal("unknown backend returned a store")
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), "not recognized") {
|
|
t.Fatalf("unknown backend error = %v, want fail-closed metadata guidance", err)
|
|
}
|
|
if !strings.Contains(err.Error(), "no storage database was opened or modified") {
|
|
t.Fatalf("unknown backend error lacks data-safety guarantee: %v", err)
|
|
}
|
|
for _, name := range []string{"embeddeddolt", "dolt", "beads.db"} {
|
|
if _, statErr := os.Stat(filepath.Join(beadsDir, name)); !os.IsNotExist(statErr) {
|
|
t.Fatalf("unknown backend created %s (stat error: %v)", name, statErr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestOpenBestAvailableRejectsCorruptMetadata(t *testing.T) {
|
|
beadsDir := filepath.Join(t.TempDir(), ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0o750); err != nil {
|
|
t.Fatalf("create .beads: %v", err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(beadsDir, "metadata.json"), []byte("{"), 0o600); err != nil {
|
|
t.Fatalf("write metadata: %v", err)
|
|
}
|
|
|
|
store, err := beads.OpenBestAvailable(context.Background(), beadsDir)
|
|
if store != nil {
|
|
_ = store.Close()
|
|
t.Fatal("corrupt metadata unexpectedly returned a store")
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), "metadata") {
|
|
t.Fatalf("corrupt metadata error = %v, want metadata load failure", err)
|
|
}
|
|
if _, statErr := os.Stat(filepath.Join(beadsDir, "embeddeddolt")); !os.IsNotExist(statErr) {
|
|
t.Fatalf("corrupt metadata created embedded Dolt storage (stat error: %v)", statErr)
|
|
}
|
|
}
|