Skip to content

SBOM: export a selected element by path, with the transitive chain - #172

Merged
villelaitila merged 1 commit into
softagram:mainfrom
villelaitila:feature/sbom-selected-element
Aug 5, 2026
Merged

SBOM: export a selected element by path, with the transitive chain#172
villelaitila merged 1 commit into
softagram:mainfrom
villelaitila:feature/sbom-selected-element

Conversation

@villelaitila

Copy link
Copy Markdown
Contributor

What

generate_for_element_from_sgraph(sgraph, element_path, transitive=False) — one CycloneDX 1.7 SBOM rooted at a chosen element (typically /Project/repo or /Project/repo/dir):

  • The element becomes the SBOM's metadata component; its descendants define the scope
  • Peers at the same tree depth form the internal-dependency universe — the same universe the level-based multi mode uses, so a selected-element SBOM composes with the multi output (same deterministic serials, same bom-refs, same BOM-Links)
  • transitive=True inlines the chain of directly and indirectly used internal elements and their 3rd-party components, exactly like the multi mode does per element (DT-safe: every ref resolves in-BOM)
  • Unknown paths and paths inside the External subtree raise ValueError

CLI: --element-path /Project/repo/dir (mutually exclusive with --level), composes with --transitive.

Example (multi-repo fixture, --element-path /OrgName/GroupA/repoA --transitive):

repoa -> [pkg:nuget/Newtonsoft.Json@13.0.1, repob]
repob -> [pkg:maven/org.apache.commons/commons-lang3@3.12.0]

Refactoring

The shared machinery is extracted from generate_multi_from_sgraph into _multi_sbom_context + _sbom_for_content_element, and the two duplicated level-walk closures fold into one _content_elements_at_level. Multi-mode behavior is unchanged (locked by the existing 16 multi/transitive tests).

New behavior forced by deep paths

bom-refs get deterministic -2, -3 suffixes on name collisions. Names are unique at repo level, but a dir-level selection makes collisions ordinary (every repo has a src), and a collision inside one transitive BOM would corrupt its dependencies graph.

Tests

7 new (single-SBOM contract, transitive chain, deep path + collision suffix, both error cases, CLI incl. mutual exclusion). Full suite: 237 passed.

generate_for_element_from_sgraph(sgraph, '/Project/repo/dir',
transitive=...) produces one CycloneDX SBOM rooted at the chosen
element: the element is the metadata component and its descendants
define the scope. Its peers at the same tree depth form the
internal-dependency universe — the same universe the level-based multi
mode uses — so with transitive=True the SBOM inlines the chain of
directly and indirectly used internal elements and their 3rd-party
components exactly like the multi mode does per element, and the two
outputs compose instead of contradicting each other.

The shared machinery (content-element walk, external lookup, serial and
bom-ref identity, per-element SBOM assembly) is refactored out of
generate_multi_from_sgraph into _multi_sbom_context and
_sbom_for_content_element; the two duplicated level-walk closures fold
into one _content_elements_at_level.

bom-refs gain deterministic '-2', '-3' suffixes on name collisions:
unique at repo level, but a dir-level split makes collisions ordinary
(every repo has a 'src') and a collision inside one transitive BOM
would corrupt its dependencies graph.

CLI: --element-path (mutually exclusive with --level), composes with
--transitive. Unknown paths and paths inside the External subtree are
rejected with a ValueError.
@softagram-bot

Copy link
Copy Markdown

Softagram Impact Report for pull/172 (head commit: 7087825)

TL;DR Changed code files: 2 | Directly impacted code files: 1

⭐ Change Overview

Showing the changed files, dependency changes and the impact - click for full size
(Open in Softagram Desktop for full details)

⭐ Details of Dependency Changes

details of dependency changes - click for full size
(Open in Softagram Desktop for full details)

[]

📄 Full report

Impact Report explained. Give feedback on this report to support@softagram.com

@villelaitila
villelaitila merged commit d78a1ac into softagram:main Aug 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants