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

The home page carries no warning banner: a test fails if any notice renders above the first content on / for a healthy forge #13452

Merged opened this

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

Merged

scout/forge:scout/13428-the-home-page-carries-no-warning-banner → main 7 commits fork

  • Merged. scout/13428-the-home-page-carries-no-warning-banner was merged into main as f40dc80.

Review

Sign in to review this change.
24 files changed +234 −298
src/actions/runs.ts +17 −9
@@ -1,11 +1,10 @@
11 /**
22 * Run actions: look at a repository's runs and their logs, cancel one,
3 * queue a finished agent run's task again, and — for the workers that produce runs — announce a run's state on the
4 * outbox. Reading follows the repository's visibility (a run's log is as
5 * private as the code it ran), and a private app's runs follow the app: a
6 * deploy log carries the app's own output, so only someone who may enter
7 * the app reads them (#620). Cancelling takes write access; announcing is
8 * the system's own voice and takes no actor.
3 * queue a finished agent run's task again, and — for the workers that produce runs — announce a
4 * run's state on the outbox. Reading follows the repository's visibility (a run's log is as private
5 * as the code it ran), and a private app's runs follow the app: a deploy log carries the app's own
6 * output, so only someone who may enter the app reads them (#620). Cancelling takes write access;
7 * announcing is the system's own voice and takes no actor.
98 */
109
1110 import { commitVerdicts, isCommitId, releaseCheck, type CommitCheck } from "../checks/commit_check.ts";
@@ -268,12 +267,18 @@ export async function checkOfCommit(
268267 );
269268 }
270269
271 /** One look of a check as the API words it: how many screens tall, and whether a phone look scrolls sideways. */
270 /**
271 * One look of a check as the API words it: how many screens tall, and whether a phone look scrolls
272 * sideways.
273 */
272274 export interface LookFigures {
273275 readonly look: string;
274276 readonly screens: string;
275277 readonly sideways: boolean;
276 /** The window and page as measured (`scrollWidth` vs `innerWidth` says whether it fits); absent when none was recorded. */
278 /**
279 * The window and page as measured (`scrollWidth` vs `innerWidth` says whether it fits); absent
280 * when none was recorded.
281 */
277282 readonly size?: PageSize;
278283 }
279284
@@ -297,7 +302,10 @@ export function looksOfCheck(
297302 }));
298303 }
299304
300 /** The own green or red verdicts of a page of commits, for whoever may read the runs; empty otherwise. */
305 /**
306 * The own green or red verdicts of a page of commits, for whoever may read the runs; empty
307 * otherwise.
308 */
301309 export function verdictsOfCommits(
302310 app: App,
303311 actor: User | undefined,
src/actions/talk.ts +4 −1
@@ -68,7 +68,10 @@ export function talk(app: App, user: User | undefined, text: string, files: read
6868 return said;
6969 }
7070
71 /** Edit the last message and resend it, regenerate the last reply, or retry a failed turn (#8817), in the named conversation or the latest. */
71 /**
72 * Edit the last message and resend it, regenerate the last reply, or retry a failed turn (#8817),
73 * in the named conversation or the latest.
74 */
7275 export function talkAgain(app: App, user: User | undefined, how: RedoHow, text = "", conversationId?: string): Result<Said, TalkRefusal> {
7376 if (user === undefined) return err("unauthorized");
7477 const options = conversationOptions(app);
src/core/conversation_markdown.ts +4 −3
@@ -2,7 +2,8 @@
22 * A talk conversation as one Markdown document (#13307): who, when, the text,
33 * and each attachment as a link, turns in the order they were written. The
44 * download route, the MCP `say` tool (`action: download`) and the terminal's talk screen all
5 * return this text; each turn's words sit in a fenced block, and only the conversation's owner is ever served it.
5 * return this text; each turn's words sit in a fenced block, and only the conversation's owner is
6 * ever served it.
67 */
78 import type { Database } from "bun:sqlite";
89 import { err, ok, type Result } from "../kernel/result.ts";
@@ -18,8 +19,8 @@ const plain = (s: string): string => s.replace(/[\r\n]+/g, " ").replace(/[[\]()<
1819 export const MAX_TEXT = 1_000_000;
1920
2021 /**
21 * The newest turns that still count (an edit's replaced ones are left out), oldest first, read a page
22 * at a time until `MAX_TEXT` is reached. `cut` is true when older turns were left unread.
22 * The newest turns that still count (an edit's replaced ones are left out), oldest first, read a
23 * page at a time until `MAX_TEXT` is reached. `cut` is true when older turns were left unread.
2324 */
2425 function recentTurns(db: Database, userId: string, conversationId: string): { turns: Turn[]; cut: boolean } {
2526 const out: Turn[] = [];
src/core/everyday.ts −12
@@ -74,18 +74,6 @@ export function keepAdmin(db: Database, admin: User): void {
7474 export const keptAdmin = (db: Database, admin: User): boolean =>
7575 getUserSetting(db, admin.id, CHOICE) === "admin";
7676
77 /** Whether the forge should ask this person to make an everyday account. */
78 export function askForEveryday(db: Database, user: User | undefined): boolean {
79 return (
80 user !== undefined &&
81 user.isAdmin &&
82 user.kind === "user" &&
83 everydayOf(db, user) === undefined &&
84 adminOf(db, user) === undefined &&
85 !keptAdmin(db, user)
86 );
87 }
88
8977 /** The two sentences of why, said the same way everywhere. */
9078 export const EVERYDAY_WHY =
9179 "Admin can change everything here, including who can see what. Use it when you mean to; day to day, use an account that cannot break the forge.";
src/crew/converge.ts +3 −1
@@ -313,7 +313,9 @@ export async function settleConverge(
313313 app: App,
314314 fork: Repo,
315315 parent: Repo,
316 /** Whoever moved the fork's branch (a merge, a push): the only name the close may be said under. */
316 /**
317 * Whoever moved the fork's branch (a merge, a push): the only name the close may be said under.
318 */
317319 by?: User,
318320 ): Promise<boolean> {
319321 const issue = convergeIssue(app, fork, parent);
src/spawn/clients.ts −5
@@ -521,11 +521,6 @@ export function servedNow(app: App): readonly ClientRow[] {
521521 return served.get(app)?.rows ?? [];
522522 }
523523
524 /** The forges proposed for archive, from the last pass: what the needs-you line says (#12262). */
525 export function archiveNeeds(app: App): ClientRow[] {
526 return servedNow(app).filter((r) => r.archive !== null && r.archive !== undefined);
527 }
528
529524 /** A forge was changed here (stopped, removed, a link made): the next list is read afresh. */
530525 export function dropServed(app: App): void {
531526 served.delete(app);
src/spawn/where.ts −11
@@ -242,17 +242,6 @@ export function whereOf(
242242 };
243243 }
244244
245 /**
246 * "N forges run inside this forge's own process; move them into sandboxes": the home's one line, or
247 * null when none does.
248 */
249 export function inProcessNeed(count: number): string | null {
250 if (count <= 0) return null;
251 return count === 1
252 ? "1 forge runs inside this forge's own process; move it into a sandbox"
253 : `${count} forges run inside this forge's own process; move them into sandboxes`;
254 }
255
256245 /** What the forge's owner is told, once, in their own forge: the whole of what changed for them. */
257246 export const SANDBOXED_WORDS =
258247 "This forge now runs in its own sandbox; nothing else changed.";
src/tui/screens/changelog.ts +14 −4
@@ -51,7 +51,8 @@ export interface Line {
5151 /**
5252 * The landed pulls told in chapters, as the page tells them (`release/chapter_groups.ts` decides
5353 * membership): a heading line per chapter, newest first, with its closing day or "open", then its
54 * pulls, one line each; pulls that served none sit under "Between chapters". `keep` narrows the pulls.
54 * pulls, one line each; pulls that served none sit under "Between chapters". `keep` narrows the
55 * pulls.
5556 */
5657 export function chapterLines(groups: readonly Group[], keep: (l: Landing) => boolean = () => true, filtering = false): Line[] {
5758 const out: Line[] = [];
@@ -79,7 +80,10 @@ export function nearLines(near: readonly Near[]): string[] {
7980
8081 type Repo = { owner: string; name: string };
8182
82 /** Who built a pull, in plain words: "by Scout, with Claude Sonnet 5.5"; empty when the commit says nothing. */
83 /**
84 * Who built a pull, in plain words: "by Scout, with Claude Sonnet 5.5"; empty when the commit says
85 * nothing.
86 */
8387 export function creditWords(by: string | undefined, withNames: readonly string[] | undefined): string {
8488 const parts = [by === undefined ? "" : `by ${by}`, withNames === undefined || withNames.length === 0 ? "" : `with ${withNames.join(", ")}`];
8589 return parts.filter((p) => p !== "").join(", ");
@@ -87,7 +91,10 @@ export function creditWords(by: string | undefined, withNames: readonly string[]
8791
8892 type Pull = ReleaseEntry["pulls"][number];
8993
90 /** A release's pulls as lines: pulls of one shape gathered ("Keys on … · 9 pulls"), the rest `#N title`. */
94 /**
95 * A release's pulls as lines: pulls of one shape gathered ("Keys on … · 9 pulls"), the rest
96 * `#N title`.
97 */
9198 export function pullLines(pulls: readonly Pull[], credits: ReadonlyMap<number, string>): { row: ListRow; pulls: readonly Pull[] }[] {
9299 return gather(pulls).map((g) =>
93100 g.landings.length === 1
@@ -96,7 +103,10 @@ export function pullLines(pulls: readonly Pull[], credits: ReadonlyMap<number, s
96103 );
97104 }
98105
99 /** One release's pulls; Enter opens a pull as the changelog's Enter once did, and a gathered line lists its own pulls. */
106 /**
107 * One release's pulls; Enter opens a pull as the changelog's Enter once did, and a gathered line
108 * lists its own pulls.
109 */
100110 function releasePulls(f: Session, ctx: Ctx, repoRef: Repo, entry: ReleaseEntry, credits: ReadonlyMap<number, string>, title = entry.version): Screen {
101111 const state = new ListState();
102112 const lines = pullLines(entry.pulls, credits);
src/tui/screens/dashboard.ts +1 −41
@@ -38,7 +38,6 @@ import { sinceDigest } from "../../web/studio/since.ts";
3838 import { askForSomething } from "./tell.ts";
3939 import { movingLines } from "./moving.ts";
4040 import { pipelineNow } from "../../web/studio/living.ts";
41 import { askForEveryday, everydayOf, EVERYDAY_WHY, keepAdmin } from "../../core/everyday.ts";
4241 import { mayView } from "../../core/sealed.ts";
4342 import { applyFleetIds, previewFleetIds, undoFleetOp } from "../../actions/fleet.ts";
4443 import { plain } from "./boards.ts";
@@ -266,14 +265,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
266265 */
267266 let figures: string[] = [];
268267 /**
269 * The web home's everyday ask, as one muted line at the head (#8046): why,
270 * and the two answers, while an admin has made no choice; once linked, the
271 * name of the account used day to day. Nobody else gets the row.
272 */
273 let everyday: { line: string; asking: boolean } | undefined;
274 /**
275 * A new forge's owner before their first tell: the home is one line, "what do you want built",
276 * and the everyday offer waits.
268 * A new forge's owner before their first tell: the home is one line, "what do you want built".
277269 */
278270 let firstTell = false;
279271 /**
@@ -386,7 +378,6 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
386378 // A client's home never carries the forge-wide figures, on either door.
387379 figures = [];
388380 firstTell = steps.some((s) => s.key === "tell" && !s.done);
389 everyday = everydayHead();
390381 if (firstTell) {
391382 clientLines = [FIRST_TELL_LINE, crewFirstText(f.app)];
392383 ctx.invalidate();
@@ -435,29 +426,11 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
435426 ctx.invalidate();
436427 };
437428
438 const everydayHead = (): typeof everyday => {
439 if (f.user === undefined || !f.user.isAdmin || f.user.kind !== "user" || firstTell) return undefined;
440 if (askForEveryday(f.db, f.user))
441 return { line: `${EVERYDAY_WHY} E makes it on the web · K keeps using admin`, asking: true };
442 const daily = everydayOf(f.db, f.user);
443 return daily === undefined
444 ? undefined
445 : { line: `Day to day you are ${daily.username}; this is the admin account.`, asking: false };
446 };
447
448 /** `K`: the admin keeps working as admin, recorded for web and terminal alike. */
449 const keepAdminHere = (): void => {
450 if (f.user === undefined) return;
451 keepAdmin(f.db, f.user);
452 reload();
453 ctx.toast("kept admin; you will not be asked again", "success");
454 };
455429
456430 const reload = (): void => {
457431 // The server remembers the *choice* and nothing about the laptop, so
458432 // this is a list of decisions — never a status that would be stale.
459433 pins = f.user ? listPins(f.db, f.user.id) : [];
460 everyday = everydayHead();
461434 startedFrom = f.user === undefined ? null : startedFromText(f.app.config.dataDir);
462435 pinned = f.user ? pinnedRepoIds(f.db, f.user.id) : new Set<string>();
463436 all = listReposVisibleTo(f.db, f.user, { limit: 200 });
@@ -1190,9 +1163,6 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
11901163 ...(focus === "repos" && f.user !== undefined && shown().some(mayArchive)
11911164 ? [binding(["space"], "mark"), ...(markedRepos.size > 0 ? [binding(["a"], "archive marked")] : [])]
11921165 : []),
1193 ...(everyday?.asking === true
1194 ? [binding(["E"], "everyday account"), binding(["K"], "keep admin")]
1195 : []),
11961166 binding(["r"], "refresh"),
11971167 ];
11981168 },
@@ -1210,11 +1180,6 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
12101180 // A site admin's forge strip, as the board's: "All fine" or a line
12111181 // per cause. Anyone else gets no rows and no reads.
12121182 let body = area;
1213 if (everyday !== undefined) {
1214 const [strip, rest] = split(body, "v", [len(1), fill(1)]);
1215 s.text(strip!.x, strip!.y, truncate(everyday.line, strip!.w), style(c.mutedFg, c.bg), strip!.x + strip!.w);
1216 body = rest!;
1217 }
12181183 if (startedFrom !== null) {
12191184 const [strip, rest] = split(body, "v", [len(1), fill(1)]);
12201185 s.text(strip!.x, strip!.y, truncate(startedFrom, strip!.w), style(c.mutedFg, c.bg), strip!.x + strip!.w);
@@ -1493,11 +1458,6 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
14931458 openOnWeb(f, ctx, "/asks", "Asks");
14941459 return true;
14951460 }
1496 if (e.key === "E" && everyday?.asking === true) {
1497 openOnWeb(f, ctx, "/settings", "Making your everyday account");
1498 return true;
1499 }
1500 if (e.key === "K" && everyday?.asking === true) return keepAdminHere(), true;
15011461 if (e.key === "A" && f.user) {
15021462 openOnWeb(f, ctx, "/settings", "Account settings");
15031463 return true;
src/tui/screens/talk_chats.ts +4 −1
@@ -39,7 +39,10 @@ const BAD_TITLE = `A title is up to ${TITLE_MAX} characters, on one line.`;
3939
4040 const WHO: Readonly<Record<string, string>> = { person: "You", agent: "Forge", tool: "Tool", confirm: "Asks" };
4141
42 /** The conversation as the Markdown download holds it, to read and scroll; the file itself is the web's /talk/:id/download. */
42 /**
43 * The conversation as the Markdown download holds it, to read and scroll; the file itself is the
44 * web's /talk/:id/download.
45 */
4346 function downloadScreen(f: Session, ctx: Ctx, chat: Conversation): Screen {
4447 const scroll = new Scroll();
4548 const made = f.user === undefined ? undefined : conversationMarkdown(f.app.db, f.user.id, chat.id, publicOrigin(f.app.config.url, `http://localhost:${f.app.config.port}`));
src/web/pages/home_flow.ts +11 −72
@@ -66,18 +66,12 @@ import { btn, field } from "../ui.ts";
6666 import { chart, figuresGrid, figuresSection } from "./home_figures.ts";
6767 import { tellBox } from "../studio/living.ts";
6868 import { requestsCard } from "../requests_card.ts";
69 import { askForEveryday } from "../../core/everyday.ts";
70 import type { ReachAsk } from "../../core/child_reach.ts";
71 import { reachNeeds } from "../../spawn/child_reach.ts";
72 import { archiveNeeds, type ClientRow } from "../../spawn/clients.ts";
73 import { reachNeed } from "./hosted-forges.ts";
7469 import { adminAskNeed } from "../studio/ask_admin.ts";
7570 import { asksToAnswer, type AskView } from "../../actions/ask_admin.ts";
76 import { inProcessNeed, whereOf } from "../../spawn/where.ts";
71 import { whereOf } from "../../spawn/where.ts";
7772 import { untoldAnswer, markTold } from "../../core/requests.ts";
7873 import { YOURE_IN_MESSAGE } from "../../actions/users.ts";
7974 import { spawnedForge } from "../../spawn/claim.ts";
80 import { forgeHasNoKey, NO_KEY_AT, NO_KEY_LINE } from "../../crew/no_key.ts";
8175 import { startedFromLine } from "../started_from.ts";
8276
8377
@@ -311,56 +305,25 @@ interface Need {
311305 }
312306
313307 /**
314 * What needs this person, most pressing first: alarms, then notices, then what waits on them. One
315 * line says the first two; the proof's own record is
316 * on /releases.
317 */
318 /**
319 * Who the strip is drawn for; `everyday` is an admin with no everyday account and no recorded
320 * choice to keep working as admin.
308 * Who the strip is drawn for. It names only work waiting on this person and what the forge itself
309 * has stopped doing (a failing proof, an alarm). A setting that needs attention (no model key, a
310 * hosted forge's ask to reach a host, a forge proposed for archive, a forge in this process) is one
311 * line on its own settings page, never on / (#13428).
321312 */
322313 interface StripViewer {
323314 readonly id: string;
324315 readonly isAdmin: boolean;
325 readonly everyday?: boolean;
326 /**
327 * What hosted forges asked to reach and no admin has answered (`spawn/child_reach.ts`); an
328 * admin's only.
329 */
330 readonly reach?: readonly ReachAsk[];
331316 /**
332317 * What people here asked this viewer, as one who can change it, to change
333318 * (`actions/ask_admin.ts`).
334319 */
335320 readonly asked?: readonly AskView[];
336 /** Hosted forges proposed for archive (`spawn/archive_proposal.ts`); an admin's only. */
337 readonly archive?: readonly ClientRow[];
338 /** Forges that run inside this forge's own process and could be in a sandbox; an admin's only. */
339 readonly inProcess?: number;
340 /** No model key reaches any repository: the crew cannot start (`crew/no_key.ts`). */
341 readonly noKey?: true;
342321 }
343322
344323 /**
345 * The everyday account's one quiet line: the step is on its own page, where "Keep using admin" is
346 * remembered.
324 * What needs this person, most pressing first: alarms, then notices, then what waits on them. One
325 * line says the first two; the proof's own record is on /releases.
347326 */
348 const EVERYDAY_NEED: Need = { says: "You are signed in as the admin. Make an everyday account", href: "/settings/everyday", tone: "notice" };
349
350 /**
351 * One line for the forges proposed for archive; its link opens the confirm page with every one
352 * picked.
353 */
354 function archiveNeed(rows: readonly ClientRow[]): Need {
355 const names = rows.map((r) => r.name);
356 const one = names.length === 1;
357 return {
358 says: `${one ? `${names[0]} is` : `${names.length} hosted forges are`} proposed for archive (${rows[0]!.archive!.why}${one ? "" : ", and more"}): archive is recommended`,
359 href: `/forges/archive?${names.map((n) => `name=${encodeURIComponent(n)}`).join("&")}`,
360 tone: "notice",
361 };
362 }
363
364327 function needsOf(picture: LanePicture, viewer: StripViewer, dataDir: string, now: number): Need[] {
365328 const proof = viewer.isAdmin ? proofNotice(dataDir, running().version, now) : undefined;
366329 const asks = picture.asks[viewer.id];
@@ -370,21 +333,11 @@ function needsOf(picture: LanePicture, viewer: StripViewer, dataDir: string, now
370333 ...(viewer.isAdmin ? (picture.strip?.needs ?? []).map((n) => ({ says: n.says, href: n.href, tone: "alarm" as const })) : []),
371334 ];
372335 return [
373 // First of all: nothing the crew would do starts until it is answered, and it is one setting.
374 ...(viewer.noKey === true ? [{ says: NO_KEY_LINE, href: NO_KEY_AT, tone: "alarm" as const }] : []),
375336 ...alarms,
376 // A person on a hosted forge is stopped until this is answered: first among what can wait.
377 ...(viewer.isAdmin ? (viewer.reach ?? []).map((a, n) => ({ ...reachNeed(a, n), tone: "notice" as const })) : []),
378337 // A person here is stopped until one who can change it does: theirs to answer, admin or not.
379338 ...(viewer.asked ?? []).map((a, n) => ({ ...adminAskNeed(a, n), tone: "notice" as const })),
380 // Proposed, never done by itself: one line, the recommended choice one tap away.
381 ...(viewer.isAdmin && (viewer.archive ?? []).length > 0 ? [archiveNeed(viewer.archive!)] : []),
382 // Work hidden inside this forge's own process: one line for all of them, and /forges moves
383 // each.
384 ...(viewer.isAdmin && inProcessNeed(viewer.inProcess ?? 0) !== null ? [{ says: inProcessNeed(viewer.inProcess ?? 0)!, href: "/forges", tone: "notice" as const }] : []),
385339 ...(proof?.tone === "notice" ? [{ says: proof.sentence, href: "/releases#proof", tone: "notice" as const }] : []),
386340 ...(waiting === null ? [] : [{ says: waiting, href: "/review", tone: "notice" as const }]),
387 ...(viewer.everyday === true ? [EVERYDAY_NEED] : []),
388341 ];
389342 }
390343
@@ -555,20 +508,6 @@ export async function forgesRegion(app: App, wait: boolean): Promise<Html> {
555508 return forgesHtml(kept);
556509 }
557510
558 /**
559 * How many forges run inside this forge's own process, from the last reading of the ledgers: never
560 * a
561 * read on a request (a new one starts behind a stale answer). `bun test` waits, so a test reads
562 * what it wrote.
563 */
564 async function inProcessForges(app: App, now: number): Promise<number> {
565 const kept = forgesKept.get(app);
566 if (kept !== undefined && now - kept.at < FORGES_REUSE_MS) return kept.inProcess;
567 const reading = readForges(app, now);
568 if (process.env["NODE_ENV"] === "test") return (await reading)?.inProcess ?? kept?.inProcess ?? 0;
569 return kept?.inProcess ?? 0;
570 }
571
572511 // ---- the page ----
573512
574513 /**
@@ -625,11 +564,11 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited
625564 // or lean.
626565 const spawned = known !== undefined ? known.spawned : await timePhaseAsync(ctx.request, "spawned", () => spawnedForge(ctx.app));
627566 const wide = user.isAdmin && spawned === undefined;
628 const strip = picture === undefined ? readingStrip(wide) : stripRegion(picture, { id: user.id, isAdmin: wide, ...(wide && forgeHasNoKey(ctx.app) ? { noKey: true as const } : {}), everyday: askForEveryday(ctx.app.db, user), asked: asksToAnswer(ctx.app, user), ...(wide ? { reach: reachNeeds(ctx.app), archive: archiveNeeds(ctx.app), inProcess: await inProcessForges(ctx.app, now) } : {}) }, ctx.app.config.dataDir, now);
567 const strip = picture === undefined ? readingStrip(wide) : stripRegion(picture, { id: user.id, isAdmin: wide, asked: asksToAnswer(ctx.app, user) }, ctx.app.config.dataDir, now);
629568 // What the old home also carried and is not a lane: the box that tells the crew (with Notes and
630569 // Talk), the welcome after an account is allowed, a
631 // spawned forge's address, and a stranger's request for an account. The everyday-account ask is
632 // one line in the strip.
570 // spawned forge's address, and a stranger's request for an account. Setting notices (no key,
571 // reach asks, archive proposals) live on their settings pages, not here.
633572 const allowed = untoldAnswer(ctx.app.db, user.id) === "allowed";
634573 if (allowed) markTold(ctx.app.db, user.id, new Date().toISOString());
635574 const before = html`${allowed ? html`<div class="toast" data-tone="success" role="status" id="youre-in"><strong>${YOURE_IN_MESSAGE}</strong> Your account is open: tell the crew what you want to build.</div>` : null}
@@ -759,7 +698,7 @@ export async function liveStripFragment(ctx: Ctx): Promise<Response> {
759698 const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx, user), "lane", now));
760699 const rendering = performance.now();
761700 const wide = user.isAdmin && (await spawnedForge(ctx.app)) === undefined;
762 const res = fragment(picture === undefined ? readingStrip(wide) : stripRegion(picture, { id: user.id, isAdmin: wide, ...(wide && forgeHasNoKey(ctx.app) ? { noKey: true as const } : {}), everyday: askForEveryday(ctx.app.db, user), asked: asksToAnswer(ctx.app, user), ...(wide ? { reach: reachNeeds(ctx.app), archive: archiveNeeds(ctx.app), inProcess: await inProcessForges(ctx.app, now) } : {}) }, ctx.app.config.dataDir, now), { request: ctx.request });
701 const res = fragment(picture === undefined ? readingStrip(wide) : stripRegion(picture, { id: user.id, isAdmin: wide, asked: asksToAnswer(ctx.app, user) }, ctx.app.config.dataDir, now), { request: ctx.request });
763702 notePhase(ctx.request, "render", performance.now() - rendering);
764703 return res;
765704 }
src/web/pages/hosted-forges.ts +7 −42
@@ -28,13 +28,11 @@ import {
2828 timePhaseAsync,
2929 } from "../../core/route_timing.ts";
3030 import type { Ctx } from "../../http/context.ts";
31 import { askSentence } from "../../spawn/child_reach.ts";
3231 import { notFoundPage, settingsLayout, signInFirst } from "../chrome.ts";
3332 import { backTo, field as formField, readForm } from "../form.ts";
3433 import { html, type Html } from "../html.ts";
3534 import { flashTo, page } from "../layout.ts";
3635 import { badge, btn, field, row, time } from "../ui.ts";
37 import { agoWords } from "./origin-reach.ts";
3836 import { accountSections } from "./origins.ts";
3937
4038 /** What the switch turns on, in the words the page and every pointer to it use. */
@@ -46,7 +44,10 @@ const AT_ONCE = "This applies at once: nothing restarts.";
4644 const hidden = (name: string, value: string): Html =>
4745 html`<input type="hidden" name="${name}" value="${value}" />`;
4846
49 /** One ask, with its answers: Allow for this forge, Allow for every hosted forge, Not now. `back` is where the admin lands after. */
47 /**
48 * One ask, with its answers: Allow for this forge, Allow for every hosted forge, Not now. `back` is
49 * where the admin lands after.
50 */
5051 function askRow(a: ReachAsk, back: string): Html {
5152 const base = `/forges/${a.child}/reach`;
5253 return row({
@@ -268,7 +269,9 @@ export async function reachSwitch(ctx: Ctx): Promise<Response> {
268269 });
269270 }
270271
271 /** One of the answers, as a route: act, then back where the admin was with what changed said once. */
272 /**
273 * One of the answers, as a route: act, then back where the admin was with what changed said once.
274 */
272275 function answer(
273276 act: (
274277 ctx: Ctx,
@@ -352,41 +355,3 @@ export const forgeReachRevoke = answer(revoke);
352355 // POST /settings/hosted-forges/reach/remove — take a name back from every hosted forge.
353356 export const reachRemove = answer(revoke, true);
354357
355 // ---- the home's line ----
356
357 /** One waiting ask as the home's line says it, with its two answers; `n` keeps the form ids apart. */
358 export function reachNeed(
359 a: ReachAsk,
360 n: number,
361 ): { says: string; href: string; after: Html; forms: Html } {
362 const base = `/forges/${a.child}/reach`;
363 const fields = html`${hidden("host", a.host)}${hidden("back", "/")}`;
364 return {
365 says: `${askSentence(a)} (${agoWords(a.lastAt)})`,
366 href: `/forges#forge-${a.child}`,
367 after: html`<span class="hf-need-acts"
368 >${btn("Allow", {
369 size: "sm",
370 variant: "primary",
371 form: `reach-allow-${n}`,
372 label: `Allow ${a.child} to reach ${a.host}`,
373 })}${btn("Not now", {
374 size: "sm",
375 variant: "ghost",
376 form: `reach-later-${n}`,
377 label: `Put aside ${a.child}'s ask to reach ${a.host}`,
378 })}</span
379 >`,
380 forms: html`<form
381 method="post"
382 action="${base}/allow"
383 id="reach-allow-${n}"
384 hidden
385 >
386 ${fields}
387 </form>
388 <form method="post" action="${base}/later" id="reach-later-${n}" hidden>
389 ${fields}
390 </form>`,
391 };
392 }
test/admin-journey.test.ts +1 −2
@@ -80,7 +80,7 @@ describe("the new owner who makes an everyday account", () => {
8080
8181 // The home asks in one quiet line that leads to the step's own page.
8282 const home = (await f.page(admin, "/")).text;
83 expect(home).toContain(`<a href="/settings/everyday">${HOME_LINE}</a>`);
83 expect(home).not.toContain(HOME_LINE);
8484 expect(home).not.toContain('role="alert"');
8585
8686 // Two sentences of why, said once; one primary action; staying on admin is offered, on purpose.
@@ -130,7 +130,6 @@ describe("the new owner who stays on admin, on purpose", () => {
130130 test("Keep using admin is one post, receipted and recorded, and the home stops asking; its agent token is labelled admin", async () => {
131131 const f = await freshForge();
132132 const admin = await f.firstSignIn("bea");
133 expect((await f.page(admin, "/")).text).toContain(HOME_LINE);
134133
135134 const kept = await f.post(admin, "/settings/everyday/keep", {});
136135 expect(kept.status).toBe(303);
test/ask-to-reach.test.ts +15 −17
@@ -53,8 +53,6 @@ import {
5353 import { launchSpecFor } from "../src/spawn/cell.ts";
5454 import { childGate, reachNeeds } from "../src/spawn/child_reach.ts";
5555 import { firstBoot } from "../src/spawn/first-boot.ts";
56 import { agoWords } from "../src/web/pages/origin-reach.ts";
57 import { reachNeed } from "../src/web/pages/hosted-forges.ts";
5856 import { newFakeState, serveFakeForge, type FakeForge } from "./fake-origin.ts";
5957 import { quietLogs } from "./helpers/globals.ts";
6058 import { everyoneIsAMember } from "./helpers/members.ts";
@@ -63,7 +61,9 @@ quietLogs();
6361
6462 const PASSWORD = "alice-login-secret";
6563 const PARENT_URL = "https://forge.test";
66 /** A person's own forge on their own domain. `.invalid` never resolves, so nothing here dials out. */
64 /**
65 * A person's own forge on their own domain. `.invalid` never resolves, so nothing here dials out.
66 */
6767 const HOST = "git.benjiverse.invalid";
6868 const OTHER = "code.elsewhere.invalid";
6969 const PAT = "pat-for-the-fake-forge";
@@ -191,7 +191,8 @@ beforeAll(async () => {
191191 refused: spec.onRefused,
192192 },
193193 );
194 // The forge's code behind it, as in a cell: the proxy is the way out, and the parent's door is named.
194 // The forge's code behind it, as in a cell: the proxy is the way out, and the parent's door is
195 // named.
195196 for (const name of ["HTTPS_PROXY", "https_proxy", "FORGE_PARENT_LOCAL"])
196197 env[name] = process.env[name];
197198 process.env["HTTPS_PROXY"] = `http://127.0.0.1:${gatePort}`;
@@ -283,7 +284,8 @@ describe("the refusal says what stands in the way and offers the one action", ()
283284 expect(body["setting"]).toBe("children.originEgress");
284285 expect(String(body["says"])).not.toContain("children.originEgress");
285286
286 // The parent's admin can see what was asked for: one line for the forge and the name, however many tries.
287 // The parent's admin can see what was asked for: one line for the forge and the name, however
288 // many tries.
287289 const lines = warned.mock.calls
288290 .map((c) => String(c[0]))
289291 .filter((l) => l.startsWith("[egress]"));
@@ -359,7 +361,8 @@ describe("the refusal says what stands in the way and offers the one action", ()
359361 expect(
360362 await askHost(maria.app, person(maria, "bob"), { host: "db.internal" }),
361363 ).toEqual({ ok: false, error: "private_name" });
362 // A name that looks public and points inside a network: the host looks, and does not take the ask.
364 // A name that looks public and points inside a network: the host looks, and does not take the
365 // ask.
363366 addresses.set("wiki.sneaky.invalid", ["10.0.0.8"]);
364367 const sneaky = await askHost(maria.app, person(maria, "bob"), {
365368 host: "wiki.sneaky.invalid",
@@ -402,14 +405,6 @@ describe("ask, allow for that forge, and the connect runs by itself", () => {
402405 state: "asked",
403406 });
404407 expect(events(parent, "forge.reach_asked")).toHaveLength(1);
405 // What the home's line says, with its two answers.
406 const need = reachNeed(waiting[0]!, 0);
407 expect(need.says).toBe(
408 `maria asks to reach ${HOST} to connect an origin (${agoWords(waiting[0]!.lastAt)})`,
409 );
410 expect(need.href).toBe("/forges#forge-maria");
411 expect(String(need.after)).toContain("Allow");
412 expect(String(need.after)).toContain("Not now");
413408
414409 // The child shows where the ask stands, where the error was.
415410 const page = await (
@@ -530,7 +525,8 @@ describe("ask, allow for that forge, and the connect runs by itself", () => {
530525 expect(mayReach(maria, HOST)).toBe(true);
531526 expect(mayReach(otto, HOST)).toBe(false);
532527
533 // The same gate, never restarted: its answer is no longer its list's. The name is looked up, and `.invalid` has no address.
528 // The same gate, never restarted: its answer is no longer its list's. The name is looked up,
529 // and `.invalid` has no address.
534530 const tried = await connectOrigin(maria.app, person(maria, "bob"), {
535531 host: HOST,
536532 token: PAT,
@@ -621,7 +617,8 @@ describe("ask, allow for that forge, and the connect runs by itself", () => {
621617
622618 describe("what a granted name still cannot do", () => {
623619 test("a granted name that resolves inside the network is refused by the gate", async () => {
624 // As if a name allowed in good faith later pointed at this machine: the grant is written past the door's checks.
620 // As if a name allowed in good faith later pointed at this machine: the grant is written past
621 // the door's checks.
625622 addGrant(parent.db, {
626623 bodyId: maria.bodyId,
627624 child: "maria",
@@ -711,7 +708,8 @@ describe("for every hosted forge, not now, and across restarts", () => {
711708 { host: OTHER, state: "later" },
712709 ]);
713710
714 // The parent's rows are its database's: a second forge over the same data reads the same asks and grants.
711 // The parent's rows are its database's: a second forge over the same data reads the same asks
712 // and grants.
715713 const again = createApp({ dataDir: dir, url: PARENT_URL, port: 0 });
716714 try {
717715 expect(listAsks(again.db)).toMatchObject([
test/everyday-language.test.ts +7 −5
@@ -1,4 +1,6 @@
1 /** The everyday-account ask on home speaks the home page's language: a block, not a card (#9957). */
1 /**
2 * The everyday-account ask on home speaks the home page's language: a block, not a card (#9957).
3 */
24 import { afterAll, beforeAll, expect, test } from "bun:test";
35 import { mkdtemp, rm } from "node:fs/promises";
46 import { tmpdir } from "node:os";
@@ -33,9 +35,9 @@ const home = async () => main(await (await fetch(`${servers.url}/`, { headers: {
3335
3436 const LINE = /<a href="\/settings\/everyday">You are signed in as the admin\. Make an everyday account<\/a>/;
3537
36 test("home asks for an everyday account in one line of the needs-you row, never a form", async () => {
38 test("home carries no ask for an everyday account, and no form (#13428: it is one line on its own page)", async () => {
3739 const m = await home();
38 expect(m).toMatch(LINE);
40 expect(m).not.toMatch(LINE);
3941 expect(m).not.toContain('id="everyday"');
4042 expect(m).not.toContain('action="/settings/everyday"');
4143 expect(m).not.toContain('name="email"');
@@ -53,14 +55,14 @@ test("the step is on its own page: why, a username, one passkey button, and Keep
5355 expect(block).not.toContain('type="password"');
5456 });
5557
56 test("dismissing is a same-origin POST, and home stops asking", async () => {
58 test("dismissing is a same-origin POST, and home never asks", async () => {
5759 const cross = await fetch(`${servers.url}/settings/everyday/keep`, {
5860 method: "POST",
5961 headers: { cookie: admin, origin: "https://evil.example", "content-type": "application/x-www-form-urlencoded" },
6062 redirect: "manual",
6163 });
6264 expect(cross.status).toBe(403);
63 expect(await home()).toMatch(LINE);
65 expect(await home()).not.toMatch(LINE);
6466 const ok = await fetch(`${servers.url}/settings/everyday/keep`, {
6567 method: "POST",
6668 headers: { cookie: admin, origin: servers.url, "content-type": "application/x-www-form-urlencoded" },
test/everyday.test.ts +2 −2
@@ -106,9 +106,9 @@ describe("the everyday account", () => {
106106 await rm(dataDir, { recursive: true, force: true });
107107 });
108108
109 test("an admin's home asks for an everyday account in one line; its own page says why; anyone else's home does not ask", async () => {
109 test("an admin's home is quiet about it; its own page says why; anyone else's home does not ask", async () => {
110110 const home = await page(await signIn("ada"), "/");
111 expect(home).toContain('<a href="/settings/everyday">You are signed in as the admin. Make an everyday account</a>');
111 expect(home).not.toContain("Make an everyday account");
112112 expect(home).not.toContain('action="/settings/everyday"');
113113 const admin = await page(await signIn("ada"), "/settings/everyday");
114114 expect(admin).toContain("Make your everyday account");
test/forge-archive.test.ts +5 −4
@@ -271,7 +271,7 @@ test("a claimed forge's owner is mailed before it can be proposed, and only a se
271271 expect((await listChildren(parent)).some((c) => c.name === "claimed-idle")).toBe(true);
272272 });
273273
274 test("an unclaimed forge untouched for 30 days is proposed in the needs-you line, never archived by itself", async () => {
274 test("an unclaimed forge untouched for 30 days is proposed on /forges, not on the home, never archived by itself", async () => {
275275 const { child } = await makeForge("long-quiet", false);
276276 child.close();
277277 const file = join(dir, "spawn", "long-quiet.json");
@@ -281,10 +281,11 @@ test("an unclaimed forge untouched for 30 days is proposed in the needs-you line
281281 useChildFetch(parent, async () => Response.json({ claimed: false }));
282282 const rows = await servedRows(parent);
283283 expect(rows.find((r) => r.name === "long-quiet")?.archive).toMatchObject({ recommended: "Archive", ownerTold: null });
284 const home = await fetch(`${servers.url}/`, { headers: { authorization: `Bearer ${token}` } });
285 const text = await home.text();
284 const home = await (await fetch(`${servers.url}/`, { headers: { authorization: `Bearer ${token}` } })).text();
285 expect(home).not.toContain("proposed for archive");
286 const text = await (await fetch(`${servers.url}/forges`, { headers: { authorization: `Bearer ${token}` } })).text();
286287 expect(text).toContain("long-quiet");
287 expect(text).toContain("proposed for archive");
288 expect(text).toContain("Proposed for archive");
288289 expect(text).toContain("/forges/archive?name=long-quiet");
289290 // Proposed only: it is still here.
290291 expect(await childNamed(parent, "long-quiet")).toBeDefined();
test/fork-follow-conflict.test.ts +4 −2
@@ -93,14 +93,16 @@ test("a conflicting update opens exactly one issue; a repeat and a clean update
9393 expect(issue!.body).toContain(`Upstream commit: ${parentTip}`);
9494 expect(issue!.body).toContain("bob: README.md");
9595 expect(issue!.body).toContain("one file changed on both sides: README.md.");
96 // Stopped: the fork's code is as it was, the update staged beside it and the default branch untouched.
96 // Stopped: the fork's code is as it was, the update staged beside it and the default branch
97 // untouched.
9798 const dir = repoDir(app.reposRoot, fork.ownerName, fork.name);
9899 expect(await tipOf(fresh(fork))).toBe(before);
99100 expect(await resolveOid(dir, "refs/following/main")).toBe(parentTip);
100101 // Autonomy is off: the issue is for people, and no agent work is queued for it.
101102 expect(listRuns(app.db, fork.id, { kind: "agent", limit: 50 }).length).toBe(0);
102103
103 // The same upstream commit asked again, with the first issue closed: nothing new, deterministically.
104 // The same upstream commit asked again, with the first issue closed: nothing new,
105 // deterministically.
104106 setIssueState(app.db, issue!.id, "closed", "dropped");
105107 const again = await convergeFork(app, fresh(fork), fresh(parent), undefined);
106108 expect(again.kind).toBe("nothing");
test/home-quiet.test.ts added +86
@@ -0,0 +1,86 @@
1 /**
2 * Quiet home (#13428): / for a signed-in owner with every setting at its default carries no
3 * notice, warning or alert above the first content. Where a setting needs attention it is one
4 * line on its own settings page. The failure names the offending notice.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtemp as mkTmp, rm as rmDir } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { createRepo } from "../src/actions/repos.ts";
12 import { createUser, getUserByName } from "../src/core/users.ts";
13 import { forgeHasNoKey, forgetNoKey, NO_KEY_LINE } from "../src/crew/no_key.ts";
14 import { createSession } from "../src/core/sessions.ts";
15 import { serve, type Servers } from "../src/http/server.ts";
16 import { seedAdmin } from "./helpers/admin.ts";
17
18 const NOTICE = /<[a-z][^<>]*?(?:\brole="(?:alert|status|alertdialog)"|\bclass="[^"]*\b(?:banner|notice|notice-danger|warning|hf-need)\b[^"]*")[^<>]*>[\s\S]{0,200}/gi;
19 /**
20 * Notices standing above the first content: the lanes (or table) that are the page's first content.
21 * A body with no such marker throws: scanning all of it would pass or fail on markup, not on the
22 * rule.
23 */
24 export function noticesAbove(body: string): string[] {
25 const at = body.search(/\bclass="hf-lanes"|\bclass="hf-table|\bclass="hf-lane[\s"]/i);
26 if (at < 0) throw new Error("home-quiet: no lane or table marker in the body; the anchor moved");
27 const head = body.slice(0, at);
28 return [...head.matchAll(NOTICE)].map((m) => m[0].replace(/\s+/g, " ").slice(0, 160));
29 }
30
31 let dataDir = "", cookie = "";
32 let app: App, servers: Servers;
33
34 beforeAll(async () => {
35 dataDir = await mkTmp(join(tmpdir(), "forge-homequiet-"));
36 app = createApp({ dataDir, port: 0 });
37 servers = await serve(app);
38 const admin = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "correct-horse-battery" });
39 if (!admin.ok) throw new Error(admin.error);
40 cookie = `forge_session=${createSession(app.db, admin.value.id).token}`;
41 }, 30_000);
42
43 afterAll(async () => {
44 servers.stop();
45 app.close();
46 await rmDir(dataDir, { recursive: true, force: true });
47 });
48
49 test("/ for a default owner has no notice above the first content", async () => {
50 const res = await fetch(`${servers.url}/`, { headers: { cookie } });
51 expect(res.status).toBe(200);
52 const body = await res.text();
53 expect(body).toContain("Your forge, right now");
54 // The anchor itself: the first content is there to be found.
55 expect(body).toMatch(/\bclass="hf-lanes"/);
56 expect({ offending: noticesAbove(body) }).toEqual({ offending: [] });
57 });
58
59 test("a forge whose crew has no model key says so on /settings/crew, and / stays quiet about it", async () => {
60 // An autonomous repository owned by someone who is not an admin: the forge's own key is not
61 // theirs.
62 const bob = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "correct-horse-battery" });
63 if (!bob.ok) throw new Error(bob.error);
64 const made = await createRepo(app, (await getUserByName(app.db, "alice"))!, { name: "garden", visibility: "public" });
65 if (!made.ok) throw new Error(`repo: ${JSON.stringify(made.error)}`);
66 app.db.query("UPDATE repo SET autonomy = 'autonomous', owner_id = ?2 WHERE id = ?1").run(made.value.id, bob.value.id);
67 forgetNoKey(app.db);
68 expect(forgeHasNoKey(app)).toBe(true);
69 const home = await (await fetch(`${servers.url}/`, { headers: { cookie } })).text();
70 expect(home).not.toContain(NO_KEY_LINE);
71 expect(home).not.toContain("/settings/crew#crew-key");
72 expect(home).toContain("Nothing needs you right now.");
73 expect({ offending: noticesAbove(home) }).toEqual({ offending: [] });
74 const crew = await (await fetch(`${servers.url}/settings/crew`, { headers: { cookie } })).text();
75 expect(crew).toContain('id="crew-key"');
76 });
77
78 test("a body with no lane marker is an error, not a vacuous pass", () => {
79 expect(() => noticesAbove('<nav class="banner">x</nav><p>no lanes</p>')).toThrow("anchor moved");
80 });
81
82 test("the detector names a notice, and spares plain content", () => {
83 expect(noticesAbove('<p class="hf-need" role="status">Make an account</p><div class="hf-lanes">x</div>')).toHaveLength(1);
84 expect(noticesAbove('<div role="alert">x</div><div class="hf-lanes">y</div>')[0]).toContain("role=\"alert\"");
85 expect(noticesAbove('<h1>Hi</h1><div class="hf-lanes"><div role="alert">x</div></div>')).toEqual([]);
86 });
test/no-model-key.test.ts +2 −3
@@ -86,10 +86,9 @@ describe("a forge with no model key", () => {
8686 expect(needsStack({ app }, bob).some((n) => n.sentence === NO_KEY_LINE)).toBe(false);
8787 });
8888
89 test("the home strip says it to the admin, and the link's target is a field that does not take focus", async () => {
89 test("the home does not say it (#13428); the crew settings page does, and its key field does not take focus", async () => {
9090 const home = await page("/");
91 expect(home).toContain(NO_KEY_LINE);
92 expect(home).toContain('href="/settings/crew#crew-key"');
91 expect(home).not.toContain(NO_KEY_LINE);
9392 const crew = await page("/settings/crew");
9493 expect(crew).toContain('id="crew-key"');
9594 expect(crew).not.toContain("autofocus");
test/no-polling.test.ts +19 −5
@@ -36,10 +36,15 @@ const NO_TIMER_PAGES = ["/system", "/flow"];
3636 * that only the owner's own submit changes; a pushed patch would move a handle under a drag. */
3737 const STREAM_PAGES = ["/system"];
3838
39 /** A page as the browser gets it: its markup, and every script it runs (fetched files and inline bodies), apart. */
39 /**
40 * A page as the browser gets it: its markup, and every script it runs (fetched files and inline
41 * bodies), apart.
42 */
4043 export interface RenderedPage { html: string; scripts: string[] }
4144
42 /** A stream a script opens. `data-live` alone, never `data-live-every`, the beat this guard forbids. */
45 /**
46 * A stream a script opens. `data-live` alone, never `data-live-every`, the beat this guard forbids.
47 */
4348 const STREAM = /EventSource\s*\(|data-live(?![-\w])/;
4449
4550 /** Script types that hold data, not code. */
@@ -230,7 +235,10 @@ describe("no rendered page polls", () => {
230235 * reads each page's markup and the scripts it loads.
231236 */
232237
233 /** The text of the balanced `(…)` or `{…}` whose opener is at `open`. Strings and comments are not understood: a bracket inside one skews it. */
238 /**
239 * The text of the balanced `(…)` or `{…}` whose opener is at `open`. Strings and comments are not
240 * understood: a bracket inside one skews it.
241 */
234242 function balanced(src: string, open: number): string {
235243 const pairs: Record<string, string> = { "(": ")", "{": "}" };
236244 const o = src[open]!, c = pairs[o]!;
@@ -242,7 +250,10 @@ function balanced(src: string, open: number): string {
242250 return src.slice(open + 1);
243251 }
244252
245 /** The body of a function a script names: `function name(…) {…}` or `name = (…) => {…}` / `name = function (…) {…}`. */
253 /**
254 * The body of a function a script names: `function name(…) {…}` or `name = (…) => {…}` /
255 * `name = function (…) {…}`.
256 */
246257 function bodyOf(src: string, name: string): string | undefined {
247258 const m = new RegExp(`(?:function\\s+${name}\\s*\\(|\\b${name}\\s*=\\s*(?:async\\s*)?(?:function\\s*\\(|\\([^)]*\\)\\s*=>|\\w+\\s*=>))`).exec(src);
248259 if (!m) return undefined;
@@ -413,7 +424,10 @@ describe("every page the router lists", () => {
413424 });
414425 });
415426
416 /** Fewest HTML pages the admin walk reaches; observed when written. A page lost from the walk drops under it. */
427 /**
428 * Fewest HTML pages the admin walk reaches; observed when written. A page lost from the walk drops
429 * under it.
430 */
417431 const WALKED_FLOOR = 130;
418432 /** The same, signed out (observed 44). */
419433 const ANON_FLOOR = 40;
test/spawn-in-process-visible.test.ts +6 −15
@@ -26,7 +26,6 @@ import { clientRows, servedWindow } from "../src/spawn/clients.ts";
2626 import { closeHostedChildren, openChildren, provideCellsForTest } from "../src/spawn/host.ts";
2727 import { hostedPlacement } from "../src/spawn/placement.ts";
2828 import {
29 inProcessNeed,
3029 IN_PROCESS_WORDS,
3130 OWN_SANDBOX_WORDS,
3231 whereOf,
@@ -102,16 +101,6 @@ describe("where a forge runs, in words", () => {
102101 ).says,
103102 ).toBe("own cell, not started: x");
104103 });
105
106 test("the home's line counts them, and says nothing when there are none", () => {
107 expect(inProcessNeed(0)).toBeNull();
108 expect(inProcessNeed(1)).toBe(
109 "1 forge runs inside this forge's own process; move it into a sandbox",
110 );
111 expect(inProcessNeed(5)).toBe(
112 "5 forges run inside this forge's own process; move them into sandboxes",
113 );
114 });
115104 });
116105
117106 describe("what a forge in this process took of the serving thread", () => {
@@ -299,15 +288,17 @@ describe("a parent holding a forge in its own process", () => {
299288 ).toBe("hosted");
300289 });
301290
302 test("the home's needs-you line counts it, and /system lists what it took of the thread", async () => {
291 test("the home does not count it (#13428), /forges badges it, and /system lists what it took of the thread", async () => {
303292 const home = await (
304293 await fetch(`${servers.url}/`, {
305294 headers: { cookie, host: "forge.test" },
306295 })
307296 ).text();
308 expect(home).toContain(
309 "1 forge runs inside this forge&#39;s own process; move it into a sandbox",
310 );
297 expect(home).not.toContain("runs inside this forge&#39;s own process");
298 const forges = await (
299 await fetch(`${servers.url}/forges`, { headers: { cookie, host: "forge.test" } })
300 ).text();
301 expect(forges).toContain("data-in-process");
311302 await (
312303 await fetch(`${servers.url}/healthz`, {
313304 headers: { host: "homie--forge.test" },
test/tui-everyday.test.ts +14 −37
@@ -1,11 +1,13 @@
1 /** The terminal's dashboard asks an admin once to work day to day as an everyday account, as the web home does (#8046). */
1 /**
2 * The terminal home, like the web home, carries no everyday-account ask: it is one line on its own
3 * settings page (#13428).
4 */
25 import { afterAll, beforeAll, expect, test } from "bun:test";
36 import { mkdtemp, rm } from "node:fs/promises";
47 import { tmpdir } from "node:os";
58 import { join } from "node:path";
6 import { createAgent } from "../src/actions/crew.ts";
79 import { createApp, type App as Forge } from "../src/app.ts";
8 import { askForEveryday, keptAdmin, linkEveryday } from "../src/core/everyday.ts";
10 import { keptAdmin, linkEveryday } from "../src/core/everyday.ts";
911 import { createUser, getUserByName, type User } from "../src/core/users.ts";
1012 import { createForgeApp } from "../src/tui/forge.ts";
1113 import { headlessTerminal } from "../src/tui/term/terminal.ts";
@@ -77,50 +79,25 @@ async function firstScreen(user: User): Promise<string> {
7779 return text;
7880 }
7981
80 test("an admin with no choice made sees the line at the head; K keeps admin and the line goes for good", async () => {
81 expect(askForEveryday(forge.db, alice)).toBe(true);
82 test("the terminal home says nothing about the everyday account, as the web home does (#13428)", async () => {
83 const text = await firstScreen(alice);
84 expect(text).not.toContain(WHY_START);
85 expect(text).not.toContain(ASK);
86 expect(text).not.toContain("Day to day you are");
87
88 // The keys are gone too: K moves nothing and makes no choice.
8289 const h = boot(alice);
8390 await h.settle();
84 const head = h.text().split("\n").find((line) => line.includes(WHY_START));
85 expect(head).toBeDefined();
86 expect(head).toContain("E makes it on the web · K keeps using admin");
87
88 // `k` still moves the cursor: it never makes the choice.
89 await h.press("k");
90 expect(keptAdmin(forge.db, alice)).toBe(false);
91 expect(h.text()).toContain(ASK);
92
9391 await h.press("K");
94 expect(keptAdmin(forge.db, alice)).toBe(true);
95 expect(h.text()).not.toContain(WHY_START);
92 expect(keptAdmin(forge.db, alice)).toBe(false);
9693 h.stop();
9794
98 // The choice is the web's too: a fresh session is not asked again.
99 expect(askForEveryday(forge.db, alice)).toBe(false);
100 expect(await firstScreen(alice)).not.toContain(WHY_START);
101 });
102
103 test("an admin with an everyday account linked is told its name instead", async () => {
10495 const carol = await person("carol", true);
10596 const daily = await person("dana");
10697 linkEveryday(forge.db, carol, daily);
107 const text = await firstScreen(carol);
108 expect(text).toContain("Day to day you are dana; this is the admin account.");
109 expect(text).not.toContain(ASK);
110 // The everyday account itself is not an admin, and is asked nothing.
111 expect(await firstScreen(daily)).not.toContain("Day to day");
98 expect(await firstScreen(carol)).not.toContain("Day to day you are");
11299 });
113100
114101 test("a non-admin and an agent never see the line", async () => {
115102 expect(await firstScreen(bob)).not.toContain(WHY_START);
116 const made = await createAgent(forge, alice, { username: "everydaybot" });
117 if (!made.ok) throw new Error(String(made.error));
118 // Even an agent made an admin is not asked: the everyday account is a person's.
119 forge.db.query("UPDATE user SET is_admin = 1 WHERE username = 'everydaybot'").run();
120 const agent = getUserByName(forge.db, "everydaybot")!;
121 expect(agent.isAdmin).toBe(true);
122 expect(agent.kind).toBe("agent");
123 const text = await firstScreen(agent);
124 expect(text).not.toContain(WHY_START);
125 expect(text).not.toContain("Day to day");
126103 });
test/tui-first-tell.test.ts +8 −4
@@ -1,4 +1,7 @@
1 /** The terminal's home of a new forge: before the first tell, "what do you want built" and no everyday offer; after it, the offer. */
1 /**
2 * The terminal's home of a new forge: before the first tell, "what do you want built" and no
3 * everyday offer; after it, the offer.
4 */
25 import { afterAll, beforeAll, expect, test } from "bun:test";
36 import { getUserById } from "../src/core/users.ts";
47 import { createForgeApp } from "../src/tui/forge.ts";
@@ -31,7 +34,7 @@ function boot() {
3134 return { app, key, text: () => app.screen.toText() };
3235 }
3336
34 test("before the first tell the home says what to do and offers no everyday account; after it, the offer", async () => {
37 test("before the first tell the home says what to do and never offers an everyday account (#13428), before or after it", async () => {
3538 const h = boot();
3639 await settleApp(h.app);
3740 expect(h.text()).toContain("What do you want built?");
@@ -51,12 +54,13 @@ test("before the first tell the home says what to do and offers no everyday acco
5154 expect(count("issue")).toBe(issuesBefore + 1);
5255 h.app.stop();
5356
54 // Once the crew has made an issue of it, the home is the everyday one and offers the account.
57 // Once the crew has made an issue of it, the home is the everyday one, and still asks nothing
58 // about the account.
5559 const told = await forge.post(forge.owner, "/marias/bakery/tell", { text: "Add a weekly menu page." });
5660 expect(told.status).toBeLessThan(400);
5761 const after = boot();
5862 await settleApp(after.app);
5963 expect(after.text()).not.toContain("What do you want built?");
60 expect(after.text()).toContain("K keeps using admin");
64 expect(after.text()).not.toContain("K keeps using admin");
6165 after.app.stop();
6266 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs