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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/16309-a-public-repo-issue-and-pull-page-tell-a → main 0 commits fork 2 threads · 2 unresolved

  • Merged. scout/16309-a-public-repo-issue-and-pull-page-tell-a was merged into main as 3256dd5.

Review

Sign in to review this change.
3 files changed +53 −1
src/web/studio/change.ts +2
@@ -52,6 +52,7 @@ import { html, raw, when, type Html } from "../html.ts";
5252 import type { IconName as Glyph } from "../icons.ts";
5353 import { threadLine } from "../describe.ts";
5454 import { fragment, page, redirect } from "../layout.ts";
55 import { publicRepoLd } from "../structured_data.ts";
5556 import { renderMarkdown } from "../markdown.ts";
5657 import { liveClientJs, liveMount } from "../live.ts";
5758 import {
@@ -906,6 +907,7 @@ async function changeConversation(
906907 title: `${pull.title} · ${repo.name}`,
907908 ogImage: cardPath("pull", repo, pull),
908909 about: `${repo.ownerName}/${repo.name}#${pull.number}`,
910 ...publicRepoLd(ctx, repo),
909911 description: threadLine({
910912 private: repo.visibility === "private",
911913 word,
src/web/studio/tell.ts +3
@@ -58,6 +58,7 @@ import { estimateLine } from "../../flow/estimate_words.ts";
5858 import { noteLine } from "./note.ts";
5959 import { threadLine } from "../describe.ts";
6060 import { page } from "../layout.ts";
61 import { publicRepoLd } from "../structured_data.ts";
6162 import { liveClientJs, liveMount } from "../live.ts";
6263 import {
6364 avatar,
@@ -669,6 +670,8 @@ async function studioTell(
669670 title: `${issue.title} · ${repo.name}`,
670671 ogImage: cardPath("issue", repo, issue),
671672 about: `${repo.ownerName}/${repo.name}#${issue.number}`,
673 // A sealed issue says nothing of the repository beyond itself.
674 ...(issue.sealed ? {} : publicRepoLd(ctx, repo)),

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.

672675 description: threadLine({
673676 private: repo.visibility === "private" || issue.sealed,
674677 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";
77 import { getRepo } from "../src/core/repos.ts";
88 import { createIssue } from "../src/core/issues.ts";
99 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";
1112 import { catalog } from "../src/packs/catalog.ts";
1213 import { seedPacks } from "./helpers/packs.ts";
1314 import { serve, type Servers } from "../src/http/server.ts";
@@ -134,6 +135,7 @@ describe("every public page names itself", () => {
134135 let servers: Servers;
135136 let base: string;
136137 let pages: string[] = [];
138 let alice: User;
137139
138140 beforeAll(async () => {
139141 dataDir = await mkdtemp(join(tmpdir(), "forge-publichead-"));
@@ -149,6 +151,7 @@ describe("every public page names itself", () => {
149151 adminIfFirst: true,
150152 });
151153 if (!u.ok) throw new Error(u.error);
154 alice = u.value;
152155 for (const name of ["shown", "widget"]) {
153156 const made = await createRepo(app, u.value, { name, visibility: "public" });
154157 if (!made.ok) throw new Error(String(made.error));
@@ -165,6 +168,21 @@ describe("every public page names itself", () => {
165168 )
166169 .run(i.value.id, shown);
167170 }
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 }
168186 const rec = createAppRecord(app.db, { repoId: getRepo(app.db, "alice", "widget")!.id, slug: "widget", access: "public" });
169187 if (!rec.ok) throw new Error(rec.error);
170188 await seedPacks(app);
@@ -193,6 +211,35 @@ describe("every public page names itself", () => {
193211 await rm(dataDir, { recursive: true, force: true });
194212 });
195213
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
196243 test("the head checker names what is missing", () => {
197244 const bad = `<html><head><title> </title><link rel="canonical" href="https://elsewhere.test/x"></head></html>`;
198245 const found = headProblems(bad, "http://forge.test");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs