fix(diff): detect upgrades for version-qualified purls#20
Open
dmchaledev wants to merge 1 commit into
Open
Conversation
Component map keys were the raw purl, which embeds the version (e.g. pkg:npm/lodash@4.17.21). Real-world SBOM generators (Syft, Trivy, cdxgen) almost always emit version-qualified purls, so every version got its own key and an upgrade was reported as a remove + add instead of an upgrade — defeating the tool's flagship "upgraded dependencies" feature. Key components by a version-independent purl identity (subpath, qualifiers, and @Version stripped), falling back to the name. Add tests covering qualified/subpath purls and guarding against false upgrades between distinct packages. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BPc7gpi66iTEvhzh9b3rNf
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.
Problem
diff()builds its component lookup map keyed on the raw purl:But a purl embeds the version (
pkg:npm/lodash@4.17.21), and real-world SBOM generators (Syft, Trivy, cdxgen, …) almost always emit version-qualified purls. So the same package at two versions gets two different keys, and an upgrade is reported as a remove + add instead of an upgrade — defeating the tool's flagship "highlights upgraded dependencies" feature for the common case.Reproduction (before)
The previous test even encoded this as "correct behavior", but it directly contradicts the README's promise.
Fix
Key components by a version-independent purl identity — strip the
#subpath,?qualifiers, and trailing@version, then fall back to the package name. (An npm scope like%40scopeis percent-encoded, so a literal@only ever separates the version.)After
Tests
All 31 tests pass; lint and typecheck clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01BPc7gpi66iTEvhzh9b3rNf
Generated by Claude Code