ax(node): add missing _Bad and _Ugly test variants for TestMessage_NewMessage
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

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 <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 17:38:04 +01:00
parent 263b45db88
commit 3e48734e7e
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -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})