修复(AI客服): 退款操作统一转人工处理
隐藏并拦截退款类业务动作,兼容旧确认流程,确保所有客户类型的退款请求进入人工支持,并补充回归测试。
This commit is contained in:
@@ -240,3 +240,55 @@ func TestBusinessActionToolRetriesExplicitPreSideEffectFailure(t *testing.T) {
|
||||
t.Fatalf("retry result=%#v reused=%t executions=%d err=%v", result, reused, executions, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRefundActionsAreHiddenAndBlockedBeforeHostCallbacks(t *testing.T) {
|
||||
t.Cleanup(func() { _ = SetBusinessActionTools(nil) })
|
||||
for _, code := range []string{"business/mall_apply_after_sale", "business/card_package_refund", "business/device_balance_refund", "business/mall_deposit_refund"} {
|
||||
t.Run(code, func(t *testing.T) {
|
||||
tool := contract.BusinessActionTool{
|
||||
Code: code, Description: "refund",
|
||||
Preview: func(context.Context, contract.BusinessReadContext, map[string]any) (string, error) {
|
||||
t.Fatal("refund preview must not reach the host")
|
||||
return "", nil
|
||||
},
|
||||
AuthorizeConfirmation: func(context.Context, contract.BusinessReadContext, map[string]any, string) error {
|
||||
t.Fatal("refund must be blocked before authorizing or claiming an invocation")
|
||||
return nil
|
||||
},
|
||||
Execute: func(context.Context, contract.BusinessReadContext, map[string]any) (*contract.BusinessActionResult, error) {
|
||||
t.Fatal("refund must not execute, even with an existing confirmation")
|
||||
return nil, nil
|
||||
},
|
||||
}
|
||||
if err := SetBusinessActionTools([]contract.BusinessActionTool{tool}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, customerType := range []string{"card", "device", "mall_user", ""} {
|
||||
if got := BusinessActionToolService.ListForCustomerType(customerType); len(got) != 0 {
|
||||
t.Fatalf("refund exposed in catalog: %#v", got)
|
||||
}
|
||||
if _, ok := BusinessActionToolService.ResolveForCustomerType(code, customerType); ok {
|
||||
t.Fatal("refund resolved for customer")
|
||||
}
|
||||
}
|
||||
if _, ok := BusinessActionToolService.Resolve(code); ok {
|
||||
t.Fatal("refund resolved for tool definitions")
|
||||
}
|
||||
_, err := BusinessActionToolService.Preview(context.Background(), tool, contract.BusinessReadContext{}, nil)
|
||||
assertRefundHumanSupportError(t, err)
|
||||
result, reused, err := BusinessActionToolService.Execute(context.Background(), 1, 2, "legacy-refund-confirmation", tool, contract.BusinessReadContext{}, nil)
|
||||
assertRefundHumanSupportError(t, err)
|
||||
if result != nil || reused {
|
||||
t.Fatalf("refund returned an execution result: %#v reused=%v", result, reused)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func assertRefundHumanSupportError(t *testing.T, err error) {
|
||||
t.Helper()
|
||||
var publicErr *contract.BusinessActionError
|
||||
if !errors.As(err, &publicErr) || publicErr.Message != RefundHumanSupportMessage {
|
||||
t.Fatalf("expected human support guidance, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user