@freshworks/shiftleft-tools 1.1.8

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.
Files changed (106) hide show
  1. package/README.md +351 -0
  2. package/bin/shiftleft.js +95 -0
  3. package/package.json +57 -0
  4. package/src/commands/doctor.js +208 -0
  5. package/src/commands/init-postman.js +298 -0
  6. package/src/commands/init-rules.js +78 -0
  7. package/src/commands/link.js +172 -0
  8. package/src/commands/protect.js +61 -0
  9. package/src/commands/run-tests.js +182 -0
  10. package/src/commands/setup-pipeline.js +209 -0
  11. package/src/commands/update.js +203 -0
  12. package/src/index.js +4 -0
  13. package/src/utils/copy-tree.js +98 -0
  14. package/src/utils/gitignore.js +26 -0
  15. package/src/utils/logger.js +9 -0
  16. package/src/utils/manifest.js +145 -0
  17. package/src/utils/stack.js +80 -0
  18. package/src/utils/template.js +135 -0
  19. package/templates/AGENTS.md +109 -0
  20. package/templates/CLAUDE.md +3 -0
  21. package/templates/jenkins/Jenkinsfile-java.groovy +432 -0
  22. package/templates/jenkins/Jenkinsfile-node.groovy +450 -0
  23. package/templates/postman/.husky/pre-commit +19 -0
  24. package/templates/postman/.prettierrc.json +5 -0
  25. package/templates/postman/README.md.ejs +147 -0
  26. package/templates/postman/collections/01-core.json.ejs +91 -0
  27. package/templates/postman/config/local.json.ejs +12 -0
  28. package/templates/postman/config/staging.json.ejs +26 -0
  29. package/templates/postman/environments/local.postman_environment.json.ejs +31 -0
  30. package/templates/postman/environments/staging.postman_environment.json.ejs +31 -0
  31. package/templates/postman/gitignore +16 -0
  32. package/templates/postman/npmrc +31 -0
  33. package/templates/postman/package.json.ejs +66 -0
  34. package/templates/postman/run-all-shim.sh +16 -0
  35. package/templates/postman/scripts/auth/generate-jwt.sh +113 -0
  36. package/templates/postman/scripts/auth/get-issuer-secret.sh +140 -0
  37. package/templates/postman/scripts/infra/start-mocks.sh +138 -0
  38. package/templates/postman/scripts/infra/stop-mocks.sh +43 -0
  39. package/templates/postman/scripts/lib/api_coverage.py +1122 -0
  40. package/templates/postman/scripts/lib/cleanup-reports.sh +101 -0
  41. package/templates/postman/scripts/lib/cleanup-stryker.sh +44 -0
  42. package/templates/postman/scripts/lib/report_combined.py +527 -0
  43. package/templates/postman/scripts/lib/report_consolidated.py +363 -0
  44. package/templates/postman/scripts/lib/report_generator.py +121 -0
  45. package/templates/postman/scripts/lib/report_migration.py +156 -0
  46. package/templates/postman/scripts/lib/report_mutation.py +110 -0
  47. package/templates/postman/scripts/lib/report_unit.py +353 -0
  48. package/templates/postman/scripts/lib/report_utils.py +973 -0
  49. package/templates/postman/scripts/report-generators/generate-consolidated-report.sh +445 -0
  50. package/templates/postman/scripts/report-generators/java-api-coverage-matrix.sh +257 -0
  51. package/templates/postman/scripts/report-generators/mutation-report.sh +672 -0
  52. package/templates/postman/scripts/report-generators/node-api-coverage-matrix.sh +167 -0
  53. package/templates/postman/scripts/report-generators/stage-report-artifacts.sh +27 -0
  54. package/templates/postman/scripts/run-all.sh +452 -0
  55. package/templates/postman/scripts/runners/run-mutation-tests.sh +113 -0
  56. package/templates/postman/scripts/runners/run-tests-local.sh +936 -0
  57. package/templates/postman/scripts/runners/run-tests-staging.sh +741 -0
  58. package/templates/postman-node/README.md.ejs +26 -0
  59. package/templates/postman-node/collections/crud/01-bootstrap.json.ejs +34 -0
  60. package/templates/postman-node/config/local.json.ejs +46 -0
  61. package/templates/postman-node/config/staging.json.ejs +31 -0
  62. package/templates/postman-node/local.test.env.ejs +3 -0
  63. package/templates/postman-node/mocks/external.js +14 -0
  64. package/templates/postman-node/package.json.ejs +39 -0
  65. package/templates/postman-node/requirements.txt +1 -0
  66. package/templates/postman-node/scripts/database/cleanup-mysql.sh +12 -0
  67. package/templates/postman-node/scripts/database/run-migrations.js +29 -0
  68. package/templates/postman-node/scripts/database/start-mysql.sh +34 -0
  69. package/templates/postman-node/scripts/database/wait-for-mysql.sh +36 -0
  70. package/templates/postman-node/scripts/lib/api_coverage_node.py +1137 -0
  71. package/templates/postman-node/scripts/lib/fetch-jwt.sh +86 -0
  72. package/templates/postman-node/scripts/lib/run-newman.sh +104 -0
  73. package/templates/postman-node/scripts/lib/setup-database.sh +55 -0
  74. package/templates/postman-node/scripts/lib/start-app.sh +48 -0
  75. package/templates/postman-node/scripts/lib/utils.sh +114 -0
  76. package/templates/postman-node/scripts/report-generators/stage-report-artifacts.sh +26 -0
  77. package/templates/postman-node/scripts/run-all.sh +303 -0
  78. package/templates/postman-node/scripts/runners/run-tests.sh +123 -0
  79. package/templates/postman-node/scripts/setup-mocks.js.ejs +29 -0
  80. package/templates/postman-node/stryker.config.js.ejs +51 -0
  81. package/templates/rules/local-test-setup.mdc +420 -0
  82. package/templates/rules/testing-node.mdc +66 -0
  83. package/templates/rules/testing.mdc +248 -0
  84. package/templates/skills/_shared/postman-standards.md +380 -0
  85. package/templates/skills/enhance-test-pipeline/SKILL-java.md +483 -0
  86. package/templates/skills/enhance-test-pipeline/SKILL-node.md +431 -0
  87. package/templates/skills/enhance-test-pipeline/SKILL.md +9 -0
  88. package/templates/skills/review-test-suite/SKILL-java.md +137 -0
  89. package/templates/skills/review-test-suite/SKILL-node.md +78 -0
  90. package/templates/skills/review-test-suite/SKILL.md +9 -0
  91. package/templates/skills/run-test-suite/SKILL-java.md +186 -0
  92. package/templates/skills/run-test-suite/SKILL-node.md +191 -0
  93. package/templates/skills/run-test-suite/SKILL.md +9 -0
  94. package/templates/skills/setup-api-tests/SKILL-java.md +1094 -0
  95. package/templates/skills/setup-api-tests/SKILL-node.md +141 -0
  96. package/templates/skills/setup-api-tests/SKILL.md +9 -0
  97. package/templates/skills/setup-mutation-tests/SKILL-java.md +303 -0
  98. package/templates/skills/setup-mutation-tests/SKILL-node.md +408 -0
  99. package/templates/skills/setup-mutation-tests/SKILL.md +9 -0
  100. package/templates/skills/setup-test-pipeline/SKILL-java.md +454 -0
  101. package/templates/skills/setup-test-pipeline/SKILL-node.md +318 -0
  102. package/templates/skills/setup-test-pipeline/SKILL.md +9 -0
  103. package/templates/skills/write-api-tests/SKILL-java.md +115 -0
  104. package/templates/skills/write-api-tests/SKILL-node.md +83 -0
  105. package/templates/skills/write-api-tests/SKILL.md +9 -0
  106. package/templates/stryker.config.js +50 -0
