Refused JSON contracts built by reflection and checked all of them in the trimmed build (#1152)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-03 18:29:50 +01:00
1 parent f864359290
commit 0b42c0288e
23 files changed
+535 -99

No files matched your search

+2 -1
View File
@@ -3,6 +3,7 @@ using System.Text;
using System.Text.Json;
using AIStudio.Tools.Rust;
using AIStudio.Tools.Services;
using AIStudio.Tools.Validation;
namespace AIStudio.Tests.Tools;
@@ -122,7 +123,7 @@ public class FileTypesTests
public void DialogFilterMatchesTheRuntimeContract()
{
// The struct FileTypeFilter in runtime/src/file_actions.rs knows exactly these two fields:
var json = JsonSerializer.Serialize(FileTypes.ToFileDialogFilter(FileTypes.JSON), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower });
var json = JsonSerializer.Serialize(FileTypes.ToFileDialogFilter(FileTypes.JSON), RustService.JSON_OPTIONS);
Assert.That(json, Is.EqualTo("""{"filter_name":"JSON","filter_extensions":["json"]}"""));
}
+4 -13
View File
@@ -11,27 +11,18 @@ namespace AIStudio.Tests.Tools;
/// <remarks>
/// ShareFileResponse in runtime/src/share_sheet.rs names the outcome in snake case. A name which the
/// app does not know would not fail anywhere: the enum converter falls back to the first member, and
/// a share sheet which did not respond would go unnoticed again. The options mirror what RustService
/// deserializes with.
/// a share sheet which did not respond would go unnoticed again. The answers are read with the options
/// of RustService itself.
/// </remarks>
[TestFixture]
public sealed class ShareFileResponseTests
{
private static readonly JsonSerializerOptions AS_THE_RUST_SERVICE_READS_IT = new()
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
Converters =
{
new RustEnumConverter(),
},
};
[TestCase("opened", ShareSheetOutcome.OPENED)]
[TestCase("failed", ShareSheetOutcome.FAILED)]
[TestCase("unresponsive", ShareSheetOutcome.UNRESPONSIVE)]
public void TheAppReadsEveryOutcomeOfTheRuntime(string outcome, ShareSheetOutcome expectedOutcome)
{
var response = JsonSerializer.Deserialize<ShareFileResponse>($$"""{"outcome":"{{outcome}}","issue":"The main window is not available."}""", AS_THE_RUST_SERVICE_READS_IT);
var response = JsonSerializer.Deserialize<ShareFileResponse>($$"""{"outcome":"{{outcome}}","issue":"The main window is not available."}""", RustService.JSON_OPTIONS);
Assert.That(response, Is.Not.Null);
using (Assert.EnterMultipleScope())
@@ -44,7 +35,7 @@ public sealed class ShareFileResponseTests
[Test]
public void AnUnknownOutcomeNeverCountsAsAnOpenedShareSheet()
{
var response = JsonSerializer.Deserialize<ShareFileResponse>("""{"outcome":"vanished","issue":""}""", AS_THE_RUST_SERVICE_READS_IT);
var response = JsonSerializer.Deserialize<ShareFileResponse>("""{"outcome":"vanished","issue":""}""", RustService.JSON_OPTIONS);
Assert.That(response?.Outcome, Is.EqualTo(ShareSheetOutcome.UNKNOWN));
}