Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ export class SelfManagedMemoryStrategy implements IMemoryStrategy {
private _validateHistoricalContextWindowSize = (historicalContextWindowSize: number): string[] => {
let errors: string[] = [];

if (cdk.Token.isUnresolved(historicalContextWindowSize)) {
return errors;
}

if (historicalContextWindowSize < HISTORICAL_CONTEXT_WINDOW_SIZE_MIN
|| historicalContextWindowSize > HISTORICAL_CONTEXT_WINDOW_SIZE_MAX) {
errors.push(`Historical context window size must be between ${HISTORICAL_CONTEXT_WINDOW_SIZE_MIN} and ${HISTORICAL_CONTEXT_WINDOW_SIZE_MAX}, got ${historicalContextWindowSize}`);
Expand All @@ -309,23 +313,23 @@ export class SelfManagedMemoryStrategy implements IMemoryStrategy {
let errors: string[] = [];

// Validate message-based trigger
if (triggerConditions.messageBasedTrigger !== undefined) {
if (triggerConditions.messageBasedTrigger !== undefined && !cdk.Token.isUnresolved(triggerConditions.messageBasedTrigger)) {
if (triggerConditions.messageBasedTrigger < MESSAGE_BASED_TRIGGER_MIN
|| triggerConditions.messageBasedTrigger > MESSAGE_BASED_TRIGGER_MAX) {
errors.push(`Message-based trigger must be between ${MESSAGE_BASED_TRIGGER_MIN} and ${MESSAGE_BASED_TRIGGER_MAX}, got ${triggerConditions.messageBasedTrigger}`);
}
}

// Validate time-based trigger
if (triggerConditions.timeBasedTrigger !== undefined) {
if (triggerConditions.timeBasedTrigger !== undefined && !triggerConditions.timeBasedTrigger.isUnresolved()) {
const seconds = triggerConditions.timeBasedTrigger.toSeconds();
if (seconds < TIME_BASED_TRIGGER_MIN || seconds > TIME_BASED_TRIGGER_MAX) {
errors.push(`Time-based trigger must be between ${TIME_BASED_TRIGGER_MIN} and ${TIME_BASED_TRIGGER_MAX} seconds, got ${seconds}`);
}
}

// Validate token-based trigger
if (triggerConditions.tokenBasedTrigger !== undefined) {
if (triggerConditions.tokenBasedTrigger !== undefined && !cdk.Token.isUnresolved(triggerConditions.tokenBasedTrigger)) {
if (triggerConditions.tokenBasedTrigger < TOKEN_BASED_TRIGGER_MIN || triggerConditions.tokenBasedTrigger > TOKEN_BASED_TRIGGER_MAX) {
errors.push(`Token-based trigger must be between ${TOKEN_BASED_TRIGGER_MIN} and ${TOKEN_BASED_TRIGGER_MAX}, got ${triggerConditions.tokenBasedTrigger}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,40 @@ describe('SelfManagedMemoryStrategy unit tests', () => {
}).toThrow('Token-based trigger must be between 100 and 500000, got 50');
});

test('Should skip validation when historicalContextWindowSize is an unresolved token', () => {
const param = new cdk.CfnParameter(stack, 'WindowSize', { type: 'Number', default: 10 });
expect(() => {
MemoryStrategy.usingSelfManaged({
name: 'token_historical',
historicalContextWindowSize: param.valueAsNumber,
invocationConfiguration: {
topic: topic,
s3Location: { bucketName: bucket.bucketName, objectKey: 'test/' },
},
});
}).not.toThrow();
});

test('Should skip validation when trigger conditions are unresolved tokens', () => {
const msgParam = new cdk.CfnParameter(stack, 'MsgTrigger', { type: 'Number', default: 5 });
const tokenParam = new cdk.CfnParameter(stack, 'TokenTrigger', { type: 'Number', default: 500 });
const timeParam = new cdk.CfnParameter(stack, 'TimeTrigger', { type: 'Number', default: 30 });
expect(() => {
MemoryStrategy.usingSelfManaged({
name: 'token_triggers',
invocationConfiguration: {
topic: topic,
s3Location: { bucketName: bucket.bucketName, objectKey: 'test/' },
},
triggerConditions: {
messageBasedTrigger: msgParam.valueAsNumber,
timeBasedTrigger: cdk.Duration.seconds(timeParam.valueAsNumber),
tokenBasedTrigger: tokenParam.valueAsNumber,
},
});
}).not.toThrow();
});

test('Should validate multiple trigger conditions', () => {
expect(() => {
MemoryStrategy.usingSelfManaged({
Expand Down
Loading