@@ -9,10 +9,29 @@ import {Client} from '../src/genai/client';
99const PROJECT = process . env [ 'GCLOUD_PROJECT' ] ;
1010const LOCATION = 'us-central1' ;
1111
12+ async function pollOperation ( client : Client , operationName : string ) {
13+ let isDone = false ;
14+ let pollCount = 0 ;
15+ while ( ! isDone && pollCount < 40 ) {
16+ const status = await client . agentEnginesInternal . getAgentOperationInternal ( {
17+ operationName,
18+ } ) ;
19+ if ( status . done ) {
20+ return status ;
21+ }
22+ pollCount ++ ;
23+ await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
24+ }
25+ throw new Error (
26+ `Operation ${ operationName } did not complete within the timeout.` ,
27+ ) ;
28+ }
29+
1230describe ( 'agentEnginesInternal' , ( ) => {
1331 let client : Client ;
1432 let agentEngineName : string | undefined ;
15- let operationName : string | undefined ;
33+ let createOperationName : string | undefined ;
34+ let updateOperationName : string | undefined ;
1635
1736 beforeEach ( ( ) => {
1837 jasmine . DEFAULT_TIMEOUT_INTERVAL = 300000 ;
@@ -25,11 +44,11 @@ describe('agentEnginesInternal', () => {
2544 afterAll ( async ( ) => {
2645 // If the test failed during the create operation, try to recover
2746 // the resource name from the operation to cleanup.
28- if ( ! agentEngineName && operationName ) {
47+ if ( ! agentEngineName && createOperationName ) {
2948 try {
3049 const status =
3150 await client . agentEnginesInternal . getAgentOperationInternal ( {
32- operationName,
51+ operationName : createOperationName ,
3352 } ) ;
3453 if ( status . done && status . response ?. name ) {
3554 agentEngineName = status . response . name ;
@@ -60,25 +79,42 @@ describe('agentEnginesInternal', () => {
6079 } ) ;
6180
6281 expect ( createOp . name ) . toBeDefined ( ) ;
63- operationName = createOp . name ;
64-
65- // Poll for operation completion to get the Agent Engine resource name.
66- let isDone = false ;
67- let pollCount = 0 ;
68- while ( ! isDone && pollCount < 40 ) {
69- const status =
70- await client . agentEnginesInternal . getAgentOperationInternal ( {
71- operationName : operationName ! ,
72- } ) ;
73- if ( status . done ) {
74- isDone = true ;
75- agentEngineName = status . response ?. name ;
76- } else {
77- pollCount ++ ;
78- await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
79- }
80- }
82+ createOperationName = createOp . name ;
83+
84+ const status = await pollOperation ( client , createOperationName ! ) ;
85+ agentEngineName = status . response ?. name ;
8186
8287 expect ( agentEngineName ) . toBeDefined ( ) ;
8388 } ) ;
89+
90+ it ( 'should get an Agent Engine' , async ( ) => {
91+ const agentEngine = await client . agentEnginesInternal . getInternal ( {
92+ name : agentEngineName ! ,
93+ } ) ;
94+ expect ( agentEngine . name ) . toBeDefined ( ) ;
95+ expect ( agentEngine . displayName ) . toEqual ( 'test-agent-engine-sample' ) ;
96+ expect ( agentEngine . labels ) . toEqual ( { 'test-label' : 'test-value' } ) ;
97+ } ) ;
98+
99+ it ( 'should update an Agent Engine' , async ( ) => {
100+ const updateOp = await client . agentEnginesInternal . updateInternal ( {
101+ name : agentEngineName ! ,
102+ config : {
103+ displayName : 'test-agent-engine-updated' ,
104+ description : 'Updated from the Vertex JS SDK system tests' ,
105+ } ,
106+ } ) ;
107+
108+ expect ( updateOp . name ) . toBeDefined ( ) ;
109+ updateOperationName = updateOp . name ;
110+
111+ const status = await pollOperation ( client , updateOperationName ! ) ;
112+
113+ if ( status . response ) {
114+ expect ( status . response . displayName )
115+ . toEqual (
116+ 'test-agent-engine-updated' ,
117+ ) ;
118+ }
119+ } ) ;
84120} ) ;
0 commit comments