@@ -0,0 +1,186 @@
1
+ # Run Tests Skill — Java Spring Boot
2
+
3
+ Execute the appropriate test suite for the project.
4
+
5
+ > **Library scripts are staged from the package.** `./postman/scripts/run-all.sh`
6
+ > (and `shiftleft test`) stage the latest scripts automatically before running.
7
+ > The individual scripts referenced below (`report-generators/*`, `runners/*`) are
8
+ > part of that gitignored, staged cache — if you invoke one directly, run
9
+ > `shiftleft stage-scripts` first (or just use `run-all.sh`). Never copy or commit them.
10
+
11
+ ## When to Use
12
+
13
+ Invoke this skill when the user says:
14
+ - "run tests", "run the tests", "execute tests"
15
+ - "check tests", "verify tests"
16
+ - "run unit tests", "run mutation tests"
17
+ - "run the full test suite"
18
+ - "check coverage", "API coverage"
19
+ - "run postman tests", "run against staging"
20
+
21
+ ## Test Commands
22
+
23
+ ### Unit Tests Only
24
+
25
+ ```bash
26
+ mvn test
27
+ ```
28
+
29
+ Runs all JUnit tests. Fast (~30 seconds).
30
+
31
+ ### Mutation Tests (PIT)
32
+
33
+ ```bash
34
+ ./postman/scripts/report-generators/mutation-report.sh
35
+ ```
36
+
37
+ Runs PIT mutation testing to verify test quality. Takes 2-3 minutes.
38
+ - Target score: **60%+**
39
+ - Generates HTML report in `postman/reports/`
40
+ - Identifies weak assertions that let mutants survive
41
+
42
+ Or run directly with Maven:
43
+
44
+ ```bash
45
+ # Single-module:
46
+ mvn org.pitest:pitest-maven:mutationCoverage -Pmutation-tests
47
+
48
+ # Multi-module (replace 'installation' with module name):
49
+ mvn -pl installation org.pitest:pitest-maven:mutationCoverage -Pmutation-tests
50
+ ```
51
+
52
+ ### Postman Tests - Local
53
+
54
+ ```bash
55
+ cd postman/scripts && ./runners/run-tests-local.sh
56
+ ```
57
+
58
+ Runs all Postman collections against local environment:
59
+ - Uses H2 in-memory database
60
+ - Uses WireMock for external service mocks
61
+ - No real JWT needed (hardcoded test token)
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
66
+ - `./run-tests-local.sh --coverage` — run tests with JaCoCo coverage
67
+ - `./run-tests-local.sh --skip-services` — skip starting services (if already running)
68
+
69
+ ### Postman Tests - Staging
70
+
71
+ ```bash
72
+ cd postman/scripts && ./run-tests-staging.sh
73
+ # or with AWS profile for local use:
74
+ AWS_PROFILE=staging ./run-tests-staging.sh
75
+ ```
76
+
77
+ Runs all Postman collections against staging environment:
78
+ - Uses real MySQL database
79
+ - Uses real external services
80
+ - Requires AWS credentials for JWT generation (via IRSA in Jenkins, AWS_PROFILE locally)
81
+
82
+ Options:
83
+ - `./run-tests-staging.sh --v3` — run only V3 tests
84
+ - `./run-tests-staging.sh --multi-product` — test all products
85
+
86
+ ### Full Test Suite
87
+
88
+ ```bash
89
+ cd postman/scripts && ./run-all.sh
90
+ ```
91
+
92
+ Runs everything in sequence:
93
+ 1. Unit tests + JaCoCo coverage
94
+ 2. PIT mutation testing
95
+ 3. Postman API integration tests (local)
96
+ 4. API coverage matrix
97
+ 5. Combined quality report
98
+
99
+ ### Full Test Suite — Staging
100
+
101
+ ```bash
102
+ cd postman/scripts && ./run-all.sh --env staging
103
+ ```
104
+
105
+ Same as above but runs Postman tests against staging environment.
106
+
107
+ ### Skipping Phases (for faster iteration)
108
+
109
+ ```bash
110
+ ./run-all.sh --skip-mutation # Skip slow mutation tests
111
+ ./run-all.sh --skip-unit # Skip unit tests (use existing results)
112
+ ./run-all.sh --skip-postman # Skip Postman tests (use existing results)
113
+ ./run-all.sh --skip-coverage # Skip API coverage matrix
114
+ ./run-all.sh --skip-report # Skip quality report generation
115
+ ./run-all.sh --no-delay # Skip countdown delays (useful in CI)
116
+ ```
117
+
118
+ Combined examples:
119
+ ```bash
120
+ # Run only mutation tests (reuse existing unit test results):
121
+ ./run-all.sh --skip-unit --skip-postman --skip-coverage --skip-report --no-delay
122
+
123
+ # Run only Postman + quality report (reuse unit + mutation results):
124
+ ./run-all.sh --skip-unit --skip-mutation --no-delay
125
+
126
+ # Jenkins: generate quality report only (reuse all existing results):
127
+ ./run-all.sh --skip-unit --skip-mutation --skip-postman --skip-coverage --no-delay
128
+ ```
129
+
130
+ ### API Coverage Report
131
+
132
+ ```bash
133
+ ./postman/scripts/report-generators/java-api-coverage-matrix.sh
134
+ ```
135
+
136
+ Generates coverage matrix showing:
137
+ - Which endpoints have tests
138
+ - Which status codes are tested
139
+ - Coverage gaps to address
140
+
141
+ ## Workflow
142
+
143
+ 1. **Determine what to run** based on user request:
144
+ - Quick check → `mvn test`
145
+ - Test quality → `./postman/scripts/report-generators/mutation-report.sh`
146
+ - API tests local → `./postman/scripts/runners/run-tests-local.sh`
147
+ - API tests staging → `AWS_PROFILE=staging ./postman/scripts/runners/run-tests-staging.sh`
148
+ - Everything → `./postman/scripts/run-all.sh`
149
+ - Everything + staging → `./postman/scripts/run-all.sh --env staging`
150
+
151
+ 2. **Execute the command** and monitor output
152
+
153
+ 3. **Report results**:
154
+ - Number of tests passed/failed
155
+ - Coverage percentage (if applicable)
156
+ - Mutation score (if applicable)
157
+ - Location of generated reports
158
+
159
+ 4. **If failures occur**:
160
+ - Parse error messages
161
+ - Identify failing tests
162
+ - Suggest fixes based on error type
163
+
164
+ ## Before Merge Checklist
165
+
166
+ Run these commands before any PR:
167
+
168
+ ```bash
169
+ # 1. Unit tests pass
170
+ mvn test
171
+
172
+ # 2. Postman tests pass
173
+ cd postman/scripts && ./runners/run-tests-local.sh
174
+
175
+ # 3. 100% 2xx API coverage
176
+ ./postman/scripts/report-generators/java-api-coverage-matrix.sh
177
+
178
+ # 4. Mutation score >= 60%
179
+ ./postman/scripts/report-generators/mutation-report.sh
180
+ ```
181
+
182
+ Or run everything at once:
183
+
184
+ ```bash
185
+ cd postman/scripts && ./run-all.sh
186
+ ```
@@ -0,0 +1,191 @@
1
+ # Run Tests Skill — Node.js / Express
2
+
3
+ Execute the appropriate test suite for the project.
4
+
5
+ > **Library scripts are staged from the package.** `./postman/scripts/run-all.sh`
6
+ > (and `shiftleft test`) stage the latest scripts automatically before running.
7
+ > The individual scripts referenced below (`report-generators/*`, `runners/*`) are
8
+ > part of that gitignored, staged cache — if you invoke one directly, run
9
+ > `shiftleft stage-scripts` first (or just use `run-all.sh`). Never copy or commit them.
10
+
11
+ ## When to Use
12
+
13
+ Invoke this skill when the user says:
14
+ - "run tests", "run the tests", "execute tests"
15
+ - "check tests", "verify tests"
16
+ - "run unit tests", "run mutation tests"
17
+ - "run the full test suite"
18
+ - "check coverage", "API coverage"
19
+ - "run postman tests", "run against staging"
20
+
21
+ ## Test Commands
22
+
23
+ ### Unit Tests Only
24
+
25
+ ```bash
26
+ yarn test
27
+ ```
28
+
29
+ Runs all Mocha/Jest unit tests. Fast (~30 seconds).
30
+
31
+ ### Unit Tests + Coverage
32
+
33
+ ```bash
34
+ yarn test:coverage
35
+ ```
36
+
37
+ Runs unit tests with nyc/Istanbul coverage. Generates report in `coverage/unit/`.
38
+
39
+ ### Mutation Tests — Since Mode (fast, for local dev)
40
+
41
+ ```bash
42
+ yarn mutation-tests
43
+ ```
44
+
45
+ Runs Stryker in `since` mode: **only mutates files changed vs `origin/master`**.
46
+
47
+ This is the key insight for Node — Stryker on a large codebase takes 10-20 minutes on ALL files. The `since` mode makes it practical for local development by only testing what you've changed. If no scoped files changed, exits immediately (0 seconds).
48
+
49
+ Use this:
50
+ - During active development (only tests your changed files)
51
+ - Before pushing a PR (verifies your changes haven't weakened tests)
52
+
53
+ Expected output when no relevant files changed:
54
+ ```
55
+ [INFO] No scoped source files changed vs origin/master; skipping Stryker.
56
+ ```
57
+
58
+ ### Mutation Tests — Full Mode (for Jenkins CI only)
59
+
60
+ ```bash
61
+ yarn mutation-tests:full
62
+ ```
63
+
64
+ Runs Stryker on ALL scoped files. Takes 10-20 minutes on a large codebase.
65
+
66
+ Use this:
67
+ - In Jenkins CI only (runs as part of the Mutation Tests stage)
68
+ - When you want to see the complete mutation score
69
+ - When you've made broad refactoring changes
70
+
71
+ **Do not run full mode locally during active development** — it's too slow. Use `since` mode instead.
72
+
73
+ ### Postman Tests - Local
74
+
75
+ ```bash
76
+ cd postman && ./scripts/run-tests.sh
77
+ # or
78
+ cd postman/scripts && ./run-all.sh --skip-mutation
79
+ ```
80
+
81
+ Runs all Postman collections against local environment.
82
+
83
+ ### Postman Tests - Staging
84
+
85
+ ```bash
86
+ cd postman/scripts && ./run-all.sh --env staging --skip-mutation --skip-unit
87
+ ```
88
+
89
+ Runs Postman tests against staging environment. Requires AWS credentials (via IRSA in Jenkins, AWS_PROFILE locally).
90
+
91
+ ### Full Test Suite
92
+
93
+ ```bash
94
+ cd postman/scripts && ./run-all.sh
95
+ ```
96
+
97
+ Runs everything in sequence:
98
+ 1. Unit tests + coverage
99
+ 2. Stryker mutation testing (since mode — only changed files)
100
+ 3. Postman API integration tests (local)
101
+ 4. API coverage matrix
102
+ 5. Combined quality report
103
+
104
+ ### Full Test Suite — Staging
105
+
106
+ ```bash
107
+ cd postman/scripts && ./run-all.sh --env staging
108
+ ```
109
+
110
+ Same as above but runs Postman tests against staging environment.
111
+
112
+ ### Skipping Phases (for faster iteration)
113
+
114
+ ```bash
115
+ ./run-all.sh --skip-mutation # Skip mutation tests (use existing results)
116
+ ./run-all.sh --skip-unit # Skip unit tests (use existing results)
117
+ ./run-all.sh --skip-postman # Skip Postman tests (use existing results)
118
+ ./run-all.sh --skip-coverage # Skip API coverage matrix
119
+ ./run-all.sh --skip-report # Skip quality report generation
120
+ ./run-all.sh --no-delay # Skip countdown delays (useful in CI)
121
+ ```
122
+
123
+ Combined examples:
124
+ ```bash
125
+ # Run only Postman tests locally (skip everything else):
126
+ ./run-all.sh --skip-unit --skip-mutation --skip-coverage --skip-report --no-delay
127
+
128
+ # Run only quality report (reuse all existing results):
129
+ ./run-all.sh --skip-unit --skip-mutation --skip-postman --skip-coverage --no-delay
130
+
131
+ # Quick API coverage check (reuse existing Postman results):
132
+ ./run-all.sh --skip-unit --skip-mutation --skip-postman --skip-report --no-delay
133
+ ```
134
+
135
+ ### API Coverage Report
136
+
137
+ ```bash
138
+ ./postman/scripts/report-generators/node-api-coverage-matrix.sh
139
+ # or with explicit routes dir:
140
+ ./postman/scripts/report-generators/node-api-coverage-matrix.sh ./src/controllers ./postman
141
+ ```
142
+
143
+ Generates coverage matrix showing:
144
+ - Which Express routes have Postman tests
145
+ - Which HTTP methods and status codes are tested
146
+ - Coverage gaps to address
147
+
148
+ ## Workflow
149
+
150
+ 1. **Determine what to run** based on user request:
151
+ - Quick check → `yarn test`
152
+ - Test quality (local) → `yarn mutation-tests` (since mode — only changed files)
153
+ - Test quality (complete) → `yarn mutation-tests:full` (all scoped files, slow)
154
+ - API tests → `cd postman/scripts && ./run-all.sh --skip-unit --skip-mutation`
155
+ - Everything → `cd postman/scripts && ./run-all.sh`
156
+ - Everything + staging → `cd postman/scripts && ./run-all.sh --env staging`
157
+
158
+ 2. **Execute the command** and monitor output
159
+
160
+ 3. **Report results**:
161
+ - Number of tests passed/failed
162
+ - Coverage percentage (if applicable)
163
+ - Mutation score (if applicable)
164
+ - Location of generated reports
165
+
166
+ 4. **If failures occur**:
167
+ - Parse error messages
168
+ - Identify failing tests
169
+ - Suggest fixes based on error type
170
+
171
+ ## Before Merge Checklist
172
+
173
+ ```bash
174
+ # 1. Unit tests pass
175
+ yarn test
176
+
177
+ # 2. Mutation score is acceptable (only your changed files)
178
+ yarn mutation-tests
179
+
180
+ # 3. Postman tests pass locally
181
+ cd postman/scripts && ./run-all.sh --skip-mutation
182
+
183
+ # 4. API coverage check
184
+ ./postman/scripts/report-generators/node-api-coverage-matrix.sh
185
+ ```
186
+
187
+ Or run everything at once:
188
+
189
+ ```bash
190
+ cd postman/scripts && ./run-all.sh
191
+ ```
@@ -0,0 +1,9 @@
1
+ # Run Test Suite Skill
2
+
3
+ ## Detect Project Type First
4
+
5
+ Before doing anything, detect the stack:
6
+
7
+ 1. `pom.xml` in project root → **Java Spring Boot** → read `SKILL-java.md` in this folder and follow it completely
8
+ 2. `package.json` (no `pom.xml`) → **Node.js** → read `SKILL-node.md` in this folder and follow it completely
9
+ 3. If unsure → ask the user: "Is this a Java or Node.js project?"