85 lines
3.1 KiB
Go
85 lines
3.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRefreshToolListing(t *testing.T) {
|
|
// Create a test agent with minimal setup
|
|
ag := &Agent{
|
|
runtime: &Runtime{
|
|
Preamble: "# Core System Prompt\nTest\n# Environment\n- Test env\n# Agent Prompt\nTest instructions\n\n# Tool Sections\n\n# Available Tools\n\n- **old_tool** — Old description\n\n# Tool Documentation\n\n**old_tool**\n\nOld docs...\n\n**Schema**:\n```json\n{}\n```\n\n## Tool discovery\nInstructions...",
|
|
},
|
|
}
|
|
|
|
// Test 1: refreshToolListing with new listing
|
|
newListing := "- **new_tool** — New description\n"
|
|
ag.refreshToolListing(newListing)
|
|
|
|
// Should contain new listing
|
|
if !strings.Contains(ag.runtime.Preamble, "**new_tool** — New description") {
|
|
t.Error("refreshToolListing should include new tool in listing")
|
|
}
|
|
|
|
// Should NOT contain old listing
|
|
if strings.Contains(ag.runtime.Preamble, "**old_tool** — Old description") {
|
|
t.Error("refreshToolListing should remove old tool from listing")
|
|
}
|
|
|
|
// PROBLEM: Should contain tool documentation and discovery sections
|
|
// but current implementation removes them!
|
|
if !strings.Contains(ag.runtime.Preamble, "# Tool Documentation") {
|
|
t.Error("refreshToolListing currently removes # Tool Documentation section (BUG)")
|
|
}
|
|
if !strings.Contains(ag.runtime.Preamble, "## Tool discovery") {
|
|
t.Error("refreshToolListing currently removes Tool discovery section (BUG)")
|
|
}
|
|
}
|
|
|
|
func TestRefreshToolListingEmpty(t *testing.T) {
|
|
ag := &Agent{
|
|
runtime: &Runtime{
|
|
Preamble: "# Core System Prompt\nTest\n# Environment\n- Test env\n# Agent Prompt\nTest instructions\n\n# Tool Sections\n\n# Available Tools\n\n- **tool** — Description\n\n# Tool Documentation\n\n**tool**\n\nDocs...\n\n## Tool discovery\nInstructions...",
|
|
},
|
|
}
|
|
|
|
// Test with empty listing (all tools removed)
|
|
ag.refreshToolListing("")
|
|
|
|
// Should not contain tool sections marker
|
|
if strings.Contains(ag.runtime.Preamble, "# Available Tools") {
|
|
t.Error("refreshToolListing with empty listing should remove # Available Tools")
|
|
}
|
|
|
|
// Should still contain other sections
|
|
if !strings.Contains(ag.runtime.Preamble, "# Core System Prompt") {
|
|
t.Error("refreshToolListing should preserve core system prompt")
|
|
}
|
|
if !strings.Contains(ag.runtime.Preamble, "# Environment") {
|
|
t.Error("refreshToolListing should preserve environment section")
|
|
}
|
|
if !strings.Contains(ag.runtime.Preamble, "# Agent Prompt") {
|
|
t.Error("refreshToolListing should preserve agent prompt")
|
|
}
|
|
}
|
|
|
|
func TestRefreshToolListingNoToolsInitially(t *testing.T) {
|
|
ag := &Agent{
|
|
runtime: &Runtime{
|
|
Preamble: "# Core System Prompt\nTest\n# Environment\n- Test env\n# Agent Prompt\nTest instructions\n\n## Tool discovery\nInstructions...",
|
|
},
|
|
}
|
|
|
|
// Test adding tools when none existed before
|
|
newListing := "- **new_tool** — New description\n"
|
|
ag.refreshToolListing(newListing)
|
|
|
|
// Should now contain tool sections
|
|
if !strings.Contains(ag.runtime.Preamble, "# Available Tools") {
|
|
t.Error("refreshToolListing should add # Available Tools when none existed")
|
|
}
|
|
if !strings.Contains(ag.runtime.Preamble, "**new_tool** — New description") {
|
|
t.Error("refreshToolListing should include new tool")
|
|
}
|
|
} |