Skip to content

fix(stjm)!: surface actionable trimming and NativeAOT warnings - #260

Merged
egil merged 5 commits into
mainfrom
egil/stjm-256-trimming-diagnostics
Sep 25, 2026
Merged

egil merged 5 commits into
mainfrom
egil/stjm-256-trimming-diagnostics

Conversation

@egil

@egil egil commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Migration-enabled applications can currently build without learning that discovery and runtime generic construction are unsupported under trimming or NativeAOT. This change reports actionable IL2026 and IL3050 warnings at public setup and registration calls, including callers using generated JSON metadata.

Changes

  • Annotate both AddJsonMigrationSupport overloads, all migrator registration methods, and the .NET 11 union classifier constructor. Messages name the unsupported behavior, corrective publish settings, and optional documentation URL.
  • Enable trim/AOT analysis for net10.0 and net11.0. Propagate requirements internally, preserve interface/override contracts with narrow justified callback suppressions, and retain service-provider activation without adding a new() constraint.
  • Add packed-package consumer checks for diagnostic IDs, real consumer source locations, message content, generated JSON metadata, generic/assembly registration, and union activation. Reject unexpected warnings and retain package hashes and diagnostic logs.
  • Document the supported untrimmed deployment and add CI checks for rooted trimmed and NativeAOT publishes on both frameworks.

No AOT-safe registration API or source generator is introduced; JSON source generation and warning-free library analysis are not presented as proof of AOT support.

Consumers treating trim/AOT warnings as errors may now fail their builds; the diagnostic change is marked as breaking in the commit history.

Validation

  • Baseline package fails the new check because IL2026 is missing at the setup call; the untrimmed control succeeds.
  • Release solution build: zero warnings/errors. Existing tests: 1,221 passed across both target frameworks.
  • Packed consumers: ordinary builds/runtime controls, trim/AOT diagnostic builds, rooted trimmed publishing, and NativeAOT compiler analysis pass on both frameworks. Controls include a DI-created external migrator without a parameterless constructor.
  • Documentation snippet generation and git diff --check pass.

Remaining limitations

  • Full rooted trimmed and NativeAOT publishes passed for net10.0 and net11.0 on Linux at commit bc8b137 (CI run). The packaged diagnostic checks, tests, documentation snippets, and package validation all passed. Local Windows native linking remains unverified because the C++ toolchain is unavailable; the local check used -Publish -NativeCompileOnly.
  • Previously measured aggregate branch coverage is 97.00% on .NET 10 and 97.99% on .NET 11. Several core classes remain below the repository's required 100%; this gate is not claimed as satisfied. The existing follow-up is #249; tracking it is not a waiver.

Closes #256.

Independent review

  • Standards: one finding—the documented core branch-coverage gate remains unmet. No other standards findings or maintainability smells were reported.
  • Spec: no actionable findings against the live issue. Subsequent CI verified full Linux NativeAOT publishing on both target frameworks.

Review remediation

At bc8b137, resolver constructors enforce the diagnostic boundary, callback suppressions share their rationale, and the consumer verifier checks warning explanations and validates package names. Source-location and reflection comments document their constraints; source-generation documentation points to the deployment rule. All 1,221 tests and local packed-consumer checks passed again. Independent Standards and Spec review found no new issues in the remediation delta. CI on this exact head passed tests, documentation snippets, package validation, and full Linux trimmed/NativeAOT publishing on both frameworks. All ten inline review threads were addressed and resolved.

Migration setup and registration now report standard trimming and NativeAOT diagnostics at consumer call sites, including configurations with generated JSON metadata. Messages explain the unsupported behavior and the deployment settings needed to avoid it.

Enable library analysis on both supported frameworks and verify the packed consumer contract without introducing a new registration API or changing service-provider activation.
Document the supported untrimmed deployment settings and distinguish JSON source generation from migration AOT compatibility.
Run trimmed and NativeAOT publish analysis for both supported frameworks and retain diagnostic evidence for package consumers.
@egil
egil marked this pull request as ready for review September 24, 2026 16:37
Copilot AI lite review requested due to automatic review settings September 24, 2026 16:37

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.

Copilot review overview

🔵 Needs a closer look

One or more issues must be addressed before approval.

Review effort: Lite
Findings: None

What changed in this PR

Adds actionable IL2026/IL3050 diagnostics for migration APIs and validates them through packed consumers on .NET 10/11.

Changes:

  • Annotates public setup, registration, and union-classifier APIs.
  • Enables trim/AOT analysis with targeted suppressions.
  • Adds consumer validation, documentation, and CI NativeAOT checks.
File Description
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Migrations/​UnionCaseRouting.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Migrations/​StaticMigratorContracts.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Migrations/​ResolverLeaves.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Migrations/​PlainContractResolver.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Migrations/​MigratorReference.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Migrations/​MigratorInvokerFactory.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Migrations/​JsonMigrationTypeInfoResolver.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Migrations/​JsonMigratableTypes.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Migrations/​ExternalMigratorInvoker.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​MigrationCompatibility.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​JsonMigrationSerializerOptionsExtensions.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​JsonMigrationBuilder.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​JsonMigratableUnionTypeClassifier.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​src/​Egil.SystemTextJson.Migration/​Egil.SystemTextJson.Migration.csproj Updated as part of this pull request.
Egil.SystemTextJson.Migration/​scripts/​verify-trimming-package.ps1 Updated as part of this pull request.
Egil.SystemTextJson.Migration/​scripts/​trimming-consumer/​Program.cs Updated as part of this pull request.
Egil.SystemTextJson.Migration/​docs/​recipes/​aot-source-gen.md Updated as part of this pull request.
.github/​workflows/​egil-systemtextjson-migration-ci.yml Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@egil egil left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Two-axis review (Standards and Spec against #256). Nothing blocking: every public entry point that reaches discovery, reflection or MakeGenericType is annotated, the suppressions sit only on interface/override callbacks, and CI runs the packed-consumer check. The inline comments are suggestions.

Standards

  • Hard, not caused by this PR: Egil.SystemTextJson.Migration/AGENTS.md requires "Core components must maintain 100% branch coverage". The PR reports 97.00% (.NET 10) and 97.99% (.NET 11). This needs a tracking issue instead of an implicit waiver.
  • Consider a BREAKING CHANGE footer on the fix commit. Consumers who run trim/AOT analysis with warnings-as-errors will now fail to build.
  • MigrationCompatibility holds diagnostic message text, not compatibility logic. A name like TrimmingDiagnostics would say what it holds. This is a judgement call.

Spec

  • Partial: the script doesn't assert the explanation part of the warning messages (inline on verify-trimming-package.ps1:66-71).
  • Slightly beyond scope: CI installs clang and does a full NativeAOT native link, where #256 asks for publish analysis. It's useful evidence, but it costs CI time and depends on the runner. The PR correctly doesn't run the native output, which belongs to the follow-up issue.
  • Nit: the docs still say "compatible with System.Text.Json source generation" (inline).

Comment thread Egil.SystemTextJson.Migration/scripts/verify-trimming-package.ps1
Comment thread Egil.SystemTextJson.Migration/scripts/verify-trimming-package.ps1
Comment thread Egil.SystemTextJson.Migration/scripts/verify-trimming-package.ps1
Comment thread Egil.SystemTextJson.Migration/scripts/verify-trimming-package.ps1
Comment thread Egil.SystemTextJson.Migration/scripts/verify-trimming-package.ps1 Outdated
Comment thread Egil.SystemTextJson.Migration/docs/recipes/aot-source-gen.md Outdated
Comment thread Egil.SystemTextJson.Migration/docs/recipes/aot-source-gen.md Outdated
Require trimming and dynamic-code diagnostics when constructing deferred resolvers, and verify that packaged warnings explain the unsupported behavior. Validate package inputs and document the source-location contract used by consumer checks.

BREAKING CHANGE: Migration setup and registration APIs now emit IL2026 and IL3050 when the corresponding analyzers are enabled. Consumers treating these warnings as errors must account for the unsupported deployment requirements.
…otes]

Separate serialization metadata support from deployment compatibility and explain the runtime limitations without duplicating the deployment rule.
Copilot AI review requested due to automatic review settings September 24, 2026 17:20
@egil egil changed the title fix(stjm): surface actionable trimming and NativeAOT warnings fix(stjm)!: surface actionable trimming and NativeAOT warnings Sep 24, 2026

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.

Copilot review overview

🔵 Needs a closer look

One or more issues must be addressed before approval.

Review effort: Lite
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Low severity Unmet core branch coverage gate lacks approved exception

.github/​workflows/​egil-systemtextjson-migration-ci.yml:70

The project policy requires 100% branch coverage for core components, but this PR explicitly leaves that gate unmet (97.00% on .NET 10 and 97.99% on .NET 11) and only points to open issue #249. Adding the trim/AOT verification here does not establish the required coverage disposition or an owner-approved exception, so this must be resolved before treating the CI validation as approval-ready.

egil commented Sep 24, 2026

Copy link
Copy Markdown
Owner Author

Addressed and resolved all ten inline suggestions in faf9644/bc8b137. The 1,221 local tests and both-framework packed-consumer checks passed; CI on bc8b137 passed tests, docs, package validation, and full trimmed/NativeAOT publishing: https://github.com/egil/framework/actions/runs/36033651215. Independent Standards and Spec review found no new issues in the remediation delta.

The existing core-coverage gap is already tracked by #249, now linked from the PR; this remains an unmet gate, not a waiver. Added the BREAKING CHANGE footer and matching PR title for warnings-as-errors consumers. Kept the existing internal helper name to avoid an optional cross-file rename, and retained full Linux native linking as useful package evidence (the native output is not run).

@claude

claude Bot commented Sep 24, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@egil
egil merged commit 28da64b into main Sep 25, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(stjm): surface actionable trimming and NativeAOT warnings at public entry points

2 participants