fix(go): remove directDepPaths filtering that drops direct dependencies#497
fix(go): remove directDepPaths filtering that drops direct dependencies#497ruromero wants to merge 2 commits intoguacsec:mainfrom
Conversation
Commit de12f6a introduced filtering in getSBOM() that uses go mod edit -json's Indirect flag to exclude root-level edges from go mod graph. This caused go_mod_no_ignore direct dependency count to drop from 45 to 7 (84% reduction). The Java client treats all root-level edges from go mod graph as direct dependencies. The go mod graph output is the authoritative dependency tree after MVS resolution — filtering based on go.mod's indirect markers removes real edges from the graph. Remove the directDepPaths set construction and its filtering guards from both the stack analysis and component analysis paths. Add a reproducer test asserting 45 direct deps for go_mod_no_ignore. Regenerate all affected expected SBOM fixtures. Implements TC-4275 Assisted-by: Claude Code
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR removes previously introduced filtering of Go module root-level dependencies based on go mod edit -json Indirect flags, restores treating all go mod graph root edges as direct dependencies, adds a targeted regression test, and updates SBOM fixture expectations accordingly. Sequence diagram for Go module SBOM generation without directDepPaths filteringsequenceDiagram
actor User
participant GolangProvider as Golang_gomodules
participant GoToolchain as Go_commands
participant SBOM as SbomBuilder
User->>GolangProvider: getSBOM(manifest, opts, includeTransitive)
GolangProvider->>GoToolchain: run go mod edit -json
GoToolchain-->>GolangProvider: goModEditOutput
GolangProvider->>GoToolchain: run go mod graph
GoToolchain-->>GolangProvider: goGraphOutput
GolangProvider->>GolangProvider: parse goGraphOutput into rows
GolangProvider->>GolangProvider: determine root module path
loop for each row in rows
GolangProvider->>GolangProvider: parent = getParentVertexFromEdge(row)
GolangProvider->>GolangProvider: child = getChildVertexFromEdge(row)
GolangProvider->>GolangProvider: source = toPurl(parent, "@")
GolangProvider->>GolangProvider: target = toPurl(child, "@")
alt dependencyNotIgnored
GolangProvider->>SBOM: addDependency(source, target)
else ignored
GolangProvider->>SBOM: skip dependency
end
end
par component analysis root dependencies
loop for each root level pair
GolangProvider->>GolangProvider: child = getChildVertexFromEdge(pair)
GolangProvider->>GolangProvider: target = toPurl(child, "@")
alt dependencyNotIgnored
GolangProvider->>SBOM: addDependency(mainModule, target)
else ignored
GolangProvider->>SBOM: skip dependency
end
end
and cleanup
GolangProvider->>SBOM: enforceRemovingIgnoredDepsInCaseOfAutomaticVersionUpdate
end
SBOM-->>User: final SBOM
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the new test,
rootDepsis derived by taking the first dependency entry with a non-emptydependsOnarray; consider explicitly identifying the root module (e.g., by matchingref/purl/module path) so the assertion doesn't depend on fixture ordering.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the new test, `rootDeps` is derived by taking the first dependency entry with a non-empty `dependsOn` array; consider explicitly identifying the root module (e.g., by matching `ref`/purl/module path) so the assertion doesn't depend on fixture ordering.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Verification Report for TC-4275 (commit 6a43c91)
Acceptance Criteria Details
Overall: WARNOne commit lacks a Jira issue reference. Test quality has advisory findings (parameterization opportunity, missing doc comments) that don't affect correctness. This comment was AI-generated by sdlc-workflow/verify-pr v0.7.2. |
Why test fixture expectations changedFor reviewers unfamiliar with the Go provider internals, here's context on why the expected SBOM fixtures changed significantly: Root causeCommit The result was that What changed in fixtures
How to verifyThe new reproducer test at line 61 of |
Collapse the stack analysis and component analysis test bodies into a single parameterized forEach over analysis type, provider method, fixture file, and CI timeout. This removes duplication while preserving identical test coverage and names. Implements TC-4275 Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
Summary
directDepPathsfiltering introduced in de12f6a that usedgo mod edit -jsonIndirect flags to exclude root-level edges fromgo mod graph, causing an 84% drop in reported direct dependencies (45→7 forgo_mod_no_ignore)go_mod_no_ignorecomponent analysis reports all 45 root-level deps fromgo mod graphFixes TC-4275
Part of TC-3818
Root Cause
Commit de12f6a built a
directDepPathsSet fromgo mod edit -jsonentries whereIndirect === false, then filtered root-level edges fromgo mod graphagainst it. Sincego mod graphreports edges after MVS resolution whilego mod edit -jsonreflects go.mod's// indirectmarkers, valid direct dependencies were incorrectly excluded.The Java client treats ALL root-level edges from
go mod graphas direct dependencies and never performs this filtering — restoring that behavior here aligns cross-client parity.Test plan
go_mod_no_ignorecomponent analysis asserts 45 root-level deps (failed with 7 before fix)go_mod_no_ignorestack=138 components,go_mod_mvs_versionsstack=138 components (matching Java client)🤖 Generated with Claude Code
Summary by Sourcery
Restore reporting of all root-level Go module dependencies in SBOM generation and update tests/fixtures accordingly.
Bug Fixes:
Tests: