Skip to content

Fix: assert detailStart ≥ 0 before using it in range expression - #143

Merged
japperJ merged 2 commits into
masterfrom
copilot/fix-code-for-review-comment
Aug 17, 2026
Merged

japperJ merged 2 commits into
masterfrom
copilot/fix-code-for-review-comment

Conversation

Copilot AI commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

detailStart was validated only after source[detailStart..] was evaluated, so a missing marker string would throw ArgumentOutOfRangeException instead of producing a meaningful FluentAssertions failure message.

Why

String.IndexOf returns -1 when the marker is absent. Passing -1 to a range indexer throws before FluentAssertions can report what went wrong.

What changed

  • Moved detailStart.Should().BeGreaterThanOrEqualTo(0) to immediately after IndexOf, before the source[detailStart..] slice that depends on it.

Notes

  • No production code changed; test-only fix.

Testing

  • dotnet test tests/WinContainers.Tests.Unit/WinContainers.Tests.Unit.csproj -c Debug --nologo -v q --filter "FullyQualifiedName~RuntimeContractTests|FullyQualifiedName~ContainerAgentTests"
  • dotnet test tests/WinContainers.Tests.Integration/WinContainers.Tests.Integration.csproj -c Debug --nologo -v q --filter "FullyQualifiedName~ServiceHost_ShouldExposeMcpToolsForAuthorizedRequests"
  • dotnet build WinContainers.slnx -c Debug --nologo -v q

Co-authored-by: japperJ <121674230+japperJ@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code based on review comment feedback Fix: assert detailStart ≥ 0 before using it in range expression Aug 17, 2026
Copilot AI requested a review from japperJ August 17, 2026 12:52
@japperJ
japperJ marked this pull request as ready for review August 17, 2026 12:56
Copilot AI lite review requested due to automatic review settings August 17, 2026 12:56
@japperJ
japperJ merged commit 42370da into master Aug 17, 2026
1 check passed

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.

Pull request overview

This PR adjusts a unit test in RuntimeContractTests to assert detailStart >= 0 immediately after IndexOf and before using detailStart in a range slice, preventing an ArgumentOutOfRangeException and ensuring FluentAssertions produces a clear failure when the marker is missing.

Changes:

  • Moved detailStart.Should().BeGreaterThanOrEqualTo(0) to occur before source[detailStart..] is evaluated.
  • Preserved existing behavior for validating detailEnd and checking the extracted section contents.

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

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