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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13428-the-home-page-carries-no-warning-banner → main 7 commits fork
24 files
changed +234
−298
src/actions/runs.ts +17 −9
| @@ -1,11 +1,10 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * 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. | |
| 9 | 8 | */ |
| 10 | 9 | |
| 11 | 10 | import { commitVerdicts, isCommitId, releaseCheck, type CommitCheck } from "../checks/commit_check.ts"; |
| @@ -268,12 +267,18 @@ export async function checkOfCommit( | ||
| 268 | 267 | ); |
| 269 | 268 | } |
| 270 | 269 | |
| 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 | */ | |
| 272 | 274 | export interface LookFigures { |
| 273 | 275 | readonly look: string; |
| 274 | 276 | readonly screens: string; |
| 275 | 277 | 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 | */ | |
| 277 | 282 | readonly size?: PageSize; |
| 278 | 283 | } |
| 279 | 284 | |
| @@ -297,7 +302,10 @@ export function looksOfCheck( | ||
| 297 | 302 | })); |
| 298 | 303 | } |
| 299 | 304 | |
| 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 | */ | |
| 301 | 309 | export function verdictsOfCommits( |
| 302 | 310 | app: App, |
| 303 | 311 | 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 | ||
| 68 | 68 | return said; |
| 69 | 69 | } |
| 70 | 70 | |
| 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 | */ | |
| 72 | 75 | export function talkAgain(app: App, user: User | undefined, how: RedoHow, text = "", conversationId?: string): Result<Said, TalkRefusal> { |
| 73 | 76 | if (user === undefined) return err("unauthorized"); |
| 74 | 77 | const options = conversationOptions(app); |
src/core/conversation_markdown.ts +4 −3
| @@ -2,7 +2,8 @@ | ||
| 2 | 2 | * A talk conversation as one Markdown document (#13307): who, when, the text, |
| 3 | 3 | * and each attachment as a link, turns in the order they were written. The |
| 4 | 4 | * 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. | |
| 6 | 7 | */ |
| 7 | 8 | import type { Database } from "bun:sqlite"; |
| 8 | 9 | import { err, ok, type Result } from "../kernel/result.ts"; |
| @@ -18,8 +19,8 @@ const plain = (s: string): string => s.replace(/[\r\n]+/g, " ").replace(/[[\]()< | ||
| 18 | 19 | export const MAX_TEXT = 1_000_000; |
| 19 | 20 | |
| 20 | 21 | /** |
| 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. | |
| 23 | 24 | */ |
| 24 | 25 | function recentTurns(db: Database, userId: string, conversationId: string): { turns: Turn[]; cut: boolean } { |
| 25 | 26 | const out: Turn[] = []; |
src/core/everyday.ts −12
| @@ -74,18 +74,6 @@ export function keepAdmin(db: Database, admin: User): void { | ||
| 74 | 74 | export const keptAdmin = (db: Database, admin: User): boolean => |
| 75 | 75 | getUserSetting(db, admin.id, CHOICE) === "admin"; |
| 76 | 76 | |
| 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 | ||
| 89 | 77 | /** The two sentences of why, said the same way everywhere. */ |
| 90 | 78 | export const EVERYDAY_WHY = |
| 91 | 79 | "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( | ||
| 313 | 313 | app: App, |
| 314 | 314 | fork: Repo, |
| 315 | 315 | 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 | */ | |
| 317 | 319 | by?: User, |
| 318 | 320 | ): Promise<boolean> { |
| 319 | 321 | const issue = convergeIssue(app, fork, parent); |
src/spawn/clients.ts −5
| @@ -521,11 +521,6 @@ export function servedNow(app: App): readonly ClientRow[] { | ||
| 521 | 521 | return served.get(app)?.rows ?? []; |
| 522 | 522 | } |
| 523 | 523 | |
| 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 | ||
| 529 | 524 | /** A forge was changed here (stopped, removed, a link made): the next list is read afresh. */ |
| 530 | 525 | export function dropServed(app: App): void { |
| 531 | 526 | served.delete(app); |
src/spawn/where.ts −11
| @@ -242,17 +242,6 @@ export function whereOf( | ||
| 242 | 242 | }; |
| 243 | 243 | } |
| 244 | 244 | |
| 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 | ||
| 256 | 245 | /** What the forge's owner is told, once, in their own forge: the whole of what changed for them. */ |
| 257 | 246 | export const SANDBOXED_WORDS = |
| 258 | 247 | "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 { | ||
| 51 | 51 | /** |
| 52 | 52 | * The landed pulls told in chapters, as the page tells them (`release/chapter_groups.ts` decides |
| 53 | 53 | * 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. | |
| 55 | 56 | */ |
| 56 | 57 | export function chapterLines(groups: readonly Group[], keep: (l: Landing) => boolean = () => true, filtering = false): Line[] { |
| 57 | 58 | const out: Line[] = []; |
| @@ -79,7 +80,10 @@ export function nearLines(near: readonly Near[]): string[] { | ||
| 79 | 80 | |
| 80 | 81 | type Repo = { owner: string; name: string }; |
| 81 | 82 | |
| 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 | */ | |
| 83 | 87 | export function creditWords(by: string | undefined, withNames: readonly string[] | undefined): string { |
| 84 | 88 | const parts = [by === undefined ? "" : `by ${by}`, withNames === undefined || withNames.length === 0 ? "" : `with ${withNames.join(", ")}`]; |
| 85 | 89 | return parts.filter((p) => p !== "").join(", "); |
| @@ -87,7 +91,10 @@ export function creditWords(by: string | undefined, withNames: readonly string[] | ||
| 87 | 91 | |
| 88 | 92 | type Pull = ReleaseEntry["pulls"][number]; |
| 89 | 93 | |
| 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 | */ | |
| 91 | 98 | export function pullLines(pulls: readonly Pull[], credits: ReadonlyMap<number, string>): { row: ListRow; pulls: readonly Pull[] }[] { |
| 92 | 99 | return gather(pulls).map((g) => |
| 93 | 100 | g.landings.length === 1 |
| @@ -96,7 +103,10 @@ export function pullLines(pulls: readonly Pull[], credits: ReadonlyMap<number, s | ||
| 96 | 103 | ); |
| 97 | 104 | } |
| 98 | 105 | |
| 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 | */ | |
| 100 | 110 | function releasePulls(f: Session, ctx: Ctx, repoRef: Repo, entry: ReleaseEntry, credits: ReadonlyMap<number, string>, title = entry.version): Screen { |
| 101 | 111 | const state = new ListState(); |
| 102 | 112 | const lines = pullLines(entry.pulls, credits); |
src/tui/screens/dashboard.ts +1 −41
| @@ -38,7 +38,6 @@ import { sinceDigest } from "../../web/studio/since.ts"; | ||
| 38 | 38 | import { askForSomething } from "./tell.ts"; |
| 39 | 39 | import { movingLines } from "./moving.ts"; |
| 40 | 40 | import { pipelineNow } from "../../web/studio/living.ts"; |
| 41 | import { askForEveryday, everydayOf, EVERYDAY_WHY, keepAdmin } from "../../core/everyday.ts"; | |
| 42 | 41 | import { mayView } from "../../core/sealed.ts"; |
| 43 | 42 | import { applyFleetIds, previewFleetIds, undoFleetOp } from "../../actions/fleet.ts"; |
| 44 | 43 | import { plain } from "./boards.ts"; |
| @@ -266,14 +265,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 266 | 265 | */ |
| 267 | 266 | let figures: string[] = []; |
| 268 | 267 | /** |
| 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". | |
| 277 | 269 | */ |
| 278 | 270 | let firstTell = false; |
| 279 | 271 | /** |
| @@ -386,7 +378,6 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 386 | 378 | // A client's home never carries the forge-wide figures, on either door. |
| 387 | 379 | figures = []; |
| 388 | 380 | firstTell = steps.some((s) => s.key === "tell" && !s.done); |
| 389 | everyday = everydayHead(); | |
| 390 | 381 | if (firstTell) { |
| 391 | 382 | clientLines = [FIRST_TELL_LINE, crewFirstText(f.app)]; |
| 392 | 383 | ctx.invalidate(); |
| @@ -435,29 +426,11 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 435 | 426 | ctx.invalidate(); |
| 436 | 427 | }; |
| 437 | 428 | |
| 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 | }; | |
| 455 | 429 | |
| 456 | 430 | const reload = (): void => { |
| 457 | 431 | // The server remembers the *choice* and nothing about the laptop, so |
| 458 | 432 | // this is a list of decisions — never a status that would be stale. |
| 459 | 433 | pins = f.user ? listPins(f.db, f.user.id) : []; |
| 460 | everyday = everydayHead(); | |
| 461 | 434 | startedFrom = f.user === undefined ? null : startedFromText(f.app.config.dataDir); |
| 462 | 435 | pinned = f.user ? pinnedRepoIds(f.db, f.user.id) : new Set<string>(); |
| 463 | 436 | all = listReposVisibleTo(f.db, f.user, { limit: 200 }); |
| @@ -1190,9 +1163,6 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1190 | 1163 | ...(focus === "repos" && f.user !== undefined && shown().some(mayArchive) |
| 1191 | 1164 | ? [binding(["space"], "mark"), ...(markedRepos.size > 0 ? [binding(["a"], "archive marked")] : [])] |
| 1192 | 1165 | : []), |
| 1193 | ...(everyday?.asking === true | |
| 1194 | ? [binding(["E"], "everyday account"), binding(["K"], "keep admin")] | |
| 1195 | : []), | |
| 1196 | 1166 | binding(["r"], "refresh"), |
| 1197 | 1167 | ]; |
| 1198 | 1168 | }, |
| @@ -1210,11 +1180,6 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1210 | 1180 | // A site admin's forge strip, as the board's: "All fine" or a line |
| 1211 | 1181 | // per cause. Anyone else gets no rows and no reads. |
| 1212 | 1182 | 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 | } | |
| 1218 | 1183 | if (startedFrom !== null) { |
| 1219 | 1184 | const [strip, rest] = split(body, "v", [len(1), fill(1)]); |
| 1220 | 1185 | 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 { | ||
| 1493 | 1458 | openOnWeb(f, ctx, "/asks", "Asks"); |
| 1494 | 1459 | return true; |
| 1495 | 1460 | } |
| 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; | |
| 1501 | 1461 | if (e.key === "A" && f.user) { |
| 1502 | 1462 | openOnWeb(f, ctx, "/settings", "Account settings"); |
| 1503 | 1463 | 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.`; | ||
| 39 | 39 | |
| 40 | 40 | const WHO: Readonly<Record<string, string>> = { person: "You", agent: "Forge", tool: "Tool", confirm: "Asks" }; |
| 41 | 41 | |
| 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 | */ | |
| 43 | 46 | function downloadScreen(f: Session, ctx: Ctx, chat: Conversation): Screen { |
| 44 | 47 | const scroll = new Scroll(); |
| 45 | 48 | 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"; | ||
| 66 | 66 | import { chart, figuresGrid, figuresSection } from "./home_figures.ts"; |
| 67 | 67 | import { tellBox } from "../studio/living.ts"; |
| 68 | 68 | 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"; | |
| 74 | 69 | import { adminAskNeed } from "../studio/ask_admin.ts"; |
| 75 | 70 | import { asksToAnswer, type AskView } from "../../actions/ask_admin.ts"; |
| 76 | import { inProcessNeed, whereOf } from "../../spawn/where.ts"; | |
| 71 | import { whereOf } from "../../spawn/where.ts"; | |
| 77 | 72 | import { untoldAnswer, markTold } from "../../core/requests.ts"; |
| 78 | 73 | import { YOURE_IN_MESSAGE } from "../../actions/users.ts"; |
| 79 | 74 | import { spawnedForge } from "../../spawn/claim.ts"; |
| 80 | import { forgeHasNoKey, NO_KEY_AT, NO_KEY_LINE } from "../../crew/no_key.ts"; | |
| 81 | 75 | import { startedFromLine } from "../started_from.ts"; |
| 82 | 76 | |
| 83 | 77 | |
| @@ -311,56 +305,25 @@ interface Need { | ||
| 311 | 305 | } |
| 312 | 306 | |
| 313 | 307 | /** |
| 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). | |
| 321 | 312 | */ |
| 322 | 313 | interface StripViewer { |
| 323 | 314 | readonly id: string; |
| 324 | 315 | 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[]; | |
| 331 | 316 | /** |
| 332 | 317 | * What people here asked this viewer, as one who can change it, to change |
| 333 | 318 | * (`actions/ask_admin.ts`). |
| 334 | 319 | */ |
| 335 | 320 | 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; | |
| 342 | 321 | } |
| 343 | 322 | |
| 344 | 323 | /** |
| 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. | |
| 347 | 326 | */ |
| 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 | ||
| 364 | 327 | function needsOf(picture: LanePicture, viewer: StripViewer, dataDir: string, now: number): Need[] { |
| 365 | 328 | const proof = viewer.isAdmin ? proofNotice(dataDir, running().version, now) : undefined; |
| 366 | 329 | const asks = picture.asks[viewer.id]; |
| @@ -370,21 +333,11 @@ function needsOf(picture: LanePicture, viewer: StripViewer, dataDir: string, now | ||
| 370 | 333 | ...(viewer.isAdmin ? (picture.strip?.needs ?? []).map((n) => ({ says: n.says, href: n.href, tone: "alarm" as const })) : []), |
| 371 | 334 | ]; |
| 372 | 335 | 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 }] : []), | |
| 375 | 336 | ...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 })) : []), | |
| 378 | 337 | // A person here is stopped until one who can change it does: theirs to answer, admin or not. |
| 379 | 338 | ...(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 }] : []), | |
| 385 | 339 | ...(proof?.tone === "notice" ? [{ says: proof.sentence, href: "/releases#proof", tone: "notice" as const }] : []), |
| 386 | 340 | ...(waiting === null ? [] : [{ says: waiting, href: "/review", tone: "notice" as const }]), |
| 387 | ...(viewer.everyday === true ? [EVERYDAY_NEED] : []), | |
| 388 | 341 | ]; |
| 389 | 342 | } |
| 390 | 343 | |
| @@ -555,20 +508,6 @@ export async function forgesRegion(app: App, wait: boolean): Promise<Html> { | ||
| 555 | 508 | return forgesHtml(kept); |
| 556 | 509 | } |
| 557 | 510 | |
| 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 | ||
| 572 | 511 | // ---- the page ---- |
| 573 | 512 | |
| 574 | 513 | /** |
| @@ -625,11 +564,11 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited | ||
| 625 | 564 | // or lean. |
| 626 | 565 | const spawned = known !== undefined ? known.spawned : await timePhaseAsync(ctx.request, "spawned", () => spawnedForge(ctx.app)); |
| 627 | 566 | 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); | |
| 629 | 568 | // What the old home also carried and is not a lane: the box that tells the crew (with Notes and |
| 630 | 569 | // 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. | |
| 633 | 572 | const allowed = untoldAnswer(ctx.app.db, user.id) === "allowed"; |
| 634 | 573 | if (allowed) markTold(ctx.app.db, user.id, new Date().toISOString()); |
| 635 | 574 | 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> { | ||
| 759 | 698 | const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx, user), "lane", now)); |
| 760 | 699 | const rendering = performance.now(); |
| 761 | 700 | 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 }); | |
| 763 | 702 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 764 | 703 | return res; |
| 765 | 704 | } |
src/web/pages/hosted-forges.ts +7 −42
| @@ -28,13 +28,11 @@ import { | ||
| 28 | 28 | timePhaseAsync, |
| 29 | 29 | } from "../../core/route_timing.ts"; |
| 30 | 30 | import type { Ctx } from "../../http/context.ts"; |
| 31 | import { askSentence } from "../../spawn/child_reach.ts"; | |
| 32 | 31 | import { notFoundPage, settingsLayout, signInFirst } from "../chrome.ts"; |
| 33 | 32 | import { backTo, field as formField, readForm } from "../form.ts"; |
| 34 | 33 | import { html, type Html } from "../html.ts"; |
| 35 | 34 | import { flashTo, page } from "../layout.ts"; |
| 36 | 35 | import { badge, btn, field, row, time } from "../ui.ts"; |
| 37 | import { agoWords } from "./origin-reach.ts"; | |
| 38 | 36 | import { accountSections } from "./origins.ts"; |
| 39 | 37 | |
| 40 | 38 | /** 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."; | ||
| 46 | 44 | const hidden = (name: string, value: string): Html => |
| 47 | 45 | html`<input type="hidden" name="${name}" value="${value}" />`; |
| 48 | 46 | |
| 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 | */ | |
| 50 | 51 | function askRow(a: ReachAsk, back: string): Html { |
| 51 | 52 | const base = `/forges/${a.child}/reach`; |
| 52 | 53 | return row({ |
| @@ -268,7 +269,9 @@ export async function reachSwitch(ctx: Ctx): Promise<Response> { | ||
| 268 | 269 | }); |
| 269 | 270 | } |
| 270 | 271 | |
| 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 | */ | |
| 272 | 275 | function answer( |
| 273 | 276 | act: ( |
| 274 | 277 | ctx: Ctx, |
| @@ -352,41 +355,3 @@ export const forgeReachRevoke = answer(revoke); | ||
| 352 | 355 | // POST /settings/hosted-forges/reach/remove — take a name back from every hosted forge. |
| 353 | 356 | export const reachRemove = answer(revoke, true); |
| 354 | 357 | |
| 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", () => { | ||
| 80 | 80 | |
| 81 | 81 | // The home asks in one quiet line that leads to the step's own page. |
| 82 | 82 | 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); | |
| 84 | 84 | expect(home).not.toContain('role="alert"'); |
| 85 | 85 | |
| 86 | 86 | // 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", () => { | ||
| 130 | 130 | test("Keep using admin is one post, receipted and recorded, and the home stops asking; its agent token is labelled admin", async () => { |
| 131 | 131 | const f = await freshForge(); |
| 132 | 132 | const admin = await f.firstSignIn("bea"); |
| 133 | expect((await f.page(admin, "/")).text).toContain(HOME_LINE); | |
| 134 | 133 | |
| 135 | 134 | const kept = await f.post(admin, "/settings/everyday/keep", {}); |
| 136 | 135 | expect(kept.status).toBe(303); |
test/ask-to-reach.test.ts +15 −17
| @@ -53,8 +53,6 @@ import { | ||
| 53 | 53 | import { launchSpecFor } from "../src/spawn/cell.ts"; |
| 54 | 54 | import { childGate, reachNeeds } from "../src/spawn/child_reach.ts"; |
| 55 | 55 | 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"; | |
| 58 | 56 | import { newFakeState, serveFakeForge, type FakeForge } from "./fake-origin.ts"; |
| 59 | 57 | import { quietLogs } from "./helpers/globals.ts"; |
| 60 | 58 | import { everyoneIsAMember } from "./helpers/members.ts"; |
| @@ -63,7 +61,9 @@ quietLogs(); | ||
| 63 | 61 | |
| 64 | 62 | const PASSWORD = "alice-login-secret"; |
| 65 | 63 | 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 | */ | |
| 67 | 67 | const HOST = "git.benjiverse.invalid"; |
| 68 | 68 | const OTHER = "code.elsewhere.invalid"; |
| 69 | 69 | const PAT = "pat-for-the-fake-forge"; |
| @@ -191,7 +191,8 @@ beforeAll(async () => { | ||
| 191 | 191 | refused: spec.onRefused, |
| 192 | 192 | }, |
| 193 | 193 | ); |
| 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. | |
| 195 | 196 | for (const name of ["HTTPS_PROXY", "https_proxy", "FORGE_PARENT_LOCAL"]) |
| 196 | 197 | env[name] = process.env[name]; |
| 197 | 198 | 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", () | ||
| 283 | 284 | expect(body["setting"]).toBe("children.originEgress"); |
| 284 | 285 | expect(String(body["says"])).not.toContain("children.originEgress"); |
| 285 | 286 | |
| 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. | |
| 287 | 289 | const lines = warned.mock.calls |
| 288 | 290 | .map((c) => String(c[0])) |
| 289 | 291 | .filter((l) => l.startsWith("[egress]")); |
| @@ -359,7 +361,8 @@ describe("the refusal says what stands in the way and offers the one action", () | ||
| 359 | 361 | expect( |
| 360 | 362 | await askHost(maria.app, person(maria, "bob"), { host: "db.internal" }), |
| 361 | 363 | ).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. | |
| 363 | 366 | addresses.set("wiki.sneaky.invalid", ["10.0.0.8"]); |
| 364 | 367 | const sneaky = await askHost(maria.app, person(maria, "bob"), { |
| 365 | 368 | host: "wiki.sneaky.invalid", |
| @@ -402,14 +405,6 @@ describe("ask, allow for that forge, and the connect runs by itself", () => { | ||
| 402 | 405 | state: "asked", |
| 403 | 406 | }); |
| 404 | 407 | 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"); | |
| 413 | 408 | |
| 414 | 409 | // The child shows where the ask stands, where the error was. |
| 415 | 410 | const page = await ( |
| @@ -530,7 +525,8 @@ describe("ask, allow for that forge, and the connect runs by itself", () => { | ||
| 530 | 525 | expect(mayReach(maria, HOST)).toBe(true); |
| 531 | 526 | expect(mayReach(otto, HOST)).toBe(false); |
| 532 | 527 | |
| 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. | |
| 534 | 530 | const tried = await connectOrigin(maria.app, person(maria, "bob"), { |
| 535 | 531 | host: HOST, |
| 536 | 532 | token: PAT, |
| @@ -621,7 +617,8 @@ describe("ask, allow for that forge, and the connect runs by itself", () => { | ||
| 621 | 617 | |
| 622 | 618 | describe("what a granted name still cannot do", () => { |
| 623 | 619 | 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. | |
| 625 | 622 | addGrant(parent.db, { |
| 626 | 623 | bodyId: maria.bodyId, |
| 627 | 624 | child: "maria", |
| @@ -711,7 +708,8 @@ describe("for every hosted forge, not now, and across restarts", () => { | ||
| 711 | 708 | { host: OTHER, state: "later" }, |
| 712 | 709 | ]); |
| 713 | 710 | |
| 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. | |
| 715 | 713 | const again = createApp({ dataDir: dir, url: PARENT_URL, port: 0 }); |
| 716 | 714 | try { |
| 717 | 715 | 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 | */ | |
| 2 | 4 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 5 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 6 | import { tmpdir } from "node:os"; |
| @@ -33,9 +35,9 @@ const home = async () => main(await (await fetch(`${servers.url}/`, { headers: { | ||
| 33 | 35 | |
| 34 | 36 | const LINE = /<a href="\/settings\/everyday">You are signed in as the admin\. Make an everyday account<\/a>/; |
| 35 | 37 | |
| 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 () => { | |
| 37 | 39 | const m = await home(); |
| 38 | expect(m).toMatch(LINE); | |
| 40 | expect(m).not.toMatch(LINE); | |
| 39 | 41 | expect(m).not.toContain('id="everyday"'); |
| 40 | 42 | expect(m).not.toContain('action="/settings/everyday"'); |
| 41 | 43 | 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 | ||
| 53 | 55 | expect(block).not.toContain('type="password"'); |
| 54 | 56 | }); |
| 55 | 57 | |
| 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 () => { | |
| 57 | 59 | const cross = await fetch(`${servers.url}/settings/everyday/keep`, { |
| 58 | 60 | method: "POST", |
| 59 | 61 | headers: { cookie: admin, origin: "https://evil.example", "content-type": "application/x-www-form-urlencoded" }, |
| 60 | 62 | redirect: "manual", |
| 61 | 63 | }); |
| 62 | 64 | expect(cross.status).toBe(403); |
| 63 | expect(await home()).toMatch(LINE); | |
| 65 | expect(await home()).not.toMatch(LINE); | |
| 64 | 66 | const ok = await fetch(`${servers.url}/settings/everyday/keep`, { |
| 65 | 67 | method: "POST", |
| 66 | 68 | 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", () => { | ||
| 106 | 106 | await rm(dataDir, { recursive: true, force: true }); |
| 107 | 107 | }); |
| 108 | 108 | |
| 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 () => { | |
| 110 | 110 | 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"); | |
| 112 | 112 | expect(home).not.toContain('action="/settings/everyday"'); |
| 113 | 113 | const admin = await page(await signIn("ada"), "/settings/everyday"); |
| 114 | 114 | 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 | ||
| 271 | 271 | expect((await listChildren(parent)).some((c) => c.name === "claimed-idle")).toBe(true); |
| 272 | 272 | }); |
| 273 | 273 | |
| 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 () => { | |
| 275 | 275 | const { child } = await makeForge("long-quiet", false); |
| 276 | 276 | child.close(); |
| 277 | 277 | 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 | ||
| 281 | 281 | useChildFetch(parent, async () => Response.json({ claimed: false })); |
| 282 | 282 | const rows = await servedRows(parent); |
| 283 | 283 | 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(); | |
| 286 | 287 | expect(text).toContain("long-quiet"); |
| 287 | expect(text).toContain("proposed for archive"); | |
| 288 | expect(text).toContain("Proposed for archive"); | |
| 288 | 289 | expect(text).toContain("/forges/archive?name=long-quiet"); |
| 289 | 290 | // Proposed only: it is still here. |
| 290 | 291 | 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 | ||
| 93 | 93 | expect(issue!.body).toContain(`Upstream commit: ${parentTip}`); |
| 94 | 94 | expect(issue!.body).toContain("bob: README.md"); |
| 95 | 95 | 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. | |
| 97 | 98 | const dir = repoDir(app.reposRoot, fork.ownerName, fork.name); |
| 98 | 99 | expect(await tipOf(fresh(fork))).toBe(before); |
| 99 | 100 | expect(await resolveOid(dir, "refs/following/main")).toBe(parentTip); |
| 100 | 101 | // Autonomy is off: the issue is for people, and no agent work is queued for it. |
| 101 | 102 | expect(listRuns(app.db, fork.id, { kind: "agent", limit: 50 }).length).toBe(0); |
| 102 | 103 | |
| 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. | |
| 104 | 106 | setIssueState(app.db, issue!.id, "closed", "dropped"); |
| 105 | 107 | const again = await convergeFork(app, fresh(fork), fresh(parent), undefined); |
| 106 | 108 | 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", () => { | ||
| 86 | 86 | expect(needsStack({ app }, bob).some((n) => n.sentence === NO_KEY_LINE)).toBe(false); |
| 87 | 87 | }); |
| 88 | 88 | |
| 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 () => { | |
| 90 | 90 | 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); | |
| 93 | 92 | const crew = await page("/settings/crew"); |
| 94 | 93 | expect(crew).toContain('id="crew-key"'); |
| 95 | 94 | expect(crew).not.toContain("autofocus"); |
test/no-polling.test.ts +19 −5
| @@ -36,10 +36,15 @@ const NO_TIMER_PAGES = ["/system", "/flow"]; | ||
| 36 | 36 | * that only the owner's own submit changes; a pushed patch would move a handle under a drag. */ |
| 37 | 37 | const STREAM_PAGES = ["/system"]; |
| 38 | 38 | |
| 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 | */ | |
| 40 | 43 | export interface RenderedPage { html: string; scripts: string[] } |
| 41 | 44 | |
| 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 | */ | |
| 43 | 48 | const STREAM = /EventSource\s*\(|data-live(?![-\w])/; |
| 44 | 49 | |
| 45 | 50 | /** Script types that hold data, not code. */ |
| @@ -230,7 +235,10 @@ describe("no rendered page polls", () => { | ||
| 230 | 235 | * reads each page's markup and the scripts it loads. |
| 231 | 236 | */ |
| 232 | 237 | |
| 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 | */ | |
| 234 | 242 | function balanced(src: string, open: number): string { |
| 235 | 243 | const pairs: Record<string, string> = { "(": ")", "{": "}" }; |
| 236 | 244 | const o = src[open]!, c = pairs[o]!; |
| @@ -242,7 +250,10 @@ function balanced(src: string, open: number): string { | ||
| 242 | 250 | return src.slice(open + 1); |
| 243 | 251 | } |
| 244 | 252 | |
| 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 | */ | |
| 246 | 257 | function bodyOf(src: string, name: string): string | undefined { |
| 247 | 258 | const m = new RegExp(`(?:function\\s+${name}\\s*\\(|\\b${name}\\s*=\\s*(?:async\\s*)?(?:function\\s*\\(|\\([^)]*\\)\\s*=>|\\w+\\s*=>))`).exec(src); |
| 248 | 259 | if (!m) return undefined; |
| @@ -413,7 +424,10 @@ describe("every page the router lists", () => { | ||
| 413 | 424 | }); |
| 414 | 425 | }); |
| 415 | 426 | |
| 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 | */ | |
| 417 | 431 | const WALKED_FLOOR = 130; |
| 418 | 432 | /** The same, signed out (observed 44). */ |
| 419 | 433 | 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"; | ||
| 26 | 26 | import { closeHostedChildren, openChildren, provideCellsForTest } from "../src/spawn/host.ts"; |
| 27 | 27 | import { hostedPlacement } from "../src/spawn/placement.ts"; |
| 28 | 28 | import { |
| 29 | inProcessNeed, | |
| 30 | 29 | IN_PROCESS_WORDS, |
| 31 | 30 | OWN_SANDBOX_WORDS, |
| 32 | 31 | whereOf, |
| @@ -102,16 +101,6 @@ describe("where a forge runs, in words", () => { | ||
| 102 | 101 | ).says, |
| 103 | 102 | ).toBe("own cell, not started: x"); |
| 104 | 103 | }); |
| 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 | }); | |
| 115 | 104 | }); |
| 116 | 105 | |
| 117 | 106 | 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", () => { | ||
| 299 | 288 | ).toBe("hosted"); |
| 300 | 289 | }); |
| 301 | 290 | |
| 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 () => { | |
| 303 | 292 | const home = await ( |
| 304 | 293 | await fetch(`${servers.url}/`, { |
| 305 | 294 | headers: { cookie, host: "forge.test" }, |
| 306 | 295 | }) |
| 307 | 296 | ).text(); |
| 308 | expect(home).toContain( | |
| 309 | "1 forge runs inside this forge's own process; move it into a sandbox", | |
| 310 | ); | |
| 297 | expect(home).not.toContain("runs inside this forge'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"); | |
| 311 | 302 | await ( |
| 312 | 303 | await fetch(`${servers.url}/healthz`, { |
| 313 | 304 | 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 | */ | |
| 2 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| 5 | 8 | import { join } from "node:path"; |
| 6 | import { createAgent } from "../src/actions/crew.ts"; | |
| 7 | 9 | 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"; | |
| 9 | 11 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| 10 | 12 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 11 | 13 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| @@ -77,50 +79,25 @@ async function firstScreen(user: User): Promise<string> { | ||
| 77 | 79 | return text; |
| 78 | 80 | } |
| 79 | 81 | |
| 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. | |
| 82 | 89 | const h = boot(alice); |
| 83 | 90 | 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 | ||
| 93 | 91 | 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); | |
| 96 | 93 | h.stop(); |
| 97 | 94 | |
| 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 () => { | |
| 104 | 95 | const carol = await person("carol", true); |
| 105 | 96 | const daily = await person("dana"); |
| 106 | 97 | 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"); | |
| 112 | 99 | }); |
| 113 | 100 | |
| 114 | 101 | test("a non-admin and an agent never see the line", async () => { |
| 115 | 102 | 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"); | |
| 126 | 103 | }); |
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 | */ | |
| 2 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 6 | import { getUserById } from "../src/core/users.ts"; |
| 4 | 7 | import { createForgeApp } from "../src/tui/forge.ts"; |
| @@ -31,7 +34,7 @@ function boot() { | ||
| 31 | 34 | return { app, key, text: () => app.screen.toText() }; |
| 32 | 35 | } |
| 33 | 36 | |
| 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 () => { | |
| 35 | 38 | const h = boot(); |
| 36 | 39 | await settleApp(h.app); |
| 37 | 40 | 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 | ||
| 51 | 54 | expect(count("issue")).toBe(issuesBefore + 1); |
| 52 | 55 | h.app.stop(); |
| 53 | 56 | |
| 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. | |
| 55 | 59 | const told = await forge.post(forge.owner, "/marias/bakery/tell", { text: "Add a weekly menu page." }); |
| 56 | 60 | expect(told.status).toBeLessThan(400); |
| 57 | 61 | const after = boot(); |
| 58 | 62 | await settleApp(after.app); |
| 59 | 63 | 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"); | |
| 61 | 65 | after.app.stop(); |
| 62 | 66 | }); |
new above
offline