Skip to content

Commit 6748a9d

Browse files
committed
fix(scan): fail a .NET build without an SDK like any other build
Drop the dedicated .NET SDK probe from --dynamic-sbom-inference and its setup wizard: a missing SDK now fails the build root the way a missing Maven does, so the run aborts through the usual failed-root path and --json lists the root. --auto-manifest keeps warning and skipping. Also write the sidecar whenever the facts-only flag is sent, for fix as for reach, type the facts-only types as non-empty, and order the result fields.
1 parent 31723a6 commit 6748a9d

12 files changed

Lines changed: 64 additions & 132 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 stop with clear next steps when a .NET build cannot be read because no .NET SDK is installed, 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+
- `--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.
1515

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

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type GeneratedSocketFacts = {
1111
artifactsFlags: string[]
1212
paths: string[]
1313
// The facts files' per-project classpaths, written outside the repository.
14-
sidecarFile: string | undefined
14+
sidecarFile: string
1515
remove: () => Promise<void>
1616
restore: () => Promise<void>
1717
}
@@ -61,7 +61,7 @@ export async function generateSocketFactsForFix({
6161
}
6262
let artifactsFlags: string[]
6363
let paths: string[]
64-
let sidecarFile: string | undefined
64+
const sidecarFile = path.join(tmpDir, 'sidecar.json')
6565
try {
6666
const { factsOnlyTypes, factsPaths, resolvedPathsSidecar } =
6767
await runDynamicSbomInference({
@@ -73,10 +73,9 @@ export async function generateSocketFactsForFix({
7373
})
7474
artifactsFlags = useOnlySocketFactsArtifactsFlags(factsOnlyTypes)
7575
paths = factsPaths.map(p => path.resolve(cwd, p))
76-
if (resolvedPathsSidecar) {
77-
sidecarFile = path.join(tmpDir, 'sidecar.json')
78-
await writeFile(sidecarFile, JSON.stringify(resolvedPathsSidecar))
79-
}
76+
// Written even when empty, as for reach; applying fixes looks each facts
77+
// file up in it, so an empty one is the same as none.
78+
await writeFile(sidecarFile, JSON.stringify(resolvedPathsSidecar ?? {}))
8079
} catch (e) {
8180
// A failed build root aborts inference after others wrote their facts.
8281
await reset(await findFactsPaths())

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,24 @@ describe('generateSocketFactsForFix', () => {
8282
'--use-only-socket-facts-artifacts',
8383
'maven,nuget',
8484
])
85-
expect(path.dirname(sidecarFile!)).toBe(tmpDir)
86-
expect(JSON.parse(await fs.readFile(sidecarFile!, 'utf8'))).toEqual({
85+
expect(path.dirname(sidecarFile)).toBe(tmpDir)
86+
expect(JSON.parse(await fs.readFile(sidecarFile, 'utf8'))).toEqual({
8787
[fresh]: { components: [], projects: [] },
8888
})
8989
})
9090

91+
it('writes an empty sidecar when no build root resolved any paths', async () => {
92+
mockRunDynamicSbomInference.mockResolvedValue({
93+
factsOnlyTypes: ['maven'],
94+
factsPaths: [],
95+
})
96+
97+
const { artifactsFlags, sidecarFile } = await generate()
98+
99+
expect(artifactsFlags).toEqual(['--maven-use-only-socket-facts'])
100+
expect(JSON.parse(await fs.readFile(sidecarFile, 'utf8'))).toEqual({})
101+
})
102+
91103
it('restores an existing facts file that generation does not rewrite', async () => {
92104
mockRunDynamicSbomInference.mockImplementation(async () => {
93105
await fs.writeFile(fresh, 'generated')

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ import {
1818
DSI_SETUP_COMMAND,
1919
REACH_CONTINUE_ON_INSTALL_ERRORS_FLAG,
2020
} from './scripts/resolution-report-render.mts'
21-
import { noDotnetSdkReason } from './scripts/run.mts'
2221
import { SOCKET_JSON } from '../../constants.mts'
2322
import { loadSocketConfig } from '../../utils/config.mts'
24-
import { InputError } from '../../utils/errors.mts'
2523
import { withTmpDir } from '../../utils/fs.mts'
2624
import {
2725
readOrDefaultSocketJson,
@@ -213,21 +211,6 @@ async function runEcosystemCandidates({
213211
outcomes.push({ ...root, ecosystem, status: 'skippedDisabled' })
214212
continue
215213
}
216-
const socketJson = displayPath(path.join(dir, SOCKET_JSON))
217-
if (ecosystem === 'dotnet') {
218-
// eslint-disable-next-line no-await-in-loop
219-
const reason = await noDotnetSdkReason(dirConfig.bin, dir)
220-
if (reason !== undefined) {
221-
throw new InputError(
222-
[
223-
`No .NET SDK runs for ${displayPath(buildRootPath(root))} (${reason}), so its Socket facts cannot be generated.`,
224-
'',
225-
`- Install the .NET SDK, or point defaults.manifest.dotnet.bin in ${socketJson} at one (\`${DSI_SETUP_COMMAND}\` walks you through it).`,
226-
`- Or leave it out with --exclude-paths, or with defaults.manifest.dotnet.disabled in ${socketJson}.`,
227-
].join('\n'),
228-
)
229-
}
230-
}
231214
// eslint-disable-next-line no-await-in-loop
232215
const result = await buildUncoveredRoot({
233216
config: {
@@ -248,7 +231,7 @@ async function runEcosystemCandidates({
248231
: undefined,
249232
flags: optionFlags,
250233
setupCommand: DSI_SETUP_COMMAND,
251-
socketJson,
234+
socketJson: displayPath(path.join(dir, SOCKET_JSON)),
252235
},
253236
root,
254237
sidecarAcc,

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ 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),
2221
}))
2322

