Skip to content

Extract portable Swift registry metadata transformations - #809

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

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

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

Part of #501, the Swift step.

As in #612 for npm, the Swift Package Registry metadata transformations move out of internal/handler into internal/metadata/swift:

  • RewriteLinkHeader and RewriteRegistryURL, which point upstream URLs in a Link header at the proxy's /swift path and leave other hosts, schemes and paths outside the upstream as they are
  • RewriteReleaseURLs and ReleaseURL, for the release list's url fields
  • SourceArchive and ArchiveInfo, which read the source archive's checksum and signature from a release's metadata
  • NormalizeChecksum and DigestHeader
  • ValidScope, ValidPackageName, ValidPackageReference and CanonicalPackage, the identifier checks the routes use

Swift has no cooldown filtering, so Options only carries the proxy and upstream URLs. The package doesn't depend on handler.Proxy. The code moves as it was, so responses are the same.

What stays in the handler: fetching, the metadata cache, routes, the source archive HEAD probe and headers, and downloads. The functions the handler and its tests use stay as thin wrappers, so the handler tests run unchanged against the real routes.

Portability: GOOS=wasip1 GOARCH=wasm go build ./internal/metadata/swift works. The package imports only the standard library; imports_test.go fails on any non-standard import and on net, net/http, log/slog or database/sql.

New tests in internal/metadata/swift cover the URL rewrite for relative URLs, query, fragment, host case, other hosts and schemes, paths outside the upstream and unparseable input; the Link header; the release list; source archive lookup, signing and its errors; the checksum helpers; and the identifier rules including length limits. They were mutation-checked, as was the handler's wiring. There are no Swift benchmarks to compare. go test ./... and golangci-lint run ./... pass.

The Swift registry rewrites, the source archive lookup in release
metadata, the checksum helpers and the package identifier checks move
from internal/handler into internal/metadata/swift, which takes the proxy
and upstream URLs explicitly and builds for wasip1. The handler keeps
fetching, caching, routes and downloads, with its functions as thin
wrappers.
@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 40 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: 886a3033-8da7-4d6c-8abe-6a38dc83cc62
Commits

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

Files selected for processing: 4

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