From 3e48734e7edac73cbd4ae0fd9047e5f3862db234 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 17:38:04 +0100 Subject: [PATCH] ax(node): add missing _Bad and _Ugly test variants for TestMessage_NewMessage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AX Principle 10 (CLI tests as artifact validation) requires all three test categories — Good, Bad, Ugly — to be mandatory. TestMessage_NewMessage had only _Good; add _Bad (unmarshalable payload returns error) and _Ugly (empty From/To fields succeed and produce a valid message ID). Co-Authored-By: Charon --- pkg/node/message_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/node/message_test.go b/pkg/node/message_test.go index 69363c9..4c0b4a6 100644 --- a/pkg/node/message_test.go +++ b/pkg/node/message_test.go @@ -60,6 +60,37 @@ func TestMessage_NewMessage_Good(t *testing.T) { }) } +// TestMessage_NewMessage_Bad verifies that NewMessage returns an error when the payload cannot be marshalled. +// +// _, err := NewMessage(MsgPing, "sender", "receiver", make(chan int)) +// if err == nil { t.Error("expected error for unmarshalable payload") } +func TestMessage_NewMessage_Bad(t *testing.T) { + // A channel cannot be marshalled to JSON — NewMessage must propagate the error. + _, err := NewMessage(MsgPing, "sender-id", "receiver-id", make(chan int)) + if err == nil { + t.Error("expected error when payload cannot be marshalled, got nil") + } +} + +// TestMessage_NewMessage_Ugly verifies that NewMessage succeeds with empty From/To fields. +// +// msg, err := NewMessage(MsgPing, "", "", nil) +// if err != nil { t.Fatalf("unexpected error: %v", err) } +// if msg.ID == "" { t.Error("message ID should not be empty even with empty from/to") } +func TestMessage_NewMessage_Ugly(t *testing.T) { + // Empty From/To should not cause an error — callers control routing. + msg, err := NewMessage(MsgPing, "", "", nil) + if err != nil { + t.Fatalf("unexpected error with empty from/to: %v", err) + } + if msg.ID == "" { + t.Error("message ID should not be empty even with empty from/to") + } + if msg.Type != MsgPing { + t.Errorf("expected type MsgPing, got %s", msg.Type) + } +} + func TestMessage_Reply_Good(t *testing.T) { original, _ := NewMessage(MsgPing, "sender", "receiver", PingPayload{SentAt: 12345})