1+ import * as path from 'path' ;
12import * as ecr from 'aws-cdk-lib/aws-ecr' ;
23import * as cdk from 'aws-cdk-lib' ;
34import { AgentRuntimeArtifact } from '../../../lib/runtime/runtime-artifact' ;
@@ -42,7 +43,7 @@ describe('AgentRuntimeArtifact tests', () => {
4243 test ( 'Should use default options when not specified for asset' , ( ) => {
4344 // Call without specifying options to use default {}
4445 // Use the testArtifact directory that exists in tests
45- const artifact = AgentRuntimeArtifact . fromAsset ( 'test/agentcore/runtime/ testArtifact') ;
46+ const artifact = AgentRuntimeArtifact . fromAsset ( path . join ( __dirname , ' testArtifact') ) ;
4647
4748 const runtime = new Runtime ( stack , 'test-runtime' , {
4849 runtimeName : 'test_runtime' ,
@@ -58,7 +59,7 @@ describe('AgentRuntimeArtifact tests', () => {
5859 } ) ;
5960
6061 test ( 'Should throw error if _render is called before bind for AssetImage' , ( ) => {
61- const artifact = AgentRuntimeArtifact . fromAsset ( 'test/agentcore/runtime/ testArtifact') ;
62+ const artifact = AgentRuntimeArtifact . fromAsset ( path . join ( __dirname , ' testArtifact') ) ;
6263
6364 // Try to render without binding
6465 expect ( ( ) => {
@@ -92,7 +93,7 @@ describe('AgentRuntimeArtifact tests', () => {
9293 } ) ;
9394
9495 test ( 'Should only bind once for asset image' , ( ) => {
95- const artifact = AgentRuntimeArtifact . fromAsset ( 'test/agentcore/runtime/ testArtifact', {
96+ const artifact = AgentRuntimeArtifact . fromAsset ( path . join ( __dirname , ' testArtifact') , {
9697 buildArgs : {
9798 TEST : 'value' ,
9899 } ,
@@ -114,4 +115,61 @@ describe('AgentRuntimeArtifact tests', () => {
114115 // Should return the same URI
115116 expect ( rendered1 . containerUri ) . toBe ( rendered2 . containerUri ) ;
116117 } ) ;
118+
119+ test ( 'Should use static construct ID for asset image regardless of directory' , ( ) => {
120+ // Create two separate stacks to test that the construct ID is always 'AgentRuntimeArtifact'
121+ const stack1 = new cdk . Stack ( app , 'test-stack-1' , {
122+ env : { account : '123456789012' , region : 'us-east-1' } ,
123+ } ) ;
124+ const stack2 = new cdk . Stack ( app , 'test-stack-2' , {
125+ env : { account : '123456789012' , region : 'us-east-1' } ,
126+ } ) ;
127+
128+ const testArtifactPath = path . join ( __dirname , 'testArtifact' ) ;
129+ const artifact1 = AgentRuntimeArtifact . fromAsset ( testArtifactPath ) ;
130+ const artifact2 = AgentRuntimeArtifact . fromAsset ( testArtifactPath ) ;
131+
132+ const runtime1 = new Runtime ( stack1 , 'test-runtime' , {
133+ runtimeName : 'test_runtime_1' ,
134+ agentRuntimeArtifact : artifact1 ,
135+ } ) ;
136+ const runtime2 = new Runtime ( stack2 , 'test-runtime' , {
137+ runtimeName : 'test_runtime_2' ,
138+ agentRuntimeArtifact : artifact2 ,
139+ } ) ;
140+
141+ artifact1 . bind ( stack1 , runtime1 ) ;
142+ artifact2 . bind ( stack2 , runtime2 ) ;
143+
144+ // Both should succeed - if the ID was dynamic based on directory hash,
145+ // different directories would produce different IDs, but now it's static
146+ const rendered1 : any = artifact1 . _render ( ) ;
147+ const rendered2 : any = artifact2 . _render ( ) ;
148+
149+ expect ( rendered1 . containerUri ) . toBeDefined ( ) ;
150+ expect ( rendered2 . containerUri ) . toBeDefined ( ) ;
151+ } ) ;
152+
153+ test ( 'Should fail when binding different asset artifacts to same scope' , ( ) => {
154+ // This test verifies the static ID behavior - binding different artifacts
155+ // to the same scope should fail because the construct ID is static
156+ const testArtifactPath = path . join ( __dirname , 'testArtifact' ) ;
157+ const artifact = AgentRuntimeArtifact . fromAsset ( testArtifactPath ) ;
158+
159+ const runtime = new Runtime ( stack , 'test-runtime' , {
160+ runtimeName : 'test_runtime' ,
161+ agentRuntimeArtifact : artifact ,
162+ } ) ;
163+
164+ // First bind should succeed
165+ artifact . bind ( stack , runtime ) ;
166+
167+ // Create a new artifact (same directory, but different artifact instance)
168+ const artifact2 = AgentRuntimeArtifact . fromAsset ( testArtifactPath ) ;
169+
170+ // Second bind to the same scope should fail because the construct ID 'AgentRuntimeArtifact' already exists
171+ expect ( ( ) => {
172+ artifact2 . bind ( stack , 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