From bcdce246f67e7e94c512edac69614b73154a5f45 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 17:16:05 +0100 Subject: [PATCH] ax(node): add missing _Bad and _Ugly tests for TestMessage_Reply AX Principle 10 requires all three categories (Good, Bad, Ugly) for every test function. TestMessage_Reply had only _Good; adds _Bad (unmarshalable payload propagates error) and _Ugly (self-to-self addressing preserves correct From/To reversal). Co-Authored-By: Charon --- pkg/node/message_test.go | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkg/node/message_test.go b/pkg/node/message_test.go index a519ebd..69363c9 100644 --- a/pkg/node/message_test.go +++ b/pkg/node/message_test.go @@ -89,6 +89,51 @@ func TestMessage_Reply_Good(t *testing.T) { } } +// TestMessage_Reply_Bad verifies that Reply returns an error when the payload cannot be marshalled. +// +// original, _ := NewMessage(MsgPing, "sender", "receiver", nil) +// _, err := original.Reply(MsgPong, make(chan int)) // unmarshalable type +// if err == nil { t.Error("expected error for unmarshalable payload") } +func TestMessage_Reply_Bad(t *testing.T) { + original, err := NewMessage(MsgPing, "sender", "receiver", nil) + if err != nil { + t.Fatalf("failed to create original message: %v", err) + } + + // A channel cannot be marshalled to JSON — Reply must propagate the error. + _, replyErr := original.Reply(MsgPong, make(chan int)) + if replyErr == nil { + t.Error("expected error when payload cannot be marshalled, got nil") + } +} + +// TestMessage_Reply_Ugly verifies that Reply correctly reverses From/To even when both are identical. +// +// original, _ := NewMessage(MsgPing, "self", "self", nil) +// reply, err := original.Reply(MsgPong, nil) +// if reply.From != "self" || reply.To != "self" { t.Error("from/to should both be 'self'") } +func TestMessage_Reply_Ugly(t *testing.T) { + original, err := NewMessage(MsgPing, "self", "self", nil) + if err != nil { + t.Fatalf("failed to create original message: %v", err) + } + + reply, replyErr := original.Reply(MsgPong, nil) + if replyErr != nil { + t.Fatalf("unexpected error: %v", replyErr) + } + + if reply.From != "self" { + t.Errorf("expected From 'self', got '%s'", reply.From) + } + if reply.To != "self" { + t.Errorf("expected To 'self', got '%s'", reply.To) + } + if reply.ReplyTo != original.ID { + t.Errorf("expected ReplyTo '%s', got '%s'", original.ID, reply.ReplyTo) + } +} + func TestMessage_ParsePayload_Good(t *testing.T) { t.Run("ValidPayload", func(t *testing.T) { payload := StartMinerPayload{