63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using System.IO;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using FluentAssertions;
|
|
using StellaOps.Signals.Models;
|
|
using StellaOps.Signals.Parsing;
|
|
using Xunit;
|
|
|
|
namespace StellaOps.Signals.Tests;
|
|
|
|
public sealed class SimpleJsonCallgraphParserGateTests
|
|
{
|
|
[Fact]
|
|
public async Task ParseAsync_parses_gate_fields_on_edges()
|
|
{
|
|
var json = """
|
|
{
|
|
"schema_version": "1.0",
|
|
"nodes": [
|
|
{ "id": "main" },
|
|
{ "id": "target" }
|
|
],
|
|
"edges": [
|
|
{
|
|
"from": "main",
|
|
"to": "target",
|
|
"kind": "call",
|
|
"gate_multiplier_bps": 3000,
|
|
"gates": [
|
|
{
|
|
"type": "authRequired",
|
|
"detail": "[Authorize] attribute",
|
|
"guard_symbol": "main",
|
|
"source_file": "/src/app.cs",
|
|
"line_number": 42,
|
|
"confidence": 0.9,
|
|
"detection_method": "pattern"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
""";
|
|
|
|
var parser = new SimpleJsonCallgraphParser("csharp");
|
|
await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json), writable: false);
|
|
var parsed = await parser.ParseAsync(stream, CancellationToken.None);
|
|
|
|
parsed.Edges.Should().ContainSingle();
|
|
var edge = parsed.Edges[0];
|
|
edge.GateMultiplierBps.Should().Be(3000);
|
|
edge.Gates.Should().NotBeNull();
|
|
edge.Gates!.Should().ContainSingle();
|
|
edge.Gates[0].Type.Should().Be(CallgraphGateType.AuthRequired);
|
|
edge.Gates[0].GuardSymbol.Should().Be("main");
|
|
edge.Gates[0].SourceFile.Should().Be("/src/app.cs");
|
|
edge.Gates[0].LineNumber.Should().Be(42);
|
|
edge.Gates[0].DetectionMethod.Should().Be("pattern");
|
|
}
|
|
}
|
|
|