Public: anyone can read this; the crew can change it.
A crew run posted in the feed opens its log in one tap #13146
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13125-a-crew-run-posted-in-the-feed-opens-its → main 14 commits fork 8 threads · 8 unresolved
docs/features/README.md +1
| @@ -24,6 +24,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 24 | 24 | - [](engine-shape.md) |
| 25 | 25 | - [](feed-fold.md) |
| 26 | 26 | - [](feed-permalink.md) |
| 27 | - [](feed-run-log.md) | |
| 27 | 28 | - [](feed-like-ledger.md) |
| 28 | 29 | - [](packs.md) |
| 29 | 30 | - [](home-frame.md) |
docs/features/feed-run-log.md added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | # A run post opens its log | |
| 2 | ||
| 3 | A crew run posted in the feed is one step from the run's log. | |
| 4 | ||
| 5 | ## How to open it | |
| 6 | ||
| 7 | - **Page:** on `/feed`, the post's headline is a plain link to the run's page, where the log is. No script is involved. | |
| 8 | - **Terminal:** open Feed from the palette, move to the run post with `j`/`k` and press `o`; the run's log screen opens. `esc` comes back to the feed. The key is listed only on a post about a run. | |
| 9 | ||
| 10 | ## What is not linked | |
| 11 | ||
| 12 | A run post whose link is not a run page (a sync failure points to the app) has no log to open: its headline on the page is plain text, not a link, and `o` does nothing. A reader who may not read the repository gets no log in either door: the page filters the feed by what the viewer may see, and `o` asks the same read check (`runTarget` in `src/feed/run_link.ts`, beside the `runLinkOf` the page headline asks). |
src/feed/run_link.ts added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | /** | |
| 2 | * The run page a feed post's link names: `/<owner>/<name>/runs/<id>`, optionally at a failing log | |
| 3 | * line (`?all=1#L<n>`). Plain data: the web headline and the terminal's `o` both ask here, so a | |
| 4 | * post links to a run only when it is one. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { Database } from "bun:sqlite"; | |
| 8 | import type { Repo } from "../core/repos.ts"; | |
| 9 | import type { User } from "../core/users.ts"; | |
| 10 | import { replyRepo } from "./reply.ts"; | |
| 11 | ||
| 12 | const RUN_LINK = /^\/([^/]+)\/([^/]+)\/runs\/([A-Za-z0-9_-]+)(?:\?all=1#L\d+)?$/; | |
| 13 | ||
| 14 | export type RunLink = { app: string; runId: string; page: string }; | |
| 15 | ||
| 16 | /** The run the link names in the post's own app; undefined when it names anything else. */ | |
| 17 | export function runLinkOf(item: { app: string; link: string }): RunLink | undefined { | |
| 18 | const m = RUN_LINK.exec(item.link); | |
| 19 | if (m === null || `${m[1]}/${m[2]}` !== item.app) return undefined; | |
| 20 | return { app: item.app, runId: m[3]!, page: `/${item.app}/runs/${m[3]!}` }; | |
| 21 | } | |
| 22 | ||
| 23 | /** The run a post's link names, with a repository the viewer may read; undefined otherwise. */ | |
| 24 | export function runTarget( | |
| 25 | db: Database, | |
| 26 | viewer: User | undefined, | |
| 27 | item: { app: string; link: string }, | |
| 28 | ): { runId: string; repo: Repo } | undefined { | |
| 29 | const run = runLinkOf(item); | |
| 30 | const repo = run === undefined ? undefined : replyRepo(db, viewer, item.app); | |
| 31 | return run === undefined || repo === undefined ? undefined : { runId: run.runId, repo }; | |
| 32 | } |
src/tui/screens/feed.ts +16 −2
| @@ -9,7 +9,8 @@ | ||
| 9 | 9 | * page's Like, behind the same `readInteraction` check (`feed/likes.ts`); `h` lists who liked or |
| 10 | 10 | * unliked it and when, newest first, behind that check too; the owner's row also says "Liked by …" |
| 11 | 11 | * (`likedByLine`, the page's line, gated by `feed/feed.ts`). `p` says the post's permalink |
| 12 | * (`permalinkOf`, the page's time link) in a toast. Twenty posts at a time; `t` switches to every | |
| 12 | * (`permalinkOf`, the page's time link) in a toast. `o` opens the log of the run a run post is | |
| 13 | * about, the page's headline link (`runTarget`). Twenty posts at a time; `t` switches to every | |
| 13 | 14 | * post, newest first (`readTimeline`); `m` narrows that to only mine (its `mine` option, the page's |
| 14 | 15 | * `?show=mine`); `n` reads the next page from the cursor the last returned. |
| 15 | 16 | */ |
| @@ -22,6 +23,7 @@ import type { FeedItem } from "../../feed/rank.ts"; | ||
| 22 | 23 | import { readInteraction } from "../../feed/interact.ts"; |
| 23 | 24 | import { likeLedger, likersOf, toggleLike } from "../../feed/likes.ts"; |
| 24 | 25 | import { permalinkOf, replyTarget } from "../../feed/reply.ts"; |
| 26 | import { runTarget } from "../../feed/run_link.ts"; | |
| 25 | 27 | import type { Ctx, Screen } from "../app/app.ts"; |
| 26 | 28 | import { binding } from "../app/keys.ts"; |
| 27 | 29 | import type { Session } from "../session.ts"; |
| @@ -33,6 +35,7 @@ import { emptyState } from "../ui/widgets.ts"; | ||
| 33 | 35 | import { EMPTY_FEED, likedByLine } from "../../web/studio/feed.ts"; |
| 34 | 36 | import { ListState, ago, drawList, errorText, runAsync, type ListRow } from "./common.ts"; |
| 35 | 37 | import type { PaletteEntry } from "./entries.ts"; |
| 38 | import { runLogScreen } from "./runlog.ts"; | |
| 36 | 39 | import { Composer } from "./thread.ts"; |
| 37 | 40 | |
| 38 | 41 | const PAGE = 20; |
| @@ -146,6 +149,13 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 146 | 149 | ctx.toast(`permalink ${permalinkOf(item.link)}`); |
| 147 | 150 | }; |
| 148 | 151 | |
| 152 | /** `o`: the log of the run the post under the cursor is about, when the viewer may read it. */ | |
| 153 | const openLog = (): void => { | |
| 154 | const item = items[state.index]; | |
| 155 | const at = item === undefined ? undefined : runTarget(f.db, f.user, item); | |
| 156 | if (at !== undefined) ctx.push(runLogScreen(f, ctx, at.repo, at.runId)); | |
| 157 | }; | |
| 158 | ||
| 149 | 159 | const submit = (): void => { |
| 150 | 160 | const at = selected(); |
| 151 | 161 | if (at === undefined) return; |
| @@ -173,6 +183,9 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 173 | 183 | ...(items.length === 0 ? [] : [binding(["l"], "like")]), |
| 174 | 184 | ...(items.length === 0 ? [] : [binding(["h"], "who liked")]), |
| 175 | 185 | ...(items.length === 0 ? [] : [binding(["p"], "permalink")]), |
| 186 | ...(items[state.index] !== undefined && runTarget(f.db, f.user, items[state.index]!) !== undefined | |
| 187 | ? [binding(["o"], "open the log")] | |
| 188 | : []), | |
| 176 | 189 | ...(next === null ? [] : [binding(["n"], "next page")]), |
| 177 | 190 | binding(["t"], timeline || mine ? "ranked" : "newest first"), |
| 178 | 191 | binding(["m"], mine ? "everyone's" : "only mine"), |
| @@ -238,6 +251,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 238 | 251 | else if (e.key === "l") like(); |
| 239 | 252 | else if (e.key === "h") showHistory(); |
| 240 | 253 | else if (e.key === "p") permalink(); |
| 254 | else if (e.key === "o") openLog(); | |
| 241 | 255 | else if (e.key === "t" || e.key === "m") { |
| 242 | 256 | if (e.key === "m") mine = !mine; |
| 243 | 257 | else { |
| @@ -260,7 +274,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 260 | 274 | export const entry: PaletteEntry = { |
| 261 | 275 | id: "feed", |
| 262 | 276 | title: "Feed", |
| 263 | hint: "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink", | |
| 277 | hint: "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log", | |
| 264 | 278 | offered: (session) => session.user !== undefined, |
| 265 | 279 | run: (session, ctx) => ctx.push(feedScreen(session, ctx)), |
| 266 | 280 | }; |
src/web/studio/feed.ts +8 −3
| @@ -22,6 +22,7 @@ import { parseShow, type Show } from "../../feed/mine.ts"; | ||
| 22 | 22 | import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts"; |
| 23 | 23 | import type { FeedItem } from "../../feed/rank.ts"; |
| 24 | 24 | import { permalinkOf, replyPath, replyRepo, threadOf } from "../../feed/reply.ts"; |
| 25 | import { runLinkOf } from "../../feed/run_link.ts"; | |
| 25 | 26 | import { getAppByRepo } from "../../core/apps.ts"; |
| 26 | 27 | import { getRepo, getRepoById } from "../../core/repos.ts"; |
| 27 | 28 | import { DEFAULT_PAGE, looksForEnv, lookUrl } from "../../core/looks.ts"; |
| @@ -44,7 +45,6 @@ export const FEED_LIVE = | ||
| 44 | 45 | |
| 45 | 46 | export const FEED_FIRST_PAGE = 20; |
| 46 | 47 | |
| 47 | const RUN_LINK = /^\/[^/]+\/[^/]+\/runs\/[A-Za-z0-9_-]+$/; | |
| 48 | 48 | |
| 49 | 49 | const KIND_LABEL: Record<FeedItem["kind"], string> = { |
| 50 | 50 | run: "Run", |
| @@ -161,7 +161,12 @@ export function feedCard( | ||
| 161 | 161 | const thread = linked !== undefined && `${linked.owner}/${linked.name}` === item.app ? linked : undefined; |
| 162 | 162 | const reply = thread !== undefined; |
| 163 | 163 | const steer = item.kind === "run" || item.kind === "cost"; |
| 164 | const target = steer && RUN_LINK.test(item.link) ? `${item.link}/steer` : null; | |
| 164 | const run = runLinkOf(item); | |
| 165 | const target = steer && run !== undefined ? `${run.page}/steer` : null; | |
| 166 | // A run post links its headline only to a run page; one without (a sync failure) is plain text. | |
| 167 | const headline = item.kind === "run" && run === undefined | |
| 168 | ? html`<p class="break">${item.what}</p>` | |
| 169 | : html`<p class="break"><a href="${item.link}" data-feed-open>${item.what}</a></p>`; | |
| 165 | 170 | const head = html`${avatar(item.actor ?? item.app)} |
| 166 | 171 | <strong class="break">${item.actor ?? item.app}</strong |
| 167 | 172 | >${nameMark(item.actor === null ? undefined : marks.get(item.actor))} |
| @@ -174,7 +179,7 @@ export function feedCard( | ||
| 174 | 179 | : html`<ul class="list">${item.lines.map((l) => row({ href: l.link, title: l.text }))}${item.more ? row({ title: `and ${item.more} more` }) : null}</ul>`; |
| 175 | 180 | const body = html`${item.opens === true |
outdated
Principle 1: the headline |
||
| 176 | 181 | ? html`<details class="feed-fold"><summary class="break">${item.what}</summary>${lineList}</details>` |
| 177 | : html`<p class="break"><a href="${item.link}" data-feed-open>${item.what}</a></p>`} | |
| 182 | : headline} | |
| 178 | 183 | ${item.opens === true ? null : lineList} |
| 179 | 184 | ${item.look === undefined |
| 180 | 185 | ? null |
test/feed-run-link.test.ts added +40
| @@ -0,0 +1,40 @@ | ||
| 1 | /** A run post's headline links to its run page, and only when the post names one. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import type { FeedItem } from "../src/feed/rank.ts"; | |
| 4 | import { runLinkOf } from "../src/feed/run_link.ts"; | |
| 5 | import { feedCard } from "../src/web/studio/feed.ts"; | |
| 6 | ||
| 7 | const post = (link: string, kind: FeedItem["kind"] = "run"): string => { | |
| 8 | const item: FeedItem = { | |
| 9 | id: "i1", kind, app: "a/b", actor: "a", at: new Date().toISOString(), link, | |
| 10 | what: "Shipped", reason: "", score: 1, | |
| 11 | }; | |
| 12 | return String(feedCard(item)); | |
| 13 | }; | |
| 14 | ||
| 15 | test("a run post links its headline to the run's page", () => { | |
| 16 | expect(post("/a/b/runs/r1")).toContain('<a href="/a/b/runs/r1" data-feed-open>Shipped</a>'); | |
| 17 | }); | |
| 18 | ||
| 19 | test("a failed run's post links its headline to the failing line of the log", () => { | |
| 20 | expect(post("/a/b/runs/r1?all=1#L12")).toContain('<a href="/a/b/runs/r1?all=1#L12" data-feed-open>Shipped</a>'); | |
| 21 | }); | |
| 22 | ||
| 23 | test("a run post with no run page (a sync failure) has no headline anchor", () => { | |
| 24 | const html = post("/a/b/app"); | |
| 25 | expect(html).toContain('<p class="break">Shipped</p>'); | |
outdated
This asserts the link the issue says must not exist. A post with no run page should render the headline without an anchor; the test should fail on main. |
||
| 26 | expect(html).not.toContain('<a href="/a/b/app" data-feed-open>'); | |
| 27 | expect(html).not.toContain("data-feed-open"); | |
| 28 | }); | |
| 29 | ||
| 30 | test("a post that is not about a run keeps its headline link", () => { | |
| 31 | expect(post("/a/b/issues/3", "pull")).toContain('<a href="/a/b/issues/3" data-feed-open>Shipped</a>'); | |
| 32 | }); | |
| 33 | ||
| 34 | test("a run link names a run only in the post's own app", () => { | |
| 35 | expect(runLinkOf({ app: "a/b", link: "/a/b/runs/r1" })).toEqual({ app: "a/b", runId: "r1", page: "/a/b/runs/r1" }); | |
| 36 | expect(runLinkOf({ app: "a/b", link: "/a/b/runs/r1?all=1#L4" })?.page).toBe("/a/b/runs/r1"); | |
| 37 | expect(runLinkOf({ app: "a/b", link: "/x/y/runs/r1" })).toBeUndefined(); | |
| 38 | expect(runLinkOf({ app: "a/b", link: "/a/b/app" })).toBeUndefined(); | |
| 39 | expect(runLinkOf({ app: "a/b", link: "/a/b/runs/r1/steer" })).toBeUndefined(); | |
| 40 | }); |
test/palette-roster.test.ts +3 −3
| @@ -199,7 +199,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 199 | 199 | ["bets", "Bets", "back, stop and finish a repository\'s bets"], |
| 200 | 200 | ["origins", "Connected accounts", "the hosts your mirrors come from"], |
| 201 | 201 | ["domains", "Failure domains", "failure domains and their last drill"], |
| 202 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink"], | |
| 202 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log"], | |
| 203 | 203 | ["feature-review", "Menu entries to review", "absorbed apps whose declared name or page changed: accept them"], |
| 204 | 204 | ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"], |
| 205 | 205 | ["features", "Features", "apps that declare a feature: absorb one, change its settings"], |
| @@ -294,7 +294,7 @@ test("a site-admin agent is offered the roster without the person-only entries", | ||
| 294 | 294 | ["plan-row", "Plan", "this forge's plan, and where its owner manages billing"], |
| 295 | 295 | ["cloud", "Cloud accounts", "provider tokens, what they are used for, today's calls"], |
| 296 | 296 | ["pinned", "Pinned forges", "deploy, update and roll back a forge on your cloud"], |
| 297 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink"], | |
| 297 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log"], | |
| 298 | 298 | ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"], |
| 299 | 299 | ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"], |
| 300 | 300 | ["forges", "Forges you sent", "each forge sent, claimed or not, and its apps"], |
| @@ -391,7 +391,7 @@ test("a member person is offered the signed-in roster without the admin entries" | ||
| 391 | 391 | ["bulk", "Bulk actions", "your last bulk actions; u undoes one inside its day"], |
| 392 | 392 | ["bets", "Bets", "back, stop and finish a repository\'s bets"], |
| 393 | 393 | ["origins", "Connected accounts", "the hosts your mirrors come from"], |
| 394 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink"], | |
| 394 | ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log"], | |
| 395 | 395 | ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"], |
| 396 | 396 | ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"], |
| 397 | 397 | ["origin-ahead", "New commits upstream", "mirrors whose origin has moved on: take them"], |
test/tui-feed-run-log.test.ts added +63
| @@ -0,0 +1,63 @@ | ||
| 1 | /** | |
| 2 | * `o` on a feed run post opens the run it names, for a viewer who may read its repository, and no | |
| 3 | * other. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { runTarget } from "../src/feed/run_link.ts"; | |
| 10 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { createUser, getUserByName } from "../src/core/users.ts"; | |
| 13 | import { quietLogs } from "./helpers/globals.ts"; | |
| 14 | import { promote } from "./helpers/members.ts"; | |
| 15 | ||
| 16 | quietLogs(); | |
| 17 | ||
| 18 | let dir = ""; | |
| 19 | let forge: App; | |
| 20 | ||
| 21 | beforeAll(async () => { | |
| 22 | dir = await mkdtemp(join(tmpdir(), "forge-tui-feed-run-log-")); | |
| 23 | forge = createApp({ dataDir: dir, port: 0 }); | |
| 24 | for (const [username, first] of [["root", true], ["alice", false], ["bob", false]] as const) { | |
| 25 | const made = await createUser(forge.db, { | |
| 26 | origin: "seed", trusted: true, allowReserved: true, username, email: `${username}@forge.local`, | |
| 27 | password: "a-good-passphrase", adminIfFirst: first, | |
| 28 | }); | |
| 29 | if (!made.ok) throw new Error(made.error); | |
| 30 | promote(forge.db, made.value); | |
| 31 | } | |
| 32 | const alice = getUserByName(forge.db, "alice")!; | |
| 33 | for (const [name, visibility] of [["open", "public"], ["secret", "private"]] as const) { | |
| 34 | const made = await createRepo(forge, alice, { name, visibility }); | |
| 35 | if (!made.ok) throw new Error(String(made.error)); | |
| 36 | } | |
| 37 | }); | |
| 38 | ||
| 39 | afterAll(async () => { | |
| 40 | forge.db.close(); | |
| 41 | await rm(dir, { recursive: true, force: true }); | |
| 42 | }); | |
| 43 | ||
| 44 | test("a run post names its run for a viewer who may read the repository", () => { | |
| 45 | const bob = getUserByName(forge.db, "bob")!; | |
| 46 | const got = runTarget(forge.db, bob, { app: "alice/open", link: "/alice/open/runs/r1" }); | |
| 47 | expect(got?.runId).toBe("r1"); | |
| 48 | expect(got?.repo.name).toBe("open"); | |
| 49 | expect(runTarget(forge.db, bob, { app: "alice/open", link: "/alice/open/runs/r1?all=1#L3" })?.runId).toBe("r1"); | |
| 50 | }); | |
| 51 | ||
| 52 | test("no target for a private repository the viewer cannot read, or when signed out", () => { | |
| 53 | const bob = getUserByName(forge.db, "bob")!; | |
| 54 | expect(runTarget(forge.db, bob, { app: "alice/secret", link: "/alice/secret/runs/r1" })).toBeUndefined(); | |
| 55 | expect(runTarget(forge.db, undefined, { app: "alice/open", link: "/alice/open/runs/r1" })).toBeUndefined(); | |
| 56 | }); | |
| 57 | ||
| 58 | test("a post that does not name a run of its own app has no target", () => { | |
| 59 | const bob = getUserByName(forge.db, "bob")!; | |
| 60 | expect(runTarget(forge.db, bob, { app: "alice/open", link: "/alice/open/app" })).toBeUndefined(); | |
| 61 | expect(runTarget(forge.db, bob, { app: "alice/open", link: "/alice/open/issues/1" })).toBeUndefined(); | |
| 62 | expect(runTarget(forge.db, bob, { app: "alice/open", link: "/alice/secret/runs/r1" })).toBeUndefined(); | |
| 63 | }); | |
Non-blocking: the tests cover runTarget but not the |
Non-blocking: leftover double blank line where RUN_LINK was removed.