@@ -34,7 +34,7 @@ func TestIsWildcard(t *testing.T) {
3434 {"literal pkg:npm/foo" , "pkg:npm/foo@1.0.0" , false },
3535 {"empty string" , "" , false },
3636 {"triple star" , "***" , false },
37- {"ROOT is wildcard" , normalize .GraphRootNodeID , true },
37+ {"ROOT is not a wildcard" , normalize .GraphRootNodeID , false },
3838 }
3939
4040 for _ , tt := range tests {
@@ -96,12 +96,14 @@ func TestRootPathPattern(t *testing.T) {
9696 path []string
9797 expected bool
9898 }{
99- {"ROOT matches ROOT" , PathPattern {normalize .GraphRootNodeID }, []string {normalize .GraphRootNodeID }, true },
100- {"ROOT matches any path with ROOT at end" , PathPattern {normalize .GraphRootNodeID }, []string {"A" , "B" , normalize .GraphRootNodeID }, true },
101- {"ROOT DOES match path without ROOT" , PathPattern {normalize .GraphRootNodeID }, []string {"A" , "B" , "C" }, true },
102- {"ROOT does not lead to all paths matching" , PathPattern {normalize .GraphRootNodeID , "X" }, []string {"A" , "B" , "C" }, false },
103- // Direct dependency: pattern created from the graph includes ROOT but VulnerabilityPath does not.
104- // ["*", "ROOT", "pkg:..."] must match ["pkg:..."] because ROOT is a wildcard that matches zero elements.
99+ // ROOT is a stop marker: [root, pkg:A] matches only direct dependencies.
100+ // VulnerabilityPath never contains ROOT, so ROOT in the pattern consumes
101+ // zero path elements and anchors the match to position 0 (no suffix scan).
102+ {"root pkg:A matches direct dependency" , PathPattern {normalize .GraphRootNodeID , "pkg:A" }, []string {"pkg:A" }, true },
103+ {"root pkg:A does not match transitive dependency" , PathPattern {normalize .GraphRootNodeID , "pkg:A" }, []string {"pkg:B" , "pkg:A" }, false },
104+ // [*, ROOT, pkg:A] is equivalent to [ROOT, pkg:A]: ROOT absorbs the wildcard prefix.
105+ {"wildcard root pkg:A matches direct dependency" , PathPattern {"*" , normalize .GraphRootNodeID , "pkg:A" }, []string {"pkg:A" }, true },
106+ {"wildcard root pkg:A does not match transitive dependency" , PathPattern {"*" , normalize .GraphRootNodeID , "pkg:A" }, []string {"pkg:B" , "pkg:A" }, false },
105107 {"wildcard ROOT pkg matches direct dependency path" , PathPattern {"*" , normalize .GraphRootNodeID , "pkg:golang/go-jose@v4" }, []string {"pkg:golang/go-jose@v4" }, true },
106108 }
107109
0 commit comments