Skip to content

Commit f8f6fcc

Browse files
committed
fix(bedrock): fix test errors
1 parent 821bb48 commit f8f6fcc

File tree

4 files changed

+53
-112
lines changed

4 files changed

+53
-112
lines changed

src/cdk-lib/bedrock/agents/agent.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export interface AgentProps {
135135
/**
136136
* The KnowledgeBases associated with the agent.
137137
*/
138-
readonly knowledgeBases?: IVectorKnowledgeBase[];
138+
readonly knowledgeBases?: IKnowledgeBase[];
139139
/**
140140
* The Action Groups associated with the agent.
141141
*/
@@ -515,9 +515,9 @@ export class Agent extends AgentBase {
515515
private renderGuardrail(): bedrock.CfnAgent.GuardrailConfigurationProperty | undefined {
516516
return this.guardrail
517517
? {
518-
guardrailIdentifier: this.guardrail.guardrailId,
519-
guardrailVersion: this.guardrail.guardrailVersion,
520-
}
518+
guardrailIdentifier: this.guardrail.guardrailId,
519+
guardrailVersion: this.guardrail.guardrailVersion,
520+
}
521521
: undefined;
522522
}
523523

@@ -574,12 +574,12 @@ export class Agent extends AgentBase {
574574
fieldName: 'description',
575575
minLength: 0,
576576
maxLength: MAX_LENGTH,
577-
}),
577+
})
578578
);
579579
} else {
580580
errors.push(
581581
'If instructionForAgents is not provided, the description property of the KnowledgeBase ' +
582-
`${knowledgeBase.knowledgeBaseId} must be provided.`,
582+
`${knowledgeBase.knowledgeBaseId} must be provided.`
583583
);
584584
}
585585
return errors;
@@ -610,7 +610,7 @@ export class Agent extends AgentBase {
610610
if (this.guardrail) {
611611
errors.push(
612612
`Cannot add Guardrail ${guardrail.guardrailId}. ` +
613-
`Guardrail ${this.guardrail.guardrailId} has already been specified for this agent.`,
613+
`Guardrail ${this.guardrail.guardrailId} has already been specified for this agent.`
614614
);
615615
}
616616
errors.push(...validation.validateFieldPattern(guardrail.guardrailVersion, 'version', /^(([0-9]{1,8})|(DRAFT))$/));

test/cdk-lib/bedrock/agents/agent.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('CDK-Agent', () => {
111111
kmsKey: Key.fromKeyArn(
112112
stack,
113113
'importedKey',
114-
'arn:aws:kms:eu-central-1:123456789012:key/06484191-7d55-49fb-9be7-0baaf7fe8418',
114+
'arn:aws:kms:eu-central-1:123456789012:key/06484191-7d55-49fb-9be7-0baaf7fe8418'
115115
),
116116
});
117117

@@ -122,15 +122,15 @@ describe('CDK-Agent', () => {
122122
});
123123

124124
expect(agent.kmsKey!.keyArn).toBe(
125-
'arn:aws:kms:eu-central-1:123456789012:key/06484191-7d55-49fb-9be7-0baaf7fe8418',
125+
'arn:aws:kms:eu-central-1:123456789012:key/06484191-7d55-49fb-9be7-0baaf7fe8418'
126126
);
127127
});
128128

