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_packagefor a project member. The permission is defined dynamically per role inAuthz::RolePermissions.define_role_permissions(:project), included byProjectPolicy(app/policies/project_policy.rb:20), which gatescreate_packagepurely onrole_enables_create_package— the user's role viaAuthz::Role.get_from_access_level, not the project's visibility level. - Auth transport doesn't affect it either.
authenticate_with(used inlib/api/nuget_project_packages.rb:221and:300) resolves bothbasic_authandapi_keyto the samecurrent_user/token before any package-creation code runs — by the timecreate_packageis 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 forPRIVATE+:basic_auth,PUBLIC+:api_key, andPRIVATE+:api_keywith 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 runBoth 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
- Checkout this branch.
- Run
bundle exec rspec spec/requests/api/nuget_project_packages_spec.rb. - Confirm 1334 examples, 0 failures.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.