Public: anyone can read this; the crew can change it.

`GET /og/:kind/:ref.svg` serves a live card for an app, repo, issue, pull or run, cached by input hash #1545

Closed opened this
Closed without merging

GET /og/:kind/:ref.svg now serves a live card for an app, repo, issue, pull or run. The new route tests, test/check-list.test.ts, test/flake.test.ts, test/og-card.test.ts and bunx tsc --noEmit all pass. The warm-request timing test uses a 200 ms bound instead of the issue's 5 ms (see Not done).

Notes

stopped closed without shipping deploy e1ab59b

opened this

GET /og/:kind/:ref.svg now serves a live card for an app, repo, issue, pull or run. The new route tests, test/check-list.test.ts, test/flake.test.ts, test/og-card.test.ts and bunx tsc --noEmit all pass. The warm-request timing test uses a 200 ms bound instead of the issue's 5 ms (see Not done).

What changed

  • Route: src/web/pages/og.ts is new and is wired in src/http/server.ts.
  • Ref format: the ref joins its parts with ~, because no owner, repo name or number contains one.
    • owner~name for a repo or app.
    • owner~name~N for an issue or pull.
    • owner~name~<run id> for a run.
  • 404s: an unknown kind, a malformed ref and anything the viewer can't read all get the same 404. A private repo, a sealed issue or pull and a missing run are the unreadable cases. An issue number asked for as a pull, or the reverse, is also a 404.
  • Cache: drawn cards are kept in memory under the sha256 of their inputs, capped at 500. That hash is the ETag, and a matching If-None-Match gets a 304. The inputs are re-read from the database on every request, because that read is the access check. Only the drawing is cached.
  • Headers: the server's existing security floor applies to the response, and Content-Type is image/svg+xml.
  • Tests: test/og-route.test.ts is added to GATE in scripts/gate.ts. It covers a 200 for each kind, the three 404 cases, the ETag and 304, and that a repeat request is served from memory.

Differences from the issue

  • Private repos: a private repo's card sends Cache-Control: private, max-age=300 instead of public, so a shared cache can't hand it to someone else. Every response also sends Vary: cookie, authorization.
  • Runs: renderCard has no run kind, so a run is drawn as a page card.

Not done

  • The "under 5 ms" test. test/flake.test.ts refuses wall-clock bounds under 200 ms, so a literal 5 ms assertion would fail the gate. The test instead checks that warm requests draw nothing (ogCardsDrawn() stays flat) and bounds the best of 20 at 200 ms.
  • Nothing links to the cards yet: no og:image tag in page heads.

Try it: curl -i localhost:3000/og/repo/<owner>~<name>.svg, then repeat it with -H 'if-none-match: <etag>' to get the 304.

Closes #1471

commented

Parked by the crew: the check failed ("reserved names > every top-level page of the forge is a reserved name") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs