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

The forge toolbar on a preview names the pull it previews and links to it #16148

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/16144-the-forge-toolbar-on-a-preview-names-the → main 0 commits fork

  • Merged. scout/16144-the-forge-toolbar-on-a-preview-names-the was merged into main as 116a391.

Review

Sign in to review this change.
2 files changed +57 −1
src/web/studio/toolbar.ts +1 −1
@@ -194,7 +194,7 @@ export async function toolbarPage(ctx: Ctx): Promise<Response> {
194194 return timePhase(request, "render", () => notFoundPage(ctx));
195195 const address = pageAddress(ctx.url.searchParams.get("page") ?? "");
196196 const base = repoBase(repo);
197 const here = html`${repo.name}, ${pull ? html`preview of pull #${pull.number}` : "production"}`;
197 const here = html`${repo.name}, ${pull ? html`<a href="${base}/pulls/${pull.number}">preview of pull #${pull.number}</a>` : "production"}`;
198198 const liveNote = pull ? html`` : await timePhaseAsync(request, "live", () => liveLine(ctx, repo, base));
199199 const home = btn("Home", { href: "/", variant: "ghost" });
200200 const side = timePhase(request, "side", () => toolbarSide(ctx, repo, record, where.env, address));
test/toolbar-preview-page.test.ts added +56
@@ -0,0 +1,56 @@
1 /**
2 * The toolbar page on a preview names its pull and links to it; production says nothing extra
3 * (#16144).
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtempSync, rmSync } from "node:fs";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { newApp } from "../src/actions/apps.ts";
10 import { createApp, type App } from "../src/app.ts";
11 import { createIssue } from "../src/core/issues.ts";
12 import { createUser } from "../src/core/users.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { proveAll } from "./helpers/verified.ts";
15 import { quietLogs } from "./helpers/globals.ts";
16
17 quietLogs();
18
19 let root = "";
20 let app: App;
21 let servers: Servers;
22 let number = 0;
23
24 beforeAll(async () => {
25 root = mkdtempSync(join(tmpdir(), "forge-toolbar-prev-page-"));
26 app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" });
27 const u = await createUser(app.db, {
28 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
29 password: "a-good-passphrase", adminIfFirst: true,
30 });
31 if (!u.ok) throw new Error(u.error);
32 proveAll(app);
33 const made = await newApp(app, u.value, { name: "forge", description: "x", visibility: "public" });
34 if (!made.ok) throw new Error(String(made.error));
35 const p = createIssue(app.db, { repoId: made.value.repo.id, authorId: u.value.id, title: "t", kind: "pull" });
36 if (!p.ok) throw new Error(p.error);
37 app.db.run("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid) VALUES (?1, 'main', 'topic', ?2, ?2)", [p.value.id, "b".repeat(40)]);
38 number = p.value.number;
39 servers = await serve(app);
40 });
41 afterAll(() => {
42 servers.stop();
43 app.close();
44 rmSync(root, { recursive: true, force: true });
45 });
46
47 test("a preview's toolbar page says 'preview of pull #N' and links to the pull", async () => {
48 const body = await (await fetch(`${servers.url}/alice/forge/toolbar?env=pull-${number}`)).text();
49 expect(body).toContain(`<a href="/alice/forge/pulls/${number}">preview of pull #${number}</a>`);
50 });
51
52 test("production's toolbar page says nothing extra", async () => {
53 const body = await (await fetch(`${servers.url}/alice/forge/toolbar?env=production`)).text();
54 expect(body).toContain("forge, production");
55 expect(body).not.toContain("preview of pull");
56 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs