Skip to content

Commit 311e551

Browse files
mtorpjdalton
authored andcommitted
upgrade coana to v14.12.107
1 parent d1169a8 commit 311e551

File tree

7 files changed

+184
-26
lines changed

7 files changed

+184
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"@babel/preset-typescript": "7.27.1",
9595
"@babel/runtime": "7.28.4",
9696
"@biomejs/biome": "2.2.4",
97-
"@coana-tech/cli": "14.12.101",
97+
"@coana-tech/cli": "14.12.107",
9898
"@cyclonedx/cdxgen": "11.11.0",
9999
"@dotenvx/dotenvx": "1.49.0",
100100
"@eslint/compat": "1.3.2",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const generalFlags: MeowFlags = {
4848
description:
4949
'Force override the organization slug, overrides the default org from config',
5050
},
51+
output: {
52+
type: 'string',
53+
default: '',
54+
description:
55+
'Path to write the reachability report to (must end with .json). Defaults to .socket.facts.json in the current working directory.',
56+
shortFlag: 'o',
57+
},
5158
}
5259

5360
export const cmdScanReach = {
@@ -84,7 +91,8 @@ async function run(
8491
${getFlagListOutput(reachabilityFlags)}
8592
8693
Runs the Socket reachability analysis without creating a scan in Socket.
87-
The output is written to .socket.facts.json in the current working directory.
94+
The output is written to .socket.facts.json in the current working directory
95+
unless the --output flag is specified.
8896
8997
Note: Manifest files are uploaded to Socket's backend services because the
9098
reachability analysis requires creating a Software Bill of Materials (SBOM)
@@ -94,6 +102,8 @@ async function run(
94102
$ ${command}
95103
$ ${command} ./proj
96104
$ ${command} ./proj --reach-ecosystems npm,pypi
105+
$ ${command} --output custom-report.json
106+
$ ${command} ./proj --output ./reports/analysis.json
97107
`,
98108
}
99109

@@ -110,6 +120,7 @@ async function run(
110120
json,
111121
markdown,
112122
org: orgFlag,
123+
output: outputPath,
113124
reachAnalysisMemoryLimit,
114125
reachAnalysisTimeout,
115126
reachConcurrency,
@@ -123,6 +134,7 @@ async function run(
123134
json: boolean
124135
markdown: boolean
125136
org: string
137+
output: string
126138
reachAnalysisTimeout: number
127139
reachAnalysisMemoryLimit: number
128140
reachConcurrency: number
@@ -193,6 +205,12 @@ async function run(
193205
message: 'The json and markdown flags cannot be both set, pick one',
194206
fail: 'omit one',
195207
},
208+
{
209+
nook: true,
210+
test: !outputPath || outputPath.endsWith('.json'),
211+
message: 'The --output path must end with .json',
212+
fail: 'use a path ending with .json',
213+
},
196214
{
197215
nook: true,
198216
test: targetValidation.isValid,
@@ -229,10 +247,10 @@ async function run(
229247

230248
await handleScanReach({
231249
cwd,
250+
interactive,
232251
orgSlug,
233252
outputKind,
234-
targets,
235-
interactive,
253+
outputPath: outputPath || '',
236254
reachabilityOptions: {
237255
reachAnalysisTimeout: Number(reachAnalysisTimeout),
238256
reachAnalysisMemoryLimit: Number(reachAnalysisMemoryLimit),
@@ -244,5 +262,6 @@ async function run(
244262
reachExcludePaths,
245263
reachSkipCache: Boolean(reachSkipCache),
246264
},
265+
targets,
247266
})
248267
}

src/commands/scan/cmd-scan-reach.test.mts

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('socket scan reach', async () => {
3434
--json Output as JSON
3535
--markdown Output as Markdown
3636
--org Force override the organization slug, overrides the default org from config
37+
--output Path to write the reachability report to (must end with .json). Defaults to .socket.facts.json in the current working directory.
3738
3839
Reachability Options
3940
--reach-analysis-memory-limit The maximum memory in MB to use for the reachability analysis. The default is 8192MB.
@@ -47,7 +48,8 @@ describe('socket scan reach', async () => {
4748
--reach-skip-cache Skip caching-based optimizations. By default, the reachability analysis will use cached configurations from previous runs to speed up the analysis.
4849
4950
Runs the Socket reachability analysis without creating a scan in Socket.
50-
The output is written to .socket.facts.json in the current working directory.
51+
The output is written to .socket.facts.json in the current working directory
52+
unless the --output flag is specified.
5153
5254
Note: Manifest files are uploaded to Socket's backend services because the
5355
reachability analysis requires creating a Software Bill of Materials (SBOM)
@@ -56,7 +58,9 @@ describe('socket scan reach', async () => {
5658
Examples
5759
$ socket scan reach
5860
$ socket scan reach ./proj
59-
$ socket scan reach ./proj --reach-ecosystems npm,pypi"
61+
$ socket scan reach ./proj --reach-ecosystems npm,pypi
62+
$ socket scan reach --output custom-report.json
63+
$ socket scan reach ./proj --output ./reports/analysis.json"
6064
`)
6165
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
6266
"
@@ -763,6 +767,131 @@ describe('socket scan reach', async () => {
763767
)
764768
})
765769

770+
describe('output path tests', () => {
771+
cmdit(
772+
[
773+
'scan',
774+
'reach',
775+
FLAG_DRY_RUN,
776+
'--output',
777+
'custom-report.json',
778+
'--org',
779+
'fakeOrg',
780+
FLAG_CONFIG,
781+
'{"apiToken":"fakeToken"}',
782+
],
783+
'should accept --output flag with .json extension',
784+
async cmd => {
785+
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
786+
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
787+
expect(code, 'should exit with code 0').toBe(0)
788+
},
789+
)
790+
791+
cmdit(
792+
[
793+
'scan',
794+
'reach',
795+
FLAG_DRY_RUN,
796+
'-o',
797+
'report.json',
798+
'--org',
799+
'fakeOrg',
800+
FLAG_CONFIG,
801+
'{"apiToken":"fakeToken"}',
802+
],
803+
'should accept -o short flag with .json extension',
804+
async cmd => {
805+
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
806+
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
807+
expect(code, 'should exit with code 0').toBe(0)
808+
},
809+
)
810+
811+
cmdit(
812+
[
813+
'scan',
814+
'reach',
815+
FLAG_DRY_RUN,
816+
'--output',
817+
'./reports/analysis.json',
818+
'--org',
819+
'fakeOrg',
820+
FLAG_CONFIG,
821+
'{"apiToken":"fakeToken"}',
822+
],
823+
'should accept --output flag with path',
824+
async cmd => {
825+
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
826+
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
827+
expect(code, 'should exit with code 0').toBe(0)
828+
},
829+
)
830+
831+
cmdit(
832+
[
833+
'scan',
834+
'reach',
835+
FLAG_DRY_RUN,
836+
'--output',
837+
'report.txt',
838+
'--org',
839+
'fakeOrg',
840+
FLAG_CONFIG,
841+
'{"apiToken":"fakeToken"}',
842+
],
843+
'should fail when --output does not end with .json',
844+
async cmd => {
845+
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
846+
const output = stdout + stderr
847+
expect(output).toContain('The --output path must end with .json')
848+
expect(code, 'should exit with non-zero code').not.toBe(0)
849+
},
850+
)
851+
852+
cmdit(
853+
[
854+
'scan',
855+
'reach',
856+
FLAG_DRY_RUN,
857+
'--output',
858+
'report',
859+
'--org',
860+
'fakeOrg',
861+
FLAG_CONFIG,
862+
'{"apiToken":"fakeToken"}',
863+
],
864+
'should fail when --output has no extension',
865+
async cmd => {
866+
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
867+
const output = stdout + stderr
868+
expect(output).toContain('The --output path must end with .json')
869+
expect(code, 'should exit with non-zero code').not.toBe(0)
870+
},
871+
)
872+
873+
cmdit(
874+
[
875+
'scan',
876+
'reach',
877+
FLAG_DRY_RUN,
878+
'--output',
879+
'report.JSON',
880+
'--org',
881+
'fakeOrg',
882+
FLAG_CONFIG,
883+
'{"apiToken":"fakeToken"}',
884+
],
885+
'should fail when --output ends with .JSON (uppercase)',
886+
async cmd => {
887+
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
888+
const output = stdout + stderr
889+
expect(output).toContain('The --output path must end with .json')
890+
expect(code, 'should exit with non-zero code').not.toBe(0)
891+
},
892+
)
893+
})
894+
766895
describe('error handling and usability tests', () => {
767896
cmdit(
768897
[

src/commands/scan/handle-scan-reach.mts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type HandleScanReachConfig = {
1616
interactive: boolean
1717
orgSlug: string
1818
outputKind: OutputKind
19+
outputPath: string
1920
reachabilityOptions: ReachabilityOptions
2021
targets: string[]
2122
}
@@ -25,6 +26,7 @@ export async function handleScanReach({
2526
interactive: _interactive,
2627
orgSlug,
2728
outputKind,
29+
outputPath,
2830
reachabilityOptions,
2931
targets,
3032
}: HandleScanReachConfig) {
@@ -33,7 +35,11 @@ export async function handleScanReach({
3335
// Get supported file names
3436
const supportedFilesCResult = await fetchSupportedScanFileNames({ spinner })
3537
if (!supportedFilesCResult.ok) {
36-
await outputScanReach(supportedFilesCResult, { cwd, outputKind })
38+
await outputScanReach(supportedFilesCResult, {
39+
cwd,
40+
outputKind,
41+
outputPath,
42+
})
3743
return
3844
}
3945

@@ -70,6 +76,7 @@ export async function handleScanReach({
7076
const result = await performReachabilityAnalysis({
7177
cwd,
7278
orgSlug,
79+
outputPath,
7380
packagePaths,
7481
reachabilityOptions,
7582
spinner,
@@ -79,5 +86,5 @@ export async function handleScanReach({
7986

8087
spinner.stop()
8188

82-
await outputScanReach(result, { cwd, outputKind })
89+
await outputScanReach(result, { cwd, outputKind, outputPath })
8390
}

src/commands/scan/output-scan-reach.mts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from 'node:path'
2-
31
import { logger } from '@socketsecurity/registry/lib/logger'
42

53
import constants from '../../constants.mts'
@@ -11,7 +9,10 @@ import type { CResult, OutputKind } from '../../types.mts'
119

1210
export async function outputScanReach(
1311
result: CResult<ReachabilityAnalysisResult>,
14-
{ cwd, outputKind }: { cwd: string; outputKind: OutputKind },
12+
{
13+
outputKind,
14+
outputPath,
15+
}: { cwd: string; outputKind: OutputKind; outputPath: string },
1516
): Promise<void> {
1617
if (!result.ok) {
1718
process.exitCode = result.code ?? 1
@@ -26,9 +27,9 @@ export async function outputScanReach(
2627
return
2728
}
2829

30+
const actualOutputPath = outputPath || constants.DOT_SOCKET_DOT_FACTS_JSON
31+
2932
logger.log('')
3033
logger.success('Reachability analysis completed successfully!')
31-
logger.info(
32-
`Reachability report has been written to: ${path.join(cwd, constants.DOT_SOCKET_DOT_FACTS_JSON)}`,
33-
)
34+
logger.info(`Reachability report has been written to: ${actualOutputPath}`)
3435
}

0 commit comments

Comments
 (0)