more audit work

This commit is contained in:
master
2026-01-08 10:21:51 +02:00
parent 43c02081ef
commit 51cf4bc16c
546 changed files with 36721 additions and 4003 deletions

View File

@@ -158,15 +158,12 @@ public class ReachabilityGraphPropertyTests
GraphWithRootsArb(),
graph =>
{
if (graph.Roots.Count == 0)
var entryPoints = FindEntryPoints(graph);
if (entryPoints.Count == 0)
return true;
var order = _orderer.OrderNodes(graph, GraphOrderingStrategy.BreadthFirstLexicographic);
var firstNodes = order.Take(graph.Roots.Count).ToHashSet();
var rootIds = graph.Roots.Select(r => r.Id).ToHashSet();
// First nodes should be anchors (roots)
return firstNodes.Intersect(rootIds).Any();
return order.FirstOrDefault() == entryPoints[0];
});
}
@@ -491,5 +488,54 @@ public class ReachabilityGraphPropertyTests
return graph with { Nodes = nodes, Edges = edges, Roots = roots };
}
private static IReadOnlyList<string> FindEntryPoints(RichGraph graph)
{
var nodeIds = graph.Nodes
.Select(n => n.Id)
.Where(id => !string.IsNullOrWhiteSpace(id))
.Distinct(StringComparer.Ordinal)
.ToList();
var inbound = new HashSet<string>(StringComparer.Ordinal);
foreach (var edge in graph.Edges)
{
if (!string.IsNullOrWhiteSpace(edge.To))
{
inbound.Add(edge.To);
}
}
var entryPoints = new HashSet<string>(StringComparer.Ordinal);
foreach (var root in graph.Roots)
{
if (!string.IsNullOrWhiteSpace(root.Id))
{
entryPoints.Add(root.Id);
}
}
foreach (var node in graph.Nodes)
{
if (node.Attributes?.TryGetValue(RichGraphSemanticAttributes.IsEntrypoint, out var value) == true &&
!string.IsNullOrWhiteSpace(value) &&
bool.TryParse(value, out var parsed) &&
parsed)
{
entryPoints.Add(node.Id);
}
}
foreach (var nodeId in nodeIds)
{
if (!inbound.Contains(nodeId))
{
entryPoints.Add(nodeId);
}
}
return entryPoints.OrderBy(id => id, StringComparer.Ordinal).ToList();
}
#endregion
}