Add golden-master tests for the Aot generator and measure its coverage - #204
Merged
Conversation
…ted code The generator was an analyzer (ReferenceOutputAssembly=false), so its code was never loaded in a test process: coverlet measured 0% over ~300 lines and Sonar saw no coverage on JsonSubTypes.Aot. - JsonSubTypes.Aot.Generated: the committed test domain (TestDomain.cs) plus the .g.cs files the generator emits for it, compiled as real sources so Sonar analyzes them and coverlet measures them. - JsonSubTypes.Aot.Generator.Tests: runs the generator in-process via the Roslyn driver (covers JsonSubTypesGenerator.cs), executes the generated converters (serialization/deserialization), and verifies the committed .g.cs match the current generator output (golden master, breaks on any output drift). - CI: the modern and analysis jobs run these tests with coverage and hand the report to Codecov/Sonar. The analysis job now also runs on pull requests (pull-request parameters + GITHUB_TOKEN for quality-gate decoration), and .g.cs are excluded from Sonar's duplication check but still analyzed.
…suffix Bug: two base types with the same short name in different namespaces produced two converters with the same class name and file hint (CS0101, file collision). Converter names now stay short when unique and are qualified with the sanitized namespace only when the short name collides; the registry keeps the short member name so existing consumers (sample, tests) are unaffected. Covered by a driver test with two homonymous Animal classes. The committed golden master files in JsonSubTypes.Aot.Generated are renamed from .g.cs to .cs so Sonar does not treat them as generated code; the golden-master test maps the generator's .g.cs hint names to the committed files.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #204 +/- ##
==========================================
- Coverage 92.32% 90.21% -2.11%
==========================================
Files 18 19 +1
Lines 964 1789 +825
Branches 200 294 +94
==========================================
+ Hits 890 1614 +724
- Misses 41 106 +65
- Partials 33 69 +36 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The pull-request branch name (github.head_ref) is user-controlled and was interpolated directly into the shell script, enabling injection. Pass it via an environment variable instead (GitHub sanitizes env values in run blocks). Add codecov.yml excluding the golden-master project (JsonSubTypes.Aot.Generated and the generator tests) from the project/patch checks: its committed generated code is exercised only partially by the generator tests, so counting it dragged the project coverage to 64% and the patch check to 9%.
With target: auto, any drop fails; adding the now-analyzed generator code shifted the baseline by ~2%. A 5% threshold absorbs legitimate variation while still catching real regressions.
Only Animal was tested, so the other generated converters (Person, Gadget, DottedGadget, Payload, Game) sat at ~0% coverage. Add serialize/deserialize tests for each, plus a JsonSerializable context so the nested Payload->Game hierarchy resolves at runtime. Generated converters now show real coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
JsonSubTypes.Aotgenerator is an analyzer (ReferenceOutputAssembly=false), so its code is never loaded in a test process: coverlet measured 0% over ~300 lines and Sonar saw no coverage, dragging the project'snew_coveragegate down to ~48%.Fix
JsonSubTypes.Aot.Generated: committed test domain (TestDomain.cs) plus the.csfiles the generator emits for it, compiled as real sources. Named without the generator's.g.cssuffix so Sonar analyzes them as regular code.JsonSubTypes.Aot.Generator.Tests: runs the generator in-process via the Roslyn driver (coversJsonSubTypesGenerator.cs), executes the generated converters (serialization/deserialization), and a golden-master test asserts the committed files exactly match the current generator output.modernandanalysisjobs run the new tests with coverage and hand the report to Codecov/Sonar. Theanalysisjob now also runs on pull requests (PR parameters +GITHUB_TOKENfor quality-gate decoration)..g.csare excluded from Sonar's duplication check but still analyzed.Tests
Honest note(s)
analysisjob will run Sonar on the branch for the first time; whether the committed.csfiles are treated as regular (non-generated) code is verified by that run, not locally.