MCPcopy Create free account
hub / github.com/astercloud/aster / TestHumanInTheLoopMiddleware_Edit

Function TestHumanInTheLoopMiddleware_Edit

pkg/middleware/hitl_test.go:207–267  ·  view source on GitHub ↗

TestHumanInTheLoopMiddleware_Edit 测试编辑参数

(t *testing.T)

Source from the content-addressed store, hash-verified

205
206// TestHumanInTheLoopMiddleware_Edit 测试编辑参数
207func TestHumanInTheLoopMiddleware_Edit(t *testing.T) {
208 ctx := context.Background()
209
210 middleware, err := NewHumanInTheLoopMiddleware(&HumanInTheLoopMiddlewareConfig{
211 InterruptOn: map[string]any{
212 "editable_tool": true,
213 },
214 ApprovalHandler: func(ctx context.Context, request *ReviewRequest) ([]Decision, error) {
215 // 编辑参数
216 editedInput := make(map[string]any)
217 maps.Copy(editedInput, request.ActionRequests[0].Input)
218 editedInput["param"] = "edited_value"
219
220 return []Decision{
221 {
222 Type: DecisionEdit,
223 EditedInput: editedInput,
224 Reason: "Parameter adjusted",
225 },
226 }, nil
227 },
228 })
229 if err != nil {
230 t.Fatalf("Failed to create middleware: %v", err)
231 }
232
233 req := &ToolCallRequest{
234 ToolCallID: "test-edit",
235 ToolName: "editable_tool",
236 ToolInput: map[string]any{
237 "param": "original_value",
238 },
239 Tool: &mockTool{name: "editable_tool"},
240 }
241
242 handler := func(ctx context.Context, req *ToolCallRequest) (*ToolCallResponse, error) {
243 result, _ := req.Tool.Execute(ctx, req.ToolInput, nil)
244 return &ToolCallResponse{
245 Result: result,
246 }, nil
247 }
248
249 resp, err := middleware.WrapToolCall(ctx, req, handler)
250 if err != nil {
251 t.Fatalf("WrapToolCall failed: %v", err)
252 }
253
254 resultMap, ok := resp.Result.(map[string]any)
255 if !ok {
256 t.Fatal("Result is not a map")
257 }
258
259 if !resultMap["ok"].(bool) {
260 t.Error("Expected ok=true")
261 }
262
263 // 验证参数已被编辑
264 if resultMap["param"] != "edited_value" {

Callers

nothing calls this directly

Calls 5

WrapToolCallMethod · 0.95
CopyMethod · 0.80
ExecuteMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected