Public: anyone can read this; the crew can change it.
A forge admin's page lists the pinned forges: name, version, address, health and last change #10116
scout/forge:scout/10106-a-forge-admin-s-page-lists-the-pinned-fo → main 2 commits fork
6 files
changed +102
−4
docs/features/pinned-forge.md +1 −2
| @@ -6,7 +6,7 @@ A pinned forge is a forge the owner put on their own cloud. It has **no crew** a | ||
| 6 | 6 | |
| 7 | 7 | - HTTP: `GET /api/v1/admin/pinned` (forges, their changes, the targets), `POST /api/v1/admin/pinned` (deploy), `POST /api/v1/admin/pinned/:name/update`, `POST /api/v1/admin/pinned/:name/rollback`. |
| 8 | 8 | - Terminal: palette → **Pinned forges** (forge admin): `d` deploy, `u` update, `r` roll back; it follows the bus, so a change made at any door shows at once (`src/tui/screens/pinned.ts`). |
| 9 | - Web: `/deploy-to` (forge admin; linked from Cloud accounts) is a server-rendered form for cloud account, app, source, version and name. The link `/deploy-to?app=owner/name&source=https://…&version=v1.2.3` (`deployToHref` in `src/web/pinned.ts`) lands on it with those filled in after one sign-in; nothing deploys until the button is pressed. The POST is same-origin checked and calls the same `deployPinned` (`src/http/pinned_routes.ts`). | |
| 9 | - Web: `/pinned` (forge admin; 404 otherwise) lists each forge: name, app, version, address, health, last check, last change with who and when (`src/web/pages/pinned.ts`, linked from Cloud accounts). `/deploy-to` (forge admin; linked from Cloud accounts) is a server-rendered form for cloud account, app, source, version and name. The link `/deploy-to?app=owner/name&source=https://…&version=v1.2.3` (`deployToHref` in `src/web/pinned.ts`) lands on it with those filled in after one sign-in; nothing deploys until the button is pressed. The POST is same-origin checked and calls the same `deployPinned` (`src/http/pinned_routes.ts`). | |
| 10 | 10 | - MCP: `pinned_forge` with `verb` `list`, `deploy`, `update`, `rollback` (and `check`) — the same words and the same checks (`src/actions/pinned.ts`). |
| 11 | 11 | |
| 12 | 12 | A deploy names a cloud account (Settings → Cloud accounts, **writes allowed**), the app (`owner/name`), a git `source` (https) and a `version` (a 40-character commit id or a tag like `v1.2.3` — never a branch, so nothing moves under it). |
| @@ -49,7 +49,6 @@ Each id is recorded the moment it exists. A first deploy that fails before a dro | ||
| 49 | 49 | |
| 50 | 50 | - No canary result on a real account yet: the script is written, the run needs an owner's token (#8746, see Canary). |
| 51 | 51 | - No TLS or domain: the URL is `http://<droplet IPv4>:<PORT or 3000>/`. |
| 52 | - No page in the web studio lists the pinned forges yet; `/deploy-to` deploys one, and the API, MCP and terminal list them. | |
| 53 | 52 | - AWS and Azure drivers. |
| 54 | 53 | |
| 55 | 54 | ## Canary (#8746) |
src/core/pinned.ts +15
| @@ -173,3 +173,18 @@ export const portOf = (p: Pick<Pinned, "config">): string => { | ||
| 173 | 173 | |
| 174 | 174 | /** Where a pinned forge is served, once its droplet's address is known; empty before. */ |
| 175 | 175 | export const urlOf = (p: Pick<Pinned, "address" | "config">): string => (p.address === "" ? "" : `http://${p.address}:${portOf(p)}/`); |
| 176 | ||
| 177 | /** When, and with what answer, the forge was last health-checked (the `pinned.check` event), or none. */ | |
| 178 | export function lastCheckOf(db: Database, name: string): { at: string; healthy: boolean } | undefined { | |
| 179 | const row = db | |
| 180 | .query<{ payload: string; created_at: string }, [string]>( | |
| 181 | "SELECT payload, created_at FROM event WHERE kind = 'pinned.check' AND json_extract(payload, '$.name') = ?1 ORDER BY id DESC LIMIT 1", | |
| 182 | ) | |
| 183 | .get(name); | |
| 184 | if (!row) return undefined; | |
| 185 | try { | |
| 186 | return { at: row.created_at, healthy: (JSON.parse(row.payload) as { healthy?: unknown }).healthy === true }; | |
| 187 | } catch { | |
| 188 | return undefined; | |
| 189 | } | |
| 190 | } |
src/http/pinned_routes.ts +2
| @@ -10,6 +10,7 @@ import { listCloudAccounts } from "../core/cloud_account.ts"; | ||
| 10 | 10 | import { notFoundPage, signInFirst } from "../web/chrome.ts"; |
| 11 | 11 | import { field, readForm } from "../web/form.ts"; |
| 12 | 12 | import { flashTo, page } from "../web/layout.ts"; |
| 13 | import { pinnedPage } from "../web/pages/pinned.ts"; | |
| 13 | 14 | import { deployPage, nameFor, type DeployForm } from "../web/pinned.ts"; |
| 14 | 15 | import type { Handler, Ctx } from "./context.ts"; |
| 15 | 16 | import type { Router } from "./router.ts"; |
| @@ -55,6 +56,7 @@ async function deployToSubmit(ctx: Ctx): Promise<Response> { | ||
| 55 | 56 | } |
| 56 | 57 | |
| 57 | 58 | export function pinnedRoutes(router: Router<Handler>): void { |
| 59 | router.add("GET", "/pinned", pinnedPage); | |
| 58 | 60 | router.add("GET", "/deploy-to", deployToPage); |
| 59 | 61 | router.add("POST", "/deploy-to", deployToSubmit); |
| 60 | 62 | } |
src/web/pages/cloud.ts +1 −1
| @@ -153,7 +153,7 @@ export async function cloudPage(ctx: Ctx): Promise<Response> { | ||
| 153 | 153 | ${settingsLayout( |
| 154 | 154 | accountSections("cloud", { admin: true }), |
| 155 | 155 | html`${accountsCard(accounts, reads, uses)}${readsCard(reads)} |
| 156 | <p class="muted small"><a href="/settings/cloud/audit">Every vendor call today</a> · <a href="/deploy-to">Deploy a pinned forge</a></p>`, | |
| 156 | <p class="muted small"><a href="/settings/cloud/audit">Every vendor call today</a> · <a href="/pinned">Pinned forges</a> · <a href="/deploy-to">Deploy a pinned forge</a></p>`, | |
| 157 | 157 | "Account settings", |
| 158 | 158 | )}`, |
| 159 | 159 | }); |
src/web/pages/pinned.ts added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | /** | |
| 2 | * `/pinned` (#10106): the pinned forges a forge admin has put on their cloud, | |
| 3 | * read through the same `pinnedForges` the API, MCP and terminal use. Each is a | |
| 4 | * card, not a table, so nothing scrolls sideways at 390px. | |
| 5 | */ | |
| 6 | ||
| 7 | import { pinnedForges, type PinnedView } from "../../actions/pinned.ts"; | |
| 8 | import { lastCheckOf } from "../../core/pinned.ts"; | |
| 9 | import { getUserById } from "../../core/users.ts"; | |
| 10 | import type { Ctx } from "../../http/context.ts"; | |
| 11 | import { notFoundPage, signInFirst } from "../chrome.ts"; | |
| 12 | import { html, type Html } from "../html.ts"; | |
| 13 | import { page } from "../layout.ts"; | |
| 14 | import { badge, btn, card, time } from "../ui.ts"; | |
| 15 | ||
| 16 | const tone = (state: string, healthy: boolean | undefined) => | |
| 17 | state === "failed" ? "danger" : healthy === true || state === "running" ? "success" : "default"; | |
| 18 | ||
| 19 | function forgeCard(ctx: Ctx, p: PinnedView): Html { | |
| 20 | const checked = lastCheckOf(ctx.app.db, p.name); | |
| 21 | const last = p.changes[0]; | |
| 22 | const who = last ? (getUserById(ctx.app.db, last.by)?.username ?? last.by) : ""; | |
| 23 | const health = checked ? (checked.healthy ? "answering" : "not answering") : p.state; | |
| 24 | return card( | |
| 25 | html`<div class="row"> | |
| 26 | <strong class="mono">${p.name}</strong> | |
| 27 | ${badge(health, { tone: tone(p.state, checked?.healthy) })} | |
| 28 | </div> | |
| 29 | <dl class="small"> | |
| 30 | <dt class="muted">App</dt><dd class="mono">${p.app}</dd> | |
| 31 | <dt class="muted">Version</dt><dd class="mono">${p.version.length === 40 ? p.version.slice(0, 12) : p.version}</dd> | |
| 32 | <dt class="muted">Address</dt> | |
| 33 | <dd>${p.url ? html`<a href="${p.url}" rel="noopener noreferrer" class="mono">${p.url}</a>` : html`<span class="muted">not read yet; ask the API or terminal to check</span>`}</dd> | |
| 34 | <dt class="muted">Last check</dt> | |
| 35 | <dd>${checked ? time(checked.at) : html`<span class="muted">never</span>`}</dd> | |
| 36 | <dt class="muted">Last change</dt> | |
| 37 | <dd>${last ? html`${last.kind} to <span class="mono">${last.toVersion.slice(0, 12)}</span> by ${who} ${time(last.at)}` : html`<span class="muted">none</span>`}</dd> | |
| 38 | </dl>`, | |
| 39 | { extra: "pinned-forge" }, | |
| 40 | ); | |
| 41 | } | |
| 42 | ||
| 43 | export function pinnedPage(ctx: Ctx): Response { | |
| 44 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 45 | const list = pinnedForges(ctx.app, ctx.auth.user); | |
| 46 | if (!list.ok) return notFoundPage(ctx); | |
| 47 | return page({ | |
| 48 | ctx, | |
| 49 | title: "Pinned forges", | |
| 50 | body: html`<div class="page-head"><h1>Pinned forges</h1></div> | |
| 51 | ${list.value.length === 0 | |
| 52 | ? card(html`<p>No pinned forge yet.</p> | |
| 53 | <p class="muted small">Put one on your cloud: add a DigitalOcean account with writes allowed in | |
| 54 | <a href="/settings/cloud">Cloud accounts</a>, then ${btn("Deploy a pinned forge", { href: "/deploy-to" })}.</p>`) | |
| 55 | : html`<div class="stack">${list.value.map((p) => forgeCard(ctx, p))}</div> | |
| 56 | <p class="muted small"><a href="/deploy-to">Deploy a pinned forge</a></p>`}`, | |
| 57 | }); | |
| 58 | } |
test/pinned-page.test.ts +25 −1
| @@ -6,7 +6,7 @@ import { join } from "node:path"; | ||
| 6 | 6 | import { createApp, type App } from "../src/app.ts"; |
| 7 | 7 | import { addAccount, allowWrite, net as cloudNet } from "../src/actions/cloud.ts"; |
| 8 | 8 | import { net } from "../src/actions/pinned.ts"; |
| 9 | import { getPinned } from "../src/core/pinned.ts"; | |
| 9 | import { getPinned, setRemote } from "../src/core/pinned.ts"; | |
| 10 | 10 | import { createToken } from "../src/core/tokens.ts"; |
| 11 | 11 | import { createUser, getUserByName } from "../src/core/users.ts"; |
| 12 | 12 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -97,6 +97,16 @@ describe("deploy-to page", () => { | ||
| 97 | 97 | expect(getPinned(app.db, "acme")).toBeUndefined(); |
| 98 | 98 | }); |
| 99 | 99 | |
| 100 | test("/pinned with none says how to deploy one; a non-admin and signed-out get no list", async () => { | |
| 101 | const r = await get("/pinned", adminTok); | |
| 102 | expect(r.status).toBe(200); | |
| 103 | const t = await r.text(); | |
| 104 | expect(t).toContain("No pinned forge yet"); | |
| 105 | expect(t).toContain('href="/deploy-to"'); | |
| 106 | expect((await get("/pinned", bobTok)).status).toBe(404); | |
| 107 | expect((await get("/pinned")).status).toBe(303); | |
| 108 | }); | |
| 109 | ||
| 100 | 110 | test("with writes allowed the account is offered and a post deploys", async () => { |
| 101 | 111 | allowWrite(app, getUserByName(app.db, "alice"), "digitalocean", "main", true); |
| 102 | 112 | expect(await (await get("/deploy-to", adminTok)).text()).toContain("DigitalOcean / main"); |
| @@ -106,4 +116,18 @@ describe("deploy-to page", () => { | ||
| 106 | 116 | expect(p.version).toBe(V); |
| 107 | 117 | expect(p.state).toBe("running"); |
| 108 | 118 | }); |
| 119 | ||
| 120 | test("/pinned lists the forge: name, version, address as a link, last check and last change", async () => { | |
| 121 | setRemote(app.db, "acme", { address: "203.0.113.9" }); | |
| 122 | app.bus.append({ kind: "pinned.check", actorId: getUserByName(app.db, "alice")!.id, payload: { name: "acme", healthy: true } }); | |
| 123 | const t = await (await get("/pinned", adminTok)).text(); | |
| 124 | expect(t).toContain("acme"); | |
| 125 | expect(t).toContain("alice/shop"); | |
| 126 | expect(t).toContain(V.slice(0, 12)); | |
| 127 | expect(t).toContain('href="http://203.0.113.9'); | |
| 128 | expect(t).toContain("answering"); | |
| 129 | expect(t).toContain("deploy to"); | |
| 130 | expect(t).toContain("by alice"); | |
| 131 | expect((await get("/pinned", bobTok)).status).toBe(404); | |
| 132 | }); | |
| 109 | 133 | }); |
new above
offline