Optimize agent planning and subagent runtime

This commit is contained in:
lpf
2026-03-09 12:33:00 +08:00
parent acf8a22c0a
commit d1abd73e63
11 changed files with 984 additions and 108 deletions

View File

@@ -47,3 +47,29 @@ func TestSubagentRouterMergeResults(t *testing.T) {
t.Fatalf("unexpected merged output: %s", out)
}
}
func TestSubagentRouterWaitReplyContextCancel(t *testing.T) {
workspace := t.TempDir()
manager := NewSubagentManager(nil, workspace, nil)
manager.SetRunFunc(func(ctx context.Context, task *SubagentTask) (string, error) {
<-ctx.Done()
return "", ctx.Err()
})
router := NewSubagentRouter(manager)
task, err := router.DispatchTask(context.Background(), RouterDispatchRequest{
Task: "long task",
AgentID: "coder",
OriginChannel: "cli",
OriginChatID: "direct",
})
if err != nil {
t.Fatalf("dispatch failed: %v", err)
}
waitCtx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond)
defer cancel()
if _, err := router.WaitReply(waitCtx, task.ID, 20*time.Millisecond); err == nil {
t.Fatalf("expected context cancellation error")
}
}