Files
HomeAgent/internal/memory/clean_text_test.go
root 3fc2151588 refactor: pluginize text cleaning and tool NoMemory control
- SDK: ToolDef.NoMemory field, PluginSDK.RegisterTextCleaner/TextCleaners
- Registry: aggregate text cleaners from plugins, expose CleanText()
- Memory: replace hardcoded QQ regex CleanTemplateText with dynamic CleanText/SetTextCleaner
- StageHost: add ToolDef(name) lookup
- eventloop: check ToolDef.NoMemory before emitMemoryCandidate
- context/Prune: replace hardcoded agentcli/terminal source filter with ToolsUsed NoMemory check
- agentcli/cmd: mark tools with NoMemory: true
- main.go: wire memory.SetTextCleaner(pluginReg.CleanText)
2026-07-24 14:49:08 +08:00

84 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package memory
import (
"testing"
)
func TestCleanTextTrim(t *testing.T) {
prev := globalTextCleaner
globalTextCleaner = nil
defer func() { globalTextCleaner = prev }()
tests := []struct {
input string
expected string
}{
{" hello ", "hello"},
{",hello", "hello"},
{",,hello", "hello"},
{" ,,hello ", "hello"},
{"", ""},
{" ", ""},
{",", ""},
{",x", "x"},
}
for _, tt := range tests {
got := CleanText(tt.input)
if got != tt.expected {
t.Errorf("CleanText(%q) = %q, want %q", tt.input, got, tt.expected)
}
}
}
func TestCleanTextWithRegisteredCleaner(t *testing.T) {
prev := globalTextCleaner
globalTextCleaner = func(text string) string {
return "prefix_" + text
}
defer func() { globalTextCleaner = prev }()
got := CleanText(" hello ")
if got != "prefix_ hello" {
t.Errorf("CleanText with cleaner = %q, want %q", got, "prefix_ hello")
}
}
func TestCleanTextCleanerChain(t *testing.T) {
prev := globalTextCleaner
globalTextCleaner = func(text string) string {
text = text + "_step1"
text = text + "_step2"
return text
}
defer func() { globalTextCleaner = prev }()
got := CleanText("test")
if got != "test_step1_step2" {
t.Errorf("CleanText chain = %q, want %q", got, "test_step1_step2")
}
}
func TestSetTextCleanerReplace(t *testing.T) {
prev := globalTextCleaner
globalTextCleaner = func(text string) string { return "old_" + text }
SetTextCleaner(func(text string) string { return "new_" + text })
defer func() { globalTextCleaner = prev }()
got := CleanText("x")
if got != "new_x" {
t.Errorf("after SetTextCleaner = %q, want %q", got, "new_x")
}
}
func TestCleanTextEmptyAfterCleaner(t *testing.T) {
prev := globalTextCleaner
globalTextCleaner = func(text string) string { return "" }
defer func() { globalTextCleaner = prev }()
got := CleanText("something")
if got != "" {
t.Errorf("expected empty, got %q", got)
}
}