Public: anyone can read this; the crew can change it.
A forge link's page shows its crew working right now: the last three runs of the new forge, with no sign-in #13694
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13666-a-forge-link-s-page-shows-its-crew-worki → main 9 commits fork 8 threads · 8 unresolved
docs/features/README.md +1
| @@ -18,6 +18,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 18 | 18 | |
| 19 | 19 | - [](started-from.md) |
| 20 | 20 | - [](first-week.md) |
| 21 | - [](crew-now.md) | |
| 21 | 22 | - [](propose-to-parent.md) |
| 22 | 23 | - [](template-timing.md) |
| 23 | 24 | - [](feed-look.md) |
docs/features/crew-now.md added +9
| @@ -0,0 +1,9 @@ | ||
| 1 | # The crew on a forge link's page | |
| 2 | ||
| 3 | The page a forge link opens (`/claim`, and `/welcome` on a forge's first account) ends with the crew at work: up to three agent runs, the ones waiting or working first, then the latest finished. Each row says what the run is for (its issue's title, else its summary), who ran it and on which repository, and its state in plain words: waiting to start, working now, finished, stopped with a problem, or cancelled. Before any run exists it says the crew is starting. No sign-in is needed. | |
| 4 | ||
| 5 | Only public repositories are read: the page is open to anyone holding the link, so a private repository's name and work never reach it. The read is one statement of five bounded, indexed lookups, so it costs the same however many runs are stored. Nothing is stored. | |
| 6 | ||
| 7 | In the terminal, the palette's **Your crew's latest work** shows the same three runs in the same words. | |
| 8 | ||
| 9 | Code: `src/core/crew_now.ts` (the read and the words), `src/web/crew_now.ts` (the section), `src/tui/screens/crew_now.ts` (the screen). Test: `test/link-crew-now.test.ts`. |
src/actions/proposals.ts +3 −1
| @@ -40,7 +40,9 @@ function errorWords(e: unknown): string { | ||
| 40 | 40 | return typeof m === "string" ? m : "it was refused"; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | /** The proposal and its repository, when this person is who it asks and it is in one of `states`. */ | |
| 43 | /** | |
| 44 | * The proposal and its repository, when this person is who it asks and it is in one of `states`. | |
| 45 | */ | |
| 44 | 46 | function mine( |
| 45 | 47 | app: App, |
| 46 | 48 | actor: User | undefined, |
src/core/crew_now.ts added +79
| @@ -0,0 +1,79 @@ | ||
| 1 | /** | |
| 2 | * What the crew of this forge is doing right now, for the page a forge link opens: up to three | |
| 3 | * agent runs, live ones first, then the latest finished, each with who ran it and what it was | |
| 4 | * for. Read from the forge's own stored runs; nothing is stored and nothing of any other forge | |
| 5 | * is read. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { Database } from "bun:sqlite"; | |
| 9 | ||
| 10 | export const CREW_NOW_MAX = 3; | |
| 11 | ||
| 12 | export interface CrewRun { | |
| 13 | readonly who: string; | |
| 14 | readonly what: string; | |
| 15 | readonly repo: string; | |
| 16 | readonly state: "queued" | "running" | "ok" | "failed" | "cancelled"; | |
| 17 | } | |
| 18 | ||
| 19 | /** The state in plain words, the same on the page and in the terminal. */ | |
| 20 | export const STATE_WORDS: Record<CrewRun["state"], string> = { | |
| 21 | queued: "waiting to start", | |
| 22 | running: "working now", | |
| 23 | ok: "finished", | |
| 24 | failed: "stopped with a problem", | |
| 25 | cancelled: "cancelled", | |
| 26 | }; | |
| 27 | ||
| 28 | /** What shows when no public run exists yet. */ | |
| 29 | export const CREW_STARTING = "Your crew is starting, and its first public work shows here."; | |
| 30 | ||
| 31 | interface Row { | |
| 32 | id: string; | |
| 33 | username: string | null; | |
| 34 | title: string | null; | |
| 35 | summary: string; | |
| 36 | reason: string; | |
| 37 | repo: string; | |
| 38 | state: CrewRun["state"]; | |
| 39 | } | |
| 40 | ||
| 41 | const clip = (s: string, n: number): string => { | |
| 42 | const one = s.replace(/\s+/g, " ").trim(); | |
| 43 | return one.length > n ? `${one.slice(0, n - 1)}…` : one; | |
| 44 | }; | |
| 45 | ||
outdated
HIGH (private data leaks across users): no filter on repo visibility. This runs for anonymous visitors and returns private repo names, issue titles and summaries. Join on repo visibility and show only public ones. |
||
| 46 | const STATES = ["running", "queued", "ok", "failed", "cancelled"] as const; | |
outdated
MEDIUM (DoS): ORDER BY on a computed expression scans and sorts every agent run on each unauthenticated request. Use two indexed, LIMITed queries (live, then latest finished) and merge them. |
||
| 47 | ||
| 48 | const BY_STATE = (n: number): string => `SELECT r.id AS id, u.username AS username, i.title AS title, r.summary AS summary, | |
| 49 | r.reason AS reason, p.name AS repo, r.state AS state | |
| 50 | FROM run r | |
| 51 | JOIN repo p ON p.id = r.repo_id AND p.visibility = 'public' | |
| 52 | LEFT JOIN user u ON u.id = r.actor_id | |
| 53 | LEFT JOIN issue i ON i.id = r.issue_id | |
| 54 | WHERE r.kind = 'agent' AND r.state = ?${n} | |
| 55 | ORDER BY r.id DESC | |
| 56 | LIMIT ?6`; | |
| 57 | ||
| 58 | /** | |
| 59 | * Only public repositories are shown: this runs for anyone who holds the link, so a private | |
outdated
|
||
| 60 | * repository's name, issue title and summary never reach it. Each state is read through the | |
| 61 | * (kind, state) index, newest first, three rows at most, so the cost does not grow with the | |
| 62 | * number of runs: one statement, five LIMITed reads, merged here. | |
| 63 | */ | |
| 64 | const ALL = STATES.map((_, i) => `SELECT * FROM (${BY_STATE(i + 1)})`).join(" UNION ALL "); | |
| 65 | ||
| 66 | const live = (r: Row): boolean => r.state === "running" || r.state === "queued"; | |
| 67 | ||
| 68 | export function crewNow(db: Database): readonly CrewRun[] { | |
| 69 | const found = db.query<Row, (string | number)[]>(ALL).all(...STATES, CREW_NOW_MAX); | |
| 70 | const rows = found | |
| 71 | .sort((a, b) => Number(live(b)) - Number(live(a)) || (a.id < b.id ? 1 : a.id > b.id ? -1 : 0)) | |
| 72 | .slice(0, CREW_NOW_MAX); | |
| 73 | return rows.map((r) => ({ | |
| 74 | who: r.username ?? "the crew", | |
| 75 | what: clip(r.title || r.summary || r.reason || "working", 100), | |
| 76 | repo: r.repo, | |
| 77 | state: r.state, | |
| 78 | })); | |
| 79 | } |
src/core/dep_standing.ts +4 −1
| @@ -286,7 +286,10 @@ export function blockerByTitle( | ||
| 286 | 286 | return { says: `${found.length > 5 ? "More than five" : found.length} issues match "${wanted}": ${found.slice(0, 5).map((i) => `#${i.number}`).join(", ")}. Type the number.` }; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | /** The chain as plain lines for the terminal: what it waits for (furthest back first), then what waits for it. */ | |
| 289 | /** | |
| 290 | * The chain as plain lines for the terminal: what it waits for (furthest back first), then what | |
| 291 | * waits for it. | |
| 292 | */ | |
| 290 | 293 | export function chainLines(s: Standing): string[] { |
| 291 | 294 | const row = (lead: string, n: StandingNode): string => |
| 292 | 295 | `${lead} #${n.number} ${n.title} - ${n.word}${n.holding ? " · holding this" : ""}${n.next === "" ? "" : ` · next: ${n.next}`}`; |
src/crew/autonomy.ts +21 −12
| @@ -394,7 +394,9 @@ function meanRunUsd(db: App["db"], repoId: string): number { | ||
| 394 | 394 | ); |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | /** The issues each repository picked in this tick, by repository id: their runs may not show yet. */ | |
| 397 | /** | |
| 398 | * The issues each repository picked in this tick, by repository id: their runs may not show yet. | |
| 399 | */ | |
| 398 | 400 | export type TickPicks = ReadonlyMap<string, ReadonlySet<string>>; |
| 399 | 401 | |
| 400 | 402 | /** |
| @@ -649,10 +651,10 @@ export function startable( | ||
| 649 | 651 | |
| 650 | 652 | /** |
| 651 | 653 | * Give the planner the direction when the reserve is due a pass — down to |
| 652 | * half of two startable issues per builder slot (`reserve.ts`) — or when the crew has handed it an issue it parked twice, | |
| 653 | * and no planning run is in flight, and the last one is old enough. | |
| 654 | * Returns whether a planning run was set up. Planning runs alongside | |
| 655 | * building: the builders are never waited for. | |
| 654 | * half of two startable issues per builder slot (`reserve.ts`) — or when the crew has handed it an | |
| 655 | * issue it parked twice, and no planning run is in flight, and the last one is old enough. Returns | |
| 656 | * whether a planning run was set up. Planning runs alongside building: the builders are never | |
| 657 | * waited for. | |
| 656 | 658 | * |
| 657 | 659 | * A hand-over is owed one pass, not one a minute: it asks only while it is |
| 658 | 660 | * newer than the last planning run. That one pass is owed even by a planner |
| @@ -1008,7 +1010,10 @@ export function parkForBreaker( | ||
| 1008 | 1010 | return true; |
| 1009 | 1011 | } |
| 1010 | 1012 | |
| 1011 | /** How many times the crew has parked this issue since a person who directs it last spoke (`parks.ts`). */ | |
| 1013 | /** | |
| 1014 | * How many times the crew has parked this issue since a person who directs it last spoke | |
| 1015 | * (`parks.ts`). | |
| 1016 | */ | |
| 1012 | 1017 | export function parkedCount(app: App, repo: Repo, issueId: string): number { |
| 1013 | 1018 | return countParks(app.db, repo, issueId); |
| 1014 | 1019 | } |
| @@ -1305,7 +1310,8 @@ export async function autonomyTick( | ||
| 1305 | 1310 | sweep: (app: App, repo: Repo) => Promise<number> = sweepGreen, |
| 1306 | 1311 | ): Promise<void> { |
| 1307 | 1312 | if (crewOffInPreview()) return; |
| 1308 | // A pull a person holds with changes requested goes back to its builder after a day of silence, in any repository. | |
| 1313 | // A pull a person holds with changes requested goes back to its builder after a day of silence, | |
| 1314 | // in any repository. | |
| 1309 | 1315 | try { |
| 1310 | 1316 | sweepStranded(app, now); |
| 1311 | 1317 | } catch (error) { |
| @@ -1336,7 +1342,8 @@ export async function autonomyTick( | ||
| 1336 | 1342 | // the next batch is formed, not at its gate (#6611). |
| 1337 | 1343 | pruneLine(app, repo); |
| 1338 | 1344 | void startSweep(app, repo, sweep); |
| 1339 | // Each pass below is one slice of the thread: a request waiting is served between them (#8848). | |
| 1345 | // Each pass below is one slice of the thread: a request waiting is served between them | |
| 1346 | // (#8848). | |
| 1340 | 1347 | await breathe(); |
| 1341 | 1348 | // First of all: a slot freed goes to an approved pull that no longer |
| 1342 | 1349 | // merges, before a changes-requested one or a new issue (#3682). |
| @@ -1432,7 +1439,8 @@ export async function autonomyTick( | ||
| 1432 | 1439 | // The standing reserve the planner keeps: startable/target (#3237). |
| 1433 | 1440 | reserve: reserveWords(reserveOf(held.startable.length, status.slots)), |
| 1434 | 1441 | held: heldWords(held), |
| 1435 | // What the picker passes over among the startable, so no ready issue goes unexplained (#8924). | |
| 1442 | // What the picker passes over among the startable, so no ready issue goes unexplained | |
| 1443 | // (#8924). | |
| 1436 | 1444 | passed: passedWords(pickFilter(app, current, held.startable, now).passed), |
| 1437 | 1445 | // The files 5 or more open pulls touch, which no new build starts on (#5934). |
| 1438 | 1446 | ...(held.by.hot_file.length === 0 ? {} : { hot: hotWords(hotFiles(current.id)) }), |
| @@ -1448,8 +1456,8 @@ export async function autonomyTick( | ||
| 1448 | 1456 | idle: idleBuilders(activeNow, crewNow), |
| 1449 | 1457 | ...(governor === undefined ? {} : { governor }), |
| 1450 | 1458 | // Approved conflicted pulls: queued, in flight, and why each other is |
| 1451 | // skipped (#3682, #6237), or "0 candidates of N open" (#6263); and the lane for rebases: conflicted N, | |
| 1452 | // rebasing M, room R (#6140). | |
| 1459 | // skipped (#3682, #6237), or "0 candidates of N open" (#6263); and the lane for rebases: | |
| 1460 | // conflicted N, rebasing M, room R (#6140). | |
| 1453 | 1461 | ...finishFields(finishing.moves, readConflictLane(app.db), finishing.open), |
| 1454 | 1462 | ...(requested.length === 0 |
| 1455 | 1463 | ? {} |
| @@ -2256,7 +2264,8 @@ async function admit( | ||
| 2256 | 2264 | if (!again) addComment(app, by, repo, getIssueById(app.db, pull.id) ?? pull, clashSaid(red.comment, together)); |
| 2257 | 2265 | // A red that reproduces on the re-gate is the code's: only then is it the doctor's to hold. |
| 2258 | 2266 | if (again) treatRed(app, repo, by, pull, red, baseOid); |
| 2259 | // Red only on top of pulls that landed first: no single culprit yet, so the class is recorded and the re-gate alone decides. | |
| 2267 | // Red only on top of pulls that landed first: no single culprit yet, so the class is recorded | |
| 2268 | // and the re-gate alone decides. | |
| 2260 | 2269 | else noteRed(app, repo, pull, red, baseOid, together); |
| 2261 | 2270 | }, |
| 2262 | 2271 | }); |
src/crew/held.ts +16 −4
| @@ -98,7 +98,10 @@ export interface Held { | ||
| 98 | 98 | readonly by: Readonly<Record<HoldName, readonly Issue[]>>; |
| 99 | 99 | /** Of the `hot_file` ones, those an admin's hold keeps: issue number to the hold that does. */ |
| 100 | 100 | readonly pinned: ReadonlyMap<number, FileHold>; |
| 101 | /** Of the `hot_file` ones, those that wait because another issue already relieves the same path: issue number to that path and issue. */ | |
| 101 | /** | |
| 102 | * Of the `hot_file` ones, those that wait because another issue already relieves the same path: | |
| 103 | * issue number to that path and issue. | |
| 104 | */ | |
| 102 | 105 | readonly relieving: ReadonlyMap<number, { path: string; by: number }>; |
| 103 | 106 | /** Of the `twin` ones: issue number to the twin that holds the same work. */ |
| 104 | 107 | readonly twins: ReadonlyMap<number, Twin>; |
| @@ -110,7 +113,10 @@ export interface LastRun { | ||
| 110 | 113 | readonly created_at: string; |
| 111 | 114 | } |
| 112 | 115 | |
| 113 | /** The newest agent run of each of `ids` in a few reads, not one per issue; an issue never run is absent. */ | |
| 116 | /** | |
| 117 | * The newest agent run of each of `ids` in a few reads, not one per issue; an issue never run is | |
| 118 | * absent. | |
| 119 | */ | |
| 114 | 120 | export function lastAgentRuns(app: App, ids: readonly string[]): Map<string, LastRun> { |
| 115 | 121 | const out = new Map<string, LastRun>(); |
| 116 | 122 | const CHUNK = 400; |
| @@ -415,7 +421,10 @@ export function mapHolds( | ||
| 415 | 421 | return { holds, startable: held.startable.map((r) => r.issue.number) }; |
| 416 | 422 | } |
| 417 | 423 | |
| 418 | /** The pulls a viewer of `scope` may see: all with the sealed scope, else the unsealed and their own. */ | |
| 424 | /** | |
| 425 | * The pulls a viewer of `scope` may see: all with the sealed scope, else the unsealed and their | |
| 426 | * own. | |
| 427 | */ | |
| 419 | 428 | export function admits(app: App, repo: Repo, scope: { sealed?: true; sealedBy?: string }) { |
| 420 | 429 | if (scope.sealed === true) return () => true; |
| 421 | 430 | return (n: number): boolean => { |
| @@ -424,7 +433,10 @@ export function admits(app: App, repo: Repo, scope: { sealed?: true; sealedBy?: | ||
| 424 | 433 | }; |
| 425 | 434 | } |
| 426 | 435 | |
| 427 | /** How long a viewer's map holds are reused by the next reader of the same repository. Off under `bun test`. */ | |
| 436 | /** | |
| 437 | * How long a viewer's map holds are reused by the next reader of the same repository. Off under | |
| 438 | * `bun test`. | |
| 439 | */ | |
| 428 | 440 | export const mapHeldReuse = { ms: process.env["NODE_ENV"] === "test" ? 0 : 5_000 }; |
| 429 | 441 | const mapHeldKept = new WeakMap<App, Map<string, { at: number; holds: ReturnType<typeof mapHolds> }>>(); |
| 430 | 442 |
src/flow/alarms.ts +4 −1
| @@ -51,7 +51,10 @@ export const FORGE_BROKEN: ReadonlySet<FiredAlarm["key"]> = new Set(["red_main", | ||
| 51 | 51 | export function firedAlarms( |
| 52 | 52 | db: Database, |
| 53 | 53 | now: Date, |
| 54 | /** `dataDir` is required so a caller cannot forget it and lose the backup alarm; `null` says there is none to read (a unit over a bare db). */ | |
| 54 | /** | |
| 55 | * `dataDir` is required so a caller cannot forget it and lose the backup alarm; `null` says there | |
| 56 | * is none to read (a unit over a bare db). | |
| 57 | */ | |
| 55 | 58 | opts: { readonly dataDir: string | null; readonly publicOnly?: boolean; readonly ceilingUsd?: number | null }, |
| 56 | 59 | ): FiredAlarm[] { |
| 57 | 60 | const out: FiredAlarm[] = []; |
src/flow/lanes_read.ts +51 −16
| @@ -52,14 +52,19 @@ export const MOVED_MS = 30 * 60_000; | ||
| 52 | 52 | export const SLOW_MS = 30_000; |
| 53 | 53 | |
| 54 | 54 | export interface LaneItem { |
| 55 | /** Stable across lanes: the same change keeps its key as it moves, so the page can move its tile. */ | |
| 55 | /** | |
| 56 | * Stable across lanes: the same change keeps its key as it moves, so the page can move its tile. | |
| 57 | */ | |
| 56 | 58 | readonly key: string; |
| 57 | 59 | readonly repoId: string; |
| 58 | 60 | readonly kind: "issue" | "pull" | "main" | "deploy"; |
| 59 | 61 | readonly number: number | null; |
| 60 | 62 | readonly title: string; |
| 61 | 63 | readonly sealed: boolean; |
| 62 | /** Who has it: the crew member, the reviewer, the person who asked or merged. Empty when no one does. */ | |
| 64 | /** | |
| 65 | * Who has it: the crew member, the reviewer, the person who asked or merged. Empty when no one | |
| 66 | * does. | |
| 67 | */ | |
| 63 | 68 | readonly who: string; |
| 64 | 69 | /** When it entered this lane. */ |
| 65 | 70 | readonly since: string; |
| @@ -71,7 +76,10 @@ export interface LaneItem { | ||
| 71 | 76 | readonly position: number | null; |
| 72 | 77 | /** When its worker last said it was alive; null when it does not say. */ |
| 73 | 78 | readonly beat: string | null; |
| 74 | /** The issue or pull this is, for an action over it (`fleet/verbs.ts`); null for a check of main and a deploy. */ | |
| 79 | /** | |
| 80 | * The issue or pull this is, for an action over it (`fleet/verbs.ts`); null for a check of main | |
| 81 | * and a deploy. | |
| 82 | */ | |
| 75 | 83 | readonly issueId: string | null; |
| 76 | 84 | /** When the issue or pull was opened; null where there is none. */ |
| 77 | 85 | readonly born: string | null; |
| @@ -95,7 +103,10 @@ export interface StripPart { | ||
| 95 | 103 | readonly usedPct: number; |
| 96 | 104 | readonly mayUsePct: number; |
| 97 | 105 | } | null; |
| 98 | /** The crew's spend over seven days at list price, for the forge's own estimate when the provider has not reported. */ | |
| 106 | /** | |
| 107 | * The crew's spend over seven days at list price, for the forge's own estimate when the provider | |
| 108 | * has not reported. | |
| 109 | */ | |
| 99 | 110 | readonly weekSpendUsd: number; |
| 100 | 111 | readonly ceilingUsd: number | null; |
| 101 | 112 | readonly needs: readonly { readonly says: string; readonly href: string }[]; |
| @@ -117,7 +128,10 @@ export interface LanePicture { | ||
| 117 | 128 | readonly asks: Readonly<Record<string, AsksWaiting>>; |
| 118 | 129 | /** The home's figures; null until the slow part has been read. */ |
| 119 | 130 | readonly figures: Figures | null; |
| 120 | /** Why no builder is starting anything, when something names it (the day's ceiling, no subscription with room, nothing ready); null otherwise. */ | |
| 131 | /** | |
| 132 | * Why no builder is starting anything, when something names it (the day's ceiling, no | |
| 133 | * subscription with room, nothing ready); null otherwise. | |
| 134 | */ | |
| 121 | 135 | readonly idle: IdleReason | null; |
| 122 | 136 | } |
| 123 | 137 | |
| @@ -223,7 +237,10 @@ function item( | ||
| 223 | 237 | }; |
| 224 | 238 | } |
| 225 | 239 | |
| 226 | /** Runs of one kind in flight, running first and then by age; a queued run paused on a limit is not waiting for a worker. */ | |
| 240 | /** | |
| 241 | * Runs of one kind in flight, running first and then by age; a queued run paused on a limit is not | |
| 242 | * waiting for a worker. | |
| 243 | */ | |
| 227 | 244 | function runRows( |
| 228 | 245 | db: Database, |
| 229 | 246 | kind: "agent" | "check", |
| @@ -342,9 +359,10 @@ interface Deploy { | ||
| 342 | 359 | /** |
| 343 | 360 | * Production deploys going live now and those that went live in the last 24 |
| 344 | 361 | * hours, newest first. Only the ids and times come from the run table, and |
| 345 | * only through its own two small indexes (`run_live`, `run_queue`), named (`INDEXED BY`) because the planner picks `run_kind_state` and walks every deploy: the | |
| 346 | * deploy ledger (`deploy_pull`) is never counted or sorted, because a deploy | |
| 347 | * lists every change it carries and production's holds ten million rows. | |
| 362 | * only through its own two small indexes (`run_live`, `run_queue`), named (`INDEXED BY`) because | |
| 363 | * the planner picks `run_kind_state` and walks every deploy: the deploy ledger (`deploy_pull`) is | |
| 364 | * never counted or sorted, because a deploy lists every change it carries and production's holds | |
| 365 | * ten million rows. | |
| 348 | 366 | */ |
| 349 | 367 | function deploys( |
| 350 | 368 | db: Database, |
| @@ -473,12 +491,14 @@ function live(db: Database, dayAgo: string): LaneRead { | ||
| 473 | 491 | const { rows, total } = deploys(db, dayAgo); |
| 474 | 492 | const seen = new Set<string>(); |
| 475 | 493 | const items: LaneItem[] = []; |
| 476 | // Enough to list; the carried-change lookup is a few rows each, so it is bounded to what a lane draws. | |
| 494 | // Enough to list; the carried-change lookup is a few rows each, so it is bounded to what a lane | |
| 495 | // draws. | |
| 477 | 496 | for (const d of rows) { |
| 478 | 497 | if (items.length >= LANE_ITEMS + 3) break; |
| 479 | 498 | const going = d.state === "queued" || d.state === "running"; |
| 480 | 499 | const change = carried(db, d.repo_id, d.at); |
| 481 | // A tile is the change it put live, keyed as the change (so Landing's tile arrives here); a deploy that names none is keyed by itself. | |
| 500 | // A tile is the change it put live, keyed as the change (so Landing's tile arrives here); a | |
| 501 | // deploy that names none is keyed by itself. | |
| 482 | 502 | const key = `i-${change?.id ?? d.id}`; |
| 483 | 503 | if (seen.has(key)) continue; |
| 484 | 504 | seen.add(key); |
| @@ -515,7 +535,10 @@ export interface Fast { | ||
| 515 | 535 | readonly working: ReadonlySet<string>; |
| 516 | 536 | } |
| 517 | 537 | |
| 518 | /** The fast part: running and queued work, approved and merged pulls, deploys. A few indexed reads, each bounded. */ | |
| 538 | /** | |
| 539 | * The fast part: running and queued work, approved and merged pulls, deploys. A few indexed reads, | |
| 540 | * each bounded. | |
| 541 | */ | |
| 519 | 542 | export function readFast(db: Database, now: Date): Fast { |
| 520 | 543 | const iso = now.toISOString(); |
| 521 | 544 | const week = new Date(now.getTime() - 7 * 86_400_000).toISOString(); |
| @@ -596,7 +619,10 @@ export function withWaits( | ||
| 596 | 619 | } |
| 597 | 620 | |
| 598 | 621 | export interface Slow { |
| 599 | /** The crew's next asks in its own order, a few more than a lane draws so a build starting leaves the lane full. */ | |
| 622 | /** | |
| 623 | * The crew's next asks in its own order, a few more than a lane draws so a build starting leaves | |
| 624 | * the lane full. | |
| 625 | */ | |
| 600 | 626 | readonly asked: readonly LaneItem[]; |
| 601 | 627 | readonly askedTotal: number; |
| 602 | 628 | readonly strip: StripPart; |
| @@ -706,7 +732,10 @@ export function readSlow( | ||
| 706 | 732 | }; |
| 707 | 733 | } |
| 708 | 734 | |
| 709 | /** Why the builders sit idle, from the same module the dispatcher is asked in; `app` is the database and the data directory, the two things it reads. */ | |
| 735 | /** | |
| 736 | * Why the builders sit idle, from the same module the dispatcher is asked in; `app` is the database | |
| 737 | * and the data directory, the two things it reads. | |
| 738 | */ | |
| 710 | 739 | function idleOf(db: Database, dataDir: string, now: Date): IdleReason | null { |
| 711 | 740 | try { |
| 712 | 741 | return idleReason({ db, config: { dataDir } } as unknown as App, now); |
| @@ -715,7 +744,10 @@ function idleOf(db: Database, dataDir: string, now: Date): IdleReason | null { | ||
| 715 | 744 | } |
| 716 | 745 | } |
| 717 | 746 | |
| 718 | /** What waits on each viewer: the same set `/review` draws (`reviewSetOf`), counted per person the worker was told of. */ | |
| 747 | /** | |
| 748 | * What waits on each viewer: the same set `/review` draws (`reviewSetOf`), counted per person the | |
| 749 | * worker was told of. | |
| 750 | */ | |
| 719 | 751 | function asksOf(db: Database, viewers: readonly string[], now: Date): Record<string, AsksWaiting> { |
| 720 | 752 | const out: Record<string, AsksWaiting> = {}; |
| 721 | 753 | for (const id of viewers) { |
| @@ -730,7 +762,10 @@ function asksOf(db: Database, viewers: readonly string[], now: Date): Record<str | ||
| 730 | 762 | return out; |
| 731 | 763 | } |
| 732 | 764 | |
| 733 | /** A short hash of what a lane shows: its items without the heartbeat, which moves every few seconds and is no change. */ | |
| 765 | /** | |
| 766 | * A short hash of what a lane shows: its items without the heartbeat, which moves every few seconds | |
| 767 | * and is no change. | |
| 768 | */ | |
| 734 | 769 | function versionOf(read: LaneRead): string { |
| 735 | 770 | return Bun.hash( |
| 736 | 771 | JSON.stringify([ |
src/snapshot/sealed_store.ts +30 −8
| @@ -34,7 +34,10 @@ export const SEALED_PREFIX = "sealed/"; | ||
| 34 | 34 | const MAGIC = Buffer.from("FSO1"); |
| 35 | 35 | const IV_BYTES = 12; |
| 36 | 36 | const TAG_BYTES = 16; |
| 37 | /** The lane's header, beside the sealed objects and unsealed: the salt and a check value, never the key. */ | |
| 37 | /** | |
| 38 | * The lane's header, beside the sealed objects and unsealed: the salt and a check value, never the | |
| 39 | * key. | |
| 40 | */ | |
| 38 | 41 | export const LANE_HEADER = `${SEALED_PREFIX}lane.json`; |
| 39 | 42 | const SALT_BYTES = 16; |
| 40 | 43 | const SALT_HEX = /^[0-9a-f]{32}$/; |
| @@ -49,7 +52,10 @@ export interface SealKeys { | ||
| 49 | 52 | readonly mac: Buffer; |
| 50 | 53 | } |
| 51 | 54 | |
| 52 | /** The two keys a passphrase gives under a lane's salt: one seals bodies, one hides names. One scrypt, about 100 ms, off the main thread. */ | |
| 55 | /** | |
| 56 | * The two keys a passphrase gives under a lane's salt: one seals bodies, one hides names. One | |
| 57 | * scrypt, about 100 ms, off the main thread. | |
| 58 | */ | |
| 53 | 59 | export function sealKeys(passphrase: string, salt: Uint8Array): Promise<SealKeys> { |
| 54 | 60 | return new Promise((resolve, reject) => { |
| 55 | 61 | scrypt(passphrase, salt, 64, SCRYPT, (error, k) => { |
| @@ -59,7 +65,10 @@ export function sealKeys(passphrase: string, salt: Uint8Array): Promise<SealKeys | ||
| 59 | 65 | }); |
| 60 | 66 | } |
| 61 | 67 | |
| 62 | /** What the header keeps to tell the right passphrase from a wrong one; an HMAC, so it gives no shortcut past scrypt. */ | |
| 68 | /** | |
| 69 | * What the header keeps to tell the right passphrase from a wrong one; an HMAC, so it gives no | |
| 70 | * shortcut past scrypt. | |
| 71 | */ | |
| 63 | 72 | const checkOf = (keys: SealKeys): string => createHmac("sha256", keys.mac).update("forge off-site lane header").digest("hex"); |
| 64 | 73 | |
| 65 | 74 | /** A header's salt and check, or a sentence when the object is not one the lane wrote. */ |
| @@ -103,7 +112,10 @@ export function sealBody(keys: SealKeys, body: Uint8Array | string): Uint8Array | ||
| 103 | 112 | return Buffer.concat([MAGIC, iv, cipher.update(plain), cipher.final(), cipher.getAuthTag()]); |
| 104 | 113 | } |
| 105 | 114 | |
| 106 | /** The plain body; throws, naming the key, when the passphrase is wrong or the object is not one the lane sealed. */ | |
| 115 | /** | |
| 116 | * The plain body; throws, naming the key, when the passphrase is wrong or the object is not one the | |
| 117 | * lane sealed. | |
| 118 | */ | |
| 107 | 119 | export function openBody(keys: SealKeys, sealed: Uint8Array, key: string): Uint8Array { |
| 108 | 120 | const b = Buffer.from(sealed.buffer, sealed.byteOffset, sealed.byteLength); |
| 109 | 121 | if (b.length < MAGIC.length + IV_BYTES + TAG_BYTES || !b.subarray(0, MAGIC.length).equals(MAGIC)) |
| @@ -130,14 +142,21 @@ export function hiddenKey(keys: SealKeys, key: string): string { | ||
| 130 | 142 | } |
| 131 | 143 | |
| 132 | 144 | export interface SealedOptions { |
| 133 | /** Whether a lane with no header yet starts one (the mirror pass); a restore reads, so it does not. */ | |
| 145 | /** | |
| 146 | * Whether a lane with no header yet starts one (the mirror pass); a restore reads, so it does | |
| 147 | * not. | |
| 148 | */ | |
| 134 | 149 | readonly create?: boolean; |
| 135 | 150 | } |
| 136 | 151 | |
| 137 | /** `inner`, every object sealed under `passphrase` and named so a path never shows. The keys are derived on first use. */ | |
| 152 | /** | |
| 153 | * `inner`, every object sealed under `passphrase` and named so a path never shows. The keys are | |
| 154 | * derived on first use. | |
| 155 | */ | |
| 138 | 156 | export function sealedStore(inner: Store, passphrase: string, options: SealedOptions = {}): Store { |
| 139 | 157 | let pending: Promise<SealKeys> | undefined; |
| 140 | // One derivation for the store and every bounded view of it; a failed read of the header is tried again next time. | |
| 158 | // One derivation for the store and every bounded view of it; a failed read of the header is tried | |
| 159 | // again next time. | |
| 141 | 160 | const keys = (): Promise<SealKeys> => |
| 142 | 161 | (pending ??= laneKeys(inner, passphrase, options.create ?? true).catch((error: unknown) => { |
| 143 | 162 | pending = undefined; |
| @@ -183,7 +202,10 @@ function over(inner: Store, keys: () => Promise<SealKeys>): Store { | ||
| 183 | 202 | return bounded === undefined ? store : { ...store, bounded: (leftMs) => over(bounded.call(inner, leftMs), keys) }; |
| 184 | 203 | } |
| 185 | 204 | |
| 186 | /** A lane that may not write: every call fails with `reason`, so the board says why and nothing leaves unsealed. */ | |
| 205 | /** | |
| 206 | * A lane that may not write: every call fails with `reason`, so the board says why and nothing | |
| 207 | * leaves unsealed. | |
| 208 | */ | |
| 187 | 209 | export function refusingStore(where: string, reason: string): Store { |
| 188 | 210 | const no = async (): Promise<never> => { |
| 189 | 211 | throw new Error(reason); |
src/snapshot/snapshot.ts +7 −2
| @@ -184,7 +184,10 @@ export interface Progress { | ||
| 184 | 184 | readonly etaMs?: number; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | /** What a page shows beside "N objects, X so far": one label and value each; parts not known are left out. */ | |
| 187 | /** | |
| 188 | * What a page shows beside "N objects, X so far": one label and value each; parts not known are | |
| 189 | * left out. | |
| 190 | */ | |
| 188 | 191 | export function progressFacts(p: Progress): { label: string; value: string }[] { |
| 189 | 192 | const rows: { label: string; value: string }[] = []; |
| 190 | 193 | if (p.already !== undefined && p.seen !== undefined && p.seen > 0) rows.push({ label: "Already there", value: `${p.already} of ${p.seen} chunks` }); |
| @@ -194,7 +197,9 @@ export function progressFacts(p: Progress): { label: string; value: string }[] { | ||
| 194 | 197 | return rows; |
| 195 | 198 | } |
| 196 | 199 | |
| 197 | /** Progress as a short sentence for the log and the terminal: what is sent, what is left, how long. */ | |
| 200 | /** | |
| 201 | * Progress as a short sentence for the log and the terminal: what is sent, what is left, how long. | |
| 202 | */ | |
| 198 | 203 | export function progressWords(p: Progress): string { |
| 199 | 204 | const parts = [`${fmtBytes(p.bytes)} sent`]; |
| 200 | 205 | if (p.toGoBytes !== undefined) parts.push(`${fmtBytes(p.toGoBytes)} left`); |
src/snapshot/store.ts +11 −3
| @@ -34,7 +34,9 @@ export interface Store { | ||
| 34 | 34 | * this out. |
| 35 | 35 | */ |
| 36 | 36 | storedKey?(key: string): Promise<string>; |
| 37 | /** True when every object is encrypted before it reaches the store (the off-site lane, #11805). */ | |
| 37 | /** | |
| 38 | * True when every object is encrypted before it reaches the store (the off-site lane, #11805). | |
| 39 | */ | |
| 38 | 40 | readonly sealed?: boolean; |
| 39 | 41 | /** |
| 40 | 42 | * What the line is giving this store's puts (`line.ts`); a store that does not measure leaves it |
| @@ -102,12 +104,18 @@ export function s3FromEnv( | ||
| 102 | 104 | |
| 103 | 105 | /** The slowest uplink a put may assume: 5 Mbit/s, a third of the home line it runs behind. */ |
| 104 | 106 | export const FLOOR_BYTES_PER_S = 5_000_000 / 8; |
| 105 | /** What every attempt gets on top of its bytes' time: the handshake, the server's thought, a queue ahead of it. */ | |
| 107 | /** | |
| 108 | * What every attempt gets on top of its bytes' time: the handshake, the server's thought, a queue | |
| 109 | * ahead of it. | |
| 110 | */ | |
| 106 | 111 | export const SLACK_MS = 60_000; |
| 107 | 112 | /** How long a read, a listing or a delete may go unanswered. */ |
| 108 | 113 | export const CALL_DEADLINE_MS = 180_000; |
| 109 | 114 | |
| 110 | /** How long a put of `bytes` may take before it counts as failed: its bytes at the floor rate, plus slack. */ | |
| 115 | /** | |
| 116 | * How long a put of `bytes` may take before it counts as failed: its bytes at the floor rate, plus | |
| 117 | * slack. | |
| 118 | */ | |
| 111 | 119 | export const deadlineFor = ( |
| 112 | 120 | bytes: number, |
| 113 | 121 | floorBytesPerS = FLOOR_BYTES_PER_S, |
src/spawn/upstream.ts +2 −1
| @@ -184,7 +184,8 @@ async function run(app: App, options: { remote?: string; now?: number }): Promis | ||
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | const repo = getRepo(app.db, o, n); |
| 187 | // Remember the tip before the card, so a crash between them can lose a card but never repeat one. | |
| 187 | // Remember the tip before the card, so a crash between them can lose a card but never repeat | |
| 188 | // one. | |
| 188 | 189 | const tell = repo !== undefined && link.mode === "tell-me" && state.error === "" && state.parentTip !== "" && |
| 189 | 190 | (state.behind ?? 0) > 0 && state.parentTip !== state.toldTip; |
| 190 | 191 | if (tell) state = { ...state, toldTip: state.parentTip }; |
src/tui/forge.ts +2
| @@ -19,6 +19,7 @@ import { sourceFor } from "../view/source.ts"; | ||
| 19 | 19 | import { fleetCommand } from "./screens/fleet.ts"; |
| 20 | 20 | import { dataCommand } from "./screens/data.ts"; |
| 21 | 21 | import { packsCommand } from "./screens/packs.ts"; |
| 22 | import { crewNowCommand } from "./screens/crew_now.ts"; | |
| 22 | 23 | import { statusCommand } from "./screens/status.ts"; |
| 23 | 24 | import { templatesCommand } from "./screens/templates.ts"; |
| 24 | 25 | import { needsCommands } from "./screens/needs.ts"; |
| @@ -271,6 +272,7 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 271 | 272 | ...needsCommands(session, ctx), |
| 272 | 273 | ...asksAdminCommands(session, ctx), |
| 273 | 274 | packsCommand(session, ctx), |
| 275 | crewNowCommand(session, ctx), | |
| 274 | 276 | statusCommand(session, ctx), |
| 275 | 277 | templatesCommand(session, ctx), |
| 276 | 278 | shareTellCommand(session, ctx), |
src/tui/screens/crew_now.ts added +38
| @@ -0,0 +1,38 @@ | ||
| 1 | /** | |
| 2 | * The crew at work, in the terminal: the same up to three public runs a forge link's page shows | |
| 3 | * (`core/crew_now.ts`), each as what, who on which repository, and its state in the page's words. | |
| 4 | */ | |
| 5 | ||
| 6 | import { CREW_STARTING, crewNow, STATE_WORDS, type CrewRun } from "../../core/crew_now.ts"; | |
| 7 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 8 | import { style } from "../term/style.ts"; | |
| 9 | import { wrap } from "../term/width.ts"; | |
| 10 | import type { Session } from "../session.ts"; | |
| 11 | ||
| 12 | /** The screen's lines, plain data: one block per run, or the starting line. */ | |
| 13 | export function crewNowLines(runs: readonly CrewRun[]): string[] { | |
| 14 | if (runs.length === 0) return [CREW_STARTING]; | |
| 15 | return runs.flatMap((r) => [r.what, ` ${r.who} on ${r.repo}: ${STATE_WORDS[r.state]}`, ""]); | |
| 16 | } | |
| 17 | ||
| 18 | export function crewNowScreen(f: Session, ctx: Ctx, runs: readonly CrewRun[] = crewNow(f.app.db)): Screen { | |
| 19 | const lines = crewNowLines(runs); | |
| 20 | return { | |
| 21 | title: "Your crew's latest work", | |
| 22 | keys: [], | |
| 23 | render(area, s) { | |
| 24 | const c = ctx.theme.c; | |
| 25 | const shown = lines.flatMap((l) => (l === "" ? [""] : wrap(l, Math.max(20, area.w - 2)))); | |
| 26 | shown.slice(0, area.h).forEach((l, i) => s.text(area.x + 1, area.y + i, l, style(c.fg, c.bg), area.x + area.w)); | |
| 27 | }, | |
| 28 | key: () => false, | |
| 29 | }; | |
| 30 | } | |
| 31 | ||
| 32 | /** Offered to everyone in `forgeCommands`, as the page shows it to anyone with the link. */ | |
| 33 | export const crewNowCommand = (session: Session, ctx: Ctx) => ({ | |
| 34 | id: "crew-now", | |
| 35 | title: "Your crew's latest work", | |
| 36 | hint: "the three runs a forge link's page shows", | |
| 37 | run: () => ctx.push(crewNowScreen(session, ctx)), | |
| 38 | }); |
src/tui/screens/resilience.ts +17 −5
| @@ -66,7 +66,10 @@ export function resilienceLines(dataDir: string): string[] { | ||
| 66 | 66 | /** How many of a nightly job's last lines the output dialog shows. */ |
| 67 | 67 | export const OUTPUT_TAIL = 12; |
| 68 | 68 | |
| 69 | /** Each nightly job's line and the tail of its newest output, as /resilience/nightly/<job> shows it whole. */ | |
| 69 | /** | |
| 70 | * Each nightly job's line and the tail of its newest output, as /resilience/nightly/<job> shows it | |
| 71 | * whole. | |
| 72 | */ | |
| 70 | 73 | export function nightlyOutputLines(dataDir: string): string[] { |
| 71 | 74 | const said = nightlyLines(dataDir); |
| 72 | 75 | return JOBS.flatMap((job, i) => { |
| @@ -103,7 +106,10 @@ export function mirrorLine(f: Session): string { | ||
| 103 | 106 | return where === undefined ? "Mirror: none." : `Mirror: ${where}`; |
| 104 | 107 | } |
| 105 | 108 | |
| 106 | /** The bucket's verdict, as home and the MCP's `backups` say it: the line, each lane's newest, what is wrong. */ | |
| 109 | /** | |
| 110 | * The bucket's verdict, as home and the MCP's `backups` say it: the line, each lane's newest, what | |
| 111 | * is wrong. | |
| 112 | */ | |
| 107 | 113 | export function verdictLines(f: Session): string[] { |
| 108 | 114 | const v = backupVerdict(f.app.config.dataDir, lastDrill(f.app.db)); |
| 109 | 115 | const mark = v.state === "red" ? "RED" : v.state === "unknown" ? "unknown" : "ok"; |
| @@ -157,7 +163,9 @@ export function resilienceScreen(f: Session, ctx: Ctx): Screen { | ||
| 157 | 163 | const refusedAll = "Where snapshots go is a forge admin's."; |
| 158 | 164 | // The actions refuse anyone else too; the keys are not offered to them. |
| 159 | 165 | const mayAct = (): boolean => f.user?.isAdmin === true; |
| 160 | /** The newest snapshots, `unreadable` when the store could not be listed; undefined until read. */ | |
| 166 | /** | |
| 167 | * The newest snapshots, `unreadable` when the store could not be listed; undefined until read. | |
| 168 | */ | |
| 161 | 169 | let snapshots: string[] | "unreadable" | undefined; |
| 162 | 170 | let asking: Asking | undefined; |
| 163 | 171 | // While an action runs, `n`, `l` and `r` are ignored: a second would queue behind it. |
| @@ -291,7 +299,8 @@ export function resilienceScreen(f: Session, ctx: Ctx): Screen { | ||
| 291 | 299 | const out: string[] = []; |
| 292 | 300 | if (asking !== undefined) out.push(QUESTION[asking], ""); |
| 293 | 301 | else if (said !== "") out.push(...wrap(said, INNER), ""); |
| 294 | // A refusal or a result of a change stays up here too, above where a prompt opens over the middle. | |
| 302 | // A refusal or a result of a change stays up here too, above where a prompt opens over the | |
| 303 | // middle. | |
| 295 | 304 | if (note !== "") out.push(...wrap(note, INNER), ""); |
| 296 | 305 | out.push(...wrap(backupsLine(f.app).says, INNER), ...verdictLines(f), ""); |
| 297 | 306 | for (const line of nightlyLines(f.app.config.dataDir)) out.push(...wrap(line, INNER)); |
| @@ -380,7 +389,10 @@ export function resilienceScreen(f: Session, ctx: Ctx): Screen { | ||
| 380 | 389 | return screen; |
| 381 | 390 | } |
| 382 | 391 | |
| 383 | /** Where snapshots go and each THREATS.md protection's standing, as /resilience says it: a site admin's; a person admin sets or forgets the destination and the mirror here. */ | |
| 392 | /** | |
| 393 | * Where snapshots go and each THREATS.md protection's standing, as /resilience says it: a site | |
| 394 | * admin's; a person admin sets or forgets the destination and the mirror here. | |
| 395 | */ | |
| 384 | 396 | export const entry: PaletteEntry = { |
| 385 | 397 | id: "resilience", |
| 386 | 398 | title: "Resilience", |
src/web/crew_now.ts added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | /** | |
| 2 | * The crew at work, as the forge link's page shows it with no sign-in: up to three runs, who and | |
| 3 | * what, or one honest line that the crew is starting. See `core/crew_now.ts`; the terminal's | |
| 4 | * screen is `tui/screens/crew_now.ts` and reads the same words. | |
| 5 | */ | |
| 6 | ||
| 7 | import { CREW_STARTING, STATE_WORDS, type CrewRun } from "../core/crew_now.ts"; | |
| 8 | import { html, type Html } from "./html.ts"; | |
| 9 | ||
| 10 | export function crewNowHtml(runs: readonly CrewRun[]): Html { | |
| 11 | if (runs.length === 0) | |
| 12 | return html`<section id="crew-now" class="mt" aria-label="The crew"><p class="small muted">${CREW_STARTING}</p></section>`; | |
| 13 | return html`<section id="crew-now" class="mt" aria-label="The crew"><h2 class="small">Your crew's latest work</h2> | |
| 14 | <ul class="list">${runs.map((r) => html`<li class="row"><span class="row-main"><span class="row-title">${r.what}</span> | |
| 15 | <span class="row-meta">${r.who} on ${r.repo}</span></span><span class="row-trail muted small">${STATE_WORDS[r.state]}</span></li>`)}</ul></section>`; | |
| 16 | } |
src/web/pages/claim.ts +4
| @@ -22,6 +22,8 @@ | ||
| 22 | 22 | * so before anyone submits, and where to remove it. |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | import { crewNow } from "../../core/crew_now.ts"; | |
| 26 | import { crewNowHtml } from "../crew_now.ts"; | |
| 25 | 27 | import { PASSWORD_TOO_LONG, withinPasswordCap } from "../../core/hash-gate.ts"; |
| 26 | 28 | import { givenEmail, MIN_SIGNUP_PASSWORD, noEmail } from "../../actions/users.ts"; |
| 27 | 29 | import type { Credential } from "../../auth/webauthn.ts"; |
| @@ -236,6 +238,7 @@ function claimForm( | ||
| 236 | 238 | <p class="mb">Pick a username, then create your passkey. You will be the admin of this forge.</p> |
| 237 | 239 | ${accountForm(ctx, "/welcome", values, errors)} |
| 238 | 240 | </section> |
| 241 | ${crewNowHtml(crewNow(ctx.app.db))} | |
| 239 | 242 | </div></div>`; |
| 240 | 243 | return html`<div class="shell"><div class="narrow"> |
| 241 | 244 | ${pageHead("This forge is yours")} |
| @@ -251,6 +254,7 @@ function claimForm( | ||
| 251 | 254 | ${takeover(ctx, spawned, spawner)} |
| 252 | 255 | ${accountForm(ctx, "/claim", values, errors)} |
| 253 | 256 | </section> |
| 257 | ${crewNowHtml(crewNow(ctx.app.db))} | |
| 254 | 258 | </div></div>`; |
| 255 | 259 | } |
| 256 | 260 |
test/home-flow.test.ts +6 −3
| @@ -97,7 +97,8 @@ describe("the new home draws every lane", () => { | ||
| 97 | 97 | const landingBefore = await (await get("/live/lane?s=landing", owner)).text(); |
| 98 | 98 | expect(titles(before, "checks")).not.toContain("Pasted links keep their address"); |
| 99 | 99 | expect(titles(landingBefore, "landing")).toContain("Pasted links keep their address"); |
| 100 | // the crew starts the checks on an approved pull: its approval is superseded by new work, a check begins | |
| 100 | // the crew starts the checks on an approved pull: its approval is superseded by new work, a | |
| 101 | // check begins | |
| 101 | 102 | const pull = seed.pulls["a2"]!; |
| 102 | 103 | app.db.run("UPDATE review SET state = 'commented' WHERE issue_id = ?1", [pull]); |
| 103 | 104 | startCheck(app, pull, seed.repos.glue.id); |
| @@ -258,7 +259,8 @@ describe("nothing on the new home polls", () => { | ||
| 258 | 259 | const text = readFileSync(join(import.meta.dir, "..", file), "utf8"); |
| 259 | 260 | expect(text).not.toMatch(/setInterval\s*\(/); |
| 260 | 261 | expect(text).not.toMatch(/requestAnimationFrame/); |
| 261 | // the picture's two one-shots (a pause, a deadline on one worker job) are the only timers, and they hold nothing | |
| 262 | // the picture's two one-shots (a pause, a deadline on one worker job) are the only timers, | |
| 263 | // and they hold nothing | |
| 262 | 264 | expect((text.match(/setTimeout\s*\(/g) ?? []).length).toBe(file === "src/flow/lanes.ts" ? 2 : 0); |
| 263 | 265 | } |
| 264 | 266 | }); |
| @@ -289,7 +291,8 @@ describe("before the first reading, a page never reads on the thread", () => { | ||
| 289 | 291 | expect(html).toContain("Reading the hosted forges"); |
| 290 | 292 | for (const lane of LANES) expect(html).toContain(`id="lane-${lane}"`); |
| 291 | 293 | expect(html).not.toContain("A cost ledger per delivery"); |
| 292 | // its script fills each region from the region's own address: the lane waits for the worker, off the thread | |
| 294 | // its script fills each region from the region's own address: the lane waits for the worker, | |
| 295 | // off the thread | |
| 293 | 296 | const lane = await (await fetch(`${srv.url}/live/lane?s=building`, { headers: { cookie } })).text(); |
| 294 | 297 | expect(lane).toContain("A cost ledger per delivery"); |
| 295 | 298 | expect(lane).not.toContain("data-reading"); |
test/home-kpi-row.test.ts +4 −1
| @@ -1,4 +1,7 @@ | ||
| 1 | /** Home's figures row (#2871): the tiles, their links, studio words only, a sparkline of 24 points and one of 30 days of visitors (#3186). */ | |
| 1 | /** | |
| 2 | * Home's figures row (#2871): the tiles, their links, studio words only, a sparkline of 24 points | |
| 3 | * and one of 30 days of visitors (#3186). | |
| 4 | */ | |
| 2 | 5 | import { Database } from "bun:sqlite"; |
| 3 | 6 | import { bugTables, reachTables } from "./helpers/reach-tables.ts"; |
| 4 | 7 | import { NO_REACH, readReach } from "../src/flow/reach.ts"; |
test/link-crew-now.test.ts added +135
| @@ -0,0 +1,135 @@ | ||
| 1 | /** | |
| 2 | * The crew section on a forge link's page (/claim), fetched with no cookie: it shows up to | |
outdated
This header describes a different test (#12416 landing page). Rewrite it for the crew-now behaviour. |
||
| 3 | * three public-repository agent runs, live first, then the latest finished, with who and what | |
| 4 | * escaped and the state in plain words; a private repository's run never appears; a failed or | |
| 5 | * cancelled run says so; with no runs it says the crew is starting; and the read costs one | |
| 6 | * statement however many runs are stored. | |
| 7 | */ | |
| 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { childDirOf } from "../src/actions/spawn.ts"; | |
| 13 | import { createApp, type App } from "../src/app.ts"; | |
| 14 | import { crewNow } from "../src/core/crew_now.ts"; | |
| 15 | import { createToken } from "../src/core/tokens.ts"; | |
| 16 | import { createUser } from "../src/core/users.ts"; | |
| 17 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 18 | import { crewNowLines } from "../src/tui/screens/crew_now.ts"; | |
| 19 | import { firstBoot } from "../src/spawn/first-boot.ts"; | |
| 20 | import { once } from "./helpers/statements.ts"; | |
| 21 | import { expectWork } from "./helpers/work.ts"; | |
| 22 | import { quietLogs } from "./helpers/globals.ts"; | |
| 23 | ||
| 24 | quietLogs(); | |
| 25 | ||
| 26 | describe("the crew on a forge link's page", () => { | |
| 27 | let dir = ""; | |
| 28 | let parent: App; | |
| 29 | let parentServers: Servers; | |
| 30 | let child: App; | |
| 31 | let childServers: Servers; | |
| 32 | ||
| 33 | beforeAll(async () => { | |
| 34 | dir = await mkdtemp(join(tmpdir(), "forge-landing-")); | |
| 35 | parent = createApp({ dataDir: dir, url: "https://forge.test", port: 0 }); | |
| 36 | const alice = await createUser(parent.db, { | |
| 37 | origin: "seed", trusted: true, username: "alice", email: "[email protected]", | |
| 38 | password: "a-long-claim-passphrase", isAdmin: true, | |
| 39 | }); | |
| 40 | if (!alice.ok) throw new Error("user"); | |
| 41 | const rw = createToken(parent.db, alice.value.id, "rw", "rw").token; | |
| 42 | parentServers = await serve(parent); | |
| 43 | const made = await fetch(`${parentServers.url}/api/v1/forges`, { | |
| 44 | method: "POST", | |
| 45 | headers: { authorization: `Bearer ${rw}`, "content-type": "application/json" }, | |
| 46 | body: JSON.stringify({ name: "maria", apps: [], dryRun: false }), | |
| 47 | }); | |
| 48 | if (made.status !== 201) throw new Error(`spawn ${made.status}`); | |
| 49 | const body = (await made.json()) as { claimUrl: string; bodyId: string }; | |
| 50 | child = createApp({ dataDir: childDirOf(parent, body.bodyId), port: 0 }); | |
| 51 | await firstBoot(child); | |
| 52 | childServers = await serve(child); | |
| 53 | }, 60_000); | |
| 54 | ||
| 55 | afterAll(async () => { | |
| 56 | childServers.stop(); | |
| 57 | child.close(); | |
| 58 | parentServers.stop(); | |
| 59 | parent.close(); | |
| 60 | await rm(dir, { recursive: true, force: true }); | |
| 61 | }); | |
| 62 | ||
| 63 | const get = async () => (await fetch(`${childServers.url}/claim`)).text(); | |
| 64 | const sql = (q: string, ...a: string[]) => child.db.query(q).run(...a); | |
| 65 | ||
| 66 | test("no runs: says the crew is starting", async () => { | |
| 67 | const text = await get(); | |
| 68 | expect(text).toContain("Your crew is starting"); | |
| 69 | expect(text).not.toContain("latest work"); | |
| 70 | expect(text).toContain('id="crew-now" class="mt"'); | |
| 71 | }); | |
| 72 | ||
| 73 | test("live runs first, three at most, who and what, escaped", async () => { | |
| 74 | const owner = child.db.query<{ id: string }, []>("SELECT id FROM user WHERE username = 'alice'").get()!.id; | |
| 75 | sql("INSERT INTO repo (id, owner_id, name, visibility) VALUES ('r1', ?1, 'notes', 'public')", owner); | |
| 76 | const add = (id: string, state: string, summary: string) => | |
| 77 | sql("INSERT INTO run (id, repo_id, kind, state, summary, actor_id) VALUES (?1, 'r1', 'agent', ?2, ?3, ?4)", id, state, summary, owner); | |
| 78 | add("01", "ok", "oldest finished"); | |
| 79 | add("02", "running", "Draft <b>the page</b>"); | |
| 80 | add("03", "ok", "newer finished"); | |
| 81 | add("04", "failed", "newest finished"); | |
| 82 | const text = await get(); | |
| 83 | expect(text).toContain("Your crew's latest work"); | |
| 84 | expect(text).toContain("Draft <b>the page</b>"); | |
| 85 | expect(text).toContain("working now"); | |
| 86 | expect(text).toContain("newest finished"); | |
| 87 | expect(text).toContain("newer finished"); | |
| 88 | expect(text).not.toContain("oldest finished"); | |
| 89 | expect(text.match(/<li class="row">/g)?.length).toBe(3); | |
| 90 | expect(text.indexOf("Draft")).toBeLessThan(text.indexOf("newest finished")); | |
| 91 | expect(text).toContain("alice on notes"); | |
| 92 | }); | |
| 93 | ||
| 94 | test("a private repository's runs never appear; failed and cancelled say so", async () => { | |
| 95 | const owner = child.db.query<{ id: string }, []>("SELECT id FROM user WHERE username = 'alice'").get()!.id; | |
| 96 | sql("INSERT INTO repo (id, owner_id, name, visibility) VALUES ('r2', ?1, 'secret-plans', 'private')", owner); | |
| 97 | sql("DELETE FROM run"); | |
| 98 | const add = (id: string, repo: string, state: string, summary: string) => | |
| 99 | sql("INSERT INTO run (id, repo_id, kind, state, summary, actor_id) VALUES (?1, ?2, 'agent', ?3, ?4, ?5)", id, repo, state, summary, owner); | |
| 100 | add("10", "r1", "failed", "public failure"); | |
| 101 | add("11", "r1", "cancelled", "public cancel"); | |
| 102 | add("12", "r2", "running", "hidden private work"); | |
| 103 | add("13", "r2", "ok", "hidden private done"); | |
| 104 | const text = await get(); | |
| 105 | expect(text).not.toContain("secret-plans"); | |
| 106 | expect(text).not.toContain("hidden private"); | |
| 107 | expect(text).toContain("stopped with a problem"); | |
| 108 | expect(text).toContain("cancelled"); | |
| 109 | expect(text.match(/<li class="row">/g)?.length).toBe(2); | |
| 110 | }); | |
| 111 | ||
| 112 | test("the read is bounded: 5,000 stored runs cost one statement and three rows", async () => { | |
| 113 | const owner = child.db.query<{ id: string }, []>("SELECT id FROM user WHERE username = 'alice'").get()!.id; | |
| 114 | sql("DELETE FROM run"); | |
| 115 | child.db.transaction(() => { | |
| 116 | for (let i = 0; i < 5000; i++) | |
| 117 | sql("INSERT INTO run (id, repo_id, kind, state, summary, actor_id) VALUES (?1, 'r1', 'agent', 'ok', 'x', ?2)", `a${String(i).padStart(5, "0")}`, owner); | |
| 118 | })(); | |
| 119 | let runs: ReturnType<typeof crewNow> = []; | |
| 120 | const n = await once(child.db, () => { | |
| 121 | runs = crewNow(child.db); | |
| 122 | }); | |
| 123 | expectWork(n, { max: 1 }); | |
| 124 | expect(runs.length).toBe(3); | |
| 125 | expect(runs[0]!.what).toBe("x"); | |
| 126 | }); | |
| 127 | ||
| 128 | test("the terminal screen shows the same runs in the page's words", () => { | |
| 129 | const runs = crewNow(child.db); | |
| 130 | const lines = crewNowLines(runs); | |
| 131 | expect(lines.filter((t) => t === "x").length).toBe(3); | |
| 132 | expect(lines).toContain(` ${runs[0]!.who} on notes: finished`); | |
| 133 | expect(crewNowLines([])).toEqual(["Your crew is starting, and its first public work shows here."]); | |
| 134 | }); | |
| 135 | }); |
test/no-alarm-banner.test.ts +7 −3
| @@ -71,7 +71,9 @@ interface World { | ||
| 71 | 71 | readonly cookie: string; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | /** A forge in an alarm state; `spent` is the crew's spend today, in dollars, against a $1 ceiling. */ | |
| 74 | /** | |
| 75 | * A forge in an alarm state; `spent` is the crew's spend today, in dollars, against a $1 ceiling. | |
| 76 | */ | |
| 75 | 77 | async function world(spent: number): Promise<World> { |
| 76 | 78 | const root = mkdtempSync(join(tmpdir(), "forge-no-alarm-banner-")); |
| 77 | 79 | const app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge", crewCeilingUsd: 1 }); |
| @@ -89,7 +91,8 @@ async function world(spent: number): Promise<World> { | ||
| 89 | 91 | mkdirSync(join(root, "snapshot"), { recursive: true }); |
| 90 | 92 | const long = new Date(Date.now() - 72 * 3_600_000).toISOString(); |
| 91 | 93 | writeFileSync(join(root, "snapshot", "state.json"), JSON.stringify({ at: long, failingSince: long, error: "the bucket refused" })); |
| 92 | // A bug past its 48 h clock, in a repository that runs itself and has started no run: the bug-clock and idle-crew alarms. | |
| 94 | // A bug past its 48 h clock, in a repository that runs itself and has started no run: the | |
| 95 | // bug-clock and idle-crew alarms. | |
| 93 | 96 | const bug = openIssue(app, made.value, repo.value, { title: "The page is blank" }); |
| 94 | 97 | if (!bug.ok) throw new Error(String(bug.error)); |
| 95 | 98 | const label = createLabel(app.db, repo.value.id, "bug", "d73a4a"); |
| @@ -209,7 +212,8 @@ test("the detector names a banner and passes the lines the forge really draws", | ||
| 209 | 212 | expect(offenders("/", `<main id="main">${banner}<h1>Home</h1></main>`)).toHaveLength(1); |
| 210 | 213 | expect(offenders("/", '<p role="alert">Disk is low</p>')).toHaveLength(1); |
| 211 | 214 | expect(offenders("/", '<div class="stack banner">x</div>')).toHaveLength(1); |
| 212 | // Markup copied from the rendered pages: the home alarm line, the board's need, the menu item that carries the disk. | |
| 215 | // Markup copied from the rendered pages: the home alarm line, the board's need, the menu item | |
| 216 | // that carries the disk. | |
| 213 | 217 | expect(offenders("/", '<p class="small"><a href="/flow">No off-box backup has landed. The snapshot failed: the bucket refused</a></p>')).toEqual([]); |
| 214 | 218 | expect(offenders("/board", '<li><a data-need id="sentinel" href="/trevato/forge/issues"><span class="dot" data-tone="attn"></span> The sentinel has 1 open finding</a></li>')).toEqual([]); |
| 215 | 219 | expect(offenders("/", '<span class="menu-item" aria-disabled="true" title="this host's disk has 0.0% free">New forge</span>')).toEqual([]); |
test/palette-roster.test.ts +4
| @@ -53,6 +53,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 53 | 53 | ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"], |
| 54 | 54 | ["mirror-packs", "Mirror the packs' upstreams", "bring each pack's upstream projects in as read-only repositories"], |
| 55 | 55 | ["pack-repos", "Pack repositories", "which repositories /packs lists"], |
| 56 | ["crew-now", "Your crew's latest work", "the three runs a forge link's page shows"], | |
| 56 | 57 | ["status", "Status", "is the forge working, in one sentence"], |
| 57 | 58 | ["templates", "Templates", "what a new forge can start from"], |
| 58 | 59 | ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"], |
| @@ -234,6 +235,7 @@ test("a site-admin agent is offered the roster without the person-only entries", | ||
| 234 | 235 | ["needs", "How is my forge?", "what needs you, with a recommendation each; a takes a safe one"], |
| 235 | 236 | ["asks-admin", "What stands in the way", "what waits on you and what stands in your way; a asks whoever can, o opens the control"], |
| 236 | 237 | ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"], |
| 238 | ["crew-now", "Your crew's latest work", "the three runs a forge link's page shows"], | |
| 237 | 239 | ["status", "Status", "is the forge working, in one sentence"], |
| 238 | 240 | ["templates", "Templates", "what a new forge can start from"], |
| 239 | 241 | ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"], |
| @@ -335,6 +337,7 @@ test("a member person is offered the signed-in roster without the admin entries" | ||
| 335 | 337 | ["needs", "How is my forge?", "what needs you, with a recommendation each; a takes a safe one"], |
| 336 | 338 | ["asks-admin", "What stands in the way", "what waits on you and what stands in your way; a asks whoever can, o opens the control"], |
| 337 | 339 | ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"], |
| 340 | ["crew-now", "Your crew's latest work", "the three runs a forge link's page shows"], | |
| 338 | 341 | ["status", "Status", "is the forge working, in one sentence"], |
| 339 | 342 | ["templates", "Templates", "what a new forge can start from"], |
| 340 | 343 | ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"], |
| @@ -432,6 +435,7 @@ test("signed out, the palette offers sign-in and the public entries", () => { | ||
| 432 | 435 | ["explore", "Explore", "on the web"], |
| 433 | 436 | ["explore-feed", "Explore feed", "Atom address"], |
| 434 | 437 | ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"], |
| 438 | ["crew-now", "Your crew's latest work", "the three runs a forge link's page shows"], | |
| 435 | 439 | ["status", "Status", "is the forge working, in one sentence"], |
| 436 | 440 | ["templates", "Templates", "what a new forge can start from"], |
| 437 | 441 | ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"], |
Clean: this comment sits above STATES but describes the whole query. Move it onto
ALL.