Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -597,19 +597,12 @@
!/src/commands/manifest/convert-conda-to-requirements.mts
!/src/commands/manifest/convert-conda-to-requirements.test.mts
!/src/commands/manifest/convert-dotnet-to-facts.mts
!/src/commands/manifest/convert-gradle-to-facts.mts
!/src/commands/manifest/convert-maven-to-facts.mts
!/src/commands/manifest/convert-sbt-to-facts.mts
!/src/commands/manifest/convert_gradle_to_maven.mts
!/src/commands/manifest/convert_sbt_to_maven.mts
!/src/commands/manifest/detect-manifest-actions.mts
!/src/commands/manifest/detect-manifest-actions.test.mts
!/src/commands/manifest/discover-manifest-roots.mts
!/src/commands/manifest/discover-manifest-roots.test.mts
!/src/commands/manifest/enumerate-workspaces.mts
!/src/commands/manifest/enumerate-workspaces.test.mts
!/src/commands/manifest/expand-env-var-refs.mts
!/src/commands/manifest/expand-env-var-refs.test.mts
!/src/commands/manifest/generate-recursive-manifests.mts
!/src/commands/manifest/generate-recursive-manifests.test.mts
!/src/commands/manifest/generate_auto_manifest.mts
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

### Added
- Socket facts for a self-contained .NET build include its runtime packs.

### Changed
- Updated the Coana CLI to v `15.15.4`.
- Coana now generates Socket facts for Gradle, Maven, sbt and .NET builds, so generating them downloads Coana and needs network access and a Socket API token.
- `--reach-version` and `--fix-version` also select the Coana that generates Socket facts, which must be the pinned version or newer.
- With `--dynamic-sbom-inference`, reachability analyzes each JVM project on the classpath its build resolved, and `socket fix` restores a build's files when an upgrade does not take.
- `--ignore-unresolved` no longer lets through a build whose resolution did not run, or a failure that names no project.
- `--dynamic-sbom-inference` builds each POM by its own file, so it ignores a `--file` in `mavenOpts`, with a warning.

## [1.16.1](https://github.com/SocketDev/socket-cli/releases/tag/v1.16.1) - 2026-11-24

