|
| 1 | +/** |
| 2 | + * Tests for execution role import from starter toolkit YAML. |
| 3 | + */ |
| 4 | +import type { AgentEnvSpec } from '../../../../schema/schemas/agent-env'; |
| 5 | +import type { ParsedStarterToolkitConfig } from '../types'; |
| 6 | +import { parseStarterToolkitYaml } from '../yaml-parser'; |
| 7 | +import * as path from 'node:path'; |
| 8 | +import { describe, expect, it } from 'vitest'; |
| 9 | + |
| 10 | +const APP_DIR = 'app'; |
| 11 | + |
| 12 | +function toAgentEnvSpec(agent: ParsedStarterToolkitConfig['agents'][0]): AgentEnvSpec { |
| 13 | + const codeLocation = path.join(APP_DIR, agent.name); |
| 14 | + const entrypoint = path.basename(agent.entrypoint); |
| 15 | + const spec: AgentEnvSpec = { |
| 16 | + type: 'AgentCoreRuntime', |
| 17 | + name: agent.name, |
| 18 | + build: agent.build, |
| 19 | + entrypoint: entrypoint as AgentEnvSpec['entrypoint'], |
| 20 | + codeLocation: codeLocation as AgentEnvSpec['codeLocation'], |
| 21 | + runtimeVersion: (agent.runtimeVersion ?? 'PYTHON_3_12') as AgentEnvSpec['runtimeVersion'], |
| 22 | + protocol: agent.protocol, |
| 23 | + networkMode: agent.networkMode, |
| 24 | + instrumentation: { enableOtel: agent.enableOtel }, |
| 25 | + }; |
| 26 | + if (agent.networkMode === 'VPC' && agent.networkConfig) { |
| 27 | + spec.networkConfig = agent.networkConfig; |
| 28 | + } |
| 29 | + if (agent.executionRoleArn) { |
| 30 | + spec.executionRoleArn = agent.executionRoleArn; |
| 31 | + } |
| 32 | + return spec; |
| 33 | +} |
| 34 | + |
| 35 | +const FIXTURE = path.join(__dirname, 'fixtures', 'agent-with-execution-role.yaml'); |
| 36 | +const FIXTURE_NO_ROLE = path.join(__dirname, 'fixtures', 'different-agent.yaml'); |
| 37 | + |
| 38 | +describe('parseStarterToolkitYaml: executionRoleArn', () => { |
| 39 | + it('extracts executionRoleArn from YAML with execution_role', () => { |
| 40 | + const parsed = parseStarterToolkitYaml(FIXTURE); |
| 41 | + expect(parsed.agents).toHaveLength(1); |
| 42 | + expect(parsed.agents[0]!.executionRoleArn).toBe('arn:aws:iam::123456789012:role/StarterToolkitExecutionRole'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('returns undefined executionRoleArn when execution_role is absent', () => { |
| 46 | + const parsed = parseStarterToolkitYaml(FIXTURE_NO_ROLE); |
| 47 | + expect(parsed.agents[0]!.executionRoleArn).toBeUndefined(); |
| 48 | + }); |
| 49 | +}); |
| 50 | + |
| 51 | +describe('toAgentEnvSpec: executionRoleArn', () => { |
| 52 | + it('includes executionRoleArn in spec when present', () => { |
| 53 | + const parsed = parseStarterToolkitYaml(FIXTURE); |
| 54 | + const spec = toAgentEnvSpec(parsed.agents[0]!); |
| 55 | + expect(spec.executionRoleArn).toBe('arn:aws:iam::123456789012:role/StarterToolkitExecutionRole'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('omits executionRoleArn from spec when absent', () => { |
| 59 | + const parsed = parseStarterToolkitYaml(FIXTURE_NO_ROLE); |
| 60 | + const spec = toAgentEnvSpec(parsed.agents[0]!); |
| 61 | + expect(spec.executionRoleArn).toBeUndefined(); |
| 62 | + }); |
| 63 | +}); |
0 commit comments