Skip to content

Commit 1db8066

Browse files
sararobcopybara-github
authored andcommitted
chore: Add system tests for agent engines and memories modules
PiperOrigin-RevId: 895367197
1 parent fc3c061 commit 1db8066

2 files changed

Lines changed: 68 additions & 25 deletions

File tree

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"test": "npm run test:src && npm run test:test",
2323
"test:test": "jasmine build/test/*.js --reporter=test/spec/reporter.js",
2424
"test:src": "jasmine build/src/functions/test/*.js build/src/models/test/*.js --reporter=test/spec/reporter.js",
25-
"test:system": "jasmine build/system_test/*.js --reporter=test/spec/reporter.js",
25+
"test:system": "jasmine build/system_test/*.js --reporter=test/spec/reporter.js --fail-fast=false",
2626
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint src/genai --no-ignore --config src/genai/eslint.config.mjs",
2727
"format": "prettier 'src/genai/**/*.ts' 'src/genai/**/*.mjs' --write",
2828
"clean-js-files": "find . -type f -name \"*.js\" -exec rm -f {} +",
@@ -36,6 +36,13 @@
3636
"pretest": "npm run compile",
3737
"posttest": "npm run lint"
3838
},
39+
"nyc": {
40+
"exclude": [
41+
"test/**",
42+
"system_test/**",
43+
"src/genai/converters/**"
44+
]
45+
},
3946
"dependencies": {
4047
"@google/genai": "^1.45.0",
4148
"google-auth-library": "^9.1.0"

system_test/agent_engine_e2e_test.ts

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,46 @@ 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

17-
beforeEach(() => {
18-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000;
36+
beforeAll(() => {
37+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
1938
client = new Client({
2039
project: PROJECT as string,
2140
location: LOCATION,
2241
});
23-
});
42+
}, 600000);
2443

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

Comments
 (0)