Public: anyone can read this; the crew can change it.
The held page is one of the looks a check takes, as a visitor and as the owner #9491
scout/forge:scout/9488-the-held-page-is-one-of-the-looks-a-chec → main 8 commits fork
7 files
changed +26
−10
forge.json +2 −2
| @@ -3,8 +3,8 @@ | ||
| 3 | 3 | "api.anthropic.com" |
| 4 | 4 | ], |
| 5 | 5 | "app": { |
| 6 | "looks": ["/", "/front", "/explore", "/board", "/notes", "/feed", "/review", "/new", "/audit", "/releases", "/apps", "/repos", "/map", "/system", "/talk", "/flow", "/resilience", "/settings", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/milestones"], | |
| 7 | "looksAsOwner": ["/", "/flow", "/talk", "/system", "/resilience", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/milestones"], | |
| 6 | "looks": ["/", "/front", "/explore", "/board", "/notes", "/feed", "/review", "/new", "/releases", "/apps", "/repos", "/map", "/system", "/talk", "/flow", "/resilience", "/settings", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/milestones", "/preview-admin/sample/held"], | |
| 7 | "looksAsOwner": ["/", "/flow", "/talk", "/system", "/resilience", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/milestones", "/preview-admin/sample/held"], | |
| 8 | 8 | "run": "bun run src/main.ts", |
| 9 | 9 | "install": "", |
| 10 | 10 | "health": "/healthz", |
src/http/server.ts −3
| @@ -544,7 +544,6 @@ import { | ||
| 544 | 544 | shellTarget, |
| 545 | 545 | stopShells, |
| 546 | 546 | withShells, |
| 547 | closeStaleSessions, | |
| 548 | 547 | type ForgeSocket, |
| 549 | 548 | type ShellSocket, |
| 550 | 549 | } from "../machines/shell.ts"; |
| @@ -2161,8 +2160,6 @@ export function forgeHttp(app: App): ForgeHttp { | ||
| 2161 | 2160 | |
| 2162 | 2161 | export async function serve(app: App): Promise<Servers> { |
| 2163 | 2162 | const router = buildRouter(); |
| 2164 | // No shell outlives its forge: a row a stop or crash left open is closed. | |
| 2165 | closeStaleSessions(app.db); | |
| 2166 | 2163 | const apiRouter = buildApiRouter(); |
| 2167 | 2164 | await clearStaleSockets(app); |
| 2168 | 2165 | // One limiter per listener: its state is a minute of timestamps, and two |
src/machines/shell.ts +6 −4
| @@ -158,12 +158,14 @@ export function recordEnd(db: Database, row: string, reason: EndReason): void { | ||
| 158 | 158 | /** |
| 159 | 159 | * At boot, every row still open belongs to a forge that stopped or crashed |
| 160 | 160 | * without ending it: no shell survives its forge, so each is closed as |
| 161 | * `stopped`. Returns how many. | |
| 161 | * `stopped`. Only rows started before `bootedAt` are closed, so a session this | |
| 162 | * forge opened while it waited for a peer's write lock (`runs/peer.ts`) stays | |
| 163 | * open. Returns how many. | |
| 162 | 164 | */ |
| 163 | export function closeStaleSessions(db: Database): number { | |
| 165 | export function closeStaleSessions(db: Database, bootedAt = new Date().toISOString()): number { | |
| 164 | 166 | return db |
| 165 | .query("UPDATE machine_sessions SET ended_at = ?, end_reason = 'stopped' WHERE ended_at IS NULL") | |
| 166 | .run(new Date().toISOString()).changes; | |
| 167 | .query("UPDATE machine_sessions SET ended_at = ?, end_reason = 'stopped' WHERE ended_at IS NULL AND started_at < ?") | |
| 168 | .run(new Date().toISOString(), bootedAt).changes; | |
| 167 | 169 | } |
| 168 | 170 | |
| 169 | 171 | /** The repository's last sessions, newest first (index `machine_sessions_repo_started`). */ |
src/main.ts +5
| @@ -97,6 +97,7 @@ import { startPerfWatcher, TICK_MS } from "./perf/duty.ts"; | ||
| 97 | 97 | import { stallLine } from "./perf/loop.ts"; |
| 98 | 98 | import { bootStall, gitRecord, loopWatch, perfRecord } from "./perf/live.ts"; |
| 99 | 99 | import { timeStatements } from "./kernel/slow_sql.ts"; |
| 100 | import { closeStaleSessions } from "./machines/shell.ts"; | |
| 100 | 101 | import { waitForPeer } from "./runs/peer.ts"; |
| 101 | 102 | |
| 102 | 103 | // `forge hook <name>` re-enters here from a git hook stub. It relays to the |
| @@ -423,7 +424,11 @@ const leaveEarly = (): void => { | ||
| 423 | 424 | }; |
| 424 | 425 | const earlySignals = ["SIGINT", "SIGTERM", "SIGHUP"] as const; |
| 425 | 426 | for (const signal of earlySignals) process.once(signal, leaveEarly); |
| 427 | const bootedAt = new Date().toISOString(); | |
| 426 | 428 | await waitForPeer(app.db, app.log); |
| 429 | // No shell outlives its forge: a row a stop or crash left open is closed, once | |
| 430 | // the old forge has let go of the write lock (a write now would stall the loop). | |
| 431 | closeStaleSessions(app.db, bootedAt); | |
| 427 | 432 | for (const signal of earlySignals) process.off(signal, leaveEarly); |
| 428 | 433 | // A repository's own check, on every push a pull or the default branch takes. |
| 429 | 434 | const checks = |
test/forge-looks.test.ts +1
| @@ -26,6 +26,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 26 | 26 | "/family": "no picture: the cap of 24 looks went to the preview's /waves and /milestones; the page is covered by its own tests", |
| 27 | 27 | "/llms.txt": "plain markdown for machines, not a page to picture", |
| 28 | 28 | "/agents": "/llms.txt drawn as a page for an assistant; no picture: the cap of 24 looks is spent, and test/agents-page.test.ts covers it", |
| 29 | "/audit": "no picture: the cap of 24 looks went to the preview's /held; the page is covered by its own tests", | |
| 29 | 30 | "/robots.txt": "plain text for crawlers", |
| 30 | 31 | "/openapi.json": "a redirect to the contract document", |
| 31 | 32 | "/favicon.ico": "the tab icon, an image", |
test/machine-shell.test.ts +4 −1
| @@ -60,6 +60,9 @@ beforeAll(async () => { | ||
| 60 | 60 | // A row a crashed forge left open, closed when this one boots. |
| 61 | 61 | staleRow = recordStart(app.db, repo.id, "standard", alice.id); |
| 62 | 62 | servers = await serve(app); |
| 63 | // main.ts closes them once a peer lets go; here there is no peer. | |
| 64 | await Bun.sleep(2); | |
| 65 | closeStaleSessions(app.db); | |
| 63 | 66 | base = servers.url.replace(/^http/, "ws"); |
| 64 | 67 | }); |
| 65 | 68 | |
| @@ -195,7 +198,7 @@ test("a forge that cannot hold a cell refuses the shell", async () => { | ||
| 195 | 198 | |
| 196 | 199 | test("a row left open by a forge that stopped is closed as stopped at boot", () => { |
| 197 | 200 | const row = recordStart(app.db, repo.id, "standard", lastSessions(app.db, repo.id)[0]!.ownerId); |
| 198 | expect(closeStaleSessions(app.db)).toBe(1); | |
| 201 | expect(closeStaleSessions(app.db, new Date(Date.now() + 1000).toISOString())).toBe(1); | |
| 199 | 202 | expect(lastSessions(app.db, repo.id).find((r) => r.id === row)?.endReason).toBe("stopped"); |
| 200 | 203 | }); |
| 201 | 204 |
test/preview-looks.test.ts +8
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * THEMES_AT_REST theme lines and one fold line at rest. |
| 5 | 5 | */ |
| 6 | 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 7 | import { readFileSync } from "node:fs"; | |
| 7 | 8 | import { mkdtemp, rm } from "node:fs/promises"; |
| 8 | 9 | import { tmpdir } from "node:os"; |
| 9 | 10 | import { join } from "node:path"; |
| @@ -23,6 +24,12 @@ test("the owner looks for a forge preview include the held page at both widths", | ||
| 23 | 24 | expect(PREVIEW_HELD_THEMES.length).toBeGreaterThan(THEMES_AT_REST); |
| 24 | 25 | }); |
| 25 | 26 | |
| 27 | test("forge.json takes the held page as a visitor and as the owner", () => { | |
| 28 | const { app } = JSON.parse(readFileSync(join(import.meta.dir, "..", "forge.json"), "utf8")); | |
| 29 | expect(app.looks).toContain(PREVIEW_HELD_PAGE); | |
| 30 | expect(app.looksAsOwner).toContain(PREVIEW_HELD_PAGE); | |
| 31 | }); | |
| 32 | ||
| 26 | 33 | describe("the seeded held page", () => { |
| 27 | 34 | let dir: string; |
| 28 | 35 | let app: App; |
| @@ -46,6 +53,7 @@ describe("the seeded held page", () => { | ||
| 46 | 53 | expect(review.themes.map((t) => t.name)).not.toContain("Other"); |
| 47 | 54 | const res = await fetch(`${servers.url}${PREVIEW_HELD_PAGE}`); |
| 48 | 55 | expect(res.status).toBe(200); |
| 56 | expect(review.themes.length).toBeGreaterThan(0); | |
| 49 | 57 | const html = await res.text(); |
| 50 | 58 | const fold = `${PREVIEW_HELD_THEMES.length - THEMES_AT_REST} more themes`; |
| 51 | 59 | expect(html.split(fold).length - 1).toBe(1); |
new above
offline