using System.Text.Json; using Sdt.Core; using Xunit; namespace DevTool.Tests; public sealed class RunEventJsonlRecorderTests { [Fact] public void Recorder_WritesJsonlEvents() { var root = Path.Combine(Path.GetTempPath(), "sdt-events-" + Guid.NewGuid().ToString("N")); Directory.CreateDirectory(root); string path; using (var recorder = RunEventJsonlRecorder.Create(root, "workflow")) { path = recorder.FilePath; recorder.Write(new RunEvent("workflow", RunEventType.WorkflowStarted, "started", WorkflowId: "build")); recorder.Write(new RunEvent("workflow", RunEventType.WorkflowCompleted, "done", WorkflowId: "build", Success: true)); } Assert.True(File.Exists(path)); var lines = File.ReadAllLines(path); Assert.Equal(2, lines.Length); using var doc = JsonDocument.Parse(lines[0]); Assert.Equal("workflow", doc.RootElement.GetProperty("category").GetString()); Assert.Equal("WorkflowStarted", doc.RootElement.GetProperty("type").GetString()); Assert.Equal("1.0", doc.RootElement.GetProperty("run_event_version").GetString()); Assert.True(doc.RootElement.TryGetProperty("run_id", out _)); Assert.True(doc.RootElement.TryGetProperty("timestamp_utc", out _)); Assert.True(doc.RootElement.TryGetProperty("event_type", out _)); } }