debug missing dolt database metadata (#4202)
* debug missing dolt database metadata When metadata.json exists without dolt_database, bd silently falls back to the default database name. Log the config discovery state under debug output so non-default database drift can be diagnosed without changing normal behavior. _codex-gpt-5.5-medium on behalf of matt wilkie_ * test config debug default database guard _codex-gpt-5.5-medium on behalf of matt wilkie_ --------- Co-authored-by: CI Bot <ci@beads.test>
This commit is contained in:
parent
5404cd688f
commit
e279a1c061
2 changed files with 95 additions and 6 deletions
|
|
@ -154,6 +154,19 @@ func loadBeadsEnvFile(beadsDir string) {
|
|||
_ = gotenv.Load(envFile)
|
||||
}
|
||||
|
||||
func logConfigDiscovery(beadsDir, reason string) {
|
||||
metadataPath := filepath.Join(beadsDir, configfile.ConfigFileName)
|
||||
configYAMLPath := filepath.Join(beadsDir, "config.yaml")
|
||||
_, metadataErr := os.Stat(metadataPath)
|
||||
_, yamlErr := os.Stat(configYAMLPath)
|
||||
debug.Logf("Debug: %s at %s -> metadata=%v (%v), config.yaml=%v (%v)\n",
|
||||
reason, beadsDir, metadataErr == nil, metadataErr, yamlErr == nil, yamlErr)
|
||||
}
|
||||
|
||||
func shouldLogDefaultDoltDatabase(cfg *configfile.Config) bool {
|
||||
return cfg != nil && cfg.DoltDatabase == "" && os.Getenv("BEADS_DOLT_SERVER_DATABASE") == ""
|
||||
}
|
||||
|
||||
// loadBeadsSelectionEnvFile loads only the selector keys needed for early
|
||||
// workspace/database discovery. Unlike loadBeadsEnvFile, this intentionally
|
||||
// limits itself to BEADS_DIR / BEADS_DB / BD_DB so caller credentials and
|
||||
|
|
@ -961,6 +974,9 @@ var rootCmd = &cobra.Command{
|
|||
// Always set database name (needed for bootstrap to find
|
||||
// prefix-based databases like "beads_hq"; see #1669)
|
||||
doltCfg.Database = cfg.GetDoltDatabase()
|
||||
if shouldLogDefaultDoltDatabase(cfg) {
|
||||
logConfigDiscovery(beadsDir, fmt.Sprintf("metadata loaded without dolt_database; using default database name %q", configfile.DefaultDoltDatabase))
|
||||
}
|
||||
|
||||
doltCfg.ServerHost = cfg.GetDoltServerHost()
|
||||
// Use doltserver.DefaultConfig for port resolution (env > port file >
|
||||
|
|
@ -973,12 +989,7 @@ var rootCmd = &cobra.Command{
|
|||
doltCfg.ServerPassword = cfg.GetDoltServerPasswordForPort(doltCfg.ServerPort)
|
||||
doltCfg.ServerTLS = cfg.GetDoltServerTLS()
|
||||
} else if cfgErr == nil {
|
||||
metadataPath := filepath.Join(beadsDir, configfile.ConfigFileName)
|
||||
configYAMLPath := filepath.Join(beadsDir, "config.yaml")
|
||||
_, metadataErr := os.Stat(metadataPath)
|
||||
_, yamlErr := os.Stat(configYAMLPath)
|
||||
debug.Logf("Debug: config discovery at %s -> metadata=%v (%v), config.yaml=%v (%v)\n",
|
||||
beadsDir, metadataErr == nil, metadataErr, yamlErr == nil, yamlErr)
|
||||
logConfigDiscovery(beadsDir, "config discovery")
|
||||
// Load returned (nil, nil) — no config file found.
|
||||
// Fall back to the canonical default database name; matches the
|
||||
// behavior of newDoltStoreFromConfig / newReadOnlyStoreFromConfig
|
||||
|
|
|
|||
78
cmd/bd/main_config_debug_test.go
Normal file
78
cmd/bd/main_config_debug_test.go
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/debug"
|
||||
)
|
||||
|
||||
func TestLogConfigDiscoveryIncludesMetadataAndYAMLState(t *testing.T) {
|
||||
beadsDir := t.TempDir()
|
||||
metadataPath := filepath.Join(beadsDir, configfile.ConfigFileName)
|
||||
if err := os.WriteFile(metadataPath, []byte(`{"database":"dolt"}`), 0o600); err != nil {
|
||||
t.Fatalf("write metadata: %v", err)
|
||||
}
|
||||
|
||||
debug.SetVerbose(true)
|
||||
defer debug.SetVerbose(false)
|
||||
|
||||
stderr := captureStderr(t, func() {
|
||||
logConfigDiscovery(beadsDir, "metadata loaded without dolt_database; using default database name \"beads\"")
|
||||
})
|
||||
|
||||
for _, want := range []string{
|
||||
`metadata loaded without dolt_database; using default database name "beads"`,
|
||||
"metadata=true",
|
||||
"config.yaml=false",
|
||||
} {
|
||||
if !strings.Contains(stderr, want) {
|
||||
t.Fatalf("debug output missing %q:\n%s", want, stderr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldLogDefaultDoltDatabase(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg *configfile.Config
|
||||
envDatabase string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "missing metadata database and env",
|
||||
cfg: &configfile.Config{},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "env database suppresses diagnostic",
|
||||
cfg: &configfile.Config{},
|
||||
envDatabase: "envdb",
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "metadata database suppresses diagnostic",
|
||||
cfg: &configfile.Config{
|
||||
DoltDatabase: "metadb",
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "nil config suppresses diagnostic",
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Setenv("BEADS_DOLT_SERVER_DATABASE", tt.envDatabase)
|
||||
|
||||
if got := shouldLogDefaultDoltDatabase(tt.cfg); got != tt.want {
|
||||
t.Fatalf("shouldLogDefaultDoltDatabase() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue