Skip to content

[coreclr] Fix LoadLibraryInitializer test#125176

Open
ilonatommy wants to merge 6 commits intodotnet:mainfrom
ilonatommy:fix-LoadLibraryInitializer
Open

[coreclr] Fix LoadLibraryInitializer test#125176
ilonatommy wants to merge 6 commits intodotnet:mainfrom
ilonatommy:fix-LoadLibraryInitializer

Conversation

@ilonatommy
Copy link
Member

Fixes #124899.

The CoreCLR WASM loader had several gaps preventing library initializers from working correctly. This PR fixes the loader and adds a CoreCLR-specific test.

Loader changes (run.ts, exit.ts)

  1. run.ts: invokeLibraryInitializers now takes an args parameter — passes loaderConfig for onRuntimeConfigLoaded and dotnetApi for onRuntimeReady (which has getAssemblyExports/getConfig, matching what Mono does)
  2. exit.ts: Restored runtimeState.creatingRuntime check (needed because dotnetReady is already true when onRuntimeReady throws)
  3. run.ts: Call onRuntimeReady on all library initializers (both modulesAfterConfigLoaded and modulesAfterRuntimeReady), since the SDK only lists lib modules in modulesAfterConfigLoaded
  4. run.ts: Wrap library initializer errors with script name in a shared invokeLibraryInitializers helper

Test changes

  • Made AbortStartupOnError Mono-only; added AbortStartupOnError_CoreCLR that throws in onRuntimeReady and checks for the abort message with script name
  • Added throwErrorOnReady query param support to WasmBasicTestApp.lib.module.js
  • Added IsCoreClrRuntime helper to BuildTestBase.cs
  • Added LibraryInitializerTests to BuildWasmAppsJobsListCoreCLR.txt to re-enable it

…added AbortStartupOnError_CoreCLR that throws in onRuntimeReady (later lifecycle hook) and checks for the abort message with script name

   2. WasmBasicTestApp.lib.module.js — Added throwErrorOnReady param to trigger error in onRuntimeReady (for CoreCLR test)
   3. run.ts — Wrapped library initializer calls with try/catch that includes the script name in the error message; extracted shared invokeLibraryInitializers helper
   4. BuildTestBase.cs — Added IsCoreClrRuntime helper property to support test separation.
   5. BuildWasmAppsJobsListCoreCLR.txt — Added LibraryInitializerTests to CoreCLR CI job list
@ilonatommy ilonatommy requested a review from pavelsavara March 4, 2026 13:46
@ilonatommy ilonatommy self-assigned this Mar 4, 2026
@ilonatommy ilonatommy requested a review from maraf as a code owner March 4, 2026 13:46
Copilot AI review requested due to automatic review settings March 4, 2026 13:46
@ilonatommy ilonatommy added arch-wasm WebAssembly architecture area-Infrastructure-coreclr os-browser Browser variant of arch-wasm labels Mar 4, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes CoreCLR WASM loader behavior so library initializer modules are invoked with the expected arguments and errors during startup correctly trigger abort behavior, and re-enables coverage via a CoreCLR-specific test.

Changes:

  • Update loader startup flow to invoke library initializers with the appropriate argument (loaderConfig for onRuntimeConfigLoaded, dotnetApi for onRuntimeReady) and to call onRuntimeReady for modules listed in modulesAfterConfigLoaded.
  • Restore startup abort behavior by keying abort logic off runtimeState.creatingRuntime.
  • Add/adjust WASM build tests and test assets to validate CoreCLR behavior and re-enable the test in CoreCLR job list.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/native/libs/Common/JavaScript/loader/run.ts Refactors library initializer invocation and changes onRuntimeReady to receive dotnetApi.
src/native/libs/Common/JavaScript/loader/exit.ts Uses creatingRuntime to decide whether to abort startup on exit.
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/WasmBasicTestApp.lib.module.js Adds query param to throw from onRuntimeReady to validate abort behavior.
src/mono/wasm/Wasm.Build.Tests/LibraryInitializerTests.cs Splits Mono/CoreCLR coverage and adds CoreCLR-specific abort assertion.
src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs Adds IsCoreClrRuntime helper for conditional test execution.
eng/testing/scenarios/BuildWasmAppsJobsListCoreCLR.txt Re-enables Wasm.Build.Tests.LibraryInitializerTests for CoreCLR scenario runs.

@ilonatommy ilonatommy force-pushed the fix-LoadLibraryInitializer branch from c6d8572 to 24e2e5c Compare March 4, 2026 14:31
Copilot AI review requested due to automatic review settings March 4, 2026 14:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

@dotnet dotnet deleted a comment from Copilot AI Mar 4, 2026
Copilot AI review requested due to automatic review settings March 4, 2026 15:02
@ilonatommy ilonatommy force-pushed the fix-LoadLibraryInitializer branch from 88f7bd3 to d4bf3f2 Compare March 4, 2026 15:02
…sses loaderConfig for onRuntimeConfigLoaded and dotnetApi for onRuntimeReady (which has getAssemblyExports/getConfig, matching what Mono does)

2. exit.ts: Restored runtimeState.creatingRuntime check (needed because dotnetReady is already true when onRuntimeReady throws)
3. run.ts: Call onRuntimeReady on all library initializers (both modulesAfterConfigLoaded and modulesAfterRuntimeReady), since the SDK only lists lib modules in modulesAfterConfigLoaded
4. run.ts: Wrap library initializer errors with script name in a shared invokeLibraryInitializers helper
5. run.ts: Skip onDotnetReady/onRuntimeReady hooks when downloadOnly is true (runtime is not initialized, so dotnetApi would throw)
@ilonatommy ilonatommy force-pushed the fix-LoadLibraryInitializer branch from d4bf3f2 to 2cee239 Compare March 4, 2026 15:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings March 6, 2026 15:04
@ilonatommy ilonatommy enabled auto-merge (squash) March 6, 2026 15:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

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

Labels

arch-wasm WebAssembly architecture area-Infrastructure-coreclr os-browser Browser variant of arch-wasm

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[coreclr] LoadLibraryInitializer throws exception

4 participants