feat(purl): guard emitted PURL validity, and build source RPM PURLs - #1354
Merged
Conversation
Nothing enforced that an emitted PURL parses. `normalize_purl` is a normalizer and returns unparsable input unchanged, and no test asserted otherwise, which is how `pkg:pypi/::`, `pkg:apk/alpine/musl>=1.2.0` and `pkg:osgi/my bundle?x@1.0.0` came to ship. Add a guard over the expected fixtures, which are generated from the parsers and so sample what they emit: every PURL-shaped value must parse, and must keep its type, namespace, name, version, qualifiers and subpath across a parse/emit round trip. Component stability rather than string equality, so the two places Provenant deliberately encodes differently from the crate — `$`/`'` in versions and golang namespace case — do not register as failures. Deliberately a check rather than a runtime filter. Dropping an unparsable PURL at the output boundary erases the component from SBOM output entirely, where the PURL doubles as its identity, and would discard caller-supplied values on the `--from-json` path. The parsers are the right place to be correct. The guard immediately found one: RPM stored the source RPM's *filename* in `source_packages`, a field specified as a list of PURLs. Decompose the NEVRA filename instead, as ScanCode does — release folded into the version, `arch` as a qualifier — so `gcc-13.1.1-2.fc38.src.rpm` becomes `pkg:rpm/gcc@13.1.1-2.fc38?arch=src`. A filename that does not decompose yields no entry rather than falling back to the raw string. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Maxim Stykow <maxim.stykow@gmail.com>
Greptile SummaryThe PR converts RPM source-package filenames into valid RPM PURLs and adds a CI guard that checks PURLs in expected fixtures for parseability and component-stable round trips.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking defects identified. The changed RPM paths consistently convert available NEVRA-form source filenames through the existing PackageURL builder, and the updated fixtures and CI guard cover the intended output contract.
|
| Filename | Overview |
|---|---|
| src/parsers/rpm_db.rs | Adds shared SRPM PURL construction using the existing RPM PackageURL builder and applies it to RPM database results. |
| src/parsers/rpm_parser.rs | Applies the shared source-RPM PURL conversion to normal and salvaged RPM archive parsing. |
| tests/emitted_purl_validity_guard.rs | Adds corpus-level checks that emitted PURLs parse and retain their components across serialization. |
| .github/workflows/check.yml | Runs the new emitted-PURL validity guard on the integration CI shard. |
Reviews (1): Last reviewed commit: "feat(purl): guard emitted PURL validity,..." | Re-trigger Greptile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
normalize_purlis a normalizer and returns unparsable input unchanged, and no test asserted otherwise — which is howpkg:pypi/::,pkg:apk/alpine/musl>=1.2.0andpkg:osgi/my bundle?x@1.0.0came to ship.source_packages, a field specified as a list of PURLs.Scope and exclusions
This is deliberately a check, not a runtime filter — and I tried the filter first. Gating
purlat theoutput_schemaboundary made an existing SBOM contract test fail, and the failure was instructive: dropping the PURL did not merely blank the field, it erased the component from the SBOM entirely, because the PURL doubles as itsbom-refidentity there. It would also discard caller-supplied values on the--from-jsonpath. The parsers are the right place to be correct; this keeps them so.Component stability rather than string equality, per the same reasoning: strict round-trip equality flags the two places Provenant intentionally differs from the crate — deliberate
$/'over-encoding in versions, and the golang namespace-case workaround for purl-spec#308 — where Provenant is the more correct of the two.The
generated-package:fallback identity is exempt and asserted as the single known non-PURL scheme; it is prefixed precisely so a consumer fails loudly rather than mis-parsing it.How to verify
cargo test --test emitted_purl_validity_guardTo see it work, reintroduce a hand-formatted PURL in any parser and regenerate its golden — the guard names the offending string.
Intentional differences from Python
rpm.py:320-337builds aPackageURLfrom the source RPM's NEVRA with the release folded into the version andarchas a qualifier. Provenant now produces the identical shape.Expected-output fixture changes
testdata/rpm/fping-…rpm.expected.json,rpmdb.sqlite.expected.json,fedora-bdb-rootfs.expected.json.source_packagesis documented as "a list of related source code Package URLs (aka. purl)"."gcc-13.1.1-2.fc38.src.rpm"is a filename, not a PURL, and no consumer could resolve it. It becomespkg:rpm/gcc@13.1.1-2.fc38?arch=src, which is both parsable and byte-identical to what ScanCode emits for the same input.