Skip to content

Commit bb3f485

Browse files
ElanHassonclaude
andauthored
fix: Implement transitive dependency resolution for NuGet packages (#13)
* fix: Implement transitive dependency resolution for NuGet packages - Enhanced NuGetPackageResolver to recursively resolve transitive dependencies - Added session-based concurrent caching to prevent duplicate resolution - Improved dependency filtering to handle Microsoft.Extensions packages properly - Fixed ExamplesTests path resolution to work in Docker containers - Updated AutoMapper test to include required logging services - Added Docker examples directory copy for container testing Resolves transitive dependency issues where packages like AutoMapper 15.0.1 would fail due to missing dependencies like Microsoft.Extensions.DependencyInjection. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * refactor: Address Claude review feedback for NuGetPackageResolver - Add recursion depth limit (MaxRecursionDepth = 10) to prevent infinite loops - Extract framework version constant (TargetFramework = "net9.0") - Replace Console.WriteLine with proper logger.LogWarning calls - Improve method signatures to pass depth parameter through recursive calls - Add depth checking at start of ResolveTransitiveDependenciesAsync Addresses critical issues identified in automated code review: - Prevents potential stack overflow from circular dependencies - Improves maintainability with extracted constants - Uses proper logging infrastructure instead of direct console output - Maintains existing error handling behavior while improving visibility All 25 tests continue to pass with these robustness improvements. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * test: Add comprehensive test coverage for NuGet resolver improvements Added 5 new tests covering critical functionality: 1. **EvalCSharp_WithDeeplyNestedDependencies_HandlesRecursionDepthLimit**: - Tests that recursion depth handling works correctly - Verifies no "Maximum recursion depth" warnings appear in normal operation 2. **EvalCSharp_WithFrameworkConstants_UsesCorrectTargetFramework**: - Validates extracted TargetFramework constant is used correctly - Tests compatibility with net9.0 packages 3. **EvalCSharp_WithInvalidPackageReference_ShowsProperError**: - Tests improved error handling for non-existent packages - Validates clear error messages without silent failures 4. **EvalCSharp_WithMalformedNuGetDirective_ShowsValidationError**: - Tests directive validation improvements - Ensures malformed syntax shows helpful error messages 5. **EvalCSharp_WithMicrosoftExtensionsPackage_HandlesFilteringCorrectly**: - Tests dependency filtering allows Microsoft.Extensions packages - Validates transitive dependency resolution for common scenarios Updated existing **EvalCSharp_WithNuGetPackageWithTransitiveDependencies_ResolvesAllDependencies**: - Simplified to use stable Newtonsoft.Json package - Maintains transitive dependency validation without version conflicts Total test count: 30 tests (was 25) All tests pass, providing comprehensive coverage for recursion limits, error handling, framework constants, and dependency filtering improvements. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * refactor: Address additional review feedback for robustness **Constants Extraction:** - Extract MicrosoftExtensionsStableVersion = "8.0.0" constant - Replace remaining hardcoded framework version strings with TargetFramework constant - Improve code maintainability with centralized version management **Network Timeout Configuration:** - Add NetworkOperationTimeout = 30 seconds constant - Implement timeout handling for all network operations using CancellationTokenSource - Add specific timeout error messages to distinguish from other failures - Prevent hanging on network operations in production environments **Resource Management Validation:** - Confirmed all MemoryStream instances already use proper 'using' statements - No resource leak risks identified in current implementation **Error Handling Enhancement:** - Add specific timeout exception handling with clear error messages - Maintain existing error handling behavior while improving visibility - Network timeouts now provide actionable feedback to users All 30 tests continue to pass with these robustness improvements. Addresses medium priority concerns from automated code review. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * feat: Add network timeout test and code analysis improvements - Add comprehensive network timeout test using cancellation token - Implement GeneratedRegex for improved performance - Add Microsoft.CodeAnalysis.Analyzers to both projects - Fix test assertions to handle NuGet error message variations - Ensure complete branch coverage for timeout scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix: Improve error handling and eliminate duplicate package downloads - Replace silent error handling with proper error classification - Add IsExpectedDependencyFailure() to distinguish built-in vs real failures - Implement dependency caching to avoid re-downloading packages - Read assemblies and dependencies in single download operation - Add comprehensive logging for unresolved dependencies - Maintain performance while improving observability Addresses review feedback on silent error swallowing and duplicate work. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 4174a74 commit bb3f485

File tree

10 files changed

+622
-276
lines changed

10 files changed

+622
-276
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"cSpell.words": [
3-
"infinityflow"
3+
"infinityflow",
4+
"netstandard",
5+
"Newtonsoft"
46
]
57
}

Directory.Packages.props

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
<Project>
2-
<PropertyGroup>
3-
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
</PropertyGroup>
5-
<ItemGroup>
6-
<!-- MCP and Core Dependencies -->
7-
<PackageVersion Include="ModelContextProtocol" Version="0.3.0-preview.2" />
8-
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.0-preview.7.25380.108" />
9-
10-
<!-- Roslyn Scripting -->
11-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.14.0" />
12-
13-
<!-- NuGet Client Libraries -->
14-
<PackageVersion Include="NuGet.Protocol" Version="6.12.1" />
15-
<PackageVersion Include="NuGet.Resolver" Version="6.12.1" />
16-
17-
<!-- Testing -->
18-
<PackageVersion Include="NUnit" Version="4.4.0" />
19-
<PackageVersion Include="NUnit.Analyzers" Version="4.10.0" />
20-
<PackageVersion Include="NUnit3TestAdapter" Version="5.1.0" />
21-
<PackageVersion Include="FluentAssertions" Version="8.6.0" />
22-
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
23-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
24-
</ItemGroup>
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<!-- MCP and Core Dependencies -->
7+
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0">
8+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9+
<PrivateAssets>all</PrivateAssets>
10+
</PackageVersion>
11+
<PackageVersion Include="ModelContextProtocol" Version="0.3.0-preview.2" />
12+
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.0-preview.7.25380.108" />
13+
<!-- Roslyn Scripting -->
14+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.14.0" />
15+
<!-- NuGet Client Libraries -->
16+
<PackageVersion Include="NuGet.Protocol" Version="6.12.1" />
17+
<PackageVersion Include="NuGet.Resolver" Version="6.12.1" />
18+
<!-- Testing -->
19+
<PackageVersion Include="NUnit" Version="4.4.0" />
20+
<PackageVersion Include="NUnit.Analyzers" Version="4.10.0" />
21+
<PackageVersion Include="NUnit3TestAdapter" Version="5.1.0" />
22+
<PackageVersion Include="FluentAssertions" Version="8.6.0" />
23+
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
24+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
25+
</ItemGroup>
2526
</Project>

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
33
WORKDIR /source
44

55
# Copy solution and project files
6-
COPY csharp-mcp.sln .
6+
COPY csharp-mcp.slnx .
77
COPY Directory.Packages.props .
88
COPY src/InfinityFlow.CSharp.Eval/*.csproj ./src/InfinityFlow.CSharp.Eval/
99
COPY tests/InfinityFlow.CSharp.Eval.Tests/*.csproj ./tests/InfinityFlow.CSharp.Eval.Tests/
@@ -14,7 +14,7 @@ RUN dotnet restore
1414
# Copy source code
1515
COPY src/ ./src/
1616
COPY tests/ ./tests/
17-
17+
COPY examples/ ./examples
1818
# Build and test
1919
RUN dotnet build -c Release --no-restore
2020
RUN dotnet test -c Release --no-build --verbosity normal
@@ -51,4 +51,4 @@ ENV NUGET_PACKAGES=/tmp/csharp-mcp-packages
5151
ENV DOTNET_RUNNING_IN_CONTAINER=true
5252

5353
# The MCP server uses stdio for communication
54-
ENTRYPOINT ["dotnet", "/app/InfinityFlow.CSharp.Eval.dll"]
54+
ENTRYPOINT ["dotnet", "/app/InfinityFlow.CSharp.Eval.dll"]

csharp-mcp.sln

Lines changed: 0 additions & 59 deletions
This file was deleted.

csharp-mcp.slnx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Solution>
2+
<Folder Name="/src/">
3+
<Project Path="src/InfinityFlow.CSharp.Eval/InfinityFlow.CSharp.Eval.csproj" />
4+
</Folder>
5+
<Folder Name="/tests/">
6+
<Project Path="tests/InfinityFlow.CSharp.Eval.Tests/InfinityFlow.CSharp.Eval.Tests.csproj" />
7+
</Folder>
8+
</Solution>

src/InfinityFlow.CSharp.Eval/InfinityFlow.CSharp.Eval.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
</ItemGroup>
3232

3333
<ItemGroup>
34+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers">
35+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
36+
<PrivateAssets>all</PrivateAssets>
37+
</PackageReference>
3438
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" />
3539
<PackageReference Include="Microsoft.Extensions.Hosting" />
3640
<PackageReference Include="ModelContextProtocol" />

0 commit comments

Comments
 (0)