Generated the JSON contracts of the stored data at compile time (#1148)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-02 18:23:19 +01:00
1 parent fc7399e81b
commit e954881fda
75 files changed
+5437 -298

No files matched your search

@@ -0,0 +1,25 @@
using System.Text.Json.Serialization;
namespace AIStudio.Tests.Serialization;
/// <summary>
/// Checks that every contract AI Studio uses for its JSON comes from source generation, never from reflection.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
[TestFixture]
public sealed class JsonCoverageTests
{
[TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.Stored))]
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);
}
}