Skip to content

fix(scan): scan without facts when no build root is found - #1817

Open
Jeppe Fredsgaard Blaabjerg (jfblaa) wants to merge 1 commit into
v1.xfrom
jfblaa/dsi-no-build-root-noop
Open

Jeppe Fredsgaard Blaabjerg (jfblaa) wants to merge 1 commit into
v1.xfrom
jfblaa/dsi-no-build-root-noop

Conversation

@jfblaa

@jfblaa Jeppe Fredsgaard Blaabjerg (jfblaa) commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

--dynamic-sbom-inference no longer fails a repository without a .NET, Gradle, Maven or sbt build. socket scan create, socket scan reach and socket fix log that no build root was found and carry on as without the flag, and socket manifest dynamic-sbom-inference reports it and exits successfully. The flag can now be passed to every repository a pipeline scans.

Behaviour
  • Scans: no facts files, no facts-only purl types sent to Coana, so the manifest files are scanned and analysed as they are.
  • socket fix: no --socket-facts-sidecar and no facts-only flag reach Coana; the fix runs exactly as without the flag.
  • A repository with build roots that all fail, or that produce no facts for reachability, still fails as before.
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.

`--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.
@jfblaa Jeppe Fredsgaard Blaabjerg (jfblaa) changed the title jfblaa/dsi no build root noop fix(scan): scan without facts when no build root is found Dec 2, 2026
@jfblaa
Jeppe Fredsgaard Blaabjerg (jfblaa) marked this pull request as ready for review December 2, 2026 23:53
@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes exit codes and scan/fix behavior for repos without JVM or .NET builds when --dynamic-sbom-inference is set globally in CI, though real failures and reachability-without-facts cases still abort as before.

Overview
--dynamic-sbom-inference no longer errors when a repo has no Gradle, Maven, sbt, or .NET build roots. The flag can be enabled uniformly in pipelines: matching projects still get Socket facts and facts-only Coana behavior, while others log that no build root was found and continue like a normal scan.

runDynamicSbomInference now returns empty paths and factsOnlyTypes: undefined instead of throwing InputError. socket fix --dynamic-sbom-inference follows the same path—generateSocketFactsForFix may return undefined, so Coana is not given --use-only-socket-facts-artifacts or --socket-facts-sidecar. socket manifest dynamic-sbom-inference reports the no-build-root message and exits successfully (ok: true), with the message shown in text/markdown output.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants