From c4cc96fde1827214756c0b3e5a9cde18b1fc03d0 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 13 Jul 2026 19:00:57 -0500 Subject: [PATCH] [wasm] Harden ReferenceNewAssemblyRebuildTest against closure changes The test relied on System.Security.Cryptography being absent from the WasmBasicTestApp's AOT closure: swapping the entry point to one that used SHA256 was expected to introduce a new AOT module and thus change driver-gen.c (the AOT modules table). That assumption broke when System.IO.Compression started referencing System.Security.Cryptography (dotnet/runtime#122093), which roots crypto into the base app via ZipArchiveInteropTest. Crypto is now always AOT'd, so the swapped entry point adds nothing, driver-gen.c is unchanged, and the test fails (dotnet/runtime#130540). This is the second time the test rotted this way (Json -> crypto in #109069). Instead of chasing another BCL assembly that happens to be absent, use a dedicated first-party library (the existing empty "Library" test project) that the default app does not reference. It is trimmed away on the first build and only enters the AOT module set once the swapped entry point uses it, so the test fully controls the new-assembly signal and is immune to future changes in the app's dependency closure. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f05b19b1-9e98-4565-9efb-bee27f2a85c2 --- .../ReferenceNewAssemblyRebuildTest.cs | 8 ++++++- .../EntryPoints/NativeRebuildNewAssembly.cs | 21 +++++++------------ .../NativeRebuildReferencedLibrary.cs | 6 ++++++ 3 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 src/mono/wasm/testassets/EntryPoints/NativeRebuildReferencedLibrary.cs diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/ReferenceNewAssemblyRebuildTest.cs b/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/ReferenceNewAssemblyRebuildTest.cs index e1620d2dd77101..15f33923a1b8a4 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/ReferenceNewAssemblyRebuildTest.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/ReferenceNewAssemblyRebuildTest.cs @@ -25,7 +25,13 @@ public ReferenceNewAssemblyRebuildTest(ITestOutputHelper output, SharedBuildPerT [MemberData(nameof(NativeBuildData))] public async Task ReferenceNewAssembly(Configuration config, bool aot, bool nativeRelink, bool invariant) { - ProjectInfo info = CopyTestAsset(config, aot, TestAsset.WasmBasicTestApp, "rebuild_tasks"); + // Reference a dedicated first-party library that the default app does not use, so it is + // trimmed away on the first build and only enters the AOT module set once the swapped + // entry point references it. Relying on a specific BCL assembly being absent from the + // closure is fragile (it has silently regressed as the base app's dependencies grew). + string extraItems = @""; + ProjectInfo info = CopyTestAsset(config, aot, TestAsset.WasmBasicTestApp, "rebuild_tasks", extraItems: extraItems); + ReplaceFile(Path.Combine("..", "Library", "Library.cs"), Path.Combine(BuildEnvironment.TestAssetsPath, "EntryPoints", "NativeRebuildReferencedLibrary.cs")); BuildPaths paths = await FirstNativeBuildAndRun(info, config, aot, nativeRelink, invariant); var pathsDict = GetFilesTable(info.ProjectName, aot, paths, unchanged: false); diff --git a/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs b/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs index bff7ffb3827a40..f870ba88b7f828 100644 --- a/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs +++ b/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs @@ -1,17 +1,10 @@ -using System; -using System.Security.Cryptography; -using System.Text; +// Reference a dedicated first-party library ("Library") that is not part of +// the WasmBasicTestApp's default assembly closure. This guarantees the rebuild +// pulls in a genuinely new AOT module, regardless of which BCL assemblies the +// base app happens to root. +using NativeRebuildReferencedLibrary; + public class Test { - public static int Main() - { - string input = "Hello, world!"; - using (SHA256 sha256 = SHA256.Create()) - { - byte[] inputBytes = Encoding.UTF8.GetBytes(input); - byte[] hashBytes = sha256.ComputeHash(inputBytes); - Console.WriteLine($"Hash of {input}: {Convert.ToBase64String(hashBytes)}"); - } - return 42; - } + public static int Main() => NewlyReferencedType.GetValue(); } diff --git a/src/mono/wasm/testassets/EntryPoints/NativeRebuildReferencedLibrary.cs b/src/mono/wasm/testassets/EntryPoints/NativeRebuildReferencedLibrary.cs new file mode 100644 index 00000000000000..9d2c0ed0d0ba6c --- /dev/null +++ b/src/mono/wasm/testassets/EntryPoints/NativeRebuildReferencedLibrary.cs @@ -0,0 +1,6 @@ +namespace NativeRebuildReferencedLibrary; + +public static class NewlyReferencedType +{ + public static int GetValue() => 42; +}