Skip to content

Extract portable Cargo metadata transformations - #807

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

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

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

Part of #501, the Cargo step.

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

  • Filter: leaves out of a sparse index the entries the denylist names and those cooldown holds back by their pubtime; entries without a readable pubtime are kept, and lines that aren't JSON entries are left out, as before
  • PublishTime, which reads a version's pubtime for a download and reports whether the index lists it
  • IndexPath and DownloadTemplate (the config.json dl value)

The package takes its inputs explicitly in Options: the cooldown policy, the time cooldown is evaluated at, and a denylist check. It reports versions cooldown holds back through OnWithheld and unreadable lines through OnInvalidEntry, which the handler logs and records as before. It doesn't depend on handler.Proxy.

What stays in the handler: fetching, writing the response, downloads and their cooldown check. applyCooldownFiltering, buildIndexPath and publishTime stay as thin wrappers, so the handler tests run unchanged against the real routes.

Cooldown in the filter is checked with Evaluate at one EvaluatedAt instead of IsAllowed per entry, as in internal/metadata/npm. The handler passes time.Now(), so results are the same unless a filter runs across a cooldown boundary. The filtered index is built and written once instead of line by line. The cooldown log's published field is the parsed time in RFC 3339, which differs from the raw pubtime only for fractional seconds.

TestCooldownSupportedCoversHandlers now also reads internal/metadata, since that is where the Cargo cooldown check is now. It's the same change as in #804, so the two merge cleanly in either order.

Portability: GOOS=wasip1 GOARCH=wasm go build ./internal/metadata/cargo 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.

New tests in internal/metadata/cargo cover cooldown evaluated at EvaluatedAt, entries without or with an unreadable pubtime, the denylist with and without a policy, a disabled policy, invalid lines, long entries, the pubtime lookup and the index paths. They were mutation-checked, as was the handler's wiring. There are no Cargo benchmarks to compare. go test ./... and golangci-lint run ./... pass.

Part of git-pkgs#501. The sparse index filter, the pubtime lookup for downloads,
the index path and the config.json download template move out of
internal/handler into internal/metadata/cargo, which takes its policy,
evaluation time and callbacks in Options and doesn't depend on
handler.Proxy. The handler keeps fetching, writing the response, logging
and recording withheld versions, with its method names as thin wrappers.

Cooldown is checked with Evaluate at one EvaluatedAt per index instead of
IsAllowed per entry, as in internal/metadata/npm.

TestCooldownSupportedCoversHandlers also reads internal/metadata, where
the cargo cooldown check now is.
@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 45 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: 66a4df5a-15bf-45ae-b1f1-2ab418bc054b
Commits

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

Files selected for processing: 5

  • internal/handler/cargo.go
  • internal/handler/cooldown_supported_test.go
  • internal/metadata/cargo/imports_test.go
  • internal/metadata/cargo/metadata.go
  • internal/metadata/cargo/metadata_test.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