@@ -7,7 +7,7 @@ import { ApiResponse } from '@opensearch-project/opensearch';
7
7
import { ResponseError } from '@opensearch-project/opensearch/lib/errors' ;
8
8
import { CoreRouteHandlerContext } from '../../../../../../../src/core/server/core_route_handler_context' ;
9
9
import { coreMock , httpServerMock } from '../../../../../../../src/core/server/mocks' ;
10
- import { agentIdMap , getAgentIdByConfig , requestWithRetryAgentSearch } from '../agents' ;
10
+ import { getAgentIdByConfig , getAgentIdAndRequest } from '../agents' ;
11
11
12
12
describe ( 'Agents helper functions' , ( ) => {
13
13
const coreContext = new CoreRouteHandlerContext (
@@ -75,27 +75,7 @@ describe('Agents helper functions', () => {
75
75
) ;
76
76
} ) ;
77
77
78
- it ( 'requests with valid agent id' , async ( ) => {
79
- agentIdMap . test_agent = 'test-id' ;
80
- mockedTransport . mockResolvedValueOnce ( {
81
- body : { inference_results : [ { output : [ { result : 'test response' } ] } ] } ,
82
- } ) ;
83
- const response = await requestWithRetryAgentSearch ( {
84
- client,
85
- configName : 'test_agent' ,
86
- shouldRetryAgentSearch : true ,
87
- body : { parameters : { param1 : 'value1' } } ,
88
- } ) ;
89
- expect ( mockedTransport ) . toBeCalledWith (
90
- expect . objectContaining ( {
91
- path : '/_plugins/_ml/agents/test-id/_execute' ,
92
- } ) ,
93
- expect . anything ( )
94
- ) ;
95
- expect ( response . body . inference_results [ 0 ] . output [ 0 ] . result ) . toEqual ( 'test response' ) ;
96
- } ) ;
97
-
98
- it ( 'searches for agent id if id is undefined' , async ( ) => {
78
+ it ( 'searches for agent id and sends request' , async ( ) => {
99
79
mockedTransport
100
80
. mockResolvedValueOnce ( {
101
81
body : {
@@ -106,36 +86,9 @@ describe('Agents helper functions', () => {
106
86
. mockResolvedValueOnce ( {
107
87
body : { inference_results : [ { output : [ { result : 'test response' } ] } ] } ,
108
88
} ) ;
109
- const response = await requestWithRetryAgentSearch ( {
89
+ const response = await getAgentIdAndRequest ( {
110
90
client,
111
91
configName : 'new_agent' ,
112
- shouldRetryAgentSearch : true ,
113
- body : { parameters : { param1 : 'value1' } } ,
114
- } ) ;
115
- expect ( mockedTransport ) . toBeCalledWith (
116
- expect . objectContaining ( { path : '/_plugins/_ml/agents/new-id/_execute' } ) ,
117
- expect . anything ( )
118
- ) ;
119
- expect ( response . body . inference_results [ 0 ] . output [ 0 ] . result ) . toEqual ( 'test response' ) ;
120
- } ) ;
121
-
122
- it ( 'searches for agent id if id is not found' , async ( ) => {
123
- agentIdMap . test_agent = 'non-exist-agent' ;
124
- mockedTransport
125
- . mockRejectedValueOnce ( { statusCode : 404 , body : { } , headers : { } } )
126
- . mockResolvedValueOnce ( {
127
- body : {
128
- type : 'agent' ,
129
- configuration : { agent_id : 'new-id' } ,
130
- } ,
131
- } )
132
- . mockResolvedValueOnce ( {
133
- body : { inference_results : [ { output : [ { result : 'test response' } ] } ] } ,
134
- } ) ;
135
- const response = await requestWithRetryAgentSearch ( {
136
- client,
137
- configName : 'test_agent' ,
138
- shouldRetryAgentSearch : true ,
139
92
body : { parameters : { param1 : 'value1' } } ,
140
93
} ) ;
141
94
expect ( mockedTransport ) . toBeCalledWith (
0 commit comments