fix: address review feedback - init ToolNameMap eagerly, log collisions, add collision test

This commit is contained in:
sususu98
2026-03-22 13:24:03 +08:00
parent 2398ebad55
commit 755ca75879
3 changed files with 18 additions and 4 deletions
+14
View File
@@ -93,6 +93,20 @@ func TestSanitizedToolNameMap(t *testing.T) {
t.Error("expected nil for nil input")
}
})
t.Run("collision keeps first mapping", func(t *testing.T) {
raw := []byte(`{"tools":[
{"name":"read/file","input_schema":{}},
{"name":"read@file","input_schema":{}}
]}`)
m := SanitizedToolNameMap(raw)
if m == nil {
t.Fatal("expected non-nil map")
}
if m["read_file"] != "read/file" {
t.Errorf("expected first mapping read/file, got %q", m["read_file"])
}
})
}
func TestRestoreSanitizedToolName(t *testing.T) {