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

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 <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 17:16:05 +01:00
parent 9e5afb3d69
commit bcdce246f6
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -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{