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

Merged opened this

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

Merged

scout/forge:scout/11926-one-palette-across-the-forge-and-its-app → main 0 commits fork 3 threads · 3 unresolved

  • Merged. scout/11926-one-palette-across-the-forge-and-its-app was merged into main as e4dd828.

Review

Sign in to review this change.
5 files changed +129 −11
docs/features/palette-rows.md +4 −2
@@ -4,10 +4,12 @@ row: Palette rows: numbers, people, settings, actions
44 ---
55 # Palette rows: numbers, people, settings, actions
66
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.
88
99 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.
1010
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.
1214
1315 Tests: `test/palette-rows.test.ts`.
src/core/repos.ts +8 −6
@@ -1508,7 +1508,7 @@ export function enterableApps(
15081508 readonly app: { readonly id: string; readonly access: "public" | "private" };
15091509 }[],
15101510 user: User | undefined,
1511 { named = true }: { named?: boolean } = {},
1511 { named = true, writable: known }: { named?: boolean; writable?: ReadonlySet<string> } = {},
15121512 ): Set<string> {
15131513 const out = new Set<string>();
15141514 const closed = rows.filter((r) => {
@@ -1516,11 +1516,13 @@ export function enterableApps(
15161516 return r.app.access !== "public";
15171517 });
15181518 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 );
15241526 const naming =
15251527 named && user.kind === "user" && isActive(user)
15261528 ? appsNaming(
src/web/layout.ts +24 −3
@@ -21,7 +21,7 @@ import { appsForRepos } from "../core/apps.ts";
2121 import { foundryHref } from "../actions/foundry_door.ts";
2222 import { appsRuntime } from "../apps/runtime.ts";
2323 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";
2525 import { wordClip } from "../text/word_clip.ts";
2626 import { absorbedForNav } from "../actions/features.ts";
2727 import {
@@ -30,6 +30,7 @@ import {
3030 type Repo,
3131 listReposByOwner,
3232 listReposVisibleTo,
33 writableRepoIds,
3334 } from "../core/repos.ts";
3435 import { mayDirectCrew } from "../crew/direct.ts";
3536 import { signupModeKnown } from "../settings/signup.ts";
@@ -505,7 +506,13 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html {
505506 repos.map((r) => r.id),
506507 );
507508 // 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.
outdated

This note belongs with the comment above it. Two separate comment lines about one read read as two reads.

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 );
509516 const enterable = enterableApps(
510517 ctx.app.db,
511518 repos.flatMap((repo) => {
@@ -513,7 +520,7 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html {
513520 return app === undefined ? [] : [{ repo, app }];
514521 }),
515522 ctx.auth.user,
516 { named: false },
523 { named: false, writable },
517524 );
518525 const open = repos.flatMap((r) => {
519526 const app = apps.get(r.id);
@@ -532,6 +539,20 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html {
532539 ...peopleRows(ctx.app.db, ctx.auth.user),
533540 ...settingsRows(ctx.auth.user),
534541 ...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 ),
535556 ...repos.map((r): PaletteItem => {
536557 const found = apps.get(r.id);
537558 const app = found !== undefined && enterable.has(found.id) ? found : undefined;
src/web/palette_rows.ts +35
@@ -14,6 +14,8 @@ export interface PaletteRow {
1414 c: string;
1515 /** An action: the palette asks once before it runs. */
1616 a?: 1;
17 /** A mutation: the palette posts these fields to `h`. */
18 p?: Record<string, string>;
1719 }
1820
1921 /** 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[] {
5355 ];
5456 }
5557
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
outdated

Rewrap this comment (gate --fix); it breaks mid-sentence and the function signature below is over 100 columns.

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
5691 /**
5792 * Actions: what sends something rather than going somewhere, so it asks one
5893 * 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";
33 import { snappyFixture, type SnappyFixture } from "../bench/snappy.ts";
44 import { createRepo } from "../src/actions/repos.ts";
55 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";
68 import { createSession } from "../src/core/sessions.ts";
79 import {
810 actionRows,
11 appActionRows,
912 peopleRows,
1013 settingsRows,
1114 } from "../src/web/palette_rows.ts";
@@ -151,3 +154,58 @@ test("every row kind is found by its own words", () => {
151154 expect(top("password")).toBe("/settings/password");
152155 expect(top("tell crew")).toBe("/o/n/tell");
153156 });
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",
outdated

A weak assertion: it passes if only one row kind appears. Assert both Redeploy and Stop for a running app, and nothing for a stopped one.

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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs