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

Settings' "Move to another owner" section has no sideways scroll at 390px, with a look on the pull #10178

Closed opened this
Closed without merging

mason/forge:mason/10157-settings-move-to-another-owner-section-h → main 5 commits fork 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
6 files changed +146 −3
forge.json +2 −2
@@ -4,8 +4,8 @@
44 "api.github.com"
55 ],
66 "app": {
7 "looks": ["/", "/front", "/explore", "/board", "/notes", "/feed", "/review", "/new", "/pinned", "/releases", "/apps", "/repos", "/map", "/system", "/talk", "/flow", "/resilience", "/settings", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/milestones"],
8 "looksAsOwner": ["/", "/flow", "/talk", "/system", "/resilience", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/milestones"],
7 "looks": ["/", "/front", "/explore", "/board", "/notes", "/feed", "/review", "/new", "/pinned", "/releases", "/apps", "/repos", "/map", "/system", "/talk", "/flow", "/resilience", "/settings", "/preview-admin/sample", "/preview-admin/sample/settings/transfer", "/preview-admin/sample/next", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/milestones"],
8 "looksAsOwner": ["/", "/flow", "/talk", "/system", "/resilience", "/preview-admin/sample", "/preview-admin/sample/settings/transfer", "/preview-admin/sample/next", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/milestones"],
99 "run": "bun run src/main.ts",
1010 "install": "",
1111 "health": "/healthz",
src/http/server.ts +2
@@ -381,6 +381,7 @@ import {
381381 settingsUpdate,
382382 waveCut,
383383 archiveSubmit,
384 transferPage,
384385 transferSubmit,
385386 provenanceSubmit,
386387 mirrorStop,
@@ -1430,6 +1431,7 @@ export function buildRouter(): Router<Handler> {
14301431 router.add("POST", "/:owner/:name/settings", settingsUpdate);
14311432 router.add("POST", "/:owner/:name/settings/wave", waveCut);
14321433 router.add("POST", "/:owner/:name/settings/archive", archiveSubmit);
1434 router.add("GET", "/:owner/:name/settings/transfer", transferPage);
14331435 router.add("POST", "/:owner/:name/settings/transfer", transferSubmit);
14341436 router.add("POST", "/:owner/:name/settings/provenance", provenanceSubmit);
14351437 router.add("POST", "/:owner/:name/settings/mirror/stop", mirrorStop);
src/spawn/preview-looks.ts +8
@@ -120,6 +120,13 @@ export const PREVIEW_SETTINGS_PAGES: readonly string[] = [
120120 "/settings/usage",
121121 ];
122122
123 /**
124 * The sample's Settings scrolled to "Move to another owner", for its phone
125 * look (#10157): the GET of the move's address lands on `settings#move`, so
126 * the look's own name carries no fragment.
127 */
128 export const PREVIEW_MOVE_PAGE = `${PREVIEW_REPO_HOME}/settings/transfer`;
129
123130 export interface OwnerLook {
124131 readonly page: string;
125132 readonly kind: LookKind;
@@ -147,6 +154,7 @@ export const PREVIEW_OWNER_LOOKS: readonly OwnerLook[] = [
147154 PREVIEW_ISSUE_EDIT_PAGE,
148155 PREVIEW_RESILIENCE_PAGE,
149156 PREVIEW_SEARCH_PAGE,
157 PREVIEW_MOVE_PAGE,
150158 ...PREVIEW_SETTINGS_PAGES,
151159 ].flatMap((page) => (["desktop", "phone"] as const).map((kind) => ({ page, kind })));
152160
src/web/pages/settings.ts +13 −1
@@ -416,7 +416,7 @@ export async function settingsPage(
416416 </div>
417417 </form>
418418 </section>`;
419 const move = html`<section class="settings-block">
419 const move = html`<section class="settings-block" id="move">
420420 <h2>Move to another owner</h2>
421421 <form method="get" action="/-/confirm">
422422 <input type="hidden" name="to" value="${base}/settings/transfer" />
@@ -574,6 +574,18 @@ export async function archiveSubmit(ctx: Ctx): Promise<Response> {
574574 );
575575 }
576576
577 /**
578 * GET /:owner/:name/settings/transfer — the move section itself: Settings,
579 * scrolled to "Move to another owner". The address a refused move leaves in
580 * the bar, and the page the preview's phone look of the section is taken of
581 * (#10157). Gated like Settings, so a stranger learns nothing.
582 */
583 export function transferPage(ctx: Ctx): Response {
584 const repo = timedAdminRepo(ctx);
585 if (!repo) return repoNotFound(ctx);
586 return redirect(`${repoBase(repo)}/settings#move`);
587 }

A real route added only so the preview look can land on #move. Drive the look with the fragment/scroll in the capture instead, so production carries no tooling-only address.

588
577589 /**
578590 * POST /:owner/:name/settings/transfer — move the repository to another
579591 * owner, through the action (never core). A refusal is the settings page
test/server-timing-sweep.test.ts +1
@@ -43,6 +43,7 @@ const REDIRECTS = new Set([
4343 "/alice/forge/following",
4444 "/alice/forge/settings/autonomy",
4545 "/alice/forge/settings/crew",
46 "/alice/forge/settings/transfer",
4647 "/alice/forge/tells",
4748 "/alice/forge/tells/new",
4849 "/big",
test/settings-move-fit.test.ts added +120
@@ -0,0 +1,120 @@
1 /**
2 * Settings › "Move to another owner" fits a 390 px phone (#10157): the section
3 * ships no fixed width over 390 px, its owner field is full width, and its
4 * refusal sentence wraps; where a chromium runs, the page is measured at
5 * 390x844 and scrolls no wider than the viewport.
6 */
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { readFileSync } from "node:fs";
9 import { mkdtemp, rm } from "node:fs/promises";
10 import { tmpdir } from "node:os";
11 import { join } from "node:path";
12 import { createApp, type App } from "../src/app.ts";
13 import { createRepo } from "../src/actions/repos.ts";
14 import { createUser, getUserByName } from "../src/core/users.ts";
15 import { serve, type Servers } from "../src/http/server.ts";
16 import { TRANSFER_SAID } from "../src/actions/transfer.ts";
17 import { utilities as base } from "../src/web/style/base.ts";
18 import { components } from "../src/web/style/components.ts";
19 import { content } from "../src/web/style/content.ts";
20 import { PREVIEW_MOVE_PAGE, PREVIEW_OWNER_LOOKS } from "../src/spawn/preview-looks.ts";
21 import { findChromium } from "../src/looks/capture.ts";
22 import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts";
23
24 const PATH = "/alice/fit/settings";
25 let dir: string;
26 let app: App;
27 let servers: Servers;
28 let page = "";
29 let refused = "";
30 let session: { name: string; value: string };
31
32 beforeAll(async () => {
33 dir = await mkdtemp(join(tmpdir(), "forge-move-fit-"));
34 app = createApp({ dataDir: dir, port: 0 });
35 servers = await serve(app);
36 const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
37 if (!made.ok) throw new Error(made.error);
38 const cookie = ((await fetch(`${servers.url}/signin`, { method: "POST", body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), redirect: "manual" })).headers.get("set-cookie") ?? "").split(";")[0]!;
39 const r = await createRepo(app, getUserByName(app.db, "alice")!, { name: "fit", visibility: "public" });
40 if (!r.ok) throw new Error(String(r.error));
41 session = { name: cookie.slice(0, cookie.indexOf("=")), value: cookie.slice(cookie.indexOf("=") + 1) };
42 page = await (await fetch(`${servers.url}${PATH}`, { headers: { cookie } })).text();
43 const res = await fetch(`${servers.url}${PATH}/transfer`, {
44 method: "POST",
45 headers: { cookie, origin: servers.url, "content-type": "application/x-www-form-urlencoded" },
46 body: new URLSearchParams({ owner: "n".repeat(64) }),
47 redirect: "manual",
48 });
49 refused = await res.text();
50 }, 30_000);
51 afterAll(async () => {
52 servers.stop();
53 app.close();
54 await rm(dir, { recursive: true, force: true });
55 });
56
57 describe("Settings › Move to another owner at 390 px", () => {
58 test("the section and a refusal are on the page", () => {
59 expect(page).toContain("Move to another owner");
60 expect(refused).toContain(TRANSFER_SAID.unknown_owner);
61 expect(refused).toContain("n".repeat(64));
62 });
63
64 test("no inline width, and no shipped rule fixes a width over 390 px", () => {
65 for (const html of [page, refused]) {
66 expect(html).not.toMatch(/style="[^"]*(?:^|[;\s"])(?:min-)?width\s*:/i);
67 const over: string[] = [];
68 for (const css of [base, components, content, ...(html.match(/<style[^>]*>[\s\S]*?<\/style>/g) ?? [])]) {
69 for (const m of css.matchAll(/(?<![-\w(])(?:min-)?width\s*:\s*(-?[\d.]+)(px|rem|em|ch)\b/g)) {
70 if (Number(m[1]) * (m[2] === "px" ? 1 : m[2] === "ch" ? 8 : 16) > 390) over.push(m[0]);
71 }
72 }
73 expect(over).toEqual([]);
74 }
75 });
76
77 test("the section has an anchor, and the preview takes its phone look scrolled to it", () => {
78 expect(page).toContain('<section class="settings-block" id="move">');
79 expect(PREVIEW_OWNER_LOOKS).toContainEqual({ page: PREVIEW_MOVE_PAGE, kind: "phone" });
80 expect(PREVIEW_MOVE_PAGE).toBe("/preview-admin/sample/settings/transfer");
outdated

This browser measurement is the only real proof of box 1 and it was skipped. It must run (or be shown run) on the pull with its logged result, and a look must be attached.

81 const app = JSON.parse(readFileSync(join(import.meta.dir, "..", "forge.json"), "utf8")).app as { looks: string[]; looksAsOwner: string[] };
82 expect(app.looks).toContain(PREVIEW_MOVE_PAGE);
83 expect(app.looksAsOwner).toContain(PREVIEW_MOVE_PAGE);
84 });
85
86 test("GET of the move's address lands on Settings at the section, for its admin only", async () => {
87 const mine = await fetch(`${servers.url}${PATH}/transfer`, { headers: { cookie: `${session.name}=${session.value}` }, redirect: "manual" });
88 expect(mine.status).toBe(303);
89 expect(mine.headers.get("location")).toBe(`${PATH}#move`);
90 const stranger = await fetch(`${servers.url}${PATH}/transfer`, { redirect: "manual" });
91 expect(stranger.status).not.toBe(303);
92 expect(stranger.headers.get("location")).toBeNull();
93 });
94
95 test("the owner field is full width and the actions row wraps", () => {
96 expect(components).toMatch(/\.input\s*\{[^}]*width:\s*100%/);
97 expect(components).toMatch(/\.form-actions\s*\{[^}]*flex-wrap:\s*wrap/);
98 });
99 });
100
101 const found = findChromium();

The only proof of box 1 skips without chromium. The forge check must run it, or the pull records a measured scrollWidth; the CSS-text checks above do not prove the page fits.

102 const chromium = found !== undefined && chromiumRuns(found) ? found : undefined;
103 if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so the move section phone look is not measured");
104
105 describe.skipIf(chromium === undefined)("Settings › Move to another owner, measured at 390x844", () => {
106 test("no sideways scroll", async () => {
107 const measure = `(() => {
108 const vw = document.documentElement.clientWidth;
109 const h = [...document.querySelectorAll("h2")].find((e) => /Move to another owner/.test(e.textContent));
110 const scope = h ? [...h.parentElement.querySelectorAll("*")] : [];
111 const overflowing = scope.filter((el) => el.getBoundingClientRect().right > vw + 1).slice(0, 8).map((el) => el.tagName.toLowerCase());
112 return JSON.stringify({ scrollWidth: document.documentElement.scrollWidth, viewportWidth: vw, scoped: scope.length, overflowing });
113 })()`;
114 const m = JSON.parse(await evaluateLoaded(chromium!, `${servers.url}${PATH}/transfer`, { width: 390, height: 844 }, [session], measure)) as { scrollWidth: number; viewportWidth: number; scoped: number; overflowing: string[] };
115 console.log(`move settings 390x844: ${JSON.stringify(m)}`);
116 expect(m.scoped).toBeGreaterThan(0);
117 expect(m.overflowing).toEqual([]);
118 expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth);
119 }, 30_000);
120 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs