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

The issue page speaks the home page's language, with looks before and after #9654

Closed opened this
Closed without merging

scout/forge:scout/9587-the-issue-page-speaks-the-home-page-s-la → main 4 commits fork 5 threads · 5 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +214 −33
src/web/pages/thread.ts +8 −7
@@ -67,6 +67,7 @@ import {
6767 card,
6868 icon,
6969 labelChip,
70 plain,
7071 time,
7172 tlComment,
7273 tlEvent,
@@ -663,13 +664,13 @@ export function labelsCard(
663664 )}
664665 </div>`;
665666 if (!mayEdit || all.length === 0)
666 return card(chips, {
667 return plain(chips, {
667668 head: html`${icon("tag")}
668669 <h2>Labels</h2>`,
669670 });
670671
671672 const applies = new Set(applied.map((l) => l.id));
672 return card(
673 return plain(
673674 html`${chips}
674675 <form method="post" action="${action}" class="mt" data-now="Applied" data-now-into="#labels-now" data-now-from="labels">
675676 <fieldset class="stack">
@@ -759,12 +760,12 @@ export function assigneeCard(
759760 })}
760761 </p>`;
761762 if (!mayEdit)
762 return card(current, {
763 return plain(current, {
763764 head: html`${icon("user")}
764765 <h2>Assignee</h2>`,
765766 });
766767 const candidates = assigneeCandidates(ctx, repo, issue);
767 return card(
768 return plain(
768769 html`${current}
769770 <form method="post" action="${action}" class="edit-row mt" data-now="Assigned" data-now-into="#assignee-now" data-now-from="assignee">
770771 <label class="sr-only" for="f-assignee">Assign to</label>
@@ -1027,8 +1028,8 @@ export function issueTeamsCard(ctx: Ctx, repo: Repo, issue: Issue, action: strin
10271028 ? html`<p class="muted small">None named.</p>`
10281029 : html`<p>${named.map((slug) => all.find((t) => t.slug === slug)?.name ?? slug).join(", ")}</p>`;
10291030 if (!canWrite(ctx.app.db, repo, ctx.auth.user) || repo.origin !== null)
1030 return card(chips, { head });
1031 return card(
1031 return plain(chips, { head });
1032 return plain(
10321033 html`${chips}
10331034 <form method="post" action="${action}" class="mt">
10341035 <fieldset class="stack">
@@ -1162,7 +1163,7 @@ export function dependenciesCard(
11621163 >
11631164 · `}<a href="${base}/map">See the map</a>
11641165 </p>`;
1165 return card(body, {
1166 return plain(body, {
11661167 head: html`${icon("map")}
11671168 <h2>Depends on</h2>`,
11681169 });
src/web/studio/tell.ts +21 −26
@@ -56,11 +56,10 @@ import {
5656 avatar,
5757 badge,
5858 btn,
59 card,
59 plain,
6060 disclosure,
6161 icon,
6262 labelCss,
63 listCard,
6463 originTag,
6564 row,
6665 stateBadge,
@@ -363,10 +362,10 @@ async function tellRuns(
363362 });
364363 }),
365364 );
366 return listCard(rows, {
367 head: html`${icon("bot")}
368 <h2>Runs</h2>`,
369 });
365 return html`<section class="stack">

Principle 7 is met here, but nothing tests it. Add a test that renders a tell with an agent run and asserts the heading plus ul.list and no card wrapper; it must fail on the old listCard markup.

366 <h2>Runs</h2>
367 <ul class="list">${rows}</ul>
368 </section>`;
370369 }
371370
372371 /** The pull that closes this tell, with its check and a way into its
@@ -380,13 +379,13 @@ async function tellClosingPull(
380379 ): Promise<Html> {
381380 const base = repoBase(repo);
382381 const { word, note } = await pullWord(wordCtx, pull);
383 return html`${card(
384 html`<p>
385 <a href="${changeHref(base, pull.number)}">${pull.title}</a>
386 ${wordBadge(word)} <span class="muted small">${note}</span>
387 </p>`,
388 { head: html`${icon("pull")} <h2>Closes with</h2>` },
389 )}${previewCard(ctx, repo, pull)}`;
382 return html`<section class="stack">
383 <h2>Closes with</h2>

Same: the Closes with section has no test. Cover a tell with an open closing pull. Also confirm the preview card that follows does not re-box this section (principle 6).

384 <p>
385 <a href="${changeHref(base, pull.number)}">${pull.title}</a>
386 ${wordBadge(word)} <span class="muted small">${note}</span>
387 </p>
388 </section>${previewCard(ctx, repo, pull)}`;
390389 }
391390
392391 /**
@@ -452,8 +451,7 @@ async function studioTell(
452451 const doneLine =
453452 doneBy.length === 0
454453 ? null
455 : card(
456 html`<form method="post" action="${thread}/state" class="row" data-now="Closed" data-now-once>
454 : html`<form method="post" action="${thread}/state" class="row mt" data-now="Closed" data-now-once>

The done-on-main line is now a bare form with mt, and its success tone is gone. Test that it renders with doneBy set and that Close shows only when mayClose. The page must work with JS off: check the data-now attributes degrade to plain text.

457455 <input type="hidden" name="state" value="closed" />
458456 <input type="hidden" name="reason" value="done" />
459457 <span
@@ -469,9 +467,7 @@ async function studioTell(
469467 ${mayClose
470468 ? btn("Close", { size: "sm", icon: "issueClosed" })
471469 : null}
472 </form>`,
473 { extra: "mt", tone: "success" },
474 );
470 </form>`;
475471 const [wordInfo, runsCard, closingCard] = await Promise.all([
476472 direction ? undefined : tellWord(wordCtx, repo, issue, closingPull),
477473 tellRuns(wordCtx, repo, issue),
@@ -581,13 +577,12 @@ async function studioTell(
581577 <aside>
582578 ${privateWorkCard(ctx, repo, issue, `${thread}/private`)}
583579 ${hasPicture(db, repo.id, issue.number)
584 ? card(
585 html`<h2>Picture of the page</h2>
586 <a href="${thread}/picture"
587 ><img src="${thread}/picture" alt="The page the sender was looking at" loading="lazy" class="tell-picture"
588 /></a>`,
589 { extra: "mt" },
590 )
580 ? html`<section class="stack">
581 <h2>Picture of the page</h2>

Principles 6 and 7: the sibling Fix it privately card directly above this section is still a box, so the sidebar mixes both languages (principle 3, one rhythm). Convert it in this pull.

582 <a href="${thread}/picture"
583 ><img src="${thread}/picture" alt="The page the sender was looking at" loading="lazy" class="tell-picture"
584 /></a>
585 </section>`
591586 : null}
592587 ${runsCard}
593588 ${closingCard}
@@ -635,7 +630,7 @@ function privateWorkCard(ctx: Ctx, repo: Repo, issue: Issue, action: string): Ht
635630 if (!issue.sealed || user === undefined || user.kind === "agent") return null;
636631 if (!canSeeSealed(ctx.app.db, repo, user)) return null;
637632 const mine = getSealedFork(ctx.app.db, user.id, repo.id);
638 return card(
633 return plain(
639634 html`<p>
640635 A branch on ${repo.ownerName}/${repo.name}, or on a public fork, is
641636 public: its fix shows where the hole is. Fix this one in your private
src/web/ui.ts +11
@@ -908,6 +908,17 @@ export function card(body: Html, o: CardOptions = {}): Html {
908908 </div>`;
909909 }
910910
911 /**
912 * A thing on a page with a heading and no box (DESIGN.md principles 6 and 7):
913 * `<section class="stack">` with the head, then the body. Same options as
914 * `card`, so a card that should not be a box changes one word.
915 */
916 export function plain(body: Html, o: Pick<CardOptions, "head" | "id" | "extra"> = {}): Html {

Principle 1: plain() keeps card options but the callers now differ on whether the head carries an icon (tell.ts Runs/Closes with have none). Keep one heading style across the sidebar and the main column.

917 return html`<section class="stack${o.extra ? ` ${o.extra}` : ""}"${o.id ? html` id="${o.id}"` : null}>
918 ${o.head ?? null} ${body}
919 </section>`;
920 }
921
911922 /** Written text kept as typed (a commit message, a report body): §5's prose, wrapped. */
912923 export function messageText(text: string): Html {
913924 return html`<div class="prose" data-text="message"><pre>${text}</pre></div>`;
test/issue-page-rows.test.ts added +174
@@ -0,0 +1,174 @@
1 /**
2 * The issue page speaks the home page's language (#9587): what hangs off an
3 * issue is a heading over rows, never a box around a thing (DESIGN.md
4 * principles 6 and 7). Each part is checked on a real page, with a run, a
5 * closing pull, a dependency, a labelled and assigned issue, a sealed
6 * report and the crew's done-on-main note.
7 */
8 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
9 import { mkdtemp, rm } from "node:fs/promises";
10 import { tmpdir } from "node:os";
11 import { join } from "node:path";
12 import { openIssue } from "../src/actions/issues.ts";
13 import { openPull } from "../src/actions/pulls.ts";
14 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
15 import { createApp, type App } from "../src/app.ts";
16 import { addComment } from "../src/core/issues.ts";
17 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
18 import { createSession } from "../src/core/sessions.ts";
19 import { serve, type Servers } from "../src/http/server.ts";
20 import { seedAdmin } from "./helpers/admin.ts";
21 import { quietLogs } from "./helpers/globals.ts";
22
23 quietLogs();
24
25 describe("the issue page's rows", () => {
26 let dataDir = "";
27 let app: App;
28 let servers: Servers;
29 let cookie = "";
30 let withEverything = 0;
31 let bare = 0;
32
33 const get = async (n: number, as = cookie): Promise<string> =>
34 await (await fetch(`${servers.url}/mel/garden/issues/${n}`, { headers: { cookie: as } })).text();
35 /** The part of the page from a heading to the next heading. */
36 const part = (html: string, heading: string): string => {
37 const at = html.indexOf(`<h2>${heading}</h2>`);
38 expect(at).toBeGreaterThan(-1);
39 const next = html.indexOf("<h2", at + 5);
40 return html.slice(at, next === -1 ? undefined : next);
41 };
42 /** The done-on-main form: the one that closes with the reason "done". */
43 const doneForm = (html: string): string => {
44 const at = html.indexOf('data-now="Closed"');
45 expect(at).toBeGreaterThan(-1);
46 return html.slice(html.lastIndexOf("<form", at), html.indexOf("</form>", at));
47 };
48 /** The tag that opens the element holding this heading. */
49 const sectionOpening = (html: string, heading: string): string => {
50 const before = html.slice(0, html.indexOf(`<h2>${heading}</h2>`));
51 const tags = [...before.matchAll(/<(section|div)[^>]*>/g)];
52 return tags[tags.length - 1]![0];
53 };
54
55 beforeAll(async () => {
56 dataDir = await mkdtemp(join(tmpdir(), "forge-issue-rows-"));
57 app = createApp({ dataDir, port: 0 });
58 servers = await serve(app);
59 const made = await seedAdmin(app, { username: "mel", email: "[email protected]", password: "rows-not-boxes-pass" });
60 if (!made.ok) throw new Error(made.error);
61 const mel = made.value;
62 cookie = `forge_session=${createSession(app.db, mel.id).token}`;
63 const r = await createRepo(app, mel, { name: "garden", visibility: "public" });
64 if (!r.ok) throw new Error(String(r.error));
65 const repo = r.value;
66 const seeded = await commitToBranch(app, mel, repo, {
67 message: "seed",
68 files: [{ path: "README.md", content: "# garden\n" }],
69 });
70 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
71
72 const a = openIssue(app, mel, repo, { title: "Water the beds" });
73 const b = openIssue(app, mel, repo, { title: "Nothing else" });
74 if (!a.ok || !b.ok) throw new Error("issues");
75 withEverything = a.value.number;
76 bare = b.value.number;
77
78 // An agent run on it.
79 const run = createRun(app.db, {
80 repoId: repo.id,
81 kind: "agent",
82 issueId: a.value.id,
83 actorId: mel.id,
84 reason: "tell",
85 });
86 claimRun(app.db, run.id);
87 finishRun(app.db, run.id, { state: "ok", summary: "watered" });
88
89 // A pull that closes it.
90 const branch = "water";
91 const c = await commitToBranch(app, mel, repo, {
92 branch,
93 base: "main",
94 message: branch,
95 files: [{ path: "water.md", content: "x\n" }],
96 });
97 if (!c.ok) throw new Error(JSON.stringify(c.error));
98 const pull = await openPull(app, mel, repo, {
99 title: "Water it",
100 body: `Closes #${a.value.number}`,
101 baseBranch: "main",
102 headBranch: branch,
103 });
104 if (!pull.ok) throw new Error(String(pull.error));
105
106 // The crew's note: found done on the base. The repo's autonomy owner is the crew.
107 app.db.query("UPDATE repo SET autonomy_by = ?1 WHERE id = ?2").run(mel.id, repo.id);
108 addComment(app.db, {
109 issueId: a.value.id,
110 authorId: mel.id,
111 body: `Done on main already, waiting for you to close it: ${"a".repeat(40)}`,
112 });
113 });
114
115 afterAll(async () => {
116 servers.stop();
117 app.close();
118 await rm(dataDir, { recursive: true, force: true });
119 });
120
121 test("Runs is a heading over a ul.list, in no card", async () => {
122 const html = await get(withEverything);
123 const runs = part(html, "Runs");
124 expect(runs).toContain('<ul class="list">');
125 expect(runs).toContain("watered");
126 expect(sectionOpening(html, "Runs")).toBe('<section class="stack">');
127 expect(runs).not.toContain('class="card');
128 });
129
130 test("Closes with is a heading and the pull link; the preview after it is its own", async () => {
131 const html = await get(withEverything);
132 const closes = part(html, "Closes with");
133 expect(closes).toContain("Water it");
134 expect(sectionOpening(html, "Closes with")).toBe('<section class="stack">');
135 // The section itself ends before anything else begins: no card wraps it.
136 expect(closes.slice(0, closes.indexOf("</section>"))).not.toContain('class="card');
137 });
138
139 test("Depends on, Labels, Assignee and Teams are sections, not cards", async () => {
140 const html = await get(withEverything);
141 for (const heading of ["Depends on", "Assignee", "Labels", "Teams"]) {
142 if (!html.includes(`<h2>${heading}</h2>`)) continue;
143 expect(sectionOpening(html, heading)).toBe('<section class="stack">');
144 }
145 expect(html).toContain("<h2>Depends on</h2>");
146 expect(html).toContain("<h2>Assignee</h2>");
147 });
148
149 test("done on main is a plain row with the commit, and Close for whoever may close", async () => {
150 const html = await get(withEverything);
151 const form = doneForm(html);
152 expect(form).toContain('class="row mt"');
153 expect(form).not.toContain("card");
154 expect(form).toContain('name="state" value="closed"');
155 expect(form).toContain("Close");
156 // The words are in the markup itself: with JS off they are all there is.
157 expect(form).toContain("waiting for you to close it.");
158 });
159
160 test("done on main shows no Close to a stranger", async () => {
161 const stranger = await fetch(`${servers.url}/mel/garden/issues/${withEverything}`);
162 const html = await stranger.text();
163 expect(html).toContain("Done on main");
164 const form = doneForm(html);
165 expect(form).not.toContain("<button");
166 });
167
168 test("an issue with nothing hanging off it has no Runs or Closes with", async () => {
169 const html = await get(bare);
170 expect(html).not.toContain("<h2>Runs</h2>");
171 expect(html).not.toContain("<h2>Closes with</h2>");
172 expect(html).not.toContain("Done on main");
173 });
174 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs