Repository navigation
fix(scan): scan without facts when no build root is found - #1817
Jeppe Fredsgaard Blaabjerg (jfblaa) wants to merge 1 commit into
Conversation
`--dynamic-sbom-inference` failed scan create, scan reach and fix when a repository had no .NET, Gradle, Maven or sbt build, so the flag could not be passed to every repository. They now log that no build root was found and continue as without the flag, and `socket manifest dynamic-sbom-inference` reports it and exits successfully.
PR SummaryMedium Risk Overview
Unchanged: runs still fail when a discovered build root fails to generate facts, or when reachability is requested but no build produced facts (empty/skipped roots). Reviewed by Cursor Bugbot for commit c8985b4. Configure here. |
| factsOnlyTypes: FactsOnlyTypes | ||
| // these types' artifacts only from facts files. Undefined when no build | ||
| // root was discovered. | ||
| factsOnlyTypes: FactsOnlyTypes | undefined |
There was a problem hiding this comment.
[agent] "No build root" now has two shapes on adjacent layers: here it's a full result with factsOnlyTypes: undefined and empty arrays, and generateSocketFactsForFix checks that field only to turn it into a plain undefined. The type also admits factsOnlyTypes: undefined with non-empty paths, which only the comment rules out.
Simpler: keep factsOnlyTypes: FactsOnlyTypes required and return DynamicSbomInferenceResult | undefined. The fix layer's check becomes if (!inferred), and the scan callers (handle-scan-reach.mts, handle-create-new-scan.mts) need about three ?./?? [], since their locals are already | undefined.
| ? { | ||
| ok: false, | ||
| code: 1, | ||
| ok: true, |
There was a problem hiding this comment.
[agent] With this branch now a success, the nesting does no work: an empty outcomes can't contain a failure, so it no longer has to be checked first. One failure branch plus one success branch whose message depends on outcomes.length does the same. (Upstack adds a third, skipped-failures success case; that fits the same shape with one more message condition.)
| code: 1, | ||
| ok: true, | ||
| message: | ||
| 'No Gradle, sbt, Maven or .NET build root was found beneath the given directory.', |
There was a problem hiding this comment.
[agent] This hardcoded list now becomes the normal success output, and it doesn't match the scan path's joinOr(buildToolLabelsFor(purlTypes)), which prints ".NET, Gradle, Maven, or sbt" (different order and comma). joinOr(buildToolLabelsFor(FACTS_PURL_TYPES)) would keep them in step. Another hardcoded copy is at setup-recursive-manifest-config.mts:1049.
| tmpDir: string | ||
| }): Promise<GeneratedSocketFacts> { | ||
| }): Promise<GeneratedSocketFacts | undefined> { | ||
| const existingPaths = await findFactsPaths() |
There was a problem hiding this comment.
[agent] With no build root, everything up to the early return at line 90 is wasted, and that is now a success path: a full repo walk via findFactsPaths(), a backup of the existing facts files, and a work dir. The walk also repeats the one coanaFixWithFacts already did into scanFilepaths.
Cheaper: pass scanFilepaths.filter(isSocketFactsFile) in for this first lookup and keep findFactsPaths for the cleanup in the catch. That also saves the repeated walk when build roots do exist.
|
|
||
| async function generate() { | ||
| return await generateSocketFactsForFix({ | ||
| function generateOrNone() { |
There was a problem hiding this comment.
[agent] The generateOrNone/generate split exists only to narrow the type, but test files are excluded from tsconfig.json, so the narrowing has no effect (run-dynamic-sbom-inference.test.mts already reads the now-optional field without it). The original single generate() with expect(await generate()).toBeUndefined() would do.
| }) | ||
|
|
||
| it('aborts when --dynamic-sbom-inference finds no build root', async () => { | ||
| it('scans without facts when --dynamic-sbom-inference finds no build root', async () => { |
There was a problem hiding this comment.
[agent] With the abort gone, this test and the next one ("build roots were found but none generated facts") have the same setup and assertions, differing only in the mocked outcomes. One it.for over [] and [empty, skippedDisabled] would cover both.
--dynamic-sbom-inferenceno longer fails a repository without a .NET, Gradle, Maven or sbt build.socket scan create,socket scan reachandsocket fixlog that no build root was found and carry on as without the flag, andsocket manifest dynamic-sbom-inferencereports it and exits successfully. The flag can now be passed to every repository a pipeline scans.Behaviour
socket fix: no--socket-facts-sidecarand no facts-only flag reach Coana; the fix runs exactly as without the flag.Tests
run-dynamic-sbom-inference.test.mts: no build root returns no facts and no facts-only types.generated-socket-facts.test.mts,coana-fix-dynamic-sbom-inference.test.mts: fix generates nothing and runs Coana as without the flag.handle-create-new-scan.test.mts,handle-manifest-dynamic-sbom-inference.test.mts: the scan goes on without facts; the manifest command succeeds with its message.