Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 15, 2025

  • Mark DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException test as [OuterLoop]
  • Add 136 tests systematically targeting uncovered code paths
  • Final Coverage: 94.27% line, 90.60% branch, 93.40% method (baseline: 93.73%, +0.54% improvement)
  • Fix OutOfMemoryException in validation tests
  • Convert all JSON string constants to raw string literals (per code review feedback)
  • Replace wasteful JsonSerializerOptions creation with JsonSerializerOptions.Default (per code review feedback)
  • Revert incorrect line in JsonValueTests to use options variable (per code review feedback)
  • Convert additional JSON strings to raw string literals in DomTests.cs (per code review feedback)
  • All 49,787 tests passing

Summary

Through systematic iterations, this PR improved System.Text.Json coverage from 93.73% to 94.27% (+0.54%) by adding 136 targeted unit tests covering previously untested API surfaces including JsonSerializer methods with JsonTypeInfo/JsonSerializerContext, multi-segment Utf8JsonReader scenarios, JsonWriter formatting options, JsonNode operations, JsonNamingPolicy variants, and collection serialization.

Remaining gaps to reach 95% (~215 lines) consist primarily of complex Utf8JsonReader edge cases requiring specialized buffer setups, ThrowHelper exception paths, and F# converter infrastructure.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 15, 2025
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Maximize code coverage for System.Text.Json library Improve code coverage for System.Text.Json with targeted unit tests Oct 15, 2025
@Copilot Copilot AI requested a review from stephentoub October 15, 2025 04:24
Copilot finished work on behalf of stephentoub October 15, 2025 04:24
@stephentoub
Copy link
Member

@copilot, please mark the DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException test as [Outerloop] and try again, following my original instructions.

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot, please mark the DeepEquals_TooDeepJsonDocument_ThrowsInsufficientExecutionStackException test as [Outerloop] and try again, following my original instructions.

Done. Marked the test as [OuterLoop] and reverted the other test changes that had incorrect assertions. All tests now pass. Changes committed in edead34.

Copilot finished work on behalf of stephentoub October 15, 2025 15:47
@stephentoub
Copy link
Member

@copilot:

  1. Run the existing test suite for System.Text.Json with coverage enabled (/p:Coverage=true) and collect detailed coverage reports.
  2. Analyze the reports to identify uncovered code paths, methods, or branches within System.Text.Json.
  3. Systematically add new unit tests targeting uncovered or under-tested areas, aiming to bring coverage as close to 100% as possible while maintaining meaningful test quality.
  4. Re-run the coverage analysis with the new tests and compare results to verify improvement.
  5. Repeat steps 1-4, focusing on any remaining uncovered segments, until coverage is maximized for all practical purposes.

Copilot AI and others added 2 commits October 15, 2025 16:26
…Deserialize from Span

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot:

  1. Run the existing test suite for System.Text.Json with coverage enabled (/p:Coverage=true) and collect detailed coverage reports.
    ...

Working on it:

  1. ✅ Ran coverage analysis - baseline: 93.73% line, 90.52% branch, 93.02% method
  2. ✅ Analyzed reports - identified uncovered SerializeToDocument/Element/Node methods with JsonTypeInfo parameters, and Deserialize from Span methods
  3. ✅ Added 12 new unit tests targeting those uncovered methods
  4. Currently building and testing to verify improvement

Next steps: Will re-run coverage analysis and continue adding tests for remaining uncovered areas. Changes committed in eace0c3.

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@stephentoub
Copy link
Member

@copilot, please keep iterating: run coverage, add more tests to fill gaps, re-run coverage, add more tests to fill gaps, etc. Please try to get line and branch coverage to greater than 95%.

Copilot AI and others added 2 commits October 15, 2025 22:14
…th JsonTypeInfo

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
…alize methods

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot, please keep iterating: run coverage, add more tests to fill gaps, re-run coverage, add more tests to fill gaps, etc. Please try to get line and branch coverage to greater than 95%.

Continuing iterations:

Current Progress:

  • Baseline: 93.73% line, 90.52% branch
  • Current: 94.06% line, 90.51% branch (93.21% method)
  • Added 40 new tests across 3 commits (40a1e92, 0b52f02)

Tests Added:

  • JsonSerializer Deserialize/Serialize with JsonTypeInfo (generic & non-generic)
  • JsonSerializer methods with JsonSerializerContext
  • Coverage for Document, Element, Node, Span, Stream, Writer, Reader formats

Next Steps to reach >95%:
Working on additional edge cases and error paths. The remaining gaps are mostly in:

  • Utf8JsonReader edge cases (153 uncovered lines)
  • ThrowHelper methods (62 uncovered lines)
  • F# converters (not easily testable)

Continuing to add more tests...

Copilot finished work on behalf of stephentoub October 15, 2025 22:30
Copilot finished work on behalf of stephentoub October 17, 2025 01:26
@stephentoub stephentoub added area-System.Text.Json and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Oct 17, 2025
@stephentoub stephentoub marked this pull request as ready for review October 17, 2025 01:28
@Copilot Copilot AI review requested due to automatic review settings October 17, 2025 01:28
Copy link
Contributor

@Copilot 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

This PR systematically improves code coverage for the System.Text.Json library by analyzing coverage reports and adding targeted unit tests. The work progressed through 10 iterations, achieving a +0.54% increase in line coverage (from 93.73% to 94.27%), +0.08% in branch coverage, and +0.38% in method coverage through the addition of 136 new unit tests.

Key changes:

  • Added comprehensive test coverage for JsonSerializer DOM APIs with JsonTypeInfo and JsonSerializerContext parameters
  • Implemented edge case testing for Utf8JsonReader numeric and floating-point Get methods
  • Created extensive multi-segment reading tests for Utf8JsonReader boundary conditions
  • Added validation tests for Utf8JsonWriter with extreme input sizes
  • Expanded testing for JsonNode, JsonArray, JsonObject, and JsonValue types
  • Implemented comprehensive JsonNamingPolicy variant tests
  • Added tests for immutable collection serialization
  • Marked one long-running test with [OuterLoop] attribute to prevent blocking normal test runs

Reviewed Changes

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

Show a summary per file
File Description
Utf8JsonWriterTests.cs Added 15 tests for extreme input validation, raw value writing, minimized/indented formatting, and various data type serialization edge cases
Utf8JsonReaderTests.cs Added 3 tests for comment handling (Skip and Allow modes) with single-line and multi-line comments
Utf8JsonReaderTests.TryGet.cs Added 2 comprehensive tests covering numeric boundary values (byte, int, long, etc.) and floating-point edge cases (single, double)
Utf8JsonReaderTests.MultiSegment.cs Added 9 tests for complex multi-segment scenarios including nested JSON, long strings, escaped sequences, numbers with exponents, literals, deep nesting, and comments across segment boundaries
OptionsTests.cs Added 8 tests for PreferredObjectCreationHandling, TypeInfoResolverChain, WriteIndented, and DefaultBufferSize properties
JsonElementTests.cs Added [OuterLoop] attribute to prevent long-running stack overflow test from blocking normal test runs
DomTests.cs Added 43 tests for JsonSerializer methods with JsonTypeInfo/JsonSerializerContext parameters, covering Document/Element/Node serialization, span/stream/reader deserialization, and async PipeWriter/PipeReader operations
Array.ReadTests.cs Added 3 tests for large array and nested array deserialization scenarios
JsonValueTests.cs Added 8 tests for JsonValue.Create methods with various types and JsonTypeInfo parameters
JsonObjectTests.cs Added 4 tests for DeepEquals, TryGetPropertyValue, and ContainsKey operations
JsonNodeTests.cs Added 2 tests for ReplaceWith and Replace operations on nodes and properties
JsonArrayTests.cs Added 3 tests for DeepEquals with nested arrays and Clear operation behavior
JsonNamingPolicyTests.cs Added new test file with 30 tests covering all 5 naming policy variants (CamelCase, SnakeCaseLower, SnakeCaseUpper, KebabCaseLower, KebabCaseUpper) with 6 test cases each
JsonDocumentTests.cs Added 6 tests for GetDouble/GetSingle edge cases, JsonDocumentOptions, and Try methods
CollectionTests.Immutable.Write.cs Added 4 tests for ImmutableStack, ImmutableQueue, ImmutableHashSet, and ImmutableDictionary serialization

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@Copilot Copilot AI requested a review from stephentoub October 17, 2025 01:57
Copilot finished work on behalf of stephentoub October 17, 2025 01:57
@stephentoub
Copy link
Member

@copilot, please address the feedback from @eiriktsarpalis

…o avoid cache recreation

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 17, 2025

@copilot, please address the feedback from @eiriktsarpalis

Fixed in commit 0c7a2e5db. Replaced all instances of creating new JsonSerializerOptions with TypeInfoResolver with JsonSerializerOptions.Default to avoid wasteful cache recreation.

Copilot finished work on behalf of stephentoub October 17, 2025 14:40
…ons.Default

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@Copilot Copilot AI requested a review from stephentoub October 17, 2025 15:02
Copilot finished work on behalf of stephentoub October 17, 2025 15:02
[Fact]
public static void DeserializeFromSpan_WithJsonTypeInfo_NonGeneric()
{
ReadOnlySpan<byte> utf8Json = "{\"StringProp\":\"Hello\",\"IntArrayProp\":[1,2]}"u8;
Copy link
Member

Choose a reason for hiding this comment

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

More opportunities to use triple-quote strings here.

Copy link
Member

Choose a reason for hiding this comment

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

@eiriktsarpalis, copilot won't respond to address your feedback unless you tag it.

Copy link
Member

Choose a reason for hiding this comment

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

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot finished work on behalf of stephentoub October 17, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants