@friggframework/devtools 2.0.0--canary.702.ef0dc8c.0 → 2.0.0--canary.710.7cfcf12.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 +0 -1
- package/frigg-cli/README.md +78 -76
- package/frigg-cli/__tests__/unit/commands/build.test.js +0 -3
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +30 -27
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
- package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
- package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
- package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
- package/frigg-cli/build-command/index.js +0 -6
- package/frigg-cli/deploy-command/index.js +0 -6
- package/frigg-cli/generate-command/index.js +1 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +10 -23
- package/frigg-cli/init-command/backend-first-handler.js +395 -531
- package/frigg-cli/init-command/deployment-modes.js +7 -0
- package/frigg-cli/init-command/index.js +82 -35
- package/frigg-cli/init-command/safe-path.js +58 -0
- package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
- package/frigg-cli/install-command/app-definition.js +174 -0
- package/frigg-cli/install-command/commit-changes.js +40 -8
- package/frigg-cli/install-command/environment-variables.js +15 -0
- package/frigg-cli/install-command/index.js +96 -21
- package/frigg-cli/install-command/install-package.js +77 -4
- package/frigg-cli/install-command/integration-file.js +20 -11
- package/frigg-cli/install-command/resolve-module.js +69 -0
- package/frigg-cli/install-command/template.js +102 -75
- package/frigg-cli/install-command/validate-package.js +36 -4
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/start-command/index.js +0 -4
- package/frigg-cli/start-command/start-command.test.js +0 -3
- package/frigg-cli/templates/backend/README.md +267 -0
- package/frigg-cli/templates/backend/env.example +20 -0
- package/frigg-cli/templates/backend/gitignore +10 -0
- package/frigg-cli/templates/backend/index.js +114 -0
- package/frigg-cli/templates/backend/infrastructure.js +20 -0
- package/frigg-cli/test/init-command.test.js +9 -2
- package/infrastructure/__tests__/postgres-config.test.js +241 -835
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
- package/infrastructure/__tests__/template-generation.test.js +36 -8
- package/infrastructure/create-frigg-infrastructure.js +1 -4
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +118 -60
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- 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/security/iam-generator.js +112 -5
- package/infrastructure/domains/security/iam-generator.test.js +94 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +7 -2
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +21 -0
- 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 +10 -8
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +0 -92
- package/frigg-cli/index.test.js +0 -158
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +0 -63
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +0 -133
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +0 -326
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +0 -241
- package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +0 -119
- package/frigg-cli/validate-command/checks/config.js +0 -468
- package/frigg-cli/validate-command/checks/integrations.js +0 -274
- package/frigg-cli/validate-command/fixtures/bad-module/index.js +0 -18
- package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +0 -76
- package/frigg-cli/validate-command/fixtures/fathom-module/index.js +0 -6
- package/frigg-cli/validate-command/format-report.js +0 -60
- package/frigg-cli/validate-command/index.js +0 -151
- package/frigg-cli/validate-command/load-app-definition.js +0 -93
- package/frigg-cli/validate-command/load-module-definition.js +0 -64
- package/frigg-cli/validate-command/schema-issues.js +0 -154
- package/frigg-cli/validate-command/validate-app-definition.js +0 -60
- package/frigg-cli/validate-command/validate-module-definition.js +0 -46
- package/infrastructure/app-definition-schema-contract.test.js +0 -607
- package/infrastructure/create-frigg-infrastructure.test.js +0 -51
- package/infrastructure/integration.test.js +0 -381
package/README.md
CHANGED
|
@@ -23,7 +23,6 @@ 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`)
|
|
27
26
|
- Run your Frigg instance locally
|
|
28
27
|
- Deploy your Frigg application to your configured provider
|
|
29
28
|
|
package/frigg-cli/README.md
CHANGED
|
@@ -10,29 +10,68 @@ The Frigg CLI provides tools for building, deploying, and managing serverless in
|
|
|
10
10
|
|
|
11
11
|
### Core Commands
|
|
12
12
|
|
|
13
|
-
#### `frigg init [options]`
|
|
13
|
+
#### `frigg init [projectName] [options]`
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Initialize a new Frigg application with scaffolding and configuration.
|
|
15
|
+
Scaffold a new Frigg backend application that installs and runs out of the box.
|
|
18
16
|
|
|
19
17
|
**Usage:**
|
|
18
|
+
|
|
20
19
|
```bash
|
|
21
|
-
frigg init
|
|
22
|
-
frigg init my-app
|
|
23
|
-
frigg init --
|
|
20
|
+
frigg init my-app # interactive (when stdin is a TTY)
|
|
21
|
+
frigg init my-app --yes # accept every default, no prompts
|
|
22
|
+
frigg init my-app --yes --mode standalone --no-install --no-git
|
|
23
|
+
frigg init my-app --mode embedded # add to an existing project (./frigg-integration)
|
|
24
|
+
npx @friggframework/devtools init my-app --yes # without a global install
|
|
24
25
|
```
|
|
25
26
|
|
|
26
27
|
**What it does:**
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
1. Validates the project name and `--mode`, and checks that the target directory is
|
|
30
|
+
empty (only `.git`, `.gitignore`, `README.md` and `.DS_Store` may exist) before asking anything else
|
|
31
|
+
2. Copies the backend template: `index.js` (app definition, named after the project),
|
|
32
|
+
`infrastructure.js`, `README.md`, `.gitignore`, `.env.example` (also seeded into `.env`)
|
|
33
|
+
3. Writes `package.json` with:
|
|
34
|
+
- scripts: `start` (`frigg start`), `build` (`frigg build`), `deploy` (`frigg deploy`),
|
|
35
|
+
`db:setup` (`frigg db:setup`), `test` (`jest --passWithNoTests`)
|
|
36
|
+
- dependencies: `@friggframework/core`, `@prisma/client`, `prisma`
|
|
37
|
+
- devDependencies: `@friggframework/devtools`, `@friggframework/serverless-plugin`,
|
|
38
|
+
`osls`, and the serverless plugins the composed definition loads
|
|
39
|
+
- Frigg package versions match the devtools that ran `init` (a prerelease is pinned exactly)
|
|
40
|
+
4. Validates the generated app definition against the app-definition schema (problems
|
|
41
|
+
are printed as warnings; `frigg start`, `build` and `deploy` do not validate)
|
|
42
|
+
5. Optionally initializes git and runs `npm install`
|
|
43
|
+
6. Prints next steps. API modules picked in the interactive prompt are not wired in
|
|
44
|
+
automatically; the next steps list a `frigg install <module>` command for each
|
|
45
|
+
|
|
46
|
+
In `embedded` mode the backend is written to `./frigg-integration` inside the target
|
|
47
|
+
directory, which may already contain your application. Git is not initialized.
|
|
28
48
|
|
|
29
49
|
**Options:**
|
|
30
|
-
- TBD
|
|
31
50
|
|
|
32
|
-
|
|
33
|
-
-
|
|
51
|
+
- `-n, --name <name>` - Project name (alternative to the positional argument)
|
|
52
|
+
- `-m, --mode <mode>` - `standalone` (default) or `embedded`
|
|
53
|
+
- `-y, --yes` - Accept the default for every prompt. Implied when stdin is not a TTY
|
|
54
|
+
- `--no-install` - Skip `npm install`
|
|
55
|
+
- `--no-git` - Skip `git init` and the initial commit
|
|
56
|
+
- `-f, --force` - Scaffold into a non-empty directory and overwrite an existing `README.md`/`.gitignore`
|
|
57
|
+
- `-v, --verbose` - Verbose output
|
|
58
|
+
|
|
59
|
+
**Next steps after `init`:**
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
cd my-app
|
|
63
|
+
docker run --name frigg-postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:16
|
|
64
|
+
npm run db:setup
|
|
65
|
+
npm start
|
|
66
|
+
```
|
|
34
67
|
|
|
35
|
-
|
|
68
|
+
The scaffolded app deploys nothing that bills by the hour, so it costs near $0 while
|
|
69
|
+
idle: no VPC, NAT gateway or database cluster (`vpc: { enable: false }`,
|
|
70
|
+
`database.postgres.management: 'external'`), field-level encryption with a per-stage
|
|
71
|
+
KMS key ($1/month, about $3/month after its first two yearly rotations), 14-day log
|
|
72
|
+
retention, and the app connecting to a PostgreSQL you host through `DATABASE_URL`.
|
|
73
|
+
`frigg deploy` reads `DATABASE_URL` from the shell that runs it, not from `.env`. The
|
|
74
|
+
generated `README.md` lists every resource, the security model and the other options.
|
|
36
75
|
|
|
37
76
|
---
|
|
38
77
|
|
|
@@ -47,28 +86,36 @@ frigg install salesforce
|
|
|
47
86
|
frigg install stripe
|
|
48
87
|
```
|
|
49
88
|
|
|
89
|
+
Run it in the app directory (the one with `package.json` and `index.js`).
|
|
90
|
+
|
|
50
91
|
**What it does:**
|
|
51
|
-
- Searches
|
|
52
|
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
|
|
92
|
+
- Searches npm for `@friggframework/api-module-<name>` and lets you pick the
|
|
93
|
+
packages to install (with no terminal to prompt on, it takes the exact match)
|
|
94
|
+
- Runs `npm install` in the app directory. An app on a Frigg 2.x prerelease
|
|
95
|
+
(what `frigg init` scaffolds today) gets the module's `@next` release, because
|
|
96
|
+
most modules' `latest` is still a 1.x release built for Frigg 1.x
|
|
97
|
+
- Resolves the installed module from the app directory and writes
|
|
98
|
+
`src/integrations/<Label>Integration.js`: an `IntegrationBase` subclass whose
|
|
99
|
+
`Definition.modules` wraps the module (an existing file is kept)
|
|
100
|
+
- Registers the class in your app definition: in `index.js` it adds the
|
|
101
|
+
`require` and the first entry of the `integrations` array. When it cannot do
|
|
102
|
+
that safely (no single `integrations: [...]` array literal, or the file does not
|
|
103
|
+
parse) it changes nothing and prints the two lines to add by hand. Older apps
|
|
104
|
+
with a `backend.js` are updated there instead
|
|
105
|
+
- Commits the files it changed (`git commit -- <files>`, so nothing else you have
|
|
106
|
+
staged is included) when the app is in a git repository; otherwise leaves them
|
|
107
|
+
in the working tree
|
|
108
|
+
- Lists the environment variables the module reads (from its `definition.js`)
|
|
109
|
+
that are not in `.env`, and offers to add them when run in a terminal
|
|
56
110
|
|
|
57
111
|
**Options:**
|
|
58
|
-
- None
|
|
112
|
+
- None
|
|
59
113
|
|
|
60
|
-
**Example
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
✓ Package installed successfully
|
|
66
|
-
🔧 Configuring integration in app definition...
|
|
67
|
-
✓ Integration configured
|
|
68
|
-
⚙️ Next steps:
|
|
69
|
-
1. Set HUBSPOT_CLIENT_ID in your environment
|
|
70
|
-
2. Set HUBSPOT_CLIENT_SECRET in your environment
|
|
71
|
-
3. Run 'frigg start' to test locally
|
|
114
|
+
**Example:**
|
|
115
|
+
```bash
|
|
116
|
+
cd my-app
|
|
117
|
+
npx frigg install hubspot
|
|
118
|
+
# -> src/integrations/HubSpotIntegration.js, listed in index.js's integrations
|
|
72
119
|
```
|
|
73
120
|
|
|
74
121
|
---
|
|
@@ -110,49 +157,6 @@ Found 5 modules matching "crm"
|
|
|
110
157
|
|
|
111
158
|
---
|
|
112
159
|
|
|
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
|
-
|
|
156
160
|
#### `frigg start [options]`
|
|
157
161
|
|
|
158
162
|
Start local development server with hot reload.
|
|
@@ -166,7 +170,7 @@ frigg start --frontend
|
|
|
166
170
|
```
|
|
167
171
|
|
|
168
172
|
**What it does:**
|
|
169
|
-
1. Validates DATABASE_URL environment variable
|
|
173
|
+
1. Validates DATABASE_URL environment variable
|
|
170
174
|
2. Detects database type (MongoDB or PostgreSQL)
|
|
171
175
|
3. Checks Prisma client generation status
|
|
172
176
|
4. Tests database connection
|
|
@@ -225,12 +229,10 @@ frigg deploy --region us-west-2
|
|
|
225
229
|
frigg deploy --force
|
|
226
230
|
frigg deploy --skip-env-validation
|
|
227
231
|
frigg deploy --skip-doctor # Skip health check (not recommended)
|
|
228
|
-
frigg deploy --skip-validate # Skip app definition validation (not recommended)
|
|
229
232
|
frigg deploy --no-interactive # CI/CD mode (no prompts, auto-repair safe issues)
|
|
230
233
|
```
|
|
231
234
|
|
|
232
235
|
**What it does:**
|
|
233
|
-
0. **Validates the app definition** (`frigg validate`) and stops on errors, unless `--skip-validate`
|
|
234
236
|
1. **Runs health check** (`frigg doctor`) to detect infrastructure issues
|
|
235
237
|
2. **Auto-repairs safe issues** (or prompts for confirmation in interactive mode)
|
|
236
238
|
3. **Fails if critical issues found** (unless `--skip-doctor` flag used)
|
|
@@ -14,9 +14,6 @@ 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
|
-
|
|
20
17
|
// Require after mocks
|
|
21
18
|
const { spawnSync } = require('child_process');
|
|
22
19
|
const { buildCommand } = require('../../../build-command');
|
|
@@ -10,17 +10,22 @@
|
|
|
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
|
-
|
|
16
13
|
jest.mock('child_process', () => ({
|
|
17
14
|
spawn: jest.fn()
|
|
18
15
|
}));
|
|
19
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).
|
|
20
19
|
jest.mock('fs', () => ({
|
|
20
|
+
...jest.requireActual('fs'),
|
|
21
21
|
existsSync: jest.fn()
|
|
22
22
|
}));
|
|
23
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
|
+
|
|
24
29
|
// Require after mocks
|
|
25
30
|
const { spawn } = require('child_process');
|
|
26
31
|
const fs = require('fs');
|
|
@@ -31,6 +36,8 @@ describe('CLI Command: deploy', () => {
|
|
|
31
36
|
let consoleWarnSpy;
|
|
32
37
|
let consoleErrorSpy;
|
|
33
38
|
let mockChildProcess;
|
|
39
|
+
let childOutcome;
|
|
40
|
+
let exitSpy;
|
|
34
41
|
|
|
35
42
|
beforeEach(() => {
|
|
36
43
|
jest.clearAllMocks();
|
|
@@ -40,10 +47,18 @@ describe('CLI Command: deploy', () => {
|
|
|
40
47
|
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
41
48
|
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
42
49
|
|
|
43
|
-
// 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 };
|
|
44
53
|
mockChildProcess = {
|
|
45
|
-
on: jest.fn()
|
|
54
|
+
on: jest.fn((event, handler) => {
|
|
55
|
+
if (event === childOutcome.event) {
|
|
56
|
+
setImmediate(() => handler(childOutcome.value));
|
|
57
|
+
}
|
|
58
|
+
return mockChildProcess;
|
|
59
|
+
})
|
|
46
60
|
};
|
|
61
|
+
exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});
|
|
47
62
|
|
|
48
63
|
// Mock successful spawn by default
|
|
49
64
|
spawn.mockReturnValue(mockChildProcess);
|
|
@@ -56,6 +71,7 @@ describe('CLI Command: deploy', () => {
|
|
|
56
71
|
consoleLogSpy.mockRestore();
|
|
57
72
|
consoleWarnSpy.mockRestore();
|
|
58
73
|
consoleErrorSpy.mockRestore();
|
|
74
|
+
exitSpy.mockRestore();
|
|
59
75
|
});
|
|
60
76
|
|
|
61
77
|
describe('Success Cases', () => {
|
|
@@ -281,43 +297,30 @@ describe('CLI Command: deploy', () => {
|
|
|
281
297
|
});
|
|
282
298
|
|
|
283
299
|
describe('Error Handling', () => {
|
|
284
|
-
it('should log
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
await deployCommand({ stage: 'dev' });
|
|
300
|
+
it('should log and reject when spawn fails', async () => {
|
|
301
|
+
childOutcome = { event: 'error', value: new Error('Spawn failed') };
|
|
288
302
|
|
|
289
|
-
|
|
290
|
-
const errorHandler = mockChildProcess.on.mock.calls.find(
|
|
291
|
-
call => call[0] === 'error'
|
|
292
|
-
)[1];
|
|
293
|
-
errorHandler(testError);
|
|
303
|
+
await expect(deployCommand({ stage: 'dev' })).rejects.toThrow('Spawn failed');
|
|
294
304
|
|
|
295
305
|
expect(consoleErrorSpy).toHaveBeenCalledWith('Error executing command: Spawn failed');
|
|
296
306
|
});
|
|
297
307
|
|
|
298
|
-
it('should log when child process exits
|
|
299
|
-
|
|
308
|
+
it('should log and exit with the code when child process exits non-zero', async () => {
|
|
309
|
+
childOutcome = { event: 'close', value: 1 };
|
|
300
310
|
|
|
301
|
-
|
|
302
|
-
const closeHandler = mockChildProcess.on.mock.calls.find(
|
|
303
|
-
call => call[0] === 'close'
|
|
304
|
-
)[1];
|
|
305
|
-
closeHandler(1);
|
|
311
|
+
await deployCommand({ stage: 'dev' });
|
|
306
312
|
|
|
307
313
|
expect(consoleLogSpy).toHaveBeenCalledWith('Child process exited with code 1');
|
|
314
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
308
315
|
});
|
|
309
316
|
|
|
310
317
|
it('should NOT log when child process exits with zero code', async () => {
|
|
311
318
|
await deployCommand({ stage: 'dev' });
|
|
312
319
|
|
|
313
|
-
// Simulate close event with success code
|
|
314
|
-
const closeHandler = mockChildProcess.on.mock.calls.find(
|
|
315
|
-
call => call[0] === 'close'
|
|
316
|
-
)[1];
|
|
317
|
-
closeHandler(0);
|
|
318
|
-
|
|
319
320
|
// Should not log exit message for success
|
|
320
321
|
expect(consoleLogSpy).not.toHaveBeenCalledWith('Child process exited with code 0');
|
|
322
|
+
expect(exitSpy).not.toHaveBeenCalled();
|
|
323
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('\n✓ Deployment completed successfully!');
|
|
321
324
|
});
|
|
322
325
|
});
|
|
323
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
|
},
|
|
@@ -94,4 +94,22 @@ describe('CLI Command: generate-iam', () => {
|
|
|
94
94
|
'arn:aws:kms:*:${AWS::AccountId}:key/*'
|
|
95
95
|
);
|
|
96
96
|
});
|
|
97
|
+
|
|
98
|
+
it("grants the app's own resources, named after Definition.name", async () => {
|
|
99
|
+
jest.doMock(
|
|
100
|
+
mockAppDefinitionPath,
|
|
101
|
+
() => ({ Definition: { name: 'my-app' } }),
|
|
102
|
+
{ virtual: true }
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
await generateIamCommand({});
|
|
106
|
+
|
|
107
|
+
const [, generatedYaml] = fs.writeFile.mock.calls[0];
|
|
108
|
+
expect(generatedYaml).toContain(
|
|
109
|
+
'arn:aws:cloudformation:*:${AWS::AccountId}:stack/*my-app*/*'
|
|
110
|
+
);
|
|
111
|
+
expect(generatedYaml).toContain(
|
|
112
|
+
'arn:aws:lambda:*:${AWS::AccountId}:function:*my-app*'
|
|
113
|
+
);
|
|
114
|
+
});
|
|
97
115
|
});
|