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' #2476
scout/forge:scout/2349-every-forge-page-carries-og-title-og-des → main 4 commits fork
14 files
changed +303
−28
README.md +11 −3
| @@ -1031,9 +1031,17 @@ Two of them carry a figure beside the words: | ||
| 1031 | 1031 | 50%), with the top three findings worst first. Public repositories' apps only, |
| 1032 | 1032 | as `/audit` shows them signed out. |
| 1033 | 1033 | |
| 1034 | The map page (public repositories) and `/audit` name their `.png` as | |
| 1035 | `og:image` with `twitter:card=summary_large_image`; every other page keeps the | |
| 1036 | forge icon. | |
| 1034 | Every page carries `og:title`, `og:description`, an `og:image` that answers | |
| 1035 | 200 `image/png`, and `twitter:card=summary_large_image` | |
| 1036 | (`test/og-every-page.test.ts` walks them). A page names its own card | |
| 1037 | (repository, issue, pull, run, app, map, audit) through `cardLink` in | |
| 1038 | `src/web/og/link.ts`, which applies the card route's own test: only what a | |
| 1039 | signed-out reader may open. Anything else (a private repository, a sealed | |
| 1040 | report, a hidden run log, a private app, the person page and every top-level | |
| 1041 | page) gets the site card, `/og/site.png`. A signed-in reader of a private | |
| 1042 | repository gets the title, `Private.` and the site card. A signed-out reader | |
| 1043 | gets the same 404 and tags as for a repository that does not exist, so a | |
| 1044 | guess never confirms one. | |
| 1037 | 1045 | |
| 1038 | 1046 | ## Develop |
| 1039 | 1047 |
src/http/server.ts +2
| @@ -1164,6 +1164,8 @@ export function buildRouter(): Router<Handler> { | ||
| 1164 | 1164 | router.add("GET", "/og/pull/:ref.svg", ogCard("pull")); |
| 1165 | 1165 | router.add("GET", "/og/run/:ref.svg", ogCard("run")); |
| 1166 | 1166 | router.add("GET", "/og/map/:ref.svg", ogCard("map")); |
| 1167 | router.add("GET", "/og/site.svg", ogCard("site")); | |
| 1168 | router.add("GET", "/og/site.png", ogCard("site", "png")); | |
| 1167 | 1169 | router.add("GET", "/og/audit.svg", ogCard("audit")); |
| 1168 | 1170 | router.add("GET", "/og/repo/:ref.png", ogCard("repo", "png")); |
| 1169 | 1171 | 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 +6 −6
| @@ -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. */ |
| @@ -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() ?? ""; |
| @@ -607,11 +611,7 @@ export function page(options: PageOptions, status = 200): Response { | ||
| 607 | 611 | } |
| 608 | 612 | <meta |
| 609 | 613 | property="og:image" |
| 610 | content="${ctx.url.origin}${ | |
| 611 | options.ogImage !== undefined && options.ogImage.startsWith("/og/") | |
| 612 | ? options.ogImage | |
| 613 | : "/og/site.png" | |
| 614 | }" | |
| 614 | content="${ctx.url.origin}${cardPath(options.ogImage)}" | |
| 615 | 615 | /> |
| 616 | 616 | <meta property="og:image:width" content="1200" /> |
| 617 | 617 | <meta property="og:image:height" content="630" /> |
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` | |
| 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 −9
| @@ -43,6 +43,7 @@ import { isSafeName } from "../../git/guard.ts"; | ||
| 43 | 43 | import type { Ctx } from "../../http/context.ts"; |
| 44 | 44 | import { notFound } from "../../http/respond.ts"; |
| 45 | 45 | import { auditInput, type AuditRow } from "../og/audit.ts"; |
| 46 | import { SITE_LINE } from "../og/link.ts"; | |
| 46 | 47 | import { renderCard, signature, type CardInput } from "../og/card.ts"; |
| 47 | 48 | import { appImages, embedShots, pullImages } from "../og/looks.ts"; |
| 48 | 49 | import { mapInput } from "../og/map.ts"; |
| @@ -147,14 +148,7 @@ function waiting(ctx: Ctx, repo: Repo, issue: Issue): string { | ||
| 147 | 148 | return `waits on ${shown.join(", ")}${more > 0 ? ` +${more}` : ""}`; |
| 148 | 149 | } |
| 149 | 150 | |
| 150 | export type OgKind = "repo" | "app" | "issue" | "pull" | "run" | "map" | "audit" | "site"; | |
| 151 | ||
| 152 | /** The card for any page without a card of its own: it says only what the forge is. */ | |
| 153 | const SITE_CARD: CardInput = { | |
| 154 | kind: "page", | |
| 155 | title: "forge", | |
| 156 | lines: ["Repositories, issues, pulls and the crew that works them."], | |
| 157 | }; | |
| 151 | export type OgKind = "site" | "repo" | "app" | "issue" | "pull" | "run" | "map" | "audit"; | |
| 158 | 152 | |
| 159 | 153 | /** The audit page's own bound. */ |
| 160 | 154 | const AUDIT_LIMIT = 200; |
| @@ -321,6 +315,11 @@ async function auditCardInput(ctx: Ctx): Promise<CardInput> { | ||
| 321 | 315 | return auditInput(rows); |
| 322 | 316 | } |
| 323 | 317 | |
| 318 | /** The card for any page that has none of its own: the forge, in a line. */ | |
| 319 | function siteInput(): CardInput { | |
| 320 | return { kind: "page", title: "forge", lines: [SITE_LINE] }; | |
| 321 | } | |
| 322 | ||
| 324 | 323 | /** |
| 325 | 324 | * A repository's card. The public repo, or one the signed-in viewer may read, |
| 326 | 325 | * gets the full card; any other well-formed ref gets a card of its title and |
| @@ -351,8 +350,8 @@ async function resolve(ctx: Ctx, kind: OgKind, ref: string): Promise<CardInput | | ||
| 351 | 350 | if (kind === "issue" || kind === "pull") return threadInput(ctx, kind, ref); |
| 352 | 351 | if (kind === "run") return runInput(ctx, ref); |
| 353 | 352 | if (kind === "map") return mapCardInput(ctx, ref); |
| 353 | if (kind === "site") return ref === "" ? siteInput() : undefined; | |
| 354 | 354 | if (kind === "audit") return ref === "" ? auditCardInput(ctx) : undefined; |
| 355 | if (kind === "site") return ref === "" ? SITE_CARD : undefined; | |
| 356 | 355 | if (kind === "repo") return repoCard(ctx, ref); |
| 357 | 356 | if (!isSlug(ref)) return undefined; |
| 358 | 357 | const record = getAppBySlug(db, ref); |
src/web/pages/repo.ts +6 −4
| @@ -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,8 +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, | |
| 992 | ogImage: `/og/repo/${repo.ownerName}~${repo.name}.png`, | |
| 993 | description: repoLine({ private: repo.visibility === "private", description: repo.description }), | |
| 994 | ogImage: cardLink(ctx, { kind: "repo", repo }), | |
| 993 | 995 | feed: { |
| 994 | 996 | href: `${repoBase(repo)}/activity.atom`, |
| 995 | 997 | title: `${repo.ownerName}/${repo.name} activity`, |
| @@ -1036,8 +1038,8 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 1036 | 1038 | return page({ |
| 1037 | 1039 | ctx, |
| 1038 | 1040 | title: repo.name, |
| 1039 | description: repo.description, | |
| 1040 | ogImage: `/og/repo/${repo.ownerName}~${repo.name}.png`, | |
| 1041 | description: repoLine({ private: repo.visibility === "private", description: repo.description }), | |
| 1042 | ogImage: cardLink(ctx, { kind: "repo", repo }), | |
| 1041 | 1043 | feed: { |
| 1042 | 1044 | href: `${repoBase(repo)}/activity.atom`, |
| 1043 | 1045 | title: `${repo.ownerName}/${repo.name} activity`, |
src/web/studio/app.ts +2
| @@ -56,6 +56,7 @@ import { appPanels } from "./previews.ts"; | ||
| 56 | 56 | import { noCrewLine, servingHistory, type WordCtx } from "./words.ts"; |
| 57 | 57 | import { crewKeyNote } from "./crew.ts"; |
| 58 | 58 | import { noteAppOpened } from "../../core/next-steps.ts"; |
| 59 | import { cardLink } from "../og/link.ts"; | |
| 59 | 60 | |
| 60 | 61 | /** |
| 61 | 62 | * What asks the viewer in this repository, muted or not: a mute quiets the |
| @@ -492,6 +493,7 @@ export async function studioApp( | ||
| 492 | 493 | return page({ |
| 493 | 494 | ctx, |
| 494 | 495 | title: `${repo.name}`, |
| 496 | ogImage: cardLink(ctx, { kind: "app", repo, record }), | |
| 495 | 497 | description: appLine({ |
| 496 | 498 | private: repo.visibility === "private", |
| 497 | 499 | name: repo.name, |
src/web/studio/change.ts +2 −1
| @@ -87,6 +87,7 @@ import { holdCard } from "./hold.ts"; | ||
| 87 | 87 | import { pullMayRun } from "../../core/pull_trust.ts"; |
| 88 | 88 | import { changeHref } from "./nouns.ts"; |
| 89 | 89 | import { pullWord, servingHistory, wordBadge, type WordCtx } from "./words.ts"; |
| 90 | import { cardLink } from "../og/link.ts"; | |
| 90 | 91 | |
| 91 | 92 | /** The pull and its repo, or the response that refuses to say why not. */ |
| 92 | 93 | export function pullContext(ctx: Ctx): { repo: Repo; pull: Pull } | Response { |
| @@ -623,7 +624,7 @@ async function changeConversation( | ||
| 623 | 624 | return page({ |
| 624 | 625 | ctx, |
| 625 | 626 | title: `${pull.title} · ${repo.name}`, |
| 626 | ogImage: cardPath("pull", repo, pull), | |
| 627 | ogImage: cardLink(ctx, { kind: "thread", repo, issue: pull }), | |
| 627 | 628 | description: threadLine({ |
| 628 | 629 | private: repo.visibility === "private", |
| 629 | 630 | word, |
src/web/studio/run.ts +2
| @@ -35,6 +35,7 @@ import { logBox, runVoice, RUN_TRANSCRIPT_CAP } from "./log.ts"; | ||
| 35 | 35 | import { changeHref, tellHref } from "./nouns.ts"; |
| 36 | 36 | import { unnamedRun, voiceFor, type Actor } from "./voice.ts"; |
| 37 | 37 | import { runWord, servingHistory, wordBadge, type WordCtx } from "./words.ts"; |
| 38 | import { cardLink } from "../og/link.ts"; | |
| 38 | 39 | |
| 39 | 40 | /** |
| 40 | 41 | * The one control a live run has: a person who can write here stops a |
| @@ -319,6 +320,7 @@ export async function runView( | ||
| 319 | 320 | return page({ |
| 320 | 321 | ctx, |
| 321 | 322 | title: `${title} · ${repo.name}`, |
| 323 | ogImage: cardLink(ctx, { kind: "run", repo, runId: run.id }), | |
| 322 | 324 | description: runLine({ |
| 323 | 325 | private: repo.visibility === "private", |
| 324 | 326 | word, |
src/web/studio/tell.ts +2 −1
| @@ -70,6 +70,7 @@ import { | ||
| 70 | 70 | servingHistory, |
| 71 | 71 | type WordCtx, |
| 72 | 72 | } from "./words.ts"; |
| 73 | import { cardLink } from "../og/link.ts"; | |
| 73 | 74 | |
| 74 | 75 | /** The pull whose merge closed this issue, from the event it left behind — |
| 75 | 76 | * the same record `stateEvents` (thread.ts) reads for the timeline's own |
| @@ -421,7 +422,7 @@ async function studioTell( | ||
| 421 | 422 | return page({ |
| 422 | 423 | ctx, |
| 423 | 424 | title: `${issue.title} · ${repo.name}`, |
| 424 | ogImage: cardPath("issue", repo, issue), | |
| 425 | ogImage: cardLink(ctx, { kind: "thread", repo, issue }), | |
| 425 | 426 | description: threadLine({ |
| 426 | 427 | private: repo.visibility === "private" || issue.sealed, |
| 427 | 428 | word: wordInfo?.word ?? (issue.state === "open" ? "open" : "closed"), |
test/og-designs.test.ts +1 −1
| @@ -340,7 +340,7 @@ 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"`); |
test/og-every-page.test.ts added +201
| @@ -0,0 +1,201 @@ | ||
| 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"], | |
| 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/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 | // The repository card names the repository and says "private", the same as for a missing one. | |
| 161 | const hidden = await (await fetch(`${base}/og/repo/alice~hidden.svg`)).text(); | |
| 162 | const absent = await (await fetch(`${base}/og/repo/alice~nothing.svg`)).text(); | |
| 163 | expect(hidden).toContain("alice/hidden"); | |
| 164 | expect(hidden).toContain("private"); | |
| 165 | expect(hidden).not.toMatch(/Secret plans|Hidden issue/); | |
| 166 | expect(hidden.replaceAll("hidden", "nothing")).toBe(absent); | |
| 167 | }); | |
| 168 | ||
| 169 | test("a signed-in reader of a private repository unfurls as 'Private.' with the site card", async () => { | |
| 170 | const signin = await fetch(base + "/signin", { | |
| 171 | method: "POST", | |
| 172 | redirect: "manual", | |
| 173 | headers: { "content-type": "application/x-www-form-urlencoded", origin: base }, | |
| 174 | body: "username=alice&password=alice-passphrase", | |
| 175 | }); | |
| 176 | const cookie = (signin.headers.getSetCookie?.() ?? []).map((c) => c.split(";")[0]).join("; "); | |
| 177 | expect(cookie).toBeTruthy(); | |
| 178 | for (const path of ["/alice/hidden", "/alice/hidden/issues/1"]) { | |
| 179 | const res = await fetch(base + path, { headers: { cookie } }); | |
| 180 | expect(res.status, path).toBe(200); | |
| 181 | const m = metas(await res.text()); | |
| 182 | expect(m.get("og:description"), path).toBe("Private."); | |
| 183 | expect(m.get("og:image"), path).toEndWith("/og/site.png"); | |
| 184 | } | |
| 185 | // Readable here, but not to a signed-out fetcher: the card falls back to the site's. | |
| 186 | const sealedNumber = (app.db.query("SELECT number FROM issue WHERE id = ?1").get(sealedId) as { number: number }).number; | |
| 187 | const hereOnly = [ | |
| 188 | `/alice/shown/issues/${sealedNumber}`, | |
| 189 | `/alice/shown/runs/${sealedRunId}`, | |
| 190 | "/alice/closed/app", | |
| 191 | ]; | |
| 192 | for (const path of hereOnly) { | |
| 193 | const res = await fetch(base + path, { headers: { cookie } }); | |
| 194 | expect(res.status, path).toBe(200); | |
| 195 | expect(metas(await res.text()).get("og:image"), path).toEndWith("/og/site.png"); | |
| 196 | } | |
| 197 | expect((await fetch(`${base}/og/issue/alice~shown~${sealedNumber}.png`)).status).toBe(404); | |
| 198 | expect((await fetch(`${base}/og/run/alice~shown~${sealedRunId}.png`)).status).toBe(404); | |
| 199 | expect((await fetch(`${base}/og/app/closed-app.png`)).status).toBe(404); | |
| 200 | }); | |
| 201 | }); |
test/standards.test.ts +1 −3
| @@ -172,9 +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 | // A repository page carries its own card (/og/repo), not the icon. | |
| 176 | expect(html).toContain(`content="${base}/og/repo/alice~open.png"`); | |
| 177 | expect(html).toContain('name="twitter:card" content="summary_large_image"'); | |
| 175 | expect(html).toContain(`name="twitter:card" content="summary_large_image"`); | |
| 178 | 176 | expect(html).toContain("viewport-fit=cover"); |
| 179 | 177 | }); |
| 180 | 178 |
new above
offline