@friggframework/devtools 2.0.0--canary.461.b5b70c5.0 → 2.0.0--canary.461.4da5172.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.
- package/frigg-cli/__tests__/unit/commands/build.test.js +28 -0
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +281 -0
- package/frigg-cli/build-command/index.js +1 -0
- package/frigg-cli/deploy-command/index.js +4 -1
- package/infrastructure/domains/shared/resource-discovery.test.js +23 -0
- package/package.json +6 -6
|
@@ -157,6 +157,34 @@ describe('CLI Command: build', () => {
|
|
|
157
157
|
delete process.env.TEST_VAR;
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
+
it('should set SLS_STAGE environment variable to match stage option', async () => {
|
|
161
|
+
await buildCommand({ stage: 'qa' });
|
|
162
|
+
|
|
163
|
+
const call = spawnSync.mock.calls[0];
|
|
164
|
+
const options = call[2];
|
|
165
|
+
|
|
166
|
+
// Verify SLS_STAGE is set for discovery to use
|
|
167
|
+
expect(options.env.SLS_STAGE).toBe('qa');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should set SLS_STAGE for production stage', async () => {
|
|
171
|
+
await buildCommand({ stage: 'production' });
|
|
172
|
+
|
|
173
|
+
const call = spawnSync.mock.calls[0];
|
|
174
|
+
const options = call[2];
|
|
175
|
+
|
|
176
|
+
expect(options.env.SLS_STAGE).toBe('production');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('should set SLS_STAGE for dev stage', async () => {
|
|
180
|
+
await buildCommand({ stage: 'dev' });
|
|
181
|
+
|
|
182
|
+
const call = spawnSync.mock.calls[0];
|
|
183
|
+
const options = call[2];
|
|
184
|
+
|
|
185
|
+
expect(options.env.SLS_STAGE).toBe('dev');
|
|
186
|
+
});
|
|
187
|
+
|
|
160
188
|
it('should use infrastructure.js as config file', async () => {
|
|
161
189
|
await buildCommand({ stage: 'dev' });
|
|
162
190
|
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test suite for deploy command
|
|
3
|
+
*
|
|
4
|
+
* Tests the serverless deployment functionality including:
|
|
5
|
+
* - Command execution with spawn
|
|
6
|
+
* - Stage option handling
|
|
7
|
+
* - Environment variable filtering and propagation
|
|
8
|
+
* - SLS_STAGE propagation for resource discovery
|
|
9
|
+
* - Error handling
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Mock dependencies BEFORE requiring modules
|
|
13
|
+
jest.mock('child_process', () => ({
|
|
14
|
+
spawn: jest.fn()
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock('fs', () => ({
|
|
18
|
+
existsSync: jest.fn()
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
// Require after mocks
|
|
22
|
+
const { spawn } = require('child_process');
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const { deployCommand } = require('../../../deploy-command');
|
|
25
|
+
|
|
26
|
+
describe('CLI Command: deploy', () => {
|
|
27
|
+
let consoleLogSpy;
|
|
28
|
+
let consoleWarnSpy;
|
|
29
|
+
let consoleErrorSpy;
|
|
30
|
+
let mockChildProcess;
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
jest.clearAllMocks();
|
|
34
|
+
|
|
35
|
+
// Mock console methods
|
|
36
|
+
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
37
|
+
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
38
|
+
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
39
|
+
|
|
40
|
+
// Mock child process
|
|
41
|
+
mockChildProcess = {
|
|
42
|
+
on: jest.fn()
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Mock successful spawn by default
|
|
46
|
+
spawn.mockReturnValue(mockChildProcess);
|
|
47
|
+
|
|
48
|
+
// Mock fs.existsSync to return false (no app definition)
|
|
49
|
+
fs.existsSync.mockReturnValue(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
consoleLogSpy.mockRestore();
|
|
54
|
+
consoleWarnSpy.mockRestore();
|
|
55
|
+
consoleErrorSpy.mockRestore();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('Success Cases', () => {
|
|
59
|
+
it('should spawn serverless with default stage', async () => {
|
|
60
|
+
await deployCommand({ stage: 'dev' });
|
|
61
|
+
|
|
62
|
+
expect(spawn).toHaveBeenCalledWith(
|
|
63
|
+
'osls',
|
|
64
|
+
['deploy', '--config', 'infrastructure.js', '--stage', 'dev'],
|
|
65
|
+
expect.objectContaining({
|
|
66
|
+
cwd: expect.any(String),
|
|
67
|
+
stdio: 'inherit'
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should spawn serverless with production stage', async () => {
|
|
73
|
+
await deployCommand({ stage: 'production' });
|
|
74
|
+
|
|
75
|
+
expect(spawn).toHaveBeenCalledWith(
|
|
76
|
+
'osls',
|
|
77
|
+
expect.arrayContaining(['--stage', 'production']),
|
|
78
|
+
expect.any(Object)
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should spawn serverless with qa stage', async () => {
|
|
83
|
+
await deployCommand({ stage: 'qa' });
|
|
84
|
+
|
|
85
|
+
expect(spawn).toHaveBeenCalledWith(
|
|
86
|
+
'osls',
|
|
87
|
+
expect.arrayContaining(['--stage', 'qa']),
|
|
88
|
+
expect.any(Object)
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should use process.cwd() as working directory', async () => {
|
|
93
|
+
await deployCommand({ stage: 'dev' });
|
|
94
|
+
|
|
95
|
+
const call = spawn.mock.calls[0];
|
|
96
|
+
const options = call[2];
|
|
97
|
+
|
|
98
|
+
expect(options.cwd).toBe(process.cwd());
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should use stdio inherit for output streaming', async () => {
|
|
102
|
+
await deployCommand({ stage: 'dev' });
|
|
103
|
+
|
|
104
|
+
const call = spawn.mock.calls[0];
|
|
105
|
+
const options = call[2];
|
|
106
|
+
|
|
107
|
+
expect(options.stdio).toBe('inherit');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should set SLS_STAGE environment variable to match stage option', async () => {
|
|
111
|
+
await deployCommand({ stage: 'qa' });
|
|
112
|
+
|
|
113
|
+
const call = spawn.mock.calls[0];
|
|
114
|
+
const options = call[2];
|
|
115
|
+
|
|
116
|
+
// Verify SLS_STAGE is set for discovery to use
|
|
117
|
+
expect(options.env.SLS_STAGE).toBe('qa');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should set SLS_STAGE for production stage', async () => {
|
|
121
|
+
await deployCommand({ stage: 'production' });
|
|
122
|
+
|
|
123
|
+
const call = spawn.mock.calls[0];
|
|
124
|
+
const options = call[2];
|
|
125
|
+
|
|
126
|
+
expect(options.env.SLS_STAGE).toBe('production');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should set SLS_STAGE for dev stage', async () => {
|
|
130
|
+
await deployCommand({ stage: 'dev' });
|
|
131
|
+
|
|
132
|
+
const call = spawn.mock.calls[0];
|
|
133
|
+
const options = call[2];
|
|
134
|
+
|
|
135
|
+
expect(options.env.SLS_STAGE).toBe('dev');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should use infrastructure.js as config file', async () => {
|
|
139
|
+
await deployCommand({ stage: 'dev' });
|
|
140
|
+
|
|
141
|
+
expect(spawn).toHaveBeenCalledWith(
|
|
142
|
+
'osls',
|
|
143
|
+
expect.arrayContaining(['--config', 'infrastructure.js']),
|
|
144
|
+
expect.any(Object)
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should log deployment start messages', async () => {
|
|
149
|
+
await deployCommand({ stage: 'dev' });
|
|
150
|
+
|
|
151
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('Deploying the serverless application...');
|
|
152
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('🚀 Deploying serverless application...');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should include essential system environment variables', async () => {
|
|
156
|
+
process.env.PATH = '/usr/bin';
|
|
157
|
+
process.env.HOME = '/home/user';
|
|
158
|
+
process.env.USER = 'testuser';
|
|
159
|
+
|
|
160
|
+
await deployCommand({ stage: 'dev' });
|
|
161
|
+
|
|
162
|
+
const call = spawn.mock.calls[0];
|
|
163
|
+
const options = call[2];
|
|
164
|
+
|
|
165
|
+
expect(options.env.PATH).toBe('/usr/bin');
|
|
166
|
+
expect(options.env.HOME).toBe('/home/user');
|
|
167
|
+
expect(options.env.USER).toBe('testuser');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should include AWS environment variables', async () => {
|
|
171
|
+
process.env.AWS_REGION = 'us-east-1';
|
|
172
|
+
process.env.AWS_PROFILE = 'test-profile';
|
|
173
|
+
process.env.AWS_ACCESS_KEY_ID = 'test-key';
|
|
174
|
+
|
|
175
|
+
await deployCommand({ stage: 'dev' });
|
|
176
|
+
|
|
177
|
+
const call = spawn.mock.calls[0];
|
|
178
|
+
const options = call[2];
|
|
179
|
+
|
|
180
|
+
expect(options.env.AWS_REGION).toBe('us-east-1');
|
|
181
|
+
expect(options.env.AWS_PROFILE).toBe('test-profile');
|
|
182
|
+
expect(options.env.AWS_ACCESS_KEY_ID).toBe('test-key');
|
|
183
|
+
|
|
184
|
+
delete process.env.AWS_REGION;
|
|
185
|
+
delete process.env.AWS_PROFILE;
|
|
186
|
+
delete process.env.AWS_ACCESS_KEY_ID;
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('should register error handler', async () => {
|
|
190
|
+
await deployCommand({ stage: 'dev' });
|
|
191
|
+
|
|
192
|
+
expect(mockChildProcess.on).toHaveBeenCalledWith('error', expect.any(Function));
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('should register close handler', async () => {
|
|
196
|
+
await deployCommand({ stage: 'dev' });
|
|
197
|
+
|
|
198
|
+
expect(mockChildProcess.on).toHaveBeenCalledWith('close', expect.any(Function));
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe('Environment Variable Filtering', () => {
|
|
203
|
+
it('should filter environment variables when app definition exists', async () => {
|
|
204
|
+
// Mock app definition with environment config
|
|
205
|
+
fs.existsSync.mockReturnValue(true);
|
|
206
|
+
jest.mock(
|
|
207
|
+
process.cwd() + '/index.js',
|
|
208
|
+
() => ({
|
|
209
|
+
Definition: {
|
|
210
|
+
environment: {
|
|
211
|
+
DATABASE_URL: true,
|
|
212
|
+
API_KEY: true
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}),
|
|
216
|
+
{ virtual: true }
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
process.env.DATABASE_URL = 'postgres://localhost';
|
|
220
|
+
process.env.API_KEY = 'test-key';
|
|
221
|
+
process.env.RANDOM_VAR = 'should-not-be-included';
|
|
222
|
+
|
|
223
|
+
await deployCommand({ stage: 'dev' });
|
|
224
|
+
|
|
225
|
+
const call = spawn.mock.calls[0];
|
|
226
|
+
const options = call[2];
|
|
227
|
+
|
|
228
|
+
// Should include app-defined variables
|
|
229
|
+
expect(options.env.DATABASE_URL).toBe('postgres://localhost');
|
|
230
|
+
expect(options.env.API_KEY).toBe('test-key');
|
|
231
|
+
|
|
232
|
+
// Should NOT include non-app-defined variables (except system/AWS)
|
|
233
|
+
expect(options.env.RANDOM_VAR).toBeUndefined();
|
|
234
|
+
|
|
235
|
+
delete process.env.DATABASE_URL;
|
|
236
|
+
delete process.env.API_KEY;
|
|
237
|
+
delete process.env.RANDOM_VAR;
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('Error Handling', () => {
|
|
242
|
+
it('should log error when spawn fails', async () => {
|
|
243
|
+
const testError = new Error('Spawn failed');
|
|
244
|
+
|
|
245
|
+
await deployCommand({ stage: 'dev' });
|
|
246
|
+
|
|
247
|
+
// Simulate error event
|
|
248
|
+
const errorHandler = mockChildProcess.on.mock.calls.find(
|
|
249
|
+
call => call[0] === 'error'
|
|
250
|
+
)[1];
|
|
251
|
+
errorHandler(testError);
|
|
252
|
+
|
|
253
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('Error executing command: Spawn failed');
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('should log when child process exits with non-zero code', async () => {
|
|
257
|
+
await deployCommand({ stage: 'dev' });
|
|
258
|
+
|
|
259
|
+
// Simulate close event with error code
|
|
260
|
+
const closeHandler = mockChildProcess.on.mock.calls.find(
|
|
261
|
+
call => call[0] === 'close'
|
|
262
|
+
)[1];
|
|
263
|
+
closeHandler(1);
|
|
264
|
+
|
|
265
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('Child process exited with code 1');
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('should NOT log when child process exits with zero code', async () => {
|
|
269
|
+
await deployCommand({ stage: 'dev' });
|
|
270
|
+
|
|
271
|
+
// Simulate close event with success code
|
|
272
|
+
const closeHandler = mockChildProcess.on.mock.calls.find(
|
|
273
|
+
call => call[0] === 'close'
|
|
274
|
+
)[1];
|
|
275
|
+
closeHandler(0);
|
|
276
|
+
|
|
277
|
+
// Should not log exit message for success
|
|
278
|
+
expect(consoleLogSpy).not.toHaveBeenCalledWith('Child process exited with code 0');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
});
|
|
@@ -149,7 +149,10 @@ function executeServerlessDeployment(environment, options) {
|
|
|
149
149
|
const childProcess = spawn(COMMANDS.SERVERLESS, serverlessArgs, {
|
|
150
150
|
cwd: path.resolve(process.cwd()),
|
|
151
151
|
stdio: 'inherit',
|
|
152
|
-
env:
|
|
152
|
+
env: {
|
|
153
|
+
...environment,
|
|
154
|
+
SLS_STAGE: options.stage, // Set stage for resource discovery
|
|
155
|
+
},
|
|
153
156
|
});
|
|
154
157
|
|
|
155
158
|
childProcess.on('error', (error) => {
|
|
@@ -392,6 +392,29 @@ describe('Resource Discovery', () => {
|
|
|
392
392
|
);
|
|
393
393
|
});
|
|
394
394
|
|
|
395
|
+
it('should read stage from SLS_STAGE environment variable for CLI integration', async () => {
|
|
396
|
+
// This test documents the contract between frigg CLI and discovery
|
|
397
|
+
// The CLI sets SLS_STAGE environment variable when user passes --stage flag
|
|
398
|
+
process.env.SLS_STAGE = 'qa';
|
|
399
|
+
|
|
400
|
+
const appDefinition = {
|
|
401
|
+
name: 'quo-integrations',
|
|
402
|
+
vpc: { enable: true },
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
await gatherDiscoveredResources(appDefinition);
|
|
406
|
+
|
|
407
|
+
// Verify stage is read from SLS_STAGE
|
|
408
|
+
expect(mockVpcDiscovery.discover).toHaveBeenCalledWith(
|
|
409
|
+
expect.objectContaining({
|
|
410
|
+
serviceName: 'quo-integrations',
|
|
411
|
+
stage: 'qa',
|
|
412
|
+
})
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
delete process.env.SLS_STAGE;
|
|
416
|
+
});
|
|
417
|
+
|
|
395
418
|
it('should include secrets in SSM discovery by default', async () => {
|
|
396
419
|
const appDefinition = {
|
|
397
420
|
ssm: { enable: true },
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/devtools",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.461.
|
|
4
|
+
"version": "2.0.0--canary.461.4da5172.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-ec2": "^3.835.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.835.0",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"@babel/eslint-parser": "^7.18.9",
|
|
12
12
|
"@babel/parser": "^7.25.3",
|
|
13
13
|
"@babel/traverse": "^7.25.3",
|
|
14
|
-
"@friggframework/schemas": "2.0.0--canary.461.
|
|
15
|
-
"@friggframework/test": "2.0.0--canary.461.
|
|
14
|
+
"@friggframework/schemas": "2.0.0--canary.461.4da5172.0",
|
|
15
|
+
"@friggframework/test": "2.0.0--canary.461.4da5172.0",
|
|
16
16
|
"@hapi/boom": "^10.0.1",
|
|
17
17
|
"@inquirer/prompts": "^5.3.8",
|
|
18
18
|
"axios": "^1.7.2",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"serverless-http": "^2.7.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@friggframework/eslint-config": "2.0.0--canary.461.
|
|
38
|
-
"@friggframework/prettier-config": "2.0.0--canary.461.
|
|
37
|
+
"@friggframework/eslint-config": "2.0.0--canary.461.4da5172.0",
|
|
38
|
+
"@friggframework/prettier-config": "2.0.0--canary.461.4da5172.0",
|
|
39
39
|
"aws-sdk-client-mock": "^4.1.0",
|
|
40
40
|
"aws-sdk-client-mock-jest": "^4.1.0",
|
|
41
41
|
"jest": "^30.1.3",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "4da5172ec0648a071c48a497c1db728a55e0ab8d"
|
|
74
74
|
}
|