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,23 @@
namespace AIStudio.Tests.Serialization;
/// <summary>
/// Checks that the contracts AI Studio uses for its JSON match those reflection builds.
/// </summary>
/// <remarks>
/// AI Studio wrote all its files with contracts which reflection built. Any other contract, e.g., one which
/// source generation builds, has to match them in every detail, or AI Studio no longer reads what it wrote
/// before: a property with another name, without a setter, or without its converter silently loses its value.
/// </remarks>
[TestFixture]
public sealed class JsonContractTests
{
[TestCaseSource(typeof(JsonTestRoots), nameof(JsonTestRoots.Stored))]
public void TheContractsMatchThoseOfReflection(JsonTestRoot root)
{
var baseline = JsonReflectionBaseline.Of(root.Options);
var expected = JsonTypeGraph.Collect(root.Type, baseline).Select(type => JsonContractDescription.Describe(baseline.GetTypeInfo(type)));
var actual = JsonTypeGraph.Collect(root.Type, root.Options).Select(type => JsonContractDescription.Describe(root.Options.GetTypeInfo(type)));
Assert.That(actual, Is.EqualTo(expected));
}
}