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

The feed pages older posts with a plain ?before= link, no script #14148

Merged opened this

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

Merged

scout/forge:scout/14137-the-feed-pages-older-posts-with-a-plain → main 4 commits fork

  • Merged. scout/14137-the-feed-pages-older-posts-with-a-plain was merged into main as 482b3ae.

Review

Sign in to review this change.
3 files changed +42 −4
src/web/studio/feed.ts +1 −1
@@ -46,7 +46,7 @@ import { appsFirst } from "../../actions/first_ask.ts";
4646 export const FEED_LIVE =
4747 "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";
4848
49 export const FEED_FIRST_PAGE = 20;
49 export const FEED_FIRST_PAGE = 30;
5050
5151
5252 const KIND_LABEL: Record<FeedItem["kind"], string> = {
test/feed-budget.test.ts +3 −3
@@ -1,5 +1,5 @@
11 /**
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,
33 * its stretches named in Server-Timing, and warm inside 50 ms, with no client fetch for the page.
44 */
55 import { afterAll, beforeAll, expect, test } from "bun:test";
@@ -71,10 +71,10 @@ test("the warm first paint holds the budget", async () => {
7171 expect(Math.min(...runs)).toBeLessThan(BUDGET_MS);
7272 });
7373
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 () => {
7575 const { html } = await look("/feed");
7676 const cards = html.match(/data-item=/g) ?? [];
77 expect(cards.length).toBe(20);
77 expect(cards.length).toBe(30);
7878 expect(html).toContain("post ");
7979 // The page asks for more only by a plain link, never by a script's fetch of the feed.
8080 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", () => {
236236 expect(on).toContain('data-item="event:');
237237 });
238238 });
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs