diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index 301661f69af9f3..ccd4b435dc5253 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -129,9 +129,19 @@ public IReadOnlyDictionary FindAndAssertDotnetFiles( if (!match.Success) return true; - actual[expectedFilename] = new(ExpectedFilename: expectedFilename, - Hash: match.Groups[1].Value, - ActualPath: actualFile); + // Multiple fingerprinted variants of the same logical file can coexist when + // republishing into an existing output directory: the previous publish's + // fingerprinted copy is not removed, and a rebuild that changes the file's + // content produces a new fingerprint alongside the stale one. Keep the newest + // file so the assertion compares against the current (re)build output instead + // of picking a stale artifact by filename ordering. + if (!actual.TryGetValue(expectedFilename, out DotNetFileName? existingMatch) || + File.GetLastWriteTimeUtc(actualFile) >= File.GetLastWriteTimeUtc(existingMatch.ActualPath)) + { + actual[expectedFilename] = new(ExpectedFilename: expectedFilename, + Hash: match.Groups[1].Value, + ActualPath: actualFile); + } } else { diff --git a/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs b/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs index bff7ffb3827a40..931f177dc8a10e 100644 --- a/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs +++ b/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs @@ -1,6 +1,7 @@ using System; using System.Security.Cryptography; using System.Text; +using System.Text.RegularExpressions; public class Test { public static int Main() @@ -12,6 +13,13 @@ public static int Main() byte[] hashBytes = sha256.ComputeHash(inputBytes); Console.WriteLine($"Hash of {input}: {Convert.ToBase64String(hashBytes)}"); } + + // Also reference System.Text.RegularExpressions, which is not otherwise part of + // the test app's closure, so that rebuilding pulls in a *new* assembly. This + // ensures native artifacts that depend on the set of assemblies (e.g. the AOT + // modules table driver-gen.c) are regenerated on rebuild. + bool isMatch = Regex.IsMatch(input, "[A-Za-z]+"); + Console.WriteLine($"Input '{input}' matches: {isMatch}"); return 42; } }