Public: anyone can read this; the crew can change it.
A backup card for branches whose commits are missing links each branch to its delete, so the repository's owner settles it in one confirmed tap #12618
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12612-a-backup-card-for-branches-whose-commits → main 15 commits fork 4 threads · 4 unresolved
12 files
changed +290
−28
docs/features/backup-refs.md +7 −3
| @@ -7,11 +7,15 @@ and names that branch. The forge's admin then sees one card for each such | ||
| 7 | 7 | repository, on the vitals and the home: |
| 8 | 8 | |
| 9 | 9 | > 1 branch of owner/name cannot be backed up: their commits are missing (name). |
| 10 | > The rest of the repository is in the snapshot. Delete it on its Branches page. | |
| 10 | > The rest of the repository is in the snapshot. Re-push each from a clone that | |
| 11 | > still has its commits, or delete it on the branches page; the repository's | |
| 12 | > owner or a writer can. | |
| 11 | 13 | |
| 12 | 14 | **To clear it:** open the card. It links to the repository's Branches page, |
| 13 | `/owner/name/branches`. A writer there presses *Delete* on the branch the card | |
| 14 | names. Pushing the branch again from a clone that has every object also works. | |
| 15 | `/owner/name/branches`, and each branch it names links to its own row there | |
| 16 | (`#branch-<name>`). The owner or a writer presses *Delete* on that row. Pushing | |
| 17 | the branch again from a clone that has every object also works. A site admin | |
| 18 | writes every repository, so the admin who reads the card can press it too. | |
| 15 | 19 | The card goes away when the next snapshot lands without the branch. |
| 16 | 20 | |
| 17 | 21 | - **The commits stay.** Deleting the branch removes only the ref. The forge |
src/actions/health.ts +14 −1
| @@ -182,6 +182,9 @@ export interface ForgeNeed { | ||
| 182 | 182 | readonly line: string; |
| 183 | 183 | /** Where to look into it. */ |
| 184 | 184 | readonly href: string; |
| 185 | /** The repository it is about, and a link each for what in it to act on (`Degraded`). */ | |
| 186 | readonly repo?: string; | |
| 187 | readonly links?: NonNullable<Degraded["links"]>; | |
| 185 | 188 | } |
| 186 | 189 | |
| 187 | 190 | const HEALTH_HREF = "/api/v1/health"; |
| @@ -205,7 +208,7 @@ export function forgeNeedList(app: App, actor: User | undefined): ForgeNeed[] | | ||
| 205 | 208 | ...(rollout === null ? [] : [{ cause: "rollout", line: rollout, href: HEALTH_HREF }]), |
| 206 | 209 | ...engineNeed(app.config.engine), |
| 207 | 210 | ...h.incidents.map((i) => ({ cause: `incident:${i.key}`, line: `${i.key}: ${i.message}`, href: HEALTH_HREF })), |
| 208 | ...h.degraded.map((d) => ({ cause: d.cause, line: needLine(d), href: d.href })), | |
| 211 | ...h.degraded.map((d): ForgeNeed => ({ cause: d.cause, line: needLine(d), href: d.href, ...(d.repo === undefined || d.links === undefined ? {} : { repo: d.repo, links: d.links }) })), | |
| 209 | 212 | ...flakeForgeNeeds(h.flakes), |
| 210 | 213 | ...(ledger === null ? [] : [{ cause: "ledger", line: ledger, href: HEALTH_HREF }]), |
| 211 | 214 | ]; |
| @@ -247,6 +250,16 @@ export function forgeNeeds(app: App, actor: User | undefined): string[] | undefi | ||
| 247 | 250 | |
| 248 | 251 | export { sinceWords }; |
| 249 | 252 | |
| 253 | /** | |
| 254 | * A need as the terminal's forge strip prints it: a broken branch's card (its sentence names the | |
| 255 | * branches) says where the terminal deletes them, the repository's branch list (`b`), as the page | |
| 256 | * links each to its row (#12612). | |
| 257 | */ | |
| 258 | export function needTermLine(n: ForgeNeed): string { | |
| 259 | if (n.repo === undefined || n.links === undefined || n.links.length === 0) return n.line; | |
| 260 | return `${n.line} In the terminal: open ${n.repo}, press b.`; | |
| 261 | } | |
| 262 | ||
| 250 | 263 | /** A cause as one line: its sentence and when it began (a stuck run's says so already). */ |
| 251 | 264 | export function needLine(d: Degraded, now: number = Date.now()): string { |
| 252 | 265 | return d.cause.startsWith("stuck:") |
src/kernel/vitals.ts +9 −2
| @@ -109,6 +109,12 @@ export interface Degraded { | ||
| 109 | 109 | readonly sentence: string; |
| 110 | 110 | readonly since: string; |
| 111 | 111 | readonly href: string; |
| 112 | /** | |
| 113 | * The repository the card is about, and a link each for what in it to act on (a broken | |
| 114 | * branch's delete). | |
| 115 | */ | |
| 116 | readonly repo?: string; | |
| 117 | readonly links?: readonly { readonly label: string; readonly href: string }[]; | |
| 112 | 118 | } |
| 113 | 119 | |
| 114 | 120 | /** How many finished checks the median is taken over. */ |
| @@ -419,6 +425,7 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 419 | 425 | sentence: string, |
| 420 | 426 | evidence: string | undefined, |
| 421 | 427 | href: string, |
| 428 | about?: { readonly repo: string; readonly links: NonNullable<Degraded["links"]> }, | |
| 422 | 429 | ) => { |
| 423 | 430 | let since = firstSeen.get(cause); |
| 424 | 431 | if (since === undefined || (evidence !== undefined && evidence < since)) { |
| @@ -427,7 +434,7 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 427 | 434 | } |
| 428 | 435 | needs.push(sentence); |
| 429 | 436 | (kind === "broken" ? broken : todo).push(sentence); |
| 430 | degraded.push({ cause, sentence, since, href }); | |
| 437 | degraded.push({ cause, sentence, since, href, ...(about === undefined ? {} : { repo: about.repo, links: about.links }) }); | |
| 431 | 438 | }; |
| 432 | 439 | |
| 433 | 440 | // Free memory under the floor the forge keeps for itself: what it serves with is gone. |
| @@ -647,7 +654,7 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 647 | 654 | if (failing !== undefined) need("todo", "snapshot-failed", failing.sentence, failing.since, "/settings/backups"); |
| 648 | 655 | // What the snapshot that landed could not hold is one card a repository until one holds it. |
| 649 | 656 | for (const left of leftOutNeeds(lastSnapshotOutcome(input.dataDir))) |
| 650 | need("todo", left.cause, left.sentence, left.since, left.href); | |
| 657 | need("todo", left.cause, left.sentence, left.since, left.href, left.links === undefined ? undefined : { repo: left.repo, links: left.links }); | |
| 651 | 658 | |
| 652 | 659 | // The bucket itself, read by this process: late, unreadable, a failed drill, or a check that stopped is one card. |
| 653 | 660 | if (isWatched(input.dataDir)) { |
src/snapshot/outcome.ts +33 −4
| @@ -121,6 +121,33 @@ export function snapshotNeed( | ||
| 121 | 121 | }; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | /** | |
| 125 | * One thing a snapshot left out; a broken branch's card carries a link a branch to where it is | |
| 126 | * deleted. | |
| 127 | */ | |
| 128 | export interface LeftOut { | |
| 129 | readonly cause: string; | |
| 130 | readonly repo: string; | |
| 131 | readonly sentence: string; | |
| 132 | readonly since: string; | |
| 133 | /** Where the card goes: the branches page for broken branches, the repository otherwise. */ | |
| 134 | readonly href: string; | |
| 135 | /** | |
| 136 | * Each broken branch, named, to the branches page where its confirmed delete is. Plain text: | |
| 137 | * the page escapes it. | |
| 138 | */ | |
| 139 | readonly links?: readonly { readonly label: string; readonly href: string }[]; | |
| 140 | } | |
| 141 | ||
| 142 | /** What settles a broken branch, and who may: nothing is deleted for them. */ | |
| 143 | export const SETTLE = | |
| 144 | "Re-push each from a clone that still has its commits, or delete it on the branches page; the repository's owner or a writer can."; | |
| 145 | ||
| 146 | /** The branches page of `owner/name`, each segment encoded for the URL. */ | |
| 147 | export function branchesHref(repo: string): string { | |
| 148 | return `/${repo.split("/").map(encodeURIComponent).join("/")}/branches`; | |
| 149 | } | |
| 150 | ||
| 124 | 151 | /** Branch names shown in one line before "and N more". */ |
| 125 | 152 | const NAMED = 5; |
| 126 | 153 | |
| @@ -130,19 +157,21 @@ const NAMED = 5; | ||
| 130 | 157 | * stands until a snapshot lands without it. `href` is where a person clears it: a broken branch |
| 131 | 158 | * is deleted on the repository's Branches page (docs/features/backup-refs.md). |
| 132 | 159 | */ |
| 133 | export function leftOutNeeds(s: SnapshotOutcome | undefined): { cause: string; repo: string; sentence: string; since: string; href: string }[] { | |
| 160 | export function leftOutNeeds(s: SnapshotOutcome | undefined): LeftOut[] { | |
| 134 | 161 | if (s?.landedAt === undefined) return []; |
| 135 | const out: { cause: string; repo: string; sentence: string; since: string; href: string }[] = []; | |
| 162 | const out: LeftOut[] = []; | |
| 136 | 163 | for (const b of s.brokenRefs ?? []) { |
| 137 | 164 | const names = b.refs.map((r) => r.replace(/^refs\/heads\//, "")); |
| 138 | 165 | const shown = names.slice(0, NAMED).join(", "); |
| 139 | 166 | const more = names.length > NAMED ? `, and ${names.length - NAMED} more` : ""; |
| 167 | const href = branchesHref(b.repo); | |
| 140 | 168 | out.push({ |
| 141 | 169 | cause: `backup-refs:${b.repo}`, |
| 142 | 170 | repo: b.repo, |
| 143 | sentence: `${names.length} ${names.length === 1 ? "branch" : "branches"} of ${b.repo} cannot be backed up: their commits are missing (${shown}${more}). The rest of the repository is in the snapshot. Delete ${names.length === 1 ? "it" : "them"} on its Branches page.`, | |
| 171 | sentence: `${names.length} ${names.length === 1 ? "branch" : "branches"} of ${b.repo} cannot be backed up: their commits are missing (${shown}${more}). The rest of the repository is in the snapshot. ${SETTLE}`, | |
| 144 | 172 | since: s.landedAt, |
| 145 | href: `/${b.repo}/branches`, | |
| 173 | href, | |
| 174 | links: names.map((label) => ({ label, href: `${href}#branch-${encodeURIComponent(label)}` })), | |
| 146 | 175 | }); |
| 147 | 176 | } |
| 148 | 177 | for (const a of s.absent ?? []) |
src/tui/screens/dashboard.ts +2 −2
| @@ -19,7 +19,7 @@ import { exploreCount, exploreFiltered, exploreLine, isExploreLine, exploreNote, | ||
| 19 | 19 | import { protectionNotice } from "../../kernel/protection.ts"; |
| 20 | 20 | import { holdWords, plannerHold } from "../../crew/autonomy.ts"; |
| 21 | 21 | import { governorLine, governorSeen } from "../../crew/governed.ts"; |
| 22 | import { forgeFlakes, forgeLane, forgeNeeds } from "../../actions/health.ts"; | |
| 22 | import { forgeFlakes, forgeLane, forgeNeedList, needTermLine } from "../../actions/health.ts"; | |
| 23 | 23 | import { ownerWaits, waitLine, withMore } from "../../actions/owner_waits.ts"; |
| 24 | 24 | import { forgeHealth } from "../../kernel/guard.ts"; |
| 25 | 25 | import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_verdict.ts"; |
| @@ -473,7 +473,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 473 | 473 | .filter((a) => a.fired) |
| 474 | 474 | .map((a) => a.says) |
| 475 | 475 | : [alarmStuck(f.db, now, { publicOnly: true })].filter((a) => a.fired).map((a) => a.says); |
| 476 | forge = forgeNeeds(f.app, f.user); | |
| 476 | forge = forgeNeedList(f.app, f.user)?.map(needTermLine); | |
| 477 | 477 | if (forge !== undefined) { |
| 478 | 478 | const fh = forgeHealth(); |
| 479 | 479 | const verdict = forgeVerdict(fh, Date.now()); |
src/tui/screens/deleterepo.ts +3 −2
| @@ -42,7 +42,8 @@ export function deleteRepoCommands(f: Session, ctx: Ctx, repo: Repo | undefined) | ||
| 42 | 42 | if (typed !== full) return `Type ${full} to confirm.`; |
| 43 | 43 | // The prompt pops itself once this returns; the repository's |
| 44 | 44 | // own screens unwind after the delete, never to read it again. |
| 45 | return (async () => { | |
| 45 | // Tracked, so the app counts as busy until the unwinding is done. | |
| 46 | return ctx.track((async () => { | |
| 46 | 47 | const done = await deleteRepo(f.app, f.user, repo); |
| 47 | 48 | if (!done.ok) { |
| 48 | 49 | ctx.toast(done.error === "not_found" ? "no such repository" : "could not delete the repository", "danger"); |
| @@ -50,7 +51,7 @@ export function deleteRepoCommands(f: Session, ctx: Ctx, repo: Repo | undefined) | ||
| 50 | 51 | } |
| 51 | 52 | ctx.toast(`deleted ${full}`, "success"); |
| 52 | 53 | ctx.leaveRepo(repo.id); |
| 53 | })(); | |
| 54 | })()); | |
| 54 | 55 | }, |
| 55 | 56 | }), |
| 56 | 57 | ), |
src/web/need_links.ts added +19
| @@ -0,0 +1,19 @@ | ||
| 1 | /** | |
| 2 | * A need's links, as the board and `/asks` print them: a broken branch's card names each branch | |
| 3 | * as a link to its row on its repository's branches page, where the existing confirmed delete is | |
| 4 | * (#12612). Nothing here deletes anything; who may act is said once, in the card's sentence. | |
Box 2: 'who may act is said once' is not enough. The issue also wants it said plainly when the viewer is not the owner or a writer. Render a short clause here, or in the callers, for a viewer who cannot write the repository (the need carries |
||
| 5 | */ | |
| 6 | ||
| 7 | import { html, type Html } from "./html.ts"; | |
| 8 | ||
| 9 | export interface Linked { | |
| 10 | readonly links?: readonly { readonly label: string; readonly href: string }[]; | |
| 11 | } | |
| 12 | ||
| 13 | /** The links after the sentence; null when the need has none. */ | |
| 14 | export function needLinks(d: Linked): Html | null { | |
| 15 | if (d.links === undefined || d.links.length === 0) return null; | |
| 16 | return html` <span data-need-links>${d.links.map( | |
| 17 | (l, i) => html`${i === 0 ? null : ", "}<a href="${l.href}">${l.label}</a>`, | |
| 18 | )}</span>`; | |
| 19 | } |
src/web/pages/board.ts +7 −1
| @@ -30,6 +30,7 @@ import { ASKS_WINDOW_DAYS, askMeasureWeek, asksMeasureEmpty, asksMeasureParts } | ||
| 30 | 30 | import { declinedWaits, reviewWaits } from "../../actions/owner_waits.ts"; |
| 31 | 31 | import { tokenReturns } from "../../core/returns.ts"; |
| 32 | 32 | import { forgeVitals, needLine } from "../../actions/health.ts"; |
| 33 | import { needLinks } from "../need_links.ts"; | |
| 33 | 34 | import { returnsRepos } from "../../actions/returns.ts"; |
| 34 | 35 | import { |
| 35 | 36 | deciderCounts, |
| @@ -453,7 +454,12 @@ function forgeNotes(ctx: Ctx): { notes: Note[]; ok: boolean; placement: Html | n | ||
| 453 | 454 | ...(ok |
| 454 | 455 | ? [] |
| 455 | 456 | : v.degraded.map((d) => |
| 456 | need(`degraded:${d.cause}`, html`<a data-need href="${d.href}">${dot("attn")} ${needLine(d)}</a>`), | |
| 457 | need( | |
| 458 | `degraded:${d.cause}`, | |
| 459 | d.links === undefined | |
| 460 | ? html`<a data-need href="${d.href}">${dot("attn")} ${needLine(d)}</a>` | |
| 461 | : html`<span data-need>${dot("attn")} ${needLine(d)}${needLinks(d)}</span>`, | |
| 462 | ), | |
| 457 | 463 | )), |
| 458 | 464 | ...(lane === null ? [] : [{ key: "lane", need: false, line: html`<span>Lane: ${lane}</span>` }]), |
| 459 | 465 | ...(flaky === null ? [] : [{ key: "flakes", need: false, line: html`<span data-flakes>Flaky this week: ${flaky}</span>` }]), |
src/web/pages/branches.ts +2 −1
| @@ -186,7 +186,8 @@ function branchRow( | ||
| 186 | 186 | const base = scope.base; |
| 187 | 187 | const encoded = encodeURIComponent(row.name); |
| 188 | 188 | const canWrite = scope.caps.write && repo !== undefined; |
| 189 | return html`<li> | |
| 189 | // The id a backup card's link lands on (#12612): `branchesHref` + `-` + the encoded name. | |
| 190 | return html`<li id="branch-${row.name}"> | |
| 190 | 191 | <div class="row branch-row" data-nav tabindex="-1"> |
| 191 | 192 | <span class="row-lead">${icon("branch")}</span> |
| 192 | 193 | <span class="row-main"> |
src/web/studio/asks_page.ts +2 −1
| @@ -30,6 +30,7 @@ import { muteRepo, removeMutes } from "../../core/interactions.ts"; | ||
| 30 | 30 | import { applyAskFilter, isAskFilterDo, type AskFilterChange } from "../../actions/ask_filter.ts"; |
| 31 | 31 | import { askFiltersOf, hasAskFilters, hiddenLine, HIDE_APP_DAY_WORDS, HIDE_KIND_WORDS, isAskKind, SHOW_ALL_WORDS } from "../../core/ask_filters.ts"; |
| 32 | 32 | import type { ForgeNeed } from "../../actions/health.ts"; |
| 33 | import { needLinks } from "../need_links.ts"; | |
| 33 | 34 | import type { Ctx } from "../../http/context.ts"; |
| 34 | 35 | import type { User } from "../../core/users.ts"; |
| 35 | 36 | import { onYouAnswer, onYouRegion } from "./home.ts"; |
| @@ -410,7 +411,7 @@ function rowCard(ctx: Ctx, r: AskRow<Decision>, picked: ReadonlySet<string>): Ht | ||
| 410 | 411 | export const forgeCard = (d: ForgeNeed): Html => |
| 411 | 412 | html`<section class="stack"> |
| 412 | 413 | <h2>The forge</h2> |
| 413 | <p role="alert"><span class="dot" data-tone="danger" aria-hidden="true"></span> <a href="${d.href}">${d.line}</a></p> | |
| 414 | <p role="alert"><span class="dot" data-tone="danger" aria-hidden="true"></span> ${d.links === undefined ? html`<a href="${d.href}">${d.line}</a>` : html`${d.line}${needLinks(d)}`}</p> | |
| 414 | 415 | <div class="bar">${d.cause.startsWith("probe:") ? btn("Remove", { href: d.href, size: "sm", variant: "primary" }) : null}${btn("Health", { href: "/api/v1/health", size: "sm" })}</div> |
| 415 | 416 | </section>`; |
| 416 | 417 |
test/backup-card-pages.test.ts added +139
| @@ -0,0 +1,139 @@ | ||
| 1 | /** | |
| 2 | * A broken branch's backup card on both doors (#12612): the board and `/asks`, read by a site | |
| 3 | * admin who neither owns nor writes the repository, link each branch to its row on the branches | |
| 4 | * page, that row carries the id the link lands on, the sentence says who may act once, and the | |
| 5 | * terminal's forge strip says where its own delete is. A site admin writes every repository | |
| 6 | * (`canWrite`), so the admin who reads the card is never barred from its delete: no line says | |
| 7 | * "not you", and the test pins the premise so a change to it fails here first. | |
| 8 | */ | |
| 9 | ||
| 10 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 11 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 12 | import { tmpdir } from "node:os"; | |
| 13 | import { join } from "node:path"; | |
| 14 | import { createApp, type App } from "../src/app.ts"; | |
| 15 | import { forgeNeedList, needTermLine } from "../src/actions/health.ts"; | |
| 16 | import { deleteBranch } from "../src/actions/branches.ts"; | |
| 17 | import { getRepo } from "../src/core/repos.ts"; | |
| 18 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 19 | import { dashboardScreen } from "../src/tui/screens/dashboard.ts"; | |
| 20 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 21 | import { settleApp } from "./helpers/tui.ts"; | |
| 22 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 23 | import { createSession } from "../src/core/sessions.ts"; | |
| 24 | import { createUser, getUserByName } from "../src/core/users.ts"; | |
| 25 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 26 | import { recordSnapshotOutcome, SETTLE } from "../src/snapshot/outcome.ts"; | |
| 27 | import { html } from "../src/web/html.ts"; | |
| 28 | import { adminCookie } from "./helpers/admin.ts"; | |
| 29 | import { quietLogs } from "./helpers/globals.ts"; | |
| 30 | import { promote } from "./helpers/members.ts"; | |
| 31 | ||
| 32 | quietLogs(); | |
| 33 | ||
| 34 | describe("a broken branch's card, read by a site admin who is not a writer", () => { | |
| 35 | let dataDir = ""; | |
| 36 | let app: App; | |
| 37 | let servers: Servers; | |
| 38 | let admin = ""; | |
| 39 | let owner = ""; | |
| 40 | ||
| 41 | const get = async (cookie: string, path: string): Promise<string> => { | |
| 42 | const response = await fetch(`${servers.url}${path}`, { headers: { cookie }, redirect: "manual" }); | |
| 43 | expect(response.status).toBe(200); | |
| 44 | return (await response.text()).replace(/\s+/g, " "); | |
| 45 | }; | |
| 46 | ||
| 47 | beforeAll(async () => { | |
| 48 | dataDir = await mkdtemp(join(tmpdir(), "forge-backup-card-")); | |
| 49 | app = createApp({ dataDir, port: 0, disk: () => ({ freeBytes: 95, totalBytes: 100 }) }); | |
| 50 | servers = await serve(app); | |
| 51 | admin = `${await adminCookie(app, { username: "keeper", email: "[email protected]", password: "a-long-keeper-passphrase" })}; forge_mode=studio`; | |
| 52 | const made = await createUser(app.db, { | |
| 53 | origin: "seed", | |
| 54 | trusted: true, | |
| 55 | username: "alice", | |
| 56 | email: "[email protected]", | |
| 57 | password: "a-long-alice-passphrase", | |
| 58 | }); | |
| 59 | if (!made.ok) throw new Error(made.error); | |
| 60 | const alice = made.value; | |
| 61 | promote(app.db, alice); | |
| 62 | owner = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 63 | const repo = await createRepo(app, alice, { name: "notes", visibility: "public" }); | |
| 64 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 65 | for (const branch of ["main", "lost"]) { | |
| 66 | const c = await commitToBranch(app, alice, repo.value, { | |
| 67 | branch, | |
| 68 | message: branch, | |
| 69 | files: [{ path: "README.md", content: `# ${branch}\n` }], | |
| 70 | }); | |
| 71 | if (!c.ok) throw new Error(JSON.stringify(c.error)); | |
| 72 | } | |
| 73 | recordSnapshotOutcome(dataDir, { landed: "y", brokenRefs: [{ repo: "alice/notes", refs: ["refs/heads/lost"] }] }); | |
| 74 | }, 30_000); | |
| 75 | ||
| 76 | afterAll(async () => { | |
| 77 | await servers.stop(); | |
| 78 | await rm(dataDir, { recursive: true, force: true }); | |
| 79 | }); | |
| 80 | ||
| 81 | const link = '<a href="/alice/notes/branches#branch-lost">lost</a>'; | |
| 82 | ||
| 83 | test("the board links the branch to its row and says who may act once", async () => { | |
| 84 | const page = await get(admin, "/board"); | |
| 85 | expect(page).toContain(link); | |
| 86 | expect(page.split(String(html`${SETTLE}`)).length - 1).toBe(1); | |
| 87 | expect(page).not.toContain("ask one of them"); | |
| 88 | }); | |
| 89 | ||
| 90 | test("/asks links the branch to its row and says who may act once", async () => { | |
| 91 | const page = await get(admin, "/asks"); | |
| 92 | expect(page).toContain(link); | |
| 93 | expect(page.split(String(html`${SETTLE}`)).length - 1).toBe(1); | |
| 94 | }); | |
| 95 | ||
| 96 | test("the branches page has the row the link lands on", async () => { | |
| 97 | const page = await get(owner, "/alice/notes/branches"); | |
| 98 | expect(page).toContain('<li id="branch-lost">'); | |
| 99 | }); | |
| 100 | ||
| 101 | test("the admin who reads the card gets the branch's Delete on that row: it is theirs", async () => { | |
| 102 | const page = await get(admin, "/alice/notes/branches"); | |
| 103 | expect(page).toContain('aria-label="Delete branch lost"'); | |
| 104 | expect(page).not.toContain("You cannot delete"); | |
| 105 | }); | |
| 106 | ||
| 107 | test("the strip renders on the dashboard with where its delete is", async () => { | |
| 108 | const terminal = headlessTerminal(400, 60); | |
| 109 | const { app: tui, session } = createForgeApp( | |
| 110 | app, | |
| 111 | { sshUsername: "keeper", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: getUserByName(app.db, "keeper")! }, | |
| 112 | { terminal, exitHooks: false }, | |
| 113 | ); | |
| 114 | tui.start(); | |
| 115 | tui.ctx.push(dashboardScreen(session, tui.ctx)); | |
| 116 | await settleApp(tui); | |
| 117 | const text = tui.screen.toText().replace(/\s+/g, " "); | |
| 118 | tui.stop?.(); | |
| 119 | expect(text).toContain("alice/notes cannot be backed up"); | |
| 120 | expect(text).toContain("In the terminal: open alice/notes, press b."); | |
| 121 | }); | |
| 122 | ||
| 123 | test("the terminal's forge strip names where its delete is", () => { | |
| 124 | // Gated as the page is: no strip for someone who is not a site admin. | |
| 125 | expect(forgeNeedList(app, getUserByName(app.db, "alice"))).toBeUndefined(); | |
| 126 | const lines = (forgeNeedList(app, getUserByName(app.db, "keeper")) ?? []).map(needTermLine); | |
| 127 | const card = lines.find((l) => l.includes("alice/notes cannot be backed up")); | |
| 128 | expect(card).toContain(SETTLE); | |
| 129 | expect(card).toEndWith("In the terminal: open alice/notes, press b."); | |
| 130 | expect(lines.filter((l) => l.includes("In the terminal"))).toHaveLength(1); | |
| 131 | }); | |
| 132 | ||
| 133 | // Last: it removes the branch the other tests read. | |
| 134 | test("the delete the card links to accepts that admin", async () => { | |
| 135 | const repo = getRepo(app.db, "alice", "notes")!; | |
| 136 | const done = await deleteBranch(app, getUserByName(app.db, "keeper"), repo, "lost"); | |
| 137 | expect(done.ok).toBe(true); | |
| 138 | }); | |
| 139 | }); |
test/snapshot-repositories.test.ts +53 −11
| @@ -51,7 +51,8 @@ import { | ||
| 51 | 51 | SEAL_SETTING, |
| 52 | 52 | } from "../src/snapshot/destination.ts"; |
| 53 | 53 | import { isOffBox } from "../src/snapshot/off_box.ts"; |
| 54 | import { lastSnapshotOutcome, leftOutNeeds } from "../src/snapshot/outcome.ts"; | |
| 54 | import { branchesHref, lastSnapshotOutcome, leftOutNeeds, recordSnapshotOutcome, SETTLE } from "../src/snapshot/outcome.ts"; | |
| 55 | import { needLinks } from "../src/web/need_links.ts"; | |
| 55 | 56 | import { restoreSnapshot } from "../src/snapshot/restore.ts"; |
| 56 | 57 | import { startSnapshots } from "../src/snapshot/service.ts"; |
| 57 | 58 | import { |
| @@ -244,7 +245,7 @@ describe("a repository with refs whose commits are missing", () => { | ||
| 244 | 245 | ]); |
| 245 | 246 | const lines = leftOutNeeds(kept); |
| 246 | 247 | expect(lines.map((l) => l.sentence)).toEqual([ |
| 247 | "2 branches of alice/notes cannot be backed up: their commits are missing (lost, torn). The rest of the repository is in the snapshot. Delete them on its Branches page.", | |
| 248 | "2 branches of alice/notes cannot be backed up: their commits are missing (lost, torn). The rest of the repository is in the snapshot. Re-push each from a clone that still has its commits, or delete it on the branches page; the repository's owner or a writer can.", | |
| 248 | 249 | ]); |
| 249 | 250 | const card = forgeVitals(app).degraded.filter((d) => |
| 250 | 251 | d.cause.startsWith("backup-refs:"), |
| @@ -275,21 +276,62 @@ describe("a repository with refs whose commits are missing", () => { | ||
| 275 | 276 | ).toContain( |
| 276 | 277 | "7 branches of a/b cannot be backed up: their commits are missing (b0, b1, b2, b3, b4, and 2 more)", |
| 277 | 278 | ); |
| 278 | // One branch is "it". | |
| 279 | expect( | |
| 280 | leftOutNeeds({ | |
| 281 | at: "t", | |
| 282 | landed: "x", | |
| 283 | landedAt: "2026-11-14T08:05:00Z", | |
| 284 | brokenRefs: [{ repo: "a/b", refs: ["refs/heads/lost"] }], | |
| 285 | })[0]!.sentence, | |
| 286 | ).toEndWith("Delete it on its Branches page."); | |
| 279 | // One branch is "1 branch", and it is settled the same way. | |
| 280 | const one = leftOutNeeds({ | |
| 281 | at: "t", | |
| 282 | landed: "x", | |
| 283 | landedAt: "2026-11-14T08:05:00Z", | |
| 284 | brokenRefs: [{ repo: "a/b", refs: ["refs/heads/lost"] }], | |
| 285 | })[0]!.sentence; | |
| 286 | expect(one).toStartWith("1 branch of a/b cannot be backed up"); | |
| 287 | expect(one).toEndWith(SETTLE); | |
| 287 | 288 | expect( |
| 288 | 289 | leftOutNeeds({ at: "t", landed: "x", landedAt: "2026-11-14T08:05:00Z" }), |
| 289 | 290 | ).toEqual([]); |
| 290 | 291 | }); |
| 291 | 292 | }); |
| 292 | 293 | |
| 294 | describe("a broken branch's card links each branch to its delete (#12612)", () => { | |
| 295 | const out = { | |
| 296 | at: "t", | |
| 297 | landed: "x", | |
| 298 | landedAt: "2026-11-14T08:05:00Z", | |
| 299 | brokenRefs: [{ repo: "alice/notes", refs: ["refs/heads/a<b", "refs/heads/x&y\"z"] }], | |
| 300 | }; | |
| 301 | ||
| 302 | test("two broken refs give two links to the branches page, each name encoded in the URL", () => { | |
| 303 | const [card] = leftOutNeeds(out); | |
| 304 | expect(card!.href).toBe("/alice/notes/branches"); | |
| 305 | expect(card!.links).toEqual([ | |
| 306 | { label: "a<b", href: "/alice/notes/branches#branch-a%3Cb" }, | |
| 307 | { label: 'x&y"z', href: "/alice/notes/branches#branch-x%26y%22z" }, | |
| 308 | ]); | |
| 309 | expect(card!.sentence).toContain("Re-push each from a clone that still has its commits, or delete it"); | |
| 310 | expect(card!.sentence).toContain("the repository's owner or a writer can"); | |
| 311 | expect(branchesHref("o w/n?m")).toBe("/o%20w/n%3Fm/branches"); | |
| 312 | }); | |
| 313 | ||
| 314 | test("rendered, the names are escaped, and who may act is not said a second time", () => { | |
| 315 | const [card] = leftOutNeeds(out); | |
| 316 | const can = String(needLinks(card!)); | |
| 317 | expect(can.match(/<a /g)?.length).toBe(2); | |
| 318 | expect(can).toContain('<a href="/alice/notes/branches#branch-a%3Cb">a<b</a>'); | |
| 319 | expect(can).toContain("x&y"z</a>"); | |
| 320 | expect(can).not.toContain("a<b"); | |
| 321 | expect(can).not.toContain("writer"); | |
| 322 | expect(needLinks({ links: [] })).toBeNull(); | |
| 323 | }); | |
| 324 | ||
| 325 | test("the vitals card carries the links and goes to the branches page; nothing is deleted", async () => { | |
| 326 | recordSnapshotOutcome(app.config.dataDir, { landed: "y", brokenRefs: out.brokenRefs }); | |
| 327 | const [card] = forgeVitals(app).degraded.filter((d) => d.cause === "backup-refs:alice/notes"); | |
| 328 | expect(card!.href).toBe("/alice/notes/branches"); | |
| 329 | expect(card!.repo).toBe("alice/notes"); | |
| 330 | expect(card!.links?.map((l) => l.label)).toEqual(["a<b", 'x&y"z']); | |
| 331 | recordSnapshotOutcome(app.config.dataDir, { landed: "z" }); | |
| 332 | }); | |
| 333 | }); | |
| 334 | ||
| 293 | 335 | describe("a repository that cannot be bundled at all", () => { |
| 294 | 336 | test("a bundle that runs out of time is not dropped silently: the manifest names it with the reason, and verify and the admin's line say so", async () => { |
| 295 | 337 | const store = dirStore(fresh("store")); |
new above
offline
Non-blocking: this ctx.track change fixes a flaky delete test and has nothing to do with the backup card. Prefer its own small pull next time.