From 596aa59379c2aacefacc12694953fb1ae6c3c7a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 5 Aug 2026 11:52:49 +0200 Subject: [PATCH] Enforce warnings as errors for reflection-free acceptance builds Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 17e64d8a-9615-4707-bfe2-bc1e4d614589 --- .../AcceptanceSourceGen.cs | 9 ++++++++- .../TestAssetFixtureBase.cs | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/AcceptanceSourceGen.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/AcceptanceSourceGen.cs index d9c924eba2..6872031cef 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/AcceptanceSourceGen.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/AcceptanceSourceGen.cs @@ -98,6 +98,9 @@ public static async Task PrepareBuildArgumentsAsync(string assetDirector string sourceGenModeArg = metadataMode == MetadataMode.AotSourceGeneration ? " -p:MSTestSourceGenMode=ReflectionFree" : " -p:MSTestSourceGenMode=Rooting"; + string warningsAsErrorsArg = metadataMode == MetadataMode.AotSourceGeneration + ? " -p:MSBuildTreatWarningsAsErrors=true -p:TreatWarningsAsErrors=true" + : string.Empty; // - CustomBeforeMicrosoftCommonProps injects the source-generator PackageReference early // enough for restore to see it, without clobbering any Directory.Build.props. @@ -107,11 +110,15 @@ public static async Task PrepareBuildArgumentsAsync(string assetDirector // escape the quote on Windows and corrupt the argument. MSBuild accepts forward slashes on // all platforms. // - The version property feeds the resolved package version into the injected props. + // - ReflectionFree warnings are errors so AOTSG diagnostics for unsupported shapes cannot + // silently drop tests from the generated registry. MSBuild warnings remain errors as well, + // preserving the warning-clean build guarantee documented in the injected props. return $"-p:CustomBeforeMicrosoftCommonProps=\"{propsPath}\" " + $"-p:BaseOutputPath=\"bin/{outputSubFolder}/\" " + $"-p:BaseIntermediateOutputPath=\"obj/{outputSubFolder}/\" " + $"-p:{versionProperty}={version}" - + sourceGenModeArg; + + sourceGenModeArg + + warningsAsErrorsArg; } private static string BuildPropsContent(string packageId, string versionProperty) => diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/TestAssetFixtureBase.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/TestAssetFixtureBase.cs index d889ad38e7..43d3e7c82f 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/TestAssetFixtureBase.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/TestAssetFixtureBase.cs @@ -80,6 +80,9 @@ public async Task InitializeAsync(CancellationToken cancellationToken) DotnetMuxerResult sourceGenResult = await DotnetCli.RunAsync( $"build {testAsset.TargetAssetPath} -c Release {sourceGenArgs}", failIfReturnValueIsNotZero: false, + // ReflectionFree carries its own warning promotion in sourceGenArgs. Disable the + // shared default here so acceptance runs verify that mode-specific contract. + warnAsError: mode != MetadataMode.AotSourceGeneration, callerMemberName: $"{assetName}_{AcceptanceSourceGen.GetOutputSubFolder(mode)}", cancellationToken: cancellationToken);