Skip to content

Serve Go vanity import paths from moq.dev - #126

Merged
kixelated merged 2 commits into
mainfrom
vanity-go-imports
Aug 20, 2026
Merged

Serve Go vanity import paths from moq.dev#126
kixelated merged 2 commits into
mainfrom
vanity-go-imports

Conversation

@kixelated

@kixelated kixelated commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

go get resolves an import path by fetching it over HTTPS with ?go-get=1 and
reading the repo to clone out of a <meta name="go-import"> tag. Serving that
tag here makes moq.dev own the published import path instead of whichever mirror
repo the code happens to land in, so the Go wrapper can be imported as
moq.dev/moq rather than github.com/moq-dev/moq-go/moq. That also makes the
identifier moq with no alias, since the last path element finally matches the
package name, and it means a future mirror rename costs a line in a table rather
than a breaking change for every consumer.

Two modules are served:

Import path Repo
moq.dev/moq github.com/moq-dev/moq-go
moq.dev/moq-ffi github.com/moq-dev/moq-go-ffi

A module owns every path beneath it, because the go command asks about the full
import path (package directory included) while the tag has to answer with the
module path regardless. Requests without ?go-get=1 are people, so they redirect
to pkg.go.dev. The page also carries go-source, which is what pkg.go.dev
follows to link a symbol back to the line that declares it.

run_worker_first

/moq* is load-bearing for the same reason #125 needed /api/*: an asset miss
is answered with the 404 page rather than falling through, so the Worker never
runs. Confirmed against wrangler dev, which reproduces that routing:
/moq?go-get=1 returned the site's 404 page until the wildcard was added. It's a
wildcard rather than four exact entries so that adding a module to the table
can't silently 404 by forgetting this file.

Testing

worker/vanity.test.ts covers the tag, a package directory resolving to its
module, /moq and /moq-ffi not bleeding into each other, and the human
redirect. Against wrangler dev: both go-get paths return the right prefix,
/moq and /moq/sub/pkg 302 to pkg.go.dev, and /, /blog/, /rss.xml, and
an unrelated /moqadillo all still serve normally. tsc --noEmit and bun test
are clean.

Not in this PR

The tags are inert until each go.mod switches its module path, which is a
breaking change and lives in the moq repo. moq.dev/moq only avoids an alias if
the package moves to its module root (today it's in a moq/ subdirectory), and
the release scripts, both workflows, and doc/lib/go/ all name the old path.
Old github.com/moq-dev/moq-go versions keep resolving from the same tags after
the switch, so a retract or a README note is worth adding then.

(written by Opus 5)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6371e38656

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread worker/index.ts Outdated
Comment on lines +28 to +29
const module = vanity(url);
if (module) return module;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict vanity handling to the primary host

In the live environment, wrangler.jsonc routes both moq.dev and de.moq.dev to this Worker, but vanity handling runs before the existing DEMOQED hostname rewrite and does not inspect the hostname. Consequently, a request such as https://de.moq.dev/moq is redirected to pkg.go.dev, while https://de.moq.dev/moq?go-get=1 returns the moq.dev/moq metadata instead of being rewritten to /de/moq; restrict this call to the primary/staging vanity hosts or perform the de rewrite first.

Useful? React with 👍 / 👎.

Base automatically changed from fix/api-run-worker-first to main August 20, 2026 16:52
`go get` resolves an import path by fetching it over HTTPS with ?go-get=1 and
reading the repo out of a <meta name="go-import"> tag, so serving that tag here
makes moq.dev own the published import path instead of whichever mirror repo
the code lands in. The Go wrapper can then be imported as `moq.dev/moq` rather
than `github.com/moq-dev/moq-go/moq`, which also means the identifier is `moq`
with no alias, and a future mirror rename costs a line in the table rather than
a breaking change for every consumer.

Two paths are served, both inert until the matching go.mod switches its module
path:

  moq.dev/moq      -> github.com/moq-dev/moq-go
  moq.dev/moq-ffi  -> github.com/moq-dev/moq-go-ffi

A module owns every path beneath it, because the go command asks about the full
import path (package directory included) and the tag has to answer with the
module path regardless. Requests without ?go-get=1 are people, so they redirect
to pkg.go.dev.

`run_worker_first` needs the /moq* wildcard for the same reason #125 needed
/api/*: an asset miss is answered with the 404 page rather than falling through,
so the Worker would never run. Verified against `wrangler dev`, which reproduces
that routing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@kixelated, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Limit details: You’ve used the included review currently available.

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

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e86b5576-318b-4a90-a4af-ba73870c106f

📥 Commits

Reviewing files that changed from the base of the PR and between 799a20b and e759b43.

📒 Files selected for processing (3)
  • .github/workflows/pr.yml
  • worker/index.test.ts
  • worker/index.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 220b88d5-3f44-497c-bb38-34fc43079e6c

📥 Commits

Reviewing files that changed from the base of the PR and between 8d1f70a and 799a20b.

📒 Files selected for processing (4)
  • worker/index.ts
  • worker/vanity.test.ts
  • worker/vanity.ts
  • wrangler.jsonc

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The Worker now handles Go vanity import paths for moq and moq-ffi modules. Discovery requests return cached go-import and go-source metadata. Other matching requests redirect to pkg.go.dev. Unrelated paths remain unhandled. Worker routing sends /moq* requests to the Worker before asset fallback. Tests cover metadata, repository selection, redirects, shared prefixes, and unrelated paths.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: serving Go vanity import paths from moq.dev.
Description check ✅ Passed The description directly explains the vanity import routes, Worker routing, tests, and inactive module-path transition.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch vanity-go-imports

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

Comment @coderabbitai help to get the list of available commands.

Review findings from Codex.

The vanity lookup ran ahead of the de.moq.dev -> /de rewrite and never looked at
the hostname, so DEMOQED lost every URL beginning with /moq: de.moq.dev/moq
redirected to pkg.go.dev instead of resolving against /de. Doing the rewrite
first fixes it, since that branch returns, and it means the import paths only
ever answer for the host they're published under.

The tests only reached vanity() directly, which is the half that can't break the
site. worker/index.test.ts drives the Worker's fetch handler against a stub
ASSETS binding instead, so the ordering above is pinned by a test that fails
without it. That still doesn't cover `run_worker_first` -- only Cloudflare
routes that -- so index.ts says out loud that the Worker doesn't see a request
unless wrangler.jsonc lists it.

None of this ran in CI: the workflow calls `bun run check` (biome + tsc), which
never runs `bun test`, so these assertions and the existing broadcast tests were
all decorative.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Ran an adversarial review pass with Codex, plus the inline finding already on this PR. Two were real and are fixed in e759b43; one is rejected.

Fixed

de.moq.dev lost every /moq URL (the inline finding on worker/index.ts). Verified real: vanity() ran ahead of the de.moq.dev -> /de rewrite and never looked at the hostname, so de.moq.dev/moq redirected to pkg.go.dev instead of resolving against the DEMOQED page. Doing the rewrite first fixes it, since that branch returns, and it means the import paths only ever answer for the host they're published under. Confirmed against wrangler dev with Host: de.moq.dev: a 404 from /de/moq rather than a redirect.

The tests missed the layer that can actually break the site. They only called vanity() directly. worker/index.test.ts now drives the Worker's fetch handler against a stub ASSETS binding. I checked it fails on the old ordering before keeping it, so it's a regression test rather than a passing decoration. It still doesn't cover run_worker_first (only Cloudflare routes that), so index.ts now says out loud that the Worker doesn't see a request unless wrangler.jsonc lists it.

And none of it ran in CI. The workflow called bun run check (biome + tsc), which never runs bun test, so these assertions and the existing broadcast.test.ts were both decorative. Added bun test to pr.yml. Slightly beyond this PR's scope, but the alternative was landing tests nothing enforces.

Rejected

"NO SHIP: the target repos don't declare these module paths." True, deliberate, and already the "Not in this PR" section above: the mirrors still declare github.com/moq-dev/moq-go, so go get moq.dev/moq fails until they flip. The ordering is forced, though. The meta tags have to be live before a mirror publishes a moq.dev/moq go.mod, or the first tag that lands resolves to nothing. Serving them early is inert, not broken.

The one useful detail in that finding is real and already noted: with today's layout the usable path would be moq.dev/moq/moq, because the package sits in a moq/ subdirectory. That's why the follow-up has to move the sources to the module root.

"Staging can't supply end-to-end evidence." By design. HOST is hardcoded so staging serves the canonical prefix, which is exactly what makes go get new.moq.dev/moq fail correctly.

CI is green.

(written by Opus 5)

@kixelated
kixelated merged commit e48befe into main Aug 20, 2026
1 check passed
@kixelated
kixelated deleted the vanity-go-imports branch August 20, 2026 18:07
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