Rebase of PR #4601 (feat/choose-your-own-backend) onto current origin/main, squashed to a single commit because the original 73-commit history built and then removed the uowStore derisk spike incrementally, which does not replay cleanly over the 125 commits main has since advanced (notably #4679, the ready-work counts fix, which merged to main and is now inherited rather than re-applied). The full pre-rebase history remains on the original branch tip for reference. Contents (multi-backend feature + the six review follow-ups): - bd init --backend=postgres|mysql|sqlite provisioning behind the Dolt-parity seam; the three SQL backends share *sqlkit.Store over pluggable dialects and carry a generated typed-unsupported shell for the non-core surface. - Passwords in init DSNs are redacted before persisting to metadata.json (driver parser + re-parse verification), with a negative-test matrix proving no secret survives (pgdialect + mysql). - The uowStore derisk spike and its report artifacts are removed; the shell generator now lives in internal/storage/unsupportedgen (neutral name). - Compile-time guard `var _ storage.DoltStorage = (*Store)(nil)` on each backend plus a regen-idempotence test keep the generated skip lists honest. - sqlkit exposes CountReadyWork so every SQL backend satisfies storage.ReadyWorkCounter and inherits the shared page-pushed ready-counts path. - Commercial/product names scrubbed from the feature's own code for vendor neutrality. Rebase reconciliations: adopted main's metadata-load hardening in the store factories alongside the backend dispatch; combined the config interface (GetMetadata + ReconcileVersion) and the conformance registrations (ReadyCounts + Claim/lease); took main's versions of the shared-infra concurrency (uow doltserver_tx) and delete-cascade (domain/issue_delete) evolutions; implemented the interface's new UnclaimIssue on sqlkit (delegating to issueops) and added it to the skip lists. Verified: go build (cgo + CGO_ENABLED=0) and go vet clean; unit tests (sqlbuild/issueops/pgdialect/mysql/unsupportedgen) and the SQLite conformance suite green (RunAll, incl. ReadyCounts equivalence and Claim/lease on the real sqlkit backend). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
89 lines
3 KiB
Go
89 lines
3 KiB
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/storage/conformance"
|
|
"github.com/steveyegge/beads/internal/storage/pgdialect"
|
|
)
|
|
|
|
// TestConformance runs bd's backend-agnostic storage conformance suite
|
|
// (internal/storage/conformance, ~40 encoded behavior tests) against the
|
|
// Postgres wedge. This is the real conformance measurement — far broader than
|
|
// the smoke. Every failure is a PG gap: either an allowlisted-unsupported method
|
|
// (expected — see completeness_test.go) or a latent divergence nothing else
|
|
// caught (the interesting ones). Gated on BEADS_PG_TEST_URL.
|
|
func TestConformance(t *testing.T) {
|
|
url := os.Getenv("BEADS_PG_TEST_URL")
|
|
if url == "" {
|
|
t.Skip("BEADS_PG_TEST_URL not set")
|
|
}
|
|
conformance.RunAll(t, pgConformanceFactory(url))
|
|
}
|
|
|
|
// TestDeferredReads runs the shared deferred non-version-control reads (statistics,
|
|
// external-ref, stale) that the wedge now implements through issueops, as a GREEN
|
|
// gate. RunAll stays the fail-loud measurement (red on genuinely Dolt-only methods
|
|
// like slots), so this focused gate is what conformance.sh runs for the wedge.
|
|
// Gated on BEADS_PG_TEST_URL.
|
|
func TestDeferredReads(t *testing.T) {
|
|
url := os.Getenv("BEADS_PG_TEST_URL")
|
|
if url == "" {
|
|
t.Skip("BEADS_PG_TEST_URL not set")
|
|
}
|
|
conformance.RunDeferredReads(t, pgConformanceFactory(url))
|
|
}
|
|
|
|
// TestPortableMethods runs the full portable-method behavior contract (molecule/
|
|
// repo-mtime/streams/counts/comment/rekey/batch). Red until the methods are wired into
|
|
// sqlkit; green after. Gated on BEADS_PG_TEST_URL.
|
|
func TestPortableMethods(t *testing.T) {
|
|
url := os.Getenv("BEADS_PG_TEST_URL")
|
|
if url == "" {
|
|
t.Skip("BEADS_PG_TEST_URL not set")
|
|
}
|
|
conformance.RunPortableMethods(t, pgConformanceFactory(url))
|
|
}
|
|
|
|
// pgConformanceFactory provisions a fresh, isolated schema per sub-test against the
|
|
// Postgres server at url, seeded with issue_prefix as `bd init` leaves it.
|
|
func pgConformanceFactory(url string) conformance.Factory {
|
|
base := time.Now().UnixNano()
|
|
var seq int64
|
|
return func(t *testing.T) storage.DoltStorage {
|
|
ctx := context.Background()
|
|
schema := fmt.Sprintf("conf_%d_%d", base, atomic.AddInt64(&seq, 1))
|
|
|
|
raw, err := pgdialect.OpenRaw(url, schema)
|
|
if err != nil {
|
|
t.Fatalf("OpenRaw: %v", err)
|
|
}
|
|
if err := InitSchema(ctx, raw, schema); err != nil {
|
|
_ = raw.Close()
|
|
t.Fatalf("InitSchema: %v", err)
|
|
}
|
|
_ = raw.Close()
|
|
|
|
st, err := New(ctx, Config{DSN: url, Schema: schema})
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
// The conformance factory contract wants an init'd store (issue_prefix
|
|
// set), as `bd init` leaves it. No Commit — PG has no commit graph.
|
|
if err := st.SetConfig(ctx, "issue_prefix", "test"); err != nil {
|
|
t.Fatalf("SetConfig(issue_prefix): %v", err)
|
|
}
|
|
t.Cleanup(func() {
|
|
_, _ = st.DB().ExecContext(context.Background(),
|
|
fmt.Sprintf(`DROP SCHEMA IF EXISTS %q CASCADE`, schema))
|
|
_ = st.Close()
|
|
})
|
|
return st
|
|
}
|
|
}
|