Files
Memoh/internal/chat/resolver_memory_context_test.go
T
BBQ ca5c6a1866 refactor(core): restructure conversation, channel and message domains
- Rename chat module to conversation with flow-based architecture
- Move channelidentities into channel/identities subpackage
- Add channel/route for routing logic
- Add message service with event hub
- Add MCP providers: container, directory, schedule
- Refactor Feishu/Telegram adapters with directory and stream support
- Add platform management page and channel badges in web UI
- Update database schema for conversations, messages and channel routes
- Add @memoh/shared package for cross-package type definitions
2026-02-12 15:34:40 +08:00

56 lines
1.3 KiB
Go

package conversation
import (
"context"
"log/slog"
"strings"
"testing"
"github.com/memohai/memoh/internal/memory"
)
func TestLoadMemoryContextMessage_NoMemoryService(t *testing.T) {
resolver := &Resolver{
memoryService: nil,
logger: slog.Default(),
}
msg := resolver.loadMemoryContextMessage(context.Background(), ChatRequest{
Query: "hello",
BotID: "bot-1",
ChatID: "chat-1",
})
if msg != nil {
t.Fatalf("expected nil message when memory service is nil")
}
}
func TestLoadMemoryContextMessage_SearchFailureFallback(t *testing.T) {
resolver := &Resolver{
memoryService: &memory.Service{},
logger: slog.Default(),
}
msg := resolver.loadMemoryContextMessage(context.Background(), ChatRequest{
Query: "hello",
BotID: "bot-1",
ChatID: "chat-1",
UserID: "user-1",
})
if msg != nil {
t.Fatalf("expected nil message when memory search cannot return results")
}
}
func TestTruncateMemorySnippet(t *testing.T) {
longText := strings.Repeat("a", 20) + " "
got := truncateMemorySnippet(longText, 10)
if got != strings.Repeat("a", 10)+"..." {
t.Fatalf("unexpected truncated value: %q", got)
}
shortText := " short "
got = truncateMemorySnippet(shortText, 10)
if got != "short" {
t.Fatalf("unexpected trimmed short value: %q", got)
}
}