Skip to content

refactor: multiple improvements#58

Merged
HandyS11 merged 1 commit intodevelopfrom
chore/edgecase-improvement
Mar 12, 2026
Merged

refactor: multiple improvements#58
HandyS11 merged 1 commit intodevelopfrom
chore/edgecase-improvement

Conversation

@HandyS11
Copy link
Owner

This pull request introduces several improvements and fixes across the codebase, including a major refactor of the Tarjan's algorithm implementation to make it iterative, enhancements to dependency depth statistics handling, improved error handling for .slnx parsing, and better deterministic type discovery. Additionally, it updates dependency injection lifetimes for renderers and improves string parsing in Entity Framework utilities. Below are the most important changes grouped by theme:

Algorithms and Statistics

  • Refactored Tarjan's strongly connected components algorithm in TarjanSccAlgorithm.cs to use an explicit stack for iterative traversal, replacing recursion. This prevents StackOverflowException on deep dependency chains and improves reliability for large graphs. [1] [2]
  • Changed DependencyDepthStats to use nullable values (double?, int?) when cycles are detected, rather than sentinel values (-1), and updated logic in ComputeStatsUseCase.cs to support this. [1] [2]

Console Output and Infrastructure

  • Removed the Write(IRenderable) method from IOutputConsole and its implementations, and replaced usages with the static SpectreOutputConsole.Write(IRenderable) method for rendering Spectre.Console objects. [1] [2] [3] [4] [5]
  • Improved the NullOutputConsole to throw an exception if no choices are available when prompting for selection, making error handling more robust.

Parsing and Error Handling

  • Added error handling to SlnxParser so that malformed XML in .slnx files throws a ParsingException, improving reliability and debugging. [1] [2]

Dependency Injection and Service Lifetimes

  • Changed registration of diagram renderers in DependencyInjection.cs from transient to singleton, clarifying that all renderers are stateless and improving resource usage.

Workspace and Entity Framework Utilities

  • Updated type discovery in WorkspaceTypeDiscovery.cs to collect all matching files and return the deterministically sorted first match, ensuring consistent results when multiple files define the same type. [1] [2] [3]
  • Enhanced FluentApiParsingUtilities to strip string literals before counting parentheses, preventing errors in block detection logic for Entity Framework Fluent API parsing. [1] [2]

Other notable changes include setting consistent JSON serialization options in ProjGraphTools.cs for camelCase property naming. [1] [2]

Copilot AI review requested due to automatic review settings March 12, 2026 10:08
Copy link
Contributor

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 refactors and hardens several core behaviors across ProjGraph: SCC (Tarjan) detection is made iterative to avoid stack overflows, dependency depth stats are updated to use nulls when cycles exist, parsing/error handling is improved (notably for .slnx), and multiple utilities are adjusted for determinism and robustness.

Changes:

  • Refactor Tarjan SCC algorithm to an iterative implementation and add deep-graph tests.
  • Update dependency depth stats to use nullable values when cycles are present, and extend stats-related tests.
  • Improve parsing/utilities (e.g., .slnx malformed XML errors, deterministic type discovery, EF fluent parsing, MCP JSON options) and adjust console rendering approach.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/ProjGraph.Tests.Unit.ProjectGraph/ComputeStatsUseCaseTests.cs Updates cycle-depth expectations to nulls and adds edge-case coverage (self-ref, deep chain, Unicode).
tests/ProjGraph.Tests.Unit.ProjectGraph/BuildGraphUseCaseTests.cs Adds coverage for self-referencing project dependencies.
tests/ProjGraph.Tests.Unit.EntityFramework/FluentApiParsingUtilitiesTests.cs Adds cases ensuring parentheses inside string literals don’t break UsingEntity block detection.
tests/ProjGraph.Tests.Unit.EntityFramework/EfAnalysisAdvancedTests.cs Adds advanced EF analysis coverage (keyless entities, converters, owned types, TPT).
tests/ProjGraph.Tests.Unit.Core/Parsers/SlnxParserTests.cs Expects ParsingException for malformed XML and adds BOM handling test.
tests/ProjGraph.Tests.Unit.Core/Parsers/ProjectParserTests.cs Adds parsing coverage for BOM files, conditional item groups, and version range syntax.
tests/ProjGraph.Tests.Unit.Core/NullOutputConsoleTests.cs Adds test ensuring empty selection choices throw a clear exception.
tests/ProjGraph.Tests.Unit.Core/Algorithms/TarjanSccAlgorithmTests.cs Adds deep-chain test to guard against StackOverflow regressions.
tests/ProjGraph.Tests.Unit.ClassDiagram/TypeAnalyzerTests.cs Adds broader Roslyn type-analysis cases (nested, generics/constraints, static, defaults, etc.).
src/ProjGraph.Mcp/ProjGraphTools.cs Uses explicit JsonSerializerOptions (camelCase) when serializing stats.
src/ProjGraph.Lib.ProjectGraph/DependencyInjection.cs Changes renderer DI lifetimes from transient to singleton.
src/ProjGraph.Lib.ProjectGraph/Application/UseCases/ComputeStatsUseCase.cs Switches cycle depth stats sentinel values to nulls when cycles are detected.
src/ProjGraph.Lib.EntityFramework/Infrastructure/FluentApiParsingUtilities.cs Strips string literals before counting parentheses for UsingEntity detection.
src/ProjGraph.Lib.Core/Parsers/SlnxParser.cs Wraps malformed .slnx XML errors into ParsingException.
src/ProjGraph.Lib.Core/Infrastructure/SpectreOutputConsole.cs Introduces static Write(IRenderable) helper for Spectre renderables.
src/ProjGraph.Lib.Core/Abstractions/NullOutputConsole.cs Removes renderable write and throws on empty selection prompts.
src/ProjGraph.Lib.Core/Abstractions/IOutputConsole.cs Removes Write(IRenderable) from the abstraction.
src/ProjGraph.Lib.ClassDiagram/Infrastructure/WorkspaceTypeDiscovery.cs Collects all matches and deterministically selects a sorted first match.
src/ProjGraph.Core/Models/SolutionStats.cs Makes dependency depth stats nullable and updates related documentation.
src/ProjGraph.Cli/Commands/StatsCommand.cs Switches renderable output to SpectreOutputConsole.Write(...).

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

You can also share your feedback on Copilot code review. Take the survey.

@HandyS11 HandyS11 merged commit b12d6e2 into develop Mar 12, 2026
7 checks passed
@HandyS11 HandyS11 deleted the chore/edgecase-improvement branch March 12, 2026 10:22
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