@friggframework/devtools 2.0.0-next.121 → 2.0.0-next.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +30 -24
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
- package/frigg-cli/__tests__/unit/commands/install.test.js +7 -0
- package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
- package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
- package/infrastructure/__tests__/postgres-config.test.js +241 -835
- package/infrastructure/__tests__/template-generation.test.js +36 -8
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
- package/infrastructure/domains/networking/vpc-builder.js +18 -8
- package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
- package/infrastructure/infrastructure-composer.test.js +268 -794
- package/infrastructure/scripts/build-prisma-layer.test.js +28 -7
- package/infrastructure/scripts/build-time-discovery.test.js +18 -3
- package/package.json +7 -7
- package/frigg-cli/index.test.js +0 -158
- package/infrastructure/integration.test.js +0 -381
|
@@ -14,10 +14,18 @@ jest.mock('child_process', () => ({
|
|
|
14
14
|
spawn: jest.fn()
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
+
// Partial mock: only existsSync is stubbed, the rest of fs stays real (a
|
|
18
|
+
// bare { existsSync } mock breaks any dependency that reads fs.constants).
|
|
17
19
|
jest.mock('fs', () => ({
|
|
20
|
+
...jest.requireActual('fs'),
|
|
18
21
|
existsSync: jest.fn()
|
|
19
22
|
}));
|
|
20
23
|
|
|
24
|
+
// The post-deployment health check calls the doctor command (real AWS).
|
|
25
|
+
jest.mock('../../../doctor-command', () => ({
|
|
26
|
+
doctorCommand: jest.fn().mockResolvedValue(undefined)
|
|
27
|
+
}));
|
|
28
|
+
|
|
21
29
|
// Require after mocks
|
|
22
30
|
const { spawn } = require('child_process');
|
|
23
31
|
const fs = require('fs');
|
|
@@ -28,6 +36,8 @@ describe('CLI Command: deploy', () => {
|
|
|
28
36
|
let consoleWarnSpy;
|
|
29
37
|
let consoleErrorSpy;
|
|
30
38
|
let mockChildProcess;
|
|
39
|
+
let childOutcome;
|
|
40
|
+
let exitSpy;
|
|
31
41
|
|
|
32
42
|
beforeEach(() => {
|
|
33
43
|
jest.clearAllMocks();
|
|
@@ -37,10 +47,18 @@ describe('CLI Command: deploy', () => {
|
|
|
37
47
|
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
38
48
|
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
39
49
|
|
|
40
|
-
// Mock child process
|
|
50
|
+
// Mock child process. deployCommand awaits the child's exit, so the mock
|
|
51
|
+
// emits `childOutcome` (default: a clean exit) once its handler is wired.
|
|
52
|
+
childOutcome = { event: 'close', value: 0 };
|
|
41
53
|
mockChildProcess = {
|
|
42
|
-
on: jest.fn()
|
|
54
|
+
on: jest.fn((event, handler) => {
|
|
55
|
+
if (event === childOutcome.event) {
|
|
56
|
+
setImmediate(() => handler(childOutcome.value));
|
|
57
|
+
}
|
|
58
|
+
return mockChildProcess;
|
|
59
|
+
})
|
|
43
60
|
};
|
|
61
|
+
exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});
|
|
44
62
|
|
|
45
63
|
// Mock successful spawn by default
|
|
46
64
|
spawn.mockReturnValue(mockChildProcess);
|
|
@@ -53,6 +71,7 @@ describe('CLI Command: deploy', () => {
|
|
|
53
71
|
consoleLogSpy.mockRestore();
|
|
54
72
|
consoleWarnSpy.mockRestore();
|
|
55
73
|
consoleErrorSpy.mockRestore();
|
|
74
|
+
exitSpy.mockRestore();
|
|
56
75
|
});
|
|
57
76
|
|
|
58
77
|
describe('Success Cases', () => {
|
|
@@ -278,43 +297,30 @@ describe('CLI Command: deploy', () => {
|
|
|
278
297
|
});
|
|
279
298
|
|
|
280
299
|
describe('Error Handling', () => {
|
|
281
|
-
it('should log
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
await deployCommand({ stage: 'dev' });
|
|
300
|
+
it('should log and reject when spawn fails', async () => {
|
|
301
|
+
childOutcome = { event: 'error', value: new Error('Spawn failed') };
|
|
285
302
|
|
|
286
|
-
|
|
287
|
-
const errorHandler = mockChildProcess.on.mock.calls.find(
|
|
288
|
-
call => call[0] === 'error'
|
|
289
|
-
)[1];
|
|
290
|
-
errorHandler(testError);
|
|
303
|
+
await expect(deployCommand({ stage: 'dev' })).rejects.toThrow('Spawn failed');
|
|
291
304
|
|
|
292
305
|
expect(consoleErrorSpy).toHaveBeenCalledWith('Error executing command: Spawn failed');
|
|
293
306
|
});
|
|
294
307
|
|
|
295
|
-
it('should log when child process exits
|
|
296
|
-
|
|
308
|
+
it('should log and exit with the code when child process exits non-zero', async () => {
|
|
309
|
+
childOutcome = { event: 'close', value: 1 };
|
|
297
310
|
|
|
298
|
-
|
|
299
|
-
const closeHandler = mockChildProcess.on.mock.calls.find(
|
|
300
|
-
call => call[0] === 'close'
|
|
301
|
-
)[1];
|
|
302
|
-
closeHandler(1);
|
|
311
|
+
await deployCommand({ stage: 'dev' });
|
|
303
312
|
|
|
304
313
|
expect(consoleLogSpy).toHaveBeenCalledWith('Child process exited with code 1');
|
|
314
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
305
315
|
});
|
|
306
316
|
|
|
307
317
|
it('should NOT log when child process exits with zero code', async () => {
|
|
308
318
|
await deployCommand({ stage: 'dev' });
|
|
309
319
|
|
|
310
|
-
// Simulate close event with success code
|
|
311
|
-
const closeHandler = mockChildProcess.on.mock.calls.find(
|
|
312
|
-
call => call[0] === 'close'
|
|
313
|
-
)[1];
|
|
314
|
-
closeHandler(0);
|
|
315
|
-
|
|
316
320
|
// Should not log exit message for success
|
|
317
321
|
expect(consoleLogSpy).not.toHaveBeenCalledWith('Child process exited with code 0');
|
|
322
|
+
expect(exitSpy).not.toHaveBeenCalled();
|
|
323
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('\n✓ Deployment completed successfully!');
|
|
318
324
|
});
|
|
319
325
|
});
|
|
320
326
|
});
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* Tests stack listing, selection, and health check orchestration
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// `jest` is the injected global: destructuring it from @jest/globals collides
|
|
7
|
+
// with the binding babel-plugin-jest-hoist (Jest 30) injects into the module.
|
|
8
|
+
const { describe, test, expect, beforeEach } = require('@jest/globals');
|
|
7
9
|
|
|
8
10
|
describe('Doctor Command - Stack Listing and Selection', () => {
|
|
9
11
|
let mockCloudFormationClient;
|
|
@@ -138,25 +140,27 @@ describe('Doctor Command - Stack Listing and Selection', () => {
|
|
|
138
140
|
{
|
|
139
141
|
name: 'production-stack',
|
|
140
142
|
status: 'UPDATE_COMPLETE',
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
// Local-time dates: an ISO date string is UTC midnight,
|
|
144
|
+
// which renders as the previous day west of UTC.
|
|
145
|
+
createdTime: new Date(2024, 0, 15),
|
|
146
|
+
updatedTime: new Date(2024, 9, 20),
|
|
143
147
|
},
|
|
144
148
|
{
|
|
145
149
|
name: 'dev-stack',
|
|
146
150
|
status: 'CREATE_COMPLETE',
|
|
147
|
-
createdTime: new Date(
|
|
151
|
+
createdTime: new Date(2024, 9, 1),
|
|
148
152
|
updatedTime: null,
|
|
149
153
|
},
|
|
150
154
|
];
|
|
151
155
|
|
|
152
156
|
const expectedChoices = [
|
|
153
157
|
{
|
|
154
|
-
name:
|
|
158
|
+
name: `✓ production-stack (UPDATE_COMPLETE) - Updated: ${mockStacks[0].updatedTime.toLocaleDateString()}`,
|
|
155
159
|
value: 'production-stack',
|
|
156
160
|
description: 'Status: UPDATE_COMPLETE',
|
|
157
161
|
},
|
|
158
162
|
{
|
|
159
|
-
name:
|
|
163
|
+
name: `✓ dev-stack (CREATE_COMPLETE) - Created: ${mockStacks[1].createdTime.toLocaleDateString()}`,
|
|
160
164
|
value: 'dev-stack',
|
|
161
165
|
description: 'Status: CREATE_COMPLETE',
|
|
162
166
|
},
|
|
@@ -621,6 +621,13 @@ describe('commitChanges', () => {
|
|
|
621
621
|
it('commits only the given files and leaves other staged changes alone', () => {
|
|
622
622
|
const dir = makeTmpDir();
|
|
623
623
|
git(['init', '-q'], dir);
|
|
624
|
+
// commitChanges spawns git without an explicit env, so it sees the
|
|
625
|
+
// real process environment, not Jest's sandboxed process.env: the
|
|
626
|
+
// GIT_* identity set above never reaches it. Give the repo its own
|
|
627
|
+
// identity so the commit works on CI runners with no git user.
|
|
628
|
+
git(['config', 'user.name', 'Test'], dir);
|
|
629
|
+
git(['config', 'user.email', 'test@example.com'], dir);
|
|
630
|
+
git(['config', 'commit.gpgsign', 'false'], dir);
|
|
624
631
|
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
|
625
632
|
fs.writeFileSync(path.join(dir, 'unrelated.txt'), 'wip');
|
|
626
633
|
git(['add', 'unrelated.txt'], dir);
|
|
@@ -33,6 +33,17 @@ 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
|
+
|
|
36
47
|
describe('CLI Command: ui', () => {
|
|
37
48
|
let consoleLogSpy;
|
|
38
49
|
let consoleErrorSpy;
|
|
@@ -43,6 +54,7 @@ describe('CLI Command: ui', () => {
|
|
|
43
54
|
|
|
44
55
|
beforeEach(() => {
|
|
45
56
|
jest.clearAllMocks();
|
|
57
|
+
jest.useFakeTimers();
|
|
46
58
|
|
|
47
59
|
// Mock console methods
|
|
48
60
|
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
@@ -75,6 +87,7 @@ describe('CLI Command: ui', () => {
|
|
|
75
87
|
});
|
|
76
88
|
|
|
77
89
|
afterEach(() => {
|
|
90
|
+
jest.useRealTimers();
|
|
78
91
|
consoleLogSpy.mockRestore();
|
|
79
92
|
consoleErrorSpy.mockRestore();
|
|
80
93
|
processExitSpy.mockRestore();
|
|
@@ -84,7 +97,7 @@ describe('CLI Command: ui', () => {
|
|
|
84
97
|
|
|
85
98
|
describe('Repository Detection', () => {
|
|
86
99
|
it('should use specified repo path when provided', async () => {
|
|
87
|
-
await
|
|
100
|
+
await runUi({ repo: '/custom/repo', port: 3001, open: false });
|
|
88
101
|
|
|
89
102
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
90
103
|
expect.stringContaining('Using specified repository')
|
|
@@ -92,7 +105,7 @@ describe('CLI Command: ui', () => {
|
|
|
92
105
|
});
|
|
93
106
|
|
|
94
107
|
it('should detect current Frigg repository', async () => {
|
|
95
|
-
await
|
|
108
|
+
await runUi({ port: 3001, open: false });
|
|
96
109
|
|
|
97
110
|
expect(getCurrentRepositoryInfo).toHaveBeenCalled();
|
|
98
111
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
@@ -107,7 +120,7 @@ describe('CLI Command: ui', () => {
|
|
|
107
120
|
currentSubPath: 'packages/backend'
|
|
108
121
|
});
|
|
109
122
|
|
|
110
|
-
await
|
|
123
|
+
await runUi({ port: 3001, open: false });
|
|
111
124
|
|
|
112
125
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
113
126
|
expect.stringContaining('Currently in subdirectory: packages/backend')
|
|
@@ -121,7 +134,7 @@ describe('CLI Command: ui', () => {
|
|
|
121
134
|
{ path: '/repos/frigg-2', name: 'frigg-2' }
|
|
122
135
|
]);
|
|
123
136
|
|
|
124
|
-
await
|
|
137
|
+
await runUi({ port: 3001, open: false });
|
|
125
138
|
|
|
126
139
|
expect(discoverFriggRepositories).toHaveBeenCalled();
|
|
127
140
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
@@ -133,7 +146,7 @@ describe('CLI Command: ui', () => {
|
|
|
133
146
|
getCurrentRepositoryInfo.mockResolvedValue(null);
|
|
134
147
|
discoverFriggRepositories.mockResolvedValue([]);
|
|
135
148
|
|
|
136
|
-
await
|
|
149
|
+
await runUi({ port: 3001, open: false });
|
|
137
150
|
|
|
138
151
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
139
152
|
expect.stringContaining('No Frigg repositories found')
|
|
@@ -144,7 +157,7 @@ describe('CLI Command: ui', () => {
|
|
|
144
157
|
|
|
145
158
|
describe('Development Mode', () => {
|
|
146
159
|
it('should spawn backend and frontend in dev mode', async () => {
|
|
147
|
-
await
|
|
160
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
148
161
|
|
|
149
162
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledTimes(2);
|
|
150
163
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
|
|
@@ -168,7 +181,7 @@ describe('CLI Command: ui', () => {
|
|
|
168
181
|
});
|
|
169
182
|
|
|
170
183
|
it('should use default port 3001', async () => {
|
|
171
|
-
await
|
|
184
|
+
await runUi({ open: false, dev: true });
|
|
172
185
|
|
|
173
186
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
|
|
174
187
|
expect.any(String),
|
|
@@ -181,7 +194,7 @@ describe('CLI Command: ui', () => {
|
|
|
181
194
|
});
|
|
182
195
|
|
|
183
196
|
it('should use custom port when specified', async () => {
|
|
184
|
-
await
|
|
197
|
+
await runUi({ port: 4000, open: false, dev: true });
|
|
185
198
|
|
|
186
199
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
|
|
187
200
|
expect.any(String),
|
|
@@ -197,10 +210,7 @@ describe('CLI Command: ui', () => {
|
|
|
197
210
|
});
|
|
198
211
|
|
|
199
212
|
it('should print status with correct URLs', async () => {
|
|
200
|
-
await
|
|
201
|
-
|
|
202
|
-
// Wait for startup delay (testing async behavior, not mocks)
|
|
203
|
-
await new Promise(resolve => setTimeout(resolve, 2100));
|
|
213
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
204
214
|
|
|
205
215
|
// Verify printStatus called with exact URLs
|
|
206
216
|
expect(mockProcessManager.printStatus).toHaveBeenCalledWith(
|
|
@@ -211,20 +221,14 @@ describe('CLI Command: ui', () => {
|
|
|
211
221
|
});
|
|
212
222
|
|
|
213
223
|
it('should open browser when open=true', async () => {
|
|
214
|
-
await
|
|
215
|
-
|
|
216
|
-
// Wait for startup + browser delay (testing async behavior, not mocks)
|
|
217
|
-
await new Promise(resolve => setTimeout(resolve, 3100));
|
|
224
|
+
await runUi({ port: 3001, open: true, dev: true });
|
|
218
225
|
|
|
219
226
|
// Verify browser opened with correct URL
|
|
220
227
|
expect(open).toHaveBeenCalledWith('http://localhost:5173');
|
|
221
228
|
});
|
|
222
229
|
|
|
223
230
|
it('should NOT open browser when open=false', async () => {
|
|
224
|
-
await
|
|
225
|
-
|
|
226
|
-
// Wait for startup delay (testing async behavior, not mocks)
|
|
227
|
-
await new Promise(resolve => setTimeout(resolve, 3100));
|
|
231
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
228
232
|
|
|
229
233
|
// Verify browser was not opened
|
|
230
234
|
expect(open).not.toHaveBeenCalled();
|
|
@@ -237,7 +241,7 @@ describe('CLI Command: ui', () => {
|
|
|
237
241
|
currentSubPath: null
|
|
238
242
|
});
|
|
239
243
|
|
|
240
|
-
await
|
|
244
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
241
245
|
|
|
242
246
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
|
|
243
247
|
expect.any(String),
|
|
@@ -252,7 +256,7 @@ describe('CLI Command: ui', () => {
|
|
|
252
256
|
});
|
|
253
257
|
|
|
254
258
|
it('should set REPOSITORY_INFO as JSON string with correct structure', async () => {
|
|
255
|
-
await
|
|
259
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
256
260
|
|
|
257
261
|
const call = mockProcessManager.spawnProcess.mock.calls[0];
|
|
258
262
|
const env = call[3].env;
|
|
@@ -275,7 +279,7 @@ describe('CLI Command: ui', () => {
|
|
|
275
279
|
{ path: '/repos/frigg-1', name: 'frigg-1' }
|
|
276
280
|
]);
|
|
277
281
|
|
|
278
|
-
await
|
|
282
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
279
283
|
|
|
280
284
|
const call = mockProcessManager.spawnProcess.mock.calls[0];
|
|
281
285
|
const env = call[3].env;
|
|
@@ -299,7 +303,7 @@ describe('CLI Command: ui', () => {
|
|
|
299
303
|
throw error;
|
|
300
304
|
});
|
|
301
305
|
|
|
302
|
-
await
|
|
306
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
303
307
|
|
|
304
308
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
305
309
|
expect.stringContaining('Failed to start Management UI'),
|
|
@@ -316,7 +320,7 @@ describe('CLI Command: ui', () => {
|
|
|
316
320
|
throw new Error('Generic startup error');
|
|
317
321
|
});
|
|
318
322
|
|
|
319
|
-
await
|
|
323
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
320
324
|
|
|
321
325
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
322
326
|
expect.stringContaining('Failed to start Management UI'),
|
|
@@ -328,16 +332,13 @@ describe('CLI Command: ui', () => {
|
|
|
328
332
|
|
|
329
333
|
describe('Process Management', () => {
|
|
330
334
|
it('should create ProcessManager instance', async () => {
|
|
331
|
-
await
|
|
335
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
332
336
|
|
|
333
337
|
expect(ProcessManager).toHaveBeenCalled();
|
|
334
338
|
});
|
|
335
339
|
|
|
336
340
|
it('should keep process running with stdin.resume', async () => {
|
|
337
|
-
await
|
|
338
|
-
|
|
339
|
-
// Wait for startup delay (testing async behavior, not mocks)
|
|
340
|
-
await new Promise(resolve => setTimeout(resolve, 2100));
|
|
341
|
+
await runUi({ port: 3001, open: false, dev: true });
|
|
341
342
|
|
|
342
343
|
// Verify stdin.resume called to keep process alive
|
|
343
344
|
expect(stdinResumeSpy).toHaveBeenCalled();
|
|
@@ -51,8 +51,12 @@ describe('frigg-cli dependencies', () => {
|
|
|
51
51
|
expect(packageJson.dependencies.commander).toBeDefined();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
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();
|
|
56
60
|
});
|
|
57
61
|
});
|
|
58
62
|
|