129129
test('Core Creation + Custom Role', () => {
130130
const myRole = Role.fromRoleArn(
131131
stack,
132132
'myRole',
133-
'arn:aws:iam::123456789012:role/AmazonBedrockExecutionRoleForAgent_12345678',
133+
'arn:aws:iam::123456789012:role/AmazonBedrockExecutionRoleForAgent_12345678'
134134
);
135135
const agent = new bedrock.Agent(stack, 'TestAgent', {
136136
name: 'TestAgent',
@@ -355,7 +355,7 @@ describe('CDK-Agent', () => {
355355

356356
// THEN
357357
expect(() => agent.addGuardrail(anotherGuardrail)).toThrow(
358-
'Cannot add Guardrail yib23y5g23b2wf. Guardrail oygh3o8g7rtl has already been specified for this agent.',
358+
'Cannot add Guardrail yib23y5g23b2wf. Guardrail oygh3o8g7rtl has already been specified for this agent.'
359359
);
360360
});
361361
});
@@ -364,10 +364,10 @@ describe('CDK-Agent', () => {
364364
* KNOWLEDGE BASES in Agents *
365365
*******************************************************/
366366
describe('w/ Knowledge Bases', () => {
367-
let myKnowledgeBase: bedrock.IKnowledgeBase;
367+
let myKnowledgeBase: bedrock.IVectorKnowledgeBase;
368368

369369
beforeEach(() => {
370-
myKnowledgeBase = bedrock.KnowledgeBase.fromKnowledgeBaseAttributes(stack, 'myKnowledgeBase', {
370+
myKnowledgeBase = bedrock.VectorKnowledgeBase.fromKnowledgeBaseAttributes(stack, 'myKnowledgeBase', {
371371
knowledgeBaseId: 'ABCDEFG1234',
372372
executionRoleArn: 'arn:aws:iam::123456789012:role/AmazonBedrockExecutionRoleForKnowledgeBase_12345678',
373373
instruction: 'This is a sample KB with info about unicorns.',
@@ -423,13 +423,13 @@ describe('CDK-Agent', () => {
423423
});
424424

425425
test('Knowledge Bases - Validation', () => {
426-
const invalidKb = (myKnowledgeBase = bedrock.KnowledgeBase.fromKnowledgeBaseAttributes(
426+
const invalidKb = (myKnowledgeBase = bedrock.VectorKnowledgeBase.fromKnowledgeBaseAttributes(
427427
stack,
428428
'otherKnowledgeBase',
429429
{
430430
knowledgeBaseId: 'ABCDEFG1234',
431431
executionRoleArn: 'arn:aws:iam::123456789012:role/AmazonBedrockExecutionRoleForKnowledgeBase_12345678',
432-
},
432+
}
433433
));
434434

435435
const agent = new bedrock.Agent(stack, 'TestAgent', {
@@ -439,7 +439,7 @@ describe('CDK-Agent', () => {
439439
});
440440

441441
expect(() => agent.addKnowledgeBase(invalidKb)).toThrow(
442-
'If instructionForAgents is not provided, the description property of the KnowledgeBase ABCDEFG1234 must be provided.',
442+
'If instructionForAgents is not provided, the description property of the KnowledgeBase ABCDEFG1234 must be provided.'
443443
);
444444
});
445445
});

test/cdk-lib/bedrock/data-sources/other-data-sources.test.ts

Lines changed: 35 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ import * as foundationModels from '../../../../src/cdk-lib/bedrock/models';
2020

2121
describe('Data Source', () => {
2222
let stack: Stack;
23-
let kb: bedrock.KnowledgeBase;
23+
let kb: bedrock.VectorKnowledgeBase;
2424
let key: IKey;
2525

2626
beforeEach(() => {
2727
const app = new App();
2828
stack = new Stack(app, 'TestStack');
29-
kb = new bedrock.KnowledgeBase(stack, 'KB', {
29+
kb = new bedrock.VectorKnowledgeBase(stack, 'KB', {
3030
embeddingsModel: foundationModels.BedrockFoundationModel.TITAN_EMBED_TEXT_V1,
3131
});
3232
const sampleKeyArn = 'arn:aws:kms:eu-central-1:123456789012:key/06484191-7d55-49fb-9be7-0baaf7fe8418';
3333
key = Key.fromKeyArn(stack, 'TestKey', sampleKeyArn);
34-
3534
});
3635

3736
test('Basic Web Crawler', () => {
@@ -63,9 +62,11 @@ describe('Data Source', () => {
6362
},
6463
SourceConfiguration: {
6564
UrlConfiguration: {
66-
SeedUrls: [{
67-
Url: 'https://example.com',
68-
}],
65+
SeedUrls: [
66+
{
67+
Url: 'https://example.com',
68+
},
69+
],
6970
},
7071
},
7172
},
@@ -76,14 +77,14 @@ describe('Data Source', () => {
7677

7778
describe('Third Party Data Source', () => {
7879
let stack: Stack;
79-
let kb: bedrock.KnowledgeBase;
80+
let kb: bedrock.VectorKnowledgeBase;
8081
let key: IKey;
8182
let secret: ISecret;
8283

8384
beforeEach(() => {
8485
const app = new App();
8586
stack = new Stack(app, 'TestStack');
86-
kb = new bedrock.KnowledgeBase(stack, 'KB', {
87+
kb = new bedrock.VectorKnowledgeBase(stack, 'KB', {
8788
embeddingsModel: foundationModels.BedrockFoundationModel.TITAN_EMBED_TEXT_V1,
8889
});
8990
const sampleKeyArn = 'arn:aws:kms:eu-central-1:123456789012:key/06484191-7d55-49fb-9be7-0baaf7fe8418';
@@ -135,21 +136,13 @@ describe('Third Party Data Source', () => {
135136
Filters: [
136137
{
137138
ObjectType: 'Attachment',
138-
InclusionFilters: [
139-
'.*\\.pdf',
140-
],
141-
ExclusionFilters: [
142-
'.*private.*\\.pdf',
143-
],
139+
InclusionFilters: ['.*\\.pdf'],
140+
ExclusionFilters: ['.*private.*\\.pdf'],
144141
},
145142
{
146143
ObjectType: 'Page',
147-
InclusionFilters: [
148-
'.*public.*\\.pdf',
149-
],
150-
ExclusionFilters: [
151-
'.*confidential.*\\.pdf',
152-
],
144+
InclusionFilters: ['.*public.*\\.pdf'],
145+
ExclusionFilters: ['.*confidential.*\\.pdf'],
153146
},
154147
],
155148
},
@@ -158,7 +151,6 @@ describe('Third Party Data Source', () => {
158151
},
159152
},
160153
});
161-
162154
});
163155

164156
test('Basic Confluence Setup - Method', () => {
@@ -203,21 +195,13 @@ describe('Third Party Data Source', () => {
203195
Filters: [
204196
{
205197
ObjectType: 'Attachment',
206-
InclusionFilters: [
207-
'.*\\.pdf',
208-
],
209-
ExclusionFilters: [
210-
'.*private.*\\.pdf',
211-
],
198+
InclusionFilters: ['.*\\.pdf'],
199+
ExclusionFilters: ['.*private.*\\.pdf'],
212200
},
213201
{
214202
ObjectType: 'Page',
215-
InclusionFilters: [
216-
'.*public.*\\.pdf',
217-
],
218-
ExclusionFilters: [
219-
'.*confidential.*\\.pdf',
220-
],
203+
InclusionFilters: ['.*public.*\\.pdf'],
204+
ExclusionFilters: ['.*confidential.*\\.pdf'],
221205
},
222206
],
223207
},
@@ -226,7 +210,6 @@ describe('Third Party Data Source', () => {
226210
},
227211
},
228212
});
229-
230213
});
231214

232215
test('Basic Sharepoint Setup - Class', () => {
@@ -265,9 +248,7 @@ describe('Third Party Data Source', () => {
265248
TenantId: '888d0b57-69f1-4fb8-957f-e1f0bedf64de',
266249
HostType: 'ONLINE',
267250
Domain: 'yourdomain',
268-
SiteUrls: [
269-
'https://yourdomain.sharepoint.com/sites/mysite',
270-
],
251+
SiteUrls: ['https://yourdomain.sharepoint.com/sites/mysite'],
271252
AuthType: 'OAUTH2_CLIENT_CREDENTIALS',
272253
CredentialsSecretArn: 'arn:aws:secretsmanager:eu-central-1:123456789012:secret:AmazonBedrock-auth-tW8BY1',
273254
},
@@ -278,21 +259,13 @@ describe('Third Party Data Source', () => {
278259
Filters: [
279260
{
280261
ObjectType: 'Page',
281-
InclusionFilters: [
282-
'.*\\.pdf',
283-
],
284-
ExclusionFilters: [
285-
'.*private.*\\.pdf',
286-
],
262+
InclusionFilters: ['.*\\.pdf'],
263+
ExclusionFilters: ['.*private.*\\.pdf'],
287264
},
288265
{
289266
ObjectType: 'File',
290-
InclusionFilters: [
291-
'.*public.*\\.pdf',
292-
],
293-
ExclusionFilters: [
294-
'.*confidential.*\\.pdf',
295-
],
267+
InclusionFilters: ['.*public.*\\.pdf'],
268+
ExclusionFilters: ['.*confidential.*\\.pdf'],
296269
},
297270
],
298271
},
@@ -301,7 +274,6 @@ describe('Third Party Data Source', () => {
301274
},
302275
},
303276
});
304-
305277
});
306278

307279
test('Basic Sharepoint Setup - Method', () => {
@@ -339,9 +311,7 @@ describe('Third Party Data Source', () => {
339311
TenantId: '888d0b57-69f1-4fb8-957f-e1f0bedf64de',
340312
HostType: 'ONLINE',
341313
Domain: 'yourdomain',
342-
SiteUrls: [
343-
'https://yourdomain.sharepoint.com/sites/mysite',
344-
],
314+
SiteUrls: ['https://yourdomain.sharepoint.com/sites/mysite'],
345315
AuthType: 'OAUTH2_CLIENT_CREDENTIALS',
346316
CredentialsSecretArn: 'arn:aws:secretsmanager:eu-central-1:123456789012:secret:AmazonBedrock-auth-tW8BY1',
347317
},
@@ -352,21 +322,13 @@ describe('Third Party Data Source', () => {
352322
Filters: [
353323
{
354324
ObjectType: 'Page',
355-
InclusionFilters: [
356-
'.*\\.pdf',
357-
],
358-
ExclusionFilters: [
359-
'.*private.*\\.pdf',
360-
],
325+
InclusionFilters: ['.*\\.pdf'],
326+
ExclusionFilters: ['.*private.*\\.pdf'],
361327
},
362328
{
363329
ObjectType: 'File',
364-
InclusionFilters: [
365-
'.*public.*\\.pdf',
366-
],
367-
ExclusionFilters: [
368-
'.*confidential.*\\.pdf',
369-
],
330+
InclusionFilters: ['.*public.*\\.pdf'],
331+
ExclusionFilters: ['.*confidential.*\\.pdf'],
370332
},
371333
],
372334
},
@@ -375,7 +337,6 @@ describe('Third Party Data Source', () => {
375337
},
376338
},
377339
});
378-
379340
});
380341

381342
test('Basic SFDC Setup - Class', () => {
@@ -420,21 +381,13 @@ describe('Third Party Data Source', () => {
420381
Filters: [
421382
{
422383
ObjectType: 'Campaign',
423-
InclusionFilters: [
424-
'.*\\.pdf',
425-
],
426-
ExclusionFilters: [
427-
'.*private.*\\.pdf',
428-
],
384+
InclusionFilters: ['.*\\.pdf'],
385+
ExclusionFilters: ['.*private.*\\.pdf'],
429386
},
430387
{
431388
ObjectType: 'Contract',
432-
InclusionFilters: [
433-
'.*public.*\\.pdf',
434-
],
435-
ExclusionFilters: [
436-
'.*confidential.*\\.pdf',
437-
],
389+
InclusionFilters: ['.*public.*\\.pdf'],
390+
ExclusionFilters: ['.*confidential.*\\.pdf'],
438391
},
439392
],
440393
},
@@ -443,7 +396,6 @@ describe('Third Party Data Source', () => {
443396
},
444397
},
445398
});
446-
447399
});
448400

449401
test('Basic SFDC Setup - Method', () => {
@@ -487,21 +439,13 @@ describe('Third Party Data Source', () => {
487439
Filters: [
488440
{
489441
ObjectType: 'Campaign',
490-
InclusionFilters: [
491-
'.*\\.pdf',
492-
],
493-
ExclusionFilters: [
494-
'.*private.*\\.pdf',
495-
],
442+
InclusionFilters: ['.*\\.pdf'],
443+
ExclusionFilters: ['.*private.*\\.pdf'],
496444
},
497445
{
498446
ObjectType: 'Contract',
499-
InclusionFilters: [
500-
'.*public.*\\.pdf',
501-
],
502-
ExclusionFilters: [
503-
'.*confidential.*\\.pdf',
504-
],
447+
InclusionFilters: ['.*public.*\\.pdf'],
448+
ExclusionFilters: ['.*confidential.*\\.pdf'],
505449
},
506450
],
507451
},
@@ -510,8 +454,5 @@ describe('Third Party Data Source', () => {
510454
},
511455
},
512456
});
513-
514457
});
515-
516-
517458
});

0 commit comments

Comments
 (0)