Skip to content

Commit 5d80176

Browse files
committed
feat(scan): allow --exclude-paths without --reach
Lift the --reach gate on --exclude-paths so the flag can filter SCA/SBOM manifest discovery on its own. The Coana --exclude-dirs merge happens unconditionally; consumers (handle-create-new-scan) only run reachability when --reach is set, so the merged options are simply unused otherwise. Move excludePaths out of reachabilityFlags into its own excludePathsFlag export so scan create lists it under the main Options block instead of the reach-only section. scan reach keeps it under Reachability Options since the command is reach-only by definition.
1 parent 239f154 commit 5d80176

8 files changed

Lines changed: 29 additions & 26 deletions

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { logger } from '@socketsecurity/registry/lib/logger'
66
import { assertNoNegationPatterns } from './exclude-paths.mts'
77
import { handleCreateNewScan } from './handle-create-new-scan.mts'
88
import { outputCreateNewScan } from './output-create-new-scan.mts'
9-
import { reachabilityFlags } from './reachability-flags.mts'
9+
import { excludePathsFlag, reachabilityFlags } from './reachability-flags.mts'
1010
import { suggestOrgSlug } from './suggest-org-slug.mts'
1111
import { suggestTarget } from './suggest_target.mts'
1212
import { validateReachabilityTarget } from './validate-reachability-target.mts'
@@ -172,6 +172,7 @@ async function run(
172172
hidden,
173173
flags: {
174174
...generalFlags,
175+
...excludePathsFlag,
175176
...reachabilityFlags,
176177
},
177178
help: command => `
@@ -182,7 +183,7 @@ async function run(
182183
${getFlagApiRequirementsOutput(`${parentName}:${CMD_NAME}`)}
183184
184185
Options
185-
${getFlagListOutput(generalFlags)}
186+
${getFlagListOutput({ ...generalFlags, ...excludePathsFlag })}
186187
187188
Reachability Options (when --reach is used)
188189
${getFlagListOutput(reachabilityFlags)}
@@ -471,8 +472,6 @@ async function run(
471472
const reachExcludePaths = cmdFlagValueToArray(cli.flags['reachExcludePaths'])
472473

473474
// Validation helpers for better readability.
474-
const hasExcludePaths = excludePaths.length > 0
475-
476475
const hasReachEcosystems = reachEcosystems.length > 0
477476

478477
const hasReachExcludePaths = reachExcludePaths.length > 0
@@ -495,7 +494,6 @@ async function run(
495494
reachVersion !== reachabilityFlags['reachVersion']?.default
496495

497496
const isUsingAnyReachabilityFlags =
498-
hasExcludePaths ||
499497
hasReachEcosystems ||
500498
hasReachExcludePaths ||
501499
isUsingNonDefaultAnalytics ||

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('socket scan create', async () => {
4040
--committers Committers
4141
--cwd working directory, defaults to process.cwd()
4242
--default-branch Set the default branch of the repository to the branch of this full-scan. Should only need to be done once, for example for the "main" or "master" branch.
43+
--exclude-paths List of glob patterns to exclude from the scan, including SCA/SBOM manifest discovery and (when --reach is enabled) Tier 1 reachability analysis. Patterns are matched relative to the project root. Bare directory names are auto-extended to recursive globs (e.g. \`tests\` becomes \`tests/**\`). Trailing slashes are stripped. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags.
4344
--interactive Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no.
4445
--json Output as JSON
4546
--markdown Output as Markdown
@@ -55,7 +56,6 @@ describe('socket scan create', async () => {
5556
--workspace The workspace in the Socket Organization that the repository is in to associate with the full scan.
5657
5758
Reachability Options (when --reach is used)
58-
--exclude-paths List of glob patterns to exclude from the entire Tier 1 scan, including SCA/SBOM manifest discovery. Patterns are matched relative to the project root. Bare directory names are auto-extended to recursive globs (e.g. \`tests\` becomes \`tests/**\`). Trailing slashes are stripped. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags.
5959
--reach-analysis-memory-limit The maximum memory in MB to use for the reachability analysis. The default is 8192MB.
6060
--reach-analysis-timeout Set timeout for the reachability analysis. Split analysis runs may cause the total scan time to exceed this timeout significantly.
6161
--reach-concurrency 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.
@@ -203,18 +203,14 @@ describe('socket scan create', async () => {
203203
FLAG_CONFIG,
204204
'{"apiToken":"fakeToken"}',
205205
],
206-
'should fail when --exclude-paths is used without --reach',
206+
'should succeed when --exclude-paths is used without --reach',
207207
async cmd => {
208-
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
209-
const output = stdout + stderr
210-
expect(output).toContain(
211-
'Reachability analysis flags require --reach to be enabled',
212-
)
213-
expect(output).toContain('add --reach flag to use --reach-* options')
208+
const { code, stdout } = await spawnSocketCli(binCliPath, cmd)
209+
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
214210
expect(
215211
code,
216-
'should exit with non-zero code when validation fails',
217-
).not.toBe(0)
212+
'should exit with code 0 when --exclude-paths is used standalone',
213+
).toBe(0)
218214
},
219215
)
220216

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

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

66
import { assertNoNegationPatterns } from './exclude-paths.mts'
77
import { handleScanReach } from './handle-scan-reach.mts'
8-
import { reachabilityFlags } from './reachability-flags.mts'
8+
import { excludePathsFlag, reachabilityFlags } from './reachability-flags.mts'
99
import { suggestTarget } from './suggest_target.mts'
1010
import { validateReachabilityTarget } from './validate-reachability-target.mts'
1111
import constants from '../../constants.mts'
@@ -75,6 +75,7 @@ async function run(
7575
hidden,
7676
flags: {
7777
...generalFlags,
78+
...excludePathsFlag,
7879
...reachabilityFlags,
7980
},
8081
help: command =>
@@ -89,7 +90,7 @@ async function run(
8990
${getFlagListOutput(generalFlags)}
9091
9192
Reachability Options
92-
${getFlagListOutput(reachabilityFlags)}
93+
${getFlagListOutput({ ...excludePathsFlag, ...reachabilityFlags })}
9394
9495
Runs the Socket reachability analysis without creating a scan in Socket.
9596
The output is written to .socket.facts.json in the current working directory

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('socket scan reach', async () => {
3737
--output Path to write the reachability report to (must end with .json). Defaults to .socket.facts.json in the current working directory.
3838
3939
Reachability Options
40-
--exclude-paths List of glob patterns to exclude from the entire Tier 1 scan, including SCA/SBOM manifest discovery. Patterns are matched relative to the project root. Bare directory names are auto-extended to recursive globs (e.g. \`tests\` becomes \`tests/**\`). Trailing slashes are stripped. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags.
40+
--exclude-paths List of glob patterns to exclude from the scan, including SCA/SBOM manifest discovery and (when --reach is enabled) Tier 1 reachability analysis. Patterns are matched relative to the project root. Bare directory names are auto-extended to recursive globs (e.g. \`tests\` becomes \`tests/**\`). Trailing slashes are stripped. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags.
4141
--reach-analysis-memory-limit The maximum memory in MB to use for the reachability analysis. The default is 8192MB.
4242
--reach-analysis-timeout Set timeout for the reachability analysis. Split analysis runs may cause the total scan time to exceed this timeout significantly.
4343
--reach-concurrency 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.

src/commands/scan/exclude-paths.mts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { SocketYml } from '@socketsecurity/config'
77

88
type ApplyFullExcludePathsOptions = {
99
cwd: string
10-
enabled?: boolean | undefined
1110
reachabilityOptions: ReachabilityOptions
1211
socketConfig: SocketYml | undefined
1312
target: string
@@ -54,15 +53,17 @@ export function normalizeExcludePath(path: string): string {
5453

5554
/**
5655
* Applies --exclude-paths consistently to SCA manifest discovery and Coana.
56+
* SCA exclusion always applies when paths are provided. The reachability
57+
* options are merged unconditionally; callers decide whether to actually run
58+
* reachability and consume them.
5759
*/
5860
export function applyFullExcludePaths({
5961
cwd,
60-
enabled = true,
6162
reachabilityOptions,
6263
socketConfig,
6364
target,
6465
}: ApplyFullExcludePathsOptions): ApplyFullExcludePathsResult {
65-
const excludePaths = enabled ? reachabilityOptions.excludePaths : []
66+
const { excludePaths } = reachabilityOptions
6667
const scaExcludeGlobs = excludePaths.map(excludePathToProjectIgnorePath)
6768
const coanaExcludeGlobs = projectIgnorePathsToReachExcludePaths(
6869
scaExcludeGlobs,

src/commands/scan/handle-create-new-scan.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ export async function handleCreateNewScan({
176176
const { effectiveSocketConfig, mergedReachabilityOptions } =
177177
applyFullExcludePaths({
178178
cwd,
179-
enabled: reach.runReachabilityAnalysis,
180179
reachabilityOptions: reach,
181180
socketConfig,
182181
target: targets[0]!,

src/commands/scan/handle-create-new-scan.test.mts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe('handleCreateNewScan excludePaths', () => {
160160
)
161161
})
162162

163-
it('does not apply excludePaths when reachability is disabled', async () => {
163+
it('applies excludePaths to SCA discovery even when reachability is disabled', async () => {
164164
await handleCreateNewScan({
165165
autoManifest: false,
166166
branchName: 'main',
@@ -208,7 +208,12 @@ describe('handleCreateNewScan excludePaths', () => {
208208
['/repo'],
209209
{ size: 1 },
210210
{
211-
config: { projectIgnorePaths: ['fixtures/**'] },
211+
config: {
212+
version: 2,
213+
issueRules: {},
214+
githubApp: {},
215+
projectIgnorePaths: ['fixtures/**', 'tests/**'],
216+
},
212217
cwd: '/repo',
213218
},
214219
)

src/commands/scan/reachability-flags.mts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import constants from '../../constants.mts'
22

33
import type { MeowFlags } from '../../flags.mts'
44

5-
export const reachabilityFlags: MeowFlags = {
5+
export const excludePathsFlag: MeowFlags = {
66
excludePaths: {
77
type: 'string',
88
isMultiple: true,
99
description:
10-
'List of glob patterns to exclude from the entire Tier 1 scan, including SCA/SBOM manifest discovery. Patterns are matched relative to the project root. Bare directory names are auto-extended to recursive globs (e.g. `tests` becomes `tests/**`). Trailing slashes are stripped. Negation patterns (`!path`) are not supported. Accepts a comma-separated value or multiple flags.',
10+
'List of glob patterns to exclude from the scan, including SCA/SBOM manifest discovery and (when --reach is enabled) Tier 1 reachability analysis. Patterns are matched relative to the project root. Bare directory names are auto-extended to recursive globs (e.g. `tests` becomes `tests/**`). Trailing slashes are stripped. Negation patterns (`!path`) are not supported. Accepts a comma-separated value or multiple flags.',
1111
},
12+
}
13+
14+
export const reachabilityFlags: MeowFlags = {
1215
reachAnalysisMemoryLimit: {
1316
type: 'number',
1417
default: 8192,

0 commit comments

Comments
 (0)