@friggframework/devtools 2.0.0--canary.710.91495fa.0 → 2.0.0--canary.702.ef0dc8c.0

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 (86) hide show
  1. package/README.md +1 -0
  2. package/frigg-cli/README.md +76 -78
  3. package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
  4. package/frigg-cli/__tests__/unit/commands/deploy.test.js +27 -30
  5. package/frigg-cli/__tests__/unit/commands/doctor.test.js +6 -10
  6. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
  7. package/frigg-cli/__tests__/unit/commands/install.test.js +341 -601
  8. package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
  9. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
  10. package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
  11. package/frigg-cli/build-command/index.js +6 -0
  12. package/frigg-cli/deploy-command/index.js +6 -0
  13. package/frigg-cli/generate-command/index.js +0 -1
  14. package/frigg-cli/generate-iam-command.js +0 -1
  15. package/frigg-cli/index.js +23 -10
  16. package/frigg-cli/index.test.js +158 -0
  17. package/frigg-cli/init-command/backend-first-handler.js +531 -395
  18. package/frigg-cli/init-command/index.js +35 -82
  19. package/frigg-cli/install-command/commit-changes.js +8 -40
  20. package/frigg-cli/install-command/environment-variables.js +0 -15
  21. package/frigg-cli/install-command/index.js +21 -96
  22. package/frigg-cli/install-command/install-package.js +4 -77
  23. package/frigg-cli/install-command/integration-file.js +11 -20
  24. package/frigg-cli/install-command/template.js +75 -102
  25. package/frigg-cli/install-command/validate-package.js +4 -36
  26. package/frigg-cli/package.json +1 -1
  27. package/frigg-cli/start-command/index.js +4 -0
  28. package/frigg-cli/start-command/start-command.test.js +3 -0
  29. package/frigg-cli/test/init-command.test.js +2 -9
  30. package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
  31. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
  32. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +326 -0
  33. package/frigg-cli/validate-command/__tests__/validate-command.test.js +241 -0
  34. package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +119 -0
  35. package/frigg-cli/validate-command/checks/config.js +468 -0
  36. package/frigg-cli/validate-command/checks/integrations.js +274 -0
  37. package/frigg-cli/validate-command/fixtures/bad-module/index.js +18 -0
  38. package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +76 -0
  39. package/frigg-cli/validate-command/fixtures/fathom-module/index.js +6 -0
  40. package/frigg-cli/validate-command/format-report.js +60 -0
  41. package/frigg-cli/validate-command/index.js +151 -0
  42. package/frigg-cli/validate-command/load-app-definition.js +93 -0
  43. package/frigg-cli/validate-command/load-module-definition.js +64 -0
  44. package/frigg-cli/validate-command/schema-issues.js +154 -0
  45. package/frigg-cli/validate-command/validate-app-definition.js +60 -0
  46. package/frigg-cli/validate-command/validate-module-definition.js +46 -0
  47. package/infrastructure/__tests__/postgres-config.test.js +835 -241
  48. package/infrastructure/__tests__/template-generation.test.js +8 -36
  49. package/infrastructure/app-definition-schema-contract.test.js +607 -0
  50. package/infrastructure/create-frigg-infrastructure.js +4 -1
  51. package/infrastructure/create-frigg-infrastructure.test.js +51 -0
  52. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +60 -118
  53. package/infrastructure/domains/database/aurora-builder.js +2 -13
  54. package/infrastructure/domains/database/aurora-builder.test.js +0 -22
  55. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +8 -12
  56. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +7 -19
  57. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +8 -12
  58. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +18 -17
  59. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +2 -12
  60. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +1 -8
  61. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +2 -4
  62. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +0 -10
  63. package/infrastructure/domains/networking/vpc-builder.js +8 -18
  64. package/infrastructure/domains/networking/vpc-builder.test.js +13 -32
  65. package/infrastructure/domains/security/iam-generator.js +5 -112
  66. package/infrastructure/domains/security/iam-generator.test.js +0 -94
  67. package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
  68. package/infrastructure/domains/shared/utilities/base-definition-factory.js +2 -7
  69. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +0 -21
  70. package/infrastructure/infrastructure-composer.test.js +794 -268
  71. package/infrastructure/integration.test.js +381 -0
  72. package/infrastructure/scripts/build-prisma-layer.test.js +7 -28
  73. package/infrastructure/scripts/build-time-discovery.test.js +3 -18
  74. package/package.json +8 -10
  75. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
  76. package/frigg-cli/init-command/deployment-modes.js +0 -7
  77. package/frigg-cli/init-command/safe-path.js +0 -58
  78. package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
  79. package/frigg-cli/install-command/app-definition.js +0 -174
  80. package/frigg-cli/install-command/resolve-module.js +0 -69
  81. package/frigg-cli/templates/backend/README.md +0 -267
  82. package/frigg-cli/templates/backend/env.example +0 -20
  83. package/frigg-cli/templates/backend/gitignore +0 -10
  84. package/frigg-cli/templates/backend/index.js +0 -114
  85. package/frigg-cli/templates/backend/infrastructure.js +0 -20
  86. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
@@ -33,17 +33,6 @@ const {
33
33
  } = require('../../../utils/repo-detection');
34
34
  const { uiCommand } = require('../../../ui-command');
35
35
 
36
- // uiCommand waits 2 s for the dev servers and opens the browser 1 s later.
37
- // Drive those timers with fake time instead of sleeping for real (the real
38
- // waits made this suite take ~40 s and tripped the 5 s default timeout).
39
- const STARTUP_AND_BROWSER_DELAY_MS = 3100;
40
-
41
- async function runUi(options) {
42
- const done = uiCommand(options);
43
- await jest.advanceTimersByTimeAsync(STARTUP_AND_BROWSER_DELAY_MS);
44
- return done;
45
- }
46
-
47
36
  describe('CLI Command: ui', () => {
48
37
  let consoleLogSpy;
49
38
  let consoleErrorSpy;
@@ -54,7 +43,6 @@ describe('CLI Command: ui', () => {
54
43
 
55
44
  beforeEach(() => {
56
45
  jest.clearAllMocks();
57
- jest.useFakeTimers();
58
46
 
59
47
  // Mock console methods
60
48
  consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
@@ -87,7 +75,6 @@ describe('CLI Command: ui', () => {
87
75
  });
88
76
 
89
77
  afterEach(() => {
90
- jest.useRealTimers();
91
78
  consoleLogSpy.mockRestore();
92
79
  consoleErrorSpy.mockRestore();
93
80
  processExitSpy.mockRestore();
@@ -97,7 +84,7 @@ describe('CLI Command: ui', () => {
97
84
 
98
85
  describe('Repository Detection', () => {
99
86
  it('should use specified repo path when provided', async () => {
100
- await runUi({ repo: '/custom/repo', port: 3001, open: false });
87
+ await uiCommand({ repo: '/custom/repo', port: 3001, open: false });
101
88
 
102
89
  expect(consoleLogSpy).toHaveBeenCalledWith(
103
90
  expect.stringContaining('Using specified repository')
@@ -105,7 +92,7 @@ describe('CLI Command: ui', () => {
105
92
  });
106
93
 
107
94
  it('should detect current Frigg repository', async () => {
108
- await runUi({ port: 3001, open: false });
95
+ await uiCommand({ port: 3001, open: false });
109
96
 
110
97
  expect(getCurrentRepositoryInfo).toHaveBeenCalled();
111
98
  expect(consoleLogSpy).toHaveBeenCalledWith(
@@ -120,7 +107,7 @@ describe('CLI Command: ui', () => {
120
107
  currentSubPath: 'packages/backend'
121
108
  });
122
109
 
123
- await runUi({ port: 3001, open: false });
110
+ await uiCommand({ port: 3001, open: false });
124
111
 
125
112
  expect(consoleLogSpy).toHaveBeenCalledWith(
126
113
  expect.stringContaining('Currently in subdirectory: packages/backend')
@@ -134,7 +121,7 @@ describe('CLI Command: ui', () => {
134
121
  { path: '/repos/frigg-2', name: 'frigg-2' }
135
122
  ]);
136
123
 
137
- await runUi({ port: 3001, open: false });
124
+ await uiCommand({ port: 3001, open: false });
138
125
 
139
126
  expect(discoverFriggRepositories).toHaveBeenCalled();
140
127
  expect(consoleLogSpy).toHaveBeenCalledWith(
@@ -146,7 +133,7 @@ describe('CLI Command: ui', () => {
146
133
  getCurrentRepositoryInfo.mockResolvedValue(null);
147
134
  discoverFriggRepositories.mockResolvedValue([]);
148
135
 
149
- await runUi({ port: 3001, open: false });
136
+ await uiCommand({ port: 3001, open: false });
150
137
 
151
138
  expect(consoleLogSpy).toHaveBeenCalledWith(
152
139
  expect.stringContaining('No Frigg repositories found')
@@ -157,7 +144,7 @@ describe('CLI Command: ui', () => {
157
144
 
158
145
  describe('Development Mode', () => {
159
146
  it('should spawn backend and frontend in dev mode', async () => {
160
- await runUi({ port: 3001, open: false, dev: true });
147
+ await uiCommand({ port: 3001, open: false, dev: true });
161
148
 
162
149
  expect(mockProcessManager.spawnProcess).toHaveBeenCalledTimes(2);
163
150
  expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
@@ -181,7 +168,7 @@ describe('CLI Command: ui', () => {
181
168
  });
182
169
 
183
170
  it('should use default port 3001', async () => {
184
- await runUi({ open: false, dev: true });
171
+ await uiCommand({ open: false, dev: true });
185
172
 
186
173
  expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
187
174
  expect.any(String),
@@ -194,7 +181,7 @@ describe('CLI Command: ui', () => {
194
181
  });
195
182
 
196
183
  it('should use custom port when specified', async () => {
197
- await runUi({ port: 4000, open: false, dev: true });
184
+ await uiCommand({ port: 4000, open: false, dev: true });
198
185
 
199
186
  expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
200
187
  expect.any(String),
@@ -210,7 +197,10 @@ describe('CLI Command: ui', () => {
210
197
  });
211
198
 
212
199
  it('should print status with correct URLs', async () => {
213
- await runUi({ port: 3001, open: false, dev: true });
200
+ await uiCommand({ port: 3001, open: false, dev: true });
201
+
202
+ // Wait for startup delay (testing async behavior, not mocks)
203
+ await new Promise(resolve => setTimeout(resolve, 2100));
214
204
 
215
205
  // Verify printStatus called with exact URLs
216
206
  expect(mockProcessManager.printStatus).toHaveBeenCalledWith(
@@ -221,14 +211,20 @@ describe('CLI Command: ui', () => {
221
211
  });
222
212
 
223
213
  it('should open browser when open=true', async () => {
224
- await runUi({ port: 3001, open: true, dev: true });
214
+ await uiCommand({ port: 3001, open: true, dev: true });
215
+
216
+ // Wait for startup + browser delay (testing async behavior, not mocks)
217
+ await new Promise(resolve => setTimeout(resolve, 3100));
225
218
 
226
219
  // Verify browser opened with correct URL
227
220
  expect(open).toHaveBeenCalledWith('http://localhost:5173');
228
221
  });
229
222
 
230
223
  it('should NOT open browser when open=false', async () => {
231
- await runUi({ port: 3001, open: false, dev: true });
224
+ await uiCommand({ port: 3001, open: false, dev: true });
225
+
226
+ // Wait for startup delay (testing async behavior, not mocks)
227
+ await new Promise(resolve => setTimeout(resolve, 3100));
232
228
 
233
229
  // Verify browser was not opened
234
230
  expect(open).not.toHaveBeenCalled();
@@ -241,7 +237,7 @@ describe('CLI Command: ui', () => {
241
237
  currentSubPath: null
242
238
  });
243
239
 
244
- await runUi({ port: 3001, open: false, dev: true });
240
+ await uiCommand({ port: 3001, open: false, dev: true });
245
241
 
246
242
  expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
247
243
  expect.any(String),
@@ -256,7 +252,7 @@ describe('CLI Command: ui', () => {
256
252
  });
257
253
 
258
254
  it('should set REPOSITORY_INFO as JSON string with correct structure', async () => {
259
- await runUi({ port: 3001, open: false, dev: true });
255
+ await uiCommand({ port: 3001, open: false, dev: true });
260
256
 
261
257
  const call = mockProcessManager.spawnProcess.mock.calls[0];
262
258
  const env = call[3].env;
@@ -279,7 +275,7 @@ describe('CLI Command: ui', () => {
279
275
  { path: '/repos/frigg-1', name: 'frigg-1' }
280
276
  ]);
281
277
 
282
- await runUi({ port: 3001, open: false, dev: true });
278
+ await uiCommand({ port: 3001, open: false, dev: true });
283
279
 
284
280
  const call = mockProcessManager.spawnProcess.mock.calls[0];
285
281
  const env = call[3].env;
@@ -303,7 +299,7 @@ describe('CLI Command: ui', () => {
303
299
  throw error;
304
300
  });
305
301
 
306
- await runUi({ port: 3001, open: false, dev: true });
302
+ await uiCommand({ port: 3001, open: false, dev: true });
307
303
 
308
304
  expect(consoleErrorSpy).toHaveBeenCalledWith(
309
305
  expect.stringContaining('Failed to start Management UI'),
@@ -320,7 +316,7 @@ describe('CLI Command: ui', () => {
320
316
  throw new Error('Generic startup error');
321
317
  });
322
318
 
323
- await runUi({ port: 3001, open: false, dev: true });
319
+ await uiCommand({ port: 3001, open: false, dev: true });
324
320
 
325
321
  expect(consoleErrorSpy).toHaveBeenCalledWith(
326
322
  expect.stringContaining('Failed to start Management UI'),
@@ -332,13 +328,16 @@ describe('CLI Command: ui', () => {
332
328
 
333
329
  describe('Process Management', () => {
334
330
  it('should create ProcessManager instance', async () => {
335
- await runUi({ port: 3001, open: false, dev: true });
331
+ await uiCommand({ port: 3001, open: false, dev: true });
336
332
 
337
333
  expect(ProcessManager).toHaveBeenCalled();
338
334
  });
339
335
 
340
336
  it('should keep process running with stdin.resume', async () => {
341
- await runUi({ port: 3001, open: false, dev: true });
337
+ await uiCommand({ port: 3001, open: false, dev: true });
338
+
339
+ // Wait for startup delay (testing async behavior, not mocks)
340
+ await new Promise(resolve => setTimeout(resolve, 2100));
342
341
 
343
342
  // Verify stdin.resume called to keep process alive
344
343
  expect(stdinResumeSpy).toHaveBeenCalled();
@@ -0,0 +1,92 @@
1
+ /**
2
+ * build and deploy validate the app definition first and stop on errors;
3
+ * start validates and only warns (ADR-051).
4
+ */
5
+
6
+ // child_process and node:child_process are one module to jest: one mock.
7
+ const mockChildProcess = {
8
+ spawnSync: jest.fn(() => ({ status: 0 })),
9
+ spawn: jest.fn(),
10
+ };
11
+ jest.mock('child_process', () => mockChildProcess);
12
+ jest.mock('node:child_process', () => mockChildProcess);
13
+ jest.mock('../../../validate-command', () => ({
14
+ preflightValidation: jest.fn(),
15
+ }));
16
+ jest.mock('../../../doctor-command', () => ({ doctorCommand: jest.fn() }));
17
+ jest.mock('../../../utils/database-validator', () => ({
18
+ validateDatabaseUrl: jest.fn(() => ({ valid: true })),
19
+ getDatabaseType: jest.fn(() => ({ dbType: 'postgresql' })),
20
+ checkPrismaClientGenerated: jest.fn(() => ({ generated: true })),
21
+ }));
22
+ jest.mock('dotenv', () => ({ config: jest.fn() }));
23
+
24
+ const childProcess = mockChildProcess;
25
+ const nodeChildProcess = mockChildProcess;
26
+ const { preflightValidation } = require('../../../validate-command');
27
+ const { buildCommand } = require('../../../build-command');
28
+ const { deployCommand } = require('../../../deploy-command');
29
+ const { startCommand } = require('../../../start-command');
30
+
31
+ describe('validation before build, deploy and start', () => {
32
+ beforeEach(() => {
33
+ jest.clearAllMocks();
34
+ jest.spyOn(console, 'log').mockImplementation(() => {});
35
+ jest.spyOn(console, 'warn').mockImplementation(() => {});
36
+ jest.spyOn(console, 'error').mockImplementation(() => {});
37
+ jest.spyOn(process, 'exit').mockImplementation(() => {});
38
+ });
39
+
40
+ afterEach(() => jest.restoreAllMocks());
41
+
42
+ it('build validates first and fails on errors', async () => {
43
+ preflightValidation.mockReturnValue(false);
44
+
45
+ await buildCommand({ stage: 'prod' });
46
+
47
+ expect(preflightValidation).toHaveBeenCalledWith({
48
+ command: 'build',
49
+ options: { stage: 'prod' },
50
+ failOnErrors: true,
51
+ });
52
+ expect(childProcess.spawnSync).not.toHaveBeenCalled();
53
+ });
54
+
55
+ it('build packages after a passing validation', async () => {
56
+ preflightValidation.mockReturnValue(true);
57
+
58
+ await buildCommand({ stage: 'prod' });
59
+
60
+ expect(childProcess.spawnSync).toHaveBeenCalled();
61
+ });
62
+
63
+ it('deploy validates first and fails on errors', async () => {
64
+ preflightValidation.mockReturnValue(false);
65
+
66
+ await deployCommand({ stage: 'prod', skipValidate: false });
67
+
68
+ expect(preflightValidation).toHaveBeenCalledWith({
69
+ command: 'deploy',
70
+ options: { stage: 'prod', skipValidate: false },
71
+ failOnErrors: true,
72
+ });
73
+ expect(childProcess.spawn).not.toHaveBeenCalled();
74
+ });
75
+
76
+ it('start validates and only warns', async () => {
77
+ preflightValidation.mockReturnValue(true);
78
+ nodeChildProcess.spawn.mockReturnValue({ on: jest.fn() });
79
+ const previous = process.env.DATABASE_URL;
80
+ process.env.DATABASE_URL = 'postgresql://localhost/frigg';
81
+
82
+ await startCommand({ stage: 'dev' });
83
+
84
+ process.env.DATABASE_URL = previous;
85
+ expect(preflightValidation).toHaveBeenCalledWith({
86
+ command: 'start',
87
+ options: { stage: 'dev' },
88
+ failOnErrors: false,
89
+ });
90
+ expect(nodeChildProcess.spawn).toHaveBeenCalled();
91
+ });
92
+ });
@@ -51,12 +51,8 @@ describe('frigg-cli dependencies', () => {
51
51
  expect(packageJson.dependencies.commander).toBeDefined();
52
52
  });
53
53
 
54
- // frigg-cli ships inside @friggframework/devtools (14236100), so
55
- // devtools is a peer, not a runtime dependency — a hard dependency
56
- // would make the package depend on itself.
57
- it('should declare @friggframework/devtools as a peer dependency for infrastructure', () => {
58
- expect(packageJson.peerDependencies['@friggframework/devtools']).toBeDefined();
59
- expect(packageJson.dependencies['@friggframework/devtools']).toBeUndefined();
54
+ it('should have @friggframework/devtools for infrastructure', () => {
55
+ expect(packageJson.dependencies['@friggframework/devtools']).toBeDefined();
60
56
  });
61
57
  });
62
58
 
@@ -1,9 +1,15 @@
1
1
  const { spawnSync } = require('child_process');
2
2
  const path = require('path');
3
+ const { preflightValidation } = require('../validate-command');
3
4
 
4
5
  async function buildCommand(options) {
5
6
  console.log('Building the serverless application...');
6
7
 
8
+ // Validate the app definition first (ADR-051); errors stop the build.
9
+ if (!preflightValidation({ command: 'build', options, failOnErrors: true })) {
10
+ return;
11
+ }
12
+
7
13
  // Suppress AWS SDK warning message about maintenance mode
8
14
  process.env.AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE = '1';
9
15
 
@@ -4,6 +4,7 @@ const fs = require('fs');
4
4
 
5
5
  // Import doctor command for post-deployment health check
6
6
  const { doctorCommand } = require('../doctor-command');
7
+ const { preflightValidation } = require('../validate-command');
7
8
 
8
9
  // Configuration constants
9
10
  const PATHS = {
@@ -312,6 +313,11 @@ async function pushOffloadedParametersOrAbort(appDefinition, options) {
312
313
  async function deployCommand(options) {
313
314
  console.log('Deploying the serverless application...');
314
315
 
316
+ // Validate the app definition first (ADR-051); errors stop the deploy.
317
+ if (!preflightValidation({ command: 'deploy', options, failOnErrors: true })) {
318
+ return;
319
+ }
320
+
315
321
  const appDefinition = loadAppDefinition();
316
322
  const environment = validateAndBuildEnvironment(appDefinition, options);
317
323
 
@@ -118,7 +118,6 @@ async function generateCommand(options = {}) {
118
118
  if (options.format === 'cloudformation') {
119
119
  template = await generateCloudFormationTemplate({
120
120
  appName,
121
- serviceName: appDefinition.name || 'create-frigg-app',
122
121
  features,
123
122
  userPrefix: options.user || 'frigg-deployment-user',
124
123
  stackName: options.stackName || 'frigg-deployment-iam',
@@ -62,7 +62,6 @@ async function generateIamCommand(options = {}) {
62
62
  // Use the summary already extracted above (line 44)
63
63
  const cloudFormationYaml = generateIAMCloudFormation({
64
64
  appName: summary.appName,
65
- serviceName: summary.serviceName,
66
65
  features: summary.features,
67
66
  userPrefix: deploymentUserName,
68
67
  stackName,
@@ -87,20 +87,16 @@ const { doctorCommand } = require('./doctor-command');
87
87
  const { repairCommand } = require('./repair-command');
88
88
  const { authCommand } = require('./auth-command');
89
89
  const { ssmPushCommand } = require('./ssm-command');
90
+ const { validateCommand } = require('./validate-command');
90
91
 
91
92
  const program = new Command();
92
93
 
93
94
  program
94
- .command('init [projectName]')
95
+ .command('init [templateName]')
95
96
  .description('Initialize a new Frigg application')
96
- .option('-n, --name <name>', 'project name (alternative to the positional argument)')
97
- .option('-m, --mode <mode>', 'deployment mode: standalone or embedded')
98
- .option('-y, --yes', 'accept the default for every prompt (implied when stdin is not a TTY)')
99
- .option('--no-install', 'skip installing dependencies')
100
- .option('--no-git', 'skip initializing a git repository')
101
- .option('-f, --force', 'scaffold into a non-empty directory and overwrite README.md')
102
- .option('-v, --verbose', 'enable verbose output')
103
- .option('-t, --template <template>', 'legacy template (no longer supported)')
97
+ .option('-t, --template <template>', 'template to use', 'backend-only')
98
+ .option('-n, --name <name>', 'project name')
99
+ .option('-d, --directory <directory>', 'target directory')
104
100
  .action(initCommand);
105
101
 
106
102
  program
@@ -113,14 +109,30 @@ program
113
109
  .description('Run the backend and optional frontend')
114
110
  .option('-s, --stage <stage>', 'deployment stage', 'dev')
115
111
  .option('-v, --verbose', 'enable verbose output')
112
+ .option('--skip-validate', 'skip app definition validation')
116
113
  .action(startCommand);
117
114
 
115
+ program
116
+ .command('validate [target]')
117
+ .description(
118
+ 'Validate the app definition (index.js), or an API module Definition with --module / module'
119
+ )
120
+ .option(
121
+ '--module',
122
+ 'validate an API module Definition in the current directory (also: frigg validate module)'
123
+ )
124
+ .option('-s, --stage <stage>', 'also run the checks for this stage (encryption, deploy-time environment)')
125
+ .option('--json', 'print the report as JSON')
126
+ .option('-v, --verbose', 'enable verbose output')
127
+ .action((target, options) => validateCommand({ ...options, target }));
128
+
118
129
  program
119
130
  .command('build')
120
131
  .description('Build the serverless application')
121
132
  .option('-s, --stage <stage>', 'deployment stage', 'dev')
122
133
  .option('-v, --verbose', 'enable verbose output')
123
134
  .option('-p, --production', 'build for production (enables AWS discovery)')
135
+ .option('--skip-validate', 'skip app definition validation (not recommended)')
124
136
  .action(buildCommand);
125
137
 
126
138
  program
@@ -130,6 +142,7 @@ program
130
142
  .option('-v, --verbose', 'enable verbose output')
131
143
  .option('-f, --force', 'force deployment (bypasses caching for layers and functions)')
132
144
  .option('--skip-doctor', 'skip post-deployment health check')
145
+ .option('--skip-validate', 'skip app definition validation (not recommended)')
133
146
  .action(deployCommand);
134
147
 
135
148
  program
@@ -225,4 +238,4 @@ authProgram
225
238
 
226
239
  program.parse(process.argv);
227
240
 
228
- module.exports = { initCommand, installCommand, startCommand, buildCommand, deployCommand, generateIamCommand, uiCommand, dbSetupCommand, doctorCommand, repairCommand, authCommand, ssmPushCommand };
241
+ module.exports = { initCommand, installCommand, startCommand, buildCommand, deployCommand, validateCommand, generateIamCommand, uiCommand, dbSetupCommand, doctorCommand, repairCommand, authCommand, ssmPushCommand };
@@ -0,0 +1,158 @@
1
+ const { Command } = require('commander');
2
+ const { installCommand } = require('./index');
3
+ const { validatePackageExists } = require('./install-command/validate-package');
4
+ const { findNearestBackendPackageJson, validateBackendPath } = require('@friggframework/core');
5
+ const { installPackage } = require('./install-command/install-package');
6
+ const { createIntegrationFile } = require('./install-command/integration-file');
7
+ const { updateBackendJsFile } = require('./install-command/backend-js');
8
+ const { commitChanges } = require('./install-command/commit-changes');
9
+ const { logInfo, logError } = require('./install-command/logger');
10
+
11
+ describe('CLI Command Tests', () => {
12
+ it('should successfully install an API module when all steps complete without errors', async () => {
13
+ const mockApiModuleName = 'testModule';
14
+ const mockPackageName = `@friggframework/api-module-${mockApiModuleName}`;
15
+ const mockBackendPath = '/mock/backend/path';
16
+
17
+ jest.mock('./install-command/validate-package', () => ({
18
+ validatePackageExists: jest.fn().mockResolvedValue(true),
19
+ }));
20
+ jest.mock('./utils/backend-path', () => ({
21
+ findNearestBackendPackageJson: jest
22
+ .fn()
23
+ .mockReturnValue(mockBackendPath),
24
+ validateBackendPath: jest.fn().mockReturnValue(true),
25
+ }));
26
+ jest.mock('./install-command/install-package', () => ({
27
+ installPackage: jest.fn().mockReturnValue(true),
28
+ }));
29
+ jest.mock('./install-command/integration-file', () => ({
30
+ createIntegrationFile: jest.fn().mockReturnValue(true),
31
+ }));
32
+ jest.mock('./install-command/backend-js', () => ({
33
+ updateBackendJsFile: jest.fn().mockReturnValue(true),
34
+ }));
35
+ jest.mock('./install-command/commit-changes', () => ({
36
+ commitChanges: jest.fn().mockReturnValue(true),
37
+ }));
38
+ jest.mock('./install-command/logger', () => ({
39
+ logInfo: jest.fn(),
40
+ logError: jest.fn(),
41
+ }));
42
+
43
+ const program = new Command();
44
+ program
45
+ .command('install <apiModuleName>')
46
+ .description('Install an API module')
47
+ .action(installCommand);
48
+
49
+ await program.parseAsync(['node', 'install', mockApiModuleName]);
50
+
51
+ expect(validatePackageExists).toHaveBeenCalledWith(mockPackageName);
52
+ expect(findNearestBackendPackageJson).toHaveBeenCalled();
53
+ expect(validateBackendPath).toHaveBeenCalledWith(mockBackendPath);
54
+ expect(installPackage).toHaveBeenCalledWith(
55
+ mockBackendPath,
56
+ mockPackageName
57
+ );
58
+ expect(createIntegrationFile).toHaveBeenCalledWith(
59
+ mockBackendPath,
60
+ mockApiModuleName
61
+ );
62
+ expect(updateBackendJsFile).toHaveBeenCalledWith(
63
+ mockBackendPath,
64
+ mockApiModuleName
65
+ );
66
+ expect(commitChanges).toHaveBeenCalledWith(
67
+ mockBackendPath,
68
+ mockApiModuleName
69
+ );
70
+ expect(logInfo).toHaveBeenCalledWith(
71
+ `Successfully installed ${mockPackageName} and updated the project.`
72
+ );
73
+ });
74
+
75
+ it('should log an error and exit with code 1 if the package does not exist', async () => {
76
+ const mockExit = jest
77
+ .spyOn(process, 'exit')
78
+ .mockImplementation(() => {});
79
+ const mockLogError = jest
80
+ .spyOn(require('./install-command/logger'), 'logError')
81
+ .mockImplementation(() => {});
82
+ const mockValidatePackageExists = jest
83
+ .spyOn(
84
+ require('./install-command/validate-package'),
85
+ 'validatePackageExists'
86
+ )
87
+ .mockImplementation(() => {
88
+ throw new Error('Package not found');
89
+ });
90
+
91
+ const program = new Command();
92
+ program
93
+ .command('install <apiModuleName>')
94
+ .description('Install an API module')
95
+ .action(installCommand);
96
+
97
+ await program.parseAsync(['node', 'install', 'nonexistent-package']);
98
+
99
+ expect(mockValidatePackageExists).toHaveBeenCalledWith(
100
+ '@friggframework/api-module-nonexistent-package'
101
+ );
102
+ expect(mockLogError).toHaveBeenCalledWith(
103
+ 'An error occurred:',
104
+ expect.any(Error)
105
+ );
106
+ expect(mockExit).toHaveBeenCalledWith(1);
107
+
108
+ mockExit.mockRestore();
109
+ mockLogError.mockRestore();
110
+ mockValidatePackageExists.mockRestore();
111
+ });
112
+
113
+ it('should log an error and exit with code 1 if the backend path is invalid', async () => {
114
+ const mockLogError = jest
115
+ .spyOn(require('./install-command/logger'), 'logError')
116
+ .mockImplementation(() => {});
117
+ const mockProcessExit = jest
118
+ .spyOn(process, 'exit')
119
+ .mockImplementation(() => {});
120
+ const mockValidatePackageExists = jest
121
+ .spyOn(
122
+ require('./install-command/validate-package'),
123
+ 'validatePackageExists'
124
+ )
125
+ .mockResolvedValue(true);
126
+ const mockFindNearestBackendPackageJson = jest
127
+ .spyOn(
128
+ require('./utils/backend-path'),
129
+ 'findNearestBackendPackageJson'
130
+ )
131
+ .mockReturnValue('/invalid/path');
132
+ const mockValidateBackendPath = jest
133
+ .spyOn(require('./utils/backend-path'), 'validateBackendPath')
134
+ .mockImplementation(() => {
135
+ throw new Error('Invalid backend path');
136
+ });
137
+
138
+ const program = new Command();
139
+ program
140
+ .command('install <apiModuleName>')
141
+ .description('Install an API module')
142
+ .action(installCommand);
143
+
144
+ await program.parseAsync(['node', 'install', 'test-module']);
145
+
146
+ expect(mockLogError).toHaveBeenCalledWith(
147
+ 'An error occurred:',
148
+ expect.any(Error)
149
+ );
150
+ expect(mockProcessExit).toHaveBeenCalledWith(1);
151
+
152
+ mockLogError.mockRestore();
153
+ mockProcessExit.mockRestore();
154
+ mockValidatePackageExists.mockRestore();
155
+ mockFindNearestBackendPackageJson.mockRestore();
156
+ mockValidateBackendPath.mockRestore();
157
+ });
158
+ });