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

A fork's repository page shows its ancestors as a breadcrumb, each a link #16649

Merged opened this

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

Merged

torque/forge:torque/16167-a-fork-s-repository-page-shows-its-ances → main 0 commits fork 2 threads · 2 unresolved

  • Merged. torque/16167-a-fork-s-repository-page-shows-its-ances was merged into main as 1d301c3.

Review

Sign in to review this change.
3 files changed +63 −2
docs/features/fork-breadcrumb.md +4 −2
@@ -1,13 +1,15 @@
11 ---
22 topic: Your apps
3 row: A fork's whole chain of ancestors, root first, in the terminal
3 row: A fork's whole chain of ancestors, root first, on the repository page and in the terminal
44 ---
55 # Fork breadcrumb
66
77 A fork two or more levels down shows where it came from without opening each parent: `a → b → c`, root first, the fork itself last (#14537).
88
9 **On the repository page.** Above the "forked from" line, the same chain as links: each ancestor you may read is a link to its page, one you may not read is "a private forge", and the fork itself is last, plain. A screen reader hears "then" between names. A repository with no upstream, or a one-level fork, draws nothing and reads no chain.
10
911 **In the terminal.** Open the repository, then its forks screen: the first row is the chain, `ann/app → a private forge → cy/app`. Each ancestor you may read is named. One you may not read is "a private forge", never named. A repository with no upstream shows no chain, and a severed fork stops at the cut. A one-level fork shows no chain: its "forked from" line already says it.
1012
1113 **Long chains.** The root and the nearest three ancestors show; the middle reads `… N more`. Only those are checked for readability.
1214
13 The chain is `ancestry` in `src/core/fork_ancestry.ts`: one gate (`canRead`) and one wording, which the repository page's breadcrumb will read too. Tests: `test/fork-breadcrumb.test.ts`.
15 The chain is `ancestry` in `src/core/fork_ancestry.ts`: one gate (`canRead`) and one wording, which the repository page's breadcrumb (`ancestryCrumb` in `src/web/chrome.ts`) reads too. Tests: `test/fork-breadcrumb.test.ts`.
src/web/chrome.ts +23
@@ -12,6 +12,7 @@ import { togetherHtml } from "./together.ts";
1212 import { repoOnRequest } from "../http/request_repo.ts";
1313 import { hereAddress, returnTo, safeNext, withReturn } from "./return_to.ts";
1414 import { MACHINE_PREFIX, typedMiss } from "../http/asset_miss.ts";
15 import { ancestry, PRIVATE_FORGE } from "../core/fork_ancestry.ts";
1516 import { audienceFacts, audienceOf } from "../core/audience.ts";
1617 import { activeEdgeToken, edgeLoginUrl, edgeStrangerLogin } from "../http/edge.ts";
1718 import {
@@ -368,6 +369,7 @@ export function scopeHeader(
368369 !options.compact && facts.description !== "",
369370 () => html`<p class="muted small">${facts.description}</p>`,
370371 )}
372 ${repo === undefined ? null : ancestryCrumb(ctx, repo)}
outdated

Two repo === undefined checks on one line, with no break between the crumb and the lineage line, are hard to read. Split them into two lines, or have ancestryCrumb take an optional repo.

371373 ${repo === undefined ? null : lineageLine(ctx.app, repo, parent, family, parent !== undefined && canAdmin(ctx.app.db, repo, ctx.auth.user) ? `${base}/settings#follow-choice` : undefined)}
372374 ${repo === undefined ? null : sourceLine(repo)}
373375 ${when(
@@ -395,6 +397,27 @@ function familyOf(ctx: Ctx, repo: Repo, parent: Repo): Family {
395397 return { siblings, mine: ownsInTree(ctx.app, parent, viewer?.id, (r) => canRead(db, r, viewer)) };
396398 }
397399
400 /**
401 * "a → b → c" from the root down for a fork two or more levels deep (#16167): each readable
402 * ancestor a link, one the viewer cannot read "a private forge". Escaped by `html`. A repository
403 * with no upstream, or one level, draws nothing and reads no chain.
404 */
405 function ancestryCrumb(ctx: Ctx, repo: Repo): Html | null {
406 if (repo.forkParentId === null) return null;
407 const parts = ancestry(ctx.app.db, repo, ctx.auth.user);
408 if (parts === null) return null;
409 const sep = html` <span aria-hidden="true">→</span><span class="sr-only"> then </span> `;
410 const cells = parts.map((p) =>
411 p.kind === "repo"
412 ? html`<a href="${p.href}">${p.name}</a>`
413 : p.kind === "private"
414 ? html`${PRIVATE_FORGE}`
415 : html`… ${p.hidden} more`,
416 );
417 cells.push(html`${repo.ownerName}/${repo.name}`);
outdated

Principle 7 (rows over boxes) and accessibility: a chain as bare inline text with aria-hidden arrows reads as one run of names to a screen reader. An ol of links inside the nav fixes that, and keeps the same muted look.

418 return html`<nav class="muted small break" aria-label="Ancestors" data-ancestry>${cells.map((c, i) => (i === 0 ? c : html`${sep}${c}`))}</nav>`;
419 }
420
398421 /**
399422 * What the lineage line says of the family: the other forks of the parent, and a way to the
400423 * viewer's own.
test/fork-breadcrumb.test.ts +36
@@ -114,3 +114,39 @@ describe("fork ancestry", () => {
114114 expect(forkAncestors(app.db, fresh)).toEqual([]);
115115 });
116116 });
117
118 describe("the repository page header", () => {
119 test("draws the chain, escapes a name with markup, and nothing for a root", async () => {
120 const { serve } = await import("../src/http/server.ts");
121 const servers = await serve(app);
122 try {
123 const root = must(await createRepo(app, u["ann"]!, { name: "pg", visibility: "public" }));
124 must(await commitToBranch(app, u["ann"]!, root, { message: "x", files: [{ path: "x.txt", content: "x\n" }] }));
125 const mid = must(await forkRepo(app, u["ben"]!, root, undefined, { visibility: "public" }));
126 const tip = must(await forkRepo(app, u["cy"]!, mid, undefined, { visibility: "public" }));
127 const get = async (r: Repo) => (await fetch(`${servers.url}/${r.ownerName}/${r.name}`)).text();
128 let h = await get(tip);
129 expect(h).toContain('data-ancestry');
130 expect(h).toContain('<a href="/ann/pg">ann/pg</a>');
131 expect(h).toContain('<a href="/ben/pg">ben/pg</a>');
132 expect(await get(root)).not.toContain("data-ancestry");
133 // Hostile name: the db is written directly, past the name validator.
134 app.db.query("UPDATE repo SET name = ?1 WHERE id = ?2").run("<b>x</b>", root.id);
135 h = await get(tip);
136 expect(h).toContain("&lt;b&gt;x&lt;/b&gt;");
137 expect(h).not.toContain("<b>x</b>");
138 must(await updateRepoSettings(app, u["ben"]!, mid, { visibility: "private" }));
139 h = await get(tip);
140 expect(h).toContain(PRIVATE_FORGE);
141 // Five deep: the root, the gap, the nearest three.
142 let deep = tip;
143 for (const [i, n] of ["ann", "ben", "cy", "zed"].entries()) {
144 deep = must(await forkRepo(app, u[n]!, deep, `g${i}`, { visibility: "public" }));
145 }
146 h = await get(deep);
147 expect(h).toMatch(/… \d+ more/);
148 } finally {
149 servers.stop?.();
150 }
151 }, 60_000);
152 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs