@friggframework/devtools 2.0.0-next.120 → 2.0.0-next.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frigg-cli/README.md +77 -30
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +30 -24
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
- package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
- package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
- package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
- package/frigg-cli/generate-command/index.js +1 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +9 -4
- package/frigg-cli/init-command/backend-first-handler.js +397 -554
- package/frigg-cli/init-command/deployment-modes.js +7 -0
- package/frigg-cli/init-command/index.js +82 -35
- package/frigg-cli/init-command/safe-path.js +58 -0
- package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
- package/frigg-cli/install-command/app-definition.js +174 -0
- package/frigg-cli/install-command/commit-changes.js +40 -8
- package/frigg-cli/install-command/environment-variables.js +15 -0
- package/frigg-cli/install-command/index.js +96 -21
- package/frigg-cli/install-command/install-package.js +77 -4
- package/frigg-cli/install-command/integration-file.js +20 -11
- package/frigg-cli/install-command/resolve-module.js +69 -0
- package/frigg-cli/install-command/template.js +102 -75
- package/frigg-cli/install-command/validate-package.js +36 -4
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/templates/backend/README.md +267 -0
- package/frigg-cli/templates/backend/env.example +20 -0
- package/frigg-cli/templates/backend/gitignore +10 -0
- package/frigg-cli/templates/backend/index.js +114 -0
- package/frigg-cli/templates/backend/infrastructure.js +20 -0
- package/frigg-cli/test/init-command.test.js +9 -2
- package/infrastructure/__tests__/postgres-config.test.js +241 -835
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
- package/infrastructure/__tests__/template-generation.test.js +36 -8
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +21 -1
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
- package/infrastructure/domains/networking/vpc-builder.js +18 -8
- package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
- package/infrastructure/domains/security/iam-generator.js +112 -5
- package/infrastructure/domains/security/iam-generator.test.js +94 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +7 -2
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +21 -0
- package/infrastructure/infrastructure-composer.test.js +268 -794
- package/infrastructure/scripts/build-prisma-layer.test.js +28 -7
- package/infrastructure/scripts/build-time-discovery.test.js +18 -3
- package/package.json +10 -8
- package/frigg-cli/index.test.js +0 -158
- package/infrastructure/integration.test.js +0 -381
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app scaffolded by `frigg init` must deploy with no always-on AWS cost.
|
|
3
|
+
*
|
|
4
|
+
* Scaffolds the backend template, loads its Definition and composes it the way
|
|
5
|
+
* `frigg deploy` does (AWS discovery stubbed), then asserts the template has
|
|
6
|
+
* no VPC, NAT gateway, Elastic IP, VPC endpoint or RDS/Aurora resource, that
|
|
7
|
+
* no Lambda is attached to a VPC, and that field-level encryption still gets
|
|
8
|
+
* its KMS key.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const os = require('os');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const fs = require('fs-extra');
|
|
14
|
+
|
|
15
|
+
jest.mock('../domains/shared/resource-discovery', () => ({
|
|
16
|
+
...jest.requireActual('../domains/shared/resource-discovery'),
|
|
17
|
+
gatherDiscoveredResources: jest.fn(),
|
|
18
|
+
}));
|
|
19
|
+
jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
|
|
20
|
+
ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
gatherDiscoveredResources,
|
|
25
|
+
} = require('../domains/shared/resource-discovery');
|
|
26
|
+
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
27
|
+
const BackendFirstHandler = require('../../frigg-cli/init-command/backend-first-handler');
|
|
28
|
+
|
|
29
|
+
const FORBIDDEN_RESOURCE_TYPES = [
|
|
30
|
+
'AWS::EC2::VPC',
|
|
31
|
+
'AWS::EC2::NatGateway',
|
|
32
|
+
'AWS::EC2::EIP',
|
|
33
|
+
'AWS::EC2::VPCEndpoint',
|
|
34
|
+
'AWS::RDS::DBCluster',
|
|
35
|
+
'AWS::RDS::DBInstance',
|
|
36
|
+
'AWS::RDS::DBSubnetGroup',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
// An account that already holds a default VPC, subnets, a NAT gateway and an
|
|
40
|
+
// Aurora cluster: none of it may leak into the scaffolded app's template.
|
|
41
|
+
const BUSY_ACCOUNT_DISCOVERY = {
|
|
42
|
+
defaultVpcId: 'vpc-123456',
|
|
43
|
+
vpcCidr: '172.31.0.0/16',
|
|
44
|
+
defaultSecurityGroupId: 'sg-123456',
|
|
45
|
+
privateSubnetId1: 'subnet-123456',
|
|
46
|
+
privateSubnetId2: 'subnet-789012',
|
|
47
|
+
publicSubnetId1: 'subnet-public-1',
|
|
48
|
+
publicSubnetId2: 'subnet-public-2',
|
|
49
|
+
defaultRouteTableId: 'rtb-123456',
|
|
50
|
+
existingNatGatewayId: 'nat-default123',
|
|
51
|
+
auroraClusterEndpoint: 'c.cluster-abc123.us-east-1.rds.amazonaws.com',
|
|
52
|
+
auroraPort: 5432,
|
|
53
|
+
auroraEngine: 'aurora-postgresql',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
describe('frigg init default infrastructure', () => {
|
|
57
|
+
let tmpDir;
|
|
58
|
+
let Definition;
|
|
59
|
+
let logSpy;
|
|
60
|
+
|
|
61
|
+
beforeAll(async () => {
|
|
62
|
+
logSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
63
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-default-infra-'));
|
|
64
|
+
const target = path.join(tmpDir, 'demo-app');
|
|
65
|
+
await new BackendFirstHandler(target, {
|
|
66
|
+
yes: true,
|
|
67
|
+
install: false,
|
|
68
|
+
git: false,
|
|
69
|
+
}).initialize();
|
|
70
|
+
({ Definition } = require(path.join(target, 'index.js')));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterAll(() => {
|
|
74
|
+
fs.removeSync(tmpDir);
|
|
75
|
+
logSpy.mockRestore();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
80
|
+
process.argv = ['node', 'test'];
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const compose = async (discovery) => {
|
|
84
|
+
gatherDiscoveredResources.mockResolvedValue(discovery);
|
|
85
|
+
// The composer mutates nested parts of the definition.
|
|
86
|
+
return composeServerlessDefinition(
|
|
87
|
+
JSON.parse(JSON.stringify(Definition))
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const resourceTypes = (definition) =>
|
|
92
|
+
Object.values(definition.resources.Resources).map((r) => r.Type);
|
|
93
|
+
|
|
94
|
+
it('passes the app-definition schema', () => {
|
|
95
|
+
const { validateAppDefinition } = require('@friggframework/schemas');
|
|
96
|
+
expect(validateAppDefinition(Definition).valid).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it.each([
|
|
100
|
+
['an empty account', {}],
|
|
101
|
+
['an account with existing VPC/NAT/Aurora', BUSY_ACCOUNT_DISCOVERY],
|
|
102
|
+
])('composes no always-on resources in %s', async (_label, discovery) => {
|
|
103
|
+
const definition = await compose(discovery);
|
|
104
|
+
const types = resourceTypes(definition);
|
|
105
|
+
|
|
106
|
+
for (const forbidden of FORBIDDEN_RESOURCE_TYPES) {
|
|
107
|
+
expect(types).not.toContain(forbidden);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// No Lambda is attached to a VPC.
|
|
111
|
+
expect(definition.provider.vpc).toBeUndefined();
|
|
112
|
+
for (const fn of Object.values(definition.functions)) {
|
|
113
|
+
expect(fn.vpc).toBeUndefined();
|
|
114
|
+
}
|
|
115
|
+
for (const resource of Object.values(definition.resources.Resources)) {
|
|
116
|
+
expect(resource.Properties?.VpcConfig).toBeUndefined();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('keeps field-level encryption on with a per-stage KMS key', async () => {
|
|
121
|
+
const definition = await compose({});
|
|
122
|
+
|
|
123
|
+
expect(definition.resources.Resources.FriggKMSKey.Type).toBe(
|
|
124
|
+
'AWS::KMS::Key'
|
|
125
|
+
);
|
|
126
|
+
expect(definition.provider.environment.KMS_KEY_ARN).toEqual({
|
|
127
|
+
'Fn::GetAtt': ['FriggKMSKey', 'Arn'],
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('connects to the external database through DATABASE_URL', async () => {
|
|
132
|
+
const definition = await compose({});
|
|
133
|
+
|
|
134
|
+
expect(definition.provider.environment.DATABASE_URL).toBe(
|
|
135
|
+
"${env:DATABASE_URL, ''}"
|
|
136
|
+
);
|
|
137
|
+
expect(definition.provider.environment.DB_TYPE).toBe('postgresql');
|
|
138
|
+
expect(definition.resources.Resources.FriggDBSecret).toBeUndefined();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('expires Lambda logs after 14 days', async () => {
|
|
142
|
+
// Without provider.logRetentionInDays, osls creates log groups that
|
|
143
|
+
// never expire, so CloudWatch storage grows forever.
|
|
144
|
+
const definition = await compose({});
|
|
145
|
+
|
|
146
|
+
expect(definition.provider.logRetentionInDays).toBe(14);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
* valid, consistent CloudFormation templates.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
// Never touch AWS or the real Prisma layer from a unit test: discovery returns
|
|
9
|
+
// nothing (a fresh account), and the layer build (npm install into
|
|
10
|
+
// layers/prisma) is stubbed out.
|
|
11
|
+
jest.mock('../domains/shared/resource-discovery', () => ({
|
|
12
|
+
...jest.requireActual('../domains/shared/resource-discovery'),
|
|
13
|
+
gatherDiscoveredResources: jest.fn().mockResolvedValue({}),
|
|
14
|
+
}));
|
|
15
|
+
jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
|
|
16
|
+
ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
|
|
17
|
+
}));
|
|
18
|
+
|
|
8
19
|
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
9
20
|
|
|
10
21
|
describe('CloudFormation Template Generation', () => {
|
|
@@ -86,11 +97,16 @@ describe('CloudFormation Template Generation', () => {
|
|
|
86
97
|
|
|
87
98
|
// Framework-generated resources (created by Serverless Framework, not our builders)
|
|
88
99
|
const frameworkResources = ['HttpApi', 'HttpApiLogGroup'];
|
|
100
|
+
// Serverless names each function's resource `<Name>LambdaFunction`
|
|
101
|
+
// (e.g. dbMigrationWorker -> DbMigrationWorkerLambdaFunction).
|
|
102
|
+
const functionResources = Object.keys(result.functions || {}).map(
|
|
103
|
+
(name) => `${name.charAt(0).toUpperCase()}${name.slice(1)}LambdaFunction`
|
|
104
|
+
);
|
|
89
105
|
|
|
90
|
-
// Verify all Refs point to existing resources, layers, or framework resources
|
|
106
|
+
// Verify all Refs point to existing resources, layers, functions or framework resources
|
|
91
107
|
refs.forEach(ref => {
|
|
92
108
|
if (!frameworkResources.includes(ref)) {
|
|
93
|
-
expect(allIds).toContain(ref);
|
|
109
|
+
expect([...allIds, ...functionResources]).toContain(ref);
|
|
94
110
|
}
|
|
95
111
|
});
|
|
96
112
|
});
|
|
@@ -123,7 +139,9 @@ describe('CloudFormation Template Generation', () => {
|
|
|
123
139
|
integrations: [
|
|
124
140
|
{ Definition: { name: 'slack' } }
|
|
125
141
|
],
|
|
126
|
-
|
|
142
|
+
// Discovery is stubbed to an empty account, so the VPC must be
|
|
143
|
+
// created explicitly; `auto` with no VPC found is a hard error.
|
|
144
|
+
vpc: { enable: true, management: 'create-new' },
|
|
127
145
|
encryption: { fieldLevelEncryptionMethod: 'kms' }
|
|
128
146
|
};
|
|
129
147
|
|
|
@@ -251,7 +269,9 @@ describe('CloudFormation Template Generation', () => {
|
|
|
251
269
|
it('should create VPC resources when enabled', async () => {
|
|
252
270
|
const appDefinition = {
|
|
253
271
|
name: 'test-app',
|
|
254
|
-
|
|
272
|
+
// Discovery is stubbed to an empty account, so the VPC must be
|
|
273
|
+
// created explicitly; `auto` with no VPC found is a hard error.
|
|
274
|
+
vpc: { enable: true, management: 'create-new' },
|
|
255
275
|
integrations: []
|
|
256
276
|
};
|
|
257
277
|
|
|
@@ -264,7 +284,9 @@ describe('CloudFormation Template Generation', () => {
|
|
|
264
284
|
it('should create subnets in VPC', async () => {
|
|
265
285
|
const appDefinition = {
|
|
266
286
|
name: 'test-app',
|
|
267
|
-
|
|
287
|
+
// Discovery is stubbed to an empty account, so the VPC must be
|
|
288
|
+
// created explicitly; `auto` with no VPC found is a hard error.
|
|
289
|
+
vpc: { enable: true, management: 'create-new' },
|
|
268
290
|
integrations: []
|
|
269
291
|
};
|
|
270
292
|
|
|
@@ -277,7 +299,9 @@ describe('CloudFormation Template Generation', () => {
|
|
|
277
299
|
it('should create security group in VPC', async () => {
|
|
278
300
|
const appDefinition = {
|
|
279
301
|
name: 'test-app',
|
|
280
|
-
|
|
302
|
+
// Discovery is stubbed to an empty account, so the VPC must be
|
|
303
|
+
// created explicitly; `auto` with no VPC found is a hard error.
|
|
304
|
+
vpc: { enable: true, management: 'create-new' },
|
|
281
305
|
integrations: []
|
|
282
306
|
};
|
|
283
307
|
|
|
@@ -290,7 +314,9 @@ describe('CloudFormation Template Generation', () => {
|
|
|
290
314
|
it('should configure Lambda functions with VPC', async () => {
|
|
291
315
|
const appDefinition = {
|
|
292
316
|
name: 'test-app',
|
|
293
|
-
|
|
317
|
+
// Discovery is stubbed to an empty account, so the VPC must be
|
|
318
|
+
// created explicitly; `auto` with no VPC found is a hard error.
|
|
319
|
+
vpc: { enable: true, management: 'create-new' },
|
|
294
320
|
integrations: [
|
|
295
321
|
{ Definition: { name: 'slack' } }
|
|
296
322
|
]
|
|
@@ -427,7 +453,9 @@ describe('CloudFormation Template Generation', () => {
|
|
|
427
453
|
{ Definition: { name: 'slack' } },
|
|
428
454
|
{ Definition: { name: 'hubspot' } }
|
|
429
455
|
],
|
|
430
|
-
|
|
456
|
+
// Discovery is stubbed to an empty account, so the VPC must be
|
|
457
|
+
// created explicitly; `auto` with no VPC found is a hard error.
|
|
458
|
+
vpc: { enable: true, management: 'create-new' },
|
|
431
459
|
encryption: { useDefaultKMSForFieldLevelEncryption: true },
|
|
432
460
|
database: {
|
|
433
461
|
type: 'postgresql',
|
|
@@ -11,10 +11,30 @@ Frigg Framework supports automatic provisioning of Amazon Aurora Serverless v2 P
|
|
|
11
11
|
- **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-1.0 ACU default)
|
|
12
12
|
- **VPC Integration**: Deployed in same private subnets as Lambda functions
|
|
13
13
|
- **Secrets Manager**: Automatic credential management and rotation
|
|
14
|
-
- **
|
|
14
|
+
- **Management Modes**: discover, create-new, use-existing, external (bring your own `DATABASE_URL`)
|
|
15
15
|
- **Security**: Private subnet deployment with security group isolation
|
|
16
16
|
- **High Availability**: Multi-AZ deployment with automatic failover
|
|
17
17
|
|
|
18
|
+
### Bring your own PostgreSQL (`management: 'external'`)
|
|
19
|
+
|
|
20
|
+
To connect to a PostgreSQL that Frigg does not manage (any hosted provider, or
|
|
21
|
+
a database you run yourself), set `management: 'external'`. Frigg then creates
|
|
22
|
+
and discovers no database resources (no RDS/Aurora, no Secrets Manager secret)
|
|
23
|
+
and needs no VPC for the database; the app connects through `DATABASE_URL`.
|
|
24
|
+
This check takes precedence over a top-level `managementMode`. The migration
|
|
25
|
+
infrastructure is still composed, so migrations run against `DATABASE_URL`.
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
const appDefinition = {
|
|
29
|
+
vpc: { enable: false },
|
|
30
|
+
database: { postgres: { enable: true, management: 'external' } },
|
|
31
|
+
environment: { DATABASE_URL: true }, // read from the shell that runs `frigg deploy` (not .env)
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Use `sslmode=require` in the URL. This is the default for apps scaffolded by
|
|
36
|
+
`frigg init`.
|
|
37
|
+
|
|
18
38
|
---
|
|
19
39
|
|
|
20
40
|
## Configuration Schema
|
|
@@ -64,7 +64,18 @@ class AuroraBuilder extends InfrastructureBuilder {
|
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
const postgres = appDefinition.database?.postgres;
|
|
68
|
+
|
|
69
|
+
// management='external': the app brings its own PostgreSQL (any
|
|
70
|
+
// provider) and connects through DATABASE_URL. Frigg creates and
|
|
71
|
+
// discovers no database resources and needs no VPC for it. This
|
|
72
|
+
// check precedes managementMode, which otherwise always manages
|
|
73
|
+
// Aurora. Migrations still run (MigrationBuilder) against DATABASE_URL.
|
|
74
|
+
if (postgres?.management === 'external') {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return postgres?.enable === true;
|
|
68
79
|
}
|
|
69
80
|
|
|
70
81
|
getDependencies() {
|
|
@@ -82,7 +93,7 @@ class AuroraBuilder extends InfrastructureBuilder {
|
|
|
82
93
|
const dbConfig = appDefinition.database.postgres;
|
|
83
94
|
|
|
84
95
|
// Validate management mode
|
|
85
|
-
const validModes = ['discover', 'managed', 'use-existing'];
|
|
96
|
+
const validModes = ['discover', 'managed', 'use-existing', 'external'];
|
|
86
97
|
const management = dbConfig.management || 'discover';
|
|
87
98
|
if (!validModes.includes(management)) {
|
|
88
99
|
result.addError(`Invalid database.postgres.management: "${management}"`);
|
|
@@ -42,6 +42,28 @@ describe('AuroraBuilder', () => {
|
|
|
42
42
|
expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
it('should return false when Postgres is external (bring your own DATABASE_URL)', () => {
|
|
46
|
+
const appDefinition = {
|
|
47
|
+
database: {
|
|
48
|
+
postgres: { enable: true, management: 'external' },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should return false for external Postgres even with managementMode=managed', () => {
|
|
56
|
+
const appDefinition = {
|
|
57
|
+
managementMode: 'managed',
|
|
58
|
+
vpcIsolation: 'isolated',
|
|
59
|
+
database: {
|
|
60
|
+
postgres: { enable: true, management: 'external' },
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
45
67
|
it('should return false when database is not defined', () => {
|
|
46
68
|
const appDefinition = {};
|
|
47
69
|
|
|
@@ -84,10 +84,12 @@ describe('MismatchAnalyzer Method Name Bug Fix', () => {
|
|
|
84
84
|
driftStatus: 'MODIFIED',
|
|
85
85
|
propertyDifferences: [
|
|
86
86
|
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
// Raw CloudFormation PropertyDifference shape, as passed through by
|
|
88
|
+
// AWSStackRepository.getResourceDrift() (PascalCase, slash-separated path).
|
|
89
|
+
PropertyPath: '/BucketEncryption/ServerSideEncryptionConfiguration/0/BucketKeyEnabled',
|
|
90
|
+
ExpectedValue: 'true',
|
|
91
|
+
ActualValue: 'false',
|
|
92
|
+
DifferenceType: 'NOT_EQUAL',
|
|
91
93
|
},
|
|
92
94
|
],
|
|
93
95
|
});
|
|
@@ -144,10 +146,12 @@ describe('MismatchAnalyzer Method Name Bug Fix', () => {
|
|
|
144
146
|
actualProperties: { BucketEncryption: { enabled: false } },
|
|
145
147
|
propertyDifferences: [
|
|
146
148
|
{
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
// Raw CloudFormation PropertyDifference shape, as passed through by
|
|
150
|
+
// AWSStackRepository.getResourceDrift() (PascalCase, slash-separated path).
|
|
151
|
+
PropertyPath: '/BucketEncryption/enabled',
|
|
152
|
+
ExpectedValue: 'true',
|
|
153
|
+
ActualValue: 'false',
|
|
154
|
+
DifferenceType: 'NOT_EQUAL',
|
|
151
155
|
},
|
|
152
156
|
],
|
|
153
157
|
});
|
|
@@ -548,7 +548,11 @@ describe('RepairViaImportUseCase - importWithLogicalIdMapping', () => {
|
|
|
548
548
|
expect(result.unmappedCount).toBe(2);
|
|
549
549
|
});
|
|
550
550
|
|
|
551
|
-
it('should
|
|
551
|
+
it('should warn about duplicate resources dropped for the same logical ID', async () => {
|
|
552
|
+
// Since 6a0bba7b, importWithLogicalIdMapping() de-duplicates candidates
|
|
553
|
+
// per logical ID and only warns about the candidates it dropped
|
|
554
|
+
// (_checkForMultipleResources(duplicates)). Distinct logical IDs are not
|
|
555
|
+
// duplicates and produce no warning.
|
|
552
556
|
// Arrange
|
|
553
557
|
const stackIdentifier = {
|
|
554
558
|
stackName: 'acme-integrations-dev',
|
|
@@ -588,7 +592,7 @@ describe('RepairViaImportUseCase - importWithLogicalIdMapping', () => {
|
|
|
588
592
|
const buildTemplate = { resources: {} };
|
|
589
593
|
const deployedTemplate = { resources: {} };
|
|
590
594
|
|
|
591
|
-
// Three VPCs mapped
|
|
595
|
+
// Three VPCs all mapped to the same logical ID
|
|
592
596
|
const mappings = [
|
|
593
597
|
{
|
|
594
598
|
logicalId: 'FriggVPC',
|
|
@@ -598,14 +602,14 @@ describe('RepairViaImportUseCase - importWithLogicalIdMapping', () => {
|
|
|
598
602
|
confidence: 'high',
|
|
599
603
|
},
|
|
600
604
|
{
|
|
601
|
-
logicalId: '
|
|
605
|
+
logicalId: 'FriggVPC',
|
|
602
606
|
physicalId: 'vpc-456',
|
|
603
607
|
resourceType: 'AWS::EC2::VPC',
|
|
604
608
|
matchMethod: 'contained-resources',
|
|
605
609
|
confidence: 'high',
|
|
606
610
|
},
|
|
607
611
|
{
|
|
608
|
-
logicalId: '
|
|
612
|
+
logicalId: 'FriggVPC',
|
|
609
613
|
physicalId: 'vpc-789',
|
|
610
614
|
resourceType: 'AWS::EC2::VPC',
|
|
611
615
|
matchMethod: 'tag',
|
|
@@ -628,13 +632,21 @@ describe('RepairViaImportUseCase - importWithLogicalIdMapping', () => {
|
|
|
628
632
|
});
|
|
629
633
|
|
|
630
634
|
// Assert
|
|
635
|
+
// Nothing is referenced by the deployed template, so the first candidate
|
|
636
|
+
// is kept and the other two are reported as duplicates.
|
|
631
637
|
expect(result.success).toBe(true);
|
|
638
|
+
expect(result.mappedCount).toBe(1);
|
|
639
|
+
expect(result.mappings[0].physicalId).toBe('vpc-123');
|
|
640
|
+
expect(result.duplicatesRemoved).toBe(2);
|
|
632
641
|
expect(result.warnings).toHaveLength(1);
|
|
633
642
|
expect(result.warnings[0].type).toBe('MULTIPLE_RESOURCES');
|
|
634
643
|
expect(result.warnings[0].resourceType).toBe('AWS::EC2::VPC');
|
|
635
|
-
expect(result.warnings[0].count).toBe(
|
|
636
|
-
expect(result.warnings[0].message).toContain('Multiple VPCs detected (
|
|
637
|
-
expect(result.warnings[0].resources).
|
|
644
|
+
expect(result.warnings[0].count).toBe(2);
|
|
645
|
+
expect(result.warnings[0].message).toContain('Multiple VPCs detected (2)');
|
|
646
|
+
expect(result.warnings[0].resources.map((r) => r.physicalId)).toEqual([
|
|
647
|
+
'vpc-456',
|
|
648
|
+
'vpc-789',
|
|
649
|
+
]);
|
|
638
650
|
});
|
|
639
651
|
|
|
640
652
|
it('should include build and deployed template paths in result', async () => {
|
package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js
CHANGED
|
@@ -133,10 +133,12 @@ describe('RunHealthCheckUseCase', () => {
|
|
|
133
133
|
driftStatus: 'MODIFIED',
|
|
134
134
|
propertyDifferences: [
|
|
135
135
|
{
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
// Raw CloudFormation PropertyDifference shape, as passed through by
|
|
137
|
+
// AWSStackRepository.getResourceDrift() (PascalCase, slash-separated path).
|
|
138
|
+
PropertyPath: '/EnableDnsSupport',
|
|
139
|
+
ExpectedValue: 'true',
|
|
140
|
+
ActualValue: 'false',
|
|
141
|
+
DifferenceType: 'NOT_EQUAL',
|
|
140
142
|
},
|
|
141
143
|
],
|
|
142
144
|
});
|
|
@@ -308,10 +310,12 @@ describe('RunHealthCheckUseCase', () => {
|
|
|
308
310
|
driftStatus: 'MODIFIED',
|
|
309
311
|
propertyDifferences: [
|
|
310
312
|
{
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
// Raw CloudFormation PropertyDifference shape, as passed through by
|
|
314
|
+
// AWSStackRepository.getResourceDrift() (PascalCase, slash-separated path).
|
|
315
|
+
PropertyPath: '/EnableDnsSupport',
|
|
316
|
+
ExpectedValue: 'true',
|
|
317
|
+
ActualValue: 'false',
|
|
318
|
+
DifferenceType: 'NOT_EQUAL',
|
|
315
319
|
},
|
|
316
320
|
],
|
|
317
321
|
});
|
package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js
CHANGED
|
@@ -412,24 +412,23 @@ describe('ImportProgressMonitor', () => {
|
|
|
412
412
|
|
|
413
413
|
mockCloudFormationRepository.getStackStatus.mockResolvedValue('IMPORT_IN_PROGRESS');
|
|
414
414
|
|
|
415
|
-
// Act & Assert -
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
).rejects.toThrow('Import operation timed out');
|
|
415
|
+
// Act & Assert - attach the rejection handler before advancing the fake
|
|
416
|
+
// clock: the monitor rejects while the timers run, and an unobserved
|
|
417
|
+
// rejection fails the test under Jest 30.
|
|
418
|
+
const resultPromise = monitor.monitorImport({
|
|
419
|
+
stackIdentifier,
|
|
420
|
+
resourceLogicalIds,
|
|
421
|
+
onProgress,
|
|
422
|
+
});
|
|
423
|
+
const assertion = expect(resultPromise).rejects.toThrow('Import operation timed out');
|
|
424
|
+
|
|
425
|
+
// Advance timers beyond 5 minutes (300,000ms) in chunks
|
|
426
|
+
// Simulate 151 polls (302 seconds = 302,000ms) to exceed timeout
|
|
427
|
+
for (let i = 0; i < 151; i++) {
|
|
428
|
+
await jest.advanceTimersByTimeAsync(2000);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
await assertion;
|
|
433
432
|
});
|
|
434
433
|
|
|
435
434
|
it('should filter events by resourceLogicalIds', async () => {
|
package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js
CHANGED
|
@@ -302,9 +302,14 @@ describe('UpdateProgressMonitor', () => {
|
|
|
302
302
|
onProgress: onProgressCallback,
|
|
303
303
|
});
|
|
304
304
|
|
|
305
|
+
// Attach the rejection handler before advancing the fake clock: the
|
|
306
|
+
// monitor rejects while the timers run, and an unobserved rejection
|
|
307
|
+
// fails the test under Jest 30.
|
|
308
|
+
const assertion = expect(monitorPromise).rejects.toThrow('Update operation failed and rolled back');
|
|
309
|
+
|
|
305
310
|
await jest.advanceTimersByTimeAsync(2000);
|
|
306
311
|
|
|
307
|
-
await
|
|
312
|
+
await assertion;
|
|
308
313
|
});
|
|
309
314
|
});
|
|
310
315
|
|
|
@@ -334,10 +339,15 @@ describe('UpdateProgressMonitor', () => {
|
|
|
334
339
|
onProgress: onProgressCallback,
|
|
335
340
|
});
|
|
336
341
|
|
|
342
|
+
// Attach the rejection handler before advancing the fake clock: the
|
|
343
|
+
// monitor rejects while the timers run, and an unobserved rejection
|
|
344
|
+
// fails the test under Jest 30.
|
|
345
|
+
const assertion = expect(monitorPromise).rejects.toThrow('Update operation timed out');
|
|
346
|
+
|
|
337
347
|
// Advance past 5 minute timeout (300000ms)
|
|
338
348
|
await jest.advanceTimersByTimeAsync(300000 + 2000);
|
|
339
349
|
|
|
340
|
-
await
|
|
350
|
+
await assertion;
|
|
341
351
|
});
|
|
342
352
|
});
|
|
343
353
|
|
|
@@ -82,7 +82,14 @@ jest.mock('@aws-sdk/client-kms', () => ({
|
|
|
82
82
|
ListAliasesCommand: jest.fn(),
|
|
83
83
|
}));
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
// SKIPPED: red-phase TDD spec for a feature that was never implemented.
|
|
86
|
+
// AWSResourceDetector has no findOrphanedResourcesWithRelationships() or
|
|
87
|
+
// _extractReferencedResourceIds(); the design is in
|
|
88
|
+
// domains/health/docs/ORPHAN-DETECTION-ANALYSIS.md. (A template-based variant of
|
|
89
|
+
// the reference analysis lives in RepairViaImportUseCase._extractReferencedIdsFromTemplate.)
|
|
90
|
+
// Un-skip when the relationship analysis is implemented.
|
|
91
|
+
// Tracked in https://github.com/friggframework/frigg/issues/709
|
|
92
|
+
describe.skip('Orphan Detection with Relationship Analysis (TDD)', () => {
|
|
86
93
|
let detector;
|
|
87
94
|
let mockEC2Send;
|
|
88
95
|
let mockRDSSend;
|
package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js
CHANGED
|
@@ -447,7 +447,9 @@ describe('AWSPropertyReconciler', () => {
|
|
|
447
447
|
);
|
|
448
448
|
|
|
449
449
|
expect(strategy.supportsTemplateUpdate).toBe(true);
|
|
450
|
-
|
|
450
|
+
// Lambda supports direct resource-mode reconciliation
|
|
451
|
+
// (UpdateFunctionConfiguration) since 6a0bba7b; template is still preferred.
|
|
452
|
+
expect(strategy.supportsResourceUpdate).toBe(true);
|
|
451
453
|
expect(strategy.recommendedMode).toBe('template');
|
|
452
454
|
expect(strategy.limitations).toContain(
|
|
453
455
|
'VpcConfig changes may take several minutes to propagate'
|
|
@@ -659,7 +661,7 @@ describe('AWSPropertyReconciler', () => {
|
|
|
659
661
|
|
|
660
662
|
expect(strategy).toEqual({
|
|
661
663
|
supportsTemplateUpdate: true,
|
|
662
|
-
supportsResourceUpdate:
|
|
664
|
+
supportsResourceUpdate: true, // resource mode via UpdateFunctionConfiguration
|
|
663
665
|
recommendedMode: 'template',
|
|
664
666
|
limitations: expect.arrayContaining([
|
|
665
667
|
'VpcConfig changes may take several minutes to propagate',
|
|
@@ -441,6 +441,16 @@ describe('AWSResourceDetector', () => {
|
|
|
441
441
|
describe('findOrphanedResources', () => {
|
|
442
442
|
const StackIdentifier = require('../../domain/value-objects/stack-identifier');
|
|
443
443
|
|
|
444
|
+
beforeEach(() => {
|
|
445
|
+
// findOrphanedResources() scans every supported resource type
|
|
446
|
+
// (EC2, RDS and KMS), not just the types in the stack, so every
|
|
447
|
+
// client needs an (empty) response; each test overrides the one
|
|
448
|
+
// service it is about.
|
|
449
|
+
mockEC2Send.mockResolvedValue({});
|
|
450
|
+
mockRDSSend.mockResolvedValue({});
|
|
451
|
+
mockKMSSend.mockResolvedValue({});
|
|
452
|
+
});
|
|
453
|
+
|
|
444
454
|
it('should find orphaned RDS DBCluster with frigg:stack tag', async () => {
|
|
445
455
|
const stackIdentifier = new StackIdentifier({
|
|
446
456
|
stackName: 'my-app-prod',
|