Public: anyone can read this; the crew can change it.
A variants deck speaks the home page's language #9968
scout/forge:scout/9958-a-variants-deck-speaks-the-home-page-s-l → main 4 commits fork
4 files
changed +103
−7
src/web/pages/apps.ts +13 −4
| @@ -87,6 +87,8 @@ import { | ||
| 87 | 87 | sha, |
| 88 | 88 | terminalLine, |
| 89 | 89 | field as formField, |
| 90 | block, | |
| 91 | type CardOptions, | |
| 90 | 92 | } from "../ui.ts"; |
| 91 | 93 | |
| 92 | 94 | // ---- what the viewer can see ---- |
| @@ -679,7 +681,14 @@ export function previewLook(env: EnvStatus): { | ||
| 679 | 681 | } |
| 680 | 682 | |
| 681 | 683 | /** Where this pull's preview stands, with the way in. */ |
| 682 | export function previewCard(ctx: Ctx, repo: Repo, pull: Pull): Html { | |
| 684 | export function previewCard( | |
| 685 | ctx: Ctx, | |
| 686 | repo: Repo, | |
| 687 | pull: Pull, | |
| 688 | plain = false, | |
| 689 | ): Html { | |
| 690 | const frame = (body: Html, o: CardOptions & { head: Html }): Html => | |
| 691 | plain ? block(body, o.head) : card(body, o); | |
| 683 | 692 | const view = appView(ctx.app, ctx.auth.user, repo); |
| 684 | 693 | if (!view.ok) return html``; |
| 685 | 694 | const base = repoBase(repo); |
| @@ -690,7 +699,7 @@ export function previewCard(ctx: Ctx, repo: Repo, pull: Pull): Html { | ||
| 690 | 699 | <h2>Preview</h2> |
| 691 | 700 | ${env === undefined ? null : envStateBadge(env.state, env.dormant !== undefined)}`; |
| 692 | 701 | if (!view.value.serving) |
| 693 | return card( | |
| 702 | return frame( | |
| 694 | 703 | html`<p class="muted small">Nothing is serving apps on this forge.</p>`, |
| 695 | 704 | { head, extra: "bare" }, |
| 696 | 705 | ); |
| @@ -701,13 +710,13 @@ export function previewCard(ctx: Ctx, repo: Repo, pull: Pull): Html { | ||
| 701 | 710 | : pull.state === "closed" |
| 702 | 711 | ? "The preview was removed when this closed. Reopen the pull request and it comes back." |
| 703 | 712 | : "No preview yet — one starts when this pull request's head deploys."; |
| 704 | return card(html`<p class="muted small">${why}</p>`, { head, extra: "bare" }); | |
| 713 | return frame(html`<p class="muted small">${why}</p>`, { head, extra: "bare" }); | |
| 705 | 714 | } |
| 706 | 715 | // A preview's terminal is a different login from production's — its own |
| 707 | 716 | // command, shown only to a writer, same as the app page's. |
| 708 | 717 | const writer = canWrite(ctx.app.db, repo, ctx.auth.user); |
| 709 | 718 | const dataNote = previewDataNote(view.value.app.previewData, pull.createdAt); |
| 710 | return card( | |
| 719 | return frame( | |
| 711 | 720 | html`${envFacts(base, env)} |
| 712 | 721 | ${dataNote === null ? null : html`<p class="muted small">${dataNote}</p>`} |
| 713 | 722 | ${when(writer, () => |
src/web/pages/variants.ts +3 −3
| @@ -25,7 +25,7 @@ import { field, readForm } from "../form.ts"; | ||
| 25 | 25 | import { html, when, type Html } from "../html.ts"; |
| 26 | 26 | import { flashTo, page } from "../layout.ts"; |
| 27 | 27 | import { changeHref } from "../studio/nouns.ts"; |
| 28 | import { btn, card } from "../ui.ts"; | |
| 28 | import { btn } from "../ui.ts"; | |
| 29 | 29 | import { previewCard } from "./apps.ts"; |
| 30 | 30 | import { lookCard } from "./looks.ts"; |
| 31 | 31 | import { parseNumber } from "./thread.ts"; |
| @@ -63,7 +63,7 @@ function deckCard( | ||
| 63 | 63 | return html`<section class="variant-card" data-swipe> |
| 64 | 64 | <h2><a href="${changeHref(base, pull.number)}">#${pull.number} ${pull.title}</a></h2> |
| 65 | 65 | ${record === undefined ? null : lookCard(ctx, repo, record, pull, pull.headOid)} |
| 66 | ${previewCard(ctx, repo, pull)} | |
| 66 | ${previewCard(ctx, repo, pull, true)} | |
| 67 | 67 | ${when(writer, () => |
| 68 | 68 | html`<div class="bar mt"> |
| 69 | 69 | <form class="like" method="post" action="${vote}/like"> |
| @@ -106,7 +106,7 @@ export function variantsPage(ctx: Ctx): Response { | ||
| 106 | 106 | scriptJs: SWIPE_JS, |
| 107 | 107 | body: html`<h1>Choose among ${pulls.length} variants</h1> |
| 108 | 108 | ${open.length === 0 |
| 109 | ? card(html`<p class="muted">Every variant is decided.</p>`) | |
| 109 | ? html`<p class="muted">Every variant is decided.</p>` | |
| 110 | 110 | : open.map((p) => |
| 111 | 111 | deckCard(ctx, repo, p, group, writer, open.length === 1), |
| 112 | 112 | )}`, |
src/web/ui.ts +7
| @@ -908,6 +908,13 @@ export function card(body: Html, o: CardOptions = {}): Html { | ||
| 908 | 908 | </div>`; |
| 909 | 909 | } |
| 910 | 910 | |
| 911 | /** A plain section under its head, the home page's language: no box. */ | |
| 912 | export function block(body: Html, head?: Html): Html { | |
| 913 | return html`<section class="settings-block"> | |
| 914 | ${head ? html`<div class="bar">${head}</div>` : null}${body} | |
| 915 | </section>`; | |
| 916 | } | |
| 917 | ||
| 911 | 918 | /** Written text kept as typed (a commit message, a report body): §5's prose, wrapped. */ |
| 912 | 919 | export function messageText(text: string): Html { |
| 913 | 920 | return html`<div class="prose" data-text="message"><pre>${text}</pre></div>`; |
test/variants-language.test.ts added +80
| @@ -0,0 +1,80 @@ | ||
| 1 | /** A variants deck speaks the home page's language: sections, not cards (#9958). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 8 | import { listDecisions } from "../src/core/decisions.ts"; | |
| 9 | import { getRepo } from "../src/core/repos.ts"; | |
| 10 | import { gitClientEnv } from "./helpers/git-client.ts"; | |
| 11 | import { adminCookie } from "./helpers/admin.ts"; | |
| 12 | ||
| 13 | const gitEnv = gitClientEnv(); | |
| 14 | let dataDir = "", work = ""; | |
| 15 | let app: App, servers: Servers; | |
| 16 | let base = "", cookie = ""; | |
| 17 | ||
| 18 | async function git(dir: string, args: string[]): Promise<void> { | |
| 19 | const p = Bun.spawn(["git", ...args], { cwd: dir, env: gitEnv, stdout: "ignore", stderr: "pipe" }); | |
| 20 | const [err, code] = await Promise.all([new Response(p.stderr).text(), p.exited]); | |
| 21 | if (code !== 0) throw new Error(`git ${args.join(" ")}: ${err}`); | |
| 22 | } | |
| 23 | const main = (page: string) => page.slice(page.indexOf("<main"), page.indexOf("</main>")); | |
| 24 | const post = (path: string) => | |
| 25 | fetch(`${base}${path}`, { method: "POST", headers: { origin: base, cookie }, body: new URLSearchParams(), redirect: "manual" }); | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | dataDir = await mkdtemp(join(tmpdir(), "forge-vl-")); | |
| 29 | work = await mkdtemp(join(tmpdir(), "forge-vl-work-")); | |
| 30 | app = createApp({ dataDir, port: 0 }); | |
| 31 | servers = await serve(app); | |
| 32 | base = servers.url; | |
| 33 | cookie = await adminCookie(app, { username: "dev", email: "[email protected]", password: "variants-deck-pass" }); | |
| 34 | const { token } = (await (await fetch(`${base}/api/v1/tokens`, { | |
| 35 | method: "POST", | |
| 36 | headers: { "content-type": "application/json" }, | |
| 37 | body: JSON.stringify({ adminConfirm: true, username: "dev", password: "variants-deck-pass", name: "cli", scope: "rw" }), | |
| 38 | })).json()) as { token: string }; | |
| 39 | const auth = { authorization: `Bearer ${token}`, "content-type": "application/json" }; | |
| 40 | await fetch(`${base}/api/v1/repos`, { method: "POST", headers: auth, body: JSON.stringify({ name: "app", visibility: "public" }) }); | |
| 41 | await git(work, ["clone", `${base.replace("http://", `http://dev:${token}@`)}/dev/app.git`, "app"]); | |
| 42 | const dir = join(work, "app"); | |
| 43 | await Bun.write(join(dir, "code.txt"), "alpha\n"); | |
| 44 | await git(dir, ["add", "."]); | |
| 45 | await git(dir, ["commit", "-m", "base"]); | |
| 46 | await git(dir, ["push", "origin", "main"]); | |
| 47 | for (const name of ["a", "b"]) { | |
| 48 | await git(dir, ["checkout", "-B", name, "main"]); | |
| 49 | await Bun.write(join(dir, "code.txt"), `alpha\n${name}\n`); | |
| 50 | await git(dir, ["commit", "-am", name]); | |
| 51 | await git(dir, ["push", "origin", name]); | |
| 52 | await fetch(`${base}/api/v1/repos/dev/app/pulls`, { method: "POST", headers: auth, body: JSON.stringify({ base: "main", head: name, title: `Try ${name}` }) }); | |
| 53 | } | |
| 54 | app.db.run("UPDATE pull SET variant_group = 'g'"); | |
| 55 | }); | |
| 56 | afterAll(async () => { | |
| 57 | servers.stop(); | |
| 58 | app.close(); | |
| 59 | await rm(dataDir, { recursive: true, force: true }); | |
| 60 | await rm(work, { recursive: true, force: true }); | |
| 61 | }); | |
| 62 | ||
| 63 | test("the deck is sections with no card, forms intact", async () => { | |
| 64 | const m = main(await (await fetch(`${base}/dev/app/variants/g`, { headers: { cookie } })).text()); | |
| 65 | expect(m).not.toContain('class="card'); | |
| 66 | expect((m.match(/class="variant-card"/g) ?? []).length).toBe(2); | |
| 67 | expect(m).toContain('action="/dev/app/variants/g/1/like"'); | |
| 68 | expect(m).toContain('action="/dev/app/variants/g/1/dislike"'); | |
| 69 | }); | |
| 70 | ||
| 71 | test("like still records, and an all-decided deck is one line, no card", async () => { | |
| 72 | const res = await post("/dev/app/variants/g/1/like"); | |
| 73 | expect(res.status).toBe(303); | |
| 74 | const repo = getRepo(app.db, "dev", "app")!; | |
| 75 | expect(listDecisions(app.db, repo.id, { kind: "lean" })).toHaveLength(1); | |
| 76 | app.db.run("UPDATE issue SET state = 'closed' WHERE number IN (1, 2)"); | |
| 77 | const m = main(await (await fetch(`${base}/dev/app/variants/g`, { headers: { cookie } })).text()); | |
| 78 | expect(m).not.toContain('class="card'); | |
| 79 | expect(m).toContain("Every variant is decided."); | |
| 80 | }); |
new above
offline