fix pipeline tool context origin injection

This commit is contained in:
lpf
2026-03-05 22:41:21 +08:00
parent b9e1efa3ef
commit 3894f0e27a
2 changed files with 45 additions and 1 deletions

View File

@@ -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")
}
}