Public: anyone can read this; the crew can change it.
Full suite red: 6 files in check run 01m7y71e9c2x5gysb3m6f1yk33 #15150
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15144-full-suite-red-6-files-in-check-run-01m7 → main 5 commits fork 1 thread · 1 unresolved
12 files
changed +90
−18
src/perf/page_budgets/app.ts +1 −1
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | import type { PageBudget } from "../page_budget.ts"; |
| 2 | 2 | |
| 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 { | ||
| 14 | 14 | } from "../../actions/issues.ts"; |
| 15 | 15 | import { parseQuestion, type Issue } from "../../core/issues.ts"; |
| 16 | 16 | import { canRead, getRepo, listReposWritableTo, type Repo } from "../../core/repos.ts"; |
| 17 | import { reportsClosed } from "../../core/reports.ts"; | |
| 17 | import { reportsClosedFor } from "../reports_closed.ts"; | |
| 18 | 18 | import { privateRepoForSealed } from "../../actions/repos.ts"; |
| 19 | 19 | import { sealedWords, sealRefusedWords } from "../../actions/seal_issue_words.ts"; |
| 20 | 20 | 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 { | ||
| 176 | 176 | "The report without an account is not sealed: do not use it for a vulnerability.", |
| 177 | 177 | action: signIn("primary"), |
| 178 | 178 | }) |
| 179 | : reportsClosed(ctx.app.db, repo.id) | |
| 179 | : reportsClosedFor(ctx, repo.id) | |
| 180 | 180 | ? empty({ |
| 181 | 181 | icon: "issue", |
| 182 | 182 | title: "Opening an issue needs an account", |
src/web/pages/proposal-tokens.ts +2 −2
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | import { listProposals, mintProposal, revokeProposal } from "../../actions/proposal_tokens.ts"; |
| 9 | 9 | import { revokeOutsideToken, setOutsideContributions, takesOutside } from "../../actions/contribute_token.ts"; |
| 10 | 10 | import { setOutsideReports } from "../../actions/reports.ts"; |
| 11 | import { reportsClosed } from "../../core/reports.ts"; | |
| 11 | import { reportsClosedFor } from "../reports_closed.ts"; | |
| 12 | 12 | import { contributeOpen, listContribute } from "../../core/contribute_token.ts"; |
| 13 | 13 | import { canAdmin, canWrite, type Repo } from "../../core/repos.ts"; |
| 14 | 14 | import { isAccountItself, type Ctx } from "../../http/context.ts"; |
| @@ -28,7 +28,7 @@ function contributeTokensSection(ctx: Ctx, repo: Repo): Html | null { | ||
| 28 | 28 | const base = repoBase(repo); |
| 29 | 29 | const open = contributeOpen(ctx.app.db, repo.id); |
| 30 | 30 | 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); | |
| 32 | 32 | return html`<section class="settings-block mb" id="contribute-tokens"> |
| 33 | 33 | <form method="post" action="${base}/settings/contribute-tokens/open"> |
| 34 | 34 | <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 | ||
| 30 | 30 | import { lacks, NOT_A_MEMBER } from "../../core/roles.ts"; |
| 31 | 31 | import { storageLimitMessage } from "../../core/storage.ts"; |
| 32 | 32 | 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"; | |
| 34 | 34 | import { publicRepoLd } from "../structured_data.ts"; |
| 35 | 35 | import { capReached, lowWallet, money, walletStanding } from "../../core/wallet.ts"; |
| 36 | 36 | import { takesOutside } from "../../actions/contribute_token.ts"; |
| @@ -1485,7 +1485,7 @@ function walletLine(ctx: Ctx, repo: Repo): Html | null { | ||
| 1485 | 1485 | */ |
| 1486 | 1486 | function reportLine(ctx: Ctx, repo: Repo): Html | null { |
| 1487 | 1487 | if (repo.visibility !== "public") return null; |
| 1488 | if (reportsClosed(ctx.app.db, repo.id)) | |
| 1488 | if (reportsClosedFor(ctx, repo.id)) | |
| 1489 | 1489 | return html`<p class="muted small mt" id="report-line">Reports from outside are closed here.</p>`; |
| 1490 | 1490 | return html`<p class="muted small mt" id="report-line"> |
| 1491 | 1491 | 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); | |
| 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"; | ||
| 34 | 34 | import { CRAWL_DELAY_S, DEEP_SEGMENTS } from "../http/crawl.ts"; |
| 35 | 35 | import { markPng, type MarkShape } from "../design/mark.ts"; |
| 36 | 36 | 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"; | |
| 38 | 39 | import { pageDay, sitemapPages } from "./sitemap_pages.ts"; |
| 39 | 40 | import { dayOf } from "../release/days.ts"; |
| 40 | 41 | import { readLandings } from "../release/landings.ts"; |
| @@ -708,7 +709,7 @@ export function pageLinks(ctx: Ctx): PageLink[] { | ||
| 708 | 709 | if ( |
| 709 | 710 | repo !== undefined && |
| 710 | 711 | canRead(ctx.app.db, repo, undefined) && |
| 711 | !reportsClosed(ctx.app.db, repo.id) | |
| 712 | !reportsClosedFor(ctx, repo.id) | |
| 712 | 713 | ) { |
| 713 | 714 | links.push({ |
| 714 | 715 | rel: "help", |
src/web/structured_data.ts +2 −2
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * out; the page puts it in a `<script type="application/ld+json">`. |
| 5 | 5 | */ |
| 6 | 6 | import { SITE_LINE } from "./site_line.ts"; |
| 7 | import { reportsClosed } from "../core/reports.ts"; | |
| 7 | import { reportsClosedFor } from "./reports_closed.ts"; | |
| 8 | 8 | import { takesOutside } from "../actions/contribute_token.ts"; |
| 9 | 9 | import { repoLine } from "./describe.ts"; |
| 10 | 10 | import type { Repo } from "../core/repos.ts"; |
| @@ -82,7 +82,7 @@ export function repoStructuredData(origin: string, path: string, description: st | ||
| 82 | 82 | export function publicRepoLd(ctx: Ctx, repo: Repo): { jsonLd?: string } { |
| 83 | 83 | if (repo.visibility !== "public") return {}; |
| 84 | 84 | const path = `${repo.ownerName}/${repo.name}`; |
| 85 | const doors = reportsClosed(ctx.app.db, repo.id) | |
| 85 | const doors = reportsClosedFor(ctx, repo.id) | |
| 86 | 86 | ? {} |
| 87 | 87 | : { report: `/api/v1/repos/${path}/reports`, ...(takesOutside(ctx.app, repo) ? { offer: "/api/v1/contribute" } : {}) }; |
| 88 | 88 | 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>>; | ||
| 19 | 19 | // replaces the daily-ceiling read, so it adds none beside it. |
| 20 | 20 | // 41: the repository page reads the repository's wallet cap, one primary-key read, to show the |
| 21 | 21 | // 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; | |
| 25 | 24 | const BARE_404_QUERIES = 0; // a 404 with no owner/name to suggest from |
| 26 | 25 | // The same 404 for a mistyped repository. One of the 7 is the noindex lookup that |
| 27 | 26 | // 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 }; | ||
| 55 | 55 | const HEAVIER: Record<string, { statements?: number; git?: number }> = { |
| 56 | 56 | "/:owner/:name/issues/:number": { statements: 71 }, // +1: whether the repository is archived, so its pages say noindex (#14305) |
| 57 | 57 | "/: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) | |
| 59 | 59 | "/api/v1/asks": { statements: 61 }, // +1: the stopped apps someone asked for, one read of the viewer's archived repositories (#12277) |
| 60 | 60 | "/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 |
| 61 | 61 | "/settings/capacity": { statements: 70 }, |
test/repo-pages-timing.test.ts +2 −2
| @@ -60,8 +60,8 @@ afterAll(() => { | ||
| 60 | 60 | /** The most statements a request may run: today's count with room for a read or two. */ |
| 61 | 61 | const MAX_STATEMENTS: Record<string, number> = { |
| 62 | 62 | "/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, | |
| 65 | 65 | "/alice/forge/make-it-yours": 27, |
| 66 | 66 | }; |
| 67 | 67 |
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", | ||
| 168 | 168 | // 30 day rows the page already has, and the cap and month spend an admin's cap form already |
| 169 | 169 | // reads. A reader who is not an admin pays those two indexed reads, which no longer sit behind |
| 170 | 170 | // 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) | |
| 172 | 172 | expectWork(await statements(app.db, () => void readWallet(app, bob, repo)), { max: 2 }); |
| 173 | 173 | }); |
| 174 | 174 |
new above
offline
Needs a test that would fail without it: (1) two calls with the same ctx run one statement; (2) after
setOutsideReportscloses 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.