Skip to content

C#: Re-factor DependabotProxy class to allow unit-testing. - #22477

Open
michaelnebel wants to merge 4 commits into
github:mainfrom
michaelnebel:csharp/refactordependabotproxy
Open

C#: Re-factor DependabotProxy class to allow unit-testing.#22477
michaelnebel wants to merge 4 commits into
github:mainfrom
michaelnebel:csharp/refactordependabotproxy

Conversation

@michaelnebel

@michaelnebel michaelnebel commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

In this PR we re-factor the DependabotProxy class to enable unit-testing (and also add some tests).
This is in preparation for adding support for replaces-base (the RegistryUrl JSON object will become more "complex").

DCA looks good.

@github-actions github-actions Bot added the C# label Sep 1, 2026
@michaelnebel
michaelnebel force-pushed the csharp/refactordependabotproxy branch from 83746ff to 131e450 Compare September 1, 2026 13:11
@michaelnebel
michaelnebel force-pushed the csharp/refactordependabotproxy branch from 131e450 to d870a57 Compare September 1, 2026 13:16
@michaelnebel
michaelnebel requested a balanced review from Copilot September 2, 2026 06:16
@michaelnebel michaelnebel added the no-change-note-required This PR does not need a change note label Sep 2, 2026

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.

Copilot review overview

🟢 Approval recommended

The refactor preserves platform and runtime behavior while adding appropriate coverage for the extracted logic.

Review tier: Balanced
Findings: None

What changed in this PR

Refactors Dependabot proxy configuration behind an injectable interface, enabling focused unit testing while preserving production behavior.

Changes:

  • Adds environment-backed proxy configuration.
  • Separates platform gating from testable proxy creation.
  • Tests credentials, certificates, and registry URL parsing.
File Description
csharp/​extractor/​Semmle.Extraction.Tests/​DependabotProxy.cs Adds proxy unit tests and stubs.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​IDependabotProxyConfiguration.cs Defines injectable configuration.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​DependencyManager.cs Uses the refactored factory.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​DependabotProxyConfiguration.cs Reads configuration from environment variables.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​DependabotProxy.cs Extracts configuration and creation logic for testing.

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

@michaelnebel
michaelnebel requested a review from hvitved September 2, 2026 06:20
@michaelnebel
michaelnebel marked this pull request as ready for review September 2, 2026 06:20
@michaelnebel
michaelnebel requested a review from a team as a code owner September 2, 2026 06:20

@mbg mbg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a very useful change, thank you for continuing to work on and improve this!

I had a few minor comments while I was looking over this (out of curiosity). From a functional perspective, this LGTM otherwise.

return MakeAux(new DependabotProxyConfiguration(), logger, diagnosticsWriter, tempWorkingDirectory);
}

internal static IDependabotProxy? MakeAux(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: It might be good to give this a more descriptive name or a doc comment explaining why it is separated out of Make.

{
if (string.IsNullOrWhiteSpace(proxyConfig.Host) || string.IsNullOrWhiteSpace(proxyConfig.Port))
{
logger.LogInfo("No Dependabot proxy credentials are configured.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: I probably chose this in the original implementation, but this could probably be changed to a Debug-level message, since we log at Info-level when the proxy is configured, so the absence of that message would imply this one under normal circumstances.

}

var result = new DependabotProxy(proxyConfig, logger, tempWorkingDirectory);
logger.LogInfo($"Dependabot proxy configured at {result.Address}");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: Again probably something I was responsible for in the original implementation, but here and elsewhere, it might make sense to change the wording of the log messages to not mention "Dependabot". While that's technically accurate, it is probably confusing for users to see in the log. E.g. "Authentication proxy" or "Registry proxy" might be better.

var config = new DependabotConfigurationStub
{
Port = "8080",
Host = "my.private.server",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: As things stand, Host would always be localhost if set. It would not currently ever point to some other address. In theory, it is possible for a user to set the env var manually before invoking CodeQL, but that's not really a use case we support since authentication to private registries can be handled more easily in advanced workflows or direct CLI usage. So for positive tests, it might make sense to use localhost as the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants