Skip to content

Commit af3e558

Browse files
jfblaaclaude
andcommitted
fix(scan): make every discovered ecosystem facts-only under --dynamic-sbom-inference
Coana was told NuGet artifacts come only from facts files when some .NET build root happened to produce facts, and Maven always. Which raw manifests reachability and fix trusted therefore depended on what other build roots produced. Every ecosystem a build root was discovered for is now facts-only, generated or not; Maven alone keeps the older flag. When Coana consumes the facts, a .NET build root without a usable SDK now fails before any build runs instead of silently losing its dependencies, reachability fails clearly when no build root produced facts (Coana refuses such a run), and roots skipped in socket.json get a warning that the analysis leaves them out. Callers now name the facts consumer (fix or reach) instead of passing withFiles/sidecar flags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7de3bc7 commit af3e558

32 files changed

Lines changed: 354 additions & 112 deletions

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [Unreleased]
8+
9+
### Changed
10+
- 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.
11+
- With `--dynamic-sbom-inference`, reachability analysis and `socket fix` now stop with clear next steps when a .NET build cannot be read because no .NET SDK is installed, and warn that builds skipped in `socket.json` are left out. Reachability analysis also stops with next steps when no build produced Socket facts.
12+
713
## [1.13.1](https://github.com/SocketDev/socket-cli/releases/tag/v1.13.1) - 2026-11-03
814

915
### Fixed

