1- import { buildDeployedState , parseGatewayOutputs } from '../outputs' ;
1+ import { buildDeployedState , parseGatewayOutputs , parseMemoryOutputs } from '../outputs' ;
22import { describe , expect , it } from 'vitest' ;
33
44describe ( 'buildDeployedState' , ( ) => {
@@ -11,14 +11,13 @@ describe('buildDeployedState', () => {
1111 } ,
1212 } ;
1313
14- const result = buildDeployedState (
15- 'default' ,
16- 'TestStack' ,
14+ const result = buildDeployedState ( {
15+ targetName : 'default' ,
16+ stackName : 'TestStack' ,
1717 agents,
18- { } ,
19- undefined ,
20- 'arn:aws:kms:us-east-1:123456789012:key/abc-123'
21- ) ;
18+ gateways : { } ,
19+ identityKmsKeyArn : 'arn:aws:kms:us-east-1:123456789012:key/abc-123' ,
20+ } ) ;
2221
2322 expect ( result . targets . default ! . resources ?. identityKmsKeyArn ) . toBe ( 'arn:aws:kms:us-east-1:123456789012:key/abc-123' ) ;
2423 } ) ;
@@ -32,7 +31,7 @@ describe('buildDeployedState', () => {
3231 } ,
3332 } ;
3433
35- const result = buildDeployedState ( 'default' , 'TestStack' , agents , { } ) ;
34+ const result = buildDeployedState ( { targetName : 'default' , stackName : 'TestStack' , agents, gateways : { } } ) ;
3635
3736 expect ( result . targets . default ! . resources ?. identityKmsKeyArn ) . toBeUndefined ( ) ;
3837 } ) ;
@@ -49,14 +48,14 @@ describe('buildDeployedState', () => {
4948 } ,
5049 } ;
5150
52- const result = buildDeployedState (
53- 'dev' ,
54- 'DevStack' ,
55- { } ,
56- { } ,
51+ const result = buildDeployedState ( {
52+ targetName : 'dev' ,
53+ stackName : 'DevStack' ,
54+ agents : { } ,
55+ gateways : { } ,
5756 existingState,
58- 'arn:aws:kms:us-east-1:123456789012:key/dev-key'
59- ) ;
57+ identityKmsKeyArn : 'arn:aws:kms:us-east-1:123456789012:key/dev-key' ,
58+ } ) ;
6059
6160 expect ( result . targets . prod ! . resources ?. stackName ) . toBe ( 'ProdStack' ) ;
6261 expect ( result . targets . dev ! . resources ?. identityKmsKeyArn ) . toBe ( 'arn:aws:kms:us-east-1:123456789012:key/dev-key' ) ;
@@ -77,7 +76,13 @@ describe('buildDeployedState', () => {
7776 } ,
7877 } ;
7978
80- const result = buildDeployedState ( 'default' , 'TestStack' , agents , { } , undefined , undefined , credentials ) ;
79+ const result = buildDeployedState ( {
80+ targetName : 'default' ,
81+ stackName : 'TestStack' ,
82+ agents,
83+ gateways : { } ,
84+ credentials,
85+ } ) ;
8186
8287 expect ( result . targets . default ! . resources ?. credentials ) . toEqual ( credentials ) ;
8388 } ) ;
@@ -91,7 +96,7 @@ describe('buildDeployedState', () => {
9196 } ,
9297 } ;
9398
94- const result = buildDeployedState ( 'default' , 'TestStack' , agents , { } ) ;
99+ const result = buildDeployedState ( { targetName : 'default' , stackName : 'TestStack' , agents, gateways : { } } ) ;
95100
96101 expect ( result . targets . default ! . resources ?. credentials ) . toBeUndefined ( ) ;
97102 } ) ;
@@ -105,10 +110,53 @@ describe('buildDeployedState', () => {
105110 } ,
106111 } ;
107112
108- const result = buildDeployedState ( 'default' , 'TestStack' , agents , { } , undefined , undefined , { } ) ;
113+ const result = buildDeployedState ( {
114+ targetName : 'default' ,
115+ stackName : 'TestStack' ,
116+ agents,
117+ gateways : { } ,
118+ credentials : { } ,
119+ } ) ;
109120
110121 expect ( result . targets . default ! . resources ?. credentials ) . toBeUndefined ( ) ;
111122 } ) ;
123+
124+ it ( 'includes memories in deployed state when provided' , ( ) => {
125+ const memories = {
126+ 'my-memory' : {
127+ memoryId : 'mem-123' ,
128+ memoryArn : 'arn:aws:bedrock:us-east-1:123456789012:memory/mem-123' ,
129+ } ,
130+ } ;
131+
132+ const result = buildDeployedState ( {
133+ targetName : 'default' ,
134+ stackName : 'TestStack' ,
135+ agents : { } ,
136+ gateways : { } ,
137+ memories,
138+ } ) ;
139+
140+ expect ( result . targets . default ! . resources ?. memories ) . toEqual ( memories ) ;
141+ } ) ;
142+
143+ it ( 'omits memories field when memories is empty object' , ( ) => {
144+ const result = buildDeployedState ( {
145+ targetName : 'default' ,
146+ stackName : 'TestStack' ,
147+ agents : { } ,
148+ gateways : { } ,
149+ memories : { } ,
150+ } ) ;
151+
152+ expect ( result . targets . default ! . resources ?. memories ) . toBeUndefined ( ) ;
153+ } ) ;
154+
155+ it ( 'omits agents field when agents is empty object' , ( ) => {
156+ const result = buildDeployedState ( { targetName : 'default' , stackName : 'TestStack' , agents : { } , gateways : { } } ) ;
157+
158+ expect ( result . targets . default ! . resources ?. agents ) . toBeUndefined ( ) ;
159+ } ) ;
112160} ) ;
113161
114162describe ( 'parseGatewayOutputs' , ( ) => {
@@ -183,3 +231,57 @@ describe('parseGatewayOutputs', () => {
183231 expect ( result [ 'third-gateway' ] ?. gatewayUrl ) . toBe ( 'https://third.url' ) ;
184232 } ) ;
185233} ) ;
234+
235+ describe ( 'parseMemoryOutputs' , ( ) => {
236+ it ( 'extracts memory outputs matching pattern' , ( ) => {
237+ const outputs = {
238+ ApplicationMemoryMyMemoryIdOutputABC123 : 'mem-123' ,
239+ ApplicationMemoryMyMemoryArnOutputDEF456 : 'arn:aws:bedrock:us-east-1:123:memory/mem-123' ,
240+ UnrelatedOutput : 'some-value' ,
241+ } ;
242+
243+ const result = parseMemoryOutputs ( outputs , [ 'my-memory' ] ) ;
244+
245+ expect ( result ) . toEqual ( {
246+ 'my-memory' : {
247+ memoryId : 'mem-123' ,
248+ memoryArn : 'arn:aws:bedrock:us-east-1:123:memory/mem-123' ,
249+ } ,
250+ } ) ;
251+ } ) ;
252+
253+ it ( 'handles multiple memories' , ( ) => {
254+ const outputs = {
255+ ApplicationMemoryFirstMemoryIdOutput123 : 'mem-1' ,
256+ ApplicationMemoryFirstMemoryArnOutput123 : 'arn:mem-1' ,
257+ ApplicationMemorySecondMemoryIdOutput456 : 'mem-2' ,
258+ ApplicationMemorySecondMemoryArnOutput456 : 'arn:mem-2' ,
259+ } ;
260+
261+ const result = parseMemoryOutputs ( outputs , [ 'first-memory' , 'second-memory' ] ) ;
262+
263+ expect ( Object . keys ( result ) ) . toHaveLength ( 2 ) ;
264+ expect ( result [ 'first-memory' ] ?. memoryId ) . toBe ( 'mem-1' ) ;
265+ expect ( result [ 'second-memory' ] ?. memoryId ) . toBe ( 'mem-2' ) ;
266+ } ) ;
267+
268+ it ( 'returns empty record when no memory outputs found' , ( ) => {
269+ const outputs = {
270+ UnrelatedOutput : 'some-value' ,
271+ } ;
272+
273+ const result = parseMemoryOutputs ( outputs , [ 'my-memory' ] ) ;
274+
275+ expect ( result ) . toEqual ( { } ) ;
276+ } ) ;
277+
278+ it ( 'skips incomplete memory outputs (missing ARN)' , ( ) => {
279+ const outputs = {
280+ ApplicationMemoryMyMemoryIdOutputABC123 : 'mem-123' ,
281+ } ;
282+
283+ const result = parseMemoryOutputs ( outputs , [ 'my-memory' ] ) ;
284+
285+ expect ( result ) . toEqual ( { } ) ;
286+ } ) ;
287+ } ) ;
0 commit comments