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

A sealed pull leaves no trace on a wave: the fix lands from a branch in trevato/forge that reviewers can read #15192

Merged opened this

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

Merged

scout/forge:scout/15190-a-sealed-pull-leaves-no-trace-on-a-wave → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/15190-a-sealed-pull-leaves-no-trace-on-a-wave was merged into main as 37610c9.

Review

Sign in to review this change.
3 files changed +130 −5
src/story/wave_duration.ts +3 −2
@@ -42,7 +42,8 @@ export function durationWords(startedAt: string | null, pulls: readonly { merged
4242
4343 /**
4444 * The earliest moment an issue of the wave was opened: its pulls' own, and the issues they close.
45 * One repo lookup per owner and name, two queries per repo however many pulls.
45 * A sealed issue a pull closes is skipped, whoever looks: its opening date would say when the
46 * report was filed. One repo lookup per owner and name, two queries per repo however many pulls.

Skipping sealed reports for every viewer is a deliberate simplification; keep it, but the test names it so a later viewer-aware change does not silently regress.

4647 */
4748 export function waveStart(db: Database, pulls: readonly CarriedPull[]): string | null {
4849 let first: string | null = null;
@@ -79,7 +80,7 @@ export function waveStart(db: Database, pulls: readonly CarriedPull[]): string |
7980 if (ns.length === 0) continue;
8081 for (const row of db
8182 .query<{ created_at: string }, (string | number)[]>(
82 `SELECT created_at FROM issue WHERE repo_id = ?1 AND number IN (${ns.map((_, i) => `?${i + 2}`).join(",")})`,
83 `SELECT created_at FROM issue WHERE repo_id = ?1 AND sealed = 0 AND number IN (${ns.map((_, i) => `?${i + 2}`).join(",")})`,
8384 )
8485 .all(repo.id, ...ns)) see(row.created_at);
8586 }
src/story/wave_pulls.ts +8 −3
@@ -1,12 +1,15 @@
11 /**
22 * The pulls a wave carries, with their live titles: the references come from
33 * the wave file (`waves.ts`), the titles from one query. A pull in a
4 * repository the viewer cannot read, or one that does not exist, is left out.
4 * repository the viewer cannot read, one the viewer may not `mayView` (a sealed fix), or one that
5 * does not exist, is left out: a stranger's wave naming another repository's pulls learns nothing
6 * of its sealed work.
57 */
68
79 import type { Database } from "bun:sqlite";
810 import { closesFromBody } from "../core/pulls.ts";
911 import { canRead, getRepo, type Repo } from "../core/repos.ts";
12 import { mayView } from "../core/sealed.ts";
1013 import type { User } from "../core/users.ts";
1114 import type { PullRef } from "./waves.ts";
1215
@@ -51,6 +54,8 @@ interface Row {
5154 merged_at: string | null;
5255 merged_by: string | null;
5356 state: "open" | "closed";
57 sealed: number;
58 author_id: string;
5459 }
5560
5661 export function carriedPulls(
@@ -73,7 +78,7 @@ export function carriedPulls(
7378 if (visible.length === 0) return [];
7479 const rows = db
7580 .query<Row, string[]>(
76 `SELECT issue.repo_id, issue.number, issue.title, issue.body, issue.state, pull.merged_at, user.username AS merged_by
81 `SELECT issue.repo_id, issue.number, issue.title, issue.body, issue.state, issue.sealed, issue.author_id, pull.merged_at, user.username AS merged_by
7782 FROM issue JOIN pull ON pull.issue_id = issue.id LEFT JOIN user ON user.id = pull.merged_by
7883 WHERE issue.kind = 'pull' AND (${visible
7984 .map(() => "(issue.repo_id = ? AND issue.number = ?)")
@@ -83,7 +88,7 @@ export function carriedPulls(
8388 const byKey = new Map(rows.map((r) => [`${r.repo_id}#${r.number}`, r]));
8489 return visible.flatMap(({ ref, repo }) => {
8590 const r = byKey.get(`${repo.id}#${ref.number}`);
86 return r
91 return r && mayView(db, repo, { sealed: r.sealed === 1, authorId: r.author_id }, viewer)
8792 ? [{ owner: ref.owner, name: ref.name, number: ref.number, title: r.title, mergedAt: r.merged_at, mergedBy: r.merged_by, state: r.state, ...((s => (s === undefined ? {} : { sentence: s }))(distill(r.body ?? ""))) }]
8893 : [];
8994 });
test/wave-pulls-sealed.test.ts added +119
@@ -0,0 +1,119 @@
1 /**
2 * A stranger's public wave that names another repository's pulls learns nothing of its sealed work
3 * (#15190): the sealed fix is left out for whoever may not see it, on the page and the API, and a
4 * sealed report it closes does not move the wave's start.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtempSync, rmSync } from "node:fs";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
11 import { createApp, type App } from "../src/app.ts";
12 import { createUser, type User } from "../src/core/users.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { waveStart } from "../src/story/wave_duration.ts";
15 import { carriedPulls } from "../src/story/wave_pulls.ts";
16 import { pullRefs } from "../src/story/waves.ts";
17 import { quietLogs } from "./helpers/globals.ts";
18 import { promote } from "./helpers/members.ts";
19 import { mergedPull, waveNaming } from "./helpers/wave-pulls.ts";
20
21 quietLogs();
22
23 let root = "";
24 let app: App;
25 let servers: Servers;
26 let alice: User;
27 let mallory: User;
28 let open = 0;
29 let fix = 0;
30 let report = 0;
31
32 const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => {
33 if (!r.ok) throw new Error(JSON.stringify(r.error));
34 return r.value;
35 };
36
37 const FIX_TITLE = "Close the token-reuse hole";
38 const FIX_BODY = "The session check skips the origin header on PUT.";
39 const WAVE = "0.0.1";
40
41 beforeAll(async () => {
42 root = mkdtempSync(join(tmpdir(), "forge-wave-sealed-"));
43 app = createApp({ dataDir: root, port: 0 });
44 servers = await serve(app);
45 const mk = async (username: string, adminIfFirst: boolean) => {
46 const u = must(
47 await createUser(app.db, {
48 origin: "seed",
49 trusted: true,
50 username,
51 email: `${username}@forge.local`,
52 password: "a-good-passphrase",
53 adminIfFirst,
54 }),
55 );
56 promote(app.db, u);
57 return u;
58 };
59 alice = await mk("alice", true);
60 mallory = await mk("mallory", false);
61 const pub = must(await createRepo(app, alice, { name: "pub", visibility: "public" }));
62 const probe = must(await createRepo(app, mallory, { name: "probe", visibility: "public" }));
63 must(await commitToBranch(app, alice, pub, { message: "init", files: [{ path: "README.md", content: "hi\n" }] }));
64 open = await mergedPull(app, alice, pub, "Open work");
65 fix = await mergedPull(app, alice, pub, FIX_TITLE);
66 // A sealed report, opened long before, that the open pull says it closes.
67 report = open + fix + 1;
68 app.db
69 .query(
70 `INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at, updated_at, sealed)
71 VALUES ('sealed-report', ?1, ?2, 'issue', 'Report', '', ?3, 'open', '2020-01-01T00:00:00.000Z', '2020-01-01T00:00:00.000Z', 1)`,
72 )
73 .run(pub.id, report, alice.id);
74 app.db.query("UPDATE issue SET body = ?3 WHERE repo_id = ?1 AND number = ?2").run(pub.id, open, `Closes #${report}`);
75 app.db.query("UPDATE issue SET sealed = 1, body = ?3 WHERE repo_id = ?1 AND number = ?2").run(pub.id, fix, FIX_BODY);
76 const refs = [open, fix].map((number) => ({ owner: "alice", name: "pub", number }));
77 must(await commitToBranch(app, mallory, probe, { message: "wave", files: [{ path: `waves/${WAVE}.md`, content: waveNaming(WAVE, refs) }] }));
78 }, 60_000);
79
80 afterAll(() => {
81 servers.stop();
82 app.close();
83 rmSync(root, { recursive: true, force: true });
84 });
85
86 const refs = () => [open, fix].map((number) => ({ owner: "alice", name: "pub", number, title: "", url: "" }));
87 const numbers = (viewer: User | undefined) => carriedPulls(app.db, refs(), viewer).map((p) => p.number);
88
89 test("a guest and the prober get only the open pull; the sealed repository's author gets both", () => {
90 expect(numbers(undefined)).toEqual([open]);
91 expect(numbers(mallory)).toEqual([open]);
92 expect(numbers(alice)).toEqual([open, fix]);
93 });
94
95 // Deliberate simplification: waveStart is not viewer-aware, so it skips a sealed report for every
96 // viewer, the writer who may see it included. A viewer-aware change must replace this test, not
97 // slip past it.
98 test("a sealed report the visible pull closes sets no viewer's start, not even its writer's", () => {
99 for (const viewer of [undefined, mallory, alice]) {
100 const start = waveStart(app.db, carriedPulls(app.db, refs(), viewer));
101 expect(start).not.toBeNull();
102 expect(start!.startsWith("2020")).toBe(false);
103 }
104 });
105
106 test("the anonymous wave page and the API carry neither the fix's title nor its description", async () => {
107 for (const path of [`/mallory/probe/waves/${WAVE}`, `/api/v1/repos/mallory/probe/waves/${WAVE}`]) {
108 const res = await fetch(`${servers.url}${path}`);
109 const body = await res.text();
110 expect(res.status).toBe(200);
111 expect(body).toContain("Open work");
112 expect(body).not.toContain(FIX_TITLE);
113 expect(body).not.toContain(FIX_BODY);
114 }
115 });
116
117 test("the wave file names both pulls, so the filter is what hides the fix", () => {
118 expect(pullRefs({ version: WAVE, date: "2026-03-05", headline: "h", highlights: [], pulls: refs().map((r) => ({ title: "t", url: `https://x.example/alice/pub/pulls/${r.number}` })) }).length).toBe(2);
119 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs