Skip to content

C#: Re-factor FeedManager to allow better unit testing. - #22468

Merged
michaelnebel merged 8 commits into
github:mainfrom
michaelnebel:csharp/refactorfeedmanager
Sep 1, 2026
Merged

C#: Re-factor FeedManager to allow better unit testing.#22468
michaelnebel merged 8 commits into
github:mainfrom
michaelnebel:csharp/refactorfeedmanager

Conversation

@michaelnebel

@michaelnebelmichaelnebel commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

In this PR we

  • Re-factor the FeedManager to enable unit testing.
  • Add some unit tests.

This is in preparation for using feeds configured via the dependabot proxy as "base" feed(s) (instead of the current hardcoded public nuget.org feed).

DCA looks good.

@michaelnebel
michaelnebelforce-pushed the csharp/refactorfeedmanager branch from 08d2f0e to b31ae61CompareAugust 31, 2026 11:24
@michaelnebel
michaelnebelforce-pushed the csharp/refactorfeedmanager branch from 98f0019 to 446e52eCompareAugust 31, 2026 13:21
@michaelnebel
michaelnebelforce-pushed the csharp/refactorfeedmanager branch from 446e52e to b76f793CompareAugust 31, 2026 13:23
@michaelnebelmichaelnebel added the no-change-note-required This PR does not need a change note label Aug 31, 2026
@michaelnebel
michaelnebel marked this pull request as ready for review September 1, 2026 06:52
@michaelnebel
michaelnebel requested a review from a team as a code ownerSeptember 1, 2026 06:52
CopilotAI balanced review requested due to automatic review settings September 1, 2026 06:52

CopilotAI 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.

Copilot review overview

🟡 Changes recommended

The new tests compare unordered sets using order-sensitive assertions, making them unreliable.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity

New issues introduced by this change (1)
SeverityFinding
Medium severitycsharp/​extractor/​Semmle.Extraction.Tests/​FeedManager.csExplicitFeeds is a set, but Assert.Equal compares these enumerables in iteration order.…
What changed in this PR

Refactors C# dependency-feed handling behind injectable interfaces and adds FeedManager unit tests.

Changes:

  • Introduces abstractions for file, proxy, and feed I/O dependencies.
  • Separates raw feed selection from CLI argument construction.
  • Adds FeedManager and restore-source tests.
FileDescription
csharp/​extractor/​Semmle.Extraction.Tests/​Runtime.csUses the shared DotNetStub.
csharp/​extractor/​Semmle.Extraction.Tests/​FeedManager.csAdds FeedManager unit tests and stubs.
csharp/​extractor/​Semmle.Extraction.Tests/​DotNetStub.csAdds reusable .NET CLI stub behavior.
csharp/​extractor/​Semmle.Extraction.Tests/​DotNet.csTests source argument generation.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​SourceGenerators/​ResxGenerator.csAccepts the file-provider interface.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​SourceGenerators/​RazorGenerator.csAccepts the file-provider interface.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​SourceGenerators/​DotnetSourceGeneratorBase.csStores the file-provider abstraction.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​PackagesConfigRestorer.csConverts selected feeds into NuGet arguments.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​NugetPackageRestorer.csUses abstract dependencies and raw feeds.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​IFileProvider.csDefines file-discovery operations.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​IFeedManagerIO.csDefines feed-related I/O operations.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​IDependabotProxy.csDefines proxy configuration access.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​FileProvider.csImplements IFileProvider.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​FeedManagerIO.csExtracts filesystem and reachability logic.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​FeedManager.csSupports injected dependencies and raw feed selection.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​DotNetCliInvoker.csUses the proxy interface.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​DotNet.csBuilds source flags from raw feed URLs.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​DependencyManager.csStores abstract dependency types.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​DependabotProxy.csImplements IDependabotProxy.
Suppressed comments (6)

csharp/extractor/Semmle.Extraction.Tests/FeedManager.cs:96

  • InheritedFeeds is a set, but Assert.Equal makes this assertion depend on its unspecified iteration order. Compare the members without imposing sequence order.
 Assert.Equal([

csharp/extractor/Semmle.Extraction.Tests/FeedManager.cs:112

  • AllFeeds is an ImmutableHashSet, so its iteration order is not part of the contract. This sequence comparison can fail for a correct set; use strict unordered equivalence.
 Assert.Equal([

csharp/extractor/Semmle.Extraction.Tests/FeedManager.cs:131

  • ReachableFeeds is set-valued, but Assert.Equal compares enumeration order. The hash-set order can vary independently of behavior, making this assertion flaky; compare unordered members.
 Assert.Equal([

csharp/extractor/Semmle.Extraction.Tests/FeedManager.cs:148

  • ReachableExplicitFeeds is an ImmutableHashSet; asserting sequence equality relies on an order the property does not guarantee. Use strict unordered equivalence.
 Assert.Equal([

csharp/extractor/Semmle.Extraction.Tests/FeedManager.cs:164

  • ReachableFallbackFeeds is set-valued, so this sequence assertion can fail solely because hash iteration order differs. Compare the set contents without ordering them.
 Assert.Equal([

csharp/extractor/Semmle.Extraction.Tests/FeedManager.cs:181

  • feedsToUse is explicitly converted to a HashSet, then compared as an ordered enumerable. Its iteration order is unspecified, so this can reject the correct members; use strict unordered equivalence.
 Assert.Equal([

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

Comment on lines +79 to +83
Assert.Equal([
"https://example.com/registry1",
"https://example.com/registry2",
"https://feed.from/config"
], actualFeeds);

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

According to the documentation seen hereAssert.Equals uses SetEquals under the hood for hash-sets - so I believe that the current implementation is correct.

@hvitvedhvitved 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.

Nice!

@michaelnebelmichaelnebel changed the title C#: Re-factor to allow better unit testing.C#: Re-factor FeedManager to allow better unit testing.Sep 1, 2026
@michaelnebel
michaelnebel merged commit c550c51 into github:mainSep 1, 2026
16 checks passed
@michaelnebel
michaelnebel requested a balanced review from CopilotSeptember 2, 2026 06:07
@michaelnebel
michaelnebel removed the request for review from CopilotSeptember 2, 2026 06:08
@michaelnebel
michaelnebel deleted the csharp/refactorfeedmanager branch September 2, 2026 06:14
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C#no-change-note-requiredThis PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@michaelnebel@hvitved@github-advanced-security