@freshworks/shiftleft-tools 1.1.14 → 1.1.16
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/package.json +1 -1
- package/templates/postman/scripts/infra/container-runtime.sh +30 -0
- package/templates/postman/scripts/infra/setup-localstack.sh +37 -0
- package/templates/postman/scripts/infra/start-mocks.sh +80 -0
- package/templates/postman/scripts/infra/stop-localstack.sh +17 -0
- package/templates/postman/scripts/lib/__pycache__/report_combined.cpython-310.pyc +0 -0
- package/templates/postman/scripts/lib/__pycache__/report_consolidated.cpython-310.pyc +0 -0
- package/templates/postman/scripts/lib/__pycache__/report_migration.cpython-310.pyc +0 -0
- package/templates/postman/scripts/lib/__pycache__/report_mutation.cpython-310.pyc +0 -0
- package/templates/postman/scripts/lib/__pycache__/report_unit.cpython-310.pyc +0 -0
- package/templates/postman/scripts/lib/__pycache__/report_utils.cpython-310.pyc +0 -0
- package/templates/postman/scripts/lib/report_consolidated.py +15 -3
- package/templates/postman/scripts/report-generators/generate-consolidated-report.sh +4 -1
- package/templates/postman/scripts/report-generators/mutation-report.sh +6 -1
- package/templates/postman/scripts/run-all.sh +13 -0
- package/templates/postman/scripts/runners/run-tests-local.sh +143 -570
- package/templates/postman/scripts/runners/run-tests-staging.sh +124 -577
- package/templates/skills/run-test-suite/SKILL-java.md +7 -6
- package/templates/skills/setup-api-tests/SKILL-java.md +70 -26
|
@@ -60,12 +60,14 @@ Runs all Postman collections against local environment:
|
|
|
60
60
|
- Uses WireMock for external service mocks
|
|
61
61
|
- No real JWT needed (hardcoded test token)
|
|
62
62
|
|
|
63
|
-
Options:
|
|
64
|
-
- `./run-tests-local.sh --v3` — run only V3 API tests
|
|
65
|
-
- `./run-tests-local.sh --v2` — run only V2 API tests
|
|
63
|
+
Options (generic baseline):
|
|
66
64
|
- `./run-tests-local.sh --coverage` — run tests with JaCoCo coverage
|
|
67
65
|
- `./run-tests-local.sh --skip-services` — skip starting services (if already running)
|
|
68
66
|
|
|
67
|
+
> Repos that added versioned suites via `/setup-api-tests` (and protected the runner) may expose
|
|
68
|
+
> extra flags such as `--v3` / `--v2`. Run `./run-tests-local.sh --help` to see what THIS repo's
|
|
69
|
+
> runner supports.
|
|
70
|
+
|
|
69
71
|
### Postman Tests - Staging
|
|
70
72
|
|
|
71
73
|
```bash
|
|
@@ -79,9 +81,8 @@ Runs all Postman collections against staging environment:
|
|
|
79
81
|
- Uses real external services
|
|
80
82
|
- Requires AWS credentials for JWT generation (via IRSA in Jenkins, AWS_PROFILE locally)
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
- `./run-tests-staging.sh --multi-product` — test all products
|
|
84
|
+
The generic staging runner takes no suite flags; run `--help` to see what THIS repo's runner
|
|
85
|
+
supports (repos may add flags after customizing + protecting the runner).
|
|
85
86
|
|
|
86
87
|
### Full Test Suite
|
|
87
88
|
|
|
@@ -246,10 +246,17 @@ shiftleft init-postman
|
|
|
246
246
|
|
|
247
247
|
This creates:
|
|
248
248
|
- `postman/` folder with all scripts
|
|
249
|
-
- `runners/run-tests-local.sh`, `run-all.sh`, `report-generators/mutation-report.sh`
|
|
249
|
+
- `runners/run-tests-local.sh`, `runners/run-tests-staging.sh`, `run-all.sh`, `report-generators/mutation-report.sh`
|
|
250
250
|
- `report-generators/java-api-coverage-matrix.sh`, `lib/api_coverage.py`
|
|
251
251
|
- `start-mocks.sh`, `stop-mocks.sh`
|
|
252
252
|
|
|
253
|
+
**IMPORTANT — the runners ship GENERIC.** `runners/run-tests-local.sh` and
|
|
254
|
+
`runners/run-tests-staging.sh` contain a `# >>> repo-specific (set by /setup-api-tests) <<<`
|
|
255
|
+
block with safe defaults. You MUST customize that block (2.3 / 2.5) **and** then run
|
|
256
|
+
`shiftleft protect` (2.6). `shiftleft test` re-stages the library scripts and
|
|
257
|
+
**force-overwrites the runners on every run** — without `protect`, your customizations are
|
|
258
|
+
silently lost on the next test run.
|
|
259
|
+
|
|
253
260
|
---
|
|
254
261
|
|
|
255
262
|
## 2.2 Create application-postman.properties
|
|
@@ -310,38 +317,39 @@ MUST be included to prevent inheriting MySQL credentials from main config.
|
|
|
310
317
|
|
|
311
318
|
---
|
|
312
319
|
|
|
313
|
-
## 2.3
|
|
314
|
-
|
|
315
|
-
Edit `postman/scripts/runners/run-tests-local.sh`:
|
|
316
|
-
|
|
317
|
-
### If H2_SCOPE = test (most common):
|
|
320
|
+
## 2.3 Apply repo-specific runner customization (local)
|
|
318
321
|
|
|
319
|
-
|
|
322
|
+
Edit the `# >>> repo-specific (set by /setup-api-tests) <<<` block at the top of
|
|
323
|
+
`postman/scripts/runners/run-tests-local.sh` using the values recorded in Phase 1:
|
|
320
324
|
|
|
321
|
-
**Option A: Use mvn spring-boot:run**
|
|
322
325
|
```bash
|
|
323
|
-
|
|
326
|
+
APP_PORT="${APP_PORT:-8080}" # Phase 1.4
|
|
327
|
+
CONTEXT_PATH="${CONTEXT_PATH:-}" # e.g. "/api" — Phase 1.4
|
|
328
|
+
SPRING_PROFILE="${SPRING_PROFILE:-postman}" # matches application-postman.properties (2.2)
|
|
329
|
+
MAVEN_MODULE="${MAVEN_MODULE:-}" # submodule name, or empty for single-module
|
|
330
|
+
JAVA_VERSION="${JAVA_VERSION:-}" # e.g. "11" or "17"; empty = use current java
|
|
331
|
+
COVERAGE_PACKAGE="${COVERAGE_PACKAGE:-com.freshworks.*}" # YOUR base package, e.g. com.freshworks.myservice.*
|
|
332
|
+
COVERAGE_MODULE_DIR="${COVERAGE_MODULE_DIR:-$PROJECT_ROOT}" # module dir if MAVEN_MODULE set
|
|
324
333
|
```
|
|
325
334
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
# Build classpath including test dependencies
|
|
329
|
-
TEST_CLASSPATH=$(mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=/dev/stdout -q)
|
|
330
|
-
CLASSES_DIR="$PROJECT_ROOT/target/classes:$PROJECT_ROOT/target/test-classes"
|
|
331
|
-
|
|
332
|
-
java -cp "$CLASSES_DIR:$TEST_CLASSPATH" \
|
|
333
|
-
com.example.YourApplication \
|
|
334
|
-
--spring.profiles.active=postman \
|
|
335
|
-
--server.port=$APP_PORT &
|
|
336
|
-
```
|
|
335
|
+
Also set `MUTATION_PACKAGE_PREFIX` (in the environment or run-all) to your base package if you
|
|
336
|
+
want shortened names in the mutation report (optional).
|
|
337
337
|
|
|
338
|
-
###
|
|
338
|
+
### App start command (based on H2_SCOPE)
|
|
339
339
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
340
|
+
The runner's default app-start block uses `mvn $module_args spring-boot:run`. Adjust the
|
|
341
|
+
`# >>> repo-specific … app start command <<<` block in `start_spring_boot()`:
|
|
342
|
+
|
|
343
|
+
- **H2_SCOPE = runtime** (default block works): `mvn [-pl $MAVEN_MODULE] spring-boot:run` is fine.
|
|
344
|
+
- **H2_SCOPE = test** (app needs test classpath): replace the `nohup mvn … spring-boot:run` line
|
|
345
|
+
with a `java -cp` launch:
|
|
346
|
+
```bash
|
|
347
|
+
TEST_CLASSPATH=$(mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=/dev/stdout -q)
|
|
348
|
+
CLASSES_DIR="$PROJECT_ROOT/target/classes:$PROJECT_ROOT/target/test-classes"
|
|
349
|
+
nohup java -cp "$CLASSES_DIR:$TEST_CLASSPATH" com.example.YourApplication \
|
|
350
|
+
--spring.profiles.active="$SPRING_PROFILE" --server.port="$APP_PORT" \
|
|
351
|
+
> "$APP_LOG_FILE" 2>&1 &
|
|
352
|
+
```
|
|
345
353
|
|
|
346
354
|
---
|
|
347
355
|
|
|
@@ -383,6 +391,42 @@ done
|
|
|
383
391
|
|
|
384
392
|
---
|
|
385
393
|
|
|
394
|
+
## 2.5 Customize the staging runner
|
|
395
|
+
|
|
396
|
+
Only if the service has a staging environment. Edit `postman/config/staging.json` (created by
|
|
397
|
+
init) with the real `aws.*`, `base_url`, and `jwt.*` values, then fill the two
|
|
398
|
+
`# >>> repo-specific … <<<` blocks in `postman/scripts/runners/run-tests-staging.sh`:
|
|
399
|
+
|
|
400
|
+
- **Extra JWT payload fields** — export any additional `.jwt.*` fields your `generate-jwt.sh`
|
|
401
|
+
needs beyond the generic defaults (e.g. `ORGANISATION_ID`, `FRESHID_ACCOUNT_ID`).
|
|
402
|
+
- **Extra newman env vars** — append app-specific `--env-var` pairs to `NEWMAN_ENV_VARS`
|
|
403
|
+
(e.g. `extension_id`, `version_id` read from `.test_data` in the config).
|
|
404
|
+
|
|
405
|
+
The generic baseline already injects `auth_token`, `base_url`, `product_id`, `account_id`,
|
|
406
|
+
`user_role`.
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
## 2.6 MANDATORY: Protect the customized runners
|
|
411
|
+
|
|
412
|
+
`shiftleft test` force-overwrites runners on every run. Freeze your customizations:
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
shiftleft protect runners/run-tests-local.sh runners/run-tests-staging.sh
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
This records them under `protected[]` in `.shiftleft.json` so staging skips them. Verify with
|
|
419
|
+
`shiftleft protect --list`. Skip this and every edit from 2.3–2.5 is lost on the next
|
|
420
|
+
`shiftleft test`.
|
|
421
|
+
|
|
422
|
+
> **Versioned suites / multi-product (optional add-on):** the generic runner runs collections
|
|
423
|
+
> from `postman/collections/` (flat `*.json`, or one suite per subdirectory). If the service
|
|
424
|
+
> needs versioned suites (e.g. v3/v2/legacy) or multi-product matrices, extend `run_tests()` /
|
|
425
|
+
> `NEWMAN_ENV_VARS` in the protected runner — the `mp-installation` app is the reference
|
|
426
|
+
> implementation for that pattern.
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
386
430
|
# Phase 3: Create Postman Collections
|
|
387
431
|
|
|
388
432
|
## 3.1 MANDATORY: Read Before Writing
|