@friggframework/devtools 2.0.0-next.3 → 2.0.0-next.30
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/.eslintrc.js +141 -0
- package/frigg-cli/__tests__/jest.config.js +102 -0
- package/frigg-cli/__tests__/unit/commands/build.test.js +483 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +418 -0
- package/frigg-cli/__tests__/unit/commands/ui.test.js +592 -0
- package/frigg-cli/__tests__/utils/command-tester.js +170 -0
- package/frigg-cli/__tests__/utils/mock-factory.js +270 -0
- package/frigg-cli/__tests__/utils/test-fixtures.js +463 -0
- package/frigg-cli/__tests__/utils/test-setup.js +286 -0
- package/frigg-cli/build-command/index.js +54 -0
- package/frigg-cli/deploy-command/index.js +36 -0
- package/frigg-cli/generate-command/__tests__/generate-command.test.js +312 -0
- package/frigg-cli/generate-command/azure-generator.js +43 -0
- package/frigg-cli/generate-command/gcp-generator.js +47 -0
- package/frigg-cli/generate-command/index.js +332 -0
- package/frigg-cli/generate-command/terraform-generator.js +555 -0
- package/frigg-cli/generate-iam-command.js +115 -0
- package/frigg-cli/index.js +47 -1
- package/frigg-cli/index.test.js +1 -4
- package/frigg-cli/init-command/backend-first-handler.js +756 -0
- package/frigg-cli/init-command/index.js +93 -0
- package/frigg-cli/init-command/template-handler.js +143 -0
- package/frigg-cli/install-command/index.js +1 -4
- package/frigg-cli/package.json +51 -0
- package/frigg-cli/start-command/index.js +24 -4
- package/frigg-cli/test/init-command.test.js +180 -0
- package/frigg-cli/test/npm-registry.test.js +319 -0
- package/frigg-cli/ui-command/index.js +154 -0
- package/frigg-cli/utils/app-resolver.js +319 -0
- package/frigg-cli/utils/backend-path.js +16 -17
- package/frigg-cli/utils/npm-registry.js +167 -0
- package/frigg-cli/utils/process-manager.js +199 -0
- package/frigg-cli/utils/repo-detection.js +405 -0
- package/infrastructure/AWS-DISCOVERY-TROUBLESHOOTING.md +245 -0
- package/infrastructure/AWS-IAM-CREDENTIAL-NEEDS.md +596 -0
- package/infrastructure/DEPLOYMENT-INSTRUCTIONS.md +268 -0
- package/infrastructure/GENERATE-IAM-DOCS.md +253 -0
- package/infrastructure/IAM-POLICY-TEMPLATES.md +176 -0
- package/infrastructure/README-TESTING.md +332 -0
- package/infrastructure/README.md +421 -0
- package/infrastructure/WEBSOCKET-CONFIGURATION.md +105 -0
- package/infrastructure/__tests__/fixtures/mock-aws-resources.js +391 -0
- package/infrastructure/__tests__/helpers/test-utils.js +277 -0
- package/infrastructure/aws-discovery.js +568 -0
- package/infrastructure/aws-discovery.test.js +373 -0
- package/infrastructure/build-time-discovery.js +206 -0
- package/infrastructure/build-time-discovery.test.js +375 -0
- package/infrastructure/create-frigg-infrastructure.js +3 -5
- package/infrastructure/frigg-deployment-iam-stack.yaml +379 -0
- package/infrastructure/iam-generator.js +687 -0
- package/infrastructure/iam-generator.test.js +169 -0
- package/infrastructure/iam-policy-basic.json +212 -0
- package/infrastructure/iam-policy-full.json +282 -0
- package/infrastructure/integration.test.js +383 -0
- package/infrastructure/run-discovery.js +110 -0
- package/infrastructure/serverless-template.js +923 -113
- package/infrastructure/serverless-template.test.js +541 -0
- package/management-ui/.eslintrc.js +22 -0
- package/management-ui/README.md +203 -0
- package/management-ui/components.json +21 -0
- package/management-ui/docs/phase2-integration-guide.md +320 -0
- package/management-ui/index.html +13 -0
- package/management-ui/package-lock.json +16517 -0
- package/management-ui/package.json +76 -0
- package/management-ui/packages/devtools/frigg-cli/ui-command/index.js +302 -0
- package/management-ui/postcss.config.js +6 -0
- package/management-ui/server/api/backend.js +256 -0
- package/management-ui/server/api/cli.js +315 -0
- package/management-ui/server/api/codegen.js +663 -0
- package/management-ui/server/api/connections.js +857 -0
- package/management-ui/server/api/discovery.js +185 -0
- package/management-ui/server/api/environment/index.js +1 -0
- package/management-ui/server/api/environment/router.js +378 -0
- package/management-ui/server/api/environment.js +328 -0
- package/management-ui/server/api/integrations.js +876 -0
- package/management-ui/server/api/logs.js +248 -0
- package/management-ui/server/api/monitoring.js +282 -0
- package/management-ui/server/api/open-ide.js +31 -0
- package/management-ui/server/api/project.js +1029 -0
- package/management-ui/server/api/users/sessions.js +371 -0
- package/management-ui/server/api/users/simulation.js +254 -0
- package/management-ui/server/api/users.js +362 -0
- package/management-ui/server/api-contract.md +275 -0
- package/management-ui/server/index.js +873 -0
- package/management-ui/server/middleware/errorHandler.js +93 -0
- package/management-ui/server/middleware/security.js +32 -0
- package/management-ui/server/processManager.js +296 -0
- package/management-ui/server/server.js +346 -0
- package/management-ui/server/services/aws-monitor.js +413 -0
- package/management-ui/server/services/npm-registry.js +347 -0
- package/management-ui/server/services/template-engine.js +538 -0
- package/management-ui/server/utils/cliIntegration.js +220 -0
- package/management-ui/server/utils/environment/auditLogger.js +471 -0
- package/management-ui/server/utils/environment/awsParameterStore.js +264 -0
- package/management-ui/server/utils/environment/encryption.js +278 -0
- package/management-ui/server/utils/environment/envFileManager.js +286 -0
- package/management-ui/server/utils/import-commonjs.js +28 -0
- package/management-ui/server/utils/response.js +83 -0
- package/management-ui/server/websocket/handler.js +325 -0
- package/management-ui/src/App.jsx +109 -0
- package/management-ui/src/assets/FriggLogo.svg +1 -0
- package/management-ui/src/components/AppRouter.jsx +65 -0
- package/management-ui/src/components/Button.jsx +70 -0
- package/management-ui/src/components/Card.jsx +97 -0
- package/management-ui/src/components/EnvironmentCompare.jsx +400 -0
- package/management-ui/src/components/EnvironmentEditor.jsx +372 -0
- package/management-ui/src/components/EnvironmentImportExport.jsx +469 -0
- package/management-ui/src/components/EnvironmentSchema.jsx +491 -0
- package/management-ui/src/components/EnvironmentSecurity.jsx +463 -0
- package/management-ui/src/components/ErrorBoundary.jsx +73 -0
- package/management-ui/src/components/IntegrationCard.jsx +481 -0
- package/management-ui/src/components/IntegrationCardEnhanced.jsx +770 -0
- package/management-ui/src/components/IntegrationExplorer.jsx +379 -0
- package/management-ui/src/components/IntegrationStatus.jsx +336 -0
- package/management-ui/src/components/Layout.jsx +716 -0
- package/management-ui/src/components/LoadingSpinner.jsx +113 -0
- package/management-ui/src/components/RepositoryPicker.jsx +248 -0
- package/management-ui/src/components/SessionMonitor.jsx +350 -0
- package/management-ui/src/components/StatusBadge.jsx +208 -0
- package/management-ui/src/components/UserContextSwitcher.jsx +212 -0
- package/management-ui/src/components/UserSimulation.jsx +327 -0
- package/management-ui/src/components/Welcome.jsx +434 -0
- package/management-ui/src/components/codegen/APIEndpointGenerator.jsx +637 -0
- package/management-ui/src/components/codegen/APIModuleSelector.jsx +227 -0
- package/management-ui/src/components/codegen/CodeGenerationWizard.jsx +247 -0
- package/management-ui/src/components/codegen/CodePreviewEditor.jsx +316 -0
- package/management-ui/src/components/codegen/DynamicModuleForm.jsx +271 -0
- package/management-ui/src/components/codegen/FormBuilder.jsx +737 -0
- package/management-ui/src/components/codegen/IntegrationGenerator.jsx +855 -0
- package/management-ui/src/components/codegen/ProjectScaffoldWizard.jsx +797 -0
- package/management-ui/src/components/codegen/SchemaBuilder.jsx +303 -0
- package/management-ui/src/components/codegen/TemplateSelector.jsx +586 -0
- package/management-ui/src/components/codegen/index.js +10 -0
- package/management-ui/src/components/connections/ConnectionConfigForm.jsx +362 -0
- package/management-ui/src/components/connections/ConnectionHealthMonitor.jsx +182 -0
- package/management-ui/src/components/connections/ConnectionTester.jsx +200 -0
- package/management-ui/src/components/connections/EntityRelationshipMapper.jsx +292 -0
- package/management-ui/src/components/connections/OAuthFlow.jsx +204 -0
- package/management-ui/src/components/connections/index.js +5 -0
- package/management-ui/src/components/index.js +21 -0
- package/management-ui/src/components/monitoring/APIGatewayMetrics.jsx +222 -0
- package/management-ui/src/components/monitoring/LambdaMetrics.jsx +169 -0
- package/management-ui/src/components/monitoring/MetricsChart.jsx +197 -0
- package/management-ui/src/components/monitoring/MonitoringDashboard.jsx +393 -0
- package/management-ui/src/components/monitoring/SQSMetrics.jsx +246 -0
- package/management-ui/src/components/monitoring/index.js +6 -0
- package/management-ui/src/components/monitoring/monitoring.css +218 -0
- package/management-ui/src/components/theme-provider.jsx +52 -0
- package/management-ui/src/components/theme-toggle.jsx +39 -0
- package/management-ui/src/components/ui/badge.tsx +36 -0
- package/management-ui/src/components/ui/button.test.jsx +56 -0
- package/management-ui/src/components/ui/button.tsx +57 -0
- package/management-ui/src/components/ui/card.tsx +76 -0
- package/management-ui/src/components/ui/dropdown-menu.tsx +199 -0
- package/management-ui/src/components/ui/select.tsx +157 -0
- package/management-ui/src/components/ui/skeleton.jsx +15 -0
- package/management-ui/src/hooks/useFrigg.jsx +601 -0
- package/management-ui/src/hooks/useSocket.jsx +58 -0
- package/management-ui/src/index.css +193 -0
- package/management-ui/src/lib/utils.ts +6 -0
- package/management-ui/src/main.jsx +10 -0
- package/management-ui/src/pages/CodeGeneration.jsx +14 -0
- package/management-ui/src/pages/Connections.jsx +252 -0
- package/management-ui/src/pages/ConnectionsEnhanced.jsx +633 -0
- package/management-ui/src/pages/Dashboard.jsx +311 -0
- package/management-ui/src/pages/Environment.jsx +314 -0
- package/management-ui/src/pages/IntegrationConfigure.jsx +669 -0
- package/management-ui/src/pages/IntegrationDiscovery.jsx +567 -0
- package/management-ui/src/pages/IntegrationTest.jsx +742 -0
- package/management-ui/src/pages/Integrations.jsx +253 -0
- package/management-ui/src/pages/Monitoring.jsx +17 -0
- package/management-ui/src/pages/Simulation.jsx +155 -0
- package/management-ui/src/pages/Users.jsx +492 -0
- package/management-ui/src/services/api.js +41 -0
- package/management-ui/src/services/apiModuleService.js +193 -0
- package/management-ui/src/services/websocket-handlers.js +120 -0
- package/management-ui/src/test/api/project.test.js +273 -0
- package/management-ui/src/test/components/Welcome.test.jsx +378 -0
- package/management-ui/src/test/mocks/server.js +178 -0
- package/management-ui/src/test/setup.js +61 -0
- package/management-ui/src/test/utils/test-utils.jsx +134 -0
- package/management-ui/src/utils/repository.js +98 -0
- package/management-ui/src/utils/repository.test.js +118 -0
- package/management-ui/src/workflows/phase2-integration-workflows.js +884 -0
- package/management-ui/tailwind.config.js +63 -0
- package/management-ui/tsconfig.json +37 -0
- package/management-ui/tsconfig.node.json +10 -0
- package/management-ui/vite.config.js +26 -0
- package/management-ui/vitest.config.js +38 -0
- package/package.json +16 -9
- package/infrastructure/app-handler-helpers.js +0 -57
- package/infrastructure/backend-utils.js +0 -90
- package/infrastructure/routers/auth.js +0 -26
- package/infrastructure/routers/integration-defined-routers.js +0 -37
- package/infrastructure/routers/middleware/loadUser.js +0 -15
- package/infrastructure/routers/middleware/requireLoggedInUser.js +0 -12
- package/infrastructure/routers/user.js +0 -41
- package/infrastructure/routers/websocket.js +0 -55
- package/infrastructure/workers/integration-defined-workers.js +0 -24
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global test setup for Frigg CLI tests
|
|
3
|
+
* This file is executed before each test file
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Store original environment
|
|
7
|
+
const originalEnv = process.env;
|
|
8
|
+
const originalConsole = { ...console };
|
|
9
|
+
const originalProcess = { ...process };
|
|
10
|
+
|
|
11
|
+
// Mock console to prevent noisy output during tests
|
|
12
|
+
global.console = {
|
|
13
|
+
...console,
|
|
14
|
+
log: jest.fn(),
|
|
15
|
+
info: jest.fn(),
|
|
16
|
+
warn: jest.fn(),
|
|
17
|
+
error: jest.fn(),
|
|
18
|
+
debug: jest.fn()
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Set up test environment variables
|
|
22
|
+
process.env = {
|
|
23
|
+
...originalEnv,
|
|
24
|
+
NODE_ENV: 'test',
|
|
25
|
+
HOME: '/mock/home',
|
|
26
|
+
PATH: '/mock/path',
|
|
27
|
+
CI: 'true'
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Global setup before each test
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
// Clear all mocks
|
|
33
|
+
jest.clearAllMocks();
|
|
34
|
+
|
|
35
|
+
// Reset timers
|
|
36
|
+
jest.clearAllTimers();
|
|
37
|
+
|
|
38
|
+
// Reset modules
|
|
39
|
+
jest.resetModules();
|
|
40
|
+
|
|
41
|
+
// Restore original process methods
|
|
42
|
+
process.exit = originalProcess.exit;
|
|
43
|
+
process.cwd = originalProcess.cwd;
|
|
44
|
+
|
|
45
|
+
// Mock process.exit to prevent actual exit
|
|
46
|
+
process.exit = jest.fn();
|
|
47
|
+
|
|
48
|
+
// Mock process.cwd to return predictable path
|
|
49
|
+
process.cwd = jest.fn().mockReturnValue('/mock/cwd');
|
|
50
|
+
|
|
51
|
+
// Reset console mocks
|
|
52
|
+
global.console.log.mockClear();
|
|
53
|
+
global.console.info.mockClear();
|
|
54
|
+
global.console.warn.mockClear();
|
|
55
|
+
global.console.error.mockClear();
|
|
56
|
+
global.console.debug.mockClear();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Global cleanup after each test
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
// Restore environment
|
|
62
|
+
process.env = { ...originalEnv };
|
|
63
|
+
|
|
64
|
+
// Restore process methods
|
|
65
|
+
process.exit = originalProcess.exit;
|
|
66
|
+
process.cwd = originalProcess.cwd;
|
|
67
|
+
|
|
68
|
+
// Clear any remaining timers
|
|
69
|
+
jest.clearAllTimers();
|
|
70
|
+
|
|
71
|
+
// Unmock all modules
|
|
72
|
+
jest.restoreAllMocks();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Global teardown after all tests
|
|
76
|
+
afterAll(() => {
|
|
77
|
+
// Restore original environment completely
|
|
78
|
+
process.env = originalEnv;
|
|
79
|
+
|
|
80
|
+
// Restore original console
|
|
81
|
+
global.console = originalConsole;
|
|
82
|
+
|
|
83
|
+
// Restore original process
|
|
84
|
+
Object.assign(process, originalProcess);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Custom matchers for CLI testing
|
|
88
|
+
expect.extend({
|
|
89
|
+
toBeValidExitCode(received) {
|
|
90
|
+
const validCodes = [0, 1, 2];
|
|
91
|
+
const pass = validCodes.includes(received);
|
|
92
|
+
|
|
93
|
+
if (pass) {
|
|
94
|
+
return {
|
|
95
|
+
message: () => `expected ${received} not to be a valid exit code`,
|
|
96
|
+
pass: true
|
|
97
|
+
};
|
|
98
|
+
} else {
|
|
99
|
+
return {
|
|
100
|
+
message: () => `expected ${received} to be a valid exit code (0, 1, or 2)`,
|
|
101
|
+
pass: false
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
toHaveLoggedError(received, expected) {
|
|
107
|
+
const errorLogs = global.console.error.mock.calls;
|
|
108
|
+
const pass = errorLogs.some(call =>
|
|
109
|
+
call.some(arg =>
|
|
110
|
+
typeof arg === 'string' && arg.includes(expected)
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
if (pass) {
|
|
115
|
+
return {
|
|
116
|
+
message: () => `expected not to have logged error containing "${expected}"`,
|
|
117
|
+
pass: true
|
|
118
|
+
};
|
|
119
|
+
} else {
|
|
120
|
+
return {
|
|
121
|
+
message: () => `expected to have logged error containing "${expected}"`,
|
|
122
|
+
pass: false
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
toHaveLoggedInfo(received, expected) {
|
|
128
|
+
const infoLogs = global.console.info.mock.calls;
|
|
129
|
+
const pass = infoLogs.some(call =>
|
|
130
|
+
call.some(arg =>
|
|
131
|
+
typeof arg === 'string' && arg.includes(expected)
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (pass) {
|
|
136
|
+
return {
|
|
137
|
+
message: () => `expected not to have logged info containing "${expected}"`,
|
|
138
|
+
pass: true
|
|
139
|
+
};
|
|
140
|
+
} else {
|
|
141
|
+
return {
|
|
142
|
+
message: () => `expected to have logged info containing "${expected}"`,
|
|
143
|
+
pass: false
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
toBeWithinTimeLimit(received, limit) {
|
|
149
|
+
const pass = received <= limit;
|
|
150
|
+
|
|
151
|
+
if (pass) {
|
|
152
|
+
return {
|
|
153
|
+
message: () => `expected ${received}ms not to be within ${limit}ms`,
|
|
154
|
+
pass: true
|
|
155
|
+
};
|
|
156
|
+
} else {
|
|
157
|
+
return {
|
|
158
|
+
message: () => `expected ${received}ms to be within ${limit}ms`,
|
|
159
|
+
pass: false
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Helper functions available in all tests
|
|
166
|
+
global.TestHelpers = {
|
|
167
|
+
/**
|
|
168
|
+
* Create a temporary directory for tests
|
|
169
|
+
*/
|
|
170
|
+
createTempDir() {
|
|
171
|
+
const fs = require('fs');
|
|
172
|
+
const path = require('path');
|
|
173
|
+
const os = require('os');
|
|
174
|
+
|
|
175
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-cli-test-'));
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Clean up temporary directory
|
|
180
|
+
*/
|
|
181
|
+
cleanupTempDir(dirPath) {
|
|
182
|
+
const fs = require('fs');
|
|
183
|
+
|
|
184
|
+
if (fs.existsSync(dirPath)) {
|
|
185
|
+
fs.rmSync(dirPath, { recursive: true, force: true });
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Create a mock package.json file
|
|
191
|
+
*/
|
|
192
|
+
createMockPackageJson(overrides = {}) {
|
|
193
|
+
return JSON.stringify({
|
|
194
|
+
name: 'test-package',
|
|
195
|
+
version: '1.0.0',
|
|
196
|
+
main: 'index.js',
|
|
197
|
+
scripts: {
|
|
198
|
+
test: 'jest',
|
|
199
|
+
start: 'node index.js'
|
|
200
|
+
},
|
|
201
|
+
dependencies: {},
|
|
202
|
+
devDependencies: {},
|
|
203
|
+
...overrides
|
|
204
|
+
}, null, 2);
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Create a mock frigg.config.json file
|
|
209
|
+
*/
|
|
210
|
+
createMockFriggConfig(overrides = {}) {
|
|
211
|
+
return JSON.stringify({
|
|
212
|
+
stage: 'dev',
|
|
213
|
+
region: 'us-east-1',
|
|
214
|
+
profile: 'default',
|
|
215
|
+
backend: {
|
|
216
|
+
runtime: 'nodejs18.x',
|
|
217
|
+
timeout: 30,
|
|
218
|
+
memory: 128
|
|
219
|
+
},
|
|
220
|
+
...overrides
|
|
221
|
+
}, null, 2);
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Wait for a specific amount of time
|
|
226
|
+
*/
|
|
227
|
+
async delay(ms) {
|
|
228
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Generate a random string for test data
|
|
233
|
+
*/
|
|
234
|
+
randomString(length = 10) {
|
|
235
|
+
return Math.random().toString(36).substring(2, length + 2);
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Simulate file system structure
|
|
240
|
+
*/
|
|
241
|
+
mockFileSystem(structure) {
|
|
242
|
+
const fs = require('fs');
|
|
243
|
+
|
|
244
|
+
const originalExistsSync = fs.existsSync;
|
|
245
|
+
const originalReadFileSync = fs.readFileSync;
|
|
246
|
+
const originalWriteFileSync = fs.writeFileSync;
|
|
247
|
+
|
|
248
|
+
fs.existsSync = jest.fn((path) => {
|
|
249
|
+
return structure.hasOwnProperty(path);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
fs.readFileSync = jest.fn((path) => {
|
|
253
|
+
if (structure.hasOwnProperty(path)) {
|
|
254
|
+
return structure[path];
|
|
255
|
+
}
|
|
256
|
+
throw new Error(`ENOENT: no such file or directory, open '${path}'`);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
fs.writeFileSync = jest.fn((path, data) => {
|
|
260
|
+
structure[path] = data;
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
restore() {
|
|
265
|
+
fs.existsSync = originalExistsSync;
|
|
266
|
+
fs.readFileSync = originalReadFileSync;
|
|
267
|
+
fs.writeFileSync = originalWriteFileSync;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// Global timeout for all tests
|
|
274
|
+
jest.setTimeout(30000);
|
|
275
|
+
|
|
276
|
+
// Suppress specific warnings during tests
|
|
277
|
+
const originalWarn = console.warn;
|
|
278
|
+
console.warn = (...args) => {
|
|
279
|
+
// Suppress specific warnings that are expected during testing
|
|
280
|
+
const message = args.join(' ');
|
|
281
|
+
if (message.includes('ExperimentalWarning') ||
|
|
282
|
+
message.includes('DeprecationWarning')) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
originalWarn.apply(console, args);
|
|
286
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const { spawnSync } = require('child_process');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
async function buildCommand(options) {
|
|
5
|
+
console.log('Building the serverless application...');
|
|
6
|
+
|
|
7
|
+
// AWS discovery is now handled directly in serverless-template.js
|
|
8
|
+
console.log('📦 Packaging serverless application...');
|
|
9
|
+
const backendPath = path.resolve(process.cwd());
|
|
10
|
+
const infrastructurePath = 'infrastructure.js';
|
|
11
|
+
const command = 'serverless';
|
|
12
|
+
const serverlessArgs = [
|
|
13
|
+
'package',
|
|
14
|
+
'--config',
|
|
15
|
+
infrastructurePath,
|
|
16
|
+
'--stage',
|
|
17
|
+
options.stage
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
// Add support for --verbose option
|
|
21
|
+
if (options.verbose) {
|
|
22
|
+
serverlessArgs.push('--verbose');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
console.log('Running command from ', backendPath);
|
|
26
|
+
console.log('Serverless Command:', command, serverlessArgs.join(' '));
|
|
27
|
+
|
|
28
|
+
const result = spawnSync(command, serverlessArgs, {
|
|
29
|
+
cwd: backendPath,
|
|
30
|
+
stdio: 'inherit',
|
|
31
|
+
shell: true,
|
|
32
|
+
env: {
|
|
33
|
+
...process.env,
|
|
34
|
+
NODE_PATH: path.resolve(backendPath, 'node_modules'),
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (result.status !== 0) {
|
|
39
|
+
console.error(`Serverless build failed with code ${result.status}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// childProcess.on('error', (error) => {
|
|
44
|
+
// console.error(`Error executing command: ${error.message}`);
|
|
45
|
+
// });
|
|
46
|
+
|
|
47
|
+
// childProcess.on('close', (code) => {
|
|
48
|
+
// if (code !== 0) {
|
|
49
|
+
// console.log(`Child process exited with code ${code}`);
|
|
50
|
+
// }
|
|
51
|
+
// });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = { buildCommand };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { spawn, spawnSync } = require('child_process');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
async function deployCommand(options) {
|
|
5
|
+
console.log('Deploying the serverless application...');
|
|
6
|
+
|
|
7
|
+
// AWS discovery is now handled directly in serverless-template.js
|
|
8
|
+
console.log('🚀 Deploying serverless application...');
|
|
9
|
+
const backendPath = path.resolve(process.cwd());
|
|
10
|
+
const infrastructurePath = 'infrastructure.js';
|
|
11
|
+
const command = 'serverless';
|
|
12
|
+
const serverlessArgs = [
|
|
13
|
+
'deploy',
|
|
14
|
+
'--config',
|
|
15
|
+
infrastructurePath,
|
|
16
|
+
'--stage',
|
|
17
|
+
options.stage
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const childProcess = spawn(command, serverlessArgs, {
|
|
21
|
+
cwd: backendPath,
|
|
22
|
+
stdio: 'inherit',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
childProcess.on('error', (error) => {
|
|
26
|
+
console.error(`Error executing command: ${error.message}`);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
childProcess.on('close', (code) => {
|
|
30
|
+
if (code !== 0) {
|
|
31
|
+
console.log(`Child process exited with code ${code}`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { deployCommand };
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const generateCommand = require('../index');
|
|
4
|
+
|
|
5
|
+
// Mock dependencies
|
|
6
|
+
jest.mock('fs');
|
|
7
|
+
jest.mock('@friggframework/core');
|
|
8
|
+
jest.mock('@inquirer/prompts');
|
|
9
|
+
jest.mock('../../../infrastructure/iam-generator');
|
|
10
|
+
jest.mock('../terraform-generator');
|
|
11
|
+
jest.mock('../azure-generator');
|
|
12
|
+
jest.mock('../gcp-generator');
|
|
13
|
+
|
|
14
|
+
describe('Generate Command', () => {
|
|
15
|
+
const mockBackendDir = '/mock/backend';
|
|
16
|
+
const mockPackageJsonPath = path.join(mockBackendDir, 'package.json');
|
|
17
|
+
const mockAppDefinitionPath = path.join(mockBackendDir, 'index.js');
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
jest.clearAllMocks();
|
|
21
|
+
|
|
22
|
+
// Mock process.exit
|
|
23
|
+
jest.spyOn(process, 'exit').mockImplementation(() => {});
|
|
24
|
+
|
|
25
|
+
// Mock console methods
|
|
26
|
+
jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
27
|
+
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
28
|
+
|
|
29
|
+
// Mock findNearestBackendPackageJson
|
|
30
|
+
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
31
|
+
findNearestBackendPackageJson.mockResolvedValue(mockPackageJsonPath);
|
|
32
|
+
|
|
33
|
+
// Mock fs operations
|
|
34
|
+
fs.readFileSync.mockImplementation((filePath) => {
|
|
35
|
+
if (filePath === mockPackageJsonPath) {
|
|
36
|
+
return JSON.stringify({ name: 'test-app' });
|
|
37
|
+
}
|
|
38
|
+
return '';
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
fs.existsSync.mockImplementation((filePath) => {
|
|
42
|
+
if (filePath === mockAppDefinitionPath) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (filePath.includes('backend/infrastructure')) {
|
|
46
|
+
return false; // Directory doesn't exist, will be created
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
fs.mkdirSync.mockImplementation(() => {});
|
|
52
|
+
fs.writeFileSync.mockImplementation(() => {});
|
|
53
|
+
|
|
54
|
+
// Mock app definition
|
|
55
|
+
jest.doMock(mockAppDefinitionPath, () => ({
|
|
56
|
+
vpc: { enable: true },
|
|
57
|
+
encryption: { useDefaultKMSForFieldLevelEncryption: true },
|
|
58
|
+
ssm: { enable: true },
|
|
59
|
+
websockets: { enable: false }
|
|
60
|
+
}), { virtual: true });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
jest.restoreAllMocks();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('AWS CloudFormation Generation', () => {
|
|
68
|
+
it('should generate CloudFormation template with explicit options', async () => {
|
|
69
|
+
const { generateCloudFormationTemplate } = require('../../../infrastructure/iam-generator');
|
|
70
|
+
generateCloudFormationTemplate.mockResolvedValue('AWSTemplateFormatVersion: 2010-09-09\nDescription: Test template');
|
|
71
|
+
|
|
72
|
+
await generateCommand({
|
|
73
|
+
provider: 'aws',
|
|
74
|
+
format: 'cloudformation',
|
|
75
|
+
output: 'backend/infrastructure',
|
|
76
|
+
user: 'test-user',
|
|
77
|
+
stackName: 'test-stack'
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(generateCloudFormationTemplate).toHaveBeenCalledWith({
|
|
81
|
+
appName: 'test-app',
|
|
82
|
+
features: {
|
|
83
|
+
vpc: true,
|
|
84
|
+
kms: true,
|
|
85
|
+
ssm: true,
|
|
86
|
+
websockets: false
|
|
87
|
+
},
|
|
88
|
+
userPrefix: 'test-user',
|
|
89
|
+
stackName: 'test-stack'
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
93
|
+
expect.stringContaining('frigg-deployment-aws-cloudformation.yaml'),
|
|
94
|
+
expect.stringContaining('AWSTemplateFormatVersion')
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('✅ Generated cloudformation template for aws'));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should handle missing app definition gracefully', async () => {
|
|
101
|
+
fs.existsSync.mockImplementation((filePath) => {
|
|
102
|
+
if (filePath === mockAppDefinitionPath) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
await generateCommand({
|
|
109
|
+
provider: 'aws',
|
|
110
|
+
format: 'cloudformation'
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
114
|
+
'Error generating deployment credentials:',
|
|
115
|
+
expect.stringContaining('App definition not found')
|
|
116
|
+
);
|
|
117
|
+
expect(process.exit).toHaveBeenCalledWith(1);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('AWS Terraform Generation', () => {
|
|
122
|
+
it('should generate Terraform template for AWS', async () => {
|
|
123
|
+
const { generateTerraformTemplate } = require('../terraform-generator');
|
|
124
|
+
generateTerraformTemplate.mockResolvedValue('provider "aws" {\n region = var.region\n}');
|
|
125
|
+
|
|
126
|
+
await generateCommand({
|
|
127
|
+
provider: 'aws',
|
|
128
|
+
format: 'terraform',
|
|
129
|
+
output: 'backend/infrastructure'
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
expect(generateTerraformTemplate).toHaveBeenCalledWith({
|
|
133
|
+
appName: 'test-app',
|
|
134
|
+
features: {
|
|
135
|
+
vpc: true,
|
|
136
|
+
kms: true,
|
|
137
|
+
ssm: true,
|
|
138
|
+
websockets: false
|
|
139
|
+
},
|
|
140
|
+
userPrefix: 'frigg-deployment-user'
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
144
|
+
expect.stringContaining('frigg-deployment-aws-terraform.tf'),
|
|
145
|
+
expect.stringContaining('provider "aws"')
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('Azure Generators', () => {
|
|
151
|
+
it('should generate ARM template for Azure', async () => {
|
|
152
|
+
const { generateAzureARMTemplate } = require('../azure-generator');
|
|
153
|
+
generateAzureARMTemplate.mockResolvedValue(JSON.stringify({
|
|
154
|
+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
|
|
155
|
+
"contentVersion": "1.0.0.0"
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
await generateCommand({
|
|
159
|
+
provider: 'azure',
|
|
160
|
+
format: 'arm',
|
|
161
|
+
output: 'backend/infrastructure'
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(generateAzureARMTemplate).toHaveBeenCalledWith({
|
|
165
|
+
appName: 'test-app',
|
|
166
|
+
features: expect.any(Object),
|
|
167
|
+
userPrefix: 'frigg-deployment-user'
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
171
|
+
expect.stringContaining('frigg-deployment-azure-arm.json'),
|
|
172
|
+
expect.stringContaining('$schema')
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should generate Terraform template for Azure', async () => {
|
|
177
|
+
const { generateAzureTerraformTemplate } = require('../azure-generator');
|
|
178
|
+
generateAzureTerraformTemplate.mockResolvedValue('provider "azurerm" {\n features {}\n}');
|
|
179
|
+
|
|
180
|
+
await generateCommand({
|
|
181
|
+
provider: 'azure',
|
|
182
|
+
format: 'terraform'
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
expect(generateAzureTerraformTemplate).toHaveBeenCalled();
|
|
186
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
187
|
+
expect.stringContaining('frigg-deployment-azure-terraform.tf'),
|
|
188
|
+
expect.stringContaining('provider "azurerm"')
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
describe('GCP Generators', () => {
|
|
194
|
+
it('should generate Deployment Manager template for GCP', async () => {
|
|
195
|
+
const { generateGCPDeploymentManagerTemplate } = require('../gcp-generator');
|
|
196
|
+
generateGCPDeploymentManagerTemplate.mockResolvedValue('resources:\n- name: test-resource\n type: compute.v1.instance');
|
|
197
|
+
|
|
198
|
+
await generateCommand({
|
|
199
|
+
provider: 'gcp',
|
|
200
|
+
format: 'deployment-manager'
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
expect(generateGCPDeploymentManagerTemplate).toHaveBeenCalled();
|
|
204
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
205
|
+
expect.stringContaining('frigg-deployment-gcp-deployment-manager.yaml'),
|
|
206
|
+
expect.stringContaining('resources:')
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should generate Terraform template for GCP', async () => {
|
|
211
|
+
const { generateGCPTerraformTemplate } = require('../gcp-generator');
|
|
212
|
+
generateGCPTerraformTemplate.mockResolvedValue('provider "google" {\n project = var.project_id\n}');
|
|
213
|
+
|
|
214
|
+
await generateCommand({
|
|
215
|
+
provider: 'gcp',
|
|
216
|
+
format: 'terraform'
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
expect(generateGCPTerraformTemplate).toHaveBeenCalled();
|
|
220
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
221
|
+
expect.stringContaining('frigg-deployment-gcp-terraform.tf'),
|
|
222
|
+
expect.stringContaining('provider "google"')
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('Interactive Mode', () => {
|
|
228
|
+
it('should prompt for provider and format when not provided', async () => {
|
|
229
|
+
const { select } = require('@inquirer/prompts');
|
|
230
|
+
select.mockResolvedValueOnce('aws').mockResolvedValueOnce('cloudformation');
|
|
231
|
+
|
|
232
|
+
const { generateCloudFormationTemplate } = require('../../../infrastructure/iam-generator');
|
|
233
|
+
generateCloudFormationTemplate.mockResolvedValue('AWSTemplateFormatVersion: 2010-09-09');
|
|
234
|
+
|
|
235
|
+
await generateCommand({});
|
|
236
|
+
|
|
237
|
+
expect(select).toHaveBeenCalledTimes(2);
|
|
238
|
+
expect(select).toHaveBeenNthCalledWith(1, expect.objectContaining({
|
|
239
|
+
message: 'Select cloud provider:',
|
|
240
|
+
choices: expect.arrayContaining([
|
|
241
|
+
expect.objectContaining({ name: 'AWS', value: 'aws' }),
|
|
242
|
+
expect.objectContaining({ name: 'Azure', value: 'azure' }),
|
|
243
|
+
expect.objectContaining({ name: 'Google Cloud Platform', value: 'gcp' })
|
|
244
|
+
])
|
|
245
|
+
}));
|
|
246
|
+
|
|
247
|
+
expect(select).toHaveBeenNthCalledWith(2, expect.objectContaining({
|
|
248
|
+
message: 'Select output format:',
|
|
249
|
+
choices: expect.arrayContaining([
|
|
250
|
+
expect.objectContaining({ name: 'CloudFormation', value: 'cloudformation' })
|
|
251
|
+
])
|
|
252
|
+
}));
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('should handle user cancellation gracefully', async () => {
|
|
256
|
+
const { select } = require('@inquirer/prompts');
|
|
257
|
+
const exitError = new Error('User cancelled');
|
|
258
|
+
exitError.name = 'ExitPromptError';
|
|
259
|
+
select.mockRejectedValue(exitError);
|
|
260
|
+
|
|
261
|
+
await generateCommand({});
|
|
262
|
+
|
|
263
|
+
expect(console.log).toHaveBeenCalledWith('\n✖ Command cancelled by user');
|
|
264
|
+
expect(process.exit).toHaveBeenCalledWith(0);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('Error Handling', () => {
|
|
269
|
+
it('should handle missing Frigg application', async () => {
|
|
270
|
+
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
271
|
+
findNearestBackendPackageJson.mockResolvedValue(null);
|
|
272
|
+
|
|
273
|
+
await generateCommand({
|
|
274
|
+
provider: 'aws',
|
|
275
|
+
format: 'cloudformation'
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
279
|
+
'Error generating deployment credentials:',
|
|
280
|
+
'Could not find a Frigg application. Make sure you are in a Frigg project directory.'
|
|
281
|
+
);
|
|
282
|
+
expect(process.exit).toHaveBeenCalledWith(1);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('should show stack trace in verbose mode', async () => {
|
|
286
|
+
const { findNearestBackendPackageJson } = require('@friggframework/core');
|
|
287
|
+
const error = new Error('Test error');
|
|
288
|
+
error.stack = 'Error: Test error\n at testFunction';
|
|
289
|
+
findNearestBackendPackageJson.mockRejectedValue(error);
|
|
290
|
+
|
|
291
|
+
await generateCommand({
|
|
292
|
+
provider: 'aws',
|
|
293
|
+
format: 'cloudformation',
|
|
294
|
+
verbose: true
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
expect(console.error).toHaveBeenCalledWith(expect.stringContaining('at testFunction'));
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('should handle unsupported formats', async () => {
|
|
301
|
+
await generateCommand({
|
|
302
|
+
provider: 'aws',
|
|
303
|
+
format: 'pulumi'
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
expect(console.error).toHaveBeenCalledWith(
|
|
307
|
+
'Error generating deployment credentials:',
|
|
308
|
+
'Pulumi support is not yet implemented'
|
|
309
|
+
);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
});
|