Expand Down
6 changes: 3 additions & 3 deletions src/commands/fix/coana-fix-dynamic-sbom-inference.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ describe('socket fix --dynamic-sbom-inference', () => {
)
const args = coanaCalls('compute-fixes-and-upgrade-purls')[0]!
expect(args).toContain('--maven-use-only-socket-facts')
expect(args).toContain('--compute-artifacts-sidecar')
expect(args[args.indexOf('--compute-artifacts-sidecar') + 1]).toBe(
expect(args).toContain('--socket-facts-sidecar')
expect(args[args.indexOf('--socket-facts-sidecar') + 1]).toBe(
generated.sidecarFile,
)
expect(generated.remove).toHaveBeenCalledTimes(1)
Expand All @@ -178,7 +178,7 @@ describe('socket fix --dynamic-sbom-inference', () => {

const args = coanaCalls('find-vulnerabilities')[0]
expect(args).toContain('--maven-use-only-socket-facts')
expect(args).not.toContain('--compute-artifacts-sidecar')
expect(args).not.toContain('--socket-facts-sidecar')
})

it('regenerates facts files that were already present, uploading each once', async () => {
Expand Down
9 changes: 5 additions & 4 deletions src/commands/fix/coana-fix.mts
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,13 @@ async function coanaFixWithFacts(
logger.info('Generating Socket facts for each build ...')
}
factsSlot.generated = await generateSocketFactsForFix({
coanaVersion,
cwd,
excludePaths,
purlTypes: factsSlot.purlTypes,
findFactsPaths: async () =>
(await findScanFilepaths()).filter(isSocketFactsFile),
orgSlug,
tmpDir: factsSlot.tmpDir,
})
scanFilepaths = await withoutDiscardedFacts(
Expand All @@ -414,13 +416,12 @@ async function coanaFixWithFacts(
}
}
const sidecarFile = factsSlot?.generated?.sidecarFile
// Discovery only needs which artifacts the facts files resolve. Applying
// fixes reads each project's tree; a Coana predating facts trees can only
// tell from the sidecar's classpaths which projects resolve an artifact.
// Discovery reads the artifacts resolved by the facts files.
// Applying a fix also reads the saved state for each build root.
const discoveryFlags = factsSlot?.generated?.artifactsFlags ?? []
const factsFlags = [
...discoveryFlags,
...(sidecarFile ? ['--compute-artifacts-sidecar', sidecarFile] : []),
...(sidecarFile ? ['--socket-facts-sidecar', sidecarFile] : []),
]
const uploadCResult = await handleApiCall(
sockSdk.uploadManifestFiles(orgSlug, scanFilepaths, {
Expand Down
39 changes: 23 additions & 16 deletions src/commands/fix/generated-socket-facts.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { useOnlySocketFactsArtifactsFlags } from '../../utils/coana.mts'
import { runDynamicSbomInference } from '../scan/run-dynamic-sbom-inference.mts'

import type { PURL_Type } from '../../utils/ecosystem.mts'
import type { KeptRootsDir } from '../scan/run-dynamic-sbom-inference.mts'

export type GeneratedSocketFacts = {
// Coana's flags selecting what the facts files resolve.
artifactsFlags: string[]
// Facts files of dropped runs, which Coana must not read.
discardedPaths: string[]
paths: string[]
// The facts files' per-project classpaths, written outside the repository.
// Records each build root's saved state for `--socket-facts-sidecar`.
// The file lives outside the repository.
sidecarFile: string
remove: () => Promise<void>
restore: () => Promise<void>
Expand Down Expand Up @@ -40,15 +42,19 @@ async function restoreAll(backups: Backup[]): Promise<void> {
// Backed up so each fix attempt sees the pre-fix build after `git clean`, and
// facts files already present are left as they were found.
export async function generateSocketFactsForFix({
coanaVersion,
cwd,
excludePaths,
findFactsPaths,
orgSlug,
purlTypes,
tmpDir,
}: {
coanaVersion?: string | undefined
cwd: string
excludePaths: string[]
findFactsPaths: () => Promise<string[]>
orgSlug?: string | undefined
purlTypes: readonly PURL_Type[]
tmpDir: string
}): Promise<GeneratedSocketFacts> {
Expand All @@ -65,25 +71,27 @@ export async function generateSocketFactsForFix({
let discardedPaths: string[]
let paths: string[]
const sidecarFile = path.join(tmpDir, 'sidecar.json')
const workDir: KeptRootsDir = {
dir: path.join(tmpDir, 'work'),
entries: new Map(),
}
await mkdir(workDir.dir)
try {
const {
discardedFactsPaths,
factsOnlyTypes,
factsPaths,
resolvedPathsSidecar,
} = await runDynamicSbomInference({
consumer: 'fix',
cwd,
excludePaths,
purlTypes,
sbtTmpDir: undefined,
})
const { discardedFactsPaths, factsOnlyTypes, factsPaths } =
await runDynamicSbomInference({
consumer: 'fix',
context: { coanaVersion, orgSlug },
cwd,
excludePaths,
purlTypes,
workDir,
})
artifactsFlags = useOnlySocketFactsArtifactsFlags(factsOnlyTypes)
discardedPaths = discardedFactsPaths
paths = factsPaths.map(p => path.resolve(cwd, p))
// Written even when empty, as for reach; applying fixes looks each facts
// file up in it, so an empty one is the same as none.
await writeFile(sidecarFile, JSON.stringify(resolvedPathsSidecar ?? {}))
await writeFile(sidecarFile, JSON.stringify([...workDir.entries.values()]))
} catch (e) {
// A failed build root aborts inference after others wrote their facts.
await reset(await findFactsPaths())
Expand All @@ -99,8 +107,7 @@ export async function generateSocketFactsForFix({
discardedPaths,
paths,
sidecarFile,
// A discarded file a run left as written is removed too.
remove: () => reset([...paths, ...discardedPaths]),
remove: () => reset(paths),
restore: () => restoreAll(backups),
}
}
46 changes: 19 additions & 27 deletions src/commands/fix/generated-socket-facts.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -67,51 +67,43 @@ describe('generateSocketFactsForFix', () => {
expect(existsSync(fresh)).toBe(false)
})

it('removes a discarded facts file a dropped run left behind', async () => {
const discarded = path.join(cwd, 'sub', 'pom.xml.socket.facts.json')
mockRunDynamicSbomInference.mockImplementation(async () => {
await fs.writeFile(discarded, 'dropped')
return {
discardedFactsPaths: [discarded, existing],
factsOnlyTypes: ['maven'],
factsPaths: [],
}
})

const generated = await generate()
await generated.remove()

expect(existsSync(discarded)).toBe(false)
expect(await fs.readFile(existing, 'utf8')).toBe('original')
})

it('writes the sidecar outside the repository', async () => {
mockRunDynamicSbomInference.mockImplementation(async () => {
it('keeps what Coana kept of each build root outside the repository', async () => {
const entry = { factsFile: fresh, stateDir: path.join(tmpDir, 'work', 'x') }
let workDirExisted = false
mockRunDynamicSbomInference.mockImplementation(async ({ workDir }) => {
workDirExisted = existsSync(workDir.dir)
await fs.writeFile(fresh, 'generated')
workDir.entries.set(entry.factsFile, entry)
return {
discardedFactsPaths: [],
factsOnlyTypes: ['maven', 'nuget'],
factsPaths: [fresh],
resolvedPathsSidecar: { [fresh]: { components: [], projects: [] } },
}
})

const { artifactsFlags, sidecarFile } = await generate()

expect(workDirExisted).toBe(true)
expect(mockRunDynamicSbomInference).toHaveBeenCalledWith(
expect.objectContaining({ consumer: 'fix', purlTypes: ['maven'] }),
expect.objectContaining({
consumer: 'fix',
context: { coanaVersion: undefined, orgSlug: undefined },
purlTypes: ['maven'],
workDir: {
dir: path.join(tmpDir, 'work'),
entries: new Map([[entry.factsFile, entry]]),
},
}),
)
expect(artifactsFlags).toEqual([
'--use-only-socket-facts-artifacts',
'maven,nuget',
])
expect(path.dirname(sidecarFile)).toBe(tmpDir)
expect(JSON.parse(await fs.readFile(sidecarFile, 'utf8'))).toEqual({
[fresh]: { components: [], projects: [] },
})
expect(JSON.parse(await fs.readFile(sidecarFile, 'utf8'))).toEqual([entry])
})

it('writes an empty sidecar when no build root resolved any paths', async () => {
it('writes an empty sidecar when no build root generated facts', async () => {
mockRunDynamicSbomInference.mockResolvedValue({
discardedFactsPaths: [],
factsOnlyTypes: ['maven'],
Expand All @@ -121,7 +113,7 @@ describe('generateSocketFactsForFix', () => {
const { artifactsFlags, sidecarFile } = await generate()

expect(artifactsFlags).toEqual(['--maven-use-only-socket-facts'])
expect(JSON.parse(await fs.readFile(sidecarFile, 'utf8'))).toEqual({})
expect(JSON.parse(await fs.readFile(sidecarFile, 'utf8'))).toEqual([])
})

it('restores an existing facts file that generation does not rewrite', async () => {
Expand Down
20 changes: 9 additions & 11 deletions src/commands/manifest/cmd-manifest-auto.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import path from 'node:path'
import { detectManifestActions } from './detect-manifest-actions.mts'
import { generateAutoManifest } from './generate_auto_manifest.mts'
import { excludePathsFlag } from './manifest-flags.mts'
import { EXCLUDE_PATHS_FLAG } from './run-manifest-facts.mts'
import constants from '../../constants.mts'
import { commonFlags } from '../../flags.mts'
import { cmdFlagValueToArray } from '../../utils/cmd.mts'
import { debugDir } from '../../utils/debug.mts'
import { withTmpDir } from '../../utils/fs.mts'
import { getOutputKind } from '../../utils/get-output-kind.mts'
import { logger } from '../../utils/logger.mts'
import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
Expand Down Expand Up @@ -124,16 +124,14 @@ async function run(
const excludePaths = cmdFlagValueToArray(cli.flags['excludePaths'])
assertValidExcludePaths(excludePaths)

await withTmpDir('socket-manifest-auto-', tmpDir =>
generateAutoManifest({
detected,
cwd,
excludePaths,
outputKind,
tmpDir,
verbose,
}),
)
await generateAutoManifest({
detected,
cwd,
excludePaths,
excludePathsFlag: EXCLUDE_PATHS_FLAG,
outputKind,
verbose,
})

logger.success(
`Finished. Should have attempted to generate manifest files for ${detected.count} targets.`,
Expand Down
7 changes: 4 additions & 3 deletions src/commands/manifest/cmd-manifest-gradle.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'node:path'

import { convertGradleToFacts } from './convert-gradle-to-facts.mts'
import { convertGradleToMaven } from './convert_gradle_to_maven.mts'
import { excludePathsFlag } from './manifest-flags.mts'
import { parseBuildToolOpts } from './parse-build-tool-opts.mts'
import { runManifestFacts } from './run-manifest-facts.mts'
import { resolveBuildToolBin } from './scripts/build-tool.mts'
import constants, { REQUIREMENTS_TXT, SOCKET_JSON } from '../../constants.mts'
import { commonFlags } from '../../flags.mts'
Expand Down Expand Up @@ -296,12 +296,13 @@ async function run(
assertValidExcludePaths(excludePaths)

if (facts) {
await convertGradleToFacts({
await runManifestFacts({
bin: String(bin),
buildOpts: parsedGradleOpts,
cwd,
ecosystem: 'gradle',
excludeConfigs: String(excludeConfigs || ''),
excludePaths,
gradleOpts: parsedGradleOpts,
ignoreUnresolved: Boolean(ignoreUnresolved),
includeConfigs: String(includeConfigs || ''),
javaHome,
Expand Down
7 changes: 4 additions & 3 deletions src/commands/manifest/cmd-manifest-kotlin.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'node:path'

import { convertGradleToFacts } from './convert-gradle-to-facts.mts'
import { convertGradleToMaven } from './convert_gradle_to_maven.mts'
import { excludePathsFlag } from './manifest-flags.mts'
import { parseBuildToolOpts } from './parse-build-tool-opts.mts'
import { runManifestFacts } from './run-manifest-facts.mts'
import { resolveBuildToolBin } from './scripts/build-tool.mts'
import constants, { REQUIREMENTS_TXT, SOCKET_JSON } from '../../constants.mts'
import { commonFlags } from '../../flags.mts'
Expand Down Expand Up @@ -299,12 +299,13 @@ async function run(
assertValidExcludePaths(excludePaths)

if (facts) {
await convertGradleToFacts({
await runManifestFacts({
bin: String(bin),
buildOpts: parsedGradleOpts,
cwd,
ecosystem: 'gradle',
excludeConfigs: String(excludeConfigs || ''),
excludePaths,
gradleOpts: parsedGradleOpts,
ignoreUnresolved: Boolean(ignoreUnresolved),
includeConfigs: String(includeConfigs || ''),
javaHome,
Expand Down
7 changes: 4 additions & 3 deletions src/commands/manifest/cmd-manifest-maven.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path'

import { convertMavenToFacts } from './convert-maven-to-facts.mts'
import { excludePathsFlag } from './manifest-flags.mts'
import { parseBuildToolOpts } from './parse-build-tool-opts.mts'
import { runManifestFacts } from './run-manifest-facts.mts'
import { resolveBuildToolBin } from './scripts/build-tool.mts'
import constants, { SOCKET_JSON } from '../../constants.mts'
import { commonFlags } from '../../flags.mts'
Expand Down Expand Up @@ -233,15 +233,16 @@ async function run(
const excludePaths = cmdFlagValueToArray(cli.flags['excludePaths'])
assertValidExcludePaths(excludePaths)

await convertMavenToFacts({
await runManifestFacts({
bin: String(bin),
buildOpts: parsedMavenOpts,
cwd,
ecosystem: 'maven',
excludeConfigs: String(excludeConfigs || ''),
excludePaths,
ignoreUnresolved: Boolean(ignoreUnresolved),
includeConfigs: String(includeConfigs || ''),
javaHome,
mavenOpts: parsedMavenOpts,
verbose: Boolean(verbose),
})
}
Loading
Loading