Skip to content

Commit 18b5d29

Browse files
committed
refactor(scan): carry the --dynamic-sbom-inference selection in one field
- One `dynamicSbomInference` option holds the selected ecosystems, or undefined when off, in place of a boolean plus a list. - `parseDynamicSbomInferenceFlags` reads both flags for scan create, scan reach and fix. - Ecosystem lists are parsed case-insensitively and de-duplicated by one parser, which `fix --ecosystems` now uses too. - The "no build root" message names the selected build tools, and the flag's help lists the supported ecosystems from the build-tool table. - `--auto-manifest` fails a .NET build without a usable SDK, as it does a Maven build without Maven, instead of skipping it.
1 parent 6748a9d commit 18b5d29

32 files changed

Lines changed: 216 additions & 398 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1111

1212
### Changed
1313
- With `--dynamic-sbom-inference`, reachability analysis and `socket fix` now take the dependencies of every Gradle, sbt, Maven and .NET build they find from Socket facts only, so results no longer depend on which other builds produced facts.
14-
- `--dynamic-sbom-inference` and its setup now fail a .NET build that has no usable .NET SDK, as they do a Maven build without Maven, instead of skipping it. With it, reachability analysis and `socket fix` warn that builds skipped in `socket.json` are left out, and reachability analysis stops with next steps when no build produced Socket facts.
14+
- `socket manifest auto`, `--auto-manifest` and `--dynamic-sbom-inference` (with its setup) now fail a .NET build that has no usable .NET SDK, as they do a Maven build without Maven, instead of skipping it. With `--dynamic-sbom-inference`, reachability analysis and `socket fix` warn that builds skipped in `socket.json` are left out, and reachability analysis stops with next steps when no build produced Socket facts.
1515

1616
## [1.13.1](https://github.com/SocketDev/socket-cli/releases/tag/v1.13.1) - 2026-11-03
1717

‎src/commands/ci/handle-ci.mts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
gitBranch,
1111
} from '../../utils/git.mts'
1212
import { serializeResultJson } from '../../utils/serialize-result-json.mts'
13-
import { FACTS_PURL_TYPES } from '../manifest/scripts/build-tool.mts'
1413
import { handleCreateNewScan } from '../scan/handle-create-new-scan.mts'
1514

