@friggframework/devtools 2.0.0--canary.667.f74cf3b.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.
- package/README.md +1 -0
- package/frigg-cli/README.md +46 -1
- package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +3 -0
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
- package/frigg-cli/build-command/index.js +6 -0
- package/frigg-cli/deploy-command/index.js +6 -0
- package/frigg-cli/index.js +19 -1
- package/frigg-cli/init-command/backend-first-handler.js +25 -46
- package/frigg-cli/start-command/index.js +4 -0
- package/frigg-cli/start-command/start-command.test.js +3 -0
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +326 -0
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +241 -0
- package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +119 -0
- package/frigg-cli/validate-command/checks/config.js +468 -0
- package/frigg-cli/validate-command/checks/integrations.js +274 -0
- package/frigg-cli/validate-command/fixtures/bad-module/index.js +18 -0
- package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +76 -0
- package/frigg-cli/validate-command/fixtures/fathom-module/index.js +6 -0
- package/frigg-cli/validate-command/format-report.js +60 -0
- package/frigg-cli/validate-command/index.js +151 -0
- package/frigg-cli/validate-command/load-app-definition.js +93 -0
- package/frigg-cli/validate-command/load-module-definition.js +64 -0
- package/frigg-cli/validate-command/schema-issues.js +154 -0
- package/frigg-cli/validate-command/validate-app-definition.js +60 -0
- package/frigg-cli/validate-command/validate-module-definition.js +46 -0
- package/infrastructure/app-definition-schema-contract.test.js +607 -0
- package/infrastructure/create-frigg-infrastructure.js +4 -1
- package/infrastructure/create-frigg-infrastructure.test.js +51 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +60 -98
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +6 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +30 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +0 -19
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +1 -13
- package/package.json +7 -7
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -281
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ The Frigg CLI is a command-line interface tool that helps developers manage and
|
|
|
23
23
|
- Automatically update project files
|
|
24
24
|
- Handle environment variables
|
|
25
25
|
- Validate package existence and backend paths
|
|
26
|
+
- Validate an API module Definition with `frigg validate --module` (or `frigg validate module`)
|
|
26
27
|
- Run your Frigg instance locally
|
|
27
28
|
- Deploy your Frigg application to your configured provider
|
|
28
29
|
|
package/frigg-cli/README.md
CHANGED
|
@@ -110,6 +110,49 @@ Found 5 modules matching "crm"
|
|
|
110
110
|
|
|
111
111
|
---
|
|
112
112
|
|
|
113
|
+
#### `frigg validate [options]`
|
|
114
|
+
|
|
115
|
+
Validate the app definition (`index.js`) before you build or deploy it (ADR-051), or validate an API module Definition from a module directory.
|
|
116
|
+
|
|
117
|
+
**Usage:**
|
|
118
|
+
```bash
|
|
119
|
+
frigg validate # schema + runtime checks (app mode)
|
|
120
|
+
frigg validate --stage prod # also the stage checks (encryption, deploy-time environment)
|
|
121
|
+
frigg validate --json # machine-readable report for CI
|
|
122
|
+
frigg validate --module # API module mode (from the module directory)
|
|
123
|
+
frigg validate module # same as --module
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**What it does (app mode):**
|
|
127
|
+
1. Loads `index.js` the way `frigg build` does (current directory, or the nearest `backend/`)
|
|
128
|
+
2. Validates it against the app-definition schema: unknown keys (with "did you mean"), types, and the values the infrastructure builders accept
|
|
129
|
+
3. Checks what the schema cannot: integration classes (static `Definition` with a valid, unique `name`, `version`, `modules`, and API module definitions that pass core's checks), an enabled database, management settings that conflict or lack ids, encryption (`aes` keys in `environment`, KMS key source, stages that never encrypt), a user config with which login works, `'ssm'` entries without `ssm.enable`, and keys that have no effect
|
|
130
|
+
4. Prints each problem with its JSON pointer and a fix; exits `1` when there are errors
|
|
131
|
+
|
|
132
|
+
**What it does (module mode):**
|
|
133
|
+
1. Loads `{ Definition }` from `./index.js` in the current directory
|
|
134
|
+
2. Validates it with `validateApiModuleDefinition` (api-module-definition schema)
|
|
135
|
+
3. Runs the structural checks from `checkModuleDefinition` (API class, required auth methods as functions)
|
|
136
|
+
4. Supports `--json` and `-v` like app mode; exits `1` listing JSON field paths on failure
|
|
137
|
+
|
|
138
|
+
**Example output:**
|
|
139
|
+
```
|
|
140
|
+
Validating /path/to/backend/index.js (stage: prod)
|
|
141
|
+
error /encrpytion Unknown key "encrpytion": nothing in Frigg reads it.
|
|
142
|
+
fix: Did you mean "encryption"?
|
|
143
|
+
error /database/postgres/management /database/postgres/management is "create-new", which is not an allowed value.
|
|
144
|
+
fix: Use one of: "discover", "managed", "use-existing".
|
|
145
|
+
warning /custom custom is not read by Frigg: it has no effect.
|
|
146
|
+
fix: Remove it.
|
|
147
|
+
✗ 2 error(s), 1 warning(s)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`--json` prints `{ valid, source, stage, errors, warnings }`; each issue is `{ severity, code, pointer, message, hint }`.
|
|
151
|
+
|
|
152
|
+
`frigg build` and `frigg deploy` run the same validation first and stop on errors (`--skip-validate` bypasses it, with a loud warning). `frigg start` runs it and only warns. `frigg init` validates the generated app the same way.
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
113
156
|
#### `frigg start [options]`
|
|
114
157
|
|
|
115
158
|
Start local development server with hot reload.
|
|
@@ -123,7 +166,7 @@ frigg start --frontend
|
|
|
123
166
|
```
|
|
124
167
|
|
|
125
168
|
**What it does:**
|
|
126
|
-
1. Validates DATABASE_URL environment variable
|
|
169
|
+
1. Validates DATABASE_URL environment variable, and the app definition (`frigg validate`; problems are printed as warnings, `--skip-validate` skips it)
|
|
127
170
|
2. Detects database type (MongoDB or PostgreSQL)
|
|
128
171
|
3. Checks Prisma client generation status
|
|
129
172
|
4. Tests database connection
|
|
@@ -182,10 +225,12 @@ frigg deploy --region us-west-2
|
|
|
182
225
|
frigg deploy --force
|
|
183
226
|
frigg deploy --skip-env-validation
|
|
184
227
|
frigg deploy --skip-doctor # Skip health check (not recommended)
|
|
228
|
+
frigg deploy --skip-validate # Skip app definition validation (not recommended)
|
|
185
229
|
frigg deploy --no-interactive # CI/CD mode (no prompts, auto-repair safe issues)
|
|
186
230
|
```
|
|
187
231
|
|
|
188
232
|
**What it does:**
|
|
233
|
+
0. **Validates the app definition** (`frigg validate`) and stops on errors, unless `--skip-validate`
|
|
189
234
|
1. **Runs health check** (`frigg doctor`) to detect infrastructure issues
|
|
190
235
|
2. **Auto-repairs safe issues** (or prompts for confirmation in interactive mode)
|
|
191
236
|
3. **Fails if critical issues found** (unless `--skip-doctor` flag used)
|
|
@@ -14,6 +14,9 @@ jest.mock('child_process', () => ({
|
|
|
14
14
|
spawnSync: jest.fn()
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
+
// The app definition validation step is tested in validate-command/.
|
|
18
|
+
jest.mock('../../../validate-command', () => ({ preflightValidation: jest.fn(() => true) }));
|
|
19
|
+
|
|
17
20
|
// Require after mocks
|
|
18
21
|
const { spawnSync } = require('child_process');
|
|
19
22
|
const { buildCommand } = require('../../../build-command');
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
// Mock dependencies BEFORE requiring modules
|
|
13
|
+
// The app definition validation step is tested in validate-command/.
|
|
14
|
+
jest.mock('../../../validate-command', () => ({ preflightValidation: jest.fn(() => true) }));
|
|
15
|
+
|
|
13
16
|
jest.mock('child_process', () => ({
|
|
14
17
|
spawn: jest.fn()
|
|
15
18
|
}));
|
|
@@ -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
|
+
});
|
|
@@ -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
|
|
package/frigg-cli/index.js
CHANGED
|
@@ -87,6 +87,7 @@ 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
|
|
|
@@ -108,14 +109,30 @@ program
|
|
|
108
109
|
.description('Run the backend and optional frontend')
|
|
109
110
|
.option('-s, --stage <stage>', 'deployment stage', 'dev')
|
|
110
111
|
.option('-v, --verbose', 'enable verbose output')
|
|
112
|
+
.option('--skip-validate', 'skip app definition validation')
|
|
111
113
|
.action(startCommand);
|
|
112
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
|
+
|
|
113
129
|
program
|
|
114
130
|
.command('build')
|
|
115
131
|
.description('Build the serverless application')
|
|
116
132
|
.option('-s, --stage <stage>', 'deployment stage', 'dev')
|
|
117
133
|
.option('-v, --verbose', 'enable verbose output')
|
|
118
134
|
.option('-p, --production', 'build for production (enables AWS discovery)')
|
|
135
|
+
.option('--skip-validate', 'skip app definition validation (not recommended)')
|
|
119
136
|
.action(buildCommand);
|
|
120
137
|
|
|
121
138
|
program
|
|
@@ -125,6 +142,7 @@ program
|
|
|
125
142
|
.option('-v, --verbose', 'enable verbose output')
|
|
126
143
|
.option('-f, --force', 'force deployment (bypasses caching for layers and functions)')
|
|
127
144
|
.option('--skip-doctor', 'skip post-deployment health check')
|
|
145
|
+
.option('--skip-validate', 'skip app definition validation (not recommended)')
|
|
128
146
|
.action(deployCommand);
|
|
129
147
|
|
|
130
148
|
program
|
|
@@ -220,4 +238,4 @@ authProgram
|
|
|
220
238
|
|
|
221
239
|
program.parse(process.argv);
|
|
222
240
|
|
|
223
|
-
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 };
|
|
@@ -5,7 +5,8 @@ const { select, confirm, multiselect } = require('@inquirer/prompts');
|
|
|
5
5
|
const { execSync } = require('child_process');
|
|
6
6
|
const spawn = require('cross-spawn');
|
|
7
7
|
const npmRegistry = require('../utils/npm-registry');
|
|
8
|
-
const {
|
|
8
|
+
const { runValidation } = require('../validate-command');
|
|
9
|
+
const { formatReport } = require('../validate-command/format-report');
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Backend-first template handler that treats frontend as optional demonstration
|
|
@@ -647,61 +648,39 @@ To integrate Frigg into your production application:
|
|
|
647
648
|
}
|
|
648
649
|
|
|
649
650
|
/**
|
|
650
|
-
* Validate generated app definition
|
|
651
|
+
* Validate the generated app definition with the same code path as
|
|
652
|
+
* `frigg validate`, `frigg build` and `frigg deploy` (ADR-051). Problems
|
|
653
|
+
* are reported as warnings: they never stop `frigg init`.
|
|
651
654
|
*/
|
|
652
655
|
async validateGeneratedAppDefinition(appDefPath) {
|
|
653
656
|
try {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
const content = await fs.readFile(appDefPath, 'utf8');
|
|
660
|
-
|
|
661
|
-
// Extract the appDefinition object (simplified approach)
|
|
662
|
-
// In a real scenario, we might use AST parsing for more robust extraction
|
|
663
|
-
const appDefinitionMatch = content.match(/const appDefinition = ({[\s\S]*?});/);
|
|
664
|
-
if (!appDefinitionMatch) {
|
|
665
|
-
throw new Error('Could not extract appDefinition from generated file');
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// Create a minimal representation for validation
|
|
669
|
-
// Since we can't easily execute the file, we'll validate the structure we know we generated
|
|
670
|
-
const appDefinition = {
|
|
671
|
-
integrations: [], // Will be populated based on selected integrations
|
|
672
|
-
user: { password: true },
|
|
673
|
-
encryption: { fieldLevelEncryptionMethod: 'kms' },
|
|
674
|
-
vpc: { enable: true },
|
|
675
|
-
security: {
|
|
676
|
-
cors: {
|
|
677
|
-
origin: 'http://localhost:3000',
|
|
678
|
-
credentials: true
|
|
679
|
-
}
|
|
680
|
-
},
|
|
681
|
-
logging: { level: 'info', retentionInDays: 30 },
|
|
682
|
-
custom: {
|
|
683
|
-
appName: 'My Frigg Application',
|
|
684
|
-
version: '1.0.0',
|
|
685
|
-
environment: 'development'
|
|
657
|
+
const report = runValidation({ cwd: path.dirname(appDefPath) });
|
|
658
|
+
const issues = [...report.errors, ...report.warnings];
|
|
659
|
+
if (issues.length === 0) {
|
|
660
|
+
if (this.options.verbose) {
|
|
661
|
+
console.log(chalk.green('✅ App definition passes validation'));
|
|
686
662
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
if (result.valid) {
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
665
|
+
if (report.errors.length === 1 && report.errors[0].code === 'load-failed') {
|
|
666
|
+
// Before `npm install`, index.js cannot load its dependencies yet.
|
|
693
667
|
if (this.options.verbose) {
|
|
694
|
-
console.log(chalk.
|
|
668
|
+
console.log(chalk.gray('App definition not validated yet: run `frigg validate` after `npm install`.'));
|
|
695
669
|
}
|
|
696
670
|
return true;
|
|
697
|
-
} else {
|
|
698
|
-
console.log(chalk.yellow('⚠️ App definition has validation warnings:'));
|
|
699
|
-
console.log(chalk.gray(formatErrors(result.errors)));
|
|
700
|
-
return false;
|
|
701
671
|
}
|
|
672
|
+
console.log(chalk.yellow('⚠️ App definition validation:'));
|
|
673
|
+
console.log(
|
|
674
|
+
formatReport({
|
|
675
|
+
...report,
|
|
676
|
+
errors: [],
|
|
677
|
+
warnings: issues.map((issue) => ({ ...issue, severity: 'warning' })),
|
|
678
|
+
})
|
|
679
|
+
);
|
|
680
|
+
return report.errors.length === 0;
|
|
702
681
|
} catch (error) {
|
|
703
682
|
if (this.options.verbose) {
|
|
704
|
-
console.log(chalk.yellow(`⚠️
|
|
683
|
+
console.log(chalk.yellow(`⚠️ Validation skipped: ${error.message}`));
|
|
705
684
|
}
|
|
706
685
|
return true; // Don't fail the process for validation issues
|
|
707
686
|
}
|
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
getDatabaseTypeNotConfiguredError,
|
|
13
13
|
getPrismaClientNotGeneratedError
|
|
14
14
|
} = require('../utils/error-messages');
|
|
15
|
+
const { preflightValidation } = require('../validate-command');
|
|
15
16
|
|
|
16
17
|
async function startCommand(options) {
|
|
17
18
|
if (options.verbose) {
|
|
@@ -25,6 +26,9 @@ async function startCommand(options) {
|
|
|
25
26
|
const envPath = path.join(process.cwd(), '.env');
|
|
26
27
|
dotenv.config({ path: envPath });
|
|
27
28
|
|
|
29
|
+
// Validate the app definition (ADR-051); local development only warns.
|
|
30
|
+
preflightValidation({ command: 'start', options, failOnErrors: false });
|
|
31
|
+
|
|
28
32
|
// Pre-flight database checks
|
|
29
33
|
try {
|
|
30
34
|
await performDatabaseChecks(options.verbose);
|
|
@@ -23,6 +23,9 @@ jest.mock('node:child_process', () => ({
|
|
|
23
23
|
}));
|
|
24
24
|
|
|
25
25
|
jest.mock('../utils/database-validator', () => mockValidator);
|
|
26
|
+
// The app definition validation step is tested in validate-command/.
|
|
27
|
+
jest.mock('../validate-command', () => ({ preflightValidation: jest.fn(() => true) }));
|
|
28
|
+
|
|
26
29
|
jest.mock('dotenv');
|
|
27
30
|
|
|
28
31
|
const { spawn } = require('node:child_process');
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `frigg init` validates the generated app with the same code path as
|
|
3
|
+
* `frigg validate`, and never fails because of it (ADR-051).
|
|
4
|
+
*/
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
jest.mock('@inquirer/prompts', () => ({}));
|
|
10
|
+
|
|
11
|
+
const BackendFirstHandler = require('../../init-command/backend-first-handler');
|
|
12
|
+
|
|
13
|
+
function writeApp(source) {
|
|
14
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-init-'));
|
|
15
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"backend"}');
|
|
16
|
+
fs.writeFileSync(path.join(dir, 'index.js'), source);
|
|
17
|
+
return dir;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('frigg init validation', () => {
|
|
21
|
+
const dirs = [];
|
|
22
|
+
let log;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
log = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
jest.restoreAllMocks();
|
|
30
|
+
for (const dir of dirs.splice(0))
|
|
31
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('validates the real generated definition, not a stand-in', async () => {
|
|
35
|
+
const dir = writeApp(
|
|
36
|
+
"module.exports = { Definition: { integrations: [], database: { postgres: { enable: true, management: 'create-new' } } } };"
|
|
37
|
+
);
|
|
38
|
+
dirs.push(dir);
|
|
39
|
+
const handler = new BackendFirstHandler(dir, {});
|
|
40
|
+
|
|
41
|
+
const ok = await handler.validateGeneratedAppDefinition(
|
|
42
|
+
path.join(dir, 'index.js')
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(ok).toBe(false);
|
|
46
|
+
expect(log.mock.calls.flat().join('\n')).toContain(
|
|
47
|
+
'/database/postgres/management'
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('stays quiet before npm install, when index.js cannot load its dependencies', async () => {
|
|
52
|
+
const dir = writeApp(
|
|
53
|
+
"require('@friggframework/api-module-does-not-exist');"
|
|
54
|
+
);
|
|
55
|
+
dirs.push(dir);
|
|
56
|
+
const handler = new BackendFirstHandler(dir, {});
|
|
57
|
+
|
|
58
|
+
await expect(
|
|
59
|
+
handler.validateGeneratedAppDefinition(path.join(dir, 'index.js'))
|
|
60
|
+
).resolves.toBe(true);
|
|
61
|
+
expect(log).not.toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const { checkIntegrations } = require('../checks/integrations');
|
|
2
|
+
|
|
3
|
+
class FakeApi {
|
|
4
|
+
static requesterType = 'oauth2';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const moduleDefinition = () => ({
|
|
8
|
+
moduleName: 'acme',
|
|
9
|
+
API: FakeApi,
|
|
10
|
+
requiredAuthMethods: {
|
|
11
|
+
getToken: async () => {},
|
|
12
|
+
getEntityDetails: async () => {},
|
|
13
|
+
getCredentialDetails: async () => {},
|
|
14
|
+
testAuthRequest: async () => {},
|
|
15
|
+
apiPropertiesToPersist: { credential: [], entity: [] },
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function integrationClass(definition) {
|
|
20
|
+
return class Integration {
|
|
21
|
+
static Definition = definition;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const goodIntegration = () =>
|
|
26
|
+
integrationClass({
|
|
27
|
+
name: 'acme',
|
|
28
|
+
version: '1.0.0',
|
|
29
|
+
modules: { acme: { definition: moduleDefinition() } },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const codes = (issues) =>
|
|
33
|
+
issues.map((i) => `${i.severity}:${i.code}:${i.pointer}`);
|
|
34
|
+
|
|
35
|
+
describe('checkIntegrations', () => {
|
|
36
|
+
it('accepts a well-formed integration class', () => {
|
|
37
|
+
expect(
|
|
38
|
+
checkIntegrations({ integrations: [goodIntegration()] })
|
|
39
|
+
).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('warns when the app lists no integrations', () => {
|
|
43
|
+
expect(codes(checkIntegrations({ integrations: [] }))).toEqual([
|
|
44
|
+
'warning:no-integrations:/integrations',
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('rejects an entry that is not a class', () => {
|
|
49
|
+
expect(
|
|
50
|
+
codes(
|
|
51
|
+
checkIntegrations({
|
|
52
|
+
integrations: [{ Definition: { name: 'x' } }],
|
|
53
|
+
})
|
|
54
|
+
)
|
|
55
|
+
).toEqual(['error:integration-not-a-class:/integrations/0']);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('rejects a class without a static Definition', () => {
|
|
59
|
+
class Bare {}
|
|
60
|
+
expect(codes(checkIntegrations({ integrations: [Bare] }))).toEqual([
|
|
61
|
+
'error:integration-definition-missing:/integrations/0/Definition',
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('requires a valid name and modules, and warns on a missing version', () => {
|
|
66
|
+
const Cls = integrationClass({ name: '1 bad name' });
|
|
67
|
+
expect(codes(checkIntegrations({ integrations: [Cls] }))).toEqual([
|
|
68
|
+
'error:integration-name-invalid:/integrations/0/Definition/name',
|
|
69
|
+
'warning:integration-version-missing:/integrations/0/Definition/version',
|
|
70
|
+
'error:integration-modules-missing:/integrations/0/Definition/modules',
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('reports duplicate integration names', () => {
|
|
75
|
+
expect(
|
|
76
|
+
codes(
|
|
77
|
+
checkIntegrations({
|
|
78
|
+
integrations: [goodIntegration(), goodIntegration()],
|
|
79
|
+
})
|
|
80
|
+
)
|
|
81
|
+
).toEqual([
|
|
82
|
+
'error:integration-name-duplicate:/integrations/1/Definition/name',
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('checks module definitions the way Module.validateDefinition does', () => {
|
|
87
|
+
const definition = moduleDefinition();
|
|
88
|
+
delete definition.requiredAuthMethods.getToken;
|
|
89
|
+
delete definition.moduleName;
|
|
90
|
+
const Cls = integrationClass({
|
|
91
|
+
name: 'acme',
|
|
92
|
+
version: '1',
|
|
93
|
+
modules: { acme: { definition }, other: {} },
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(codes(checkIntegrations({ integrations: [Cls] }))).toEqual([
|
|
97
|
+
'error:module-name-missing:/integrations/0/Definition/modules/acme/definition/moduleName',
|
|
98
|
+
'error:module-auth-method-missing:/integrations/0/Definition/modules/acme/definition/requiredAuthMethods/getToken',
|
|
99
|
+
'error:module-definition-missing:/integrations/0/Definition/modules/other/definition',
|
|
100
|
+
]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('does not require getToken for non-OAuth2 modules', () => {
|
|
104
|
+
const definition = moduleDefinition();
|
|
105
|
+
definition.API = class {
|
|
106
|
+
static requesterType = 'apiKey';
|
|
107
|
+
};
|
|
108
|
+
delete definition.requiredAuthMethods.getToken;
|
|
109
|
+
const Cls = integrationClass({
|
|
110
|
+
name: 'acme',
|
|
111
|
+
version: '1',
|
|
112
|
+
modules: { acme: { definition } },
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(checkIntegrations({ integrations: [Cls] })).toEqual([]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('warns that a module rateLimit is not applied', () => {
|
|
119
|
+
const definition = {
|
|
120
|
+
...moduleDefinition(),
|
|
121
|
+
rateLimit: { requests: 10, period: 'second' },
|
|
122
|
+
};
|
|
123
|
+
const Cls = integrationClass({
|
|
124
|
+
name: 'acme',
|
|
125
|
+
version: '1',
|
|
126
|
+
modules: { acme: { definition } },
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(codes(checkIntegrations({ integrations: [Cls] }))).toEqual([
|
|
130
|
+
'warning:module-rate-limit-ignored:/integrations/0/Definition/modules/acme/definition/rateLimit',
|
|
131
|
+
]);
|
|
132
|
+
});
|
|
133
|
+
});
|