From d01a315e3105953a00a6a52970c1f2aa9a7992c2 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 6 Dec 2026 16:21:38 +0800 Subject: [PATCH] refactor(sbom): reuse Go module records for graph coverage (#17451) --- src/domain/analysisView/cyclonedxView.ts | 27 ++++++++++-------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/domain/analysisView/cyclonedxView.ts b/src/domain/analysisView/cyclonedxView.ts index 4199fa4d55..4254838e78 100644 --- a/src/domain/analysisView/cyclonedxView.ts +++ b/src/domain/analysisView/cyclonedxView.ts @@ -546,12 +546,12 @@ const projectGoCycloneDx = ( "Go parent subject must identify the report's exact artifact.", ); if (!subject.ok) return subject; - const info = report.build_info; - const modules = [ - ...(info?.module.main === null || info === null ? [] : [info.module.main]), - ...(info?.module.dependencies ?? []), - ]; - const published = modules.map(publishedGoModule); + const recorded = report.build_info?.module; + const main = recorded?.main; + const dependencyModules = recorded?.dependencies ?? []; + const published = ( + main == null ? dependencyModules : [main, ...dependencyModules] + ).map(publishedGoModule); const minimumBytes = documentBytesAtLeast(0, published, goComponentBytes); if (minimumBytes > CYCLONEDX_DOCUMENT_BYTE_LIMIT) return documentAllowanceExceeded(minimumBytes, "lower_bound"); @@ -572,27 +572,22 @@ const projectGoCycloneDx = ( goComponentProperties(item), ); }); - const mainRef = - info?.module.main === null || info === null ? undefined : refs[0]; - const dependencyRefs = mainRef === undefined ? [] : refs.slice(1); + const mainRef = main == null ? undefined : refs[0]; // Empty dependsOn claims absence. That claim is valid only when every module line parsed. const dependencies = mainRef === undefined || - (info?.module.complete === false && dependencyRefs.length === 0) + (recorded?.complete === false && dependencyModules.length === 0) ? undefined : [ { ref: mainRef, - dependsOn: uniqueRefs(dependencyRefs), + dependsOn: uniqueRefs(refs.slice(1)), }, ]; - const moduleRecordDecoded = - info !== null && - (info.module.main !== null || info.module.dependencies.length > 0); const sourceCoverage: SourceCoverage = - info === null || (info.module.complete && !moduleRecordDecoded) + recorded === undefined || (recorded.complete && published.length === 0) ? { aggregate: "unknown", records: "absent" } - : info.module.complete + : recorded.complete ? { aggregate: "unknown", records: "present" } : { aggregate: "incomplete", records: "partial" }; const reportedUnknowns = goBinaryUnknowns(report);