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

A pull's looks show main's picture beside the head's, so before and after are on every pull with no one attaching them #9676

Parked opened this
Closed without merging

mason/forge:mason/9669-a-pull-s-looks-show-main-s-picture-besid → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +115 −38
src/web/pages/looks.ts +40 −36
@@ -163,7 +163,7 @@ export function lookCard(
163163 );
164164 const labelled = pages.length > 1;
165165 // What main looks like, to set each page beside: only what this viewer may fetch.
166 const mainLooks = looksForEnv(ctx.app.db, record.id, "production").filter(
166 const mainLooks = looksForEnv(ctx.app.db, record.id, "production", "any").filter(
167167 (l) => !isAttached(l) && mayFetchLook(ctx, repo, record, l),
168168 );
169169 const picture = (
@@ -207,14 +207,17 @@ export function lookCard(
207207 </p>
208208 </section>`;
209209 const moved = shown.commitOid !== headOid;
210 // Beside the same page at the same width and theme: a width main lacks is left out.
210211 const mainOfPage = mainLooks.filter((l) => l.page === page);
211 const beforePhone = pictured(mainOfPage, "phone");
212 const beforeDesktop = pictured(mainOfPage, "desktop");
213 // Beside the same page at the same width: a width main lacks is left out.
214 const beforeShown = [
215 phone === undefined ? undefined : beforePhone,
216 desktop === undefined ? undefined : beforeDesktop,
217 ].filter((l): l is Look => l !== undefined);
212 const beforeOf = (theme: Look["theme"], ...have: (Look | undefined)[]): Look[] =>
213 ([["phone", have[0]], ["desktop", have[1]]] as const)
214 .map(([kind, mine]) =>
215 mine === undefined
216 ? undefined
217 : pictured(mainOfPage.filter((l) => l.theme === theme), kind),
218 )
219 .filter((l): l is Look => l !== undefined);
220 const beforeShown = beforeOf("light", phone, desktop);
218221 // Only the dark pictures of the commit the caption names: after a push
219222 // the light pair is retaken first, and an old head's dark pair must not
220223 // sit under the new head's words.
@@ -223,38 +226,39 @@ export function lookCard(
223226 );
224227 const darkPhone = pictured(darkOfPage, "phone");
225228 const darkDesktop = pictured(darkOfPage, "desktop");
229 // Main's picture beside the head's; where main has none, the head stands alone.
230 const compare = (before: readonly Look[], after: readonly Look[]): Html =>
231 before.length === 0
232 ? html`<div class="looks">
233 ${after.map((l) => picture(l, l.kind, page))}
234 </div>`
235 : html`<div class="looks" data-compare>
236 <div>
237 <p class="muted small">main</p>
238 <div class="looks">
239 ${before.map((l) => picture(l, l.kind, page, "main"))}
240 </div>
241 <p class="muted small">
242 at ${sha(before[0]!.commitOid, `${base}/commit/${before[0]!.commitOid}`)} ·
243 ${time(before[0]!.createdAt)}
244 </p>
245 </div>
246 <div>
247 <p class="muted small">this pull</p>
248 <div class="looks">
249 ${after.map((l) => picture(l, l.kind, page))}
250 </div>
251 </div>
252 </div>`;
253 const lightAfter = [phone, desktop].filter((l): l is Look => l !== undefined);
254 const darkAfter = [darkPhone, darkDesktop].filter((l): l is Look => l !== undefined);
226255 return html`<section class="stack stack-tight">
227256 ${label}
228 <div class="looks" data-compare>
229 <div>
230 <p class="muted small">Before · main</p>
231 ${beforeShown.length === 0
232 ? html`<p class="muted small">
233 Main has no look of ${page} yet.
234 </p>`
235 : html`<div class="looks">
236 ${beforeShown.map((l) => picture(l, l.kind, page, "main"))}
237 </div>
238 <p class="muted small">
239 at ${sha(beforeShown[0]!.commitOid, `${base}/commit/${beforeShown[0]!.commitOid}`)} ·
240 ${time(beforeShown[0]!.createdAt)}
241 </p>`}
242 </div>
243 <div>
244 <p class="muted small">After · #${pull.number}</p>
245 <div class="looks">
246 ${when(phone, (l) => picture(l, "phone", page))}
247 ${when(desktop, (l) => picture(l, "desktop", page))}
248 </div>
249 </div>
250 </div>
251 ${when(darkPhone ?? darkDesktop, () =>
257 ${compare(beforeShown, lightAfter)}
258 ${when(darkAfter.length > 0, () =>
252259 disclosure(
253260 "In the dark",
254 html`<div class="looks">
255 ${when(darkPhone, (l) => picture(l, "phone", page))}
256 ${when(darkDesktop, (l) => picture(l, "desktop", page))}
257 </div>`,
261 compare(beforeOf("dark", darkPhone, darkDesktop), darkAfter),
258262 { small: true },
259263 ),
260264 )}
test/looks.test.ts +2 −2
@@ -1235,14 +1235,14 @@ describe("the look", () => {
12351235 const map = group("/map");
12361236 expect(map).toContain(`/looks/production/${mainOid}/map-phone.png?v=`);
12371237 expect(map).toContain(`/looks/${env}/${oid}/map-phone.png?v=`);
1238 expect(map.indexOf("Before")).toBeLessThan(map.indexOf("After"));
1238 expect(map.indexOf(">main<")).toBeLessThan(map.indexOf(">this pull<"));
12391239 expect(map.indexOf(`/looks/production/`)).toBeLessThan(
12401240 map.indexOf(`/looks/${env}/`),
12411241 );
12421242 expect(map).not.toContain("has no look");
12431243 expect(map).toContain(`/commit/${mainOid}`);
12441244 const solo = group("/solo");
1245 expect(solo).toContain("Main has no look of /solo yet.");
1245 expect(solo).not.toContain(">main<");
12461246 expect(solo).not.toContain("/looks/production/");
12471247 });
12481248
test/pull-looks-pair.test.ts added +73
@@ -0,0 +1,73 @@
1 /** The pull page sets main's look beside the head's, per page, width and theme; where main has none the head stands alone (#9669). */
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 { openPull } from "../src/actions/pulls.ts";
7 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
8 import { createApp, type App } from "../src/app.ts";
9 import { previewEnv } from "../src/apps/data.ts";
10 import { createApp as insertApp } from "../src/core/apps.ts";
11 import { recordLook } from "../src/core/looks.ts";
12 import { createUser } from "../src/core/users.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { quietLogs } from "./helpers/globals.ts";
15
16 quietLogs();
17
18 let dataDir: string;
19 let app: App;
20 let servers: Servers;
21 let page = "";
22 const MAIN = "b".repeat(40);
23 const HEAD = "c".repeat(40);
24
25 beforeAll(async () => {
26 dataDir = await mkdtemp(join(tmpdir(), "forge-pull-pair-"));
27 app = createApp({ dataDir, port: 0 });
28 const made = await createUser(app.db, {
29 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
30 password: "a-good-passphrase", adminIfFirst: true,
31 });
32 if (!made.ok) throw new Error(made.error);
33 const r = await createRepo(app, made.value, { name: "garden", visibility: "public" });
34 if (!r.ok) throw new Error(String(r.error));
35 await commitToBranch(app, made.value, r.value, { message: "seed", files: [{ path: "README.md", content: "# g\n" }] });
36 await commitToBranch(app, made.value, r.value, { branch: "one", base: "main", message: "one", files: [{ path: "one.md", content: "x\n" }] });
37 const o = await openPull(app, made.value, r.value, { title: "One", body: "", baseBranch: "main", headBranch: "one" });
38 if (!o.ok) throw new Error(String(o.error));
39 const a = insertApp(app.db, { repoId: r.value.id, slug: "garden", access: "public" });
40 if (!a.ok) throw new Error(a.error);
41 const take = (env: string, commitOid: string, extra: Record<string, unknown>) =>
42 recordLook(app.db, { appId: a.value.id, env, commitOid, kind: "phone", path: "looks/x.png", takenAs: "nobody", ...extra } as Parameters<typeof recordLook>[1]);
43 const pr = previewEnv(o.value.number);
44 take("production", MAIN, { kind: "phone" });
45 take("production", MAIN, { kind: "phone", theme: "dark" });
46 take(pr, HEAD, { kind: "phone" });
47 take(pr, HEAD, { kind: "phone", theme: "dark" });
48 take(pr, HEAD, { kind: "desktop" }); // main has no desktop look
49 servers = await serve(app);
50 page = await (await fetch(`${servers.url}/alice/garden/pulls/${o.value.number}`)).text();
51 }, 30_000);
52
53 afterAll(async () => {
54 servers.stop();
55 app.close();
56 await rm(dataDir, { recursive: true, force: true });
57 });
58
59 test("a paired look is labelled main and this pull, in light and dark", () => {
60 expect(page).toContain(">main</p>");
61 expect(page).toContain(">this pull</p>");
62 expect(page).toContain(`/looks/production/${MAIN}/phone.png`);
63 expect(page).toContain(`/looks/production/${MAIN}/phone-dark.png`);
64 expect(page).toContain(`/${HEAD}/phone.png`);
65 expect(page).toContain(`/${HEAD}/phone-dark.png`);
66 });
67
68 test("an unpaired look stands alone, and every image keeps its size", () => {
69 expect(page).toContain(`/${HEAD}/desktop.png`);
70 expect(page).not.toContain(`/production/${MAIN}/desktop`);
71 for (const img of page.match(/<img[^>]*looks\/[^>]*>/g) ?? [])
72 expect(img).toMatch(/width="\d+"[\s\S]*height="\d+"/);
73 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs