Skip to content

Commit 4d4e573

Browse files
mprpicclaude
andcommitted
test(sbom): address review feedback on SPDX id tests
Pin the UUID in the different-packages test so only name and version keep the ids apart, validate the document in the name/version test, and note in `generate_sbom()` that the wheel package should be found through DESCRIBES. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Martin Prpič <mprpic@redhat.com>
1 parent e9121a7 commit 4d4e573

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎src/fromager/sbom.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ def generate_sbom(
123123
package entry, its purl, and the document identity use
124124
``wheel_version`` when given; the upstream package entry always
125125
uses ``version``.
126+
127+
Package SPDX ids include a per-document suffix and are not predictable,
128+
so consumers should find the wheel package through the document's
129+
DESCRIBES relationship rather than by a fixed id.
126130
"""
127131
sbom_settings = ctx.settings.sbom_settings
128132
if sbom_settings is None:

‎tests/test_sbom.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ def test_generate_sbom_spdx_ids_name_package_and_document(
421421
"SPDXRef-wheel-test-0.1.0-12345678",
422422
"SPDXRef-upstream-test-0.1.0-12345678",
423423
]
424+
_validate_spdx(doc)
424425

425426

426427
def test_generate_sbom_spdx_ids_differ_between_packages(
@@ -429,13 +430,16 @@ def test_generate_sbom_spdx_ids_differ_between_packages(
429430
"""Verify SBOMs of different wheels share no package SPDX ids.
430431
431432
Tools such as syft merge packages from several SBOMs by SPDX id, so
432-
shared ids would attribute one wheel's data to another.
433+
shared ids would attribute one wheel's data to another. Both documents
434+
get the same UUID so only the name and version can keep the ids apart.
433435
"""
434436
ctx = make_sbom_ctx(tmp_path, sbom_settings=SbomSettings())
435-
docs = [
436-
sbom.generate_sbom(ctx=ctx, req=Requirement(req), version=Version(ver))
437-
for req, ver in [("idna==3.6", "3.6"), ("packaging==26.3", "26.3")]
438-
]
437+
fixed_uuid = uuid.UUID("12345678-1234-5678-1234-567812345678")
438+
with patch("fromager.sbom.uuid.uuid4", return_value=fixed_uuid):
439+
docs = [
440+
sbom.generate_sbom(ctx=ctx, req=Requirement(req), version=Version(ver))
441+
for req, ver in [("idna==3.6", "3.6"), ("packaging==26.3", "26.3")]
442+
]
439443

440444
ids = [{p["SPDXID"] for p in doc["packages"]} for doc in docs]
441445
assert ids[0].isdisjoint(ids[1])

0 commit comments

Comments
 (0)