using System.Text.Json.Serialization; namespace AIStudio.Tests.Serialization; /// /// Checks that every contract AI Studio uses for its JSON comes from source generation, never from reflection. /// /// /// A type which no context of the options knows makes System.Text.Json throw, unless the options fall back to /// reflection. Such a fallback hides the missing type until a trimmed build removes what reflection needs, and /// only a published build shows it then. /// [TestFixture] public sealed class JsonCoverageTests { [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.Stored))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.ProviderRequests))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.ProviderAnswers))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.RuntimeRequests))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.RuntimeAnswers))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.ServiceRequests))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.ServiceAnswers))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.VisualBriefingStored))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.VisualBriefingHashed))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.VisualBriefingAnswers))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.ModelAnswers))] [TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.ModelPrompts))] public void EveryContractComesFromSourceGeneration(JsonTestRoot root) { var typesWithoutGeneratedContract = JsonTypeGraph.Collect(root.Type, root.Options) .Where(type => root.Options.GetTypeInfo(type).OriginatingResolver is not JsonSerializerContext) .Select(JsonContractDescription.TypeName); Assert.That(typesWithoutGeneratedContract, Is.Empty); } }