Public: anyone can read this; the crew can change it.
A test pins that a wave never names a pull from a repository the viewer cannot read #6836
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/6824-a-test-pins-that-a-wave-never-names-a-pu → main 1 commit fork 1 thread · 1 unresolved
1 file
changed +36
−1
test/wave-pulls.test.ts +36 −1
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /** A wave's page lists the pulls it names: title, date, link; the unseen are left out (#5942). */ |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 2 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 3 | 3 | import { mkdtempSync, rmSync } from "node:fs"; |
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | import { join } from "node:path"; |
| @@ -9,6 +9,7 @@ import type { Repo } from "../src/core/repos.ts"; | ||
| 9 | 9 | import { createSession } from "../src/core/sessions.ts"; |
| 10 | 10 | import { createUser, type User } from "../src/core/users.ts"; |
| 11 | 11 | import { serve, type Servers } from "../src/http/server.ts"; |
| 12 | import { carriedPulls } from "../src/story/wave_pulls.ts"; | |
| 12 | 13 | import { pullRefs } from "../src/story/waves.ts"; |
| 13 | 14 | import { writeWave } from "../src/story/wave.ts"; |
| 14 | 15 | import { quietLogs } from "./helpers/globals.ts"; |
| @@ -144,3 +145,37 @@ test("refs are read from the file and the phase is named", async () => { | ||
| 144 | 145 | await res.text(); |
| 145 | 146 | expect(res.headers.get("server-timing") ?? "").toMatch(/pulls;dur=\d+\.\d/); |
| 146 | 147 | }); |
| 148 | ||
| 149 | describe("carriedPulls", () => { | |
| 150 | const numberOf = (repo: string, title: string): number => | |
| 151 | app.db | |
| 152 | .query<{ number: number }, [string, string]>( | |
| 153 | "SELECT issue.number FROM issue JOIN repo ON repo.id = issue.repo_id WHERE repo.name = ? AND issue.title = ?", | |
| 154 | ) | |
| 155 | .get(repo, title)!.number; | |
| 156 | const refs = () => [ | |
| 157 | { owner: "alice", name: "pub", number: numberOf("pub", "Fix the other") }, | |
| 158 | { owner: "alice", name: "priv", number: numberOf("priv", "Secret work") }, | |
| 159 | { owner: "alice", name: "pub", number: 999 }, | |
| 160 | ]; | |
| 161 | const titles = (viewer: User | undefined) => carriedPulls(app.db, refs(), viewer).map((p) => p.title); | |
| 162 | ||
| 163 | test("a guest and a stranger get the public pull only; the private repository's owner gets both", () => { | |
| 164 | expect(titles(undefined)).toEqual(["Fix the other"]); | |
| 165 | expect(titles(bob)).toEqual(["Fix the other"]); | |
| 166 | expect(titles(alice)).toEqual(["Fix the other", "Secret work"]); | |
| 167 | }); | |
| 168 | ||
| 169 | test("a reference to a pull that does not exist is left out, not an error", () => { | |
| 170 | const ghost = [{ owner: "alice", name: "pub", number: 999 }, { owner: "nobody", name: "nothing", number: 1 }]; | |
| 171 | expect(carriedPulls(app.db, ghost, alice)).toEqual([]); | |
| 172 | }); | |
| 173 | ||
| 174 | test("the titles are the live ones", () => { | |
| 175 | const n = numberOf("pub", "Dropped idea"); | |
| 176 | const ref = [{ owner: "alice", name: "pub", number: n }]; | |
| 177 | expect(carriedPulls(app.db, ref, undefined)[0]?.title).toBe("Dropped idea"); | |
| 178 | app.db.query("UPDATE issue SET title = 'Renamed idea' WHERE title = 'Dropped idea'").run(); | |
| 179 | expect(carriedPulls(app.db, ref, undefined)[0]?.title).toBe("Renamed idea"); | |
| 180 | }); | |
| 181 | }); |
new above
offline
This UPDATE leaks into the shared fixture. Rename it back at the end of the test (or create a pull just for it) so test order cannot matter.