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

Parked opened this
Closed without merging

scout/forge:scout/9488-the-held-page-is-one-of-the-looks-a-chec → main 8 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +26 −10
forge.json +2 −2
@@ -3,8 +3,8 @@
33 "api.anthropic.com"
44 ],
55 "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"],
88 "run": "bun run src/main.ts",
99 "install": "",
1010 "health": "/healthz",
src/http/server.ts −3
@@ -544,7 +544,6 @@ import {
544544 shellTarget,
545545 stopShells,
546546 withShells,
547 closeStaleSessions,
548547 type ForgeSocket,
549548 type ShellSocket,
550549 } from "../machines/shell.ts";
@@ -2161,8 +2160,6 @@ export function forgeHttp(app: App): ForgeHttp {
21612160
21622161 export async function serve(app: App): Promise<Servers> {
21632162 const router = buildRouter();
2164 // No shell outlives its forge: a row a stop or crash left open is closed.
2165 closeStaleSessions(app.db);
21662163 const apiRouter = buildApiRouter();
21672164 await clearStaleSockets(app);
21682165 // 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 {
158158 /**
159159 * At boot, every row still open belongs to a forge that stopped or crashed
160160 * 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.
162164 */
163 export function closeStaleSessions(db: Database): number {
165 export function closeStaleSessions(db: Database, bootedAt = new Date().toISOString()): number {
164166 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;
167169 }
168170
169171 /** 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";
9797 import { stallLine } from "./perf/loop.ts";
9898 import { bootStall, gitRecord, loopWatch, perfRecord } from "./perf/live.ts";
9999 import { timeStatements } from "./kernel/slow_sql.ts";
100 import { closeStaleSessions } from "./machines/shell.ts";
100101 import { waitForPeer } from "./runs/peer.ts";
101102
102103 // `forge hook <name>` re-enters here from a git hook stub. It relays to the
@@ -423,7 +424,11 @@ const leaveEarly = (): void => {
423424 };
424425 const earlySignals = ["SIGINT", "SIGTERM", "SIGHUP"] as const;
425426 for (const signal of earlySignals) process.once(signal, leaveEarly);
427 const bootedAt = new Date().toISOString();
426428 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);
427432 for (const signal of earlySignals) process.off(signal, leaveEarly);
428433 // A repository's own check, on every push a pull or the default branch takes.
429434 const checks =
test/forge-looks.test.ts +1
@@ -26,6 +26,7 @@ const NOT_A_PAGE: Record<string, string> = {
2626 "/family": "no picture: the cap of 24 looks went to the preview's /waves and /milestones; the page is covered by its own tests",
2727 "/llms.txt": "plain markdown for machines, not a page to picture",
2828 "/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",
2930 "/robots.txt": "plain text for crawlers",
3031 "/openapi.json": "a redirect to the contract document",
3132 "/favicon.ico": "the tab icon, an image",
test/machine-shell.test.ts +4 −1
@@ -60,6 +60,9 @@ beforeAll(async () => {
6060 // A row a crashed forge left open, closed when this one boots.
6161 staleRow = recordStart(app.db, repo.id, "standard", alice.id);
6262 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);
6366 base = servers.url.replace(/^http/, "ws");
6467 });
6568
@@ -195,7 +198,7 @@ test("a forge that cannot hold a cell refuses the shell", async () => {
195198
196199 test("a row left open by a forge that stopped is closed as stopped at boot", () => {
197200 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);
199202 expect(lastSessions(app.db, repo.id).find((r) => r.id === row)?.endReason).toBe("stopped");
200203 });
201204
test/preview-looks.test.ts +8
@@ -4,6 +4,7 @@
44 * THEMES_AT_REST theme lines and one fold line at rest.
55 */
66 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7 import { readFileSync } from "node:fs";
78 import { mkdtemp, rm } from "node:fs/promises";
89 import { tmpdir } from "node:os";
910 import { join } from "node:path";
@@ -23,6 +24,12 @@ test("the owner looks for a forge preview include the held page at both widths",
2324 expect(PREVIEW_HELD_THEMES.length).toBeGreaterThan(THEMES_AT_REST);
2425 });
2526
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
2633 describe("the seeded held page", () => {
2734 let dir: string;
2835 let app: App;
@@ -46,6 +53,7 @@ describe("the seeded held page", () => {
4653 expect(review.themes.map((t) => t.name)).not.toContain("Other");
4754 const res = await fetch(`${servers.url}${PREVIEW_HELD_PAGE}`);
4855 expect(res.status).toBe(200);
56 expect(review.themes.length).toBeGreaterThan(0);
4957 const html = await res.text();
5058 const fold = `${PREVIEW_HELD_THEMES.length - THEMES_AT_REST} more themes`;
5159 expect(html.split(fold).length - 1).toBe(1);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs