Public: anyone can read this; the crew can change it.
One palette across the forge and its apps — restarted from the parked branch, forge side first #16779
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/11926-one-palette-across-the-forge-and-its-app → main 0 commits fork 3 threads · 3 unresolved
5 files
changed +129
−11
docs/features/palette-rows.md +4 −2
| @@ -4,10 +4,12 @@ row: Palette rows: numbers, people, settings, actions | ||
| 4 | 4 | --- |
| 5 | 5 | # Palette rows: numbers, people, settings, actions |
| 6 | 6 | |
| 7 | The palette finds, on a repository's page, `#123` (one row, "Go to #123", built in the browser from the page's own path; issues and pulls share one number space and each address redirects to the other kind, so it never dead-ends on a kind). For signed-in viewers it also carries people, more settings pages and one action, "Tell the crew". A title is found by the forge's own search behind the palette, not by a local list: no issue or pull rides in the page. | |
| 7 | The palette finds, on a repository's page, `#123` (one row, "Go to #123", built in the browser from the page's own path; issues and pulls share one number space and each address redirects to the other kind, so it never dead-ends on a kind). For signed-in viewers it also carries people, more settings pages and actions: "Tell the crew", and, for each app the viewer may write (eight at most, among the repositories the palette lists), "Redeploy <owner/name>" and, while it runs, "Stop <owner/name>" (`appActionRows`, #11926). Those rows post the app's own `/app/production/redeploy` and `/stop` routes, so the server's gate and same-origin check decide; the palette only asks once first. A title is found by the forge's own search behind the palette, not by a local list: no issue or pull rides in the page. | |
| 8 | 8 | |
| 9 | 9 | Filtered on the server before the list exists (`src/web/palette_rows.ts`, `paletteIndex` in `src/web/layout.ts`): `here` (the page's repository, for `#N`) is sent only when it is public or the viewer may direct its crew; the rest are for a signed-in viewer only. An action row (`a: 1`) is something that sends rather than goes: the first tap or Enter arms it ("Tap or press Enter again to confirm", announced through a polite live region and `aria-description`), the second runs it. Navigation rows, the map and New app among them, never ask. |
| 10 | 10 | |
| 11 | No terminal screen: the palette is a web surface and has no TUI counterpart. | |
| 11 | Terminal: the palette itself is a web surface, but its app actions have their door. On an app's deploys screen (`src/tui/screens/deploys.ts`) a writer presses `D` to redeploy production and `S` to stop it, each after a one-line confirm, through the same `redeployEnv` and `stopEnv`; a stopped production offers only `D`, a reader neither. That is the terminal side of "Redeploy" and "Stop" here, gated the same way. | |
| 12 | ||
| 13 | The cap of eight apps: two rows an app, so at most sixteen rows, about one screen of the list; the page lists thirty repositories and a palette is a short list, not a table. | |
| 12 | 14 | |
| 13 | 15 | Tests: `test/palette-rows.test.ts`. |
src/core/repos.ts +8 −6
| @@ -1508,7 +1508,7 @@ export function enterableApps( | ||
| 1508 | 1508 | readonly app: { readonly id: string; readonly access: "public" | "private" }; |
| 1509 | 1509 | }[], |
| 1510 | 1510 | user: User | undefined, |
| 1511 | { named = true }: { named?: boolean } = {}, | |
| 1511 | { named = true, writable: known }: { named?: boolean; writable?: ReadonlySet<string> } = {}, | |
| 1512 | 1512 | ): Set<string> { |
| 1513 | 1513 | const out = new Set<string>(); |
| 1514 | 1514 | const closed = rows.filter((r) => { |
| @@ -1516,11 +1516,13 @@ export function enterableApps( | ||
| 1516 | 1516 | return r.app.access !== "public"; |
| 1517 | 1517 | }); |
| 1518 | 1518 | if (closed.length === 0 || user === undefined) return out; |
| 1519 | const writable = writableRepoIds( | |
| 1520 | db, | |
| 1521 | user, | |
| 1522 | closed.map((r) => r.repo.id), | |
| 1523 | ); | |
| 1519 | const writable = | |
| 1520 | known ?? | |
| 1521 | writableRepoIds( | |
| 1522 | db, | |
| 1523 | user, | |
| 1524 | closed.map((r) => r.repo.id), | |
| 1525 | ); | |
| 1524 | 1526 | const naming = |
| 1525 | 1527 | named && user.kind === "user" && isActive(user) |
| 1526 | 1528 | ? appsNaming( |
src/web/layout.ts +24 −3
| @@ -21,7 +21,7 @@ import { appsForRepos } from "../core/apps.ts"; | ||
| 21 | 21 | import { foundryHref } from "../actions/foundry_door.ts"; |
| 22 | 22 | import { appsRuntime } from "../apps/runtime.ts"; |
| 23 | 23 | import { doorRepos } from "../actions/front.ts"; |
| 24 | import { actionRows, peopleRows, settingsRows } from "./palette_rows.ts"; | |
| 24 | import { actionRows, appActionRows, peopleRows, settingsRows } from "./palette_rows.ts"; | |
| 25 | 25 | import { wordClip } from "../text/word_clip.ts"; |
| 26 | 26 | import { absorbedForNav } from "../actions/features.ts"; |
| 27 | 27 | import { |
| @@ -30,6 +30,7 @@ import { | ||
| 30 | 30 | type Repo, |
| 31 | 31 | listReposByOwner, |
| 32 | 32 | listReposVisibleTo, |
| 33 | writableRepoIds, | |
| 33 | 34 | } from "../core/repos.ts"; |
| 34 | 35 | import { mayDirectCrew } from "../crew/direct.ts"; |
| 35 | 36 | import { signupModeKnown } from "../settings/signup.ts"; |
| @@ -505,7 +506,13 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html { | ||
| 505 | 506 | repos.map((r) => r.id), |
| 506 | 507 | ); |
| 507 | 508 | // A private app is the writers' to see; to anyone else the row is plain. |
| 508 | // Asked once for the page, never per row. | |
| 509 | // Asked once for the page, never per row: the same read of the writable | |
| 510 | // repositories answers the palette's app actions below. | |
| 511 | const writable = writableRepoIds( | |
| 512 | ctx.app.db, | |
| 513 | ctx.auth.user, | |
| 514 | repos.filter((r) => apps.has(r.id)).map((r) => r.id), | |
| 515 | ); | |
| 509 | 516 | const enterable = enterableApps( |
| 510 | 517 | ctx.app.db, |
| 511 | 518 | repos.flatMap((repo) => { |
| @@ -513,7 +520,7 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html { | ||
| 513 | 520 | return app === undefined ? [] : [{ repo, app }]; |
| 514 | 521 | }), |
| 515 | 522 | ctx.auth.user, |
| 516 | { named: false }, | |
| 523 | { named: false, writable }, | |
| 517 | 524 | ); |
| 518 | 525 | const open = repos.flatMap((r) => { |
| 519 | 526 | const app = apps.get(r.id); |
| @@ -532,6 +539,20 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html { | ||
| 532 | 539 | ...peopleRows(ctx.app.db, ctx.auth.user), |
| 533 | 540 | ...settingsRows(ctx.auth.user), |
| 534 | 541 | ...actionRows(ctx.auth.user, tellHref), |
| 542 | ...appActionRows( | |
| 543 | repos.flatMap((r) => { | |
| 544 | const found = apps.get(r.id); | |
| 545 | return found !== undefined && enterable.has(found.id) | |
| 546 | ? [{ | |
| 547 | id: r.id, | |
| 548 | name: `${r.ownerName}/${r.name}`, | |
| 549 | base: `/${r.ownerName}/${r.name}`, | |
| 550 | state: states?.get(found.id)?.find((e) => e.env === "production")?.state, | |
| 551 | }] | |
| 552 | : []; | |
| 553 | }), | |
| 554 | writable, | |
| 555 | ), | |
| 535 | 556 | ...repos.map((r): PaletteItem => { |
| 536 | 557 | const found = apps.get(r.id); |
| 537 | 558 | const app = found !== undefined && enterable.has(found.id) ? found : undefined; |
src/web/palette_rows.ts +35
| @@ -14,6 +14,8 @@ export interface PaletteRow { | ||
| 14 | 14 | c: string; |
| 15 | 15 | /** An action: the palette asks once before it runs. */ |
| 16 | 16 | a?: 1; |
| 17 | /** A mutation: the palette posts these fields to `h`. */ | |
| 18 | p?: Record<string, string>; | |
| 17 | 19 | } |
| 18 | 20 | |
| 19 | 21 | /** The people list is bounded: the palette is a local list, not a database. */ |
| @@ -53,6 +55,39 @@ export function settingsRows(user: User | undefined): PaletteRow[] { | ||
| 53 | 55 | ]; |
| 54 | 56 | } |
| 55 | 57 | |
| 58 | /** | |
| 59 | * At most this many apps get their own action rows. Two rows an app would | |
| 60 | * crowd out the by-name rows below them: eight apps is at most sixteen | |
| 61 | * rows, about a screen of the list, and the page lists thirty repositories. | |
| 62 | */ | |
| 63 | export const PALETTE_APP_ACTIONS = 8; | |
| 64 | ||
| 65 | /** | |
| 66 | * What the viewer can do to an app from anywhere: redeploy it, and stop it | |
| 67 | * while it runs. Only apps the viewer may write get rows (`writable`, asked | |
| 68 | * once for the page), and each posts the same route the app's own page does, | |
| 69 | * so the server's gate is the one that decides; the palette asks once first | |
| 70 | * (`a`). `apps` is the forge's own data: what the page already read to draw | |
| 71 | * the by-name rows. | |
| 72 | */ | |
| 73 | export function appActionRows( | |
| 74 | apps: readonly { | |
| 75 | readonly name: string; | |
| 76 | readonly base: string; | |
| 77 | readonly id: string; | |
| 78 | readonly state: string | undefined; | |
| 79 | }[], | |
| 80 | writable: ReadonlySet<string>, | |
| 81 | ): PaletteRow[] { | |
| 82 | const out: PaletteRow[] = []; | |
| 83 | for (const app of apps.filter((a) => writable.has(a.id)).slice(0, PALETTE_APP_ACTIONS)) { | |
| 84 | out.push({ t: `Redeploy ${app.name}`, h: `${app.base}/app/production/redeploy`, c: "Actions", a: 1, p: {} }); | |
| 85 | if (app.state === "running") | |
| 86 | out.push({ t: `Stop ${app.name}`, h: `${app.base}/app/production/stop`, c: "Actions", a: 1, p: {} }); | |
| 87 | } | |
| 88 | return out; | |
| 89 | } | |
| 90 | ||
| 56 | 91 | /** |
| 57 | 92 | * Actions: what sends something rather than going somewhere, so it asks one |
| 58 | 93 | * confirmation in the palette first. Only "Tell the crew" is one; "New app" |
test/palette-rows.test.ts +58
| @@ -3,9 +3,12 @@ import { afterAll, beforeAll, expect, test } from "bun:test"; | ||
| 3 | 3 | import { snappyFixture, type SnappyFixture } from "../bench/snappy.ts"; |
| 4 | 4 | import { createRepo } from "../src/actions/repos.ts"; |
| 5 | 5 | import { addTeamMember, createOrg, createTeam } from "../src/core/orgs.ts"; |
| 6 | import { AppsRuntime } from "../src/apps/runtime.ts"; | |
| 7 | import { createApp as createAppRecord } from "../src/core/apps.ts"; | |
| 6 | 8 | import { createSession } from "../src/core/sessions.ts"; |
| 7 | 9 | import { |
| 8 | 10 | actionRows, |
| 11 | appActionRows, | |
| 9 | 12 | peopleRows, |
| 10 | 13 | settingsRows, |
| 11 | 14 | } from "../src/web/palette_rows.ts"; |
| @@ -151,3 +154,58 @@ test("every row kind is found by its own words", () => { | ||
| 151 | 154 | expect(top("password")).toBe("/settings/password"); |
| 152 | 155 | expect(top("tell crew")).toBe("/o/n/tell"); |
| 153 | 156 | }); |
| 157 | ||
| 158 | test("through the page: a running app carries Redeploy and Stop, a stopped one only Redeploy, a peer none (#11926)", async () => { | |
| 159 | const made = createAppRecord(f.app.db, { repoId: f.repos[0]!.id, slug: "palette-act", access: "public" }); | |
| 160 | if (!made.ok) throw new Error(String(made.error)); | |
| 161 | const record = made.value; | |
| 162 | const name = `${f.repos[0]!.ownerName}/${f.repos[0]!.name}`; | |
| 163 | const runtime = new AppsRuntime(f.app, { | |
| 164 | domain: "apps.test", | |
| 165 | scheme: "http", | |
| 166 | publicPort: 0, | |
| 167 | forgeUrl: f.base, | |
| 168 | concurrency: 1, | |
| 169 | }); | |
| 170 | const acts = async (cookie?: string) => | |
| 171 | (await read("/", cookie)).items.filter((i) => /^(Redeploy|Stop) /.test(i.t)); | |
| 172 | try { | |
| 173 | // Stopped (no live environment): Redeploy only, and Stop is absent. | |
| 174 | const stopped = (await acts(f.ownerCookie)).filter((r) => r.t.endsWith(` ${name}`)); | |
| 175 | expect(stopped.map((r) => r.t)).toEqual([`Redeploy ${name}`]); | |
| 176 | expect(stopped[0]!.h).toBe(`/${name}/app/production/redeploy`); | |
| 177 | // Running: both, each posting the app's own route and asking first. | |
| 178 | (runtime as unknown as { envs: Map<string, Record<string, unknown>> }).envs.set(`${record.id}/production`, { | |
| 179 | app: record, | |
| 180 | env: "production", | |
| 181 | chain: Promise.resolve(), | |
| 182 | restarts: [], | |
| 183 | live: { | |
| 184 | commitOid: "a".repeat(40), | |
| 185 | handle: { port: 4321, stop: async () => {} }, | |
| 186 | runId: "fake", | |
| 187 | since: new Date().toISOString(), | |
| 188 | manifest: { tty: null }, | |
| 189 | }, | |
| 190 | }); | |
| 191 | const running = (await acts(f.ownerCookie)).filter((r) => r.t.endsWith(` ${name}`)); | |
| 192 | expect(running.map((r) => r.t).sort()).toEqual([`Redeploy ${name}`, `Stop ${name}`]); | |
| 193 | expect(running.map((r) => r.h).sort()).toEqual([`/${name}/app/production/redeploy`, `/${name}/app/production/stop`]); | |
| 194 | expect(running.every((r) => r.a === 1)).toBe(true); | |
| 195 | // A stranger may open public apps but write none: no Redeploy or Stop row at all. | |
| 196 | expect(await acts(f.peerCookie)).toEqual([]); | |
| 197 | // Signed out: none either. | |
| 198 | expect(await acts()).toEqual([]); | |
| 199 | } finally { | |
| 200 | await runtime.stop(); | |
| 201 | } | |
| 202 | }); | |
| 203 | ||
| 204 | test("appActionRows: writable apps only, Stop only while running, capped", () => { | |
| 205 | const apps = Array.from({ length: 12 }, (_, i) => ({ id: `a${i}`, name: `o/n${i}`, base: `/o/n${i}`, state: i === 0 ? "running" : "stopped" })); | |
| 206 | const rows = appActionRows(apps, new Set(apps.map((a) => a.id))); | |
| 207 | expect(rows.map((r) => r.t).slice(0, 3)).toEqual(["Redeploy o/n0", "Stop o/n0", "Redeploy o/n1"]); | |
| 208 | expect(rows.length).toBe(8 + 1); | |
| 209 | expect(appActionRows(apps, new Set(["a3"])).map((r) => r.t)).toEqual(["Redeploy o/n3"]); | |
| 210 | expect(appActionRows(apps, new Set())).toEqual([]); | |
| 211 | }); |
new above
offline
This note belongs with the comment above it. Two separate comment lines about one read read as two reads.