Public: anyone can read this; the crew can change it.
A pull opened by a stranger shows its status link on the pull page's head, copyable in one tap #16009
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15988-a-pull-opened-by-a-stranger-shows-its-st → main 0 commits fork 2 threads · 2 unresolved
6 files
changed +102
−3
docs/features/report-status.md +1
| @@ -35,5 +35,6 @@ The answer to a report or an offer (`…/offers`, the MCP `offer` tool) also car | ||
| 35 | 35 | - **Shows:** `kind`, `state` (received, read, planned, landed or declined), its words, and the dates it arrived, last changed and expires. Never the title, the words, a name or an id. |
| 36 | 36 | - **States:** a report is received until a person decides; accepting makes it planned, closing that issue makes it landed (done) or declined (dropped); dismissing declines it. An offer is received, then read once a reviewer reviews, then landed or declined. So a report is never `read` (a person's decision is its first change) and an offer is never `planned`; each shows only the states its own steps can reach. |
| 37 | 37 | - **The token:** 192 random bits, read-only, good 90 days; a wrong, malformed or expired one is a 404 (`src/core/outsider_status.ts`, `src/http/offer_routes.ts`). The status routes answer 429 past 60 reads a minute per client, and links past their day are deleted hourly. Pinned by `test/outsider-status.test.ts`. |
| 38 | - **Where the owner finds an offer's link (#15988):** on that pull's page, one line with Copy, and on the terminal's pull screen as a `status link:` row. Both ask `offerStatusLinkFor` (`src/core/outsider_status.ts`): writers only, because the link is a capability, and only on a pull an offer opened. A pull the owner opened, or a reader or guest looking, shows no such line. Pinned by `test/outsider-status.test.ts` (page) and `test/pull-next-tui.test.ts` (terminal). | |
| 38 | 39 | |
| 39 | 40 | Pinned by `test/report-status.test.ts`. |
src/core/outsider_status.ts +32
| @@ -15,6 +15,8 @@ import type { Database } from "bun:sqlite"; | ||
| 15 | 15 | import { getIssueById } from "./issues.ts"; |
| 16 | 16 | import { getPull } from "./pulls.ts"; |
| 17 | 17 | import { listReviews } from "./reviews.ts"; |
| 18 | import { canWrite, type Repo } from "./repos.ts"; | |
| 19 | import type { User } from "./users.ts"; | |
| 18 | 20 | |
| 19 | 21 | export type OutsiderState = "received" | "read" | "planned" | "landed" | "declined"; |
| 20 | 22 | export type OutsiderKind = "report" | "offer"; |
| @@ -59,6 +61,18 @@ export function issueStatusToken(db: Database, kind: OutsiderKind, refId: string | ||
| 59 | 61 | return token; |
| 60 | 62 | } |
| 61 | 63 | |
| 64 | /** | |
| 65 | * The live token of an offer's pull (its issue id), newest first; undefined when none or past its | |
| 66 | * day. | |
| 67 | */ | |
| 68 | export function offerStatusToken(db: Database, issueId: string, now = Date.now()): string | undefined { | |
| 69 | return db | |
| 70 | .query<{ token: string }, [string, string]>( | |
| 71 | "SELECT token FROM outsider_status WHERE kind = 'offer' AND ref_id = ?1 AND expires_at > ?2 ORDER BY created_at DESC LIMIT 1", | |
| 72 | ) | |
| 73 | .get(issueId, new Date(now).toISOString())?.token; | |
| 74 | } | |
| 75 | ||
| 62 | 76 | /** Drop the links past their day; a dead token already answers 404, so this only frees rows. */ |
| 63 | 77 | export function pruneOutsiderStatus(db: Database, now = Date.now()): number { |
| 64 | 78 | return db.query("DELETE FROM outsider_status WHERE expires_at <= ?1").run(new Date(now).toISOString()).changes; |
| @@ -126,3 +140,21 @@ export const statusLinks = (origin: string, token: string): { page: string; json | ||
| 126 | 140 | page: `${origin}/status/${token}`, |
| 127 | 141 | json: `${origin}/api/v1/status/${token}`, |
| 128 | 142 | }); |
| 143 | ||
| 144 | /** | |
| 145 | * The status page link of an outsider's offer, for a person who may see it (#15988): a writer of | |
| 146 | * the repository, on a pull an offer opened whose link is still live. It is a capability (anyone | |
| 147 | * holding it reads the state), so a reader, a guest and an ordinary pull get undefined. The web | |
| 148 | * page and the terminal's pull screen both ask here, so they cannot drift. | |
| 149 | */ | |
| 150 | export function offerStatusLinkFor( | |
| 151 | db: Database, | |
| 152 | repo: Repo, | |
| 153 | user: User | undefined, | |
| 154 | pullId: string, | |
| 155 | origin: () => string, | |
| 156 | ): string | undefined { | |
| 157 | if (user === undefined || !canWrite(db, repo, user)) return undefined; | |
| 158 | const token = offerStatusToken(db, pullId); | |
| 159 | return token === undefined ? undefined : statusLinks(origin(), token).page; | |
| 160 | } |
src/tui/screens/pull.ts +11 −1
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | import { OFFER_PULL_WORDS, offerPull, previewOfferPull } from "../../actions/offer_pull.ts"; |
| 30 | import { offerStatusLinkFor } from "../../core/outsider_status.ts"; | |
| 30 | 31 | import { outsideClause } from "../../web/outside.ts"; |
| 31 | 32 | import { teamHoldRefusal, waitingOnTeams } from "../../core/teams_words.ts"; |
| 32 | 33 | import { crewFilters, guardedRefusal, isStrangerPull, strangerGuard, strangerNext } from "../../crew/stranger.ts"; |
| @@ -362,6 +363,8 @@ export function pullScreen( | ||
| 362 | 363 | * for anyone else's. |
| 363 | 364 | */ |
| 364 | 365 | let strangerLine = ""; |
| 366 | /** The offer's status link, for a writer only (`offerStatusLinkFor`, #15988); empty otherwise. */ | |
| 367 | let statusLink = ""; | |
| 365 | 368 | /** `h` is a person's key: an agent's hold is refused by the action, so it is not offered. */ |
| 366 | 369 | const mayHold = (): boolean => |
| 367 | 370 | mayWrite() && f.user?.kind === "user" && issueRow !== undefined; |
| @@ -414,6 +417,10 @@ export function pullScreen( | ||
| 414 | 417 | repo !== undefined && row !== undefined && row.state === "open" && row.mergedAt === null && isStrangerPull(f.db, repo, row) |
| 415 | 418 | ? strangerNext(repo, await strangerGuard(f.app, repo, row)) |
| 416 | 419 | : ""; |
| 420 | statusLink = | |
| 421 | repo === undefined || row === undefined | |
| 422 | ? "" | |
| 423 | : (offerStatusLinkFor(f.db, repo, f.user, row.id, () => lookOrigin(f.app.config)) ?? ""); | |
| 417 | 424 | combined = |
| 418 | 425 | repo !== undefined && row !== undefined && facts !== null |
| 419 | 426 | ? await (async () => { |
| @@ -1287,13 +1294,14 @@ export function pullScreen( | ||
| 1287 | 1294 | (checksLine === "" ? 0 : 1) + |
| 1288 | 1295 | (originCheckText === "" ? 0 : 1) + |
| 1289 | 1296 | teams.length; |
| 1290 | const [strip, head, nextRow, previewRow, boxRow, tabRow, body, comp] = split( | |
| 1297 | const [strip, head, nextRow, linkRow, previewRow, boxRow, tabRow, body, comp] = split( | |
| 1291 | 1298 | area, |
| 1292 | 1299 | "v", |
| 1293 | 1300 | [ |
| 1294 | 1301 | len(whereRows(src)), |
| 1295 | 1302 | len(3), |
| 1296 | 1303 | len(strangerLine === "" ? 0 : 1), |
| 1304 | len(statusLink === "" ? 0 : 1), | |
| 1297 | 1305 | len(isApp ? 1 : 0), |
| 1298 | 1306 | len(boxH), |
| 1299 | 1307 | len(2), |
| @@ -1354,6 +1362,8 @@ export function pullScreen( | ||
| 1354 | 1362 | } |
| 1355 | 1363 | if (strangerLine !== "" && nextRow!.h > 0) |
| 1356 | 1364 | s.text(nextRow!.x, nextRow!.y, truncate(`next: ${strangerLine}`, nextRow!.w), style(c.mutedFg, c.bg), nextRow!.x + nextRow!.w); |
| 1365 | if (statusLink !== "" && linkRow!.h > 0) | |
| 1366 | s.text(linkRow!.x, linkRow!.y, truncate(`status link: ${statusLink}`, linkRow!.w), style(c.mutedFg, c.bg), linkRow!.x + linkRow!.w); | |
| 1357 | 1367 | if (isApp && previewRow!.h > 0) |
| 1358 | 1368 | drawPreviewLine(s, previewRow!, c, preview); |
| 1359 | 1369 | drawMergeBox(s, boxRow!, c, issue, facts, view.summary(), mirrored(), { |
src/web/studio/change.ts +14 −1
| @@ -14,6 +14,7 @@ import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; | ||
| 14 | 14 | import { cardPath } from "../og/path.ts"; |
| 15 | 15 | import { pullProposalAt, type PullProposalAt } from "../../core/proposal_token.ts"; |
| 16 | 16 | import { attestationLine } from "../../core/attestation.ts"; |
| 17 | import { offerStatusLinkFor } from "../../core/outsider_status.ts"; | |
| 17 | 18 | import { getIssueById } from "../../core/issues.ts"; |
| 18 | 19 | import { mayEditIssue } from "../../actions/issues.ts"; |
| 19 | 20 | import { outsideLabelFrom } from "../outside.ts"; |
| @@ -56,6 +57,7 @@ import { | ||
| 56 | 57 | card, |
| 57 | 58 | crumbs, |
| 58 | 59 | confirmAction, |
| 60 | copyField, | |
| 59 | 61 | badge, |
| 60 | 62 | icon, |
| 61 | 63 | originTag, |
| @@ -249,6 +251,17 @@ function reviewEntry( | ||
| 249 | 251 | }; |
| 250 | 252 | } |
| 251 | 253 | |
| 254 | /** | |
| 255 | * The status link an outsider was handed for this offer (#15988), as one line with Copy. It is a | |
| 256 | * capability (anyone holding it reads the state), so only a writer sees it, and only on a pull | |
| 257 | * that an outsider's offer opened. | |
| 258 | */ | |
| 259 | function statusLinkLine(ctx: Ctx, repo: Repo, pull: Pull): Html | "" { | |
| 260 | const url = offerStatusLinkFor(ctx.app.db, repo, ctx.auth.user, pull.id, () => ctx.app.config.url ?? ctx.url.origin); | |
| 261 | if (url === undefined) return ""; | |
| 262 | return html`<div class="small" data-status-link>${copyField("status-link", url, "Status link for the person who offered this", "Copy status link")}</div>`; | |
| 263 | } | |
| 264 | ||
| 252 | 265 | /** A change's head, the same on both of its tabs: the title, its state, |
| 253 | 266 | * who opened it and in answer to whom, where it came from, and what the |
| 254 | 267 | * crew spent on it. */ |
| @@ -309,7 +322,7 @@ export function changeHead( | ||
| 309 | 322 | >`, |
| 310 | 323 | )} |
| 311 | 324 | </div> |
| 312 | ${when(step, (st) => pathLine(st, next === null ? undefined : `${next.who}, ${next.why}`))}${when( | |
| 325 | ${statusLinkLine(ctx, repo, pull)}${when(step, (st) => pathLine(st, next === null ? undefined : `${next.who}, ${next.why}`))}${when( | |
| 313 | 326 | pull.mergedAt === null ? pausedSentence(ctx.app.db, { issueId: pull.id }) : undefined, |
| 314 | 327 | (says) => html`<p class="muted small" data-paused role="status">${says}.</p>`, |
| 315 | 328 | )}${when( |
test/outsider-status.test.ts +26 −1
| @@ -8,7 +8,8 @@ import { tmpdir } from "node:os"; | ||
| 8 | 8 | import { join } from "node:path"; |
| 9 | 9 | import { createApp, type App } from "../src/app.ts"; |
| 10 | 10 | import { editFiles } from "../src/actions/contents.ts"; |
| 11 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { openPull } from "../src/actions/pulls.ts"; | |
| 12 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 12 | 13 | import { acceptReport, dismissReport } from "../src/actions/reports.ts"; |
| 13 | 14 | import { setIssueState } from "../src/core/issues.ts"; |
| 14 | 15 | import { pruneOutsiderStatus, STATUS_TTL_MS } from "../src/core/outsider_status.ts"; |
| @@ -16,6 +17,7 @@ import { getRepo } from "../src/core/repos.ts"; | ||
| 16 | 17 | import { submitReview } from "../src/core/reviews.ts"; |
| 17 | 18 | import { createUser, type User } from "../src/core/users.ts"; |
| 18 | 19 | import { serve, type Servers } from "../src/http/server.ts"; |
| 20 | import { signInCookie } from "./helpers/studio-signin.ts"; | |
| 19 | 21 | import { LOOPBACK_PROXIES } from "./helpers/loopback-proxy.ts"; |
| 20 | 22 | |
| 21 | 23 | const PATCH = `diff --git a/hello.txt b/hello.txt |
| @@ -176,4 +178,27 @@ describe("outsider status link", () => { | ||
| 176 | 178 | for (let i = 0; i < 61; i++) last = (await get()).status; |
| 177 | 179 | expect(last).toBe(429); |
| 178 | 180 | }); |
| 181 | ||
| 182 | test("the owner sees an offer's status link on its pull page, with Copy; a reader, a guest and an own pull do not", async () => { | |
| 183 | const a = await offer(); | |
| 184 | const bob = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 185 | if (!bob.ok) throw new Error(bob.error); | |
| 186 | const page = async (cookie: string, number: number) => | |
| 187 | (await fetch(`${servers.url}/alice/game/pulls/${number}`, { headers: cookie === "" ? {} : { cookie } })).text(); | |
| 188 | const owner = await signInCookie(servers.url, "alice"); | |
| 189 | const mine = await page(owner, a.number); | |
| 190 | expect(mine).toContain(a.statusPage); | |
| 191 | expect(mine).toContain('data-copy="status-link"'); | |
| 192 | expect(await page(await signInCookie(servers.url, "bob"), a.number)).not.toContain(tokenOf(a.statusPage)); | |
| 193 | expect(await page("", a.number)).not.toContain(tokenOf(a.statusPage)); | |
outdated
Box 2 is a pull the owner opened, not an offer with its token deleted. Open an ordinary pull as alice and assert it has no data-status-link. Add a test for the terminal screen too. |
||
| 194 | // A pull the owner opened herself has no line. | |
| 195 | const branch = await commitToBranch(app, alice, repo(), { branch: "own", message: "own", files: [{ path: "own.txt", content: "x\n" }] }); | |
| 196 | if (!branch.ok) throw new Error(JSON.stringify(branch.error)); | |
| 197 | const own = await openPull(app, alice, repo(), { title: "Own", baseBranch: "main", headBranch: "own" }); | |
| 198 | if (!own.ok) throw new Error(JSON.stringify(own.error)); | |
| 199 | const ownPage = await page(owner, own.value.number); | |
| 200 | expect(ownPage).toContain("Own"); | |
| 201 | expect(ownPage).not.toContain("data-status-link"); | |
| 202 | expect(app.db.query("SELECT 1 FROM outsider_status WHERE ref_id = ?1").get(own.value.id)).toBeNull(); | |
| 203 | }); | |
| 179 | 204 | }); |
test/pull-next-tui.test.ts +18
| @@ -8,6 +8,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 8 | 8 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; |
| 9 | 9 | import { repoDir } from "../src/git/repos.ts"; |
| 10 | 10 | import { submitReview } from "../src/core/reviews.ts"; |
| 11 | import { issueStatusToken, offerStatusLinkFor } from "../src/core/outsider_status.ts"; | |
| 11 | 12 | import { createUser, type User } from "../src/core/users.ts"; |
| 12 | 13 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 13 | 14 | import { pullScreen } from "../src/tui/screens/pull.ts"; |
| @@ -118,3 +119,20 @@ test("the terminal's pull screen says when an approval was given for a base that | ||
| 118 | 119 | if (!moved.ok) throw new Error(JSON.stringify(moved.error)); |
| 119 | 120 | await screenSaying(topic, "the base moved since the approval"); |
| 120 | 121 | }); |
| 122 | ||
| 123 | test("the terminal's pull screen shows an offer's status link to a writer only, and none on an ordinary pull (#15988)", async () => { | |
| 124 | const topic = await openTopic("lib-link", true); | |
| 125 | const plain = await screenSaying(topic, "Topic"); | |
| 126 | if (plain.includes("status link:")) throw new Error(plain); | |
| 127 | const token = issueStatusToken(app.db, "offer", topic.pull.id); | |
| 128 | const url = offerStatusLinkFor(app.db, topic.repo, alice, topic.pull.id, () => "http://forge.test"); | |
| 129 | if (url !== `http://forge.test/status/${token}`) throw new Error(String(url)); | |
| 130 | const text = await screenSaying(topic, "status link:"); | |
| 131 | if (!text.includes(`/status/${token}`)) throw new Error(text); | |
| 132 | const bob = await createUser(app.db, { | |
| 133 | origin: "seed", trusted: true, username: "bobl", email: "[email protected]", password: "a-good-passphrase", | |
| 134 | }); | |
| 135 | if (!bob.ok) throw new Error(String(bob.error)); | |
| 136 | if (offerStatusLinkFor(app.db, topic.repo, bob.value, topic.pull.id, () => "http://forge.test") !== undefined) throw new Error("a reader got the link"); | |
| 137 | if (offerStatusLinkFor(app.db, topic.repo, undefined, topic.pull.id, () => "http://forge.test") !== undefined) throw new Error("a guest got the link"); | |
| 138 | }); |
new above
offline
Medium: the web page is the only door that shows the link. The terminal's pull screen (src/tui/) must show it too, behind the same writer check, and reach the same data (offerStatusToken). Put the 'writer may see the link' decision in one core function so the page and the terminal cannot drift.