mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-03 23:47:21 +00:00
36 lines
1.9 KiB
C#
36 lines
1.9 KiB
C#
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))]
|
|
[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);
|
|
}
|
|
} |