test(tools,utils): add ToolRegistry unit tests and fix Truncate panic on negative maxLen (#517)

Add comprehensive unit tests for the ToolRegistry covering registration,
lookup, execution, context injection, async callbacks, schema generation,
provider definition conversion, and concurrent access.

Fix a defensive edge case in Truncate where a negative maxLen would cause
a slice bounds panic, and add table-driven tests covering boundary
conditions, zero/negative lengths, and Unicode handling.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
King Tai
2026-02-22 18:40:59 +08:00
committed by GitHub
parent 6b55fb5f1d
commit cb0c8703fb
3 changed files with 459 additions and 0 deletions
+3
View File
@@ -4,6 +4,9 @@ package utils
// Handles multi-byte Unicode characters properly.
// If the string is truncated, "..." is appended to indicate truncation.
func Truncate(s string, maxLen int) string {
if maxLen <= 0 {
return ""
}
runes := []rune(s)
if len(runes) <= maxLen {
return s