fix(embeddeddolt): keep gate notes in blunt lenient warning (bd-1z1pc)
An embedded read-only or working-set command that hits a blunt remote migrate gate stop prints a lenient warning and continues. That warning swapped UserMessage's guidance body for the shorter shared migrate-or-adopt guidance by rebuilding the text as Error() plus the guidance, which also dropped everything UserMessage appends after the body: the smart gate's fallback-reason note (#4516) and the note for a set-but-unrecognized BD_ALLOW_REMOTE_MIGRATE value. Server mode's lenient warning prints UserMessage() and keeps both. So the same stop told an embedded user less: not whether the smart gate fell back because the remote's schema state was unreadable, the database is below the convergence floor, or BD_SMART_GATE=0 turned it off (each needs a different next step), and not that a mistyped consent value did not unlock the migration. Move those trailing notes out of UserMessage into RemoteMigrateGateError.Notes(), which UserMessage now appends (its output is unchanged), and append them after the shared guidance in the blunt arm, in the order server mode prints them. A blunt stop with neither note renders byte-for-byte as before. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3862b03ff5
commit
3a37baf745
3 changed files with 71 additions and 3 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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" +
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue