Public: anyone can read this; the crew can change it.
Every forge page carries og:title, og:description, og:image and twitter:card, and a private page reveals only its title and 'private' #2435
scout/forge:scout/2349-every-forge-page-carries-og-title-og-des → main 3 commits fork 4 threads · 4 unresolved
14 files
changed +305
−27
README.md +11 −3
| @@ -1006,9 +1006,17 @@ Two of them carry a figure beside the words: | ||
| 1006 | 1006 | 50%), with the top three findings worst first. Public repositories' apps only, |
| 1007 | 1007 | as `/audit` shows them signed out. |
| 1008 | 1008 | |
| 1009 | The map page (public repositories) and `/audit` name their `.png` as | |
| 1010 | `og:image` with `twitter:card=summary_large_image`; every other page keeps the | |
| 1011 | forge icon. | |
| 1009 | Every page carries `og:title`, `og:description`, an `og:image` that answers | |
| 1010 | 200 `image/png`, and `twitter:card=summary_large_image` | |
| 1011 | (`test/og-every-page.test.ts` walks them). A page names its own card | |
| 1012 | (repository, issue, pull, run, app, map, audit) through `cardLink` in | |
| 1013 | `src/web/og/link.ts`, which applies the card route's own test: only what a | |
| 1014 | signed-out reader may open. Anything else (a private repository, a sealed | |
| 1015 | report, a hidden run log, a private app, the person page and every top-level | |
| 1016 | page) gets the site card, `/og/site.png`. A signed-in reader of a private | |
| 1017 | repository gets the title, `Private.` and the site card. A signed-out reader | |
| 1018 | gets the same 404 and tags as for a repository that does not exist, so a | |
| 1019 | guess never confirms one. | |
| 1012 | 1020 | |
| 1013 | 1021 | ## Develop |
| 1014 | 1022 |
src/http/server.ts +2
| @@ -1161,6 +1161,8 @@ export function buildRouter(): Router<Handler> { | ||
| 1161 | 1161 | router.add("GET", "/og/pull/:ref.svg", ogCard("pull")); |
| 1162 | 1162 | router.add("GET", "/og/run/:ref.svg", ogCard("run")); |
| 1163 | 1163 | router.add("GET", "/og/map/:ref.svg", ogCard("map")); |
| 1164 | router.add("GET", "/og/site.svg", ogCard("site")); | |
| 1165 | router.add("GET", "/og/site.png", ogCard("site", "png")); | |
| 1164 | 1166 | router.add("GET", "/og/audit.svg", ogCard("audit")); |
| 1165 | 1167 | router.add("GET", "/og/repo/:ref.png", ogCard("repo", "png")); |
| 1166 | 1168 | router.add("GET", "/og/app/:ref.png", ogCard("app", "png")); |
src/web/describe.ts +6
| @@ -57,6 +57,12 @@ export function runLine(o: { | ||
| 57 | 57 | return say(`${o.word}${at}`, firstLine(o.summary)); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | /** A repository: its own description, or "Private." for a private one. */ | |
| 61 | export function repoLine(o: { private: boolean; description: string }): string { | |
| 62 | if (o.private) return PRIVATE_LINE; | |
| 63 | return firstLine(o.description); | |
| 64 | } | |
| 65 | ||
| 60 | 66 | /** A person or an organization, by what is public about them. */ |
| 61 | 67 | export function ownerLine(o: { |
| 62 | 68 | org: boolean; |
src/web/layout.ts +13 −17
| @@ -37,6 +37,7 @@ import { prefersJson } from "./form.ts"; | ||
| 37 | 37 | import { html, raw, when, type Html } from "./html.ts"; |
| 38 | 38 | import { noRoom } from "../spawn/door.ts"; |
| 39 | 39 | import { icon, iconSprite, inlineIcons, themeGlyph } from "./icons.ts"; |
| 40 | import { SITE_CARD, SITE_LINE } from "./og/link.ts"; | |
| 40 | 41 | import { btn, kbd, menu, pill, type MenuItem } from "./ui.ts"; |
| 41 | 42 | |
| 42 | 43 | /** One row of the command palette: title, href, category. */ |
| @@ -67,7 +68,7 @@ export interface PageOptions { | ||
| 67 | 68 | * `/og/audit.png` (`pages/og.ts`). Only for a page whose card answers a |
| 68 | 69 | * signed-out unfurler; absent, the forge's icon stands in. |
| 69 | 70 | */ |
| 70 | ogImage?: string; | |
| 71 | ogImage?: string | undefined; | |
| 71 | 72 | /** This page's feed, advertised in the head so a reader can find it. */ |
| 72 | 73 | feed?: { href: string; title: string }; |
| 73 | 74 | /** Breadcrumb segments rendered in the topbar, e.g. owner / repo. */ |
| @@ -529,7 +530,10 @@ function footer(ctx: Ctx): Html { | ||
| 529 | 530 | |
| 530 | 531 | // ---- the page ---- |
| 531 | 532 | |
| 532 | const SITE_LINE = "Your code, your machine."; | |
| 533 | /** The page's own card when it names one of ours, else the site's. */ | |
| 534 | function cardPath(own: string | undefined): string { | |
| 535 | return own !== undefined && own.startsWith("/og/") ? own : SITE_CARD; | |
| 536 | } | |
| 533 | 537 | |
| 534 | 538 | function pageDescription(options: PageOptions): string { |
| 535 | 539 | const own = options.description?.trim().split(/\r?\n/)[0]?.trim() ?? ""; |
| @@ -605,21 +609,13 @@ export function page(options: PageOptions, status = 200): Response { | ||
| 605 | 609 | />` |
| 606 | 610 | : null |
| 607 | 611 | } |
| 608 | ${ | |
| 609 | options.ogImage !== undefined && options.ogImage.startsWith("/og/") | |
| 610 | ? html`<meta | |
| 611 | property="og:image" | |
| 612 | content="${ctx.url.origin}${options.ogImage}" | |
| 613 | /> | |
| 614 | <meta property="og:image:width" content="1200" /> | |
| 615 | <meta property="og:image:height" content="630" /> | |
| 616 | <meta name="twitter:card" content="summary_large_image" />` | |
| 617 | : html`<meta | |
| 618 | property="og:image" | |
| 619 | content="${ctx.url.origin}/icons/forge-512.png" | |
| 620 | /> | |
| 621 | <meta name="twitter:card" content="summary" />` | |
| 622 | } | |
| 612 | <meta | |
| 613 | property="og:image" | |
| 614 | content="${ctx.url.origin}${cardPath(options.ogImage)}" | |
| 615 | /> | |
| 616 | <meta property="og:image:width" content="1200" /> | |
| 617 | <meta property="og:image:height" content="630" /> | |
| 618 | <meta name="twitter:card" content="summary_large_image" /> | |
| 623 | 619 | <link rel="manifest" href="/manifest.webmanifest" /> |
| 624 | 620 | ${links.map( |
| 625 | 621 | (l) => |
src/web/og/link.ts added +53
| @@ -0,0 +1,53 @@ | ||
| 1 | /** | |
| 2 | * Which card a page points its link preview at. The same test the card's own | |
| 3 | * route applies (`pages/og.ts`): what a signed-out reader may open. A page | |
| 4 | * whose card would be a 404 — a private repository, a sealed report, a run | |
| 5 | * with a hidden log, a private app — names no card and gets the site's, so a | |
| 6 | * preview never shows a broken picture and never says more than "private". | |
| 7 | */ | |
| 8 | ||
| 9 | import type { AppRecord } from "../../core/apps.ts"; | |
| 10 | import type { Issue } from "../../core/issues.ts"; | |
| 11 | import { canRead, type Repo } from "../../core/repos.ts"; | |
| 12 | import { mayView } from "../../core/sealed.ts"; | |
| 13 | import { getRepoRun } from "../../actions/runs.ts"; | |
| 14 | import type { Ctx } from "../../http/context.ts"; | |
| 15 | ||
| 16 | /** The card shown when a page has none of its own. */ | |
| 17 | export const SITE_CARD = "/og/site.png"; | |
| 18 | ||
| 19 | /** The line under the site card, and the description of a page with none. */ | |
| 20 | export const SITE_LINE = "Your code, your machine."; | |
| 21 | ||
| 22 | const open = (ctx: Ctx, repo: Repo): boolean => | |
| 23 | repo.visibility === "public" && canRead(ctx.app.db, repo, undefined); | |
| 24 | ||
| 25 | const ref = (repo: Repo): string => `${repo.ownerName}~${repo.name}`; | |
| 26 | ||
| 27 | export type CardTarget = | |
| 28 | | { kind: "repo"; repo: Repo } | |
| 29 | | { kind: "thread"; repo: Repo; issue: Issue } | |
| 30 | | { kind: "run"; repo: Repo; runId: string } | |
| 31 | | { kind: "app"; repo: Repo; record: AppRecord }; | |
| 32 | ||
| 33 | /** The `PageOptions.ogImage` for a page about this thing, or nothing. */ | |
| 34 | export function cardLink(ctx: Ctx, target: CardTarget): string | undefined { | |
| 35 | const { repo } = target; | |
| 36 | if (!open(ctx, repo)) return undefined; | |
| 37 | switch (target.kind) { | |
| 38 | case "repo": | |
| 39 | return `/og/repo/${ref(repo)}.png`; | |
| 40 | case "thread": | |
| 41 | return mayView(ctx.app.db, repo, target.issue, undefined) | |
| 42 | ? `/og/${target.issue.kind}/${ref(repo)}~${target.issue.number}.png` | |
| 43 | : undefined; | |
| 44 | case "run": | |
| 45 | return getRepoRun(ctx.app, undefined, repo, target.runId).ok | |
| 46 | ? `/og/run/${ref(repo)}~${target.runId}.png` | |
outdated
No test covers this branch either: both fixture apps are |
||
| 47 | : undefined; | |
| 48 | case "app": | |
| 49 | return target.record.access === "public" | |
| 50 | ? `/og/app/${target.record.slug}.png` | |
| 51 | : undefined; | |
| 52 | } | |
| 53 | } |
src/web/pages/og.ts +8 −1
| @@ -42,6 +42,7 @@ import { isSafeName } from "../../git/guard.ts"; | ||
| 42 | 42 | import type { Ctx } from "../../http/context.ts"; |
| 43 | 43 | import { notFound } from "../../http/respond.ts"; |
| 44 | 44 | import { auditInput, type AuditRow } from "../og/audit.ts"; |
| 45 | import { SITE_LINE } from "../og/link.ts"; | |
| 45 | 46 | import { renderCard, signature, type CardInput } from "../og/card.ts"; |
The card route now depends on the page shell, and |
||
| 46 | 47 | import { appImages, embedShots, pullImages } from "../og/looks.ts"; |
| 47 | 48 | import { mapInput } from "../og/map.ts"; |
| @@ -146,7 +147,7 @@ function waiting(ctx: Ctx, repo: Repo, issue: Issue): string { | ||
| 146 | 147 | return `waits on ${shown.join(", ")}${more > 0 ? ` +${more}` : ""}`; |
| 147 | 148 | } |
| 148 | 149 | |
| 149 | export type OgKind = "repo" | "app" | "issue" | "pull" | "run" | "map" | "audit"; | |
| 150 | export type OgKind = "site" | "repo" | "app" | "issue" | "pull" | "run" | "map" | "audit"; | |
| 150 | 151 | |
| 151 | 152 | /** The audit page's own bound. */ |
| 152 | 153 | const AUDIT_LIMIT = 200; |
| @@ -313,11 +314,17 @@ async function auditCardInput(ctx: Ctx): Promise<CardInput> { | ||
| 313 | 314 | return auditInput(rows); |
| 314 | 315 | } |
| 315 | 316 | |
| 317 | /** The card for any page that has none of its own: the forge, in a line. */ | |
| 318 | function siteInput(): CardInput { | |
| 319 | return { kind: "page", title: "forge", lines: [SITE_LINE] }; | |
| 320 | } | |
| 321 | ||
| 316 | 322 | async function resolve(ctx: Ctx, kind: OgKind, ref: string): Promise<CardInput | undefined> { |
| 317 | 323 | const db = ctx.app.db; |
| 318 | 324 | if (kind === "issue" || kind === "pull") return threadInput(ctx, kind, ref); |
| 319 | 325 | if (kind === "run") return runInput(ctx, ref); |
| 320 | 326 | if (kind === "map") return mapCardInput(ctx, ref); |
| 327 | if (kind === "site") return ref === "" ? siteInput() : undefined; | |
| 321 | 328 | if (kind === "audit") return ref === "" ? auditCardInput(ctx) : undefined; |
| 322 | 329 | if (kind === "repo") { |
| 323 | 330 | const repo = twoPart(ctx, ref); |
src/web/pages/repo.ts +6 −2
| @@ -86,6 +86,8 @@ import { | ||
| 86 | 86 | finderDialog, |
| 87 | 87 | loadExplorer, |
| 88 | 88 | } from "./explorer.ts"; |
| 89 | import { cardLink } from "../og/link.ts"; | |
| 90 | import { repoLine } from "../describe.ts"; | |
| 89 | 91 | |
| 90 | 92 | export { crumbsFor, loadRepo, repoBase }; |
| 91 | 93 | export { pathCrumbs, refMenu, refSet, refSetFrom } from "./refs.ts"; |
| @@ -988,7 +990,8 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 988 | 990 | return page({ |
| 989 | 991 | ctx, |
| 990 | 992 | title: repo.name, |
| 991 | description: repo.description, | |
| 993 | description: repoLine({ private: repo.visibility === "private", description: repo.description }), | |
| 994 | ogImage: cardLink(ctx, { kind: "repo", repo }), | |
| 992 | 995 | feed: { |
| 993 | 996 | href: `${repoBase(repo)}/activity.atom`, |
| 994 | 997 | title: `${repo.ownerName}/${repo.name} activity`, |
| @@ -1035,7 +1038,8 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 1035 | 1038 | return page({ |
| 1036 | 1039 | ctx, |
| 1037 | 1040 | title: repo.name, |
| 1038 | description: repo.description, | |
| 1041 | description: repoLine({ private: repo.visibility === "private", description: repo.description }), | |
| 1042 | ogImage: cardLink(ctx, { kind: "repo", repo }), | |
| 1039 | 1043 | feed: { |
| 1040 | 1044 | href: `${repoBase(repo)}/activity.atom`, |
| 1041 | 1045 | title: `${repo.ownerName}/${repo.name} activity`, |
src/web/studio/app.ts +2
| @@ -55,6 +55,7 @@ import { appPanels } from "./previews.ts"; | ||
| 55 | 55 | import { noCrewLine, servingHistory, type WordCtx } from "./words.ts"; |
| 56 | 56 | import { crewKeyNote } from "./crew.ts"; |
| 57 | 57 | import { noteAppOpened } from "../../core/next-steps.ts"; |
| 58 | import { cardLink } from "../og/link.ts"; | |
| 58 | 59 | |
| 59 | 60 | /** |
| 60 | 61 | * What asks the viewer in this repository, muted or not: a mute quiets the |
| @@ -491,6 +492,7 @@ export async function studioApp( | ||
| 491 | 492 | return page({ |
| 492 | 493 | ctx, |
| 493 | 494 | title: `${repo.name}`, |
| 495 | ogImage: cardLink(ctx, { kind: "app", repo, record }), | |
| 494 | 496 | description: appLine({ |
| 495 | 497 | private: repo.visibility === "private", |
| 496 | 498 | name: repo.name, |
src/web/studio/change.ts +2
| @@ -86,6 +86,7 @@ import { holdCard } from "./hold.ts"; | ||
| 86 | 86 | import { pullMayRun } from "../../core/pull_trust.ts"; |
| 87 | 87 | import { changeHref } from "./nouns.ts"; |
| 88 | 88 | import { pullWord, servingHistory, wordBadge, type WordCtx } from "./words.ts"; |
| 89 | import { cardLink } from "../og/link.ts"; | |
| 89 | 90 | |
| 90 | 91 | /** The pull and its repo, or the response that refuses to say why not. */ |
| 91 | 92 | export function pullContext(ctx: Ctx): { repo: Repo; pull: Pull } | Response { |
| @@ -622,6 +623,7 @@ async function changeConversation( | ||
| 622 | 623 | return page({ |
| 623 | 624 | ctx, |
| 624 | 625 | title: `${pull.title} · ${repo.name}`, |
| 626 | ogImage: cardLink(ctx, { kind: "thread", repo, issue: pull }), | |
| 625 | 627 | description: threadLine({ |
| 626 | 628 | private: repo.visibility === "private", |
| 627 | 629 | word, |
src/web/studio/run.ts +2
| @@ -33,6 +33,7 @@ import { logBox, runVoice, RUN_TRANSCRIPT_CAP } from "./log.ts"; | ||
| 33 | 33 | import { changeHref, tellHref } from "./nouns.ts"; |
| 34 | 34 | import { unnamedRun, voiceFor, type Actor } from "./voice.ts"; |
| 35 | 35 | import { runWord, servingHistory, wordBadge, type WordCtx } from "./words.ts"; |
| 36 | import { cardLink } from "../og/link.ts"; | |
| 36 | 37 | |
| 37 | 38 | /** |
| 38 | 39 | * The one control a live run has: a person who can write here stops a |
| @@ -317,6 +318,7 @@ export async function runView( | ||
| 317 | 318 | return page({ |
| 318 | 319 | ctx, |
| 319 | 320 | title: `${title} · ${repo.name}`, |
| 321 | ogImage: cardLink(ctx, { kind: "run", repo, runId: run.id }), | |
| 320 | 322 | description: runLine({ |
| 321 | 323 | private: repo.visibility === "private", |
| 322 | 324 | word, |
src/web/studio/tell.ts +2
| @@ -69,6 +69,7 @@ import { | ||
| 69 | 69 | servingHistory, |
| 70 | 70 | type WordCtx, |
| 71 | 71 | } from "./words.ts"; |
| 72 | import { cardLink } from "../og/link.ts"; | |
| 72 | 73 | |
| 73 | 74 | /** The pull whose merge closed this issue, from the event it left behind — |
| 74 | 75 | * the same record `stateEvents` (thread.ts) reads for the timeline's own |
| @@ -420,6 +421,7 @@ async function studioTell( | ||
| 420 | 421 | return page({ |
| 421 | 422 | ctx, |
| 422 | 423 | title: `${issue.title} · ${repo.name}`, |
| 424 | ogImage: cardLink(ctx, { kind: "thread", repo, issue }), | |
| 423 | 425 | description: threadLine({ |
| 424 | 426 | private: repo.visibility === "private" || issue.sealed, |
| 425 | 427 | word: wordInfo?.word ?? (issue.state === "open" ? "open" : "closed"), |
test/og-designs.test.ts +3 −3
| @@ -340,14 +340,14 @@ describe("over HTTP", () => { | ||
| 340 | 340 | expect(svg).not.toContain("hidden"); |
| 341 | 341 | }); |
| 342 | 342 | |
| 343 | test("the map page names its card only when the repo is public; the audit page always", async () => { | |
| 343 | test("the map page names its card only when the repo is public; the audit page always; any other page has the site's", async () => { | |
| 344 | 344 | const page = await (await get("/alice/shown/map")).text(); |
| 345 | 345 | expect(page).toContain(`content="${base}/og/map/alice~shown.png"`); |
| 346 | 346 | expect(page).toContain(`content="summary_large_image"`); |
| 347 | 347 | const audit = await (await get("/audit")).text(); |
| 348 | 348 | expect(audit).toContain(`content="${base}/og/audit.png"`); |
| 349 | 349 | const home = await (await get("/")).text(); |
| 350 | expect(home).toContain("/icons/forge-512.png"); | |
| 351 | expect(home).not.toContain("summary_large_image"); | |
| 350 | expect(home).toContain(`content="${base}/og/site.png"`); | |
| 351 | expect(home).toContain(`content="summary_large_image"`); | |
| 352 | 352 | }); |
| 353 | 353 | }); |
test/og-every-page.test.ts added +194
| @@ -0,0 +1,194 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createApp as createForge, type App } from "../src/app.ts"; | |
| 6 | import { createRepo } from "../src/actions/repos.ts"; | |
| 7 | import { createApp } from "../src/core/apps.ts"; | |
| 8 | import { setSealed } from "../src/core/sealed.ts"; | |
| 9 | import { createIssue } from "../src/core/issues.ts"; | |
| 10 | import { getRepo } from "../src/core/repos.ts"; | |
| 11 | import { createRun } from "../src/core/runs.ts"; | |
| 12 | import { createUser } from "../src/core/users.ts"; | |
| 13 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 14 | ||
| 15 | /** Every page a link can be pasted from carries a card, written from its state. */ | |
| 16 | describe("link previews on every page", () => { | |
| 17 | let dataDir: string; | |
| 18 | let app: App; | |
| 19 | let servers: Servers; | |
| 20 | let base: string; | |
| 21 | let runId = ""; | |
| 22 | let sealedRunId = ""; | |
| 23 | let sealedId = ""; | |
| 24 | ||
| 25 | beforeAll(async () => { | |
| 26 | dataDir = await mkdtemp(join(tmpdir(), "forge-og-all-")); | |
| 27 | app = createForge({ dataDir, port: 0 }); | |
| 28 | servers = await serve(app); | |
| 29 | base = servers.url; | |
| 30 | const u = await createUser(app.db, { | |
| 31 | trusted: true, | |
| 32 | username: "alice", | |
| 33 | email: "[email protected]", | |
| 34 | password: "alice-passphrase", | |
| 35 | adminIfFirst: true, | |
| 36 | }); | |
| 37 | if (!u.ok) throw new Error(u.error); | |
| 38 | for (const [name, visibility, description, access] of [ | |
| 39 | ["shown", "public", "A public thing for the cards", "public"], | |
| 40 | ["hidden", "private", "Secret plans nobody may read", "public"], | |
| 41 | ["closed", "public", "A public repository with a private app", "private"], | |
outdated
Every app here is public, so |
||
| 42 | ] as const) { | |
| 43 | const made = await createRepo(app, u.value, { name, visibility, description }); | |
| 44 | if (!made.ok) throw new Error(String(made.error)); | |
| 45 | const rec = createApp(app.db, { repoId: made.value.id, slug: `${name}-app`, access }); | |
| 46 | if (!rec.ok) throw new Error(rec.error); | |
| 47 | } | |
| 48 | const id = (n: string) => getRepo(app.db, "alice", n)!.id; | |
| 49 | const mk = (repo: string, title: string, kind: "issue" | "pull") => { | |
| 50 | const i = createIssue(app.db, { | |
| 51 | repoId: id(repo), | |
| 52 | authorId: u.value.id, | |
| 53 | title, | |
| 54 | kind, | |
| 55 | body: `Body of ${title}`, | |
| 56 | }); | |
| 57 | if (!i.ok) throw new Error(String(i.error)); | |
| 58 | if (kind === "pull") | |
| 59 | app.db | |
| 60 | .query( | |
| 61 | `INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id) | |
| 62 | VALUES (?1, 'main', 'topic', '', '', ?2)`, | |
| 63 | ) | |
| 64 | .run(i.value.id, id(repo)); | |
| 65 | }; | |
| 66 | mk("shown", "Shown issue", "issue"); | |
| 67 | mk("shown", "Shown pull", "pull"); | |
| 68 | mk("hidden", "Hidden issue", "issue"); | |
| 69 | // A sealed report and a run on it, and a private-access app, all on the public repository. | |
| 70 | const sealed = createIssue(app.db, { | |
| 71 | repoId: id("shown"), | |
| 72 | authorId: u.value.id, | |
| 73 | title: "Sealed report", | |
| 74 | kind: "issue", | |
| 75 | body: "Body of the sealed report", | |
| 76 | }); | |
| 77 | if (!sealed.ok) throw new Error(String(sealed.error)); | |
| 78 | sealedId = sealed.value.id; | |
| 79 | setSealed(app.db, sealedId, true); | |
| 80 | sealedRunId = createRun(app.db, { repoId: id("shown"), kind: "agent", summary: "sealed work", issueId: sealedId }).id; | |
| 81 | runId = createRun(app.db, { repoId: id("shown"), kind: "agent", summary: "did a thing" }).id; | |
| 82 | }); | |
| 83 | ||
| 84 | afterAll(async () => { | |
| 85 | await servers.stop(); | |
| 86 | await rm(dataDir, { recursive: true, force: true }); | |
| 87 | }); | |
| 88 | ||
| 89 | const metas = (htmlText: string) => { | |
| 90 | const out = new Map<string, string>(); | |
| 91 | for (const m of htmlText.matchAll(/<meta\s+(?:property|name)="([^"]+)"\s+content="([^"]*)"/g)) | |
| 92 | out.set(m[1]!, m[2]!); | |
| 93 | return out; | |
| 94 | }; | |
| 95 | ||
| 96 | const TOP = [ | |
| 97 | "/", "/explore", "/signin", "/signup", "/audit", "/map", "/apps", "/releases", | |
| 98 | "/search", "/flow", "/system", "/contribute", "/resilience", "/board", "/asks", | |
| 99 | "/asked", "/family", "/new", "/migrate", | |
| 100 | ]; | |
| 101 | const things = () => [ | |
| 102 | "/alice/shown", | |
| 103 | "/alice/shown/issues/1", | |
| 104 | "/alice/shown/pulls/2", | |
| 105 | `/alice/shown/runs/${runId}`, | |
| 106 | "/alice", | |
| 107 | "/alice/shown/app", | |
| 108 | ]; | |
| 109 | ||
| 110 | const carries = async (path: string) => { | |
| 111 | const res = await fetch(base + path, { redirect: "follow" }); | |
| 112 | expect(res.status, path).toBe(200); | |
| 113 | const m = metas(await res.text()); | |
| 114 | expect(m.get("og:title"), path).toBeTruthy(); | |
| 115 | expect(m.get("og:description"), path).toBeTruthy(); | |
| 116 | expect(m.get("twitter:card"), path).toBe("summary_large_image"); | |
| 117 | const image = m.get("og:image"); | |
| 118 | expect(image, path).toBeTruthy(); | |
| 119 | const img = await fetch(image!.replace(/^https?:\/\/[^/]+/, base)); | |
| 120 | expect(img.status, `${path} → ${image}`).toBe(200); | |
| 121 | expect(img.headers.get("content-type"), path).toBe("image/png"); | |
| 122 | return m; | |
| 123 | }; | |
| 124 | ||
| 125 | for (const path of TOP) | |
| 126 | test(`${path} carries a card`, async () => { | |
| 127 | await carries(path); | |
| 128 | }); | |
| 129 | ||
| 130 | test("repo, issue, pull, run, person and app pages carry a card written from their state", async () => { | |
| 131 | const want: Record<string, RegExp> = { | |
| 132 | "/alice/shown": /A public thing for the cards/, | |
| 133 | "/alice/shown/issues/1": /Body of Shown issue|Shown issue/, | |
| 134 | "/alice/shown/pulls/2": /Body of Shown pull|Shown pull/, | |
| 135 | [`/alice/shown/runs/${runId}`]: /did a thing/, | |
| 136 | "/alice": /repositor/i, | |
| 137 | "/alice/shown/app": /not running/, | |
| 138 | }; | |
| 139 | for (const path of things()) { | |
| 140 | const m = await carries(path); | |
| 141 | expect(m.get("og:description")!, path).toMatch(want[path]!); | |
| 142 | expect(m.get("og:image"), path).toContain("/og/"); | |
| 143 | expect(m.get("og:image"), path).not.toContain("icons"); | |
| 144 | } | |
| 145 | }); | |
| 146 | ||
| 147 | test("a private repository, seen anonymously, is the same page as a missing one", async () => { | |
| 148 | const miss = metas(await (await fetch(base + "/alice/nothing")).text()); | |
| 149 | for (const path of ["/alice/hidden", "/alice/hidden/issues/1", "/alice/hidden/runs/x"]) { | |
| 150 | const res = await fetch(base + path); | |
| 151 | expect(res.status, path).toBe(404); | |
| 152 | const m = metas(await res.text()); | |
| 153 | expect([...m.entries()], path).toEqual([...miss.entries()]); | |
| 154 | expect([...m.values()].join("\n"), path).not.toMatch(/Secret plans|Hidden issue|hidden/); | |
| 155 | expect(m.get("twitter:card"), path).toBe("summary_large_image"); | |
| 156 | } | |
| 157 | for (const card of ["/og/repo/alice~hidden", "/og/issue/alice~hidden~1", "/og/app/hidden-app"]) | |
| 158 | for (const ext of ["svg", "png"]) | |
| 159 | expect((await fetch(`${base}${card}.${ext}`)).status, card).toBe(404); | |
| 160 | }); | |
| 161 | ||
| 162 | test("a signed-in reader of a private repository unfurls as 'Private.' with the site card", async () => { | |
| 163 | const signin = await fetch(base + "/signin", { | |
| 164 | method: "POST", | |
| 165 | redirect: "manual", | |
| 166 | headers: { "content-type": "application/x-www-form-urlencoded", origin: base }, | |
| 167 | body: "username=alice&password=alice-passphrase", | |
| 168 | }); | |
| 169 | const cookie = (signin.headers.getSetCookie?.() ?? []).map((c) => c.split(";")[0]).join("; "); | |
| 170 | expect(cookie).toBeTruthy(); | |
| 171 | for (const path of ["/alice/hidden", "/alice/hidden/issues/1"]) { | |
| 172 | const res = await fetch(base + path, { headers: { cookie } }); | |
| 173 | expect(res.status, path).toBe(200); | |
| 174 | const m = metas(await res.text()); | |
| 175 | expect(m.get("og:description"), path).toBe("Private."); | |
| 176 | expect(m.get("og:image"), path).toEndWith("/og/site.png"); | |
| 177 | } | |
| 178 | // Readable here, but not to a signed-out fetcher: the card falls back to the site's. | |
| 179 | const sealedNumber = (app.db.query("SELECT number FROM issue WHERE id = ?1").get(sealedId) as { number: number }).number; | |
| 180 | const hereOnly = [ | |
| 181 | `/alice/shown/issues/${sealedNumber}`, | |
| 182 | `/alice/shown/runs/${sealedRunId}`, | |
| 183 | "/alice/closed/app", | |
| 184 | ]; | |
| 185 | for (const path of hereOnly) { | |
| 186 | const res = await fetch(base + path, { headers: { cookie } }); | |
| 187 | expect(res.status, path).toBe(200); | |
| 188 | expect(metas(await res.text()).get("og:image"), path).toEndWith("/og/site.png"); | |
| 189 | } | |
| 190 | expect((await fetch(`${base}/og/issue/alice~shown~${sealedNumber}.png`)).status).toBe(404); | |
| 191 | expect((await fetch(`${base}/og/run/alice~shown~${sealedRunId}.png`)).status).toBe(404); | |
| 192 | expect((await fetch(`${base}/og/app/closed-app.png`)).status).toBe(404); | |
| 193 | }); | |
| 194 | }); |
test/standards.test.ts +1 −1
| @@ -172,7 +172,7 @@ describe("what the open web expects", () => { | ||
| 172 | 172 | expect(html).toContain( |
| 173 | 173 | 'rel="apple-touch-icon" href="/icons/forge-180.png"', |
| 174 | 174 | ); |
| 175 | expect(html).toContain('name="twitter:card" content="summary"'); | |
| 175 | expect(html).toContain(`name="twitter:card" content="summary_large_image"`); | |
| 176 | 176 | expect(html).toContain("viewport-fit=cover"); |
| 177 | 177 | }); |
| 178 | 178 |
new above
offline
No test covers this branch. Add a sealed issue on a public repository and check that, for a signed-in reader, its page names
/og/site.png, not the issue card that 404s.