Skip to content

Add test coverage for prerendering closed generic components#5

Open
tomerqodo wants to merge 2 commits into
coderabbit_full_base_add_test_coverage_for_prerendering_closed_generic_components_pr5from
coderabbit_full_head_add_test_coverage_for_prerendering_closed_generic_components_pr5
Open

Add test coverage for prerendering closed generic components#5
tomerqodo wants to merge 2 commits into
coderabbit_full_base_add_test_coverage_for_prerendering_closed_generic_components_pr5from
coderabbit_full_head_add_test_coverage_for_prerendering_closed_generic_components_pr5

Conversation

@tomerqodo

@tomerqodo tomerqodo commented Jan 29, 2026

Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#5

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for rendering closed generic components across server and client render modes, including prerendered and interactive scenarios. Tests validate marker generation, component metadata, and rendered output across different rendering configurations.

Copilot AI and others added 2 commits January 25, 2026 11:59
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jan 29, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request adds comprehensive test coverage for rendering and deserializing closed generic components in Blazor. A new generic test component (GenericComponent<TValue>) is introduced, accompanied by five new test methods validating behavior across server and client render modes, including both prerendered and non-prerendered scenarios.

Changes

Cohort / File(s) Summary
Generic Test Component
src/Components/Endpoints/test/TestComponents/GenericComponent.razor
New generic Blazor component with a type parameter TValue and a Value parameter that renders the parameterized value.
Endpoint Renderer Tests
src/Components/Endpoints/test/EndpointHtmlRendererTest.cs
Five new test methods validating closed generic component rendering in default, server, and client (WebAssembly) modes, including assertions on markers, descriptors, and prerendered content.
Deserialization Tests
src/Components/Server/test/Circuits/ServerComponentDeserializerTest.cs
New test cases for deserializing markers of closed generic components with int and string type parameters, plus minor formatting adjustments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Testing generics, types in flight,
<T> components render just right,
Server, client, prerender too,
Generic hopping, all paths through!
Markers dance and assertions bloom,
Coverage brightens the test room.

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is largely incomplete, providing only a benchmark PR link without following the required template structure or including any substantive summary of changes. Add a detailed description following the template: include a summary of changes (under 80 chars), detailed description section, and specify if this fixes any issues.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately and specifically describes the main change: adding test coverage for prerendering closed generic components, which aligns with all file modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch coderabbit_full_head_add_test_coverage_for_prerendering_closed_generic_components_pr5

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

1 similar comment
@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tomerqodo

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@sharoneyal

