Public: anyone can read this; the crew can change it.
A public repo, issue and pull page tell an outside agent where to report and offer, in its structured data #16617
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16309-a-public-repo-issue-and-pull-page-tell-a → main 0 commits fork 2 threads · 2 unresolved
3 files
changed +53
−1
src/web/studio/change.ts +2
| @@ -52,6 +52,7 @@ import { html, raw, when, type Html } from "../html.ts"; | ||
| 52 | 52 | import type { IconName as Glyph } from "../icons.ts"; |
| 53 | 53 | import { threadLine } from "../describe.ts"; |
| 54 | 54 | import { fragment, page, redirect } from "../layout.ts"; |
| 55 | import { publicRepoLd } from "../structured_data.ts"; | |
| 55 | 56 | import { renderMarkdown } from "../markdown.ts"; |
| 56 | 57 | import { liveClientJs, liveMount } from "../live.ts"; |
| 57 | 58 | import { |
| @@ -906,6 +907,7 @@ async function changeConversation( | ||
| 906 | 907 | title: `${pull.title} · ${repo.name}`, |
| 907 | 908 | ogImage: cardPath("pull", repo, pull), |
| 908 | 909 | about: `${repo.ownerName}/${repo.name}#${pull.number}`, |
| 910 | ...publicRepoLd(ctx, repo), | |
| 909 | 911 | description: threadLine({ |
| 910 | 912 | private: repo.visibility === "private", |
| 911 | 913 | word, |
src/web/studio/tell.ts +3
| @@ -58,6 +58,7 @@ import { estimateLine } from "../../flow/estimate_words.ts"; | ||
| 58 | 58 | import { noteLine } from "./note.ts"; |
| 59 | 59 | import { threadLine } from "../describe.ts"; |
| 60 | 60 | import { page } from "../layout.ts"; |
| 61 | import { publicRepoLd } from "../structured_data.ts"; | |
| 61 | 62 | import { liveClientJs, liveMount } from "../live.ts"; |
| 62 | 63 | import { |
| 63 | 64 | avatar, |
| @@ -669,6 +670,8 @@ async function studioTell( | ||
| 669 | 670 | title: `${issue.title} · ${repo.name}`, |
| 670 | 671 | ogImage: cardPath("issue", repo, issue), |
| 671 | 672 | about: `${repo.ownerName}/${repo.name}#${issue.number}`, |
| 673 | // A sealed issue says nothing of the repository beyond itself. | |
| 674 | ...(issue.sealed ? {} : publicRepoLd(ctx, repo)), | |
| 672 | 675 | description: threadLine({ |
| 673 | 676 | private: repo.visibility === "private" || issue.sealed, |
| 674 | 677 | word: wordInfo?.word ?? (issue.state === "open" ? "open" : "closed"), |
test/public-head.test.ts +48 −1
| @@ -7,7 +7,8 @@ import { createRepo } from "../src/actions/repos.ts"; | ||
| 7 | 7 | import { getRepo } from "../src/core/repos.ts"; |
| 8 | 8 | import { createIssue } from "../src/core/issues.ts"; |
| 9 | 9 | import { createApp as createAppRecord } from "../src/core/apps.ts"; |
| 10 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { createUser, type User } from "../src/core/users.ts"; | |
| 11 | import { createSession } from "../src/core/sessions.ts"; | |
| 11 | 12 | import { catalog } from "../src/packs/catalog.ts"; |
| 12 | 13 | import { seedPacks } from "./helpers/packs.ts"; |
| 13 | 14 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -134,6 +135,7 @@ describe("every public page names itself", () => { | ||
| 134 | 135 | let servers: Servers; |
| 135 | 136 | let base: string; |
| 136 | 137 | let pages: string[] = []; |
| 138 | let alice: User; | |
| 137 | 139 | |
| 138 | 140 | beforeAll(async () => { |
| 139 | 141 | dataDir = await mkdtemp(join(tmpdir(), "forge-publichead-")); |
| @@ -149,6 +151,7 @@ describe("every public page names itself", () => { | ||
| 149 | 151 | adminIfFirst: true, |
| 150 | 152 | }); |
| 151 | 153 | if (!u.ok) throw new Error(u.error); |
| 154 | alice = u.value; | |
| 152 | 155 | for (const name of ["shown", "widget"]) { |
| 153 | 156 | const made = await createRepo(app, u.value, { name, visibility: "public" }); |
| 154 | 157 | if (!made.ok) throw new Error(String(made.error)); |
| @@ -165,6 +168,21 @@ describe("every public page names itself", () => { | ||
| 165 | 168 | ) |
| 166 | 169 | .run(i.value.id, shown); |
| 167 | 170 | } |
| 171 | // A sealed issue on the public repository: number 3, after the issue and the pull. | |
| 172 | const sealed = createIssue(app.db, { repoId: shown, authorId: u.value.id, title: "A hole", kind: "issue", sealed: true }); | |
| 173 | if (!sealed.ok) throw new Error(String(sealed.error)); | |
| 174 | // A private repository with an issue (1) and a pull (2). | |
| 175 | const hiddenMade = await createRepo(app, u.value, { name: "hidden", visibility: "private" }); | |
| 176 | if (!hiddenMade.ok) throw new Error(String(hiddenMade.error)); | |
| 177 | const hidden = getRepo(app.db, "alice", "hidden")!.id; | |
| 178 | for (const kind of ["issue", "pull"] as const) { | |
| 179 | const i = createIssue(app.db, { repoId: hidden, authorId: u.value.id, title: `A private ${kind}`, kind }); | |
| 180 | if (!i.ok) throw new Error(String(i.error)); | |
| 181 | if (kind === "pull") | |
| 182 | app.db | |
| 183 | .query(`INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id) VALUES (?1, 'main', 'topic', '', '', ?2)`) | |
| 184 | .run(i.value.id, hidden); | |
| 185 | } | |
| 168 | 186 | const rec = createAppRecord(app.db, { repoId: getRepo(app.db, "alice", "widget")!.id, slug: "widget", access: "public" }); |
| 169 | 187 | if (!rec.ok) throw new Error(rec.error); |
| 170 | 188 | await seedPacks(app); |
| @@ -193,6 +211,35 @@ describe("every public page names itself", () => { | ||
| 193 | 211 | await rm(dataDir, { recursive: true, force: true }); |
| 194 | 212 | }); |
| 195 | 213 | |
| 214 | test("a public repo, issue and pull page name the report and offer doors in JSON-LD; script text cannot close", async () => { | |
| 215 | const origin = new URL(base).origin; | |
| 216 | const doors = (docs: Record<string, unknown>[]) => | |
| 217 | docs.filter((d) => d["@type"] === "SoftwareSourceCode").flatMap((d) => (d["potentialAction"] as { target: string }[]).map((a) => a.target)); | |
| 218 | for (const path of ["/alice/shown", "/alice/shown/issues/1", "/alice/shown/pulls/2"]) { | |
| 219 | const html = await (await fetch(base + path)).text(); | |
| 220 | const targets = doors(jsonLd(html)); | |
| 221 | expect(targets, path).toContain(`${origin}/alice/shown/report`); | |
| 222 | expect(targets, path).toContain(`${origin}/api/v1/repos/alice/shown/reports`); | |
| 223 | for (const block of html.match(/<script type="application\/ld\+json">[\s\S]*?<\/script>/g) ?? []) | |
| 224 | expect(block.slice(1, -9).includes("</"), path).toBe(false); | |
| 225 | } | |
| 226 | }); | |
| 227 | ||
| 228 | test("a private repository's issue and pull pages, and a sealed issue, name no door", async () => { | |
| 229 | const cookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 230 | const sourceCode = (html: string) => jsonLd(html).filter((d) => d["@type"] === "SoftwareSourceCode"); | |
| 231 | // Control: the owner sees an ordinary issue on the public repository, with its doors. | |
| 232 | const ordinary = await fetch(`${base}/alice/shown/issues/1`, { headers: { cookie } }); | |
| 233 | expect(ordinary.status).toBe(200); | |
| 234 | expect(sourceCode(await ordinary.text())).toHaveLength(1); | |
| 235 | for (const path of ["/alice/hidden/issues/1", "/alice/hidden/pulls/2", "/alice/shown/issues/3"]) { | |
| 236 | const res = await fetch(base + path, { headers: { cookie } }); | |
| 237 | expect(res.status, path).toBe(200); // the owner reads it, so the guard is what is tested | |
| 238 | const html = await res.text(); | |
| 239 | expect(sourceCode(html), path).toEqual([]); | |
| 240 | } | |
| 241 | }); | |
| 242 | ||
| 196 | 243 | test("the head checker names what is missing", () => { |
| 197 | 244 | const bad = `<html><head><title> </title><link rel="canonical" href="https://elsewhere.test/x"></head></html>`; |
| 198 | 245 | const found = headProblems(bad, "http://forge.test"); |
new above
offline
The sealed branch is new behaviour with no test. Add one that fails when this guard is removed: a sealed issue on a public repo carries no SoftwareSourceCode block.