using System.Text.Json; using Launcher.Next.App; using Xunit; namespace Launcher.Next.Tests; public sealed class LocalParityEvidenceTests { [Fact] public async Task EvidenceWriter_AtomicallyPublishesValidatedSchema() { var root = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); try { Directory.CreateDirectory(root); var path = await LocalParityLaunchService.WriteEvidenceAsync(root, new { schemaVersion = 4, state = "PACKAGE_LOAD_VERIFIED" }, CancellationToken.None); Assert.True(File.Exists(path)); using var document = JsonDocument.Parse(await File.ReadAllTextAsync(path)); Assert.Equal(4, document.RootElement.GetProperty("schemaVersion").GetInt32()); Assert.False(File.Exists(path + ".tmp")); } finally { if (Directory.Exists(root)) Directory.Delete(root, recursive: true); } } [Fact] public async Task EvidenceWriter_ReplacesStaleTemporaryArtifact() { var root = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); try { Directory.CreateDirectory(root); await File.WriteAllTextAsync(Path.Combine(root, "controlled-local-parity-launch.json.tmp"), "stale"); var path = await LocalParityLaunchService.WriteEvidenceAsync(root, new { schemaVersion = 4, terminalResult = "PACKAGE_LOAD_VERIFIED" }, CancellationToken.None); Assert.Contains("PACKAGE_LOAD_VERIFIED", await File.ReadAllTextAsync(path)); Assert.False(File.Exists(path + ".tmp")); } finally { if (Directory.Exists(root)) Directory.Delete(root, recursive: true); } } }