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

Revert "A pull's reviews, checks, logs and history open in place as folds, with no notes" #16698

Closed opened this
Closed without merging

revert-16678 → main 1 commit 1 thread · 1 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
6 files changed +46 −201
docs/features/pull-folds.md deleted −23
@@ -1,23 +0,0 @@
1 ---
2 topic: Ship and undo
3 row: A pull's reviews, checks, log and history, folded in place
4 ---
5 # A pull's reviews, checks, log and history (#10538)
6
7 A pull's own page keeps its verdict and its change first, then three folds, each one line closed:
8
9 - **Reviews**: how they stand ("2 reviews · 1 approved"), and each review when opened. A request for changes still waiting shows here only, not again in the thread.
10 - **Checks**: the check's word (a check not yet run says "not run yet") and its live line. Inside it, **Log** holds the last 60 lines of the run, with a link to the whole run. A viewer who may not read run logs gets no Log fold.
11 - **History**: the steps on this pull, newest first, each linking to its page.
12
13 Only a failing check opens on its own, with its log; every other fold stays closed, so opening one never moves what is above it. A log wider than the screen scrolls sideways inside its own box.
14
15 ## The terminal says the same
16
17 The terminal is the other door onto the same facts, under the same gates:
18
19 - Reviews: the pull screen (`src/tui/screens/pull.ts`, with `pull_review.ts` for the review threads and verdicts).
20 - Check log: `src/tui/screens/runlist.ts` opens a run in `runlog.ts`, which reads through `runLog`, so an unreadable log says "not found" there as on the web; the pull screen's step line uses `mayReadRunLog` too.
21 - History: the pull's commits in `src/tui/screens/commits.ts`.
22
23 Try it: open a pull whose check failed; its Checks and Log folds are open. Open a green one: all three are closed.
src/web/studio/change.ts +29 −29
@@ -39,10 +39,6 @@ import { canAdmin, canWrite, type Repo } from "../../core/repos.ts";
3939 import { listReviews, type Review } from "../../core/reviews.ts";
4040 import { wallOf, wallPlain, wallSentence, type Wall } from "../../contract/policy.ts";
4141 import { checkSummary } from "../../core/runs.ts";
42 import { commitLog } from "../../git/read.ts";
43 import { mayReadRunLog } from "../../actions/runs.ts";
44 import { readRunLogTail } from "../../runs/log.ts";
45 import { pullFolds } from "./pull_folds.ts";
4642 import type { Ctx } from "../../http/context.ts";
4743 import {
4844 crumbsFor,
@@ -196,6 +192,29 @@ export function wallCard(wall: Wall, act?: string): Html {
196192 * current position, and a dismissed approval that still looks like an
197193 * approval is exactly how a review gate becomes decorative.
198194 */
195 /**

This second docblock stacks on top of reviewEntry's. Put standingRequests above the 'One verdict as a timeline entry' block so each function keeps its own doc.

196 * Each review, and whether it is a question still waiting: a request for
197 * changes that is its reviewer's newest verdict (a plain comment does not
198 * withdraw it) on a pull still open. Those stay
199 * out of the conversation's history fold (`Entry.open`).
200 */
201 export function standingRequests(
202 reviews: readonly Review[],
203 pullOpen: boolean,
204 ): { review: Review; open: boolean }[] {
205 const newest = new Map<string, string>();
206 for (const r of reviews) {
207 if (r.state === "commented") continue;
208 const seen = newest.get(r.authorId);
209 const was = seen === undefined ? undefined : reviews.find((x) => x.id === seen);
210 if (was === undefined || was.createdAt <= r.createdAt) newest.set(r.authorId, r.id);
211 }
212 return reviews.map((review) => ({
213 review,
214 open: pullOpen && review.state === "changes_requested" && newest.get(review.authorId) === review.id,
215 }));
216 }
217
199218 function reviewEntry(
200219 review: Review,
201220 headOid: string,
@@ -814,6 +833,10 @@ async function changeConversation(
814833 );
815834 const talk = conversation(ctx, repo, pull, {
816835 openVerb: "opened this",
836 extra: standingRequests(reviews, pull.state === "open" && pull.mergedAt === null).map(({ review, open }) => ({
837 ...reviewEntry(review, headOid, glyph, reviewerMarks),
838 ...(open ? { open: true as const } : {}),
839 })),
817840 editAction:
818841 mayEditIssue(ctx.app, repo, pull, ctx.auth.user).ok && !mirrored
819842 ? `${thread}/edit`
@@ -842,29 +865,6 @@ async function changeConversation(
842865 const totals =
843866 status === undefined ? null : (await lap(spent, "diff", () => keptChange(wordCtx.dir, status))).diff;
844867 const verdict = verdictOf(verdictFacts(ctx, repo, pull, status, { mayMerge: writer }), thread, files);
845 const check = checkSummary(db, pull.id, headOid);
846 const commits = await lap(spent, "diff", async () => {
847 if (headOid === "") return [];
848 const log = await commitLog(wordCtx.dir, headOid, { limit: Math.min(Math.max(status?.ahead ?? 20, 1), 50) });
849 return log.ok ? log.value : [];
850 });
851 const kept =
852 check.run !== null && mayReadRunLog(ctx.app, ctx.auth.user, repo)
853 ? readRunLogTail(ctx.app.config.dataDir, check.run.id, 60)
854 : undefined;
855 const folds = pullFolds({
856 reviews,
857 reviewNodes: reviews.map((r) => reviewEntry(r, headOid, glyph, reviewerMarks).node),
858 checkWord: word === "told" ? "not run yet" : word,
859 red: check.state === "failed",
860 checkBody: checkLine,
861 runLine,
862 ...(kept === undefined || check.run === null || kept.lines.length === 0
863 ? {}
864 : { log: { lines: kept.lines, truncated: kept.truncated, href: `${base}/runs/${check.run.id}` } }),
865 commits,
866 base,
867 });
868868 const wave = backToWave(ctx.url.searchParams.get("from"));
869869 const body = html`${pageHead.top}
870870 ${when(wave, (w) => crumbs([{ label: `Wave ${w.version}`, href: w.href }, { label: "This pull" }]))}
@@ -879,8 +879,8 @@ async function changeConversation(
879879 >
880880 </p>`,
881881 )}
882 ${folds}
883 ${gate} ${decisionSection}
882 <div id="pull-check">${checkLine}</div>
883 ${when(runLine, (l) => l)} ${gate} ${decisionSection}
884884 ${shipsOn(verdict, ctx.app, repo, pull, ctx.auth.user) && writer && word === "look"
885885 ? landAsIs(ctx, repo, pull)
886886 : null}
src/web/studio/pull_folds.ts deleted −85
@@ -1,85 +0,0 @@
1 /**
2 * Below a pull's verdict and its change: reviews, checks (with their log) and history, each one
3 * folded `row()`. Closed, a fold is one line of how it stands; open, it is the detail, in place.
4 * Only a failing check opens on its own. Plain data in, markup out: the page reads, this draws.
5 */
6 import type { Commit } from "../../git/read.ts";
7 import type { Review } from "../../core/reviews.ts";
8 import { html, type Html } from "../html.ts";
9 import { icon, row, rowList, sha, time } from "../ui.ts";
10
11 export interface PullFolds {
12 readonly reviews: readonly Review[];
13 /** Each review already drawn, same order as `reviews`. */
14 readonly reviewNodes: readonly Html[];
15 /** The check's word ("passed", "failed"…) and whether it is red. */
16 readonly checkWord: string;
17 readonly red: boolean;
18 /** The check's own line, with its live region. */
19 readonly checkBody: Html;
20 /** The live checks line beneath it, when the check is running or has run. */
21 readonly runLine?: Html | undefined;
22 /** The run's log tail; absent when none is kept or the viewer may not read it. */
23 readonly log?: { readonly lines: readonly string[]; readonly truncated: boolean; readonly href: string };
24 readonly commits: readonly Commit[];
25 readonly base: string;
26 }
27
28 const plural = (n: number, one: string): string => `${n} ${one}${n === 1 ? "" : "s"}`;
29
30 /** How the reviews stand, in one line. */
31 export function reviewsSummary(reviews: readonly Review[]): string {
32 if (reviews.length === 0) return "none yet";
33 const approved = reviews.filter((r) => r.state === "approved").length;
34 const asked = reviews.filter((r) => r.state === "changes_requested").length;
35 return [plural(reviews.length, "review"), approved > 0 ? `${approved} approved` : "", asked > 0 ? `${asked} asked for changes` : ""]
36 .filter((w) => w !== "")
37 .join(" · ");
38 }
39
40 const fold = (id: string, title: string, meta: Html | string, open: boolean, body: Html) =>
41 row({ lead: icon("chevronRight"), title, meta: html`${meta}`, fold: { id, open, body: html`<div class="card-body">${body}</div>` } });
42
43 export function pullFolds(i: PullFolds): Html {
44 const reviews = fold(
45 "fold-reviews",
46 "Reviews",
47 reviewsSummary(i.reviews),
48 false,
49 i.reviewNodes.length === 0 ? html`<p class="muted small">No review yet.</p>` : html`<div class="timeline">${[...i.reviewNodes]}</div>`,
50 );
51 const log =
52 i.log === undefined
53 ? null
54 : row({
55 lead: icon("chevronRight"),
56 title: "Log",
57 meta: html`${plural(i.log.lines.length, "line")}${i.log.truncated ? " (the tail)" : ""}`,
58 fold: {
59 id: "fold-log",
60 open: i.red,
61 body: html`<pre>${i.log.lines.join("\n")}</pre><p class="small"><a href="${i.log.href}">The whole run</a></p>`,
62 },
63 });
64 const checks = fold(
65 "fold-checks",
66 "Checks",
67 i.checkWord,
68 i.red,
69 html`<div id="pull-check">${i.checkBody}</div>${i.runLine ?? null}${log === null ? null : rowList([log])}`,
70 );
71 const history = fold(
72 "fold-history",
73 "History",
74 plural(i.commits.length, "step"),
75 false,
76 i.commits.length === 0
77 ? html`<p class="muted small">Nothing to show.</p>`
78 : rowList(
79 i.commits.map((c) =>
80 row({ href: `${i.base}/commit/${c.oid}`, title: c.subject, titleAttr: c.subject, meta: html`${c.author} · ${time(c.date)}`, trail: sha(c.oid) }),
81 ),
82 ),
83 );
84 return rowList([reviews, checks, history]);
85 }
src/web/style/content.ts −2
@@ -167,8 +167,6 @@ a.origin-chip:hover { border-color: var(--border-strong); color: var(--fg); }
167167 [data-tell] .page-head-sub { flex-wrap: wrap; }
168168 [data-tell] .comment-body img { max-width: 100%; height: auto; }
169169 [data-tell] pre { max-width: 100%; overflow-x: auto; }
170 /* A pull's log fold: the tail scrolls sideways inside its own box, never the page. */
171 .card-body > pre { max-width: 100%; overflow-x: auto; margin: 0 0 8px; }
172170 [data-apps], [data-apps-page], [data-bet-card], [data-explore], [data-family], [data-forges], [data-milestone], [data-new-repo], [data-now], [data-people] { overflow-wrap: anywhere; }
173171 /* /new (#9830): a long owner name or refused value stays inside the form on a phone. */
174172 [data-new-repo] form, [data-new-repo] .error { min-width: 0; max-width: 100%; }
test/pull-verdict.test.ts +1 −62
@@ -3,12 +3,7 @@
33 * change itself; reviews and checks come after.
44 */
55 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdir, mkdtemp, rm } from "node:fs/promises";
7 import { createRun } from "../src/core/runs.ts";
8 import { submitReview } from "../src/core/reviews.ts";
9 import type { Review } from "../src/core/reviews.ts";
10 import { reviewsSummary } from "../src/web/studio/pull_folds.ts";
11 import { runLogPath } from "../src/runs/log.ts";
6 import { mkdtemp, rm } from "node:fs/promises";
127 import { tmpdir } from "node:os";
138 import { join } from "node:path";
149 import { createApp, type App } from "../src/app.ts";
@@ -148,59 +143,3 @@ test("verdictOf names what holds a pull, in the merge box's order", () => {
148143 expect(words({ merged: true })).toBe("Merged");
149144 expect(verdictOf({ ...base, mayMerge: false }, "/t").action).toBeNull();
150145 });
151
152 const foldOpen = (body: string, id: string): boolean => {
153 const tag = body.match(new RegExp(`<details id="${id}"[^>]*>`))?.[0];
154 expect(tag).toBeDefined();
155 return tag!.includes("open");
156 };
157
158 test("a pull's own page folds reviews, checks, log and history; only a red check opens", async () => {
159 // Green or not yet run: every fold present, every one closed, and no `.note` block anywhere.
160 const calm = await pageOf("ready", "");
161 for (const id of ["fold-reviews", "fold-checks", "fold-history"]) expect(foldOpen(calm, id)).toBe(false);
162 expect(calm.slice(calm.indexOf("<body"))).not.toMatch(/class="(?:[^"]* )?note(?: [^"]*)?"/);
163
164 const repoId = app.db.query<{ repo_id: string; issue_id: string; head_oid: string }, []>(
165 "SELECT issue.repo_id, pull.issue_id, pull.head_oid FROM pull JOIN issue ON issue.id = pull.issue_id JOIN repo ON repo.id = issue.repo_id WHERE repo.name = 'held'",
166 ).get()!;
167 const run = createRun(app.db, { repoId: repoId.repo_id, kind: "check", issueId: repoId.issue_id, env: `pull-${numbers["held"]}`, commitOid: repoId.head_oid });
168 await mkdir(join(dataDir, "runs"), { recursive: true });
169 await Bun.write(runLogPath(dataDir, run.id), "step one\nTest failed: expected 1\n");
170 app.db.query("UPDATE run SET state = 'failed', summary = 'red' WHERE id = ?1").run(run.id);
171
172 const red = await pageOf("held", "");
173 expect(foldOpen(red, "fold-checks")).toBe(true);
174 expect(foldOpen(red, "fold-log")).toBe(true);
175 expect(red).toContain("Test failed: expected 1");
176 expect(foldOpen(red, "fold-reviews")).toBe(false);
177 expect(foldOpen(red, "fold-history")).toBe(false);
178 expect(red.slice(red.indexOf("<body"))).not.toMatch(/class="(?:[^"]* )?note(?: [^"]*)?"/);
179 });
180
181 test("the review summary says how the reviews stand, in plain words", () => {
182 const r = (state: "approved" | "changes_requested" | "commented") => ({ state }) as Review;
183 expect(reviewsSummary([])).toBe("none yet");
184 expect(reviewsSummary([r("commented")])).toBe("1 review");
185 expect(reviewsSummary([r("approved"), r("approved"), r("changes_requested")])).toBe("3 reviews · 2 approved · 1 asked for changes");
186 });
187
188 test("a pull with reviews lists them in the Reviews fold, once, and a viewer who may not read the log gets no log fold", async () => {
189 const row = app.db.query<{ issue_id: string; head_oid: string }, []>(
190 "SELECT pull.issue_id, pull.head_oid FROM pull JOIN issue ON issue.id = pull.issue_id JOIN repo ON repo.id = issue.repo_id WHERE repo.name = 'ready'",
191 ).get()!;
192 submitReview(app.db, { issueId: row.issue_id, authorId: alice.id, state: "changes_requested", body: "Please rename the zebra", commitOid: row.head_oid });
193 const page = await pageOf("ready", "");
194 const fold = page.slice(page.indexOf('id="fold-reviews"'), page.indexOf('id="fold-checks"'));
195 expect(fold).toContain("Please rename the zebra");
196 expect(fold).toContain("1 review · 1 asked for changes");
197 expect(page.split("Please rename the zebra").length - 1).toBe(1);
198
199 // The held pull's red check keeps a log; a stranger reads the page but not the log.
200 const res = await fetch(`${servers.url}/alice/held/pulls/${numbers["held"]}`);
201 const stranger = await res.text();
202 expect(res.status).toBe(200);
203 expect(stranger).toContain('id="fold-checks"');
204 expect(stranger).not.toContain('id="fold-log"');
205 expect(stranger).not.toContain("Test failed: expected 1");
206 });
test/thread-window.test.ts +16
@@ -13,8 +13,10 @@ import { foldJs } from "../src/web/fold.ts";
1313 import { shellJs } from "../src/web/client.ts";
1414 import { css } from "../src/web/style.ts";
1515 import { conversation, type Entry } from "../src/web/pages/thread.ts";
16 import { standingRequests } from "../src/web/studio/change.ts";
1617 import { html } from "../src/web/html.ts";
1718 import type { Ctx } from "../src/http/context.ts";
19 import type { Review } from "../src/core/reviews.ts";
1820 import { candidatesFor } from "../src/feed/items.ts";
1921
2022 let f: SnappyFixture;
@@ -296,6 +298,20 @@ test("an entry still waiting for its answer stays out of the fold, and splits it
296298 expect(settled.match(/<details class="tl-fold"/g)?.length).toBe(1);
297299 });
298300
301 test("a request for changes stands while it is its reviewer's newest verdict on an open pull", () => {
302 const r = (id: string, authorId: string, state: Review["state"], createdAt: string): Review =>
303 ({ id, authorId, authorName: authorId, originAuthor: null, state, body: "", commitOid: "h", baseOid: "", createdAt }) as Review;
304 const reviews = [
305 r("1", "a", "changes_requested", "2026-01-01"),
306 r("2", "a", "commented", "2026-01-02"),
307 r("3", "b", "changes_requested", "2026-01-01"),
308 r("4", "b", "approved", "2026-01-03"),
309 ];
310 const open = (pullOpen: boolean) => standingRequests(reviews, pullOpen).filter((x) => x.open).map((x) => x.review.id);
311 expect(open(true)).toEqual(["1"]);
312 expect(open(false)).toEqual([]);
313 });
314
299315 test("an ordinary comment carries no question form; the composer offers 'Ask as a question', and posting with it marks the comment", async () => {
300316 const repo = f.repos[0]!;
301317 const opened = openIssue(f.app, f.owner, repo, { title: "Composer", body: "c" });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs