Public: anyone can read this; the crew can change it.
A public page prints the morning paper's latest edition date, so the v1 probe can prove schedules ran #15394
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15393-a-public-page-prints-the-morning-paper-s → main 0 commits fork 1 thread · 1 unresolved
10 files
changed +174
−2
docs/OPERATING.md +1
| @@ -362,6 +362,7 @@ of this check only, never loaded by the server: its rules need a rendered page | ||
| 362 | 362 | and an accessibility tree, which nothing dependency-free gives. |
| 363 | 363 | |
| 364 | 364 | `bun scripts/v1-probe.ts https://forge.open-platform.sh` reads production (GETs and one MCP initialize, never signed in) and prints PASS, FAIL or UNKNOWN per v1.0.0 item with its URL and evidence. |
| 365 | The `schedules ran in 24 h` line reads a public page's newest `<time datetime>`: pass `--edition https://forge.open-platform.sh/edition`. That page (`src/http/edition.ts`) prints when the newest morning paper ran and nothing of the thread it was posted in; before any paper has run it prints no `<time>`. Its ETag holds the newest run and the build, so a deploy never answers 304 to older markup; signed-in and flash responses are never tagged. | |
| 365 | 366 | The owner tags v1.0.0 only when every line is PASS; an UNKNOWN line names what a person must check, and is not a pass. |
| 366 | 367 | |
| 367 | 368 | ## Secrets in the terminal |
src/core/edition.ts added +15
| @@ -0,0 +1,15 @@ | ||
| 1 | /** | |
| 2 | * When the newest morning paper was printed, by anyone: one instant and nothing of the thread it | |
| 3 | * was posted in (that is private, and written by an agent). Plain data out, for the public | |
| 4 | * `/edition` page (#15393). | |
| 5 | */ | |
| 6 | import type { Database } from "bun:sqlite"; | |
| 7 | ||
| 8 | /** | |
| 9 | * The latest `last_at` of any person's morning paper as an ISO instant, or null when none has run. | |
| 10 | */ | |
| 11 | export function latestEdition(db: Database): string | null { | |
| 12 | const row = db.query<{ at: string | null }, []>("SELECT MAX(last_at) AS at FROM talk_routine WHERE kind = 'paper' AND last_at IS NOT NULL").get(); | |
| 13 | const ms = row?.at == null ? Number.NaN : Date.parse(row.at); | |
| 14 | return Number.isFinite(ms) ? new Date(ms).toISOString() : null; | |
| 15 | } |
src/core/reserved.ts +1
| @@ -116,6 +116,7 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 116 | 116 | "maintenance", |
| 117 | 117 | "origins", |
| 118 | 118 | "robots.txt", |
| 119 | "edition", | |
| 119 | 120 | "favicon.ico", |
| 120 | 121 | "apple-touch-icon.png", |
| 121 | 122 | "apple-touch-icon-precomposed.png", |
src/http/edition.ts added +47
| @@ -0,0 +1,47 @@ | ||
| 1 | /** | |
| 2 | * `GET /edition`: a public page that prints when the newest scheduled morning paper ran, as one | |
| 3 | * `<time datetime>`, so an outside reader (`scripts/v1-probe.ts --edition`) can see schedules | |
| 4 | * run. The timestamp only: no thread text, no names, no sign-in (#15393). | |
| 5 | */ | |
| 6 | import { latestEdition } from "../core/edition.ts"; | |
| 7 | import { leanPage } from "../web/lean_page.ts"; | |
| 8 | import { html } from "../web/html.ts"; | |
| 9 | import { time } from "../web/time_element.ts"; | |
| 10 | import { notePhase, takeSessionTime, timePhase } from "../core/route_timing.ts"; | |
| 11 | import { readFlash } from "../web/flash.ts"; | |
| 12 | import { BOOT } from "../web/page_tag.ts"; | |
| 13 | import type { Handler } from "./context.ts"; | |
| 14 | import { taggable, unchanged, weakEtag } from "./etag.ts"; | |
| 15 | import { pageStamp } from "./page_stamp.ts"; | |
| 16 | import { securityFloor } from "./respond.ts"; | |
| 17 | ||
| 18 | /** | |
| 19 | * The page's weak tag: the newest run and the build that draws it, so a deploy never answers 304 to | |
| 20 | * old markup. | |
| 21 | */ | |
| 22 | export function editionTag(at: string | null, boot: string = BOOT): string { | |
| 23 | return weakEtag(JSON.stringify([boot, at])); | |
| 24 | } | |
| 25 | ||
| 26 | export const editionPage: Handler = (ctx) => { | |
| 27 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 28 | return timePhase(ctx.request, "render", () => { | |
| 29 | const at = latestEdition(ctx.app.db); | |
| 30 | const body = at === null | |
| 31 | ? html`<h1>Latest edition</h1><p>No morning paper has been printed yet.</p>` | |
| 32 | : html`<h1>Latest edition</h1><p>The newest morning paper was printed ${time(at)}.</p>`; | |
| 33 | const res = leanPage("Latest edition", body, 200); | |
| 34 | res.headers.set("cache-control", "public, max-age=60"); | |
| 35 | // The page is anonymous-only, but a signed-in reader or a one-shot flash (a notice drawn from | |
| 36 | // the request's cookie) still sees bytes that are theirs, so those are never tagged or cached | |
| 37 | // by tag. Named twice, as every open page is (a weak tag and a date): a repeat read is an | |
| 38 | // empty 304. | |
| 39 | if (!taggable(ctx.request, ctx.auth.user !== undefined, readFlash(ctx.request) !== undefined)) return res; | |
| 40 | const etag = editionTag(at); | |
| 41 | const lastModified = pageStamp(ctx.app, ctx.url.pathname, etag); | |
| 42 | res.headers.set("etag", etag); | |
| 43 | res.headers.set("last-modified", lastModified); | |
| 44 | if (!unchanged(ctx.request, etag, lastModified)) return res; | |
| 45 | return securityFloor(new Response(null, { status: 304, headers: res.headers })); | |
| 46 | }); | |
| 47 | }; |
src/http/marks/edition.json added +4
| @@ -0,0 +1,4 @@ | ||
| 1 | { | |
| 2 | "head": "/edition", | |
| 3 | "mark": "open" | |
| 4 | } |
src/http/server.ts +3
| @@ -211,6 +211,7 @@ import { findingAccept, findingsPage } from "../web/pages/findings.ts"; | ||
| 211 | 211 | import { queueCeiling, queueDefer, queuePage, queueSwitch } from "../web/pages/queue.ts"; |
| 212 | 212 | import { chapterAct, chapterPage, chaptersPage } from "../web/pages/chapters.ts"; |
| 213 | 213 | import { betAct, betPage, betPropose, betsPage } from "../web/pages/bets.ts"; |
| 214 | import { editionPage } from "./edition.ts"; | |
| 214 | 215 | import { changelogJson, changelogPage } from "../web/pages/changelog.ts"; |
| 215 | 216 | import { llmsFull } from "../web/llms_full.ts"; |
| 216 | 217 | import { docsFeature, docsFile, docsFolder } from "../web/pages/docs_link.ts"; |
| @@ -903,6 +904,8 @@ export function buildRouter(): Router<Handler> { | ||
| 903 | 904 | router.add("GET", "/agents", agentsPage); |
| 904 | 905 | router.add("GET", "/.well-known/change-password", changePassword); |
| 905 | 906 | router.add("GET", "/robots.txt", robotsTxt); |
| 907 | // When the newest morning paper ran: a timestamp alone, public (#15393). | |
| 908 | router.add("GET", "/edition", editionPage); | |
| 906 | 909 | router.add("GET", "/oembed", oembed); |
| 907 | 910 | router.add("GET", "/releases.json", releasesJson); |
| 908 | 911 | router.add("GET", "/sitemap.xml", sitemapXml); |
src/web/page_tag.ts +2 −1
| @@ -20,7 +20,8 @@ import { beaconAsset, shellAsset, spriteAsset, stylesheetAsset } from "./asset.t | ||
| 20 | 20 | import { readFlash } from "./flash.ts"; |
| 21 | 21 | import { documentHeaders, signInHref, signUpHref } from "./layout.ts"; |
| 22 | 22 | |
| 23 | const BOOT = crypto.randomUUID(); | |
| 23 | /** This process's boot: a tag that holds it never outlives the build that drew the page. */ | |
| 24 | export const BOOT = crypto.randomUUID(); | |
| 24 | 25 | |
| 25 | 26 | /** What a signed-out visitor's palette lists: the door's apps and whether each is running. */ |
| 26 | 27 | function paletteStamp(ctx: Ctx): unknown { |
test/design-audit.test.ts +1 −1
| @@ -17,7 +17,7 @@ const doc = readFileSync("docs/design/audit.md", "utf8"); | ||
| 17 | 17 | |
| 18 | 18 | /** Routes that answer a file, a fragment, a redirect hop or a callback. */ |
| 19 | 19 | const NOT_PAGES = |
| 20 | /^\/(assets\/|\.well-known\/|icons\/|og\/|live\/|__forge\/|go\/|new\/issue$|events$|system\/stream$|talk\/stream$|settings\/teams\/stream$|sw\.js$|offline$|robots\.txt$|favicon\.ico$|apple-touch-icon(-precomposed)?\.png$|sitemap\.xml$|oembed$|manifest\.webmanifest$|opensearch\.xml$|llms(-full)?\.txt$|openapi\.json$|releases\.json$|templates\.json$|maintenance\.json$|changelog\.atom$|explore\.atom$|feed\.json$|docs(\/[^/]*)?$|audit\.csv$|settings\/traffic\/scrapes\/export$|fleet\/graph\/live$|fleet\/graph\.csv$|forges\/export\.csv$|settings\/origins\/callback$|broker\/origins\/start$|home\/archived\/|settings\/backups\/live$|api\/v1(\/|$))/; | |
| 20 | /^\/(assets\/|\.well-known\/|icons\/|og\/|live\/|__forge\/|go\/|new\/issue$|events$|system\/stream$|talk\/stream$|settings\/teams\/stream$|sw\.js$|offline$|robots\.txt$|favicon\.ico$|apple-touch-icon(-precomposed)?\.png$|sitemap\.xml$|edition$|oembed$|manifest\.webmanifest$|opensearch\.xml$|llms(-full)?\.txt$|openapi\.json$|releases\.json$|templates\.json$|maintenance\.json$|changelog\.atom$|explore\.atom$|feed\.json$|docs(\/[^/]*)?$|audit\.csv$|settings\/traffic\/scrapes\/export$|fleet\/graph\/live$|fleet\/graph\.csv$|forges\/export\.csv$|settings\/origins\/callback$|broker\/origins\/start$|home\/archived\/|settings\/backups\/live$|api\/v1(\/|$))/; | |
| 21 | 21 | |
| 22 | 22 | const getRoutes = [ |
| 23 | 23 | ...server.matchAll(/router\.add\(\s*"GET",\s*"([^"]+)"/g), |
test/edition.test.ts added +99
| @@ -0,0 +1,99 @@ | ||
| 1 | /** | |
| 2 | * `GET /edition` prints the newest morning paper's instant as <time datetime>, anonymously, and no | |
| 3 | * thread text. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { createUser } from "../src/core/users.ts"; | |
| 11 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 12 | import { latestEdition } from "../src/core/edition.ts"; | |
| 13 | import { editionTag } from "../src/http/edition.ts"; | |
| 14 | ||
| 15 | describe("GET /edition", () => { | |
| 16 | let dataDir: string; | |
| 17 | let app: App; | |
| 18 | let servers: Servers; | |
| 19 | let userId: string; | |
| 20 | ||
| 21 | beforeAll(async () => { | |
| 22 | dataDir = await mkdtemp(join(tmpdir(), "forge-edition-")); | |
| 23 | app = createApp({ dataDir, port: 0 }); | |
| 24 | servers = await serve(app); | |
| 25 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 26 | if (!u.ok) throw new Error(u.error); | |
| 27 | userId = u.value.id; | |
| 28 | }, 30_000); | |
| 29 | ||
| 30 | afterAll(async () => { | |
| 31 | servers.stop(); | |
| 32 | app.close(); | |
| 33 | await rm(dataDir, { recursive: true, force: true }); | |
| 34 | }); | |
| 35 | ||
| 36 | test("says so when no paper has run, with no sign-in", async () => { | |
| 37 | const res = await fetch(`${servers.url}/edition`, { redirect: "manual" }); | |
| 38 | expect(res.status).toBe(200); | |
| 39 | expect(await res.text()).not.toContain("<time"); | |
| 40 | }); | |
| 41 | ||
| 42 | test("prints the newest paper's instant and nothing else of it", async () => { | |
| 43 | app.db.query("INSERT INTO talk_routine (user_id, kind, every_min, at_hour, last_at, conversation_id) VALUES (?1,'paper',1440,7,'2026-11-21T07:00:03.000Z','secret-thread-id')").run(userId); | |
| 44 | app.db.query("INSERT INTO talk_routine (user_id, kind, every_min, at_hour, last_at, conversation_id) VALUES (?1,'checkin',60,NULL,'2026-11-21T09:00:00.000Z','other')").run(userId); | |
| 45 | const res = await fetch(`${servers.url}/edition`, { redirect: "manual" }); | |
| 46 | expect(res.status).toBe(200); | |
| 47 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 48 | const text = await res.text(); | |
| 49 | expect(text).toContain('datetime="2026-11-21T07:00:03.000Z"'); | |
| 50 | expect(text).not.toContain("2026-11-21T09:00"); | |
| 51 | expect(text).not.toContain("secret-thread-id"); | |
| 52 | expect(text).not.toContain("sign in"); | |
| 53 | }); | |
| 54 | }); | |
| 55 | ||
| 56 | describe("GET /edition caching", () => { | |
| 57 | let dataDir: string; | |
| 58 | let app: App; | |
| 59 | let servers: Servers; | |
| 60 | ||
| 61 | beforeAll(async () => { | |
| 62 | dataDir = await mkdtemp(join(tmpdir(), "forge-edition-c-")); | |
| 63 | app = createApp({ dataDir, port: 0 }); | |
| 64 | servers = await serve(app); | |
| 65 | }, 30_000); | |
| 66 | ||
| 67 | afterAll(async () => { | |
| 68 | servers.stop(); | |
| 69 | app.close(); | |
| 70 | await rm(dataDir, { recursive: true, force: true }); | |
| 71 | }); | |
| 72 | ||
| 73 | test("a held tag is an empty 304 that keeps the security floor; Cache-Control is public", async () => { | |
| 74 | const first = await fetch(`${servers.url}/edition`); | |
| 75 | expect(first.headers.get("cache-control")).toBe("public, max-age=60"); | |
| 76 | const etag = first.headers.get("etag"); | |
| 77 | expect(etag).toMatch(/^W\//); | |
| 78 | await first.text(); | |
| 79 | const again = await fetch(`${servers.url}/edition`, { headers: { "if-none-match": etag ?? "" } }); | |
| 80 | expect(again.status).toBe(304); | |
| 81 | expect(await again.text()).toBe(""); | |
| 82 | expect(again.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 83 | expect(again.headers.get("referrer-policy")).not.toBeNull(); | |
| 84 | expect(again.headers.get("content-security-policy")).not.toBeNull(); | |
| 85 | }); | |
| 86 | ||
| 87 | test("a different build or a newer paper changes the tag", () => { | |
| 88 | expect(editionTag("2026-11-21T07:00:00.000Z", "boot-a")).not.toBe(editionTag("2026-11-21T07:00:00.000Z", "boot-b")); | |
| 89 | expect(editionTag("2026-11-21T07:00:00.000Z", "boot-a")).not.toBe(editionTag("2026-11-22T07:00:00.000Z", "boot-a")); | |
| 90 | expect(editionTag(null, "boot-a")).toBe(editionTag(null, "boot-a")); | |
| 91 | }); | |
| 92 | ||
| 93 | test("latestEdition ignores a malformed last_at", async () => { | |
| 94 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 95 | if (!u.ok) throw new Error(u.error); | |
| 96 | app.db.query("INSERT INTO talk_routine (user_id, kind, every_min, at_hour, last_at, conversation_id) VALUES (?1,'paper',1440,7,'not-a-date','c')").run(u.value.id); | |
| 97 | expect(latestEdition(app.db)).toBeNull(); | |
| 98 | }); | |
| 99 | }); |
test/forge-looks.test.ts +1
| @@ -44,6 +44,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 44 | 44 | "/map": "no picture: its slot went to /security, the visitor's security page (#13208); covered by test/map-cache.test.ts and the other map tests", |
| 45 | 45 | "/packs": "no picture: not in app.looks; the page is covered by test/packs.test.ts", |
| 46 | 46 | "/fleet": "no picture: not in app.looks; the page is covered by test/fleet-table.test.ts", |
| 47 | "/edition": "a bare timestamp page for the v1 probe; covered by test/edition.test.ts", | |
| 47 | 48 | "/robots.txt": "plain text for crawlers", |
| 48 | 49 | "/openapi.json": "a redirect to the contract document", |
| 49 | 50 | "/favicon.ico": "the tab icon, an image", |
new above
offline
Add the boot id to the tag (as pageTag does) so a new build never answers 304 to an old render.