mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-04 07:57:28 +08:00
refactor: stabilize runtime and unify config
This commit is contained in:
37
pkg/tools/compat_alias_test.go
Normal file
37
pkg/tools/compat_alias_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type captureAliasTool struct {
|
||||
args map[string]interface{}
|
||||
}
|
||||
|
||||
func (t *captureAliasTool) Name() string { return "capture" }
|
||||
func (t *captureAliasTool) Description() string { return "capture" }
|
||||
func (t *captureAliasTool) Parameters() map[string]interface{} {
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
func (t *captureAliasTool) Execute(_ context.Context, args map[string]interface{}) (string, error) {
|
||||
t.args = args
|
||||
return "ok", nil
|
||||
}
|
||||
|
||||
func TestAliasToolExecuteDoesNotMutateCallerArgs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
base := &captureAliasTool{}
|
||||
tool := NewAliasTool("read", "", base, map[string]string{"file_path": "path"})
|
||||
original := map[string]interface{}{"file_path": "README.md"}
|
||||
if _, err := tool.Execute(context.Background(), original); err != nil {
|
||||
t.Fatalf("execute failed: %v", err)
|
||||
}
|
||||
if _, ok := original["path"]; ok {
|
||||
t.Fatalf("caller args were mutated: %+v", original)
|
||||
}
|
||||
if got, _ := base.args["path"].(string); got != "README.md" {
|
||||
t.Fatalf("expected translated arg, got %+v", base.args)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user