Public: anyone can read this; the crew can change it.
The feed pages older posts with a plain ?before= link, no script #14148
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14137-the-feed-pages-older-posts-with-a-plain → main 4 commits fork
3 files
changed +42
−4
src/web/studio/feed.ts +1 −1
| @@ -46,7 +46,7 @@ import { appsFirst } from "../../actions/first_ask.ts"; | ||
| 46 | 46 | export const FEED_LIVE = |
| 47 | 47 | "run.finished,issue.opened,issue.commented,pull.commented,pull.opened,pull.merged,pull.reviewed,pull.closed,look.taken,app.serving,app.gated,beat.ran,issue.blocked,issue.unblocked,crew.governed,issue.closed,decision.*,thought.received,thought.placed"; |
| 48 | 48 | |
| 49 | export const FEED_FIRST_PAGE = 20; | |
| 49 | export const FEED_FIRST_PAGE = 30; | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | const KIND_LABEL: Record<FeedItem["kind"], string> = { |
test/feed-budget.test.ts +3 −3
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /** |
| 2 | * The feed's first paint on a forge of 500 posts (#13659): server-rendered with its first twenty, | |
| 2 | * The feed's first paint on a forge of 500 posts (#13659): server-rendered with its first thirty, | |
| 3 | 3 | * its stretches named in Server-Timing, and warm inside 50 ms, with no client fetch for the page. |
| 4 | 4 | */ |
| 5 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| @@ -71,10 +71,10 @@ test("the warm first paint holds the budget", async () => { | ||
| 71 | 71 | expect(Math.min(...runs)).toBeLessThan(BUDGET_MS); |
| 72 | 72 | }); |
| 73 | 73 | |
| 74 | test("the first twenty posts are in the HTML, and no script fetches them", async () => { | |
| 74 | test("the first thirty posts are in the HTML, and no script fetches them", async () => { | |
| 75 | 75 | const { html } = await look("/feed"); |
| 76 | 76 | const cards = html.match(/data-item=/g) ?? []; |
| 77 | expect(cards.length).toBe(20); | |
| 77 | expect(cards.length).toBe(30); | |
| 78 | 78 | expect(html).toContain("post "); |
| 79 | 79 | // The page asks for more only by a plain link, never by a script's fetch of the feed. |
| 80 | 80 | expect(html).not.toMatch(/fetch\(\s*['"`]\/api\/v1\/feed(?!\/)/); |
test/feed-cursor.test.ts +38
| @@ -236,3 +236,41 @@ describe("the feed pages by cursor", () => { | ||
| 236 | 236 | expect(on).toContain('data-item="event:'); |
| 237 | 237 | }); |
| 238 | 238 | }); |
| 239 | ||
| 240 | describe("the feed page pages 70 posts, 30 at a time", () => { | |
| 241 | test("no overlap and no gap, by plain links", async () => { | |
| 242 | const dataDir = await mkdtemp(join(tmpdir(), "forge-feed-70-")); | |
| 243 | const app = createApp({ dataDir, port: 0 }); | |
| 244 | const servers = await serve(app); | |
| 245 | try { | |
| 246 | const r = await createUser(app.db, { | |
| 247 | origin: "seed", trusted: true, username: "dana", allowReserved: true, | |
| 248 | email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true, | |
| 249 | }); | |
| 250 | if (!r.ok) throw new Error(r.error); | |
| 251 | promote(app.db, r.value); | |
| 252 | const repo = await createRepo(app, r.value, { name: "open", visibility: "public" }); | |
| 253 | if (!repo.ok) throw new Error("repo"); | |
| 254 | for (let n = 1; n <= 70; n++) | |
| 255 | app.bus.append({ kind: "issue.opened", repoId: repo.value.id, actorId: r.value.id, payload: { number: n } }); | |
| 256 | const cookie = `forge_session=${createSession(app.db, r.value.id).token}`; | |
| 257 | const ids: string[] = []; | |
| 258 | const sizes: number[] = []; | |
| 259 | let path: string | undefined = "/feed?before=now"; | |
| 260 | while (path !== undefined) { | |
| 261 | const html = await (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text(); | |
| 262 | const found = [...html.matchAll(/data-item="(event:[^"]+)"/g)].map((m) => m[1]!); | |
| 263 | sizes.push(found.length); | |
| 264 | ids.push(...found); | |
| 265 | const next = /href="(\/feed\?before=[0-9a-z]{26})">Older posts/.exec(html); | |
| 266 | path = next?.[1]; | |
| 267 | } | |
| 268 | expect(sizes).toEqual([30, 30, 10]); | |
| 269 | expect(new Set(ids).size).toBe(70); | |
| 270 | } finally { | |
| 271 | servers.stop(); | |
| 272 | app.close(); | |
| 273 | await rm(dataDir, { recursive: true, force: true }); | |
| 274 | } | |
| 275 | }); | |
| 276 | }); |
new above
offline