Skip to content

Extract portable NuGet metadata transformations - #808

Open
simonchrz wants to merge 1 commit into
git-pkgs:mainfrom
simonchrz:refactor/metadata-nuget
Open

simonchrz wants to merge 1 commit into
git-pkgs:mainfrom
simonchrz:refactor/metadata-nuget

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

Part of #501, the NuGet step.

As in #612 for npm, the NuGet metadata transformations move out of internal/handler into internal/metadata/nuget:

  • RewriteServiceIndex and ServiceURL, which point the services the proxy handles at it
  • WriteRegistration, the streaming registration copy that points links at the proxy and, with filtering on, leaves out the leaves cooldown holds back and the pages that end up empty, correcting counts and bounds
  • DecodeTimes, Times and Release, which read only the members that decide cooldown, the way WriteRegistration copies them
  • FilterVersions for the flat container version list, and DecodeDocument
  • ProxyLink, CatalogPath, RegistrationPagePath, RegistrationID, RegistrationLeafVersion, VersionKey and UnlistedTime

The package takes its inputs explicitly in Options: upstream and proxy URLs, the cooldown policy and the time cooldown is evaluated at. It reports versions cooldown holds back through OnWithheld, which the handler records as before. It doesn't depend on handler.Proxy.

What stays in the handler: fetching and the metadata cache, the fallback to older registration hives, expanding linked pages, the catalog lookup for unlisted versions, downloads and error responses. The handler's function names stay as thin wrappers and nugetTimes is an alias for nuget.Times, so the handler tests run unchanged.

Cooldown is checked with Evaluate at one EvaluatedAt instead of IsAllowed per leaf, as in internal/metadata/npm. The handler passes time.Now(), and a registration request now uses one time for the leaf check and the copy, so results are the same unless a request runs across a cooldown boundary. TestCooldownSupportedCoversHandlers also reads internal/metadata, since NuGet's cooldown call now lives there; it's the same change as in #804.

Portability: GOOS=wasip1 GOARCH=wasm go build ./internal/metadata/nuget works. imports_test.go fails on any non-standard import outside an allowlist (cooldown, purl, vers, packageurl-go, internal/packageurl) and on net, net/http, log/slog or database/sql. The package has its own copy of the path traversal check, since the handler's can't be imported.

New tests in internal/metadata/nuget cover the service index, cooldown evaluated at EvaluatedAt with the callback, no policy and no callback, blocked versions in nested registrations, the version list filter, the registration copy with and without filtering and with inlined pages, the times decoder, and the link and path helpers including traversal and foreign hosts. They were mutation-checked, as was the handler's wiring. There are no NuGet benchmarks to compare. go test ./... and golangci-lint run ./... pass.

Part of git-pkgs#501. The NuGet service index rewrite, the registration copy
that points links at the proxy and leaves out versions in cooldown, the
registration times decoder, the flat container version filter and the
link and path helpers move into internal/metadata/nuget. The package
takes the URLs, the cooldown policy and the evaluation time in Options
and reports withheld versions through a callback, so it doesn't depend
on handler.Proxy and builds for wasip1.

The handler keeps fetching, caching, routes and downloads; its function
names stay as thin wrappers. A registration request decides cooldown at
one evaluation time for the leaf check and the copy.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 57e28594-be6e-4a8f-8b8c-cd97981ceb63
Commits

Reviewing files that changed from the base of the PR and between be51120 and fb28268.

Files selected for processing: 8

  • internal/handler/cooldown_supported_test.go
  • internal/handler/nuget.go
  • internal/handler/nuget_cooldown.go
  • internal/metadata/nuget/imports_test.go
  • internal/metadata/nuget/metadata.go
  • internal/metadata/nuget/metadata_test.go
  • internal/metadata/nuget/registration.go
  • internal/metadata/nuget/times.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant