rony-llm-agent/pkg/persona/persona_test.go
Victor Vargas 0f835a0802 feat(agent): wire AGENTS.md discovery into the agent loop's system prompt
Export persona.DiscoverAgentsMD and add agent.Config.AgentsMD so project
and global AGENTS.md rules actually reach the model. Previously
buildInitialMessages always called AssembleSystemPrompt with an empty
string, so no AGENTS.md content was ever injected despite the discovery
logic already existing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-08 23:27:17 -07:00

68 lines
1.8 KiB
Go

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