Public: anyone can read this; the crew can change it.
An outsider's report on a public app answers with a receipt: the issue number as a link and one sentence on what happens next #14132
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14127-an-outsider-s-report-on-a-public-app-ans → main 4 commits fork 2 threads · 2 unresolved
3 files
changed +38
−4
src/web/pages/reports.ts +5 −1
| @@ -12,6 +12,7 @@ import { | ||
| 12 | 12 | waitingReports, |
| 13 | 13 | } from "../../actions/reports.ts"; |
| 14 | 14 | import { |
| 15 | REPORT_RECEIVED, | |
| 15 | 16 | REPORT_WHERE_REPLY, |
| 16 | 17 | REPORT_WHO_READS, |
| 17 | 18 | reportTooFast, |
| @@ -193,6 +194,9 @@ function reportBody(ctx: Ctx, repo: Repo): Response { | ||
| 193 | 194 | <section class="settings-block"> |
| 194 | 195 | <h1>Report sent</h1> |
| 195 | 196 | <dl class="status-rows"> |
| 197 | ${standing !== null && standing !== undefined | |
| 198 | ? html`<div class="status-row"><dt>Receipt</dt><dd id="report-receipt"><a href="${base}/report?sent=${sentId.slice(0, 64)}">${sentId.slice(0, 64)}</a></dd></div>` | |
| 199 | : ""} | |
| 196 | 200 | ${standing?.title !== undefined |
| 197 | 201 | ? html`<div class="status-row"><dt>Title</dt><dd id="report-title">${standing.title}</dd></div>` |
| 198 | 202 | : ""} |
| @@ -202,7 +206,7 @@ function reportBody(ctx: Ctx, repo: Repo): Response { | ||
| 202 | 206 | <a href="${base}/issues/${standing.issue}">an issue</a> from it.` |
| 203 | 207 | : standing?.state === "dismissed" |
| 204 | 208 | ? "A person read it and closed it without an issue." |
| 205 | : "Not read yet. Keep this link and look again." | |
| 209 | : REPORT_RECEIVED | |
| 206 | 210 | }</dd></div> |
| 207 | 211 | ${standing?.state === "pending" |
| 208 | 212 | ? html`<div class="status-row"><dt>Answer</dt><dd id="report-due">${ |
test/report-receipt.test.ts +32 −2
| @@ -4,7 +4,7 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | import { join } from "node:path"; |
| 6 | 6 | import { createRepo } from "../src/actions/repos.ts"; |
| 7 | import { REPORT_NEXT_STEP } from "../src/actions/report_words.ts"; | |
| 7 | import { REPORT_NEXT_STEP, REPORT_RECEIVED } from "../src/actions/report_words.ts"; | |
| 8 | 8 | import { createApp, type App } from "../src/app.ts"; |
| 9 | 9 | import { createUser } from "../src/core/users.ts"; |
| 10 | 10 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -83,7 +83,7 @@ describe("a report's receipt", () => { | ||
| 83 | 83 | const page = await (await fetch(r.url)).text(); |
| 84 | 84 | expect(page).toContain("Broken <b>link</b>"); |
| 85 | 85 | expect(page).not.toContain("<b>link</b>"); |
| 86 | expect(page).toContain("Not read yet"); | |
| 86 | expect(page).toContain("Received."); | |
| 87 | 87 | const closed = await fetch(`${base}/alice/shut/report?sent=${r.id}`); |
| 88 | 88 | expect(closed.status).toBe(404); |
| 89 | 89 | expect((await file("shut", { title: "x" })).status).toBe(404); |
| @@ -102,3 +102,33 @@ describe("the receipt's link origin", () => { | ||
| 102 | 102 | expect(publicOrigin(ctxOf(undefined, "localhost:3000"))).toBe("http://localhost:3000"); |
| 103 | 103 | }); |
| 104 | 104 | }); |
| 105 | ||
| 106 | describe("the page and the API say the same words", () => { | |
| 107 | test("the sent page carries REPORT_RECEIVED, as the API's message does", async () => { | |
| 108 | const dir = await mkdtemp(join(tmpdir(), "forge-receipt-page-")); | |
| 109 | const app = createApp({ dataDir: dir, port: 0 }); | |
| 110 | const servers = await serve(app); | |
| 111 | try { | |
| 112 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", | |
| 113 | email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 114 | if (!a.ok) throw new Error(a.error); | |
| 115 | const r = await createRepo(app, a.value, { name: "open", visibility: "public" }); | |
| 116 | if (!r.ok) throw new Error(String(r.error)); | |
| 117 | const res = await fetch(`${servers.url}/api/v1/repos/alice/open/reports`, { | |
| 118 | method: "POST", | |
| 119 | headers: { "content-type": "application/json", "x-forwarded-for": "203.0.113.200" }, | |
| 120 | body: JSON.stringify({ title: "Broken" }), | |
| 121 | }); | |
| 122 | const j = (await res.json()) as { message: string; url: string; id: string }; | |
| 123 | const page = await (await fetch(j.url)).text(); | |
| 124 | expect(page).toContain(REPORT_RECEIVED); | |
| 125 | expect(page).toContain(`id="report-receipt"`); | |
| 126 | expect(page).toContain(`href="/alice/open/report?sent=${j.id}">${j.id}</a>`); | |
outdated
Assert the page carries the receipt (the id or link) as well as the sentence; today this would pass with the number missing, which is the point of the issue. |
||
| 127 | expect(page.split(REPORT_RECEIVED).length).toBe(2); | |
| 128 | expect(j.message).toBe(REPORT_RECEIVED); | |
| 129 | } finally { | |
| 130 | await servers.stop(); | |
| 131 | await rm(dir, { recursive: true, force: true }); | |
| 132 | } | |
| 133 | }); | |
| 134 | }); |
test/reports.test.ts +1 −1
| @@ -307,7 +307,7 @@ describe("reports from outside", () => { | ||
| 307 | 307 | // The returned link is this report's own, and says where it stands. |
| 308 | 308 | expect(link).toMatch(/^\/alice\/side\/report\?sent=\w+/); |
| 309 | 309 | const sentPage = await (await fetch(`${base}${link}`)).text(); |
| 310 | expect(sentPage).toContain("Not read yet"); | |
| 310 | expect(sentPage).toContain("Received."); | |
| 311 | 311 | const sixth = await post(); |
| 312 | 312 | expect(sixth.status).toBe(429); |
| 313 | 313 | expect(Number(sixth.headers.get("retry-after"))).toBeGreaterThan(0); |
new above
offline
Principle 1: this says what the State row below says again ("Not read yet"). Keep one. Also the receipt the issue asks for (id, link, who will see it) is not here: add the report link/number, and the issue link as soon as it exists.