Skip to content

chore(quality): clear Sonar code smells and raise coverage to ~95.8% - #169

Merged
HandyS11 merged 2 commits into
developfrom
chore/sonar-quality-pass-coverage
Jul 20, 2026
Merged

chore(quality): clear Sonar code smells and raise coverage to ~95.8%#169
HandyS11 merged 2 commits into
developfrom
chore/sonar-quality-pass-coverage

Conversation

@HandyS11

Copy link
Copy Markdown
Owner

Summary

Resolves the 4 open SonarQube code smells and lifts coverage from 89.8% → ~95.8% (line 91.8% → 97.4%, branch 84.1% → 91.6%; measured locally via opencover with the CI's sonar.coverage.exclusions).

Code smells (all in Lib.EntityFramework)

Rule File Fix
S1192 SqlColumnTypeMapper.cs repeated "decimal" literal → Decimal const
S3776 FluentSyntax.cs ResolveOwningEntity (cognitive complexity 22) split into ResolveFromReceiverChain / ResolveFromAncestors / ComposeOwnedKey
S107 FluentOwnedTypeWalker.cs GetOrCreateOwned 8 params → 5 via OwnedTarget record
S107 EfModelAnalyzer.cs ResolveOwnedNavigationTypesAsync 8 params → 3 via OwnedTypeResolutionContext record

All refactors are behavior-preserving; the S3776 split keeps each return in the receiver-chain loop terminal (including the UsingEntitynull case) by signalling "the chain settled it" rather than falling through to the ancestor search.

Bug fix (surfaced by new coverage)

FluentOwnedTypeWalker.ResolveOwnedType seeded zero columns for an OwnsMany over a T[] array navigation — its is not INamedTypeSymbol guard rejected IArrayTypeSymbol, even though the file-discovery path (OwnedClrTypeName) already unwraps T[] and documents it as supported. The seeding path now unwraps the array element type up front so both paths agree. Covered by a new test.

Coverage

15 new *CoverageTests.cs files (~207 tests) across CLI, MCP, Core, ClassDiagram and EntityFramework, targeting the worst-covered error/fallback paths (ErdCommand 60%, CollectingOutputConsole 44%, DiagramResourceCache 62%, CompilationFactory 69%, the EF fluent walkers, …).

Verification

  • 1118 tests passing; build clean under TreatWarningsAsErrors + EnforceCodeStyleInBuild.
  • The real Sonar quality-gate number re-evaluates on the develop push after merge (the sonarqube.yml workflow only triggers on push to develop, not on PRs).

Note (pre-existing, out of scope)

McpTransportTests.ListTools_OverRealStdioTransport_ExposesAllFourTools is flaky under full-suite parallel load (65s init timeout) but passes standalone in ~5s. Not touched here; worth a separate stabilization fix.

🤖 Generated with Claude Code

Resolve the 4 open SonarQube code smells and lift coverage from 89.8% to
~95.8% (line 91.8%->97.4%, branch 84.1%->91.6%).

Smell fixes (all in Lib.EntityFramework):
- S1192: extract repeated "decimal" literal to a const (SqlColumnTypeMapper)
- S3776: split FluentSyntax.ResolveOwningEntity (cognitive complexity 22)
  into ResolveFromReceiverChain / ResolveFromAncestors / ComposeOwnedKey
- S107: fold GetOrCreateOwned's 8 params into an OwnedTarget record
  (FluentOwnedTypeWalker)
- S107: fold ResolveOwnedNavigationTypesAsync's 8 params into an
  OwnedTypeResolutionContext record (EfModelAnalyzer)

Bug fix (surfaced by new coverage): FluentOwnedTypeWalker.ResolveOwnedType
seeded zero columns for an OwnsMany over a T[] array navigation -- its
`is not INamedTypeSymbol` guard rejected IArrayTypeSymbol, though the
file-discovery path (OwnedClrTypeName) already unwraps T[]. Now unwraps the
array element type up front so both paths agree.

Coverage: 15 new *CoverageTests.cs files (~207 tests) across CLI, MCP, Core,
ClassDiagram and EntityFramework, targeting the worst-covered error/fallback
paths (ErdCommand, CollectingOutputConsole, DiagramResourceCache,
CompilationFactory, the EF fluent walkers, ...).

1118 tests passing; build clean under TreatWarningsAsErrors and
EnforceCodeStyleInBuild.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 20, 2026 15:47

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 focuses on improving code quality and resilience across ProjGraph (notably EF Fluent API analysis and MCP/CLI robustness) by clearing SonarQube smells, fixing an owned-type array edge case, and substantially expanding automated coverage for error/fallback paths.

Changes:

  • Refactors EF Fluent API ownership resolution and owned-type handling to reduce complexity/parameter counts and fix OwnsMany over array navigations.
  • Adds broad “coverage tests” suites across EF, Core, ClassDiagram, CLI, and MCP to exercise guard rails and degraded/fallback behavior.
  • Adds renderer and discovery edge-case coverage to ensure diagrams remain valid under unexpected model states.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/ProjGraph.Tests.Unit.EntityFramework/FluentWalkerCoverageTests.cs New unit coverage for EF Fluent API walkers’ guard/fallback paths.
tests/ProjGraph.Tests.Unit.EntityFramework/FluentSyntaxCoverageTests.cs New unit coverage for FluentSyntax receiver-chain/ancestor resolution and name extraction.
tests/ProjGraph.Tests.Unit.EntityFramework/EfRenderingCoverageTests.cs New unit coverage for Mermaid ERD renderer defensive fallbacks.
tests/ProjGraph.Tests.Unit.EntityFramework/EfDiscoveryCoverageTests.cs New unit coverage for EF file discovery boundaries and array-owned navigation discovery.
tests/ProjGraph.Tests.Unit.EntityFramework/EfAnalyzerCoverageTests.cs New unit coverage for EF Roslyn analyzers on unusual attribute/type shapes.
tests/ProjGraph.Tests.Unit.Core/ProjectParserCoverageTests.cs New unit coverage for malformed MSBuild inputs and property/version fallback logic.
tests/ProjGraph.Tests.Unit.Core/OutputConsoleCoverageTests.cs New unit coverage for SpectreOutputConsole stdout/stderr routing and markup escaping.
tests/ProjGraph.Tests.Unit.Core/CompilationFactoryCoverageTests.cs New unit coverage for compilation options, references, and cross-tree binding behavior.
tests/ProjGraph.Tests.Unit.ClassDiagram/ClassDiagramCoverageTests.cs New unit coverage for class-diagram discovery/resolution fallbacks and renderer defaults.
tests/ProjGraph.Tests.Integration.Mcp/WorkspaceRootServiceTests.cs New integration coverage for MCP workspace roots negotiation, caching, and invalidation.
tests/ProjGraph.Tests.Integration.Mcp/Helpers/InProcessMcpSession.cs Adds in-memory client/server harness for MCP integration testing.
tests/ProjGraph.Tests.Integration.Mcp/DiagramResourceCacheTests.cs New integration coverage for publishing/eviction/update notifications of cached MCP resources.
tests/ProjGraph.Tests.Integration.Mcp/CollectingOutputConsoleTests.cs New coverage for MCP stdout-safe console warning buffering and async-flow isolation.
tests/ProjGraph.Tests.Integration.Cli/ErdCommandCoverageTests.cs New CLI integration coverage for ERD discovery/prompting/non-interactive behavior and snapshot branch.
tests/ProjGraph.Tests.Integration.Cli/CommandOptionsCoverageTests.cs New CLI integration coverage for validation/error reporting branches and DI adapter behavior.
src/ProjGraph.Lib.EntityFramework/Infrastructure/SqlColumnTypeMapper.cs Removes repeated "decimal" literal via shared constant for Sonar smell cleanup.
src/ProjGraph.Lib.EntityFramework/Infrastructure/FluentSyntax.cs Refactors ownership resolution to reduce cognitive complexity (receiver-chain vs ancestor search).
src/ProjGraph.Lib.EntityFramework/Infrastructure/FluentOwnedTypeWalker.cs Refactors owned creation parameters and fixes OwnsMany array element-type seeding.
src/ProjGraph.Lib.EntityFramework/Infrastructure/EfModelAnalyzer.cs Refactors owned-navigation resolution state into a context record to reduce parameter count.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…fy CI

The CI's `dotnet format --verify-no-changes` whitespace check is stricter than
the local `EnforceCodeStyleInBuild` build and flagged two multi-property object
initializers in FluentWalkerCoverageTests. Reformat one property per line.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@HandyS11
HandyS11 merged commit 0f1f3a3 into develop Jul 20, 2026
6 checks passed
@HandyS11
HandyS11 deleted the chore/sonar-quality-pass-coverage branch July 20, 2026 16:02
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.

2 participants