rony-llm-agent/pkg/persona/persona_test.go

69 lines
1.8 KiB
Go
Raw Normal View History

package persona
import (
"context"
"os"
"path/filepath"
"testing"
)
func TestDefaultPersona(t *testing.T) {
p := DefaultPersona()
if p.Name != "Rony" {
t.Errorf("expected name 'Rony', got %q", p.Name)
}
if p.Tone != "professional and helpful" {
t.Errorf("expected tone 'professional and helpful', got %q", p.Tone)
}
}
func TestAssembleSystemPrompt(t *testing.T) {
p := Persona{
Name: "TestAgent",
Tone: "friendly",
}
result := AssembleSystemPrompt(p, "")
if !contains(result, "TestAgent") {
t.Error("expected system prompt to contain persona name")
}
if !contains(result, "friendly") {
t.Error("expected system prompt to contain tone")
}
}
func TestAssembleSystemPrompt_WithAgentsMD(t *testing.T) {
p := DefaultPersona()
agentsMD := "This is the project instructions."
result := AssembleSystemPrompt(p, agentsMD)
if !contains(result, agentsMD) {
t.Error("expected system prompt to contain AGENTS.md content")
}
}
func TestDiscoverAgentsMD(t *testing.T) {
tmpDir := t.TempDir()
agentsPath := filepath.Join(tmpDir, "AGENTS.md")
os.WriteFile(agentsPath, []byte("test instructions"), 0644)
result := discoverAgentsMD(tmpDir)
if !contains(result, "test instructions") {
t.Error("expected discoverAgentsMD to find AGENTS.md")
}
}
func TestLoader_Discover_NoFile(t *testing.T) {
loader := NewYAMLLoader()
ctx := context.Background()
p, err := loader.Discover(ctx, "/tmp/nonexistent_12345")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if p.Name != "Rony" {
t.Errorf("expected default persona, got %q", p.Name)
}
}
func contains(haystack, needle string) bool {
return len(haystack) > 0 && len(needle) > 0 && len(haystack) >= len(needle) && haystack[:len(needle)] == needle || len(haystack) > len(needle) && contains(haystack[1:], needle)
}