|
17 | 17 | * SOFTWARE. |
18 | 18 | */ |
19 | 19 |
|
| 20 | +import { execFileSync } from 'node:child_process'; |
| 21 | +import { readFileSync, existsSync } from 'node:fs'; |
| 22 | +import { join } from 'node:path'; |
| 23 | + |
20 | 24 | import { Stack } from 'aws-cdk-lib'; |
21 | 25 |
|
22 | 26 | import { allPolicies } from '../../src/bootstrap/policies'; |
@@ -184,3 +188,48 @@ describe('resource-action-map', () => { |
184 | 188 | }); |
185 | 189 | }); |
186 | 190 | }); |
| 191 | + |
| 192 | +describe('Synth coverage', () => { |
| 193 | + const SKIP_TYPES = new Set([ |
| 194 | + 'AWS::CDK::Metadata', |
| 195 | + 'Custom::AWS', |
| 196 | + 'Custom::S3AutoDeleteObjects', |
| 197 | + 'Custom::VpcRestrictDefaultSG', |
| 198 | + ]); |
| 199 | + |
| 200 | + function getResourceTypes(templatePath: string): string[] { |
| 201 | + if (!existsSync(templatePath)) return []; |
| 202 | + const template = JSON.parse(readFileSync(templatePath, 'utf-8')); |
| 203 | + const resources = template.Resources as Record<string, { Type: string }>; |
| 204 | + return [...new Set(Object.values(resources).map(r => r.Type))]; |
| 205 | + } |
| 206 | + |
| 207 | + it('all agentcore resource types have map entries', () => { |
| 208 | + const templatePath = join(__dirname, '..', '..', 'cdk.out', 'backgroundagent-dev.template.json'); |
| 209 | + const types = getResourceTypes(templatePath); |
| 210 | + if (types.length === 0) return; |
| 211 | + const unmapped = types.filter(t => !SKIP_TYPES.has(t) && !RESOURCE_ACTION_MAP[t]); |
| 212 | + expect(unmapped).toEqual([]); |
| 213 | + }); |
| 214 | + |
| 215 | + it('all ecs resource types have map entries', () => { |
| 216 | + const ecsOutDir = join(__dirname, '..', '..', 'cdk.out.ecs'); |
| 217 | + const ecsTemplatePath = join(ecsOutDir, 'backgroundagent-dev.template.json'); |
| 218 | + // Try to synth with ecs config — skip if unavailable (no AWS creds, etc.) |
| 219 | + if (!existsSync(ecsTemplatePath)) { |
| 220 | + try { |
| 221 | + execFileSync('npx', ['cdk', 'synth', '-q', '-c', 'compute_type=ecs', '-o', ecsOutDir], { |
| 222 | + cwd: join(__dirname, '..', '..'), |
| 223 | + stdio: 'pipe', |
| 224 | + timeout: 120000, |
| 225 | + }); |
| 226 | + } catch { |
| 227 | + return; // synth unavailable — skip gracefully |
| 228 | + } |
| 229 | + } |
| 230 | + const types = getResourceTypes(ecsTemplatePath); |
| 231 | + if (types.length === 0) return; |
| 232 | + const unmapped = types.filter(t => !SKIP_TYPES.has(t) && !RESOURCE_ACTION_MAP[t]); |
| 233 | + expect(unmapped).toEqual([]); |
| 234 | + }); |
| 235 | +}); |
0 commit comments