2026-07-01 06:53:28 +00:00
|
|
|
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)
|
|
|
|
|
|
2026-07-09 06:27:17 +00:00
|
|
|
result := DiscoverAgentsMD(tmpDir)
|
2026-07-01 06:53:28 +00:00
|
|
|
if !contains(result, "test instructions") {
|
2026-07-09 06:27:17 +00:00
|
|
|
t.Error("expected DiscoverAgentsMD to find AGENTS.md")
|
2026-07-01 06:53:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|