ollie/agent/agent_test.go

58 lines
1.6 KiB
Go

package agent
import (
"strings"
"testing"
)
func TestRefreshToolListing(t *testing.T) {
p := &Preamble{}
p.Set(SectionSystem, "# System")
p.Set(SectionEnv, "# Env")
p.Set(SectionAgent, "# Agent")
p.Set(SectionTools, "# Available Tools\n\n- **old_tool** — Old description\n")
p.Set(SectionToolDocs, "# Tool Documentation\n\n**old_tool**\n\nDocs...\n")
ag := &Agent{runtime: &Runtime{Preamble: p}}
ag.refreshToolListing("- **new_tool** — New description\n")
preamble := ag.runtime.PreambleString()
if !strings.Contains(preamble, "**new_tool** — New description") {
t.Error("should contain new tool listing")
}
if strings.Contains(preamble, "**old_tool** — Old description") {
t.Error("should not contain old tool listing")
}
// Tool docs section is untouched by refreshToolListing
if !strings.Contains(preamble, "# Tool Documentation") {
t.Error("tool docs should be preserved")
}
}
func TestRefreshToolListingEmpty(t *testing.T) {
p := &Preamble{}
p.Set(SectionSystem, "# System")
p.Set(SectionEnv, "# Env")
p.Set(SectionAgent, "# Agent")
p.Set(SectionTools, "# Available Tools\n\n- **tool** — Desc\n")
p.Set(SectionToolDocs, "# Tool Documentation\n\nDocs\n")
ag := &Agent{runtime: &Runtime{Preamble: p}}
ag.refreshToolListing("")
preamble := ag.runtime.PreambleString()
if strings.Contains(preamble, "# Available Tools") {
t.Error("empty listing should remove tools section")
}
if !strings.Contains(preamble, "# System") {
t.Error("system section should be preserved")
}
if !strings.Contains(preamble, "# Tool Documentation") {
t.Error("tool docs should be preserved")
}
}