refactor: unify float64 conversion logic in ToolSleep and ToolSleepMS, enhance error logging

This commit is contained in:
lilong.129
2025-08-12 14:49:47 +08:00
parent 9cddad0d75
commit 1253d5848d
4 changed files with 80 additions and 85 deletions
+45
View File
@@ -30,6 +30,15 @@ func TestToolSleep_ConvertActionToCallToolRequest(t *testing.T) {
expectedArgs: map[string]any{"seconds": float64(3.5)},
shouldError: false,
},
{
name: "float64 parameter",
action: option.MobileAction{
Method: option.ACTION_Sleep,
Params: float64(5.2),
},
expectedArgs: map[string]any{"seconds": float64(5.2)},
shouldError: false,
},
{
name: "int64 parameter",
action: option.MobileAction{
@@ -63,6 +72,24 @@ func TestToolSleep_ConvertActionToCallToolRequest(t *testing.T) {
expectedArgs: nil,
shouldError: true,
},
{
name: "json.Number with integer value",
action: option.MobileAction{
Method: option.ACTION_Sleep,
Params: json.Number("10"),
},
expectedArgs: map[string]any{"seconds": float64(10)},
shouldError: false,
},
{
name: "json.Number with decimal value",
action: option.MobileAction{
Method: option.ACTION_Sleep,
Params: json.Number("1.25"),
},
expectedArgs: map[string]any{"seconds": float64(1.25)},
shouldError: false,
},
}
for _, tt := range tests {
@@ -109,6 +136,15 @@ func TestToolSleepMS_ConvertActionToCallToolRequest(t *testing.T) {
expectedArgs: map[string]any{"milliseconds": int64(2000)},
shouldError: false,
},
{
name: "float64 parameter",
action: option.MobileAction{
Method: option.ACTION_SleepMS,
Params: float64(2500.7),
},
expectedArgs: map[string]any{"milliseconds": int64(2500)},
shouldError: false,
},
{
name: "SleepConfig with startTime",
action: option.MobileAction{
@@ -124,6 +160,15 @@ func TestToolSleepMS_ConvertActionToCallToolRequest(t *testing.T) {
},
shouldError: false,
},
{
name: "json.Number with decimal value",
action: option.MobileAction{
Method: option.ACTION_SleepMS,
Params: json.Number("1234.56"),
},
expectedArgs: map[string]any{"milliseconds": int64(1234)},
shouldError: false,
},
{
name: "invalid parameter type",
action: option.MobileAction{