Public: anyone can read this; the crew can change it.

Full suite red: 6 files in check run 01m7y71e9c2x5gysb3m6f1yk33 #15150

Merged opened this in answer to

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

Merged

scout/forge:scout/15144-full-suite-red-6-files-in-check-run-01m7 → main 5 commits fork 1 thread · 1 unresolved

  • Merged. scout/15144-full-suite-red-6-files-in-check-run-01m7 was merged into main as 876685a.

Review

Sign in to review this change.
12 files changed +90 −18
src/perf/page_budgets/app.ts +1 −1
@@ -1,3 +1,3 @@
11 import type { PageBudget } from "../page_budget.ts";
22
3 export const budget: PageBudget = { page: "an app page", pattern: "/:owner/:name", medianMs: 50, statements: 49 };
3 export const budget: PageBudget = { page: "an app page", pattern: "/:owner/:name", medianMs: 50, statements: 50 };
src/web/pages/issues.ts +2 −2
@@ -14,7 +14,7 @@ import {
1414 } from "../../actions/issues.ts";
1515 import { parseQuestion, type Issue } from "../../core/issues.ts";
1616 import { canRead, getRepo, listReposWritableTo, type Repo } from "../../core/repos.ts";
17 import { reportsClosed } from "../../core/reports.ts";
17 import { reportsClosedFor } from "../reports_closed.ts";
1818 import { privateRepoForSealed } from "../../actions/repos.ts";
1919 import { sealedWords, sealRefusedWords } from "../../actions/seal_issue_words.ts";
2020 import { BODY_TOO_LONG, TITLE_TOO_LONG } from "../../actions/thread_limits_words.ts";
@@ -176,7 +176,7 @@ function accountOrReport(ctx: Ctx, repo: Repo, sealed: boolean): Response {
176176 "The report without an account is not sealed: do not use it for a vulnerability.",
177177 action: signIn("primary"),
178178 })
179 : reportsClosed(ctx.app.db, repo.id)
179 : reportsClosedFor(ctx, repo.id)
180180 ? empty({
181181 icon: "issue",
182182 title: "Opening an issue needs an account",
src/web/pages/proposal-tokens.ts +2 −2
@@ -8,7 +8,7 @@
88 import { listProposals, mintProposal, revokeProposal } from "../../actions/proposal_tokens.ts";
99 import { revokeOutsideToken, setOutsideContributions, takesOutside } from "../../actions/contribute_token.ts";
1010 import { setOutsideReports } from "../../actions/reports.ts";
11 import { reportsClosed } from "../../core/reports.ts";
11 import { reportsClosedFor } from "../reports_closed.ts";
1212 import { contributeOpen, listContribute } from "../../core/contribute_token.ts";
1313 import { canAdmin, canWrite, type Repo } from "../../core/repos.ts";
1414 import { isAccountItself, type Ctx } from "../../http/context.ts";
@@ -28,7 +28,7 @@ function contributeTokensSection(ctx: Ctx, repo: Repo): Html | null {
2828 const base = repoBase(repo);
2929 const open = contributeOpen(ctx.app.db, repo.id);
3030 const tokens = open ? listContribute(ctx.app.db, repo.id, new Date()) : [];
31 const reportsOpen = !reportsClosed(ctx.app.db, repo.id);
31 const reportsOpen = !reportsClosedFor(ctx, repo.id);
3232 return html`<section class="settings-block mb" id="contribute-tokens">
3333 <form method="post" action="${base}/settings/contribute-tokens/open">
3434 <input type="hidden" name="on" value="${open ? "0" : "1"}" />
src/web/pages/repo.ts +2 −2
@@ -30,7 +30,7 @@ import { GUEST_REFUSALS, HELP_BUILD, HELP_BUILD_NEXT, isContributionFork, isGues
3030 import { lacks, NOT_A_MEMBER } from "../../core/roles.ts";
3131 import { storageLimitMessage } from "../../core/storage.ts";
3232 import { canRead, canWrite, listForks, visibleForksRecent, type RecentFork, type Repo } from "../../core/repos.ts";
33 import { reportsClosed } from "../../core/reports.ts";
33 import { reportsClosedFor } from "../reports_closed.ts";
3434 import { publicRepoLd } from "../structured_data.ts";
3535 import { capReached, lowWallet, money, walletStanding } from "../../core/wallet.ts";
3636 import { takesOutside } from "../../actions/contribute_token.ts";
@@ -1485,7 +1485,7 @@ function walletLine(ctx: Ctx, repo: Repo): Html | null {
14851485 */
14861486 function reportLine(ctx: Ctx, repo: Repo): Html | null {
14871487 if (repo.visibility !== "public") return null;
1488 if (reportsClosed(ctx.app.db, repo.id))
1488 if (reportsClosedFor(ctx, repo.id))
14891489 return html`<p class="muted small mt" id="report-line">Reports from outside are closed here.</p>`;
14901490 return html`<p class="muted small mt" id="report-line">
14911491 Something wrong? <a href="${repoBase(repo)}/report">Report a problem</a>, no account needed${takesOutside(ctx.app, repo)
src/web/reports_closed.ts added +14
@@ -0,0 +1,14 @@
1 /** Whether reports are closed, read once per request however many parts of a page ask. */
2 import type { Ctx } from "../http/context.ts";
3 import { reportsClosed } from "../core/reports.ts";
4
5 // Per request, so a close made elsewhere still holds on the next one (#15039).
6 const asked = new WeakMap<Ctx, Map<string, boolean>>();
7
8 export function reportsClosedFor(ctx: Ctx, repoId: string): boolean {
9 let seen = asked.get(ctx);

Needs a test that would fail without it: (1) two calls with the same ctx run one statement; (2) after setOutsideReports closes reports, a fresh ctx returns true. Without (2) the #15039 cross-process guarantee is unpinned, and without (1) the only guard is six raised budget pins.

10 if (seen === undefined) asked.set(ctx, (seen = new Map()));
11 let closed = seen.get(repoId);
12 if (closed === undefined) seen.set(repoId, (closed = reportsClosed(ctx.app.db, repoId)));
13 return closed;
14 }
src/web/standards.ts +3 −2
@@ -34,7 +34,8 @@ import { UPSTREAM_REPO } from "../core/upstream.ts";
3434 import { CRAWL_DELAY_S, DEEP_SEGMENTS } from "../http/crawl.ts";
3535 import { markPng, type MarkShape } from "../design/mark.ts";
3636 import { metaThemeColor } from "../design/themes.ts";
37 import { BODY_MAX, TITLE_MAX, reportsClosed } from "../core/reports.ts";
37 import { BODY_MAX, TITLE_MAX } from "../core/reports.ts";
38 import { reportsClosedFor } from "./reports_closed.ts";
3839 import { pageDay, sitemapPages } from "./sitemap_pages.ts";
3940 import { dayOf } from "../release/days.ts";
4041 import { readLandings } from "../release/landings.ts";
@@ -708,7 +709,7 @@ export function pageLinks(ctx: Ctx): PageLink[] {
708709 if (
709710 repo !== undefined &&
710711 canRead(ctx.app.db, repo, undefined) &&
711 !reportsClosed(ctx.app.db, repo.id)
712 !reportsClosedFor(ctx, repo.id)
712713 ) {
713714 links.push({
714715 rel: "help",
src/web/structured_data.ts +2 −2
@@ -4,7 +4,7 @@
44 * out; the page puts it in a `<script type="application/ld+json">`.
55 */
66 import { SITE_LINE } from "./site_line.ts";
7 import { reportsClosed } from "../core/reports.ts";
7 import { reportsClosedFor } from "./reports_closed.ts";
88 import { takesOutside } from "../actions/contribute_token.ts";
99 import { repoLine } from "./describe.ts";
1010 import type { Repo } from "../core/repos.ts";
@@ -82,7 +82,7 @@ export function repoStructuredData(origin: string, path: string, description: st
8282 export function publicRepoLd(ctx: Ctx, repo: Repo): { jsonLd?: string } {
8383 if (repo.visibility !== "public") return {};
8484 const path = `${repo.ownerName}/${repo.name}`;
85 const doors = reportsClosed(ctx.app.db, repo.id)
85 const doors = reportsClosedFor(ctx, repo.id)
8686 ? {}
8787 : { report: `/api/v1/repos/${path}/reports`, ...(takesOutside(ctx.app, repo) ? { offer: "/api/v1/contribute" } : {}) };
8888 return { jsonLd: repoStructuredData(ctx.url.origin, path, repoLine({ private: false, name: repo.name, description: repo.description }), doors) };
test/did-you-mean.test.ts +2 −3
@@ -19,9 +19,8 @@ let servers: Awaited<ReturnType<typeof serve>>;
1919 // replaces the daily-ceiling read, so it adds none beside it.
2020 // 41: the repository page reads the repository's wallet cap, one primary-key read, to show the
2121 // wallet line (#13309).
22 // 44: the page's statements grew by three on main without this pin following (red on every
23 // pull, #15154). The count is deterministic: a drift is a code change, never machine load.
24 const FOUND_QUERIES = 44;
22 // 42: whether reports are closed, one read per request from the row (#15053).
23 const FOUND_QUERIES = 42;
2524 const BARE_404_QUERIES = 0; // a 404 with no owner/name to suggest from
2625 // The same 404 for a mistyped repository. One of the 7 is the noindex lookup that
2726 // answerGet makes for every /:owner/:name route before its handler runs (1e71740ab, #14305,
test/pages-budget.test.ts +1 −1
@@ -55,7 +55,7 @@ const DEFAULT = { statements: 60, git: 8 };
5555 const HEAVIER: Record<string, { statements?: number; git?: number }> = {
5656 "/:owner/:name/issues/:number": { statements: 71 }, // +1: whether the repository is archived, so its pages say noindex (#14305)
5757 "/:owner/:name/next": { statements: 67 }, // +1: whether the repository is archived (#14305); +1: the wallet row, one read of the monthly cap (#13529); +1: the growth line, one read for the week, the open counts and the planner pause (#12290, #12867)
58 "/:owner/:name/pulls/:number": { statements: 115 }, // +1: whether the repository is archived (#14305); +1: the desk hold on the pull, one read of the notes that link it (#12536); +1: whether a repository is the forge's own copy, one read of the source setting for the tell box (#12037); +1: the paused sentence, one read of a queued paused run on the pull (#12010); +1: the header Talk count (#10327); +1: the landing line (#10860); +1: whether a reviewer is seated, read only when Require review is off and the pull would otherwise wait on one; the page loads no crew besides (#11666)
58 "/:owner/:name/pulls/:number": { statements: 116 }, // +1: whether the reports door is closed, one primary-key read per request, never from memory (#15053); +1: whether the repository is archived (#14305); +1: the desk hold on the pull, one read of the notes that link it (#12536); +1: whether a repository is the forge's own copy, one read of the source setting for the tell box (#12037); +1: the paused sentence, one read of a queued paused run on the pull (#12010); +1: the header Talk count (#10327); +1: the landing line (#10860); +1: whether a reviewer is seated, read only when Require review is off and the pull would otherwise wait on one; the page loads no crew besides (#11666)
5959 "/api/v1/asks": { statements: 61 }, // +1: the stopped apps someone asked for, one read of the viewer's archived repositories (#12277)
6060 "/board": { statements: 72 }, // +1: the forge-copy read for the tell box (#12037); +1: the vitals read the database's growth (#12025); +6: the money line (#510) — one settings read, then the month's and the 30 days' meter, storage and ledger reads; constant in the number of apps
6161 "/settings/capacity": { statements: 70 },
test/repo-pages-timing.test.ts +2 −2
@@ -60,8 +60,8 @@ afterAll(() => {
6060 /** The most statements a request may run: today's count with room for a read or two. */
6161 const MAX_STATEMENTS: Record<string, number> = {
6262 "/alice/forge/issues/new": 38,
63 "/alice/forge/report": 36,
64 "/alice/forge/toolbar": 21,
63 "/alice/forge/report": 37, // +1: reports closed, read from the row (#15053)
64 "/alice/forge/toolbar": 22,
6565 "/alice/forge/make-it-yours": 27,
6666 };
6767
test/reports-closed-for.test.ts added +58
@@ -0,0 +1,58 @@
1 /**
2 * reportsClosedFor: one read per request, and a close made elsewhere shows on the next (#15039).
3 */
4 import { afterAll, beforeAll, expect, test } from "bun:test";
5 import { mkdtemp, rm } from "node:fs/promises";
6 import { tmpdir } from "node:os";
7 import { join } from "node:path";
8 import { createApp } from "../src/app.ts";
9 import { createRepo } from "../src/actions/repos.ts";
10 import { createUser } from "../src/core/users.ts";
11 import { setReportsClosed } from "../src/core/reports.ts";
12 import type { Ctx } from "../src/http/context.ts";
13 import { reportsClosedFor } from "../src/web/reports_closed.ts";
14
15 let dir = "";
16 let app: ReturnType<typeof createApp>;
17 let reads = 0;
18 let repoId = "";
19 const request = () => ({ app }) as unknown as Ctx;
20
21 beforeAll(async () => {
22 dir = await mkdtemp(join(tmpdir(), "forge-rcf-"));
23 app = createApp({ dataDir: dir, port: 0 });
24 const made = await createUser(app.db, {
25 origin: "seed", trusted: true, username: "trevato", email: "[email protected]",
26 password: "a-good-passphrase", adminIfFirst: true,
27 });
28 const owner = (made as any).value ?? made;
29 const repo = await createRepo(app, owner, { name: "forge", visibility: "public" });
30 repoId = ((repo as any).value ?? repo).id;
31 const query = app.db.query.bind(app.db);
32 (app.db as any).query = (sql: string) => {
33 if (sql.includes("report_closed") && sql.startsWith("SELECT")) reads++;
34 return query(sql);
35 };
36 });
37 afterAll(async () => {
38 app.close();
39 await rm(dir, { recursive: true, force: true });
40 });
41
42 test("two asks in one request run one statement per repository", () => {
43 const ctx = request();
44 reads = 0;
45 expect(reportsClosedFor(ctx, "r1")).toBe(false);
46 expect(reportsClosedFor(ctx, "r1")).toBe(false);
47 expect(reads).toBe(1);
48 reportsClosedFor(ctx, "r2");
49 expect(reads).toBe(2);
50 });
51
52 test("a new request after a close sees the close", () => {
53 const before = request();
54 expect(reportsClosedFor(before, repoId)).toBe(false);
55 setReportsClosed(app.db, repoId, true);
56 expect(reportsClosedFor(before, repoId)).toBe(false); // same request: the memo holds
57 expect(reportsClosedFor(request(), repoId)).toBe(true);
58 });
test/wallet.test.ts +1 −1
@@ -168,7 +168,7 @@ test("with 10,000 ledger rows the page costs a few statements, not one per row",
168168 // 30 day rows the page already has, and the cap and month spend an admin's cap form already
169169 // reads. A reader who is not an admin pays those two indexed reads, which no longer sit behind
170170 // the admin check.
171 expectWork(await requestStatements(app.db, url, { headers }), { max: 41 });
171 expectWork(await requestStatements(app.db, url, { headers }), { max: 42 }); // +1: whether reports are closed, read from the row (#15053)
172172 expectWork(await statements(app.db, () => void readWallet(app, bob, repo)), { max: 2 });
173173 });
174174

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs