ollie/agent/agent_test.go

62 lines
1.4 KiB
Go

package agent
import (
"strings"
"testing"
"ollie/toolsrv"
)
func TestRefreshToolListing(t *testing.T) {
infos := []toolsrv.ToolInfo{
{
Name: "new_tool",
Description: "New description",
Prompt: "## new_tool\n\nNew description with details.",
},
}
p := &Preamble{}
p.Set(SectionSystem, "# System")
p.Set(SectionEnv, "# Env")
p.Set(SectionAgent, "# Agent")
p.Set(SectionTools, "# Tools\n\n## old_tool\n\nOld description\n\n")
// Test renderTools directly since refreshToolListing depends on ToolServer
rendered := renderTools(infos)
p.Set(SectionTools, rendered)
preamble := p.String()
if !strings.Contains(preamble, "## new_tool") {
t.Error("should contain new tool")
}
if !strings.Contains(preamble, "New description with details.") {
t.Error("should contain tool prompt/docs")
}
if strings.Contains(preamble, "old_tool") {
t.Error("should not contain old tool")
}
}
func TestRefreshToolListingEmpty(t *testing.T) {
p := &Preamble{}
p.Set(SectionSystem, "# System")
p.Set(SectionEnv, "# Env")
p.Set(SectionAgent, "# Agent")
p.Set(SectionTools, "# Tools\n\n## tool\n\nDesc\n\n")
ag := &Agent{runtime: &Runtime{Preamble: p}}
ag.refreshToolListing()
preamble := ag.runtime.PreambleString()
if strings.Contains(preamble, "# Tools") {
t.Error("empty listing should remove tools section")
}
if !strings.Contains(preamble, "# System") {
t.Error("system section should be preserved")
}
}