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

A frozen mirror says so in one line on its repository page, not in a boxed card #10015

Parked opened this
Closed without merging

mason/forge:mason/9953-a-frozen-mirror-says-so-in-one-line-on-i → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
2 files changed +117 −24
src/web/pages/frozen.ts +12 −24
@@ -23,7 +23,7 @@ import { loadRepo, notFoundPage, repoBase } from "../chrome.ts";
2323 import { field, readForm } from "../form.ts";
2424 import { html, type Html } from "../html.ts";
2525 import { flashTo } from "../layout.ts";
26 import { btn, card, selectField } from "../ui.ts";
26 import { btn, selectField } from "../ui.ts";
2727
2828 /** `codeberg.org` from a URL — what a person calls a forge; "" if unknown. */
2929 const hostLabel = (url: string): string => URL.parse(url)?.host ?? "";
@@ -82,24 +82,14 @@ export function frozenBlock(ctx: Ctx, repo: Repo): Html | null {
8282 // is filled with something discovery takes as it is.
8383 const forge = URL.parse(d.htmlUrl)?.origin ?? "";
8484 const connect = `/settings/origins${forge === "" ? "" : `?host=${encodeURIComponent(forge)}`}#connect`;
85 const row = (body: Html): Html =>
86 html`<li class="row"><div class="row-main">${body}</div></li>`;
8785 const action = !admin
88 ? row(
89 html`<p class="muted small">
90 An admin of this repository can reconnect it.
91 </p>`,
92 )
86 ? null
9387 : origins.length === 0
94 ? row(
95 html`<p class="small">
96 Connect an
97 account${host === "" ? null : html` at ${hostLabel(d.htmlUrl)}`}
98 under <a href="${connect}">Settings → Origins</a>: connecting one
99 reconnects this mirror by itself.
100 </p>`,
101 )
102 : row(html`<form
88 ? html`Connect an
89 account${host === "" ? null : html` at ${hostLabel(d.htmlUrl)}`} under
90 <a href="${connect}">Settings → Origins</a>: connecting one reconnects
91 this mirror by itself.`
92 : html`<form
10393 method="post"
10494 action="${repoBase(repo)}/settings/origin/reconnect"
10595 class="field-row"
@@ -114,13 +104,11 @@ export function frozenBlock(ctx: Ctx, repo: Repo): Html | null {
114104 })),
115105 })}
116106 ${btn("Reconnect", { size: "sm", variant: "primary", icon: "sync" })}
117 </form>`);
118 return card(
119 html`<ul class="list">
120 ${row(html`<p>${frozenSentence(d)}</p>`)} ${action}
121 </ul>`,
122 { tone: "attn", id: "frozen", pad: false },
123 );
107 </form>`;
108 return html`<section id="frozen">
109 <p class="small">${frozenSentence(d)}${origins.length === 0 ? html` ${action}` : null}</p>
110 ${origins.length === 0 ? null : action}
111 </section>`;
124112 }
125113
126114 /** A refusal to re-attach, in a sentence a person can act on. */
test/frozen-line.test.ts added +105
@@ -0,0 +1,105 @@
1 /** A frozen mirror says so in one line, not a boxed card (#9953). */
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 { commitToBranch, createRepo } from "../src/actions/repos.ts";
8 import { createOrigin } from "../src/core/origins.ts";
9 import { createUser, getUserByName } from "../src/core/users.ts";
10 import { createSession } from "../src/core/sessions.ts";
11 import { serve, type Servers } from "../src/http/server.ts";
12 import { seedAdmin } from "./helpers/admin.ts";
13
14 let dataDir = "";
15 let app: App, servers: Servers;
16 let admin = "", reader = "";
17
18 beforeAll(async () => {
19 dataDir = await mkdtemp(join(tmpdir(), "forge-frozen-line-"));
20 app = createApp({ dataDir, port: 0 });
21 servers = await serve(app);
22 const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "correct-horse-battery" });
23 if (!a.ok) throw new Error(a.error);
24 const b = await createUser(app.db, { origin: "seed", trusted: true, username: "bobby", email: "[email protected]", password: "correct-horse-battery" });
25 if (!b.ok) throw new Error(b.error);
26 const alice = getUserByName(app.db, "alice")!;
27 admin = `forge_session=${createSession(app.db, alice.id).token}`;
28 reader = `forge_session=${createSession(app.db, getUserByName(app.db, "bobby")!.id).token}`;
29 const made = await createRepo(app, alice, { name: "widgets", visibility: "public" });
30 if (!made.ok) throw new Error(String(made.error));
31 const seeded = await commitToBranch(app, alice, made.value, {
32 message: "Start",
33 files: [{ path: "README.md", content: "# widgets\n" }],
34 });
35 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
36 app.db
37 .query(
38 `UPDATE repo SET origin_id = NULL, origin_full_name = 'octo/widgets',
39 origin_html_url = 'https://codeberg.org/octo/widgets',
40 origin_detached_at = '2026-10-11T00:00:00.000Z',
41 last_fetch_at = '2026-10-10T00:00:00.000Z' WHERE name = 'widgets'`,
42 )
43 .run();
44 });
45 afterAll(async () => {
46 servers.stop();
47 app.close();
48 await rm(dataDir, { recursive: true, force: true });
49 });
50
51 const main = (page: string) => page.slice(page.indexOf("<main"), page.indexOf("</main>"));
52 /** Just the frozen line: from its id to the end of its section. */
53 const get = async (path: string, cookie: string) => {
54 const m = main(await (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text());
55 const at = m.indexOf('<section id="frozen">');
56 expect(at).toBeGreaterThan(-1);
57 return m.slice(at, m.indexOf("</section>", at));
58 };
59
60 for (const path of ["/alice/widgets", "/alice/widgets/branches"]) {
61 test(`${path}: one line, no card; a reader gets the sentence only`, async () => {
62 const m = await get(path, reader);
63 expect(m).toContain('id="frozen"');
64 expect(m).not.toContain('class="card');
65 expect(m).toContain("This repository mirrors");
66 expect(m).toContain("it has been frozen since");
67 expect(m).not.toContain("settings/origin/reconnect");
68 expect(m).not.toContain("Settings → Origins");
69 });
70
71 test(`${path}: an admin with no origin is pointed to connect one`, async () => {
72 const m = await get(path, admin);
73 expect(m).not.toContain('class="card');
74 expect(m).toContain("Settings → Origins");
75 expect(m).not.toContain("settings/origin/reconnect");
76 });
77 }
78
79 test("an admin with a working origin on that site gets the same-origin POST form", async () => {
80 const alice = getUserByName(app.db, "alice")!;
81 const made = createOrigin(app.db, app.config.dataDir, {
82 userId: alice.id,
83 kind: "forgejo",
84 apiUrl: "https://codeberg.org/api/v1",
85 webUrl: "https://codeberg.org",
86 login: "octo",
87 token: "octo-secret-1",
88 });
89 if (!made.ok) throw new Error(made.error);
90 for (const path of ["/alice/widgets", "/alice/widgets/branches"]) {
91 const m = await get(path, admin);
92 expect(m).not.toContain('class="card');
93 expect(m).toMatch(/<form\s+method="post"\s+action="\/alice\/widgets\/settings\/origin\/reconnect"/);
94 expect(m).toContain("Reconnect");
95 expect(await get(path, reader)).not.toContain("settings/origin/reconnect");
96 }
97 // a cross-origin POST is refused
98 const res = await fetch(`${servers.url}/alice/widgets/settings/origin/reconnect`, {
99 method: "POST",
100 headers: { cookie: admin, origin: "https://evil.example", "content-type": "application/x-www-form-urlencoded" },
101 body: `origin=${made.value.id}`,
102 redirect: "manual",
103 });
104 expect(res.status).toBeGreaterThanOrEqual(400);
105 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs