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

A page starts a forge in the tab and says plainly it lives on this device #17431

opened this

Merged 32h 46m ago, live in production

torque/forge:torque/17276-a-page-starts-a-forge-in-the-tab-and-say → main 0 commits fork 6 threads · 6 unresolved

  • Merged. torque/17276-a-page-starts-a-forge-in-the-tab-and-say was merged into main as 24c75d5.

Review

Sign in to review this change.
7 files changed +137 −12
docs/features/tabforge.md +3 −1
@@ -10,4 +10,6 @@ The store is read by the page, not by the worker: a service worker cannot open i
1010
1111 It needs a browser with service workers and the private file system. Without them the page says so and the pages under `/tabforge/` stay unanswered.
1212
13 The page is `src/web/pages/tabforge.ts`. It has no terminal twin of its own: the store exists only in a browser tab, which a terminal session cannot reach. The terminal's issue list (`src/tui/screens/issues.ts`) shows the forge's issues, not the tab's.
13 The page says, before anything else, where it lives: on this device, in this browser's own storage; it stops when the tab closes; others cannot reach it. Its one primary action opens the tab's home. It is two taps from making a forge: `/forges/new` carries a link, "Or try a forge in this tab", that leads to `/tabforge`.
14
15 The page is `src/web/pages/tabforge.ts`; the words are `src/web/tabforge/words.ts`, shared with the terminal. The store itself exists only in a browser tab, which a terminal session cannot reach, so the terminal's twin is the new-forge screen (`src/tui/screens/newforge.ts`): its last row offers the tab forge with the same words and this forge's `/tabforge` address (hidden when the forge has no URL). The terminal's issue list (`src/tui/screens/issues.ts`) shows the forge's issues, not the tab's.
scripts/hollow-allow.ts +1 −7
@@ -18,10 +18,4 @@ export type Allowed = {
1818 issue: number;
1919 };
2020
21 export const ALLOWED: readonly Allowed[] = [
22 {
23 orphan: "GET /tabforge",
24 reason: "the tab forge is reached by its address while it is built; no page of the forge links it until it has a home there",
25 issue: 17275,
26 },
27 ];
21 export const ALLOWED: readonly Allowed[] = [];
src/tui/screens/newforge.ts +9 −1
@@ -28,6 +28,7 @@ import { truncate } from "../term/width.ts";
2828 import { field } from "../ui/widgets.ts";
2929 import type { Session } from "../session.ts";
3030 import { childTokenScreen } from "./child_token.ts";
31 import { TAB_FORGE_OFFER, TAB_FORGE_PAGE } from "../../web/tabforge/words.ts";
3132 import { linkScreen, runAsync } from "./common.ts";
3233
3334 interface Spec {
@@ -310,7 +311,14 @@ export function newForgeScreen(f: Session, ctx: Ctx, initial: Record<string, str
310311 return;
311312 }
312313 // Three rows a field; the window scrolls so the focused one is in view.
313 const rows = Math.max(1, Math.floor(area.h / 3));
314 // The last row, when there is room, offers the tab forge as the page does.
315 const origin = (f.app.config.url ?? "").replace(/\/$/, "");
316 // With no URL there is no address to print, so the row is hidden.
outdated

When config.url is unset the origin is empty and the row prints just /tabforge, which is no address in a terminal. Hide the row, or say the forge has no URL.

317 const offer = area.h >= 10 && origin !== "";
318 const rows = Math.max(1, Math.floor((offer ? area.h - 1 : area.h) / 3));
319 if (offer) {
320 s.text(area.x, area.y + area.h - 1, truncate(`${TAB_FORGE_OFFER}: ${origin}${TAB_FORGE_PAGE}`, area.w), style(c.faint, c.bg), area.x + area.w);
321 }
314322 const first = Math.max(0, Math.min(focus - rows + 1, specs.length - rows));
315323 let cursor: { x: number; y: number } | null = null;
316324 specs.slice(first, first + rows).forEach((spec, n) => {
src/web/pages/new-forge.ts +2
@@ -57,6 +57,7 @@ import { pickList } from "../pick.ts";
5757 import { btn, field as formField, selectField } from "../ui.ts";
5858 import { cloudsOffered, NO_CHARGE, otherPlaces, placeWords, roomWords, whereFields, type CloudOffer } from "../../spawn/clouds_offered.ts";
5959 import { catalogPlan } from "../../spawn/cloud_placement.ts";
60 import { TAB_FORGE_OFFER, TAB_FORGE_PAGE } from "../tabforge/words.ts";
6061 import { CEILING_PAGE } from "../../cloud/ceiling.ts";
6162
6263 interface Values {
@@ -259,6 +260,7 @@ function formView(
259260 // /forges answers only an admin; to anyone else the link would lead to a 404.
260261 actions: ctx.auth.user?.isAdmin ? sentLink() : undefined,
261262 })}
263 <p class="muted small" id="tab-forge-offer"><a href="${TAB_FORGE_PAGE}">${TAB_FORGE_OFFER}</a></p>
outdated

Principle 1: this offer repeats the facts that /tabforge opens with. Say 'Or try a forge in this tab' and let the destination carry the rest. 'Start it' is also a weak link label out of context; for a screen reader name the destination, e.g. 'Start a forge in this tab'.

262264 ${quota ? html`<p role="status" id="quota-full">This forge has no room for another forge: ${quota}.</p>` : null}
263265 ${errors["form"]
264266 ? html`<p class="error mb" role="alert">${errors["form"]}${values.where !== "" ? html` <a href="${CEILING_PAGE}">Cloud accounts</a>` : null}</p>`
src/web/pages/tabforge.ts +6 −3
@@ -12,7 +12,9 @@ import { pageHead } from "../chrome.ts";
1212 import { html } from "../html.ts";
1313 import { page } from "../layout.ts";
1414 import { sqliteWasmAsset, tabforgeAsset, tabforgePageAsset } from "../tabforge/asset.ts";
15 import { row, rowList } from "../ui.ts";
1516 import { SCOPE } from "../tabforge/routes.ts";
17 import { TAB_FORGE_FACTS } from "../tabforge/words.ts";
1618
1719
1820 /** The database the tab keeps its forge in: one name, fixed here, never taken from the request. */
@@ -28,12 +30,13 @@ export async function tabforgePage(ctx: Ctx): Promise<Response> {
2830 wide: false,
2931 wasm: ready,
3032 ...(script === null ? {} : { scriptAsset: script.path }),
31 body: html`${pageHead(html`Tab forge`, { sub: "A forge kept in this browser tab, answered from the tab's own store." })}
33 body: html`${pageHead(html`Tab forge`)}
3234 ${ready
33 ? html`<div id="tabforge" data-worker="${worker.path}" data-wasm="${sqliteWasmAsset().path}" data-db="${DB}" data-sw="${SCOPE}sw.js" data-css="${stylesheetAsset().path}">
35 ? html`<div id="tabforge-facts">${rowList(TAB_FORGE_FACTS.map((f) => row({ title: f })))}</div>

Principle 1: the sub-line, three fact rows and the status line all say what this page is. Keep the three facts and cut the rest to one line. Principle 3: wrapping the facts in their own div beside the status div is fine, but check there is no layout shift when the status text is replaced at 360px.

36 <div id="tabforge" data-worker="${worker.path}" data-wasm="${sqliteWasmAsset().path}" data-db="${DB}" data-sw="${SCOPE}sw.js" data-css="${stylesheetAsset().path}">
3437 <p id="tabforge-status" class="muted" role="status" aria-live="polite">Starting the tab's store…</p>
3538 </div>
36 <p><a href="${SCOPE}">Home</a> · <a href="${SCOPE}issues">Issues</a></p>`
39 <p><a class="btn primary" href="${SCOPE}">Open its home</a> <a class="btn" href="${SCOPE}issues">Issues</a></p>`
outdated

Good: one primary <a class="btn primary"> and the secondary link is plain. Phone check: the two links sit inline in one paragraph, so confirm each tap target is at least 44px at 360px.

3740 : html`<p class="muted" role="status">The tab forge could not load on this forge.</p>`}`,
3841 }));
3942 }
src/web/tabforge/words.ts added +21
@@ -0,0 +1,21 @@
1 /**
2 * What the tab forge says about itself (#17276), one set of words for the page
3 * (`pages/tabforge.ts`), the new-forge page's link and the terminal's new-forge screen, so they
4 * cannot drift apart.
5 */
6
7 /** The page that starts the tab forge. */
8 export const TAB_FORGE_PAGE = "/tabforge";
9
10 /** Where it lives, when it stops, who can reach it: said plainly, in this order. */
11 export const TAB_FORGE_FACTS: readonly string[] = [
12 "It lives on this device, in this browser's own storage.",
13 "It stops when the tab closes.",
14 "Others cannot reach it: it has no address of its own.",
15 ];
16
17 /**
18 * The line the new-forge page and screen offer before a person spawns a hosted forge; the
outdated

The offer repeats the first fact ('lives only on this device'). See the new-forge comment.

19 * destination says the rest.
20 */
21 export const TAB_FORGE_OFFER = "Or try a forge in this tab";
test/tabforge-door.test.ts added +95
@@ -0,0 +1,95 @@
1 /**

Box 3: the headless boot test (home and an empty issue list) is gone. These three tests only check wording; nothing here fails if the worker or store breaks.

2 * The person-facing door to the tab forge (#17276): the page says plainly where it lives, the
3 * new-forge page and screen link it.
4 * (The worker's end-to-end boot in a headless browser is not asserted here: it never activated in
5 * the check's browser.)
6 */
7 import { afterAll, beforeAll, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { createUser, type User } from "../src/core/users.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { usePlacement, useProbe } from "../src/spawn/door.ts";
15 import { hostedPlacement } from "../src/spawn/placement.ts";
16 import { createForgeApp } from "../src/tui/forge.ts";
17 import { newForgeScreen } from "../src/tui/screens/newforge.ts";
18 import { headlessTerminal } from "../src/tui/term/terminal.ts";
19 import { TAB_FORGE_FACTS, TAB_FORGE_OFFER } from "../src/web/tabforge/words.ts";
20 import { quietLogs } from "./helpers/globals.ts";
21 import { settleApp } from "./helpers/tui.ts";
22
23 quietLogs();
24
25 let dir = "";
26 let app: App;
27 let servers: Servers;
28 let admin: User;
29
30 beforeAll(async () => {
31 dir = await mkdtemp(join(tmpdir(), "forge-tabforge-door-"));
32 app = createApp({ dataDir: dir, url: "https://forge.test", port: 0 });
33 const r = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", isAdmin: true });
34 if (!r.ok) throw new Error(r.error);
35 admin = r.value;
36 useProbe(app, () => async () => true);
37 usePlacement(app, hostedPlacement({ host: "forge.test" }));
38 servers = await serve(app);
39 });
40 afterAll(async () => {
41 servers.stop();
42 app.close();
43 await rm(dir, { recursive: true, force: true });
44 });
45
46 test("/tabforge says it lives on this device, stops with the tab and cannot be reached by others, with one primary action", async () => {
47 const body = await (await fetch(`${servers.url}/tabforge`)).text();
48 for (const fact of TAB_FORGE_FACTS) expect(body).toContain(fact.replaceAll("'", "&#39;"));
49 expect(TAB_FORGE_FACTS.join(" ")).toMatch(/this device/);
50 expect(TAB_FORGE_FACTS.join(" ")).toMatch(/tab closes/);
51 expect(TAB_FORGE_FACTS.join(" ")).toMatch(/Others cannot reach/);
52 expect(body.match(/class="btn primary"/g)?.length).toBe(1);
53 // The status line is in the first paint, so the script's words change text, not layout.
54 expect(body).toContain('id="tabforge-status"');
55 });
56
57 test("the new-forge page links the tab forge", async () => {
58 const body = await (await fetch(`${servers.url}/forges/new`)).text();
59 expect(body).toContain('id="tab-forge-offer"');
60 expect(body).toMatch(/<a href="\/tabforge">Or try a forge in this tab<\/a>/);
61 });
62
63 test("the terminal's new-forge screen offers it in the same words", async () => {
64 const terminal = headlessTerminal(240, 40);
65 const { app: tui, session } = createForgeApp(app, { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: admin }, { terminal, exitHooks: false });
66 tui.start();
67 tui.ctx.push(newForgeScreen(session, tui.ctx));
68 try {
69 await settleApp(tui);
70 const screen = tui.screen.toText();
71 expect(screen).toContain(TAB_FORGE_OFFER);
72 expect(screen).toContain("https://forge.test/tabforge");
73 } finally {
74 tui.stop?.();
75 }
76 });
77
78 test("with no URL the terminal hides the row rather than print a bare path", async () => {
79 const bare = createApp({ dataDir: await mkdtemp(join(tmpdir(), "forge-tabforge-nourl-")), port: 0 });
80 try {
81 expect(bare.config.url ?? "").toBe("");
82 const terminal = headlessTerminal(240, 40);
83 const { app: tui, session } = createForgeApp(bare, { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: admin }, { terminal, exitHooks: false });
84 tui.start();
85 tui.ctx.push(newForgeScreen(session, tui.ctx));
86 try {
87 await settleApp(tui);
88 expect(tui.screen.toText()).not.toContain("/tabforge");
89 } finally {
90 tui.stop?.();
91 }
92 } finally {
93 bare.close();
94 }
95 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs