Skip to content

Add stage commandline command - #7712

Merged
Nigusu-Allehu merged 9 commits into
devfrom
dev-nyenework-nuget-stage-cli
Sep 20, 2026
Merged

Nigusu-Allehu merged 9 commits into
devfrom
dev-nyenework-nuget-stage-cli

Conversation

@Nigusu-Allehu

@Nigusu-Allehu Nigusu-Allehu commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Bug

Fixes: NuGet/Home#15083

Description

Design spec: NuGet/Home#15048

Adds the initial stage command family with support for staging packages

Option Description
-s, --source Specifies a configured package source name or V3 service-index URL. Uses DefaultPushSource when omitted.
-k, --api-key Specifies the staging API key. The command otherwise checks NUGET_API_KEY and configured API keys.
--group Stages the package and matching symbols in the specified staging group.
--no-symbols Prevents automatic discovery and staging of sibling symbols.
--configfile Uses only the specified NuGet configuration file.
--interactive Allows credential providers to prompt for authentication.

Also API-key configuration lookup is moved to SettingsUtility so that the same logic is used across commands.

PR Checklist

@Nigusu-Allehu
Nigusu-Allehu marked this pull request as ready for review September 16, 2026 18:37
@Nigusu-Allehu
Nigusu-Allehu requested a review from a team as a code owner September 16, 2026 18:37
@Nigusu-Allehu
Nigusu-Allehu requested review from kartheekp-ms and zivkan and a lite review from Copilot September 16, 2026 18:37

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.

🟡 Changes recommended

Unresolved critical and moderate issues remain in HTTP handling, configuration isolation, and staging error reporting.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds the initial dotnet nuget stage push command for package and symbol staging, source/API-key resolution, HTTP controls, and shared API-key lookup.

Changes:

  • Adds command parsing, execution, validation, and staging tests.
  • Moves API-key resolution into SettingsUtility.
  • Updates protocol APIs, callers, localization, and functional test infrastructure.
File summaries
File Summary
test/NuGet.Core.Tests/NuGet.Configuration.Test/SettingsUtilityTests.cs Tests shared API-key resolution.
test/NuGet.Core.Tests/NuGet.Commands.Test/CommandRunnerUtilityTests.cs Removes tests for the relocated helper.
test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Stage/StagePushCommandRunnerTests.cs Tests runner validation and symbol discovery.
test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/Commands/Stage/StagePushCommandLineParsingTests.cs Tests stage command parsing.
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XPlatStagePushTests.cs Adds functional staging tests.
test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/StagePushTestServer.cs Provides staging test-server behavior.
src/NuGet.Core/NuGet.Protocol/Resources/PackageStagingResourceV3.cs Removes an obsolete staging overload.
src/NuGet.Core/NuGet.Protocol/PublicAPI/net472/PublicAPI.Unshipped.txt Updates protocol API metadata.
src/NuGet.Core/NuGet.Protocol/PublicAPI/net10.0/PublicAPI.Unshipped.txt Updates protocol API metadata.
src/NuGet.Core/NuGet.Configuration/Utility/SettingsUtility.cs Adds shared API-key lookup.
src/NuGet.Core/NuGet.Configuration/PublicAPI.Unshipped.txt Records the new API.
src/NuGet.Core/NuGet.Commands/Utility/CommandRunnerUtility.cs Removes duplicated API-key logic.
src/NuGet.Core/NuGet.Commands/CommandRunners/PushRunner.cs Uses shared API-key lookup.
src/NuGet.Core/NuGet.Commands/CommandRunners/DeleteRunner.cs Uses shared API-key lookup.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hant.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.zh-Hans.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.tr.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pt-BR.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf Adds localized resources.
src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx Adds stage command strings.
src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs Adds generated string accessors.
src/NuGet.Core/NuGet.CommandLine.XPlat/PublicAPI.Unshipped.txt Records the command API.
src/NuGet.Core/NuGet.CommandLine.XPlat/Program.cs Registers stage commands.
src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Stage/StagePushCommandRunner.cs Implements staging execution. Moderate findings: propagate insecure-connection opt-in to HttpSource (1 vote); use only the specified config file (1 vote); surface structured staging errors (1 vote). Critical finding: require the explicit CLI opt-in for HTTP sources rather than treating configuration as implicit consent (1 vote). Nit findings: add API-key fallback coverage (2 votes) and an end-to-end opt-in test (1 vote).
src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Stage/StagePushCommandArgs.cs Defines staging arguments.
src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Stage/StagePushCommand.cs Defines push options and parsing.
src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Stage/StageCommand.cs Defines the stage command family.
Review details

Files not reviewed (1)

  • src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs: Generated file

Suppressed comments (4)

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Stage/StagePushCommandRunner.cs:68

  • This flag is not propagated to the HttpSource used by the staging resource. When an HTTPS service index advertises an HTTP staging endpoint, PackageStagingResourceV3 can pass this check, but HttpSource.ProcessResponseAsync still rejects the request because PackageSource.AllowInsecureConnections remains false, so --allow-insecure-connections fails for that valid configuration. Propagate the opt-in to the package source before creating/discovering the resource, and cover an HTTPS index with an HTTP staging endpoint.
            bool allowInsecureConnections = args.AllowInsecureConnections || packageSource.AllowInsecureConnections;

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Stage/StagePushCommandRunner.cs:68

  • The positive functional tests configure every HTTP test source with allowInsecureConnections=true, so they do not exercise the newly added command-line opt-in. Add an end-to-end case with an HTTP source that has no config opt-in and verify that --allow-insecure-connections permits the upload and emits the warning.
            bool allowInsecureConnections = args.AllowInsecureConnections || packageSource.AllowInsecureConnections;

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Stage/StagePushCommandRunner.cs:51

  • --configfile is documented as using only the specified NuGet configuration, but XPlatUtility.ProcessConfigFile calls Settings.LoadDefaultSettings, which also loads the normal hierarchy, user-wide settings, and machine-wide settings. A staging invocation can therefore select a source or API key outside the specified file; use Settings.LoadSpecificSettings for the supplied path and the default loader only when the option is omitted.
            ISettings settings = XPlatUtility.ProcessConfigFile(args.ConfigFile);

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Stage/StagePushCommandRunner.cs:125

  • The linked staging CLI contract requires structured non-2xx responses to surface the server's error.code and error.message. These uploads delegate failures to EnsureSuccessStatusCode, and the symbol-failure path logs only HttpRequestException.Message, so staging-service diagnostics are discarded and users receive only a generic status error; parse and propagate the staging error payload for both package and symbol uploads.
            await stagingResource.PushPackageAsync(
                packagePath,
                apiKey,
                args.GroupId,
                RequestTimeout,
                allowInsecureConnections,
                args.Logger,
                args.CancellationToken);
  • Files reviewed: 34/35 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

@Nigusu-Allehu Nigusu-Allehu self-assigned this Sep 16, 2026

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

I haven't looked at the test code yet, but I thought I'd publish my comments so far on the product code.

@Nigusu-Allehu Nigusu-Allehu changed the title Add nuget stage commandline Add stage commandline command Sep 17, 2026
zivkan
zivkan previously approved these changes Sep 18, 2026

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

just nickpicks. FWIW, I'm really not a fan of MemberData for theory tests. I much prefer InlineData, but also consider whether a private helper function, and then individually named tests is more maintainable than a generic test method with complex inputs that need to be read to understand all the different test scenarios.

};

[PlatformTheory(Platform.Windows)]
[MemberData(nameof(ApiKeyPriorityTestData))]

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.

nitpick: I think that needing MemberData is usually a sign that the test is overly complex, making it harder to readers to understand. But 3 strings can use InlineData, so we don't need this level of indirection.


// Assert
Assert.Equal(ExitCodes.Success, exitCode);
Assert.Equal(expectedApiKey, Assert.Single(server.Requests).ApiKey);

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.

nitpick: The scenarios tested by this test method took 2.6s, 850ms and 290ms to run on CI. The 2.6s is almost certainly due to needing to JIT compile a lot of code that hasn't run yet, but the other two scenarios, 850ms and 290ms are very slow considering what it's trying to test. If the test could inject a mock SourceRepository with a mock staging resource, then the assert can check the api key provided without making actual http requests to an actual server, and would only take single digit milliseconds. I don't think it's a good thing that our tests take many hours of CI time to complete, especially since the CI agent pool is so busy we often need to wait an hour for our CI pipeline to start running our job. Anyway, I think it'd be nice to be more considerate about test duration, and look for opportunities to use quick unit tests, leaving the slow functional/integration tests for actual integration testing.

string[] args = CreateArgs(pathContext, server, packagePath);

// Act
int exitCode = CommandLine.XPlat.Program.MainInternal(

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.

nitpick: This is running the CLI app, but in-proc rather than a child proc. I think that's the wrong strategy, and has the problem I reported in the previous review about calling the cred provider's static function in-proc.

Other commands I'm familiar with have unit tests for the CLI parser, and then test the command runner by calling the runner directly.

Program.Main might be setting static variables that could introduce flakiness in parallel tests, or even sequential tests, since Program.Main expects the process to end when it returns.

It also does a whole lot of work unnecessary to test this command, like setting up the root command, registering every command, and then parsing the CLI args.


[Theory]
[MemberData(nameof(ValidArgumentsTestData))]
public void PushCommand_WithValidArguments_SetsExpectedValues(

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.

nitpick: Looking at the test results on Azure DevOps, all the scenarios have the same name/title. So, if just one of them were to fail, I'd have no idea which one failed, and therefore which scenario is broken.

@Nigusu-Allehu
Nigusu-Allehu merged commit 714413d into dev Sep 20, 2026
18 checks passed
@Nigusu-Allehu
Nigusu-Allehu deleted the dev-nyenework-nuget-stage-cli branch September 20, 2026 22:13
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.

Implement dotnet nuget stage push command

4 participants