Repository navigation
Add stage commandline command - #7712
Conversation
There was a problem hiding this comment.
🟡 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
HttpSourceused by the staging resource. When an HTTPS service index advertises an HTTP staging endpoint,PackageStagingResourceV3can pass this check, butHttpSource.ProcessResponseAsyncstill rejects the request becausePackageSource.AllowInsecureConnectionsremains false, so--allow-insecure-connectionsfails 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-connectionspermits the upload and emits the warning.
bool allowInsecureConnections = args.AllowInsecureConnections || packageSource.AllowInsecureConnections;
src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Stage/StagePushCommandRunner.cs:51
--configfileis documented as using only the specified NuGet configuration, butXPlatUtility.ProcessConfigFilecallsSettings.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; useSettings.LoadSpecificSettingsfor 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.codeanderror.message. These uploads delegate failures toEnsureSuccessStatusCode, and the symbol-failure path logs onlyHttpRequestException.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.
zivkan
left a comment
There was a problem hiding this comment.
I haven't looked at the test code yet, but I thought I'd publish my comments so far on the product code.
zivkan
left a comment
There was a problem hiding this comment.
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))] |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
Bug
Fixes: NuGet/Home#15083
Description
Design spec: NuGet/Home#15048
Adds the initial
stagecommand family with support for staging packagesAlso API-key configuration lookup is moved to
SettingsUtilityso that the same logic is used across commands.PR Checklist
dotnet nuget stage pushcommand Home#15087