Copy link
Copy Markdown

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/Components/Endpoints/test/EndpointHtmlRendererTest.cs`:
- Around line 816-846: The assertions in
CanPrerender_ClosedGenericComponent_ClientMode are checking the wrong generic
type: change the expected assembly and type name checks that reference
GenericComponent<string> to instead reference GenericComponent<int> so they
match the rendered component (replace
typeof(GenericComponent<string>).Assembly.GetName().Name and
typeof(GenericComponent<string>).FullName with the corresponding
typeof(GenericComponent<int>) checks when asserting preambleMarker.Assembly and
preambleMarker.TypeName).

In `@src/Components/Server/test/Circuits/ServerComponentDeserializerTest.cs`:
- Around line 127-145: The test
CanParseMultipleMarkersForClosedGenericComponents has an incorrect assertion for
the second descriptor's sequence: change the assertion on
secondDescriptor.Sequence to expect 1 instead of 0 so it matches the
incrementing-sequence behavior (see CanParseMultipleMarkers and the descriptors
list created by
ServerComponentDeserializer.TryDeserializeComponentDescriptorCollection).

Comment on lines +816 to +846
[Fact]
public async Task CanPrerender_ClosedGenericComponent_ClientMode()
{
// Arrange
var httpContext = GetHttpContext();
var writer = new StringWriter();

// Act
var parameters = ParameterView.FromDictionary(new Dictionary<string, object> { { "Value", 456 } });
var result = await renderer.PrerenderComponentAsync(httpContext, typeof(GenericComponent<int>), RenderMode.InteractiveWebAssembly, parameters);
await renderer.Dispatcher.InvokeAsync(() => result.WriteTo(writer, HtmlEncoder.Default));
var content = writer.ToString();
content = AssertAndStripWebAssemblyOptions(content);
var match = Regex.Match(content, PrerenderedComponentPattern, RegexOptions.Multiline);

// Assert
Assert.True(match.Success);
var preamble = match.Groups["preamble"].Value;
var preambleMarker = JsonSerializer.Deserialize<ComponentMarker>(preamble, ServerComponentSerializationSettings.JsonSerializationOptions);
Assert.NotNull(preambleMarker.PrerenderId);
Assert.Equal("webassembly", preambleMarker.Type);
Assert.Equal(typeof(GenericComponent<string>).Assembly.GetName().Name, preambleMarker.Assembly);
Assert.Equal(typeof(GenericComponent<string>).FullName, preambleMarker.TypeName);

var prerenderedContent = match.Groups["content"].Value;
Assert.Equal("<p>Generic value: 456</p>", prerenderedContent);

var epilogue = match.Groups["epilogue"].Value;
var epilogueMarker = JsonSerializer.Deserialize<ComponentMarker>(epilogue, ServerComponentSerializationSettings.JsonSerializationOptions);
Assert.Equal(preambleMarker.PrerenderId, epilogueMarker.PrerenderId);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Type mismatch in assertions: GenericComponent<string> should be GenericComponent<int>.

The test renders GenericComponent<int> (line 825) but asserts against GenericComponent<string> (lines 837-838). This will cause the test to fail because typeof(GenericComponent<int>).FullName differs from typeof(GenericComponent<string>).FullName.

🐛 Proposed fix
         var preambleMarker = JsonSerializer.Deserialize<ComponentMarker>(preamble, ServerComponentSerializationSettings.JsonSerializationOptions);
         Assert.NotNull(preambleMarker.PrerenderId);
         Assert.Equal("webassembly", preambleMarker.Type);
-        Assert.Equal(typeof(GenericComponent<string>).Assembly.GetName().Name, preambleMarker.Assembly);
-        Assert.Equal(typeof(GenericComponent<string>).FullName, preambleMarker.TypeName);
+        Assert.Equal(typeof(GenericComponent<int>).Assembly.GetName().Name, preambleMarker.Assembly);
+        Assert.Equal(typeof(GenericComponent<int>).FullName, preambleMarker.TypeName);
🤖 Prompt for AI Agents
In `@src/Components/Endpoints/test/EndpointHtmlRendererTest.cs` around lines 816 -
846, The assertions in CanPrerender_ClosedGenericComponent_ClientMode are
checking the wrong generic type: change the expected assembly and type name
checks that reference GenericComponent<string> to instead reference
GenericComponent<int> so they match the rendered component (replace
typeof(GenericComponent<string>).Assembly.GetName().Name and
typeof(GenericComponent<string>).FullName with the corresponding
typeof(GenericComponent<int>) checks when asserting preambleMarker.Assembly and
preambleMarker.TypeName).

Comment on lines +127 to +145
[Fact]
public void CanParseMultipleMarkersForClosedGenericComponents()
{
// Arrange
var markers = SerializeMarkers(CreateMarkers(typeof(GenericTestComponent<int>), typeof(GenericTestComponent<string>)));
var serverComponentDeserializer = CreateServerComponentDeserializer();

// Act & assert
Assert.True(serverComponentDeserializer.TryDeserializeComponentDescriptorCollection(markers, out var descriptors));
Assert.Equal(2, descriptors.Count);

var firstDescriptor = descriptors[0];
Assert.Equal(typeof(GenericTestComponent<int>).FullName, firstDescriptor.ComponentType.FullName);
Assert.Equal(0, firstDescriptor.Sequence);

var secondDescriptor = descriptors[1];
Assert.Equal(typeof(GenericTestComponent<string>).FullName, secondDescriptor.ComponentType.FullName);
Assert.Equal(0, secondDescriptor.Sequence);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Incorrect sequence assertion for second descriptor.

Line 144 asserts Assert.Equal(0, secondDescriptor.Sequence), but when parsing multiple markers, each should have an incrementing sequence number. Comparing with CanParseMultipleMarkers (line 164), the second descriptor should have sequence 1.

🐛 Proposed fix
         var secondDescriptor = descriptors[1];
         Assert.Equal(typeof(GenericTestComponent<string>).FullName, secondDescriptor.ComponentType.FullName);
-        Assert.Equal(0, secondDescriptor.Sequence);
+        Assert.Equal(1, secondDescriptor.Sequence);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[Fact]
public void CanParseMultipleMarkersForClosedGenericComponents()
{
// Arrange
var markers = SerializeMarkers(CreateMarkers(typeof(GenericTestComponent<int>), typeof(GenericTestComponent<string>)));
var serverComponentDeserializer = CreateServerComponentDeserializer();
// Act & assert
Assert.True(serverComponentDeserializer.TryDeserializeComponentDescriptorCollection(markers, out var descriptors));
Assert.Equal(2, descriptors.Count);
var firstDescriptor = descriptors[0];
Assert.Equal(typeof(GenericTestComponent<int>).FullName, firstDescriptor.ComponentType.FullName);
Assert.Equal(0, firstDescriptor.Sequence);
var secondDescriptor = descriptors[1];
Assert.Equal(typeof(GenericTestComponent<string>).FullName, secondDescriptor.ComponentType.FullName);
Assert.Equal(0, secondDescriptor.Sequence);
}
[Fact]
public void CanParseMultipleMarkersForClosedGenericComponents()
{
// Arrange
var markers = SerializeMarkers(CreateMarkers(typeof(GenericTestComponent<int>), typeof(GenericTestComponent<string>)));
var serverComponentDeserializer = CreateServerComponentDeserializer();
// Act & assert
Assert.True(serverComponentDeserializer.TryDeserializeComponentDescriptorCollection(markers, out var descriptors));
Assert.Equal(2, descriptors.Count);
var firstDescriptor = descriptors[0];
Assert.Equal(typeof(GenericTestComponent<int>).FullName, firstDescriptor.ComponentType.FullName);
Assert.Equal(0, firstDescriptor.Sequence);
var secondDescriptor = descriptors[1];
Assert.Equal(typeof(GenericTestComponent<string>).FullName, secondDescriptor.ComponentType.FullName);
Assert.Equal(1, secondDescriptor.Sequence);
}
🤖 Prompt for AI Agents
In `@src/Components/Server/test/Circuits/ServerComponentDeserializerTest.cs`
around lines 127 - 145, The test
CanParseMultipleMarkersForClosedGenericComponents has an incorrect assertion for
the second descriptor's sequence: change the assertion on
secondDescriptor.Sequence to expect 1 instead of 0 so it matches the
incrementing-sequence behavior (see CanParseMultipleMarkers and the descriptors
list created by
ServerComponentDeserializer.TryDeserializeComponentDescriptorCollection).

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.

3 participants