feat(scanner): expose Trivy dependency graph fields on Library#2552
Merged
Conversation
Collaborator
|
Description updated |
shino
reviewed
May 18, 2026
shino
reviewed
May 18, 2026
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.
What did you implement:
This PR threads three Trivy
Packagefields —ID,Relationship, andDependsOn— throughscanner.convertLibWithScanner()so they survive on themodels.Librarystruct. Trivy already populates these fields in its language-package analyzers, but vuls currently drops them during theftypes.Package→models.Libraryconversion.Surfacing this information lets any consumer of
LibraryScannerresults:IDas the key andDependsOnas edges, which is the same model Trivy exposes viaPackages.ParentDeps().The change is intentionally minimal and additive: existing fields are untouched and no new dependencies are introduced. JSON output gains three new keys — ID, Relationship, DependsOn — each tagged omitempty. ID and DependsOn are dropped when Trivy does not populate them, so libraries from analyzers that don't emit package IDs look unchanged. Relationship, however, is always emitted: Trivy's Relationship.String() returns the literal "unknown" for the zero value (RelationshipUnknown), and we keep that string deliberately so the JSON tells consumers "Trivy did not classify this dependency" instead of silently dropping the field. Consumers that diff vuls.json across versions will therefore see a new "Relationship": "..." key on every library entry.
What changed
models/library.go: addID,Relationship,DependsOntoLibrary(allomitempty).Relationshipis stored as the stringified form ("direct" | "indirect" | "workspace" | "root" | "unknown") so themodelspackage does not gain a dependency onaquasecurity/trivy/pkg/fanal/types.scanner/library.go: copylib.ID,lib.Relationship.String(), andlib.DependsOninconvertLibWithScanner(). Three additional lines.scanner/library_test.go: update existing wants withRelationship: "unknown"(the zero-value string Trivy returns forRelationshipUnknown) and add a new table-driven case coveringdirect/indirect/unknownpackages withDependsOnedges.Fixes # (no associated issue — happy to file one first if preferred)
Type of change
How Has This Been Tested?
go test ./scanner/... -run Test_convertLibWithScanner -vgo test ./models/... -count=1make testwas not run end-to-end locally becausescanner.TestAnalyzeLibrary_Golden/TestAnalyzeLibrary_PomOnlinerequire theintegration/submodule data, which is unavailable in my checkout. These failures are unrelated to this change (their own log says "run: git submodule update --init, or check the CI integration checkout step") and should pass on CI where the submodule is checked out.Reproduction commands:
Backward compatibility
models.Libraryare unchanged.ftypeswas already imported by both files).lib.Relationship.String()is the same conversion Trivy uses internally; for the zero value (RelationshipUnknown) it returns the literal string"unknown", which is reflected in the updated existing-test expectations.Checklist:
You don't have to satisfy all of the following.
make fmtmake testIs this ready for review?: YES
Reference