From 742ced7970ccecac078f7250efe4ebba293e8d5f Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 15 Jun 2026 09:52:13 -0400 Subject: [PATCH] test(go): assert ping echo in JSON output; comment ping fallback TestRunPingJSON now verifies the fake gateway's echoed text appears in the serialised reply body, catching any future wiring regression that maps PingRaw to the wrong proto field. runPing gains a one-line comment explaining why DiagnosticMessage carries the echo, why the kind-string fallback exists, and why writeCommandOutput is not reused on the plain-text path. --- clients/go/cmd/mxgw-go/main.go | 5 +++++ clients/go/cmd/mxgw-go/main_test.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/clients/go/cmd/mxgw-go/main.go b/clients/go/cmd/mxgw-go/main.go index 768ea8c..3604d40 100644 --- a/clients/go/cmd/mxgw-go/main.go +++ b/clients/go/cmd/mxgw-go/main.go @@ -263,6 +263,11 @@ func runPing(ctx context.Context, args []string, stdout, stderr io.Writer) error Reply: mustMarshalProto(reply), }) } + // DiagnosticMessage carries the echoed ping text set by the gateway. + // Fall back to the kind string when the gateway returns an empty message + // (forward-compat guard for future gateway versions). writeCommandOutput + // is not reused here because it would print the opaque Kind enum rather + // than the human-readable echo. echo := reply.GetDiagnosticMessage() if echo == "" { echo = reply.GetKind().String() diff --git a/clients/go/cmd/mxgw-go/main_test.go b/clients/go/cmd/mxgw-go/main_test.go index 4e02a39..efbe9c4 100644 --- a/clients/go/cmd/mxgw-go/main_test.go +++ b/clients/go/cmd/mxgw-go/main_test.go @@ -255,6 +255,13 @@ func TestRunPingJSON(t *testing.T) { if out.Command != "ping" { t.Fatalf("command = %q, want %q", out.Command, "ping") } + // The fake gateway echoes "pong:" in diagnostic_message; verify the + // echo appears in the serialised reply so a future regression that wired + // PingRaw to the wrong proto field would be caught here. + replyStr := string(out.Reply) + if !strings.Contains(replyStr, "pong:hello") { + t.Fatalf("ping JSON reply missing echoed message %q; reply = %s", "pong:hello", replyStr) + } } // TestRunPingRequiresSessionID verifies the ping subcommand rejects missing session-id.