Skip to content

Extract portable pub.dev metadata transformations - #804

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

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

Conversation

@simonchrz

@simonchrz simonchrz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Part of #501, the pub.dev step.

As in #612 for npm, the pub.dev metadata transformations move out of internal/handler into internal/metadata/pub:

  • Rewrite: archive URLs pointing at the proxy, cooldown filtering, and latest following the versions kept (the newest stable version left, else the newest prerelease, dropped when none is left)
  • ArchiveURL, where the proxy serves a version's archive

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

What stays in the handler: fetching, the metadata cache, routes, downloads and their cooldown check. rewriteMetadata stays as a thin wrapper, so the handler tests run unchanged against the real routes.

Cooldown in the rewrite is checked with Evaluate at one EvaluatedAt instead of IsAllowed per version, as in internal/metadata/npm. The handler passes time.Now(), so results are the same unless a rewrite runs across a cooldown boundary. The per-version debug log of rewritten archive URLs is gone.

TestCooldownSupportedCoversHandlers now also reads internal/metadata, since pub's only literal cooldown check was the rewrite; downloads go through the shared download check.

Portability: GOOS=wasip1 GOARCH=wasm go build ./internal/metadata/pub works. imports_test.go fails on any non-standard import outside an allowlist (cooldown, purl, vers, packageurl-go, internal/packageurl, and Masterminds/semver for latest) and on net, net/http, log/slog or database/sql.

New tests in internal/metadata/pub cover the archive URL rewrite, cooldown evaluated at EvaluatedAt, the callback, versions without a usable publish time, a disabled and a missing policy, every latest case, and documents without versions. They were mutation-checked, as was the handler's wiring. There are no pub benchmarks to compare. go test ./... and golangci-lint run ./... pass.

Summary by CodeRabbit

  • Refactor
    • Package metadata responses continue to include proxy archive links and apply cooldown filtering to published versions.
    • The reported latest version reflects an available stable release when possible, or the newest available prerelease when no stable versions remain.
  • Tests
    • Added coverage for metadata rewriting, cooldown decisions, archive links, and latest-version selection.

As for npm, PyPI and Composer, the pub.dev metadata rewrite moves out of
internal/handler into internal/metadata/pub: archive URLs pointing at
the proxy, cooldown filtering, and latest following the versions kept.
It takes the proxy URL, cooldown policy and evaluation time in Options
and reports held-back versions through OnCooldownFilter, which the
handler logs and records. It builds for wasip1.

Cooldown is checked with Evaluate at one EvaluatedAt per rewrite instead
of IsAllowed per version. The cooldown coverage test now also reads
internal/metadata, where the extracted rewrites check cooldown.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Pub metadata rewriting moves from PubHandler into internal/metadata/pub. The new package handles archive URL rewriting, cooldown filtering, and latest selection. The handler supplies rewrite inputs and records filtered versions.

Changes: Pub Metadata Rewriting

Layer / File(s) Summary
Metadata rewrite implementation and validation
internal/metadata/pub/metadata.go, internal/metadata/pub/metadata_test.go, internal/metadata/pub/imports_test.go
The new package provides Rewrite and ArchiveURL. It filters versions by cooldown, updates archive URLs and latest, and includes tests for rewrite behavior and allowed imports.
Handler delegation and cooldown coverage
internal/handler/pub.go, internal/handler/cooldown_supported_test.go
PubHandler delegates metadata rewriting and logs and records filtered versions. The cooldown coverage test scans metadata package files as well as handler files.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related issues

  • git-pkgs/proxy#501 asks to move metadata transformations into packages with explicit inputs. This change adds internal/metadata/pub with explicit rewrite options.
  • git-pkgs/proxy#127 asks for filtered-version reporting that supports latest rewriting. This change reports cooldown-filtered versions and updates latest, but does not add the requested general filter interface.

Possibly related PRs

Suggested reviewers: andrew

Merge Risk: Minimal · up to def72

This change moves pub.dev metadata rewriting into a standalone package, and the handler delegates to it. No concrete merge-blocking risk was found, and behavior appears preserved apart from the described single-instant cooldown evaluation.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says the PR extracts portable pub.dev metadata transformations. The changeset does this: it adds internal/metadata/pub with Rewrite and ArchiveURL, and moves cooldown filtering, archive URL …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title says the PR extracts portable pub.dev metadata transformations. The changeset does this: it adds internal/metadata/pub with Rewrite and ArchiveURL, and moves cooldown filtering, archive URL rewriting, and latest-version selection out of PubHandler. The title names the main change, and it is specific enough for a teammate scanning history.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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

Recent review info

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: 0b34ec23-d844-47aa-a93a-01d6ead62f0c
Commits

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

Files selected for processing: 5

  • internal/handler/cooldown_supported_test.go
  • internal/handler/pub.go
  • internal/metadata/pub/imports_test.go
  • internal/metadata/pub/metadata.go
  • internal/metadata/pub/metadata_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

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