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
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/16167-a-fork-s-repository-page-shows-its-ances → main 0 commits fork 2 threads · 2 unresolved
3 files
changed +63
−2
docs/features/fork-breadcrumb.md +4 −2
| @@ -1,13 +1,15 @@ | ||
| 1 | 1 | --- |
| 2 | 2 | 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 | |
| 4 | 4 | --- |
| 5 | 5 | # Fork breadcrumb |
| 6 | 6 | |
| 7 | 7 | 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). |
| 8 | 8 | |
| 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 | ||
| 9 | 11 | **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. |
| 10 | 12 | |
| 11 | 13 | **Long chains.** The root and the nearest three ancestors show; the middle reads `… N more`. Only those are checked for readability. |
| 12 | 14 | |
| 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"; | ||
| 12 | 12 | import { repoOnRequest } from "../http/request_repo.ts"; |
| 13 | 13 | import { hereAddress, returnTo, safeNext, withReturn } from "./return_to.ts"; |
| 14 | 14 | import { MACHINE_PREFIX, typedMiss } from "../http/asset_miss.ts"; |
| 15 | import { ancestry, PRIVATE_FORGE } from "../core/fork_ancestry.ts"; | |
| 15 | 16 | import { audienceFacts, audienceOf } from "../core/audience.ts"; |
| 16 | 17 | import { activeEdgeToken, edgeLoginUrl, edgeStrangerLogin } from "../http/edge.ts"; |
| 17 | 18 | import { |
| @@ -368,6 +369,7 @@ export function scopeHeader( | ||
| 368 | 369 | !options.compact && facts.description !== "", |
| 369 | 370 | () => html`<p class="muted small">${facts.description}</p>`, |
| 370 | 371 | )} |
| 372 | ${repo === undefined ? null : ancestryCrumb(ctx, repo)} | |
| 371 | 373 | ${repo === undefined ? null : lineageLine(ctx.app, repo, parent, family, parent !== undefined && canAdmin(ctx.app.db, repo, ctx.auth.user) ? `${base}/settings#follow-choice` : undefined)} |
| 372 | 374 | ${repo === undefined ? null : sourceLine(repo)} |
| 373 | 375 | ${when( |
| @@ -395,6 +397,27 @@ function familyOf(ctx: Ctx, repo: Repo, parent: Repo): Family { | ||
| 395 | 397 | return { siblings, mine: ownsInTree(ctx.app, parent, viewer?.id, (r) => canRead(db, r, viewer)) }; |
| 396 | 398 | } |
| 397 | 399 | |
| 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}`); | |
| 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 | ||
| 398 | 421 | /** |
| 399 | 422 | * What the lineage line says of the family: the other forks of the parent, and a way to the |
| 400 | 423 | * viewer's own. |
test/fork-breadcrumb.test.ts +36
| @@ -114,3 +114,39 @@ describe("fork ancestry", () => { | ||
| 114 | 114 | expect(forkAncestors(app.db, fresh)).toEqual([]); |
| 115 | 115 | }); |
| 116 | 116 | }); |
| 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("<b>x</b>"); | |
| 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 | }); |
new above
offline
Two
repo === undefinedchecks on one line, with no break between the crumb and the lineage line, are hard to read. Split them into two lines, or haveancestryCrumbtake an optional repo.