‎src/commands/fix/generated-socket-facts.mts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ export async function generateSocketFactsForFix({
5959
let paths: string[]
6060
let sidecarFile: string | undefined
6161
try {
62-
const { factsPaths, resolvedPathsSidecar } = await runDynamicSbomInference({
63-
cwd,
64-
excludePaths,
65-
sbtTmpDir: undefined,
66-
sidecar: true,
67-
withFiles: false,
68-
})
69-
artifactsFlags = useOnlySocketFactsArtifactsFlags(resolvedPathsSidecar)
62+
const { factsOnlyTypes, factsPaths, resolvedPathsSidecar } =
63+
await runDynamicSbomInference({
64+
consumer: 'fix',
65+
cwd,
66+
excludePaths,
67+
sbtTmpDir: undefined,
68+
})
69+
artifactsFlags = useOnlySocketFactsArtifactsFlags(factsOnlyTypes)
7070
paths = factsPaths.map(p => path.resolve(cwd, p))
7171
if (resolvedPathsSidecar) {
7272
sidecarFile = path.join(tmpDir, 'sidecar.json')

‎src/commands/fix/generated-socket-facts.test.mts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('generateSocketFactsForFix', () => {
4545
mockRunDynamicSbomInference.mockImplementation(async () => {
4646
await fs.writeFile(existing, 'regenerated')
4747
await fs.writeFile(fresh, 'generated')
48-
return { factsPaths: [existing, fresh] }
48+
return { factsOnlyTypes: ['maven'], factsPaths: [existing, fresh] }
4949
})
5050

5151
const generated = await generate()
@@ -66,6 +66,7 @@ describe('generateSocketFactsForFix', () => {
6666
mockRunDynamicSbomInference.mockImplementation(async () => {
6767
await fs.writeFile(fresh, 'generated')
6868
return {
69+
factsOnlyTypes: ['maven', 'nuget'],
6970
factsPaths: [fresh],
7071
resolvedPathsSidecar: { [fresh]: { components: [], projects: [] } },
7172
}
@@ -74,9 +75,12 @@ describe('generateSocketFactsForFix', () => {
7475
const { artifactsFlags, sidecarFile } = await generate()
7576

7677
expect(mockRunDynamicSbomInference).toHaveBeenCalledWith(
77-
expect.objectContaining({ sidecar: true }),
78+
expect.objectContaining({ consumer: 'fix' }),
7879
)
79-
expect(artifactsFlags).toEqual(['--maven-use-only-socket-facts'])
80+
expect(artifactsFlags).toEqual([
81+
'--use-only-socket-facts-artifacts',
82+
'maven,nuget',
83+
])
8084
expect(path.dirname(sidecarFile!)).toBe(tmpDir)
8185
expect(JSON.parse(await fs.readFile(sidecarFile!, 'utf8'))).toEqual({
8286
[fresh]: { components: [], projects: [] },
@@ -86,7 +90,7 @@ describe('generateSocketFactsForFix', () => {
8690
it('restores an existing facts file that generation does not rewrite', async () => {
8791
mockRunDynamicSbomInference.mockImplementation(async () => {
8892
await fs.writeFile(fresh, 'generated')
89-
return { factsPaths: [fresh] }
93+
return { factsOnlyTypes: ['maven'], factsPaths: [fresh] }
9094
})
9195

9296
const generated = await generate()

‎src/commands/manifest/generate-recursive-manifests.mts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import {
1818
DSI_SETUP_COMMAND,
1919
REACH_CONTINUE_ON_INSTALL_ERRORS_FLAG,
2020
} from './scripts/resolution-report-render.mts'
21-
import { skipWithoutDotnetSdk } from './scripts/run.mts'
21+
import { noDotnetSdkReason, skipWithoutDotnetSdk } from './scripts/run.mts'
2222
import { SOCKET_JSON } from '../../constants.mts'
2323
import { loadSocketConfig } from '../../utils/config.mts'
24+
import { InputError } from '../../utils/errors.mts'
2425
import { withTmpDir } from '../../utils/fs.mts'
2526
import {
2627
readOrDefaultSocketJson,
@@ -152,6 +153,7 @@ async function runEcosystemCandidates({
152153
ignoreUnresolved: ignoreUnresolvedOverride,
153154
optionFlags,
154155
realCwd,
156+
requireDotnetSdk,
155157
rootSockJson,
156158
sbtTmpDir,
157159
sidecarAcc,
@@ -163,6 +165,7 @@ async function runEcosystemCandidates({
163165
ignoreUnresolved: boolean | undefined
164166
optionFlags: ReadonlySet<BuildOption>
165167
realCwd: string
168+
requireDotnetSdk: boolean | undefined
166169
rootSockJson: SocketJson
167170
// sbt only: a shared global base reused across every sbt root in this run,
168171
// so sbt's own Scala-toolchain cache under <base>/boot survives between
@@ -212,7 +215,20 @@ async function runEcosystemCandidates({
212215
outcomes.push({ ...root, ecosystem, status: 'skippedDisabled' })
213216
continue
214217
}
215-
if (
218+
if (ecosystem === 'dotnet' && requireDotnetSdk) {
219+
// eslint-disable-next-line no-await-in-loop
220+
const reason = await noDotnetSdkReason(dirConfig.bin, dir)
221+
if (reason !== undefined) {
222+
throw new InputError(
223+
[
224+
`No .NET SDK runs for ${displayPath(buildRootPath(root))} (${reason}), so it has no Socket facts, and the analysis takes .NET dependencies only from them.`,
225+
'',
226+
'- Install the .NET SDK, or point defaults.manifest.dotnet.bin in socket.json at one.',
227+
'- Or leave it out with --exclude-paths, or with defaults.manifest.dotnet.disabled in socket.json.',
228+
].join('\n'),
229+
)
230+
}
231+
} else if (
216232
ecosystem === 'dotnet' &&
217233
// eslint-disable-next-line no-await-in-loop
218234
(await skipWithoutDotnetSdk(dirConfig.bin, dir))
@@ -355,6 +371,7 @@ export async function generateRecursiveManifests({
355371
excludePaths,
356372
ignoreUnresolved,
357373
optionFlags = new Set(),
374+
requireDotnetSdk,
358375
sbtTmpDir,
359376
sidecarAcc,
360377
verbose,
@@ -367,6 +384,8 @@ export async function generateRecursiveManifests({
367384
// Options the invoking command takes as flags; hints send the rest to each
368385
// build root's socket.json.
369386
optionFlags?: ReadonlySet<BuildOption> | undefined
387+
// Fail instead of skipping a .NET build root no .NET SDK can build.
388+
requireDotnetSdk?: boolean | undefined
370389
// Reachability path only: caller-supplied directory to use as sbt's shared
371390
// global base across every sbt root in this run. sbt provisions the Scala
372391
// toolchain under `<base>/boot`, which withFiles' artifactPaths point into,
@@ -405,6 +424,7 @@ export async function generateRecursiveManifests({
405424
ignoreUnresolved,
406425
optionFlags,
407426
realCwd,
427+
requireDotnetSdk,
408428
rootSockJson,
409429
sbtTmpDir: resolvedSbtTmpDir,
410430
sidecarAcc,

‎src/commands/manifest/generate-recursive-manifests.test.mts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ vi.mock('./run-manifest-facts.mts', () => ({
1818
vi.mock('./scripts/run.mts', async importOriginal => ({
1919
...(await importOriginal<typeof import('./scripts/run.mts')>()),
2020
listDotnetEntryProjects: vi.fn(async () => undefined),
21+
noDotnetSdkReason: vi.fn(async () => undefined),
2122
skipWithoutDotnetSdk: vi.fn(async () => false),
2223
}))
2324

@@ -26,6 +27,7 @@ import { generateRecursiveManifests } from './generate-recursive-manifests.mts'
2627
import { runManifestFacts } from './run-manifest-facts.mts'
2728
import {
2829
listDotnetEntryProjects,
30+
noDotnetSdkReason,
2931
skipWithoutDotnetSdk,
3032
} from './scripts/run.mts'
3133
import { testPath } from '../../../test/utils.mts'
@@ -527,6 +529,28 @@ describe('generateRecursiveManifests', () => {
527529
})
528530
})
529531

532+
it('fails before building anything when a .NET build root needs an SDK that does not run', async () => {
533+
const dir = await fs.mkdtemp(path.join(tmpdir(), 'dsi-require-sdk-'))
534+
try {
535+
await fs.writeFile(path.join(dir, 'pom.xml'), '<project/>')
536+
await fs.writeFile(path.join(dir, 'App.csproj'), '')
537+
vi.mocked(noDotnetSdkReason).mockResolvedValueOnce('dotnet not found')
538+
vi.mocked(runManifestFacts).mockClear()
539+
540+
await expect(
541+
generateRecursiveManifests({
542+
cwd: dir,
543+
requireDotnetSdk: true,
544+
verbose: false,
545+
}),
546+
).rejects.toThrow(/No .NET SDK runs for .* \(dotnet not found\)/)
547+
expect(skipWithoutDotnetSdk).not.toHaveBeenCalled()
548+
expect(runManifestFacts).not.toHaveBeenCalled()
549+
} finally {
550+
await fs.rm(dir, { recursive: true, force: true })
551+
}
552+
})
553+
530554
it('skips .NET builds, without failing, where no .NET SDK runs', async () => {
531555
const dir = await fs.mkdtemp(path.join(tmpdir(), 'dsi-no-sdk-'))
532556
try {

‎src/commands/manifest/scripts/run.mts‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -528,27 +528,37 @@ async function readDotnetSdkVersion(
528528

529529
const noSdkWarnings = new Set<string>()
530530

531-
// True, after a warning, when no .NET SDK runs in `dir` (none installed, or
532-
// none matching its global.json), so its .NET builds are skipped.
533-
export async function skipWithoutDotnetSdk(
531+
// Why no .NET SDK runs in `dir` (none installed, or none matching its
532+
// global.json), or undefined when one does.
533+
export async function noDotnetSdkReason(
534534
bin: string,
535535
dir: string,
536-
): Promise<boolean> {
536+
): Promise<string | undefined> {
537537
try {
538538
await dotnetSdkVersion(bin, { projectDir: dir })
539-
return false
539+
return undefined
540540
} catch (e) {
541-
const reason = getErrorMessageOr(e, `\`${bin} --version\` failed`).split(
542-
'\n',
543-
)[0]!
544-
if (!noSdkWarnings.has(reason)) {
545-
noSdkWarnings.add(reason)
546-
logger.warn(
547-
`Skipping .NET builds where no .NET SDK runs (${reason}); their project files are scanned as they are.`,
548-
)
549-
}
550-
return true
541+
return getErrorMessageOr(e, `\`${bin} --version\` failed`).split('\n')[0]!
542+
}
543+
}
544+
545+
// True, after a warning, when no .NET SDK runs in `dir`, so its .NET builds
546+
// are skipped.
547+
export async function skipWithoutDotnetSdk(
548+
bin: string,
549+
dir: string,
550+
): Promise<boolean> {
551+
const reason = await noDotnetSdkReason(bin, dir)
552+
if (reason === undefined) {
553+
return false
554+
}
555+
if (!noSdkWarnings.has(reason)) {
556+
noSdkWarnings.add(reason)
557+
logger.warn(
558+
`Skipping .NET builds where no .NET SDK runs (${reason}); their project files are scanned as they are.`,
559+
)
551560
}
561+
return true
552562
}
553563

554564
// Runs the bundled tool against the build's own dotnet, in `mode` (none: a

‎src/commands/manifest/scripts/sidecar.mts‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,12 @@ export function serializeSidecar(
158158
return result
159159
}
160160

161-
// Tells Coana which ecosystems' artifacts only these facts files attribute.
162-
// Maven's always are (the dynamic-SBOM-inference contract), under its own flag
163-
// every Coana release knows unless another ecosystem's facts are present too.
161+
// Facts-only whether or not any facts were generated. Maven alone keeps the
162+
// older flag, which Coana releases before 15.14.1 also know.
164163
export function useOnlySocketFactsArtifactsFlags(
165-
sidecar: ResolvedPathsSidecar | undefined,
164+
types: readonly string[],
166165
): string[] {
167-
const types = new Set(['maven'])
168-
for (const entry of Object.values(sidecar ?? {})) {
169-
for (const item of [...entry.projects, ...entry.components]) {
170-
types.add(item.type)
171-
}
172-
}
173-
return types.size === 1
166+
return types.length === 1 && types[0] === 'maven'
174167
? ['--maven-use-only-socket-facts']
175168
: ['--use-only-socket-facts-artifacts', [...types].sort().join(',')]
176169
}

‎src/commands/manifest/scripts/sidecar.test.mts‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -423,27 +423,21 @@ describe('compute-artifacts sidecar', () => {
423423
})
424424
})
425425

426-
function entryOfType(type: string) {
427-
return { projects: [], components: [{ type, name: 'x', id: 'x' }] }
428-
}
429-
430426
describe('useOnlySocketFactsArtifactsFlags', () => {
431-
it('keeps the Maven-only flag every Coana release knows for JVM facts', () => {
432-
expect(useOnlySocketFactsArtifactsFlags(undefined)).toEqual([
427+
it('keeps the Maven-only flag every Coana release knows for Maven alone', () => {
428+
expect(useOnlySocketFactsArtifactsFlags(['maven'])).toEqual([
433429
'--maven-use-only-socket-facts',
434430
])
435-
expect(
436-
useOnlySocketFactsArtifactsFlags({
437-
'/a/pom.xml.socket.facts.json': entryOfType('maven'),
438-
}),
439-
).toEqual(['--maven-use-only-socket-facts'])
440431
})
441432

442-
it('names every ecosystem once another one has facts', () => {
443-
expect(
444-
useOnlySocketFactsArtifactsFlags({
445-
'/a/App.sln.socket.facts.json': entryOfType('nuget'),
446-
}),
447-
).toEqual(['--use-only-socket-facts-artifacts', 'maven,nuget'])
433+
it('names every other selection, sorted', () => {
434+
expect(useOnlySocketFactsArtifactsFlags(['nuget', 'maven'])).toEqual([
435+
'--use-only-socket-facts-artifacts',
436+
'maven,nuget',
437+
])
438+
expect(useOnlySocketFactsArtifactsFlags(['nuget'])).toEqual([
439+
'--use-only-socket-facts-artifacts',
440+
'nuget',
441+
])
448442
})
449443
})

0 commit comments

Comments
 (0)