PR #7561 (gascity mc-3gbed) let New() retry a declared endpoint when an env-inherited one fails the project identity check, but review found the fallback still left several holes open: - B1 (blocker): bd serve's provider arm builds its topology straight from resolveDoltServerConnection, never through dolt.New, so it got neither the identity check nor the fallback's correction — serve would migrate and front an inherited env endpoint's database with no check at all. Exported dolt.EnvEndpointDivergesFromDeclared (envEndpointFallback's own eligibility test, without an open) and wired it into resolveServerModeUOWTopologyWithTransportResolver as an outright refusal: serve cannot cheaply verify identity without the migration work this fix deliberately avoids, so it refuses instead of guessing. - S1: the retry now reapplies New()'s BEADS_TEST_MODE=1 production-port guard (rewrite-to-1, then panic if still production), since the retry calls newServerMode directly and bypassed it before. - S2: already satisfied — envEndpointFallback already excludes cfg.CreateIfMissing opens (GH#2336: init/bootstrap ignore config ports). - S3: already satisfied — a failed retry still returns errors.Join(err, altErr), keeping the original identity refusal primary and errors.As-able. - S4: the retry now re-resolves its own user/TLS from configfile.Load instead of carrying the env endpoint's values forward, and refuses to retry onto a non-loopback host. - S5: added tests for the gateway, global-database, shared-server-mode and empty-BeadsDir exclusions, config.yaml-vs-metadata.json precedence, a non-positive yaml port, the retry keeping the declared host (not the env host), New's own wiring through the fallback, the loopback restriction, and the retry's credential/production-port re-resolution. - L1: already satisfied — envEndpointFallback takes the pre-transport- resolution socket value, captured before ResolveSocketTransport can clear it. - Nits: the fallback note now respects --json (debug.SetJSON, wired from main's jsonOutput) and --quiet, and names the env var (BEADS_DOLT_SERVER_PORT vs. the legacy BEADS_DOLT_PORT) that actually supplied the port. newServerModeOpener (a var, like ensureRunningDetailed) lets a test swap New's opener to pin that New always goes through openWithEnvEndpointFallback, without dialing a real dolt sql-server. No schema change. Mutation testing (27 mutants spanning the fallback's exclusions, precedence, retry wiring, and the new S1/S4 guards): 26 killed, 1 survived (an untyped-error wrap inside verifyProjectIdentity's own call site, store.go, pre-existing and outside this diff — needs a live-server integration test to exercise, since it requires an actual mismatching database). Agent-Signature: claude-agent-sdk-claude-sonnet-5-80 on behalf of Julian Knutsen Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package debug
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
var (
|
|
enabled = os.Getenv("BD_DEBUG") != ""
|
|
verboseMode = false
|
|
quietMode = false
|
|
jsonMode = false
|
|
)
|
|
|
|
func Enabled() bool {
|
|
return enabled || verboseMode
|
|
}
|
|
|
|
// SetVerbose enables verbose/debug output
|
|
func SetVerbose(verbose bool) {
|
|
verboseMode = verbose
|
|
}
|
|
|
|
// SetQuiet enables quiet mode (suppress non-essential output)
|
|
func SetQuiet(quiet bool) {
|
|
quietMode = quiet
|
|
}
|
|
|
|
// IsQuiet returns true if quiet mode is enabled
|
|
func IsQuiet() bool {
|
|
return quietMode
|
|
}
|
|
|
|
// SetJSON marks that the command's output is machine-readable (--json or
|
|
// --format json). Callers outside the normal output path (e.g. an advisory
|
|
// note on a fallback) use IsJSON to stay out of a machine-readable stream.
|
|
func SetJSON(json bool) {
|
|
jsonMode = json
|
|
}
|
|
|
|
// IsJSON returns true if JSON output mode is enabled.
|
|
func IsJSON() bool {
|
|
return jsonMode
|
|
}
|
|
|
|
func Logf(format string, args ...interface{}) {
|
|
if enabled || verboseMode {
|
|
fmt.Fprintf(os.Stderr, format, args...)
|
|
}
|
|
}
|
|
|
|
func Printf(format string, args ...interface{}) {
|
|
if enabled || verboseMode {
|
|
fmt.Printf(format, args...)
|
|
}
|
|
}
|
|
|
|
// PrintNormal prints output unless quiet mode is enabled.
|
|
// Use this for normal informational output that should be suppressed in quiet mode.
|
|
func PrintNormal(format string, args ...interface{}) {
|
|
if !quietMode {
|
|
fmt.Printf(format, args...)
|
|
}
|
|
}
|
|
|
|
// PrintlnNormal prints a line unless quiet mode is enabled.
|
|
func PrintlnNormal(args ...interface{}) {
|
|
if !quietMode {
|
|
fmt.Println(args...)
|
|
}
|
|
}
|