1615
/**
@@ -66,8 +65,7 @@ export async function handleCi(autoManifest: boolean): Promise<void> {
6665
pendingHead: true,
6766
pullRequest: detectCiPullRequestNumber(),
6867
reach: {
69-
dynamicSbomInference: false,
70-
dynamicSbomInferenceEcosystems: FACTS_PURL_TYPES,
68+
dynamicSbomInference: undefined,
7169
excludePaths: [],
7270
reachAdvisories: [],
7371
reachAnalysisMemoryLimit: '',

‎src/commands/fix/cmd-fix.integration.test.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ describe('socket fix', async () => {
170170
--debug Enable debug logging in the Coana-based Socket Fix CLI invocation.
171171
--disable-external-tool-checks Disable external tool checks during fix analysis.
172172
--dynamic-sbom-inference For Gradle, sbt, Maven and .NET: generate a Socket facts SBOM (produced directly by each package manager) per independent build root, instead of one synthetic root. Fixes are then attributed to the projects/modules that actually resolve each vulnerable dependency. The generated files are removed afterwards.
173-
--dynamic-sbom-inference-ecosystems With --dynamic-sbom-inference: generate Socket facts only for these ecosystems, as either a comma separated value or as multiple flags; the others keep their manifest files as they are. Supported: maven (Gradle, sbt and Maven) and nuget (.NET). Defaults to both.
173+
--dynamic-sbom-inference-ecosystems With --dynamic-sbom-inference: generate Socket facts only for these ecosystems, as either a comma separated value or as multiple flags; the others keep their manifest files as they are. Supported: maven (Gradle, Maven, and sbt) and nuget (.NET). Defaults to all of them.
174174
--ecosystems Limit fix analysis to specific ecosystems. Accepts space- or comma-separated values and is case-insensitive. Defaults to all ecosystems.
175175
--exclude-paths Skip matching paths from the scan entirely: manifests under these paths are not uploaded, and fixes are not applied to workspaces under them. Patterns are anchored micromatch globs matched relative to the target directory (CWD); \`data/postgres/pgdata\` matches that exact path, \`**/pgdata\` matches at any depth. Use this to skip directories the current user cannot read so they do not abort manifest collection. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags.
176176
--fix-version Override the version of @coana-tech/cli used for fix analysis. Default: <coana-version>.

‎src/commands/fix/cmd-fix.mts‎

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import constants, {
1919
import { commonFlags, outputFlags } from '../../flags.mts'
2020
import { checkCommandInput } from '../../utils/check-input.mts'
2121
import { cmdFlagValueToArray } from '../../utils/cmd.mts'
22-
import { getEcosystemChoicesForMeow } from '../../utils/ecosystem.mts'
22+
import {
23+
getEcosystemChoicesForMeow,
24+
parseEcosystemChoices,
25+
} from '../../utils/ecosystem.mts'
2326
import { getOutputKind } from '../../utils/get-output-kind.mts'
2427
import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
2528
import {
@@ -36,11 +39,10 @@ import { assertValidExcludePaths } from '../scan/exclude-paths.mts'
3639
import {
3740
DYNAMIC_SBOM_INFERENCE_DESCRIPTION,
3841
dynamicSbomInferenceEcosystemsFlags,
39-
parseDynamicSbomInferenceEcosystems,
42+
parseDynamicSbomInferenceFlags,
4043
} from '../scan/reachability-flags.mts'
4144

4245
import type { MeowFlag, MeowFlags } from '../../flags.mts'
43-
import type { PURL_Type } from '../../utils/ecosystem.mts'
4446
import type {
4547
CliCommandConfig,
4648
CliCommandContext,
@@ -344,7 +346,6 @@ async function run(
344346
autopilot,
345347
debug,
346348
disableExternalToolChecks,
347-
dynamicSbomInference,
348349
ecosystems,
349350
exclude,
350351
excludePaths,
@@ -372,7 +373,6 @@ async function run(
372373
autopilot: boolean
373374
debug: boolean
374375
disableExternalToolChecks: boolean
375-
dynamicSbomInference: boolean
376376
ecosystems: string[]
377377
exclude: string[]
378378
excludePaths: string[]
@@ -403,33 +403,13 @@ async function run(
403403

404404
const outputKind = getOutputKind(json, markdown)
405405

406-
const dynamicSbomInferenceEcosystemsRaw = cmdFlagValueToArray(
407-
cli.flags['dynamicSbomInferenceEcosystems'],
408-
)
409-
const dynamicSbomInferenceEcosystems = parseDynamicSbomInferenceEcosystems(
410-
dynamicSbomInferenceEcosystemsRaw,
411-
)
412-
413-
// Process comma-separated values for ecosystems flag.
414-
// ALL_ECOSYSTEMS is lowercase, so normalize input for a case-insensitive
415-
// match (mirrors --package-managers behavior).
416-
const ecosystemsRaw = cmdFlagValueToArray(ecosystems).map(s =>
417-
s.toLowerCase(),
418-
)
406+
const dynamicSbomInference = parseDynamicSbomInferenceFlags(cli.flags)
419407

420408
// Validate ecosystem values early, before dry-run check.
421-
const validatedEcosystems: PURL_Type[] = []
422-
const validEcosystemChoices = getEcosystemChoicesForMeow()
423-
for (const ecosystem of ecosystemsRaw) {
424-
if (!validEcosystemChoices.includes(ecosystem)) {
425-
logger.fail(
426-
`Invalid ecosystem: "${ecosystem}". Valid values are: ${joinAnd(validEcosystemChoices)}`,
427-
)
428-
process.exitCode = 1
429-
return
430-
}
431-
validatedEcosystems.push(ecosystem as PURL_Type)
432-
}
409+
const validatedEcosystems = parseEcosystemChoices(
410+
cmdFlagValueToArray(ecosystems),
411+
getEcosystemChoicesForMeow(),
412+
)
433413

434414
// Process and validate package manager values early, before dry-run check.
435415
// Coana normalizes input to uppercase and rejects unknown values, so do the
@@ -458,13 +438,6 @@ async function run(
458438

459439
const wasValidInput = checkCommandInput(
460440
outputKind,
461-
{
462-
nook: true,
463-
test: dynamicSbomInference || !dynamicSbomInferenceEcosystemsRaw.length,
464-
message:
465-
'--dynamic-sbom-inference-ecosystems requires --dynamic-sbom-inference',
466-
fail: 'add --dynamic-sbom-inference',
467-
},
468441
{
469442
test: RangeStyles.includes(rangeStyle),
470443
message: `Expecting range style of ${joinOr(RangeStyles)}`,
@@ -557,7 +530,6 @@ async function run(
557530
disableExternalToolChecks,
558531
disableMajorUpdates,
559532
dynamicSbomInference,
560-
dynamicSbomInferenceEcosystems,
561533
ecosystems: validatedEcosystems,
562534
exclude: excludePatterns,
563535
excludePaths: excludePathsPatterns,

‎src/commands/fix/coana-fix-dynamic-sbom-inference.test.mts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ describe('socket fix --dynamic-sbom-inference', () => {
102102
debug: false,
103103
disableExternalToolChecks: false,
104104
disableMajorUpdates: false,
105-
dynamicSbomInference: true,
106-
dynamicSbomInferenceEcosystems: ['maven'],
105+
dynamicSbomInference: ['maven'],
107106
ecosystems: [],
108107
exclude: [],
109108
excludePaths: [],
@@ -200,7 +199,7 @@ describe('socket fix --dynamic-sbom-inference', () => {
200199

201200
const result = await coanaFix({
202201
...baseConfig,
203-
dynamicSbomInference: false,
202+
dynamicSbomInference: undefined,
204203
})
205204

206205
expect(result.ok).toBe(true)
@@ -215,15 +214,15 @@ describe('socket fix --dynamic-sbom-inference', () => {
215214
FACTS,
216215
])
217216

218-
await coanaFix({ ...baseConfig, dynamicSbomInference: false })
217+
await coanaFix({ ...baseConfig, dynamicSbomInference: undefined })
219218

220219
expect(uploadManifestFiles).toHaveBeenCalledWith('test-org', [FACTS], {
221220
pathsRelativeTo: '/test/cwd',
222221
})
223222
})
224223

225224
it('does not pass the facts restriction without the flag', async () => {
226-
await coanaFix({ ...baseConfig, dynamicSbomInference: false })
225+
await coanaFix({ ...baseConfig, dynamicSbomInference: undefined })
227226

228227
expect(mockGenerateSocketFactsForFix).not.toHaveBeenCalled()
229228
expect(coanaCalls('compute-fixes-and-upgrade-purls')[0]).not.toContain(

‎src/commands/fix/coana-fix.mts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import { fetchSupportedScanFileNames } from '../scan/fetch-supported-scan-file-n
6060
import type { GeneratedSocketFacts } from './generated-socket-facts.mts'
6161
import type { FixConfig } from './types.mts'
6262
import type { CResult } from '../../types.mts'
63+
import type { FactsOnlyTypes } from '../../utils/coana.mts'
6364
import type { PURL_Type } from '../../utils/ecosystem.mts'
6465
import type { Spinner } from '@socketsecurity/registry/lib/spinner'
6566

@@ -283,15 +284,17 @@ function formatNotAppliedFixes(notApplied: NotAppliedFix[]): string {
283284

284285
type GeneratedSocketFactsSlot = {
285286
generated?: GeneratedSocketFacts | undefined
287+
purlTypes: FactsOnlyTypes
286288
tmpDir: string
287289
}
288290

289291
export async function coanaFix(fixConfig: FixConfig): Promise<CoanaFixResult> {
290-
if (!fixConfig.dynamicSbomInference) {
292+
const purlTypes = fixConfig.dynamicSbomInference
293+
if (!purlTypes) {
291294
return await coanaFixWithFacts(fixConfig, undefined)
292295
}
293296
return await withTmpDir('socket-fix-facts-', async tmpDir => {
294-
const slot: GeneratedSocketFactsSlot = { tmpDir }
297+
const slot: GeneratedSocketFactsSlot = { purlTypes, tmpDir }
295298
try {
296299
return await coanaFixWithFacts(fixConfig, slot)
297300
} finally {
@@ -396,7 +399,7 @@ async function coanaFixWithFacts(
396399
factsSlot.generated = await generateSocketFactsForFix({
397400
cwd,
398401
excludePaths,
399-
purlTypes: fixConfig.dynamicSbomInferenceEcosystems,
402+
purlTypes: factsSlot.purlTypes,
400403
findFactsPaths: async () =>
401404
(await findScanFilepaths()).filter(isSocketFactsFile),
402405
tmpDir: factsSlot.tmpDir,

‎src/commands/fix/handle-fix.mts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export async function handleFix({
6969
disableExternalToolChecks,
7070
disableMajorUpdates,
7171
dynamicSbomInference,
72-
dynamicSbomInferenceEcosystems,
7372
ecosystems,
7473
exclude,
7574
excludePaths,
@@ -101,7 +100,6 @@ export async function handleFix({
101100
disableExternalToolChecks,
102101
disableMajorUpdates,
103102
dynamicSbomInference,
104-
dynamicSbomInferenceEcosystems,
105103
ecosystems,
106104
exclude,
107105
excludePaths,
@@ -132,7 +130,6 @@ export async function handleFix({
132130
disableExternalToolChecks,
133131
disableMajorUpdates,
134132
dynamicSbomInference,
135-
dynamicSbomInferenceEcosystems,
136133
ecosystems,
137134
exclude,
138135
excludePaths,

‎src/commands/fix/types.mts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { FactsOnlyTypes } from '../../utils/coana.mts'
12
import type { PURL_Type } from '../../utils/ecosystem.mts'
23
import type { RangeStyle } from '../../utils/semver.mts'
34
import type { Spinner } from '@socketsecurity/registry/lib/spinner'
@@ -12,8 +13,8 @@ export type FixConfig = {
1213
debug: boolean
1314
disableExternalToolChecks: boolean
1415
disableMajorUpdates: boolean
15-
dynamicSbomInference: boolean
16-
dynamicSbomInferenceEcosystems: readonly PURL_Type[]
16+
// The ecosystems to generate Socket facts for; undefined when off.
17+
dynamicSbomInference: FactsOnlyTypes | undefined
1718
ecosystems: PURL_Type[]
1819
exclude: string[]
1920
excludePaths: string[]

‎src/commands/manifest/discover-manifest-roots.test.mts‎

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { testPath } from '../../../test/utils.mts'
1515
import { loadSocketConfig } from '../../utils/config.mts'
1616

1717
import type { BuildRoot } from './discover-manifest-roots.mts'
18+
import type { BuildTool } from './scripts/build-tool.mts'
19+
import type { PURL_Type } from '../../utils/ecosystem.mts'
1820
import type { SocketJson } from '../../utils/socket-json.mts'
1921

2022
const monorepo = path.join(
@@ -140,37 +142,41 @@ describe('findBuildToolCandidates', () => {
140142
expect(dirsOf(candidates.get('gradle'))).toContain(dualDir)
141143
})
142144

143-
it('drops a disabled ecosystem entirely', async () => {
144-
const candidates = await findBuildToolCandidates({
145-
cwd: monorepo,
146-
socketConfig: undefined,
145+
it.for<{
146+
name: string
147+
purlTypes?: PURL_Type[]
148+
sockJson?: SocketJson
149+
tools: BuildTool[]
150+
}>([
151+
{
152+
name: 'a disabled ecosystem',
147153
sockJson: {
148154
defaults: { manifest: { maven: { disabled: true } } },
149155
} as SocketJson,
150-
})
151-
expect(candidates.has('maven')).toBe(false)
152-
expect(candidates.get('gradle')?.length).toBeGreaterThan(0)
153-
})
154-
155-
it('drops the build tools of unselected purl types', async () => {
156-
const maven = await findBuildToolCandidates({
157-
cwd: monorepo,
156+
tools: ['dotnet', 'gradle', 'sbt'],
157+
},
158+
{
159+
name: 'purl types other than maven',
158160
purlTypes: ['maven'],
159-
socketConfig: undefined,
160-
sockJson: {} as SocketJson,
161-
})
162-
expect(maven.get('maven')?.length).toBeGreaterThan(0)
163-
expect(maven.get('gradle')?.length).toBeGreaterThan(0)
164-
expect(maven.has('dotnet')).toBe(false)
165-
166-
const nuget = await findBuildToolCandidates({
167-
cwd: monorepo,
161+
tools: ['gradle', 'maven', 'sbt'],
162+
},
163+
{
164+
name: 'purl types other than nuget',
168165
purlTypes: ['nuget'],
169-
socketConfig: undefined,
170-
sockJson: {} as SocketJson,
171-
})
172-
expect([...nuget.keys()]).toEqual(['dotnet'])
173-
})
166+
tools: ['dotnet'],
167+
},
168+
])(
169+
'drops the build tools of $name',
170+
async ({ purlTypes, sockJson = {} as SocketJson, tools }) => {
171+
const candidates = await findBuildToolCandidates({
172+
cwd: monorepo,
173+
purlTypes,
174+
socketConfig: undefined,
175+
sockJson,
176+
})
177+
expect([...candidates.keys()]).toEqual(tools)
178+
},
179+
)
174180

175181
it('respects --exclude-paths', async () => {
176182
const candidates = await findBuildToolCandidates({

‎src/commands/manifest/generate_auto_manifest.mts‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { handleManifestConda } from './handle-manifest-conda.mts'
1414
import { parseBuildToolOpts } from './parse-build-tool-opts.mts'
1515
import { resolveBuildToolBin } from './scripts/build-tool.mts'
1616
import { REACH_CONTINUE_ON_INSTALL_ERRORS_FLAG } from './scripts/resolution-report-render.mts'
17-
import { skipWithoutDotnetSdk } from './scripts/run.mts'
1817
import { hasSidecarEntries, serializeSidecar } from './scripts/sidecar.mts'
1918
import {
2019
ENVIRONMENT_YML,
@@ -225,21 +224,18 @@ export async function generateAutoManifest({
225224
}
226225

227226
if (!sockJson?.defaults?.manifest?.dotnet?.disabled && detected.dotnet) {
228-
const config = resolveEcosystemConfig('dotnet', cwd, sockJson)
229-
if (!(await skipWithoutDotnetSdk(config.bin, cwd))) {
230-
logger.log(
231-
'Detected a .NET solution or project, generating Socket facts...',
232-
)
233-
const outcome = await convertDotnetToFacts({
234-
config,
235-
cwd,
236-
excludePaths,
237-
hints,
238-
sidecarAcc,
239-
withFiles: computeArtifactsSidecar,
240-
})
241-
abortFactsRunIfFailed('dotnet', outcome)
242-
}
227+
logger.log(
228+
'Detected a .NET solution or project, generating Socket facts...',
229+
)
230+
const outcome = await convertDotnetToFacts({
231+
config: resolveEcosystemConfig('dotnet', cwd, sockJson),
232+
cwd,
233+
excludePaths,
234+
hints,
235+
sidecarAcc,
236+
withFiles: computeArtifactsSidecar,
237+
})
238+
abortFactsRunIfFailed('dotnet', outcome)
243239
}
244240

245241
if (!sockJson?.defaults?.manifest?.conda?.disabled && detected.conda) {

0 commit comments

Comments
 (0)