|
| 1 | +import { TagsSchema } from '../../../../schema/schemas/primitives/tags'; |
| 2 | +import { stripReservedTags } from '../import-utils'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
| 4 | + |
| 5 | +// Regression: a runtime retained after its CloudFormation stack was deleted keeps orphaned |
| 6 | +// aws:cloudformation:* tags. The import commands used to copy them verbatim into agentcore.json, |
| 7 | +// where TagsSchema rejects the reserved "aws:" prefix and blocks the import. |
| 8 | +describe('stripReservedTags', () => { |
| 9 | + const orphaned = { |
| 10 | + 'aws:cloudformation:stack-name': 'AgentCore-MyProject-default', |
| 11 | + 'aws:cloudformation:logical-id': 'ApplicationAgentMyAgentRuntime140BFE6B', |
| 12 | + 'aws:cloudformation:stack-id': |
| 13 | + 'arn:aws:cloudformation:us-east-1:123456789012:stack/AgentCore-MyProject-default/abc', |
| 14 | + }; |
| 15 | + |
| 16 | + it('drops every aws: reserved key, leaving no tags to persist', () => { |
| 17 | + expect(stripReservedTags(orphaned)).toBeUndefined(); |
| 18 | + }); |
| 19 | + |
| 20 | + it('keeps user tags and removes only reserved ones', () => { |
| 21 | + const kept = stripReservedTags({ ...orphaned, team: 'life-sciences', env: 'test' }); |
| 22 | + expect(kept).toEqual({ team: 'life-sciences', env: 'test' }); |
| 23 | + }); |
| 24 | + |
| 25 | + it('passes undefined through', () => { |
| 26 | + expect(stripReservedTags(undefined)).toBeUndefined(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('produces tags that survive the config schema (the actual blocker)', () => { |
| 30 | + // Before the fix, feeding orphaned tags straight to TagsSchema throws "aws:" reserved. |
| 31 | + expect(() => TagsSchema.parse(orphaned)).toThrow(); |
| 32 | + const cleaned = stripReservedTags({ ...orphaned, team: 'life-sciences' }); |
| 33 | + expect(() => TagsSchema.parse(cleaned)).not.toThrow(); |
| 34 | + }); |
| 35 | +}); |
0 commit comments