2423
import { buildRootPath } from './discover-manifest-roots.mts'
2524
import { generateRecursiveManifests } from './generate-recursive-manifests.mts'
2625
import { runManifestFacts } from './run-manifest-facts.mts'
27-
import { listDotnetEntryProjects, noDotnetSdkReason } from './scripts/run.mts'
26+
import { listDotnetEntryProjects } from './scripts/run.mts'
2827
import { testPath } from '../../../test/utils.mts'
2928
import {
3029
readOrDefaultSocketJson,
@@ -524,26 +523,6 @@ describe('generateRecursiveManifests', () => {
524523
})
525524
})
526525

527-
it('fails before building anything when no .NET SDK runs for a .NET build root', async () => {
528-
const dir = await fs.mkdtemp(path.join(tmpdir(), 'dsi-require-sdk-'))
529-
try {
530-
await fs.writeFile(path.join(dir, 'pom.xml'), '<project/>')
531-
await fs.writeFile(path.join(dir, 'App.csproj'), '')
532-
vi.mocked(noDotnetSdkReason).mockResolvedValueOnce('dotnet not found')
533-
vi.mocked(runManifestFacts).mockClear()
534-
535-
await expect(
536-
generateRecursiveManifests({
537-
cwd: dir,
538-
verbose: false,
539-
}),
540-
).rejects.toThrow(/No .NET SDK runs for .* \(dotnet not found\)/)
541-
expect(runManifestFacts).not.toHaveBeenCalled()
542-
} finally {
543-
await fs.rm(dir, { recursive: true, force: true })
544-
}
545-
})
546-
547526
it("does not list a solution's members for coverage another tool's builds recorded", async () => {
548527
const dir = await fs.mkdtemp(path.join(tmpdir(), 'dsi-per-tool-'))
549528
try {

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

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

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

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(
534-
bin: string,
535-
dir: string,
536-
): Promise<string | undefined> {
537-
try {
538-
await dotnetSdkVersion(bin, { projectDir: dir })
539-
return undefined
540-
} catch (e) {
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.
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.
547533
export async function skipWithoutDotnetSdk(
548534
bin: string,
549535
dir: string,
550536
): Promise<boolean> {
551-
const reason = await noDotnetSdkReason(bin, dir)
552-
if (reason === undefined) {
537+
try {
538+
await dotnetSdkVersion(bin, { projectDir: dir })
553539
return false
540+
} 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
554551
}
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-
)
560-
}
561-
return true
562552
}
563553

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

‎src/commands/manifest/setup-recursive-manifest-config.mts‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
} from './discover-manifest-roots.mts'
1919
import { enumerateWorkspaces } from './enumerate-workspaces.mts'
2020
import { resolveEcosystemConfig } from './generate-recursive-manifests.mts'
21-
import { noDotnetSdkReason } from './scripts/run.mts'
2221
import {
2322
setupDotnet,
2423
setupGradle,
@@ -241,17 +240,6 @@ export async function markWorkspaceCoverage({
241240
if (skipReason) {
242241
return { ok: true, data: undefined }
243242
}
244-
if (ecosystem === 'dotnet') {
245-
const reason = await noDotnetSdkReason(bin, dir)
246-
if (reason !== undefined) {
247-
return {
248-
ok: false,
249-
message: `No .NET SDK runs in ${path.relative(cwd, dir) || '.'} (${reason})`,
250-
cause:
251-
'Install the .NET SDK, or point defaults.manifest.dotnet.bin at one; or leave the directory out with --exclude-paths.',
252-
}
253-
}
254-
}
255243

256244
for (const root of roots) {
257245
if (

‎src/commands/manifest/setup-recursive-manifest-config.test.mts‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ vi.mock('./discover-manifest-roots.mts', async importOriginal => {
2525
vi.mock('./enumerate-workspaces.mts', () => ({
2626
enumerateWorkspaces: vi.fn(),
2727
}))
28-
vi.mock('./scripts/run.mts', async importOriginal => ({
29-
...(await importOriginal<typeof import('./scripts/run.mts')>()),
30-
noDotnetSdkReason: vi.fn(async () => undefined),
31-
}))
3228
vi.mock('@socketsecurity/registry/lib/prompts', () => ({
3329
select: vi.fn(),
3430
}))
@@ -52,7 +48,6 @@ import {
5248
findBuildToolCandidates,
5349
} from './discover-manifest-roots.mts'
5450
import { enumerateWorkspaces } from './enumerate-workspaces.mts'
55-
import { noDotnetSdkReason } from './scripts/run.mts'
5651
import { setupGradle, setupMaven, setupSbt } from './setup-manifest-config.mts'
5752
import {
5853
configureCandidate,
@@ -460,25 +455,6 @@ describe('markWorkspaceCoverage', () => {
460455
expect(covered.size).toBe(0)
461456
})
462457

463-
it('fails closed when no .NET SDK runs for a .NET root', async () => {
464-
vi.mocked(noDotnetSdkReason).mockResolvedValueOnce('dotnet not found')
465-
466-
const result = await markWorkspaceCoverage({
467-
covered: new Set<string>(),
468-
cwd,
469-
dir: reactor,
470-
ecosystem: 'dotnet',
471-
rootSockJson: emptySockJson(),
472-
roots: [{ dir: reactor, entryFile: 'App.csproj' }],
473-
})
474-
475-
expect(result).toMatchObject({
476-
ok: false,
477-
message: 'No .NET SDK runs in reactor (dotnet not found)',
478-
})
479-
expect(enumerateWorkspaces).not.toHaveBeenCalled()
480-
})
481-
482458
it('resolves settings once per directory and skips a POM an earlier one covers', async () => {
483459
vi.mocked(enumerateWorkspaces).mockResolvedValue({
484460
buildRoot: reactor,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import type { ReachabilityFallback } from './output-create-new-scan.mts'
3636
import type { ReachabilityOptions } from './perform-reachability-analysis.mts'
3737
import type { REPORT_LEVEL } from './types.mts'
3838
import type { OutputKind } from '../../types.mts'
39-
import type { PURL_Type } from '../../utils/ecosystem.mts'
39+
import type { FactsOnlyTypes } from '../../utils/coana.mts'
4040
import type { ResolvedPathsSidecar } from '../manifest/scripts/sidecar.mts'
4141
import type { Remap } from '@socketsecurity/registry/lib/objects'
4242
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
@@ -160,7 +160,7 @@ async function createNewScan(
160160

161161
// Sidecar forwarded to reachability; populated only when reach runs.
162162
let resolvedPathsSidecar: ResolvedPathsSidecar | undefined
163-
let factsOnlyTypes: PURL_Type[] | undefined
163+
let factsOnlyTypes: FactsOnlyTypes | undefined
164164

165165
// sbt provisions its Scala toolchain under the directory passed as its
166166
// isolated global base; reach's artifactPaths point into it, so it must

‎src/commands/scan/perform-reachability-analysis.mts‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { hasResolvedPathsSidecarEntries } from '../manifest/scripts/sidecar.mts'
2121
import { fetchOrganization } from '../organization/fetch-organization-list.mts'
2222

2323
import type { CResult, OutputKind } from '../../types.mts'
24+
import type { FactsOnlyTypes } from '../../utils/coana.mts'
2425
import type { PURL_Type } from '../../utils/ecosystem.mts'
2526
import type { ResolvedPathsSidecar } from '../manifest/scripts/sidecar.mts'
2627
import type { Spinner } from '@socketsecurity/registry/lib/spinner'
@@ -57,7 +58,7 @@ export type ReachabilityAnalysisOptions = {
5758
branchName?: string | undefined
5859
cwd?: string | undefined
5960
// Purl types whose artifacts Coana takes only from facts files.
60-
factsOnlyTypes?: readonly PURL_Type[] | undefined
61+
factsOnlyTypes?: FactsOnlyTypes | undefined
6162
// Required: the manifest upload they drive produces the tar hash Coana needs
6263
// to run without Docker.
6364
orgSlug: string
@@ -193,23 +194,19 @@ export async function performReachabilityAnalysis(
193194
spinner?.infoAndStop('Running reachability analysis with Coana...')
194195

195196
// Temp file for --compute-artifacts-sidecar, removed in the finally below.
196-
// Written even when empty with factsOnlyTypes, since the facts-only flag
197-
// below requires one to be present.
197+
// Written even when empty with factsOnlyTypes: `coana run` rejects the
198+
// facts-only flag without one.
198199
let sidecarPath: string | undefined
199200
if (
200-
factsOnlyTypes?.length ||
201+
factsOnlyTypes ||
201202
(resolvedPathsSidecar &&
202203
hasResolvedPathsSidecarEntries(resolvedPathsSidecar))
203204
) {
204205
sidecarPath = path.join(
205206
tmpdir(),
206207
`socket-compute-artifacts-sidecar-${randomUUID()}.json`,
207208
)
208-
await fs.writeFile(
209-
sidecarPath,
210-
JSON.stringify(resolvedPathsSidecar ?? {}),
211-
'utf8',
212-
)
209+
await fs.writeFile(sidecarPath, JSON.stringify(resolvedPathsSidecar ?? {}))
213210
}
214211

215212
// Build Coana arguments.
@@ -271,10 +268,7 @@ export async function performReachabilityAnalysis(
271268
...(reachabilityOptions.reachExcludePaths.length
272269
? ['--exclude-dirs', ...reachabilityOptions.reachExcludePaths]
273270
: []),
274-
// sidecarPath is always set above then; Coana rejects this flag without one.
275-
...(factsOnlyTypes?.length
276-
? useOnlySocketFactsArtifactsFlags(factsOnlyTypes)
277-
: []),
271+
...(factsOnlyTypes ? useOnlySocketFactsArtifactsFlags(factsOnlyTypes) : []),
278272
...(reachabilityOptions.reachSkipCache ? ['--skip-cache-usage'] : []),
279273
...(reachabilityOptions.reachUseOnlyPregeneratedSboms
280274
? ['--use-only-pregenerated-sboms']

0 commit comments

Comments
 (0)