Public: anyone can read this; the crew can change it.
A post in the feed shows who made it and when as one quiet line, and the time is the same one the thread shows #14623
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14588-a-post-in-the-feed-shows-who-made-it-and → main 2 commits fork 1 thread · 1 unresolved
4 files
changed +101
−2
src/feed/items.ts +5 −2
| @@ -743,7 +743,7 @@ function fromEvent( | ||
| 743 | 743 | }; |
| 744 | 744 | } |
| 745 | 745 | case "pull.opened": |
| 746 | return { ...common, kind: "pull", link: change, what: `opened a pull request${title ? `: ${clip(title)}` : ""}${toldWords}` }; | |
| 746 | return { ...common, at: subjects.issue(repo.id, number!)?.createdAt ?? common.at, kind: "pull", link: change, what: `opened a pull request${title ? `: ${clip(title)}` : ""}${toldWords}` }; | |
| 747 | 747 | case "pull.merged": { |
| 748 | 748 | // A trusted source's landing is credited as it happens (#9015): |
| 749 | 749 | // where it came from, and whose work it is. |
| @@ -800,9 +800,12 @@ function fromEvent( | ||
| 800 | 800 | // A tell is a post; a comment is a reply under it, in its own words. |
| 801 | 801 | case "issue.opened": { |
| 802 | 802 | if (number === undefined) return undefined; |
| 803 | const told = subjects.issue(repo.id, number)?.title ?? ""; | |
| 803 | const thread = subjects.issue(repo.id, number); | |
| 804 | const told = thread?.title ?? ""; | |
| 804 | 805 | return { |
| 805 | 806 | ...common, |
| 807 | // The thread's opening card says when the issue was made: the post says the same instant. | |
| 808 | at: thread?.createdAt ?? common.at, | |
| 806 | 809 | kind: "tell", |
| 807 | 810 | link: `${base(repo)}/issues/${number}`, |
| 808 | 811 | what: `opened an issue: ${told === "" ? `#${number}` : clip(told)}`, |
src/web/studio/feed.ts +2
| @@ -73,6 +73,8 @@ const KIND_LABEL: Record<FeedItem["kind"], string> = { | ||
| 73 | 73 | */ |
| 74 | 74 | const saysMore = (item: FeedItem): boolean => |
| 75 | 75 | !item.reason.startsWith(item.what) && |
| 76 | // The age is on the byline already, once: never again beneath the headline in other words. | |
| 77 | !/^(just now|an hour ago|yesterday|\d+ (minutes|hours|days) ago)$/.test(item.reason) && | |
| 76 | 78 | !/^because you (own|work on|pinned) /.test(item.reason); |
| 77 | 79 | |
| 78 | 80 | /** A look post's thumbnail: its address and the size it is drawn at, so nothing shifts. */ |
test/feed-issue-fold.test.ts +2
| @@ -130,6 +130,8 @@ describe("folding a burst of issues", () => { | ||
| 130 | 130 | ids.forEach((r, i) => |
| 131 | 131 | app.db.query("UPDATE event SET created_at = ?1 WHERE id = ?2").run(new Date(Date.now() - 3600_000 + i * 180_000).toISOString(), r.id), |
| 132 | 132 | ); |
| 133 | // A post says when its issue was made (#14588), so the issues move with the events. | |
| 134 | app.db.query("UPDATE issue SET created_at = (SELECT created_at FROM event WHERE kind = 'issue.opened' AND event.repo_id = issue.repo_id AND json_extract(event.payload, '$.number') = issue.number)").run(); | |
| 133 | 135 | const mine = posts().filter((i) => i.actor === "alice"); |
| 134 | 136 | expect(mine).toHaveLength(11); |
| 135 | 137 | expect(mine.every((i) => i.lines === undefined)).toBe(true); |
test/feed-post-byline.test.ts added +92
| @@ -0,0 +1,92 @@ | ||
| 1 | /** | |
| 2 | * A post in the feed reads who, what, when: author and age on one quiet line, and the thread of the | |
| 3 | * same post shows the same instant (#14588). | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, setSystemTime, test } from "bun:test"; | |
| 6 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { openIssue } from "../src/actions/issues.ts"; | |
| 10 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { createSession } from "../src/core/sessions.ts"; | |
| 13 | import { createUser } from "../src/core/users.ts"; | |
| 14 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 15 | import { timeAgo } from "../src/web/ui.ts"; | |
| 16 | import { quietLogs } from "./helpers/globals.ts"; | |
| 17 | ||
| 18 | quietLogs(); | |
| 19 | ||
| 20 | let root = ""; | |
| 21 | let app: App; | |
| 22 | let servers: Servers; | |
| 23 | let cookie = ""; | |
| 24 | let number = 0; | |
| 25 | ||
| 26 | const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 27 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 28 | return r.value; | |
| 29 | }; | |
| 30 | ||
| 31 | beforeAll(async () => { | |
| 32 | root = mkdtempSync(join(tmpdir(), "forge-feed-byline-")); | |
| 33 | app = createApp({ dataDir: root, port: 0, disk: () => ({ freeBytes: 95, totalBytes: 100 }) }); | |
| 34 | servers = await serve(app); | |
| 35 | const alice = must( | |
| 36 | await createUser(app.db, { | |
| 37 | origin: "seed", trusted: true, allowReserved: true, username: "alice", | |
| 38 | email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true, | |
| 39 | }), | |
| 40 | ); | |
| 41 | cookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 42 | const repo = must(await createRepo(app, alice, { name: "open", visibility: "public" })); | |
| 43 | must(await commitToBranch(app, alice, repo, { message: "seed", files: [{ path: "README.md", content: "# r\n" }] })); | |
| 44 | number = must(openIssue(app, alice, repo, { title: "Byline please", body: "why?" })).number; | |
| 45 | }, 30_000); | |
| 46 | ||
| 47 | afterAll(async () => { | |
| 48 | await servers.stop(); | |
| 49 | app.close(); | |
| 50 | rmSync(root, { recursive: true, force: true }); | |
| 51 | }); | |
| 52 | ||
| 53 | const get = async (path: string) => (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text(); | |
| 54 | const stamps = (html: string) => [...html.matchAll(/<time datetime="([^"]+)"\s+title="([^"]+)"\s*>([^<]*)<\/time/g)]; | |
| 55 | ||
| 56 | test("the feed card names the author and the age on one line, and the thread shows the same time", async () => { | |
| 57 | const feed = await get("/feed"); | |
| 58 | const card = feed.split("data-item=").find((a) => a.includes(`/alice/open/issues/${number}"`)); | |
| 59 | expect(card).toBeDefined(); | |
| 60 | // One line: the author, then the app and the age, in the card's head. | |
| 61 | const line = /<strong[^>]*>alice<\/strong\s*>[\s\S]*?<span class="muted small break">[\s\S]*?<time [\s\S]*?<\/time\s*>/.exec(card!); | |
| 62 | expect(line).not.toBeNull(); | |
| 63 | expect(line![0]).not.toContain("</p>"); | |
| 64 | const fromFeed = stamps(card!).find((s) => s[0].includes("datetime"))!; | |
| 65 | ||
| 66 | const thread = await get(`/alice/open/issues/${number}`); | |
| 67 | const fromThread = stamps(thread)[0]!; | |
| 68 | expect(fromThread[1]).toBe(fromFeed[1]); // the same instant | |
| 69 | expect(fromThread[2]).toBe(fromFeed[2]); // the same exact title | |
| 70 | expect(fromThread[3]).toBe(fromFeed[3]); // the same words | |
| 71 | expect(fromFeed[3]).toBe(timeAgo(fromFeed[1]!)); | |
| 72 | }); | |
| 73 | ||
| 74 | test("hours later, the timeline and the thread still say the same age, and the card says it once", async () => { | |
| 75 | setSystemTime(new Date(Date.now() + 3 * 3_600_000 + 60_000)); | |
| 76 | try { | |
| 77 | for (const path of ["/feed", "/feed?before=now"]) { | |
| 78 | const feed = await get(path); | |
| 79 | const card = feed.split("data-item=").find((a) => a.includes(`/alice/open/issues/${number}"`))!.split("card-foot")[0]!; | |
| 80 | expect(card).toBeDefined(); | |
| 81 | const fromFeed = stamps(card)[0]!; | |
| 82 | const fromThread = stamps(await get(`/alice/open/issues/${number}`))[0]!; | |
| 83 | expect(fromFeed[3]).toBe("3h ago"); | |
| 84 | expect(fromThread[3]).toBe(fromFeed[3]); | |
| 85 | expect(fromThread[1]).toBe(fromFeed[1]); | |
| 86 | // The age is not said again beneath the headline in other words. | |
| 87 | expect(card).not.toMatch(/hours? ago/); | |
| 88 | } | |
| 89 | } finally { | |
| 90 | setSystemTime(); | |
| 91 | } | |
| 92 | }); |
new above
offline
Principle 8 and fragility: this regex duplicates the wording of ago() and misses weeks, months and years. Compare item.reason to ago(item.at) instead.