Reduce example count in nuget_project_packages

What does this MR do and why?

ee/spec/requests/api/nuget_project_packages_spec.rb runs the full 'process nuget upload' shared example (dozens of examples covering object storage, direct upload, nuspec extraction success/failure, and package tracking events) once per combination of project visibility (PUBLIC/PRIVATE) and auth transport (:basic_auth/:api_key) for the success case (developer, project member, valid token). None of those three extra combinations add real coverage:

  • Visibility doesn't affect create_package for a project member. The permission is defined dynamically per role in Authz::RolePermissions.define_role_permissions(:project), included by ProjectPolicy (app/policies/project_policy.rb:20), which gates create_package purely on role_enables_create_package — the user's role via Authz::Role.get_from_access_level, not the project's visibility level.
  • Auth transport doesn't affect it either. authenticate_with (used in lib/api/nuget_project_packages.rb:221 and :300) resolves both basic_auth and api_key to the same current_user/token before any package-creation code runs — by the time create_package is checked, the transport is already gone.

This MR keeps the full 'process nuget upload' suite on exactly one combination (PUBLIC

  • :basic_auth, the file's existing primary case) and replaces the same success case for PRIVATE + :basic_auth, PUBLIC + :api_key, and PRIVATE + :api_key with the new, lightweight 'accepts nuget upload' shared example, which still asserts the package gets created and the expected status is returned — just without repeating the full object storage / nuspec-extraction / tracking-event suite three more times for dimensions that don't change its outcome.

No coverage was removed: every visibility × role × transport combination in the table is still exercised somewhere (the full suite once, the lightweight check three times, and every 'rejects nuget packages access' row — which does vary by these dimensions — is untouched).

Spec Run Time Optimization Results

Before optimization:

  • 1478 examples
  • Run time: 3m 0.9s

After optimization:

  • 1334 examples
  • Run time: 2m 35.0s

Improvement:

  • Example count reduced by: 9.74% (1478 to 1334)
  • Run time reduced by: 0m 25.9s (25.9s)

Verified with:

bundle exec rspec spec/requests/api/nuget_project_packages_spec.rb --dry-run  # example count
bundle exec rspec spec/requests/api/nuget_project_packages_spec.rb            # full run

Both runs measured in the same local checkout for a fair comparison (same warm Rails boot, same DB/Gitaly state), swapping only the shared examples file's content between the pre- and post-optimization version.

bundle exec rubocop spec/support/shared_examples/requests/api/nuget_packages_shared_examples.rb reports no offenses.

Estimated CI Cost Savings

Using the same methodology as !248403 (merged): 25.9s saved per pipeline × $0.03/minute (large runners: 3x cost factor on $10/1,000 base minutes).

Scenario Pipelines/month Time saved/month Savings/year
Pessimistic 15,000 107.9h $2,331.00
Moderate 30,000 215.8h $4,662.00
Optimistic 50,000 359.7h $7,770.00

How to set up and validate locally

  1. Checkout this branch.
  2. Run bundle exec rspec spec/requests/api/nuget_project_packages_spec.rb.
  3. Confirm 1334 examples, 0 failures.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Merge request reports

Loading
Loading