@friggframework/devtools 2.0.0-next.45 → 2.0.0-next.47

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.
Files changed (212) hide show
  1. package/infrastructure/ARCHITECTURE.md +487 -0
  2. package/infrastructure/HEALTH.md +468 -0
  3. package/infrastructure/README.md +51 -0
  4. package/infrastructure/__tests__/postgres-config.test.js +914 -0
  5. package/infrastructure/__tests__/template-generation.test.js +687 -0
  6. package/infrastructure/create-frigg-infrastructure.js +1 -1
  7. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +630 -0
  8. package/infrastructure/{DEPLOYMENT-INSTRUCTIONS.md → docs/deployment-instructions.md} +3 -3
  9. package/infrastructure/{IAM-POLICY-TEMPLATES.md → docs/iam-policy-templates.md} +9 -10
  10. package/infrastructure/domains/database/aurora-builder.js +809 -0
  11. package/infrastructure/domains/database/aurora-builder.test.js +950 -0
  12. package/infrastructure/domains/database/aurora-discovery.js +87 -0
  13. package/infrastructure/domains/database/aurora-discovery.test.js +188 -0
  14. package/infrastructure/domains/database/aurora-resolver.js +210 -0
  15. package/infrastructure/domains/database/aurora-resolver.test.js +347 -0
  16. package/infrastructure/domains/database/migration-builder.js +695 -0
  17. package/infrastructure/domains/database/migration-builder.test.js +294 -0
  18. package/infrastructure/domains/database/migration-resolver.js +163 -0
  19. package/infrastructure/domains/database/migration-resolver.test.js +337 -0
  20. package/infrastructure/domains/health/application/ports/IPropertyReconciler.js +164 -0
  21. package/infrastructure/domains/health/application/ports/IResourceDetector.js +129 -0
  22. package/infrastructure/domains/health/application/ports/IResourceImporter.js +142 -0
  23. package/infrastructure/domains/health/application/ports/IStackRepository.js +131 -0
  24. package/infrastructure/domains/health/application/ports/index.js +26 -0
  25. package/infrastructure/domains/health/application/use-cases/__tests__/execute-resource-import-use-case.test.js +679 -0
  26. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +167 -0
  27. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +1130 -0
  28. package/infrastructure/domains/health/application/use-cases/execute-resource-import-use-case.js +221 -0
  29. package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.js +152 -0
  30. package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.test.js +343 -0
  31. package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.js +535 -0
  32. package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.test.js +376 -0
  33. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.js +213 -0
  34. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +441 -0
  35. package/infrastructure/domains/health/docs/ACME-DEV-DRIFT-ANALYSIS.md +267 -0
  36. package/infrastructure/domains/health/docs/BUILD-VS-DEPLOYED-TEMPLATE-ANALYSIS.md +324 -0
  37. package/infrastructure/domains/health/docs/ORPHAN-DETECTION-ANALYSIS.md +386 -0
  38. package/infrastructure/domains/health/docs/SPEC-CLEANUP-COMMAND.md +1419 -0
  39. package/infrastructure/domains/health/docs/TDD-IMPLEMENTATION-SUMMARY.md +391 -0
  40. package/infrastructure/domains/health/docs/TEMPLATE-COMPARISON-IMPLEMENTATION.md +551 -0
  41. package/infrastructure/domains/health/domain/entities/issue.js +299 -0
  42. package/infrastructure/domains/health/domain/entities/issue.test.js +528 -0
  43. package/infrastructure/domains/health/domain/entities/property-mismatch.js +108 -0
  44. package/infrastructure/domains/health/domain/entities/property-mismatch.test.js +275 -0
  45. package/infrastructure/domains/health/domain/entities/resource.js +159 -0
  46. package/infrastructure/domains/health/domain/entities/resource.test.js +432 -0
  47. package/infrastructure/domains/health/domain/entities/stack-health-report.js +306 -0
  48. package/infrastructure/domains/health/domain/entities/stack-health-report.test.js +601 -0
  49. package/infrastructure/domains/health/domain/services/__tests__/health-score-percentage-based.test.js +380 -0
  50. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +971 -0
  51. package/infrastructure/domains/health/domain/services/__tests__/import-template-generator.test.js +1150 -0
  52. package/infrastructure/domains/health/domain/services/__tests__/logical-id-mapper.test.js +672 -0
  53. package/infrastructure/domains/health/domain/services/__tests__/template-parser.test.js +496 -0
  54. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +419 -0
  55. package/infrastructure/domains/health/domain/services/health-score-calculator.js +248 -0
  56. package/infrastructure/domains/health/domain/services/health-score-calculator.test.js +504 -0
  57. package/infrastructure/domains/health/domain/services/import-progress-monitor.js +195 -0
  58. package/infrastructure/domains/health/domain/services/import-template-generator.js +435 -0
  59. package/infrastructure/domains/health/domain/services/logical-id-mapper.js +345 -0
  60. package/infrastructure/domains/health/domain/services/mismatch-analyzer.js +234 -0
  61. package/infrastructure/domains/health/domain/services/mismatch-analyzer.test.js +431 -0
  62. package/infrastructure/domains/health/domain/services/property-mutability-config.js +382 -0
  63. package/infrastructure/domains/health/domain/services/template-parser.js +245 -0
  64. package/infrastructure/domains/health/domain/services/update-progress-monitor.js +192 -0
  65. package/infrastructure/domains/health/domain/value-objects/health-score.js +138 -0
  66. package/infrastructure/domains/health/domain/value-objects/health-score.test.js +267 -0
  67. package/infrastructure/domains/health/domain/value-objects/property-mutability.js +161 -0
  68. package/infrastructure/domains/health/domain/value-objects/property-mutability.test.js +198 -0
  69. package/infrastructure/domains/health/domain/value-objects/resource-state.js +167 -0
  70. package/infrastructure/domains/health/domain/value-objects/resource-state.test.js +196 -0
  71. package/infrastructure/domains/health/domain/value-objects/stack-identifier.js +192 -0
  72. package/infrastructure/domains/health/domain/value-objects/stack-identifier.test.js +262 -0
  73. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-cfn-tagged.test.js +312 -0
  74. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-multi-stack.test.js +367 -0
  75. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +432 -0
  76. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.js +784 -0
  77. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +1133 -0
  78. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.js +565 -0
  79. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +554 -0
  80. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.js +318 -0
  81. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.test.js +398 -0
  82. package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.js +777 -0
  83. package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.test.js +580 -0
  84. package/infrastructure/domains/integration/integration-builder.js +397 -0
  85. package/infrastructure/domains/integration/integration-builder.test.js +593 -0
  86. package/infrastructure/domains/integration/integration-resolver.js +170 -0
  87. package/infrastructure/domains/integration/integration-resolver.test.js +369 -0
  88. package/infrastructure/domains/integration/websocket-builder.js +69 -0
  89. package/infrastructure/domains/integration/websocket-builder.test.js +195 -0
  90. package/infrastructure/domains/networking/vpc-builder.js +1829 -0
  91. package/infrastructure/domains/networking/vpc-builder.test.js +1262 -0
  92. package/infrastructure/domains/networking/vpc-discovery.js +177 -0
  93. package/infrastructure/domains/networking/vpc-discovery.test.js +350 -0
  94. package/infrastructure/domains/networking/vpc-resolver.js +324 -0
  95. package/infrastructure/domains/networking/vpc-resolver.test.js +501 -0
  96. package/infrastructure/domains/parameters/ssm-builder.js +79 -0
  97. package/infrastructure/domains/parameters/ssm-builder.test.js +189 -0
  98. package/infrastructure/domains/parameters/ssm-discovery.js +84 -0
  99. package/infrastructure/domains/parameters/ssm-discovery.test.js +210 -0
  100. package/infrastructure/{iam-generator.js → domains/security/iam-generator.js} +2 -2
  101. package/infrastructure/domains/security/kms-builder.js +366 -0
  102. package/infrastructure/domains/security/kms-builder.test.js +374 -0
  103. package/infrastructure/domains/security/kms-discovery.js +80 -0
  104. package/infrastructure/domains/security/kms-discovery.test.js +177 -0
  105. package/infrastructure/domains/security/kms-resolver.js +96 -0
  106. package/infrastructure/domains/security/kms-resolver.test.js +216 -0
  107. package/infrastructure/domains/shared/base-builder.js +112 -0
  108. package/infrastructure/domains/shared/base-resolver.js +186 -0
  109. package/infrastructure/domains/shared/base-resolver.test.js +305 -0
  110. package/infrastructure/domains/shared/builder-orchestrator.js +212 -0
  111. package/infrastructure/domains/shared/builder-orchestrator.test.js +213 -0
  112. package/infrastructure/domains/shared/cloudformation-discovery-v2.js +334 -0
  113. package/infrastructure/domains/shared/cloudformation-discovery.js +375 -0
  114. package/infrastructure/domains/shared/cloudformation-discovery.test.js +590 -0
  115. package/infrastructure/domains/shared/environment-builder.js +119 -0
  116. package/infrastructure/domains/shared/environment-builder.test.js +247 -0
  117. package/infrastructure/domains/shared/providers/aws-provider-adapter.js +544 -0
  118. package/infrastructure/domains/shared/providers/aws-provider-adapter.test.js +377 -0
  119. package/infrastructure/domains/shared/providers/azure-provider-adapter.stub.js +93 -0
  120. package/infrastructure/domains/shared/providers/cloud-provider-adapter.js +136 -0
  121. package/infrastructure/domains/shared/providers/gcp-provider-adapter.stub.js +82 -0
  122. package/infrastructure/domains/shared/providers/provider-factory.js +108 -0
  123. package/infrastructure/domains/shared/providers/provider-factory.test.js +170 -0
  124. package/infrastructure/domains/shared/resource-discovery.js +192 -0
  125. package/infrastructure/domains/shared/resource-discovery.test.js +552 -0
  126. package/infrastructure/domains/shared/types/app-definition.js +205 -0
  127. package/infrastructure/domains/shared/types/discovery-result.js +106 -0
  128. package/infrastructure/domains/shared/types/discovery-result.test.js +258 -0
  129. package/infrastructure/domains/shared/types/index.js +46 -0
  130. package/infrastructure/domains/shared/types/resource-ownership.js +108 -0
  131. package/infrastructure/domains/shared/types/resource-ownership.test.js +101 -0
  132. package/infrastructure/domains/shared/utilities/base-definition-factory.js +380 -0
  133. package/infrastructure/domains/shared/utilities/base-definition-factory.js.bak +338 -0
  134. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +248 -0
  135. package/infrastructure/domains/shared/utilities/handler-path-resolver.js +134 -0
  136. package/infrastructure/domains/shared/utilities/handler-path-resolver.test.js +268 -0
  137. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +55 -0
  138. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +138 -0
  139. package/infrastructure/{env-validator.js → domains/shared/validation/env-validator.js} +2 -1
  140. package/infrastructure/domains/shared/validation/env-validator.test.js +173 -0
  141. package/infrastructure/esbuild.config.js +53 -0
  142. package/infrastructure/infrastructure-composer.js +87 -0
  143. package/infrastructure/{serverless-template.test.js → infrastructure-composer.test.js} +115 -24
  144. package/infrastructure/scripts/build-prisma-layer.js +553 -0
  145. package/infrastructure/scripts/build-prisma-layer.test.js +102 -0
  146. package/infrastructure/{build-time-discovery.js → scripts/build-time-discovery.js} +80 -48
  147. package/infrastructure/{build-time-discovery.test.js → scripts/build-time-discovery.test.js} +5 -4
  148. package/layers/prisma/nodejs/package.json +8 -0
  149. package/management-ui/server/utils/cliIntegration.js +1 -1
  150. package/management-ui/server/utils/environment/awsParameterStore.js +29 -18
  151. package/package.json +11 -11
  152. package/frigg-cli/.eslintrc.js +0 -141
  153. package/frigg-cli/__tests__/unit/commands/build.test.js +0 -251
  154. package/frigg-cli/__tests__/unit/commands/db-setup.test.js +0 -548
  155. package/frigg-cli/__tests__/unit/commands/install.test.js +0 -400
  156. package/frigg-cli/__tests__/unit/commands/ui.test.js +0 -346
  157. package/frigg-cli/__tests__/unit/utils/database-validator.test.js +0 -366
  158. package/frigg-cli/__tests__/unit/utils/error-messages.test.js +0 -304
  159. package/frigg-cli/__tests__/unit/utils/prisma-runner.test.js +0 -486
  160. package/frigg-cli/__tests__/utils/mock-factory.js +0 -270
  161. package/frigg-cli/__tests__/utils/prisma-mock.js +0 -194
  162. package/frigg-cli/__tests__/utils/test-fixtures.js +0 -463
  163. package/frigg-cli/__tests__/utils/test-setup.js +0 -287
  164. package/frigg-cli/build-command/index.js +0 -65
  165. package/frigg-cli/db-setup-command/index.js +0 -193
  166. package/frigg-cli/deploy-command/index.js +0 -175
  167. package/frigg-cli/generate-command/__tests__/generate-command.test.js +0 -301
  168. package/frigg-cli/generate-command/azure-generator.js +0 -43
  169. package/frigg-cli/generate-command/gcp-generator.js +0 -47
  170. package/frigg-cli/generate-command/index.js +0 -332
  171. package/frigg-cli/generate-command/terraform-generator.js +0 -555
  172. package/frigg-cli/generate-iam-command.js +0 -118
  173. package/frigg-cli/index.js +0 -75
  174. package/frigg-cli/index.test.js +0 -158
  175. package/frigg-cli/init-command/backend-first-handler.js +0 -756
  176. package/frigg-cli/init-command/index.js +0 -93
  177. package/frigg-cli/init-command/template-handler.js +0 -143
  178. package/frigg-cli/install-command/backend-js.js +0 -33
  179. package/frigg-cli/install-command/commit-changes.js +0 -16
  180. package/frigg-cli/install-command/environment-variables.js +0 -127
  181. package/frigg-cli/install-command/environment-variables.test.js +0 -136
  182. package/frigg-cli/install-command/index.js +0 -54
  183. package/frigg-cli/install-command/install-package.js +0 -13
  184. package/frigg-cli/install-command/integration-file.js +0 -30
  185. package/frigg-cli/install-command/logger.js +0 -12
  186. package/frigg-cli/install-command/template.js +0 -90
  187. package/frigg-cli/install-command/validate-package.js +0 -75
  188. package/frigg-cli/jest.config.js +0 -124
  189. package/frigg-cli/package.json +0 -54
  190. package/frigg-cli/start-command/index.js +0 -149
  191. package/frigg-cli/start-command/start-command.test.js +0 -297
  192. package/frigg-cli/test/init-command.test.js +0 -180
  193. package/frigg-cli/test/npm-registry.test.js +0 -319
  194. package/frigg-cli/ui-command/index.js +0 -154
  195. package/frigg-cli/utils/app-resolver.js +0 -319
  196. package/frigg-cli/utils/backend-path.js +0 -25
  197. package/frigg-cli/utils/database-validator.js +0 -161
  198. package/frigg-cli/utils/error-messages.js +0 -257
  199. package/frigg-cli/utils/npm-registry.js +0 -167
  200. package/frigg-cli/utils/prisma-runner.js +0 -280
  201. package/frigg-cli/utils/process-manager.js +0 -199
  202. package/frigg-cli/utils/repo-detection.js +0 -405
  203. package/infrastructure/aws-discovery.js +0 -1176
  204. package/infrastructure/aws-discovery.test.js +0 -1220
  205. package/infrastructure/serverless-template.js +0 -2094
  206. /package/infrastructure/{WEBSOCKET-CONFIGURATION.md → docs/WEBSOCKET-CONFIGURATION.md} +0 -0
  207. /package/infrastructure/{GENERATE-IAM-DOCS.md → docs/generate-iam-command.md} +0 -0
  208. /package/infrastructure/{iam-generator.test.js → domains/security/iam-generator.test.js} +0 -0
  209. /package/infrastructure/{frigg-deployment-iam-stack.yaml → domains/security/templates/frigg-deployment-iam-stack.yaml} +0 -0
  210. /package/infrastructure/{iam-policy-basic.json → domains/security/templates/iam-policy-basic.json} +0 -0
  211. /package/infrastructure/{iam-policy-full.json → domains/security/templates/iam-policy-full.json} +0 -0
  212. /package/infrastructure/{run-discovery.js → scripts/run-discovery.js} +0 -0
@@ -1,175 +0,0 @@
1
- const { spawn } = require('child_process');
2
- const path = require('path');
3
- const fs = require('fs');
4
-
5
- // Configuration constants
6
- const PATHS = {
7
- APP_DEFINITION: 'index.js',
8
- INFRASTRUCTURE: 'infrastructure.js'
9
- };
10
-
11
- const COMMANDS = {
12
- SERVERLESS: 'serverless'
13
- };
14
-
15
- /**
16
- * Constructs filtered environment variables for serverless deployment
17
- * @param {string[]} appDefinedVariables - Array of environment variable names from app definition
18
- * @returns {Object} Filtered environment variables object
19
- */
20
- function buildFilteredEnvironment(appDefinedVariables) {
21
- return {
22
- // Essential system variables needed to run serverless
23
- PATH: process.env.PATH,
24
- HOME: process.env.HOME,
25
- USER: process.env.USER,
26
-
27
- // AWS credentials and configuration (all AWS_ prefixed variables)
28
- ...Object.fromEntries(
29
- Object.entries(process.env).filter(([key]) =>
30
- key.startsWith('AWS_')
31
- )
32
- ),
33
-
34
- // App-defined environment variables
35
- ...Object.fromEntries(
36
- appDefinedVariables
37
- .map((key) => [key, process.env[key]])
38
- .filter(([_, value]) => value !== undefined)
39
- ),
40
- };
41
- }
42
-
43
- /**
44
- * Loads and parses the app definition from index.js
45
- * @returns {Object|null} App definition object or null if not found
46
- */
47
- function loadAppDefinition() {
48
- const appDefPath = path.join(process.cwd(), PATHS.APP_DEFINITION);
49
-
50
- if (!fs.existsSync(appDefPath)) {
51
- return null;
52
- }
53
-
54
- try {
55
- const { Definition } = require(appDefPath);
56
- return Definition;
57
- } catch (error) {
58
- console.warn('Could not load appDefinition environment config:', error.message);
59
- return null;
60
- }
61
- }
62
-
63
- /**
64
- * Extracts environment variable names from app definition
65
- * @param {Object} appDefinition - App definition object
66
- * @returns {string[]} Array of environment variable names
67
- */
68
- function extractEnvironmentVariables(appDefinition) {
69
- if (!appDefinition?.environment) {
70
- return [];
71
- }
72
-
73
- console.log('🔧 Loading environment configuration from appDefinition...');
74
-
75
- const appDefinedVariables = Object.keys(appDefinition.environment).filter(
76
- (key) => appDefinition.environment[key] === true
77
- );
78
-
79
- console.log(` Found ${appDefinedVariables.length} environment variables: ${appDefinedVariables.join(', ')}`);
80
- return appDefinedVariables;
81
- }
82
-
83
- /**
84
- * Handles environment validation warnings
85
- * @param {Object} validation - Validation result object
86
- * @param {Object} options - Deploy command options
87
- */
88
- function handleValidationWarnings(validation, options) {
89
- if (validation.missing.length === 0 || options.skipEnvValidation) {
90
- return;
91
- }
92
-
93
- console.warn(`⚠️ Warning: Missing ${validation.missing.length} environment variables: ${validation.missing.join(', ')}`);
94
- console.warn(' These variables are optional and deployment will continue');
95
- console.warn(' Run with --skip-env-validation to bypass this check');
96
- }
97
-
98
- /**
99
- * Validates environment variables and builds filtered environment
100
- * @param {Object} appDefinition - App definition object
101
- * @param {Object} options - Deploy command options
102
- * @returns {Object} Filtered environment variables
103
- */
104
- function validateAndBuildEnvironment(appDefinition, options) {
105
- if (!appDefinition) {
106
- return buildFilteredEnvironment([]);
107
- }
108
-
109
- const appDefinedVariables = extractEnvironmentVariables(appDefinition);
110
-
111
- // Try to use the env-validator if available
112
- try {
113
- const { validateEnvironmentVariables } = require('@friggframework/devtools/infrastructure/env-validator');
114
- const validation = validateEnvironmentVariables(appDefinition);
115
-
116
- handleValidationWarnings(validation, options);
117
- return buildFilteredEnvironment(appDefinedVariables);
118
-
119
- } catch (validatorError) {
120
- // Validator not available, do basic validation
121
- const missingVariables = appDefinedVariables.filter((variable) => !process.env[variable]);
122
-
123
- if (missingVariables.length > 0) {
124
- console.warn(`⚠️ Warning: Missing ${missingVariables.length} environment variables: ${missingVariables.join(', ')}`);
125
- console.warn(' These variables are optional and deployment will continue');
126
- console.warn(' Set them in your CI/CD environment or .env file if needed');
127
- }
128
-
129
- return buildFilteredEnvironment(appDefinedVariables);
130
- }
131
- }
132
-
133
- /**
134
- * Executes the serverless deployment command
135
- * @param {Object} environment - Environment variables to pass to serverless
136
- * @param {Object} options - Deploy command options
137
- */
138
- function executeServerlessDeployment(environment, options) {
139
- console.log('🚀 Deploying serverless application...');
140
-
141
- const serverlessArgs = [
142
- 'deploy',
143
- '--config',
144
- PATHS.INFRASTRUCTURE,
145
- '--stage',
146
- options.stage,
147
- ];
148
-
149
- const childProcess = spawn(COMMANDS.SERVERLESS, serverlessArgs, {
150
- cwd: path.resolve(process.cwd()),
151
- stdio: 'inherit',
152
- env: environment,
153
- });
154
-
155
- childProcess.on('error', (error) => {
156
- console.error(`Error executing command: ${error.message}`);
157
- });
158
-
159
- childProcess.on('close', (code) => {
160
- if (code !== 0) {
161
- console.log(`Child process exited with code ${code}`);
162
- }
163
- });
164
- }
165
-
166
- async function deployCommand(options) {
167
- console.log('Deploying the serverless application...');
168
-
169
- const appDefinition = loadAppDefinition();
170
- const environment = validateAndBuildEnvironment(appDefinition, options);
171
-
172
- executeServerlessDeployment(environment, options);
173
- }
174
-
175
- module.exports = { deployCommand };
@@ -1,301 +0,0 @@
1
- const path = require('path');
2
-
3
- /**
4
- * Test suite for generate command
5
- *
6
- * Tests the ACTUAL Frigg template generation implementation:
7
- * - CloudFormation template generation (REAL - tests actual YAML syntax)
8
- * - Terraform template generation (REAL - tests actual HCL syntax)
9
- * - Azure ARM template generation (REAL - tests actual JSON syntax)
10
- * - GCP Deployment Manager (REAL - tests actual YAML syntax)
11
- * - File system operations (MOCKED - external I/O boundary)
12
- * - Package discovery (MOCKED - external boundary)
13
- * - Interactive prompts (MOCKED - external boundary)
14
- *
15
- * REFACTORED: CloudFormation generator now uses same API as Terraform generator
16
- * ==============================================================================
17
- * Fixed export name and aligned API signatures:
18
- * - Added generateCloudFormationTemplate alias export
19
- * - Refactored to accept flattened options: { appName, features, userPrefix, stackName }
20
- * - Consistent with Terraform generator pattern
21
- * - All callers updated to use getFeatureSummary(appDefinition)
22
- */
23
-
24
- // Mock ONLY external boundaries - let template generators run!
25
- jest.mock('fs', () => ({
26
- readFileSync: jest.fn(),
27
- existsSync: jest.fn(),
28
- mkdirSync: jest.fn(),
29
- writeFileSync: jest.fn()
30
- }));
31
- jest.mock('../../utils/backend-path', () => ({
32
- findNearestBackendPackageJson: jest.fn() // External: file system discovery
33
- }));
34
- jest.mock('@inquirer/prompts', () => ({
35
- select: jest.fn() // External: interactive user input
36
- }));
37
-
38
- // DON'T mock these - let them run to test actual template generation:
39
- // - generateCloudFormationTemplate (tests YAML syntax)
40
- // - generateTerraformTemplate (tests HCL syntax)
41
- // - generateAzureARMTemplate (tests JSON syntax)
42
- // - generateGCPDeploymentManagerTemplate (tests YAML syntax)
43
-
44
- // Require after mocks
45
- const fs = require('fs');
46
- const { findNearestBackendPackageJson } = require('../../utils/backend-path');
47
- const { select } = require('@inquirer/prompts');
48
- const generateCommand = require('../index');
49
-
50
- // NOTE: We test via generateCommand() which internally uses the real generators
51
- // No need to import generators directly - they run when generateCommand() is called
52
-
53
- describe('Generate Command', () => {
54
- const mockBackendDir = '/mock/backend';
55
- const mockPackageJsonPath = path.join(mockBackendDir, 'package.json');
56
- const mockAppDefinitionPath = path.join(mockBackendDir, 'index.js');
57
-
58
- beforeEach(() => {
59
- jest.clearAllMocks();
60
-
61
- // Mock process.exit
62
- jest.spyOn(process, 'exit').mockImplementation(() => {});
63
-
64
- // Mock console methods
65
- jest.spyOn(console, 'log').mockImplementation(() => {});
66
- jest.spyOn(console, 'error').mockImplementation(() => {});
67
-
68
- // Re-setup mocks after clearAllMocks
69
- findNearestBackendPackageJson.mockResolvedValue(mockPackageJsonPath);
70
-
71
- // Re-setup fs mock implementations
72
- fs.readFileSync.mockImplementation((filePath, encoding) => {
73
- // Normalize path to handle different separators
74
- const normalizedPath = filePath.toString();
75
-
76
- if (normalizedPath === mockPackageJsonPath || normalizedPath.endsWith('backend/package.json')) {
77
- return JSON.stringify({ name: 'test-app' });
78
- }
79
-
80
- // For any other file, throw ENOENT like real fs would
81
- const error = new Error(`ENOENT: no such file or directory, open '${filePath}'`);
82
- error.code = 'ENOENT';
83
- throw error;
84
- });
85
-
86
- fs.existsSync.mockImplementation((filePath) => {
87
- if (filePath === mockAppDefinitionPath) {
88
- return true;
89
- }
90
- if (filePath.includes('backend/infrastructure')) {
91
- return false; // Directory doesn't exist, will be created
92
- }
93
- return true;
94
- });
95
-
96
- fs.mkdirSync.mockImplementation(() => {});
97
- fs.writeFileSync.mockImplementation(() => {});
98
-
99
- // Mock the app definition module
100
- const mockAppDefinition = {
101
- vpc: { enable: true },
102
- encryption: { fieldLevelEncryptionMethod: 'kms' },
103
- ssm: { enable: true },
104
- websockets: { enable: false }
105
- };
106
-
107
- // Use jest.doMock to mock the dynamic require
108
- jest.doMock(mockAppDefinitionPath, () => mockAppDefinition, { virtual: true });
109
- });
110
-
111
- afterEach(() => {
112
- jest.restoreAllMocks();
113
-
114
- // Clean up the mock
115
- jest.dontMock(mockAppDefinitionPath);
116
- });
117
-
118
- describe('AWS CloudFormation Generation', () => {
119
- it('should generate valid CloudFormation template with actual YAML syntax', async () => {
120
- await generateCommand({
121
- provider: 'aws',
122
- format: 'cloudformation',
123
- output: 'backend/infrastructure',
124
- user: 'test-user',
125
- stackName: 'test-stack'
126
- });
127
-
128
- // Verify file was written with correct path
129
- expect(fs.writeFileSync).toHaveBeenCalledWith(
130
- expect.stringContaining('frigg-deployment-aws-cloudformation.yaml'),
131
- expect.any(String)
132
- );
133
-
134
- // Get the actual generated template content
135
- const writeCall = fs.writeFileSync.mock.calls.find(call =>
136
- call[0].includes('frigg-deployment-aws-cloudformation.yaml')
137
- );
138
-
139
- expect(writeCall).toBeDefined();
140
- const [filePath, generatedTemplate] = writeCall;
141
-
142
- // Verify template has valid CloudFormation YAML structure
143
- expect(generatedTemplate).toContain('AWSTemplateFormatVersion: \'2010-09-09\'');
144
- expect(generatedTemplate).toContain('Description:');
145
- expect(generatedTemplate).toContain('Resources:');
146
-
147
- // Verify IAM user resource exists
148
- expect(generatedTemplate).toContain('Type: AWS::IAM::User');
149
-
150
- // Verify feature-based policies are included (uses ManagedPolicy, not Policy)
151
- expect(generatedTemplate).toContain('AWS::IAM::ManagedPolicy'); // Managed policies
152
- expect(generatedTemplate).toContain('kms:'); // KMS permissions
153
- expect(generatedTemplate).toContain('ssm:'); // SSM permissions (via parameters)
154
-
155
- // Verify no WebSocket permissions (websockets: false in mock)
156
- expect(generatedTemplate).not.toContain('execute-api:ManageConnections');
157
-
158
- expect(console.log).toHaveBeenCalledWith(expect.stringContaining('✅ Generated cloudformation template for aws'));
159
- });
160
-
161
- it('should handle missing app definition gracefully', async () => {
162
- fs.existsSync.mockImplementation((filePath) => {
163
- if (filePath === mockAppDefinitionPath) {
164
- return false;
165
- }
166
- return true;
167
- });
168
-
169
- await generateCommand({
170
- provider: 'aws',
171
- format: 'cloudformation'
172
- });
173
-
174
- expect(console.error).toHaveBeenCalledWith(
175
- 'Error generating deployment credentials:',
176
- expect.stringContaining('App definition not found')
177
- );
178
- expect(process.exit).toHaveBeenCalledWith(1);
179
- });
180
- });
181
-
182
- describe('AWS Terraform Generation', () => {
183
- it('should generate valid Terraform template with actual HCL syntax', async () => {
184
- await generateCommand({
185
- provider: 'aws',
186
- format: 'terraform',
187
- output: 'backend/infrastructure'
188
- });
189
-
190
- // Verify file was written with correct path
191
- expect(fs.writeFileSync).toHaveBeenCalledWith(
192
- expect.stringContaining('frigg-deployment-aws-terraform.tf'),
193
- expect.any(String)
194
- );
195
-
196
- // Get the actual generated template content
197
- const writeCall = fs.writeFileSync.mock.calls.find(call =>
198
- call[0].includes('frigg-deployment-aws-terraform.tf')
199
- );
200
-
201
- expect(writeCall).toBeDefined();
202
- const [filePath, generatedTemplate] = writeCall;
203
-
204
- // Verify template has valid Terraform HCL structure
205
- expect(generatedTemplate).toContain('terraform {');
206
- expect(generatedTemplate).toContain('required_providers {');
207
- expect(generatedTemplate).toContain('source = "hashicorp/aws"'); // AWS provider config
208
-
209
- // Verify IAM user resource exists
210
- expect(generatedTemplate).toContain('resource "aws_iam_user"');
211
-
212
- // Verify feature variables are defined
213
- expect(generatedTemplate).toContain('variable "enable_vpc"');
214
- expect(generatedTemplate).toContain('variable "enable_kms"');
215
- expect(generatedTemplate).toContain('variable "enable_ssm"');
216
-
217
- // Verify feature-based policies
218
- expect(generatedTemplate).toContain('resource "aws_iam_policy"');
219
-
220
- // Verify brace matching (valid HCL syntax)
221
- const openBraces = (generatedTemplate.match(/{/g) || []).length;
222
- const closeBraces = (generatedTemplate.match(/}/g) || []).length;
223
- expect(openBraces).toBe(closeBraces);
224
- });
225
- });
226
-
227
- // TODO: Update Azure/GCP tests to follow same pattern as CloudFormation/Terraform
228
- // Skipping for now to focus on core AWS templates
229
- describe.skip('Azure Generators', () => {
230
- it('should generate ARM template for Azure', async () => {
231
- // Test disabled - needs update to test actual generator output
232
- });
233
-
234
- it('should generate Terraform template for Azure', async () => {
235
- // Test disabled - needs update to test actual generator output
236
- });
237
- });
238
-
239
- describe.skip('GCP Generators', () => {
240
- it('should generate Deployment Manager template for GCP', async () => {
241
- // Test disabled - needs update to test actual generator output
242
- });
243
-
244
- it('should generate Terraform template for GCP', async () => {
245
- // Test disabled - needs update to test actual generator output
246
- });
247
- });
248
-
249
- describe.skip('Interactive Mode', () => {
250
- it('should prompt for provider and format when not provided', async () => {
251
- // Test disabled - needs update to work with unmocked generators
252
- });
253
-
254
- it('should handle user cancellation gracefully', async () => {
255
- // Test disabled - needs update to work with unmocked generators
256
- });
257
- });
258
-
259
- describe('Error Handling', () => {
260
- it('should handle missing Frigg application', async () => {
261
- findNearestBackendPackageJson.mockResolvedValue(null);
262
-
263
- await generateCommand({
264
- provider: 'aws',
265
- format: 'cloudformation'
266
- });
267
-
268
- expect(console.error).toHaveBeenCalledWith(
269
- 'Error generating deployment credentials:',
270
- 'Could not find a Frigg application. Make sure you are in a Frigg project directory.'
271
- );
272
- expect(process.exit).toHaveBeenCalledWith(1);
273
- });
274
-
275
- it('should show stack trace in verbose mode', async () => {
276
- const error = new Error('Test error');
277
- error.stack = 'Error: Test error\n at testFunction';
278
- findNearestBackendPackageJson.mockRejectedValue(error);
279
-
280
- await generateCommand({
281
- provider: 'aws',
282
- format: 'cloudformation',
283
- verbose: true
284
- });
285
-
286
- expect(console.error).toHaveBeenCalledWith(expect.stringContaining('at testFunction'));
287
- });
288
-
289
- it('should handle unsupported formats', async () => {
290
- await generateCommand({
291
- provider: 'aws',
292
- format: 'pulumi'
293
- });
294
-
295
- expect(console.error).toHaveBeenCalledWith(
296
- 'Error generating deployment credentials:',
297
- 'Pulumi support is not yet implemented'
298
- );
299
- });
300
- });
301
- });
@@ -1,43 +0,0 @@
1
- async function generateAzureARMTemplate(options) {
2
- const { appName, features, userPrefix } = options;
3
-
4
- // Placeholder for Azure ARM template generation
5
- const template = {
6
- "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
7
- "contentVersion": "1.0.0.0",
8
- "metadata": {
9
- "description": "Frigg deployment credentials for Azure - Coming Soon",
10
- "author": "Frigg CLI"
11
- },
12
- "parameters": {},
13
- "variables": {},
14
- "resources": [],
15
- "outputs": {
16
- "message": {
17
- "type": "string",
18
- "value": "Azure ARM template generation is coming soon. Please use Terraform for now."
19
- }
20
- }
21
- };
22
-
23
- return JSON.stringify(template, null, 2);
24
- }
25
-
26
- async function generateAzureTerraformTemplate(options) {
27
- // Placeholder for Azure Terraform template
28
- return `# Frigg Deployment Configuration for Azure
29
- # Coming Soon
30
-
31
- # Azure support with Terraform is under development.
32
- # Please check back in a future release.
33
-
34
- output "message" {
35
- value = "Azure Terraform support is coming soon"
36
- }
37
- `;
38
- }
39
-
40
- module.exports = {
41
- generateAzureARMTemplate,
42
- generateAzureTerraformTemplate
43
- };
@@ -1,47 +0,0 @@
1
- async function generateGCPDeploymentManagerTemplate(options) {
2
- const { appName, features, userPrefix } = options;
3
-
4
- // Placeholder for GCP Deployment Manager template
5
- const template = `# Frigg Deployment Configuration for Google Cloud Platform
6
- # Coming Soon
7
-
8
- # GCP Deployment Manager support is under development.
9
- # Please use Terraform for GCP deployments in the meantime.
10
-
11
- resources: []
12
-
13
- outputs:
14
- - name: message
15
- value: "GCP Deployment Manager support is coming soon"
16
- `;
17
-
18
- return template;
19
- }
20
-
21
- async function generateGCPTerraformTemplate(options) {
22
- // Placeholder for GCP Terraform template
23
- return `# Frigg Deployment Configuration for Google Cloud Platform
24
- # Coming Soon
25
-
26
- terraform {
27
- required_providers {
28
- google = {
29
- source = "hashicorp/google"
30
- version = "~> 5.0"
31
- }
32
- }
33
- }
34
-
35
- # GCP support with Terraform is under development.
36
- # Please check back in a future release.
37
-
38
- output "message" {
39
- value = "GCP Terraform support is coming soon"
40
- }
41
- `;
42
- }
43
-
44
- module.exports = {
45
- generateGCPDeploymentManagerTemplate,
46
- generateGCPTerraformTemplate
47
- };