Skip to content

Commit c482811

Browse files
sararobcopybara-github
authored andcommitted
chore: Add system tests for agent engines module
PiperOrigin-RevId: 895367197
1 parent 7932c2b commit c482811

2 files changed

Lines changed: 167 additions & 21 deletions

File tree

system_test/agent_engine_e2e_test.ts

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,29 @@ import {Client} from '../src/genai/client';
99
const PROJECT = process.env['GCLOUD_PROJECT'];
1010
const 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+
1230
describe('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
});

system_test/memories_e2e_test.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import {Client} from '../src/genai/client';
8+
9+
const PROJECT = process.env['GCLOUD_PROJECT'];
10+
const LOCATION = 'us-central1';
11+
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+
30+
describe('agentEnginesInternal.memories', () => {
31+
let client: Client;
32+
let agentEngineName: string|undefined;
33+
let createOperationName: string|undefined;
34+
35+
const memoriesToCleanup: string[] = [];
36+
37+
beforeAll(async () => {
38+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000;
39+
40+
client = new Client({
41+
project: PROJECT as string,
42+
location: LOCATION,
43+
});
44+
45+
// Create the Agent Engine and wait for it to be ready
46+
const createOp = await client.agentEnginesInternal.createInternal({
47+
config: {
48+
displayName: 'agent-engine-memories-test',
49+
description: 'Created from the Vertex JS SDK system tests',
50+
labels: {'test-label': 'test-value'},
51+
},
52+
});
53+
54+
createOperationName = createOp.name;
55+
const status = await pollOperation(client, createOperationName!);
56+
agentEngineName = status.response?.name;
57+
});
58+
59+
afterAll(async () => {
60+
// Clean up any memories created during the tests
61+
for (const memoryName of memoriesToCleanup) {
62+
try {
63+
await client.agentEnginesInternal.memories.delete({name: memoryName});
64+
} catch (e) {
65+
console.error(
66+
`Failed to delete memory ${memoryName} during cleanup:`, e);
67+
}
68+
}
69+
70+
// Recover the Agent Engine name if the creation failed
71+
if (!agentEngineName && createOperationName) {
72+
try {
73+
const status =
74+
await client.agentEnginesInternal.getAgentOperationInternal({
75+
operationName: createOperationName,
76+
});
77+
if (status.done && status.response?.name) {
78+
agentEngineName = status.response.name;
79+
}
80+
} catch (e) {
81+
console.error('Failed to recover Agent Engine name from operation:', e);
82+
}
83+
}
84+
85+
// Clean up the Agent Engine
86+
if (agentEngineName) {
87+
try {
88+
await client.agentEnginesInternal.deleteInternal({
89+
name: agentEngineName,
90+
});
91+
} catch (e) {
92+
console.error('Failed to delete Agent Engine during cleanup:', e);
93+
}
94+
}
95+
});
96+
97+
it('should create a memory in an agent engine', async () => {
98+
const createOp = await client.agentEnginesInternal.memories.createInternal({
99+
name: agentEngineName!,
100+
fact: 'test-memory-fact',
101+
scope: {'user_id': 'test-user-id'},
102+
});
103+
104+
expect(createOp.name).toBeDefined();
105+
106+
if (createOp.name) {
107+
memoriesToCleanup.push(createOp.name);
108+
}
109+
});
110+
});

0 commit comments

Comments
 (0)