Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test": "npm run test:src && npm run test:test",
"test:test": "jasmine build/test/*.js --reporter=test/spec/reporter.js",
"test:src": "jasmine build/src/functions/test/*.js build/src/models/test/*.js --reporter=test/spec/reporter.js",
"test:system": "jasmine build/system_test/*.js --reporter=test/spec/reporter.js",
"test:system": "jasmine build/system_test/*.js --reporter=test/spec/reporter.js --fail-fast=false",
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint src/genai --no-ignore --config src/genai/eslint.config.mjs",
"format": "prettier 'src/genai/**/*.ts' 'src/genai/**/*.mjs' --write",
"clean-js-files": "find . -type f -name \"*.js\" -exec rm -f {} +",
Expand All @@ -36,6 +36,13 @@
"pretest": "npm run compile",
"posttest": "npm run lint"
},
"nyc": {
"exclude": [
"test/**",
"system_test/**",
"src/genai/converters/**"
]
},
"dependencies": {
"@google/genai": "^1.45.0",
"google-auth-library": "^9.1.0"
Expand Down
84 changes: 60 additions & 24 deletions system_test/agent_engine_e2e_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,46 @@ import {Client} from '../src/genai/client';
const PROJECT = process.env['GCLOUD_PROJECT'];
const LOCATION = 'us-central1';

async function pollOperation(client: Client, operationName: string) {
let isDone = false;
let pollCount = 0;
while (!isDone && pollCount < 40) {
const status = await client.agentEnginesInternal.getAgentOperationInternal({
operationName,
});
if (status.done) {
return status;
}
pollCount++;
await new Promise((resolve) => setTimeout(resolve, 5000));
}
throw new Error(
`Operation ${operationName} did not complete within the timeout.`,
);
}

describe('agentEnginesInternal', () => {
let client: Client;
let agentEngineName: string|undefined;
let operationName: string|undefined;
let createOperationName: string|undefined;
let updateOperationName: string|undefined;

beforeEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000;
beforeAll(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
client = new Client({
project: PROJECT as string,
location: LOCATION,
});
});
}, 600000);

afterAll(async () => {
// If the test failed during the create operation, try to recover
// the resource name from the operation to cleanup.
if (!agentEngineName && operationName) {
if (!agentEngineName && createOperationName) {
try {
const status =
await client.agentEnginesInternal.getAgentOperationInternal({
operationName,
operationName: createOperationName,
});
if (status.done && status.response?.name) {
agentEngineName = status.response.name;
Expand Down Expand Up @@ -60,25 +79,42 @@ describe('agentEnginesInternal', () => {
});

expect(createOp.name).toBeDefined();
operationName = createOp.name;

// Poll for operation completion to get the Agent Engine resource name.
let isDone = false;
let pollCount = 0;
while (!isDone && pollCount < 40) {
const status =
await client.agentEnginesInternal.getAgentOperationInternal({
operationName: operationName!,
});
if (status.done) {
isDone = true;
agentEngineName = status.response?.name;
} else {
pollCount++;
await new Promise((resolve) => setTimeout(resolve, 5000));
}
}
createOperationName = createOp.name;

const status = await pollOperation(client, createOperationName!);
agentEngineName = status.response?.name;

expect(agentEngineName).toBeDefined();
});

it('should get an Agent Engine', async () => {
const agentEngine = await client.agentEnginesInternal.getInternal({
name: agentEngineName!,
});
expect(agentEngine.name).toBeDefined();
expect(agentEngine.displayName).toEqual('test-agent-engine-sample');
expect(agentEngine.labels).toEqual({'test-label': 'test-value'});
});

it('should update an Agent Engine', async () => {
const updateOp = await client.agentEnginesInternal.updateInternal({
name: agentEngineName!,
config: {
displayName: 'test-agent-engine-updated',
description: 'Updated from the Vertex JS SDK system tests',
},
});

expect(updateOp.name).toBeDefined();
updateOperationName = updateOp.name;

const status = await pollOperation(client, updateOperationName!);

if (status.response) {
expect(status.response.displayName)
.toEqual(
'test-agent-engine-updated',
);
}
});
});
Loading