1+ import * as path from 'path' ;
12import * as ecr from 'aws-cdk-lib/aws-ecr' ;
23import * as cdk from 'aws-cdk-lib' ;
4+ import { Template } from 'aws-cdk-lib/assertions' ;
35import { AgentRuntimeArtifact } from '../../../lib/runtime/runtime-artifact' ;
46import { Runtime } from '../../../lib/runtime/runtime' ;
57
@@ -42,7 +44,7 @@ describe('AgentRuntimeArtifact tests', () => {
4244 test ( 'Should use default options when not specified for asset' , ( ) => {
4345 // Call without specifying options to use default {}
4446 // Use the testArtifact directory that exists in tests
45- const artifact = AgentRuntimeArtifact . fromAsset ( 'test/agentcore/runtime/ testArtifact') ;
47+ const artifact = AgentRuntimeArtifact . fromAsset ( path . join ( __dirname , ' testArtifact') ) ;
4648
4749 const runtime = new Runtime ( stack , 'test-runtime' , {
4850 runtimeName : 'test_runtime' ,
@@ -58,7 +60,7 @@ describe('AgentRuntimeArtifact tests', () => {
5860 } ) ;
5961
6062 test ( 'Should throw error if _render is called before bind for AssetImage' , ( ) => {
61- const artifact = AgentRuntimeArtifact . fromAsset ( 'test/agentcore/runtime/ testArtifact') ;
63+ const artifact = AgentRuntimeArtifact . fromAsset ( path . join ( __dirname , ' testArtifact') ) ;
6264
6365 // Try to render without binding
6466 expect ( ( ) => {
@@ -92,7 +94,7 @@ describe('AgentRuntimeArtifact tests', () => {
9294 } ) ;
9395
9496 test ( 'Should only bind once for asset image' , ( ) => {
95- const artifact = AgentRuntimeArtifact . fromAsset ( 'test/agentcore/runtime/ testArtifact', {
97+ const artifact = AgentRuntimeArtifact . fromAsset ( path . join ( __dirname , ' testArtifact') , {
9698 buildArgs : {
9799 TEST : 'value' ,
98100 } ,
@@ -114,4 +116,60 @@ describe('AgentRuntimeArtifact tests', () => {
114116 // Should return the same URI
115117 expect ( rendered1 . containerUri ) . toBe ( rendered2 . containerUri ) ;
116118 } ) ;
119+
120+ test ( 'Should use static construct ID for asset image regardless of directory' , ( ) => {
121+ // Create two separate stacks to test that the construct ID is always 'AgentRuntimeArtifact'
122+ const stack1 = new cdk . Stack ( app , 'test-stack-1' , {
123+ env : { account : '123456789012' , region : 'us-east-1' } ,
124+ } ) ;
125+ const stack2 = new cdk . Stack ( app , 'test-stack-2' , {
126+ env : { account : '123456789012' , region : 'us-east-1' } ,
127+ } ) ;
128+
129+ const testArtifactPath = path . join ( __dirname , 'testArtifact' ) ;
130+
131+ const runtime1 = new Runtime ( stack1 , 'test-runtime' , {
132+ runtimeName : 'test_runtime_1' ,
133+ agentRuntimeArtifact : AgentRuntimeArtifact . fromAsset ( testArtifactPath ) ,
134+ } ) ;
135+ const runtime2 = new Runtime ( stack2 , 'test-runtime' , {
136+ runtimeName : 'test_runtime_2' ,
137+ agentRuntimeArtifact : AgentRuntimeArtifact . fromAsset ( testArtifactPath ) ,
138+ } ) ;
139+
140+ // Both stacks should synthesize successfully with the static construct ID
141+ const template1 = Template . fromStack ( stack1 ) ;
142+ const template2 = Template . fromStack ( stack2 ) ;
143+
144+ template1 . hasResourceProperties ( 'AWS::BedrockAgentCore::Runtime' , {
145+ AgentRuntimeName : 'test_runtime_1' ,
146+ } ) ;
147+ template2 . hasResourceProperties ( 'AWS::BedrockAgentCore::Runtime' , {
148+ AgentRuntimeName : 'test_runtime_2' ,
149+ } ) ;
150+
151+ // Verify both runtimes have the same static construct ID for the asset
152+ const assetNode1 = runtime1 . node . findChild ( 'AgentRuntimeArtifact' ) ;
153+ const assetNode2 = runtime2 . node . findChild ( 'AgentRuntimeArtifact' ) ;
154+ expect ( assetNode1 . node . id ) . toBe ( 'AgentRuntimeArtifact' ) ;
155+ expect ( assetNode1 . node . id ) . toEqual ( assetNode2 . node . id ) ;
156+ } ) ;
157+
158+ test ( 'internal: should throw when binding different asset artifacts to same scope' , ( ) => {
159+ const testArtifactPath = path . join ( __dirname , 'testArtifact' ) ;
160+
161+ const runtime = new Runtime ( stack , 'test-runtime' , {
162+ runtimeName : 'test_runtime' ,
163+ agentRuntimeArtifact : AgentRuntimeArtifact . fromAsset ( testArtifactPath ) ,
164+ } ) ;
165+
166+ // Synthesize to trigger lazy asset creation
167+ Template . fromStack ( stack ) ;
168+
169+ const artifact2 = AgentRuntimeArtifact . fromAsset ( testArtifactPath ) ;
170+
171+ expect ( ( ) => {
172+ artifact2 . bind ( runtime , runtime ) ;
173+ } ) . toThrow ( / T h e r e i s a l r e a d y a C o n s t r u c t w i t h n a m e ' A g e n t R u n t i m e A r t i f a c t ' / ) ;
174+ } ) ;
117175} ) ;
0 commit comments