fix(diff): detect upgrades by version-independent purl coordinate - #58
Open
dmchaledev wants to merge 1 commit into
Open
fix(diff): detect upgrades by version-independent purl coordinate#58dmchaledev wants to merge 1 commit into
dmchaledev wants to merge 1 commit into
Conversation
diff() keyed components by `comp.purl ?? comp.name`, but a purl embeds the version (e.g. `pkg:npm/lodash@4.17.21`). A version bump therefore changed the key, so upgrades were reported as a removal plus an addition instead of an upgrade. Because real CycloneDX/SPDX SBOMs almost always carry purls, the tool's headline "upgraded dependencies" feature — and the isMajorBump / [MAJOR] signal — effectively never fired in practice. Key components on the purl *coordinate* (purl with version, qualifiers, and subpath stripped), falling back to the lowercased name. Scoped npm names like `@babel/core` are preserved since the scope's `@` precedes a `/`, while the version `@` follows the final path segment. Replace the test that rationalized the old add/remove behavior with coverage asserting upgrades are detected when purls are present, plus scoped-package and qualifier/subpath cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014nrrhhcYr3dDS5FztH9DSr
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
Fixes the tool's headline "upgraded dependencies" detection, which silently never fired for real-world SBOMs.
diff()keyed components bycomp.purl ?? comp.name(src/diff.ts), but a purl embeds the version — e.g.pkg:npm/lodash@4.17.21. When a dependency is upgraded, its purl changes, so the two versions hash to different keys and the diff reports the change as one removed + one added instead of an upgrade.Because real CycloneDX/SPDX SBOMs almost always carry purls (purl is the standard component identifier), this meant:
upgradedarray stayed empty in practice → the Markdown "Upgraded Components" table and the text-report↑ Upgradedsection were effectively dead for real inputs.isMajorBump/ the[MAJOR]flag — the most security-relevant signal — never surfaced.The prior
diff.test.tseven rationalized this as "correct behavior — different purls are different packages", which contradicts the package's own description ("Highlights added, removed, upgraded dependencies").Change
Match components on their version-independent purl coordinate — the purl with version, qualifiers (
?…), and subpath (#…) stripped — falling back to the lowercased name when no purl is present:pkg:npm/lodash@4.17.20andpkg:npm/lodash@4.17.21→ both key topkg:npm/lodash→ reported as an upgrade.@babel/coreare preserved: the scope's@precedes a/, while the version@follows the final path segment, so only the version is cut.No public API or type changes — this only corrects how existing components are matched inside
diff().Tests
@babel/core, with a major-bump assertion) and for purls carrying qualifiers/subpaths.tsc --noEmitandeslint srcclean.🤖 Generated with Claude Code
https://claude.ai/code/session_014nrrhhcYr3dDS5FztH9DSr
Generated by Claude Code