Skip to content

Commit 301a27f

Browse files
committed
Address feedback
1 parent f97ff44 commit 301a27f

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,18 @@ private static void PruneFilteredComponentsFromGraphs(DependencyGraphCollection
141141
}
142142

143143
// Remove references to removed IDs from remaining nodes' dependency sets.
144-
foreach (var edges in graph.Values)
144+
// Normalize empty edge sets to null for consistent leaf-node serialization.
145+
foreach (var nodeId in graph.Keys.ToList())
145146
{
146-
edges?.RemoveWhere(id => !retainedIds.Contains(id));
147+
var edges = graph[nodeId];
148+
if (edges != null)
149+
{
150+
edges.RemoveWhere(id => !retainedIds.Contains(id));
151+
if (edges.Count == 0)
152+
{
153+
graph[nodeId] = null;
154+
}
155+
}
147156
}
148157

149158
// Clean up metadata sets.

test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DefaultGraphTranslationServiceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,9 @@ public void FilterBaseImageComponents_PrunesFilteredComponentsFromDependencyGrap
731731
graph.Should().ContainKey(retainedComponent.Component.Id);
732732
graph.Should().NotContainKey(baseImageComponent.Component.Id);
733733

734-
// The retained component's edge set should not reference the removed component.
734+
// The retained component should be a leaf node (null edges) after its only dependency was pruned.
735735
var retainedEdges = graph[retainedComponent.Component.Id];
736-
retainedEdges?.Should().NotContain(baseImageComponent.Component.Id);
736+
retainedEdges.Should().BeNull();
737737

738738
// Metadata sets should also be cleaned.
739739
graphEntry.Value.ExplicitlyReferencedComponentIds.Should().NotContain(baseImageComponent.Component.Id);

0 commit comments

Comments
 (0)