From 3894f0e27a191d117cadf7133c79130dc99817e5 Mon Sep 17 00:00:00 2001 From: lpf Date: Thu, 5 Mar 2026 22:41:21 +0800 Subject: [PATCH] fix pipeline tool context origin injection --- pkg/agent/loop.go | 2 +- pkg/agent/loop_tool_context_test.go | 44 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 pkg/agent/loop_tool_context_test.go diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index dc48254..bd4ad1f 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -1560,7 +1560,7 @@ func withToolContextArgs(toolName string, args map[string]interface{}, channel, return args } switch toolName { - case "message", "spawn", "remind": + case "message", "spawn", "remind", "pipeline_create", "pipeline_dispatch": default: return args } diff --git a/pkg/agent/loop_tool_context_test.go b/pkg/agent/loop_tool_context_test.go new file mode 100644 index 0000000..851f516 --- /dev/null +++ b/pkg/agent/loop_tool_context_test.go @@ -0,0 +1,44 @@ +package agent + +import "testing" + +func TestWithToolContextArgsPipelineAutoInject(t *testing.T) { + args := map[string]interface{}{ + "objective": "build feature", + } + got := withToolContextArgs("pipeline_create", args, "telegram", "123") + if got["channel"] != "telegram" { + t.Fatalf("expected channel auto-injected for pipeline_create, got %v", got["channel"]) + } + if got["chat_id"] != "123" { + t.Fatalf("expected chat_id auto-injected for pipeline_create, got %v", got["chat_id"]) + } +} + +func TestWithToolContextArgsPipelineRespectsExplicitTarget(t *testing.T) { + args := map[string]interface{}{ + "pipeline_id": "p-1", + "channel": "webui", + "chat_id": "panel", + } + got := withToolContextArgs("pipeline_dispatch", args, "telegram", "123") + if got["channel"] != "webui" { + t.Fatalf("expected explicit channel preserved, got %v", got["channel"]) + } + if got["chat_id"] != "panel" { + t.Fatalf("expected explicit chat_id preserved, got %v", got["chat_id"]) + } +} + +func TestWithToolContextArgsIgnoresUnrelatedTools(t *testing.T) { + args := map[string]interface{}{ + "path": "README.md", + } + got := withToolContextArgs("read_file", args, "telegram", "123") + if _, ok := got["channel"]; ok { + t.Fatalf("did not expect channel for unrelated tool") + } + if _, ok := got["chat_id"]; ok { + t.Fatalf("did not expect chat_id for unrelated tool") + } +}