package services

import (
	"fmt"
	"testing"
)

func TestAutomaticReplyEchoIdentityIsScopedAndBounded(t *testing.T) {
	rememberAutomaticReply(501, "ai-echo-first")
	if !IsAutomaticReplyMessage(501, "ai-echo-first") || IsAutomaticReplyMessage(502, "ai-echo-first") || IsAutomaticReplyMessage(501, "") {
		t.Fatal("automatic echo identity leaked across numbers")
	}
	for i := 0; i < 4096; i++ {
		rememberAutomaticReply(501, fmt.Sprintf("bounded-echo-%d", i))
	}
	if IsAutomaticReplyMessage(501, "ai-echo-first") || !IsAutomaticReplyMessage(501, "bounded-echo-4095") {
		t.Fatal("outgoing ID cache did not rotate")
	}
}
