diff --git a/internal/storage/embeddeddolt/lenient_gate_warning_test.go b/internal/storage/embeddeddolt/lenient_gate_warning_test.go index bb2053726..47e1de8d5 100644 --- a/internal/storage/embeddeddolt/lenient_gate_warning_test.go +++ b/internal/storage/embeddeddolt/lenient_gate_warning_test.go @@ -16,6 +16,13 @@ import ( // downgrading the case to a blunt refusal. const dataBehindFallbackReason = "data-behind" +// unreadableStateFallbackReason is the literal for the smart gate's +// unreadable-remote-state fallback, unexported in schema for the same reason. +// The fixture using it is guarded by its own UserMessage carrying the note +// this reason selects, so a drift here fails as a broken fixture rather than +// as a dropped note. +const unreadableStateFallbackReason = "unreadable-remote-state" + func TestLenientGateWarningBody_ShapedDecisions(t *testing.T) { tests := []struct { name string @@ -109,6 +116,9 @@ func TestLenientGateWarning_ComposedOutput(t *testing.T) { gateErr *schema.RemoteMigrateGateError wantDataBehind bool wantBody string + // wantNotes are lines the gate's UserMessage appends after its + // body, which server mode's warning therefore carries too. + wantNotes []string }{ { name: "blunt refusal", @@ -119,6 +129,37 @@ func TestLenientGateWarning_ComposedOutput(t *testing.T) { }, wantBody: "designated migrator", }, + { + // bd-1z1pc: the blunt arm swaps UserMessage's body for the + // shorter shared guidance, and must not drop the note naming + // why the smart gate fell back to this stop along with it. + // Decision stays empty and FallbackReason is set: the note is + // empty by design on the shaped decisions, so only a fallback + // stop reaches the arm that dropped it. + name: "blunt smart-gate fallback", + gateErr: &schema.RemoteMigrateGateError{ + CurrentVersion: 41, + LatestVersion: 42, + Pending: 1, + FallbackReason: unreadableStateFallbackReason, + }, + wantBody: "designated migrator", + wantNotes: []string{"Smart gate (#4516): it could not read the remote's cached schema state"}, + }, + { + // The other note UserMessage appends after its body, dropped by + // the same arm: a typo'd consent variable must not leave the + // operator believing they had unlocked the migration. + name: "blunt unrecognized consent env", + gateErr: &schema.RemoteMigrateGateError{ + CurrentVersion: 41, + LatestVersion: 42, + Pending: 1, + UnrecognizedEnv: "yes", + }, + wantBody: "designated migrator", + wantNotes: []string{schema.AllowRemoteMigrateEnv + "=yes is set but was not recognized"}, + }, { name: "data-behind fallback", gateErr: &schema.RemoteMigrateGateError{ @@ -170,6 +211,14 @@ func TestLenientGateWarning_ComposedOutput(t *testing.T) { if got := shape.gateErr.IsDataBehind(); got != shape.wantDataBehind { t.Fatalf("%s fixture: IsDataBehind() = %v, want %v — the fixture no longer builds the shape it names", shape.name, got, shape.wantDataBehind) } + // UserMessage is what server mode's lenient warning prints for the + // same stop (dolt.warnLenientOpenRefusal), so a wanted note it lacks + // is a broken fixture, not a dropped note. + for _, note := range shape.wantNotes { + if msg := shape.gateErr.UserMessage(); !strings.Contains(msg, note) { + t.Fatalf("%s fixture: UserMessage() lacks %q — the fixture no longer builds the shape it names; got:\n%s", shape.name, note, msg) + } + } for _, intent := range intents { t.Run(shape.name+"/"+intent.name, func(t *testing.T) { got := lenientGateWarning(intent.intent, shape.gateErr) @@ -199,6 +248,11 @@ func TestLenientGateWarning_ComposedOutput(t *testing.T) { if !strings.Contains(got, shape.wantBody) { t.Errorf("composed warning is missing the %s body text %q; got:\n%s", shape.name, shape.wantBody, got) } + for _, note := range shape.wantNotes { + if !strings.Contains(got, note) { + t.Errorf("composed warning dropped the note %q that server mode prints for the same stop; got:\n%s", note, got) + } + } }) } } diff --git a/internal/storage/embeddeddolt/store.go b/internal/storage/embeddeddolt/store.go index 842717273..337f3dc2b 100644 --- a/internal/storage/embeddeddolt/store.go +++ b/internal/storage/embeddeddolt/store.go @@ -87,11 +87,16 @@ const lenientSharedGateGuidance = " This is a coordination decision, not an aut // blunt gate refusals while allowing smart-gate decisions to explain their // narrower recovery. A non-empty Decision means UserMessage has a shaped body; // data-behind is the one shaped refusal deliberately represented as a fallback. +// The blunt arm swaps only UserMessage's body for the shared guidance and keeps +// the gate's Notes after it, where UserMessage (and so server mode) prints +// them: the smart gate's fallback reason is what tells an unreadable remote +// state apart from a below-floor database or a BD_SMART_GATE=0 opt-out, and +// each calls for a different next step (bd-1z1pc). func lenientGateWarningBody(gateErr *schema.RemoteMigrateGateError) string { if gateErr.Decision != "" || gateErr.IsDataBehind() { return "Warning: " + gateErr.UserMessage() } - return "Warning: " + gateErr.Error() + "\n" + lenientSharedGateGuidance + return "Warning: " + gateErr.Error() + "\n" + lenientSharedGateGuidance + gateErr.Notes() } // openIntent classifies why a store is being opened. openStrict fails the diff --git a/internal/storage/schema/remote_migrate_gate.go b/internal/storage/schema/remote_migrate_gate.go index 0d6075dd6..a5e56cd5b 100644 --- a/internal/storage/schema/remote_migrate_gate.go +++ b/internal/storage/schema/remote_migrate_gate.go @@ -253,8 +253,17 @@ func FormatMigrationVersions(versions []int) string { // UserMessage returns the full multi-line error block for terminal output. func (e *RemoteMigrateGateError) UserMessage() string { - msg := e.Error() + "\n" + e.userBody() - msg += e.fallbackReasonNote() + return e.Error() + "\n" + e.userBody() + e.Notes() +} + +// Notes returns what UserMessage appends after its guidance body: the smart +// gate's reason for falling back to this stop (fallbackReasonNote) and a +// set-but-unrecognized AllowRemoteMigrateEnv value. Empty when neither +// applies. A renderer that pairs Error() with guidance of its own instead of +// userBody (embeddeddolt's lenient-open warning) appends it, so swapping the +// body does not drop these diagnostics with it (bd-1z1pc). +func (e *RemoteMigrateGateError) Notes() string { + msg := e.fallbackReasonNote() if e.UnrecognizedEnv != "" { msg += "\n" + " Note: " + AllowRemoteMigrateEnv + "=" + e.UnrecognizedEnv + " is set but was not recognized —\n" +