Skip to content

Commit eba18f7

Browse files
mtorpjdalton
authored andcommitted
feat(cli): add --reach-debug flag to enable verbose logging in the reachability (Coana) CLI
1 parent 6753963 commit eba18f7

File tree

8 files changed

+194
-229
lines changed

8 files changed

+194
-229
lines changed

packages/cli/src/commands/ci/handle-ci.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export async function handleCi(autoManifest: boolean): Promise<void> {
5353
reachAnalysisMemoryLimit: 0,
5454
reachAnalysisTimeout: 0,
5555
reachConcurrency: 1,
56+
reachDebug: false,
5657
reachDisableAnalytics: false,
5758
reachDisableAnalysisSplitting: false,
5859
reachEcosystems: [],

packages/cli/src/commands/scan/cmd-scan-create.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ async function run(
243243
reachAnalysisMemoryLimit,
244244
reachAnalysisTimeout,
245245
reachConcurrency,
246+
reachDebug,
246247
reachDisableAnalysisSplitting,
247248
reachDisableAnalytics,
248249
reachMinSeverity,
@@ -272,6 +273,7 @@ async function run(
272273
reachAnalysisMemoryLimit: number
273274
reachAnalysisTimeout: number
274275
reachConcurrency: number
276+
reachDebug: boolean
275277
reachDisableAnalytics: boolean
276278
reachDisableAnalysisSplitting: boolean
277279
reachMinSeverity: string
@@ -594,6 +596,7 @@ async function run(
594596
reachAnalysisMemoryLimit: Number(reachAnalysisMemoryLimit),
595597
reachAnalysisTimeout: Number(reachAnalysisTimeout),
596598
reachConcurrency: Number(reachConcurrency),
599+
reachDebug: Boolean(reachDebug),
597600
reachDisableAnalytics: Boolean(reachDisableAnalytics),
598601
reachDisableAnalysisSplitting: Boolean(reachDisableAnalysisSplitting),
599602
reachEcosystems,

packages/cli/src/commands/scan/cmd-scan-reach.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ async function run(
124124
reachAnalysisMemoryLimit,
125125
reachAnalysisTimeout,
126126
reachConcurrency,
127+
reachDebug,
127128
reachDisableAnalysisSplitting,
128129
reachDisableAnalytics,
129130
reachMinSeverity,
@@ -139,6 +140,7 @@ async function run(
139140
reachAnalysisMemoryLimit: number
140141
reachAnalysisTimeout: number
141142
reachConcurrency: number
143+
reachDebug: boolean
142144
reachDisableAnalytics: boolean
143145
reachDisableAnalysisSplitting: boolean
144146
reachMinSeverity: string
@@ -282,6 +284,7 @@ async function run(
282284
reachAnalysisMemoryLimit: Number(reachAnalysisMemoryLimit),
283285
reachAnalysisTimeout: Number(reachAnalysisTimeout),
284286
reachConcurrency: Number(reachConcurrency),
287+
reachDebug: Boolean(reachDebug),
285288
reachDisableAnalytics: Boolean(reachDisableAnalytics),
286289
reachDisableAnalysisSplitting: Boolean(reachDisableAnalysisSplitting),
287290
reachEcosystems,

packages/cli/src/commands/scan/create-scan-from-github.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ async function scanOneRepo(
257257
reachAnalysisMemoryLimit: 0,
258258
reachAnalysisTimeout: 0,
259259
reachConcurrency: 1,
260+
reachDebug: false,
260261
reachDisableAnalytics: false,
261262
reachDisableAnalysisSplitting: false,
262263
reachEcosystems: [],

packages/cli/src/commands/scan/perform-reachability-analysis.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type ReachabilityOptions = {
2121
reachAnalysisMemoryLimit: number
2222
reachAnalysisTimeout: number
2323
reachConcurrency: number
24+
reachDebug: boolean
2425
reachDisableAnalytics: boolean
2526
reachDisableAnalysisSplitting: boolean
2627
reachEcosystems: PURL_Type[]
@@ -169,6 +170,7 @@ export async function performReachabilityAnalysis(
169170
...(reachabilityOptions.reachConcurrency
170171
? ['--concurrency', `${reachabilityOptions.reachConcurrency}`]
171172
: []),
173+
...(reachabilityOptions.reachDebug ? ['--debug'] : []),
172174
...(reachabilityOptions.reachDisableAnalytics
173175
? ['--disable-analytics-sharing']
174176
: []),

packages/cli/src/commands/scan/reachability-flags.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export const reachabilityFlags: MeowFlags = {
1919
description:
2020
'Set the maximum number of concurrent reachability analysis runs. It is recommended to choose a concurrency level that ensures each analysis run has at least the --reach-analysis-memory-limit amount of memory available. NPM reachability analysis does not support concurrent execution, so the concurrency level is ignored for NPM.',
2121
},
22+
reachDebug: {
23+
type: 'boolean',
24+
default: false,
25+
description:
26+
'Enable debug mode for reachability analysis. Provides verbose logging from the reachability CLI.',
27+
},
2228
reachDisableAnalytics: {
2329
type: 'boolean',
2430
default: false,

packages/cli/test/integration/cli/cmd-scan-create.test.mts

Lines changed: 109 additions & 163 deletions
Large diffs are not rendered by default.

packages/cli/test/unit/commands/analytics/output-analytics.test.mts

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,11 @@
1-
/**
2-
* Unit tests for analytics output formatting functions.
3-
*
4-
* Tests the data transformation and output formatting for analytics data.
5-
* These tests use fixture data and snapshot testing for markdown rendering.
6-
*
7-
* Test Coverage:
8-
* - Repository data formatting (formatDataRepo)
9-
* - Organization data formatting (formatDataOrg)
10-
* - Markdown rendering (renderMarkdown)
11-
* - Alert type aggregation (dynamicRequire, envVars, filesystemAccess, etc.)
12-
* - Time series data formatting (critical, high, medium, low alerts)
13-
* - Alert counts by severity level
14-
* - Top 5 alert types ranking
15-
*
16-
* Testing Approach:
17-
* - Load analytics-fixture.json for realistic test data
18-
* - Use inline snapshots to verify formatting output
19-
* - Test both org-level and repo-level data transformations
20-
* - Verify markdown table generation with proper headers and formatting
21-
*
22-
* Related Files:
23-
* - src/commands/analytics/output-analytics.mts - Implementation
24-
* - src/commands/analytics/analytics-fixture.json - Test fixture data
25-
* - src/commands/analytics/handle-analytics.mts - Handler that uses output functions
26-
*/
27-
281
import { describe, expect, it } from 'vitest'
292

30-
import FIXTURE from '../../../../src/commands/analytics/analytics-fixture.json' with {
31-
type: 'json',
32-
}
3+
import FIXTURE from './analytics-fixture.json' with { type: 'json' }
334
import {
345
formatDataOrg,
356
formatDataRepo,
367
renderMarkdown,
37-
} from '../../../../src/commands/analytics/output-analytics.mts'
8+
} from './output-analytics.mts'
389

3910
describe('output-analytics', () => {
4011
describe('format data', () => {
@@ -51,63 +22,75 @@ describe('output-analytics', () => {
5122
"unmaintained": 133,
5223
},
5324
"total_critical_added": {
54-
"Apr 18": 0,
25+
"Apr 19": 0,
5526
"Apr 20": 0,
27+
"Apr 21": 0,
5628
"Apr 22": 0,
5729
},
5830
"total_critical_alerts": {
59-
"Apr 18": 0,
31+
"Apr 19": 0,
6032
"Apr 20": 0,
33+
"Apr 21": 0,
6134
"Apr 22": 0,
6235
},
6336
"total_critical_prevented": {
64-
"Apr 18": 0,
37+
"Apr 19": 0,
6538
"Apr 20": 0,
39+
"Apr 21": 0,
6640
"Apr 22": 0,
6741
},
6842
"total_high_added": {
69-
"Apr 18": 0,
43+
"Apr 19": 0,
7044
"Apr 20": 0,
45+
"Apr 21": 0,
7146
"Apr 22": 0,
7247
},
7348
"total_high_alerts": {
74-
"Apr 18": 13,
49+
"Apr 19": 13,
7550
"Apr 20": 13,
51+
"Apr 21": 13,
7652
"Apr 22": 10,
7753
},
7854
"total_high_prevented": {
79-
"Apr 18": 0,
55+
"Apr 19": 0,
8056
"Apr 20": 0,
57+
"Apr 21": 0,
8158
"Apr 22": 0,
8259
},
8360
"total_low_added": {
84-
"Apr 18": 0,
61+
"Apr 19": 0,
8562
"Apr 20": 0,
63+
"Apr 21": 0,
8664
"Apr 22": 0,
8765
},
8866
"total_low_alerts": {
89-
"Apr 18": 1054,
67+
"Apr 19": 1054,
9068
"Apr 20": 1060,
69+
"Apr 21": 1066,
9170
"Apr 22": 1059,
9271
},
9372
"total_low_prevented": {
94-
"Apr 18": 0,
73+
"Apr 19": 0,
9574
"Apr 20": 0,
75+
"Apr 21": 0,
9676
"Apr 22": 0,
9777
},
9878
"total_medium_added": {
99-
"Apr 18": 0,
79+
"Apr 19": 0,
10080
"Apr 20": 0,
81+
"Apr 21": 0,
10182
"Apr 22": 0,
10283
},
10384
"total_medium_alerts": {
104-
"Apr 18": 206,
85+
"Apr 19": 206,
10586
"Apr 20": 207,
87+
"Apr 21": 209,
10688
"Apr 22": 206,
10789
},
10890
"total_medium_prevented": {
109-
"Apr 18": 0,
91+
"Apr 19": 0,
11092
"Apr 20": 0,
93+
"Apr 21": 0,
11194
"Apr 22": 0,
11295
},
11396
}
@@ -127,63 +110,75 @@ describe('output-analytics', () => {
127110
"unmaintained": 532,
128111
},
129112
"total_critical_added": {
130-
"Apr 18": 0,
113+
"Apr 19": 0,
131114
"Apr 20": 0,
115+
"Apr 21": 0,
132116
"Apr 22": 0,
133117
},
134118
"total_critical_alerts": {
135-
"Apr 18": 0,
119+
"Apr 19": 0,
136120
"Apr 20": 0,
121+
"Apr 21": 0,
137122
"Apr 22": 0,
138123
},
139124
"total_critical_prevented": {
140-
"Apr 18": 0,
125+
"Apr 19": 0,
141126
"Apr 20": 0,
127+
"Apr 21": 0,
142128
"Apr 22": 0,
143129
},
144130
"total_high_added": {
145-
"Apr 18": 0,
131+
"Apr 19": 0,
146132
"Apr 20": 0,
133+
"Apr 21": 0,
147134
"Apr 22": 0,
148135
},
149136
"total_high_alerts": {
150-
"Apr 18": 13,
151-
"Apr 20": 26,
137+
"Apr 19": 13,
138+
"Apr 20": 13,
139+
"Apr 21": 13,
152140
"Apr 22": 10,
153141
},
154142
"total_high_prevented": {
155-
"Apr 18": 0,
143+
"Apr 19": 0,
156144
"Apr 20": 0,
145+
"Apr 21": 0,
157146
"Apr 22": 0,
158147
},
159148
"total_low_added": {
160-
"Apr 18": 0,
149+
"Apr 19": 0,
161150
"Apr 20": 0,
151+
"Apr 21": 0,
162152
"Apr 22": 0,
163153
},
164154
"total_low_alerts": {
165-
"Apr 18": 1054,
166-
"Apr 20": 2126,
155+
"Apr 19": 1054,
156+
"Apr 20": 1060,
157+
"Apr 21": 1066,
167158
"Apr 22": 1059,
168159
},
169160
"total_low_prevented": {
170-
"Apr 18": 0,
161+
"Apr 19": 0,
171162
"Apr 20": 0,
163+
"Apr 21": 0,
172164
"Apr 22": 0,
173165
},
174166
"total_medium_added": {
175-
"Apr 18": 0,
167+
"Apr 19": 0,
176168
"Apr 20": 0,
169+
"Apr 21": 0,
177170
"Apr 22": 0,
178171
},
179172
"total_medium_alerts": {
180-
"Apr 18": 206,
181-
"Apr 20": 416,
173+
"Apr 19": 206,
174+
"Apr 20": 207,
175+
"Apr 21": 209,
182176
"Apr 22": 206,
183177
},
184178
"total_medium_prevented": {
185-
"Apr 18": 0,
179+
"Apr 19": 0,
186180
"Apr 20": 0,
181+
"Apr 21": 0,
187182
"Apr 22": 0,
188183
},
189184
}
@@ -205,7 +200,8 @@ describe('output-analytics', () => {
205200
206201
| Date | Counts |
207202
| ------ | ------ |
208-
| Apr 18 | 0 |
203+
| Apr 19 | 0 |
204+
| Apr 21 | 0 |
209205
| Apr 20 | 0 |
210206
| Apr 22 | 0 |
211207
| ------ | ------ |
@@ -214,7 +210,8 @@ describe('output-analytics', () => {
214210
215211
| Date | Counts |
216212
| ------ | ------ |
217-
| Apr 18 | 13 |
213+
| Apr 19 | 13 |
214+
| Apr 21 | 13 |
218215
| Apr 20 | 13 |
219216
| Apr 22 | 10 |
220217
| ------ | ------ |
@@ -223,7 +220,8 @@ describe('output-analytics', () => {
223220
224221
| Date | Counts |
225222
| ------ | ------ |
226-
| Apr 18 | 0 |
223+
| Apr 19 | 0 |
224+
| Apr 21 | 0 |
227225
| Apr 20 | 0 |
228226
| Apr 22 | 0 |
229227
| ------ | ------ |
@@ -232,7 +230,8 @@ describe('output-analytics', () => {
232230
233231
| Date | Counts |
234232
| ------ | ------ |
235-
| Apr 18 | 0 |
233+
| Apr 19 | 0 |
234+
| Apr 21 | 0 |
236235
| Apr 20 | 0 |
237236
| Apr 22 | 0 |
238237
| ------ | ------ |
@@ -241,7 +240,8 @@ describe('output-analytics', () => {
241240
242241
| Date | Counts |
243242
| ------ | ------ |
244-
| Apr 18 | 0 |
243+
| Apr 19 | 0 |
244+
| Apr 21 | 0 |
245245
| Apr 20 | 0 |
246246
| Apr 22 | 0 |
247247
| ------ | ------ |
@@ -250,7 +250,8 @@ describe('output-analytics', () => {
250250
251251
| Date | Counts |
252252
| ------ | ------ |
253-
| Apr 18 | 0 |
253+
| Apr 19 | 0 |
254+
| Apr 21 | 0 |
254255
| Apr 20 | 0 |
255256
| Apr 22 | 0 |
256257
| ------ | ------ |
@@ -259,7 +260,8 @@ describe('output-analytics', () => {
259260
260261
| Date | Counts |
261262
| ------ | ------ |
262-
| Apr 18 | 0 |
263+
| Apr 19 | 0 |
264+
| Apr 21 | 0 |
263265
| Apr 20 | 0 |
264266
| Apr 22 | 0 |
265267
| ------ | ------ |
@@ -268,7 +270,8 @@ describe('output-analytics', () => {
268270
269271
| Date | Counts |
270272
| ------ | ------ |
271-
| Apr 18 | 0 |
273+
| Apr 19 | 0 |
274+
| Apr 21 | 0 |
272275
| Apr 20 | 0 |
273276
| Apr 22 | 0 |
274277
| ------ | ------ |

0 commit comments

Comments
 (0)