diff --git a/src/commands/fix/coana-fix-dynamic-sbom-inference.test.mts b/src/commands/fix/coana-fix-dynamic-sbom-inference.test.mts index b62fe4bfe..0c2f2409b 100644 --- a/src/commands/fix/coana-fix-dynamic-sbom-inference.test.mts +++ b/src/commands/fix/coana-fix-dynamic-sbom-inference.test.mts @@ -122,7 +122,7 @@ describe('socket fix --dynamic-sbom-inference', () => { } const uploadManifestFiles = vi.fn() const generated = { - artifactsFlags: ['--maven-use-only-socket-facts'], + factsOnlyTypes: ['maven'], paths: [FACTS], sidecarFile: '/tmp/socket-fix-facts/sidecar.json', remove: vi.fn(), @@ -155,7 +155,7 @@ describe('socket fix --dynamic-sbom-inference', () => { { pathsRelativeTo: '/test/cwd' }, ) const args = coanaCalls('compute-fixes-and-upgrade-purls')[0]! - expect(args).toContain('--maven-use-only-socket-facts') + expect(args).toContain('--use-only-socket-facts-artifacts') expect(args).toContain('--socket-facts-sidecar') expect(args[args.indexOf('--socket-facts-sidecar') + 1]).toBe( generated.sidecarFile, @@ -177,7 +177,7 @@ describe('socket fix --dynamic-sbom-inference', () => { await coanaFix({ ...baseConfig, all: true, ghsas: [] }) const args = coanaCalls('find-vulnerabilities')[0] - expect(args).toContain('--maven-use-only-socket-facts') + expect(args).toContain('--use-only-socket-facts-artifacts') expect(args).not.toContain('--socket-facts-sidecar') }) @@ -225,7 +225,7 @@ describe('socket fix --dynamic-sbom-inference', () => { expect(mockGenerateSocketFactsForFix).not.toHaveBeenCalled() expect(coanaCalls('compute-fixes-and-upgrade-purls')[0]).not.toContain( - '--maven-use-only-socket-facts', + '--use-only-socket-facts-artifacts', ) }) diff --git a/src/commands/fix/coana-fix.mts b/src/commands/fix/coana-fix.mts index 87f4761e8..735a67c28 100644 --- a/src/commands/fix/coana-fix.mts +++ b/src/commands/fix/coana-fix.mts @@ -24,6 +24,7 @@ import { import { handleApiCall } from '../../utils/api.mts' import { joinAnd } from '../../utils/arrays.mts' import { spawnCoana } from '../../utils/coana/release.mts' +import { useOnlySocketFactsArtifactsFlags } from '../../utils/coana.mts' import { isReachabilityReportPath, isSocketFactsFile, @@ -417,7 +418,9 @@ async function coanaFixWithFacts( const sidecarFile = factsSlot?.generated?.sidecarFile // 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 discoveryFlags = factsSlot?.generated + ? useOnlySocketFactsArtifactsFlags(factsSlot.generated.factsOnlyTypes) + : [] const factsFlags = [ ...discoveryFlags, ...(sidecarFile ? ['--socket-facts-sidecar', sidecarFile] : []), diff --git a/src/commands/fix/generated-socket-facts.mts b/src/commands/fix/generated-socket-facts.mts index 78ebf82e0..289be5c2b 100644 --- a/src/commands/fix/generated-socket-facts.mts +++ b/src/commands/fix/generated-socket-facts.mts @@ -1,7 +1,6 @@ import { copyFile, mkdir, rm, writeFile } from 'node:fs/promises' import path from 'node:path' -import { useOnlySocketFactsArtifactsFlags } from '../../utils/coana.mts' import { EXCLUDE_PATHS_HINTS, createSocketFactsWorkDir, @@ -9,14 +8,15 @@ import { } from '../manifest/run-manifest-facts.mts' import { runDynamicSbomInference } from '../scan/run-dynamic-sbom-inference.mts' +import type { FactsOnlyTypes } from '../../utils/coana.mts' import type { PURL_Type } from '../../utils/ecosystem.mts' import type { SocketFactsContext } from '../manifest/run-manifest-facts.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[] + // The purl types whose artifacts Coana takes from the facts files alone. + factsOnlyTypes: FactsOnlyTypes paths: string[] // Records each build root's saved state for `--socket-facts-sidecar`. // The file lives outside the repository. @@ -70,8 +70,8 @@ export async function generateSocketFactsForFix({ ) await restoreAll(originals) } - let artifactsFlags: string[] let discardedPaths: string[] + let factsOnlyTypes: FactsOnlyTypes let paths: string[] const sidecarFile = path.join(tmpDir, 'sidecar.json') const workDir = await createSocketFactsWorkDir( @@ -79,17 +79,16 @@ export async function generateSocketFactsForFix({ 'fix', ) try { - const { discardedFactsPaths, factsOnlyTypes, factsPaths } = - await runDynamicSbomInference({ - context: { ...context, workDir }, - cwd, - excludePaths, - hints: EXCLUDE_PATHS_HINTS, - purlTypes, - }) - artifactsFlags = useOnlySocketFactsArtifactsFlags(factsOnlyTypes) - discardedPaths = discardedFactsPaths - paths = factsPaths.map(p => path.resolve(cwd, p)) + const inferred = await runDynamicSbomInference({ + context: { ...context, workDir }, + cwd, + excludePaths, + hints: EXCLUDE_PATHS_HINTS, + purlTypes, + }) + discardedPaths = inferred.discardedFactsPaths + factsOnlyTypes = inferred.factsOnlyTypes + paths = inferred.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(socketFactsSidecar(workDir))) @@ -104,8 +103,8 @@ export async function generateSocketFactsForFix({ ...(await backUp(paths, path.join(tmpDir, 'generated'))), ] return { - artifactsFlags, discardedPaths, + factsOnlyTypes, paths, sidecarFile, remove: () => reset(paths), diff --git a/src/commands/fix/generated-socket-facts.test.mts b/src/commands/fix/generated-socket-facts.test.mts index 683d1ef89..9abc8c3cb 100644 --- a/src/commands/fix/generated-socket-facts.test.mts +++ b/src/commands/fix/generated-socket-facts.test.mts @@ -82,7 +82,7 @@ describe('generateSocketFactsForFix', () => { } }) - const { artifactsFlags, sidecarFile } = await generate() + const { factsOnlyTypes, sidecarFile } = await generate() expect(workDirExisted).toBe(true) expect(mockRunDynamicSbomInference).toHaveBeenCalledWith( @@ -99,10 +99,7 @@ describe('generateSocketFactsForFix', () => { purlTypes: ['maven'], }), ) - expect(artifactsFlags).toEqual([ - '--use-only-socket-facts-artifacts', - 'maven,nuget', - ]) + expect(factsOnlyTypes).toEqual(['maven', 'nuget']) expect(path.dirname(sidecarFile)).toBe(tmpDir) expect(JSON.parse(await fs.readFile(sidecarFile, 'utf8'))).toEqual([entry]) }) @@ -114,9 +111,9 @@ describe('generateSocketFactsForFix', () => { factsPaths: [], }) - const { artifactsFlags, sidecarFile } = await generate() + const { factsOnlyTypes, sidecarFile } = await generate() - expect(artifactsFlags).toEqual(['--maven-use-only-socket-facts']) + expect(factsOnlyTypes).toEqual(['maven']) expect(JSON.parse(await fs.readFile(sidecarFile, 'utf8'))).toEqual([]) }) diff --git a/src/commands/scan/perform-reachability-analysis.test.mts b/src/commands/scan/perform-reachability-analysis.test.mts index 7f2ea4980..55c862b97 100644 --- a/src/commands/scan/perform-reachability-analysis.test.mts +++ b/src/commands/scan/perform-reachability-analysis.test.mts @@ -267,11 +267,7 @@ async function coanaArgsFor( function factsOnlyArgs(args: string[]): string[] { return args.flatMap((arg, i) => - arg === '--maven-use-only-socket-facts' - ? [arg] - : arg === '--use-only-socket-facts-artifacts' - ? [arg, args[i + 1]!] - : [], + arg === '--use-only-socket-facts-artifacts' ? [arg, args[i + 1]!] : [], ) } @@ -370,10 +366,10 @@ describe('performReachabilityAnalysis --use-only-socket-facts-artifacts gating', expectedSidecar: sidecar, }, { - name: 'keeps the Maven-only flag older Coana releases know, with an empty sidecar', + name: 'writes an empty sidecar when facts-only types come without entries', factsOnlyTypes: ['maven'], socketFactsSidecar: undefined, - expected: ['--maven-use-only-socket-facts'], + expected: ['--use-only-socket-facts-artifacts', 'maven'], expectedSidecar: [], }, { diff --git a/src/utils/coana.mts b/src/utils/coana.mts index 3c478f5e4..c543c86d0 100644 --- a/src/utils/coana.mts +++ b/src/utils/coana.mts @@ -310,12 +310,8 @@ export function isFactsOnlyTypes( return !!types.length } -// Maven alone keeps the older flag, which Coana releases before 15.14.1 also -// know. export function useOnlySocketFactsArtifactsFlags( types: FactsOnlyTypes, ): string[] { - return types.length === 1 && types[0] === 'maven' - ? ['--maven-use-only-socket-facts'] - : ['--use-only-socket-facts-artifacts', [...types].sort().join(',')] + return ['--use-only-socket-facts-artifacts', [...types].sort().join(',')] } diff --git a/src/utils/coana.test.mts b/src/utils/coana.test.mts index 0bb1bde68..ce351b67a 100644 --- a/src/utils/coana.test.mts +++ b/src/utils/coana.test.mts @@ -483,8 +483,6 @@ describe('coana facts-file utils', () => { describe('useOnlySocketFactsArtifactsFlags', () => { it.for([ - // Maven alone keeps the flag Coana releases before 15.14.1 also know. - { types: ['maven'], expected: ['--maven-use-only-socket-facts'] }, { types: ['nuget', 'maven'], expected: ['--use-only-socket-facts-artifacts', 'maven,nuget'],