improved tool debugging

This commit is contained in:
Luxferre
2026-03-22 12:01:29 +02:00
parent 77d0d17c89
commit cd2de78c2c
16 changed files with 986 additions and 592 deletions
+48 -16
View File
@@ -25,14 +25,24 @@ func TestBufferGate(t *testing.T) {
var tfs []string
threshold := 10
s := "small"
if o, _ := BufferGate(s, &tfs, threshold); o != s { t.Errorf("expected small") }
if o, _ := BufferGate(s, &tfs, threshold); o != s {
t.Errorf("expected small")
}
l := strings.Repeat("A", threshold+1)
o, err := BufferGate(l, &tfs, threshold)
if err != nil { t.Fatalf("err: %v", err) }
if !strings.Contains(o, "file '") { t.Errorf("no file pointer") }
if len(tfs) != 1 { t.Fatalf("no temp file") }
if err != nil {
t.Fatalf("err: %v", err)
}
if !strings.Contains(o, "file '") {
t.Errorf("no file pointer")
}
if len(tfs) != 1 {
t.Fatalf("no temp file")
}
c, _ := os.ReadFile(tfs[0])
if string(c) != l { t.Errorf("content mismatch") }
if string(c) != l {
t.Errorf("content mismatch")
}
os.Remove(tfs[0])
}
@@ -40,15 +50,21 @@ func TestJSONActionParsing(t *testing.T) {
a := &Sidekick{}
m := Message{Content: `{"action": "RESPOND", "params": {"response": "Hi"}}`}
act, p, ok, err := a.parseAction(m)
if err != nil || !ok || act != ActionTypeRespond { t.Errorf("parse fail") }
if p["response"] != "Hi" { t.Errorf("param mismatch") }
if err != nil || !ok || act != ActionTypeRespond {
t.Errorf("parse fail")
}
if p["response"] != "Hi" {
t.Errorf("param mismatch")
}
}
func TestDualResponseMode(t *testing.T) {
a := &Sidekick{}
m := Message{ToolCalls: []ToolCall{{Function: FunctionCall{Name: "rf", Arguments: "{}"}}}}
act, _, ok, _ := a.parseAction(m)
if !ok || act != ActionTypeToolCall { t.Errorf("dual fail") }
if !ok || act != ActionTypeToolCall {
t.Errorf("dual fail")
}
}
func TestSingleAgentLoop(t *testing.T) {
@@ -60,7 +76,9 @@ func TestSingleAgentLoop(t *testing.T) {
}}
SetLLMClient(mc)
ans, _ := a.Run(context.Background(), nil, nil)
if ans != "Done" { t.Errorf("expected Done, got %s", ans) }
if ans != "Done" {
t.Errorf("expected Done, got %s", ans)
}
}
func TestDelegation(t *testing.T) {
@@ -76,7 +94,9 @@ func TestDelegation(t *testing.T) {
SetLLMClient(mc)
p := map[string]*Sidekick{"s1": sa}
ans, _ := coord.Run(context.Background(), nil, p)
if ans != "Coord done" { t.Errorf("expected Coord done, got %s", ans) }
if ans != "Coord done" {
t.Errorf("expected Coord done, got %s", ans)
}
}
func TestShellExecRegistration(t *testing.T) {
@@ -99,9 +119,11 @@ func TestTempFileCleanup(t *testing.T) {
threshold := 10
a := NewSidekick(AgentConfig{MaxIterations: 2, ToolResponseThreshold: threshold}, ModelConfig{}, nil)
h := strings.Repeat("B", threshold+1)
a.ToolRegistry["huge"] = ToolDefinition{Name: "huge", Internal: true, Handler: func(m map[string]interface{}) (string, error) {
return h, nil
}}
a.ToolRegistry["huge"] = ToolDefinition{
Name: "huge", Internal: true,
Handler: func(m map[string]interface{}) (string, error) {
return h, nil
}}
a.ToolMapping["huge"] = "huge"
mc := &mockLLMClient{responses: []Message{
{Content: `{"action": "TOOL_CALL", "params": {"tool_name": "huge", "arguments": {}}}`},
@@ -112,7 +134,17 @@ func TestTempFileCleanup(t *testing.T) {
a.Run(context.Background(), nil, nil)
afs, _ := os.ReadDir(os.TempDir())
bc, ac := 0, 0
for _, f := range bfs { if strings.HasPrefix(f.Name(), "sidekick-buf-") { bc++ } }
for _, f := range afs { if strings.HasPrefix(f.Name(), "sidekick-buf-") { ac++ } }
if ac > bc { t.Errorf("leak: before %d, after %d", bc, ac) }
for _, f := range bfs {
if strings.HasPrefix(f.Name(), "sidekick-buf-") {
bc++
}
}
for _, f := range afs {
if strings.HasPrefix(f.Name(), "sidekick-buf-") {
ac++
}
}
if ac > bc {
t.Errorf("leak: before %d, after %d", bc, ac)
}
}