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

A crew run posted in the feed opens its log in one tap #13146

Merged opened this

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

Merged

scout/forge:scout/13125-a-crew-run-posted-in-the-feed-opens-its → main 14 commits fork 8 threads · 8 unresolved

  • Merged. scout/13125-a-crew-run-posted-in-the-feed-opens-its was merged into main as 947df62.

Review

Sign in to review this change.
8 files changed +175 −8
docs/features/README.md +1
@@ -24,6 +24,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md).
2424 - [Engine shape](engine-shape.md)
2525 - [Feed fold](feed-fold.md)
2626 - [A feed post has a permalink](feed-permalink.md)
27 - [A run post opens its log](feed-run-log.md)
2728 - [Feed likes: the ledger](feed-like-ledger.md)
2829 - [Forge packs: a premade forge to deploy (`/packs`)](packs.md)
2930 - [Home paints its frame first](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/tui/screens/feed.ts +16 −2
@@ -9,7 +9,8 @@
99 * page's Like, behind the same `readInteraction` check (`feed/likes.ts`); `h` lists who liked or
1010 * unliked it and when, newest first, behind that check too; the owner's row also says "Liked by …"
1111 * (`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
1314 * post, newest first (`readTimeline`); `m` narrows that to only mine (its `mine` option, the page's
1415 * `?show=mine`); `n` reads the next page from the cursor the last returned.
1516 */
@@ -22,6 +23,7 @@ import type { FeedItem } from "../../feed/rank.ts";
2223 import { readInteraction } from "../../feed/interact.ts";
2324 import { likeLedger, likersOf, toggleLike } from "../../feed/likes.ts";
2425 import { permalinkOf, replyTarget } from "../../feed/reply.ts";
26 import { runTarget } from "../../feed/run_link.ts";
2527 import type { Ctx, Screen } from "../app/app.ts";
2628 import { binding } from "../app/keys.ts";
2729 import type { Session } from "../session.ts";
@@ -33,6 +35,7 @@ import { emptyState } from "../ui/widgets.ts";
3335 import { EMPTY_FEED, likedByLine } from "../../web/studio/feed.ts";
3436 import { ListState, ago, drawList, errorText, runAsync, type ListRow } from "./common.ts";
3537 import type { PaletteEntry } from "./entries.ts";
38 import { runLogScreen } from "./runlog.ts";
3639 import { Composer } from "./thread.ts";
3740
3841 const PAGE = 20;
@@ -146,6 +149,13 @@ export function feedScreen(f: Session, ctx: Ctx): Screen {
146149 ctx.toast(`permalink ${permalinkOf(item.link)}`);
147150 };
148151
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
149159 const submit = (): void => {
150160 const at = selected();
151161 if (at === undefined) return;
@@ -173,6 +183,9 @@ export function feedScreen(f: Session, ctx: Ctx): Screen {
173183 ...(items.length === 0 ? [] : [binding(["l"], "like")]),
174184 ...(items.length === 0 ? [] : [binding(["h"], "who liked")]),
175185 ...(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 : []),
176189 ...(next === null ? [] : [binding(["n"], "next page")]),
177190 binding(["t"], timeline || mine ? "ranked" : "newest first"),
178191 binding(["m"], mine ? "everyone's" : "only mine"),
@@ -238,6 +251,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen {
238251 else if (e.key === "l") like();
239252 else if (e.key === "h") showHistory();
240253 else if (e.key === "p") permalink();
254 else if (e.key === "o") openLog();
241255 else if (e.key === "t" || e.key === "m") {
242256 if (e.key === "m") mine = !mine;
243257 else {
@@ -260,7 +274,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen {
260274 export const entry: PaletteEntry = {
261275 id: "feed",
262276 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",
264278 offered: (session) => session.user !== undefined,
265279 run: (session, ctx) => ctx.push(feedScreen(session, ctx)),
266280 };
src/web/studio/feed.ts +8 −3
@@ -22,6 +22,7 @@ import { parseShow, type Show } from "../../feed/mine.ts";
2222 import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts";
2323 import type { FeedItem } from "../../feed/rank.ts";
2424 import { permalinkOf, replyPath, replyRepo, threadOf } from "../../feed/reply.ts";
25 import { runLinkOf } from "../../feed/run_link.ts";
2526 import { getAppByRepo } from "../../core/apps.ts";
2627 import { getRepo, getRepoById } from "../../core/repos.ts";
2728 import { DEFAULT_PAGE, looksForEnv, lookUrl } from "../../core/looks.ts";
@@ -44,7 +45,6 @@ export const FEED_LIVE =
4445
4546 export const FEED_FIRST_PAGE = 20;
4647
47 const RUN_LINK = /^\/[^/]+\/[^/]+\/runs\/[A-Za-z0-9_-]+$/;
4848

Non-blocking: leftover double blank line where RUN_LINK was removed.

4949 const KIND_LABEL: Record<FeedItem["kind"], string> = {
5050 run: "Run",
@@ -161,7 +161,12 @@ export function feedCard(
161161 const thread = linked !== undefined && `${linked.owner}/${linked.name}` === item.app ? linked : undefined;
162162 const reply = thread !== undefined;
163163 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>`;
165170 const head = html`${avatar(item.actor ?? item.app)}
166171 <strong class="break">${item.actor ?? item.app}</strong
167172 >${nameMark(item.actor === null ? undefined : marks.get(item.actor))}
@@ -174,7 +179,7 @@ export function feedCard(
174179 : 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>`;
175180 const body = html`${item.opens === true
outdated

Principle 1: the headline <a href=item.link data-feed-open> just above already goes to this run; a second link to the same URL explains itself twice. Make the headline the one-tap door (e.g. clearer affordance) instead of adding a line. Also the terminal feed has no matching action (both doors).

176181 ? 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}
178183 ${item.opens === true ? null : lineList}
179184 ${item.look === undefined
180185 ? null
test/palette-roster.test.ts +3 −3
@@ -199,7 +199,7 @@ test("a site-admin person is offered the whole roster", () => {
199199 ["bets", "Bets", "back, stop and finish a repository\'s bets"],
200200 ["origins", "Connected accounts", "the hosts your mirrors come from"],
201201 ["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"],
203203 ["feature-review", "Menu entries to review", "absorbed apps whose declared name or page changed: accept them"],
204204 ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"],
205205 ["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",
294294 ["plan-row", "Plan", "this forge's plan, and where its owner manages billing"],
295295 ["cloud", "Cloud accounts", "provider tokens, what they are used for, today's calls"],
296296 ["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"],
298298 ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"],
299299 ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"],
300300 ["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"
391391 ["bulk", "Bulk actions", "your last bulk actions; u undoes one inside its day"],
392392 ["bets", "Bets", "back, stop and finish a repository\'s bets"],
393393 ["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"],
395395 ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"],
396396 ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"],
397397 ["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 o key on the feed screen; add one that presses o and asserts the run log screen is pushed.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs