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

The weekly production probe also checks /terms, /privacy and /.well-known/security.txt answer 200 #13287

Merged opened this

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

Merged

scout/forge:scout/13116-the-weekly-production-probe-also-checks → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/13116-the-weekly-production-probe-also-checks was merged into main as 0e272e2.

Review

Sign in to review this change.
3 files changed +62 −5
src/core/v1_proof.ts +16
@@ -227,6 +227,22 @@ export const probes: readonly Probe[] = [
227227 return `${path} carries ${entries} entr${entries === 1 ? "y" : "ies"} (${bytes} bytes)`;
228228 },
229229 },
230 {
231 issue: 13116,
232 item: "/terms, /privacy and /.well-known/security.txt answer 200",
233 // The failure names the first path that does not, with its status and bytes; the defect's
234 // evidence block carries the URL.
235 run: async (get) => {
236 const seen: string[] = [];
237 for (const path of ["/terms", "/privacy", "/.well-known/security.txt"]) {
238 const got = await get(path);
239 const bytes = new TextEncoder().encode(got.text).length;
240 expect(got.status === 200, `${path} answers ${got.status}, not 200 (${bytes} bytes)`);
241 seen.push(path);
242 }
243 return `${seen.join(", ")} answer 200`;
244 },
245 },
230246 {
231247 issue: 10441,
232248 item: "the security headers are on the page and on a machine answer",
test/maintain-v1-proven.test.ts +29 −1
@@ -10,7 +10,7 @@ import { createApp, type App } from "../src/app.ts";
1010 import { createIssue, listComments } from "../src/core/issues.ts";
1111 import { createRepo } from "../src/core/repos.ts";
1212 import { createUser } from "../src/core/users.ts";
13 import { probes, type Result } from "../src/core/v1_proof.ts";
13 import { probes, prove, type Result } from "../src/core/v1_proof.ts";
1414 import { v1Proven } from "../src/maintain/duties/v1_proven.ts";
1515 import { watcherId } from "../src/rules/bot.ts";
1616 import { duties } from "../src/maintain/registry.ts";
@@ -235,3 +235,31 @@ test("a run defect notes passing once when every probe passes again", async () =
235235 await run(undefined, undefined, mixed({}));
236236 expect(listComments(app.db, made.id).map((c) => c.body.split(" ")[0])).toEqual(["Passing"]);
237237 });
238
239 test("a failing /terms probe files exactly one defect carrying its URL, status and bytes (#13116)", async () => {
240 closeDefects();
241 const before = total();
242 const origin = Bun.serve({
243 port: 0,
244 fetch: (req) => {
245 const path = new URL(req.url).pathname;
246 return path === "/terms" ? new Response("nope", { status: 404 }) : new Response("ok");
247 },
248 });
249 try {
250 const base = `http://localhost:${origin.port}`;
251 const only = async (b: string): Promise<Result[]> => {
252 const all = await prove(b, fetch);
253 return all.filter((r) => r.issue === 13116);
254 };
255 const proof = async (b: string): Promise<Result[]> => (await only(b)).concat([]);
256 await run(base, undefined, proof);
257 await run(base, undefined, proof);
258 expect(total()).toBe(before + 1);

(await only(b)).concat([]) is a no-op wrapper; proof and only should be one function.

259 const made = defects().at(-1)!;
260 const ev = readEvidence(app.db.query<{ body: string }, [string]>("SELECT body FROM issue WHERE id = ?1").get(made.id)!.body)!;
261 expect(ev).toMatchObject({ url: `${base}/terms`, status: "404", bytes: "4" });
262 } finally {
263 origin.stop(true);
264 }
265 });
test/v1-proven.test.ts +17 −4
@@ -42,6 +42,9 @@ function stub(over: Over = {}, seen: string[] = []): Fetch {
4242 "/settings/crew": () => new Response(null, { status: 303, headers: { location: "/signin?next=%2Fsettings%2Fcrew" } }),
4343 "/api/v1/health": () => health({ overdue: 0, oldestSeconds: 0 }),
4444 "/changelog.atom": () => new Response(FEED),
45 "/terms": () => new Response("terms"),
46 "/privacy": () => new Response("privacy"),
47 "/.well-known/security.txt": () => new Response("Contact: mailto:[email protected]"),
4548 ...over,
4649 };
4750 return async (url, init) => {
@@ -55,9 +58,9 @@ describe("v1-proven", () => {
5558 test("every list item has a probe, and all pass on a healthy forge", async () => {
5659 const results = await prove("https://f.test/", stub());
5760 expect(results.map((r) => r.issue).sort()).toEqual(
58 [11541, 11539, 11158, 11573, 10304, 13042, 11507, 11138, 11140, 11141, 11515, 11595, 13072, 10441].sort(),
61 [11541, 11539, 11158, 11573, 10304, 13042, 11507, 11138, 11140, 11141, 11515, 11595, 13072, 13116, 10441].sort(),
5962 );
60 expect(probes.length).toBe(14);
63 expect(probes.length).toBe(15);
6164 const status = (n: number) => results.find((r) => r.issue === n)?.status;
6265 // What no public read can show is unproven, never a pass.
6366 expect(results.filter((r) => r.status === "unproven").map((r) => r.issue).sort()).toEqual([]);
@@ -72,6 +75,16 @@ describe("v1-proven", () => {
7275 expect(line(results.find((r) => r.issue === 13042)!)).toBe("fail #13042 the release production runs is 1.0.0 or later: the release is 0.7.604, not 1.0.0");
7376 });
7477
78 test("/terms, /privacy and security.txt must answer 200: a failure names the path, status and bytes (#13116)", async () => {
79 for (const path of ["/terms", "/privacy", "/.well-known/security.txt"]) {
80 const results = await prove("https://f.test", stub({ [path]: () => new Response("gone", { status: 404 }) }));
81 const bad = results.filter((r) => r.status === "fail");
82 expect(bad).toHaveLength(1);
83 expect(bad[0]!.detail).toBe(`${path} answers 404, not 200 (4 bytes)`);
84 expect(bad[0]!.seen).toMatchObject({ url: `https://f.test${path}`, status: 404, bytes: 4 });
85 }
86 });
87
7588 test("only reads: every request is a GET", async () => {
7689 const seen: string[] = [];
7790 await prove("https://f.test", stub({}, seen));
@@ -163,7 +176,7 @@ describe("v1-proven", () => {
163176 const { code, out } = await run(async () => new Response("down", { status: 503 }));
164177 expect(code).toBe(1);
165178 expect(out).toContain("fail #11539");
166 expect(out).toContain("v1.0.0 is not proven: 14 of 14 fail, 0 unproven");
179 expect(out).toContain("v1.0.0 is not proven: 15 of 15 fail, 0 unproven");
167180 });
168181
169182 test("the script exits 3, not 0, when nothing fails but some items are unproven", async () => {
@@ -171,7 +184,7 @@ describe("v1-proven", () => {
171184 expect(out).not.toContain("fail #");
172185 expect(code).toBe(3);
173186 expect(out).toContain("unproven #11595");
174 expect(out).toContain("v1.0.0 is not proven: none fail, 1 of 14 unproven");
187 expect(out).toContain("v1.0.0 is not proven: none fail, 1 of 15 unproven");
175188 });
176189
177190 test("the script exits 2 on bad usage", () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs