added test
This commit is contained in:
+21
-1
@@ -1161,9 +1161,23 @@ func TestALRunSubagent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestALSubagentDepthLimit(t *testing.T) {
|
func TestALSubagentDepthLimit(t *testing.T) {
|
||||||
// depth >= MAX_DEPTH must not spawn an HTTP request at all
|
// depth >= MAX_DEPTH must not spawn a child request; the LLM gets the
|
||||||
|
// depth-limit tool result and is expected to acknowledge and finish.
|
||||||
|
var n int
|
||||||
|
var mu sync.Mutex
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
mu.Lock()
|
||||||
|
n++
|
||||||
|
cur := n
|
||||||
|
mu.Unlock()
|
||||||
|
switch cur {
|
||||||
|
case 1:
|
||||||
w.Write([]byte(`{"choices":[{"message":{"role":"assistant","content":null,"tool_calls":[{"id":"c1","type":"function","function":{"name":"run_subagent","arguments":"{\"prompt\":\"deep\"}"}}]}}]}`))
|
w.Write([]byte(`{"choices":[{"message":{"role":"assistant","content":null,"tool_calls":[{"id":"c1","type":"function","function":{"name":"run_subagent","arguments":"{\"prompt\":\"deep\"}"}}]}}]}`))
|
||||||
|
case 2:
|
||||||
|
w.Write([]byte(`{"choices":[{"message":{"role":"assistant","content":"done"}}]}`))
|
||||||
|
default:
|
||||||
|
t.Errorf("unexpected request #%d (child must not be spawned)", cur)
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
|
|
||||||
@@ -1175,6 +1189,12 @@ func TestALSubagentDepthLimit(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("AL: %v", err)
|
t.Fatalf("AL: %v", err)
|
||||||
}
|
}
|
||||||
|
if n != 2 {
|
||||||
|
t.Errorf("expected exactly 2 LLM requests, got %d", n)
|
||||||
|
}
|
||||||
|
if got := last(msgs); got != "done" {
|
||||||
|
t.Errorf("last = %q, want done", got)
|
||||||
|
}
|
||||||
found := false
|
found := false
|
||||||
for _, m := range msgs {
|
for _, m := range msgs {
|
||||||
if m.Role == "tool" && m.Content != nil && strings.Contains(*m.Content, "depth limit") {
|
if m.Role == "tool" && m.Content != nil && strings.Contains(*m.Content, "depth limit") {
|
||||||
|
|||||||
Reference in New Issue
Block a user