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

Merged opened this

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

Merged

scout/forge:scout/14127-an-outsider-s-report-on-a-public-app-ans → main 4 commits fork 2 threads · 2 unresolved

  • Merged. scout/14127-an-outsider-s-report-on-a-public-app-ans was merged into main as 13a2263.

Review

Sign in to review this change.
3 files changed +38 −4
src/web/pages/reports.ts +5 −1
@@ -12,6 +12,7 @@ import {
1212 waitingReports,
1313 } from "../../actions/reports.ts";
1414 import {
15 REPORT_RECEIVED,
1516 REPORT_WHERE_REPLY,
1617 REPORT_WHO_READS,
1718 reportTooFast,
@@ -193,6 +194,9 @@ function reportBody(ctx: Ctx, repo: Repo): Response {
193194 <section class="settings-block">
194195 <h1>Report sent</h1>
195196 <dl class="status-rows">
outdated

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.

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 : ""}
196200 ${standing?.title !== undefined
197201 ? html`<div class="status-row"><dt>Title</dt><dd id="report-title">${standing.title}</dd></div>`
198202 : ""}
@@ -202,7 +206,7 @@ function reportBody(ctx: Ctx, repo: Repo): Response {
202206 <a href="${base}/issues/${standing.issue}">an issue</a> from it.`
203207 : standing?.state === "dismissed"
204208 ? "A person read it and closed it without an issue."
205 : "Not read yet. Keep this link and look again."
209 : REPORT_RECEIVED
206210 }</dd></div>
207211 ${standing?.state === "pending"
208212 ? 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";
44 import { tmpdir } from "node:os";
55 import { join } from "node:path";
66 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";
88 import { createApp, type App } from "../src/app.ts";
99 import { createUser } from "../src/core/users.ts";
1010 import { serve, type Servers } from "../src/http/server.ts";
@@ -83,7 +83,7 @@ describe("a report's receipt", () => {
8383 const page = await (await fetch(r.url)).text();
8484 expect(page).toContain("Broken &lt;b&gt;link&lt;/b&gt;");
8585 expect(page).not.toContain("<b>link</b>");
86 expect(page).toContain("Not read yet");
86 expect(page).toContain("Received.");
8787 const closed = await fetch(`${base}/alice/shut/report?sent=${r.id}`);
8888 expect(closed.status).toBe(404);
8989 expect((await file("shut", { title: "x" })).status).toBe(404);
@@ -102,3 +102,33 @@ describe("the receipt's link origin", () => {
102102 expect(publicOrigin(ctxOf(undefined, "localhost:3000"))).toBe("http://localhost:3000");
103103 });
104104 });
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", () => {
307307 // The returned link is this report's own, and says where it stands.
308308 expect(link).toMatch(/^\/alice\/side\/report\?sent=\w+/);
309309 const sentPage = await (await fetch(`${base}${link}`)).text();
310 expect(sentPage).toContain("Not read yet");
310 expect(sentPage).toContain("Received.");
311311 const sixth = await post();
312312 expect(sixth.status).toBe(429);
313313 expect(Number(sixth.headers.get("retry-after"))).toBeGreaterThan(0);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs