* test: consolidate embedded migrate journeys (bd-1rh.5) Reduce TestEmbeddedMigrate from 17 full bd init calls to five while retaining distinct CLI and persistence boundaries with stricter JSON and readback assertions. Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of CI Bot * test: make migrate JSON assertions config-independent (bd-1rh.5) Use the explicit root JSON flag in strict migrate journeys so clean CI cannot mask or trigger the known migrate-local flag-shadowing bug. Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of CI Bot * test: make migrate JSON harness deterministic (bd-1rh.5) Use the unique root --format=json alias so migrate local flags cannot shadow explicit JSON selection. Treat the second fresh migrate process as the persistence readback instead of crossing into the YAML-only config-get plane. Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of CI Bot --------- Co-authored-by: CI Bot <ci@beads.test>
90 lines
3 KiB
Go
90 lines
3 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/storage/dolt"
|
|
)
|
|
|
|
// TestMigrateCommand removed: detectDatabases, getDBVersion, formatDBList, dbInfo
|
|
// were removed in Dolt-native pruning. Migration is now handled by bd init --from-jsonl.
|
|
|
|
// TestFormatDBList removed: formatDBList and dbInfo types were removed.
|
|
|
|
func TestMigrateSchemaFlagBoundaries(t *testing.T) {
|
|
// Registration only: strict subprocess tests use the unique root persistent
|
|
// --format=json alias because duplicate local --json registration can shadow
|
|
// whether PersistentPreRunE sees the root flag as explicitly set.
|
|
for _, name := range []string{"inspect", "dry-run"} {
|
|
if flag := migrateSchemaCmd.Flags().Lookup(name); flag != nil {
|
|
t.Errorf("migrate schema unexpectedly registers local --%s", name)
|
|
}
|
|
}
|
|
for _, name := range []string{"json", "force"} {
|
|
if flag := migrateSchemaCmd.Flags().Lookup(name); flag == nil {
|
|
t.Errorf("migrate schema must register local --%s", name)
|
|
}
|
|
}
|
|
if flag := rootCmd.PersistentFlags().Lookup("json"); flag == nil {
|
|
t.Error("root command must register persistent --json")
|
|
}
|
|
if flag := rootCmd.PersistentFlags().Lookup("format"); flag == nil {
|
|
t.Error("root command must register persistent --format")
|
|
}
|
|
}
|
|
|
|
func TestMigrateRespectsConfigJSON(t *testing.T) {
|
|
t.Skip("SQLite-specific: Dolt backend always uses 'dolt' directory, not custom database filenames")
|
|
// Test that migrate respects custom database name from metadata.json
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0750); err != nil {
|
|
t.Fatalf("Failed to create .beads directory: %v", err)
|
|
}
|
|
|
|
// Create metadata.json with custom database name
|
|
configPath := filepath.Join(beadsDir, "metadata.json")
|
|
configData := `{"database": "beady.db", "version": "0.21.1"}`
|
|
if err := os.WriteFile(configPath, []byte(configData), 0600); err != nil {
|
|
t.Fatalf("Failed to create metadata.json: %v", err)
|
|
}
|
|
|
|
// Create old database with custom name
|
|
oldDBPath := filepath.Join(beadsDir, "beady.db")
|
|
store, err := dolt.New(context.Background(), &dolt.Config{Path: oldDBPath})
|
|
if err != nil {
|
|
t.Skipf("skipping: Dolt server not available: %v", err)
|
|
}
|
|
ctx := context.Background()
|
|
if err := store.SetLocalMetadata(ctx, "bd_version", "0.21.1"); err != nil {
|
|
t.Fatalf("Failed to set version: %v", err)
|
|
}
|
|
_ = store.Close()
|
|
|
|
// Load config
|
|
cfg, err := loadOrCreateConfig(beadsDir)
|
|
if err != nil {
|
|
t.Fatalf("Failed to load config: %v", err)
|
|
}
|
|
|
|
// Verify config respects custom database name
|
|
if cfg.Database != "beady.db" {
|
|
t.Errorf("Expected database name 'beady.db', got %s", cfg.Database)
|
|
}
|
|
|
|
expectedPath := filepath.Join(beadsDir, "beady.db")
|
|
actualPath := cfg.DatabasePath(beadsDir)
|
|
if actualPath != expectedPath {
|
|
t.Errorf("Expected path %s, got %s", expectedPath, actualPath)
|
|
}
|
|
|
|
// Verify database exists at custom path
|
|
if _, err := os.Stat(actualPath); os.IsNotExist(err) {
|
|
t.Errorf("Database does not exist at custom path: %s", actualPath)
|
|
}
|
|
}
|