fix subagent completion notify path and pipeline origin routing

This commit is contained in:
lpf
2026-03-05 22:17:44 +08:00
parent e8e1cdae32
commit b9e1efa3ef
5 changed files with 228 additions and 22 deletions

View File

@@ -3,8 +3,11 @@ package tools
import (
"context"
"errors"
"strings"
"testing"
"time"
"clawgo/pkg/bus"
)
func TestSubagentSpawnEnforcesTaskQuota(t *testing.T) {
@@ -105,6 +108,45 @@ func TestSubagentRunWithTimeoutFails(t *testing.T) {
}
}
func TestSubagentBroadcastIncludesFailureStatus(t *testing.T) {
workspace := t.TempDir()
msgBus := bus.NewMessageBus()
defer msgBus.Close()
manager := NewSubagentManager(nil, workspace, msgBus, nil)
manager.SetRunFunc(func(ctx context.Context, task *SubagentTask) (string, error) {
return "", errors.New("boom")
})
_, err := manager.Spawn(context.Background(), SubagentSpawnOptions{
Task: "failing task",
AgentID: "coder",
OriginChannel: "cli",
OriginChatID: "direct",
})
if err != nil {
t.Fatalf("spawn failed: %v", err)
}
task := waitSubagentDone(t, manager, 4*time.Second)
if task.Status != "failed" {
t.Fatalf("expected failed task, got %s", task.Status)
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
msg, ok := msgBus.ConsumeInbound(ctx)
if !ok {
t.Fatalf("expected subagent completion message")
}
if got := strings.TrimSpace(msg.Metadata["status"]); got != "failed" {
t.Fatalf("expected metadata status=failed, got %q", got)
}
if !strings.Contains(strings.ToLower(msg.Content), "failed") {
t.Fatalf("expected failure wording in content, got %q", msg.Content)
}
}
func waitSubagentDone(t *testing.T, manager *SubagentManager, timeout time.Duration) *SubagentTask {
t.Helper()
deadline := time.Now().Add(timeout)