Skip to content

[wasm] Harden ReferenceNewAssemblyRebuildTest against dependency-closure changes#130655

Closed
lewing wants to merge 1 commit into
mainfrom
lewing-harden-wasm-native-rebuild-test
Closed

[wasm] Harden ReferenceNewAssemblyRebuildTest against dependency-closure changes#130655
lewing wants to merge 1 commit into
mainfrom
lewing-harden-wasm-native-rebuild-test

Conversation

@lewing

@lewing lewing commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

Wasm.Build.NativeRebuild.Tests.ReferenceNewAssemblyRebuildTest has been failing on the browser-wasm AOT leg (Known Build Error #130540, "Expected changed file: driver-gen.c"). This hardens the test so it no longer depends on the app's incidental dependency closure.

Root cause

The test replaces the app's entry point with one that references a "new" assembly, then asserts that driver-gen.c — the AOT modules table, one mono_aot_register_module line per AOT'd assembly — changes because a new module was added.

It relied on System.Security.Cryptography being absent from WasmBasicTestApp's AOT closure (the swapped entry point used SHA256). That assumption broke when #122093 ("Add Zip Archives password support") added an unconditional System.Security.Cryptography ProjectReference to System.IO.Compression. The app always compiles ZipArchiveInteropTest.cs (uses System.IO.Compression), so crypto is now always in the closure and always AOT'd. The swapped entry point therefore adds no new module, driver-gen.c is byte-identical between build and rebuild, MonoAOTCompiler's CopyIfDifferent skips the write, the timestamp is unchanged, and CompareStat fails.

This is the second time the test rotted this way — #109069 previously switched it from Json to System.Security.Cryptography for the same reason ("Json lib was already referenced before the change in the test").

Fix

Stop guessing which BCL assembly happens to be absent. Instead reference the existing dedicated first-party Library test project (an empty library not referenced by the default app), following the same pattern already used by PInvokeTableGeneratorTests:

  • Inject <ProjectReference Include="..\Library\Library.csproj" /> via CopyTestAsset(extraItems: ...).
  • Populate Library.cs with a small type via ReplaceFile.
  • Point the swapped entry point (NativeRebuildNewAssembly.cs) at that type instead of SHA256.

Library is unused in the first build → trimmed away → absent from the AOT module set. The swapped entry point uses it → rooted → new module in the rebuild → driver-gen.c changes. Because Library is first-party and the test fully controls whether it is referenced, the new-assembly signal is deterministic and immune to future changes in the app's dependency closure.

Fixes #130540.

Related

The underlying dependency regression (crypto rooted into every trimmed app that uses ZipArchive, a browser-wasm size concern) is tracked separately in #130650.

Testing

Not built/run locally — WBT requires a browser-wasm runtime baseline + emscripten and executes in a browser via the Helix/xharness harness. Relying on CI (the failing AOT leg exercises exactly this test) to validate.

Note

This PR was authored with the assistance of GitHub Copilot.

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 (#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 (#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
Copilot AI review requested due to automatic review settings July 14, 2026 00:01
@lewing lewing requested review from ilonatommy and maraf as code owners July 14, 2026 00:01
@lewing lewing temporarily deployed to copilot-pat-pool July 14, 2026 00:01 — with GitHub Actions Inactive
@lewing lewing temporarily deployed to copilot-pat-pool July 14, 2026 00:01 — with GitHub Actions Inactive
@lewing lewing had a problem deploying to copilot-pat-pool July 14, 2026 00:02 — with GitHub Actions Failure
@lewing lewing temporarily deployed to copilot-pat-pool July 14, 2026 00:03 — with GitHub Actions Inactive
@lewing lewing temporarily deployed to copilot-pat-pool July 14, 2026 00:03 — with GitHub Actions Inactive
@lewing lewing temporarily deployed to copilot-pat-pool July 14, 2026 00:04 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens the Wasm.Build.NativeRebuild.Tests.ReferenceNewAssemblyRebuildTest to make the “new AOT module added” signal deterministic by referencing a dedicated first-party test library, instead of relying on an incidental BCL dependency being absent/present in the app’s dependency closure.

Changes:

  • Injects a ProjectReference to WasmBasicTestApp/Library into the copied test asset and populates Library.cs with a controlled type.
  • Updates the “swapped entry point” (NativeRebuildNewAssembly.cs) to reference the new library type instead of System.Security.Cryptography.
  • Adds a new entrypoint source file (NativeRebuildReferencedLibrary.cs) used to overwrite the library’s source during the test setup.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/ReferenceNewAssemblyRebuildTest.cs Injects a ProjectReference to the test Library project and replaces Library.cs so the rebuild deterministically pulls in a new rooted assembly.
src/mono/wasm/testassets/EntryPoints/NativeRebuildReferencedLibrary.cs New testasset snippet defining NewlyReferencedType, used as the “new assembly” signal.
src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs Switches the rebuilt entry point to call into NewlyReferencedType rather than crypto APIs.

@lewing lewing added the arch-wasm WebAssembly architecture label Jul 14, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Build-mono

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wasm.Build.NativeRebuild.Tests.ReferenceNewAssemblyRebuildTest.ReferenceNewAssembly failure: Expected changed file: driver-gen.c

2 participants