Public: anyone can read this; the crew can change it.
The forge toolbar names the app's live version and its last deploy time, read from the running record #14528
Check · Review · Land · Live — Changes were asked on this head: sentinel asked for changes (review 01m7vdkfy2gbsdxx90fm9bvpas).
scout/forge:scout/14520-the-forge-toolbar-names-the-app-s-live-v → main 1 commit fork 1 thread · 1 unresolved
This pull asks to reach lab--forge-trevato-apps.open-platform.sh. Its preview and check reach what main reaches; the new host opens when the pull lands.
3 files
changed +69
−30
src/apps/door.ts +18 −21
| @@ -65,39 +65,36 @@ function whereLine(where: PillWhere, forgeUrl: string): string { | ||
| 65 | 65 | return `${words.replace(n, `<a href="${escapeAttr(href)}">${n}</a>`)}: ${escapeAttr(where.title)}`; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | /** `2026-10-25 14:03 UTC`, or the raw text when it is not a date. */ | |
| 69 | function when(at: string): string { | |
| 68 | /** `3 h ago`: how long ago, in the toolbar pill's words; the exact time rides beside it. */ | |
| 69 | export function ago(at: string, now: number = Date.now()): string { | |
| 70 | 70 | const t = Date.parse(at); |
| 71 | return Number.isNaN(t) ? at : new Date(t).toISOString().slice(0, 16).replace("T", " ") + " UTC"; | |
| 71 | if (Number.isNaN(t)) return at; | |
| 72 | const m = Math.max(0, Math.floor((now - t) / 60000)); | |
| 73 | return m < 1 ? "just now" : m < 60 ? `${m} min ago` : m < 1440 ? `${Math.floor(m / 60)} h ago` : `${Math.floor(m / 1440)} d ago`; | |
| 72 | 74 | } |
| 73 | 75 | |
| 74 | const stamp = (at: string): string => | |
| 75 | `<time datetime="${escapeAttr(at)}">${escapeAttr(when(at))}</time>`; | |
| 76 | /** The relative time in a <time>, its exact UTC time in the title. */ | |
| 77 | const stamp = (at: string): string => { | |
| 78 | const t = Date.parse(at); | |
| 79 | const exact = Number.isNaN(t) ? at : new Date(t).toUTCString(); | |
| 80 | return `<time datetime="${escapeAttr(at)}" title="${escapeAttr(exact)}">${escapeAttr(ago(at))}</time>`; | |
| 81 | }; | |
| 76 | 82 | |
| 77 | 83 | function servingHtml(facts: DoorFacts): string { |
| 78 | 84 | const s = facts.serving; |
| 79 | 85 | if (s === undefined) return ""; |
| 80 | 86 | const repo = facts.where.repo; |
| 87 | const now = s.kind === "preview" ? s.current : s.releases[0]; | |
| 88 | if (now === undefined) return "<p>Not deployed yet</p>"; | |
| 81 | 89 | // Commit ids and the release history belong to someone who may read the |
| 82 | 90 | // repository; a guest of the app learns only when it last changed. |
| 83 | if (repo === undefined) { | |
| 84 | if (s.kind === "preview") | |
| 85 | return `<p>Preview of #${s.pull}${ | |
| 86 | s.current === undefined ? ", not deployed yet" : `, deployed ${stamp(s.current.at)}` | |
| 87 | }</p>`; | |
| 88 | const now = s.releases[0]; | |
| 89 | return now === undefined ? "<p>not released yet</p>" : `<p>Serving since ${stamp(now.at)}</p>`; | |
| 90 | } | |
| 91 | if (repo === undefined) return `<p>Deployed ${stamp(now.at)}</p>`; | |
| 91 | 92 | const sha = (x: Served): string => |
| 92 | 93 | `<a href="${escapeAttr(new URL(`/${repo}/commit/${x.sha}`, facts.forgeUrl).href)}"><code>${escapeAttr(x.sha.slice(0, 7))}</code></a>`; |
| 93 | if (s.kind === "preview") | |
| 94 | return `<p>Preview of #${s.pull}${ | |
| 95 | s.current === undefined ? ", not deployed yet" : ` at ${sha(s.current)}, deployed ${stamp(s.current.at)}` | |
| 96 | }</p>`; | |
| 97 | const [now, ...before] = s.releases; | |
| 98 | if (now === undefined) return "<p>not released yet</p>"; | |
| 99 | const older = before.map((r) => `<li>${sha(r)}, ${stamp(r.at)}</li>`).join(""); | |
| 100 | return `<p>Serving ${sha(now)} since ${stamp(now.at)}</p>${older === "" ? "" : `<h2>Before it</h2><ul>${older}</ul>`}`; | |
| 94 | const line = `<p>Version ${sha(now)} · deployed ${stamp(now.at)}</p>`; | |
| 95 | if (s.kind === "preview") return line; | |
| 96 | const older = s.releases.slice(1).map((r) => `<li>${sha(r)}, ${stamp(r.at)}</li>`).join(""); | |
| 97 | return `${line}${older === "" ? "" : `<h2>Before it</h2><ul>${older}</ul>`}`; | |
| 101 | 98 | } |
| 102 | 99 | |
| 103 | 100 | function pullsHtml(pulls: DoorPullLine[] | undefined, morePulls: string | undefined): string { |
test/apps-door-serving.test.ts +8 −9
| @@ -22,8 +22,8 @@ test("production shows the newest release and the three before it, linked", asyn | ||
| 22 | 22 | deploy("production", c.repeat(40), `2026-10-0${i + 1}T10:00:00.000Z`); |
| 23 | 23 | deploy("production", "f".repeat(40), null); |
| 24 | 24 | const { html } = await page("r1", "production"); |
| 25 | expect(html).toContain("Serving <a href=\"https://forge.test/me/notes/commit/" + "e".repeat(40)); | |
| 26 | expect(html).toContain("since <time datetime=\"2026-10-05T10:00:00.000Z\">2026-10-05 10:00 UTC"); | |
| 25 | expect(html).toContain("Version <a href=\"https://forge.test/me/notes/commit/" + "e".repeat(40)); | |
| 26 | expect(html).toContain("deployed <time datetime=\"2026-10-05T10:00:00.000Z\" title=\"Mon, 05 Oct 2026 10:00:00 GMT\">"); | |
| 27 | 27 | for (const c of ["d", "c", "b"]) expect(html).toContain(`/commit/${c.repeat(40)}`); |
| 28 | 28 | expect(html).not.toContain("a".repeat(40)); |
| 29 | 29 | expect(html).not.toContain("f".repeat(7)); |
| @@ -32,26 +32,25 @@ test("production shows the newest release and the three before it, linked", asyn | ||
| 32 | 32 | test("a preview shows its pull and short sha", async () => { |
| 33 | 33 | deploy("pull-7", "1234567890abcdef".repeat(2) + "12345678", "2026-10-06T08:30:00.000Z"); |
| 34 | 34 | const { html } = await page("r1", "pull-7"); |
| 35 | expect(html).toContain("Preview of #7 at "); | |
| 35 | expect(html).toContain("Version <a "); | |
| 36 | 36 | expect(html).toContain("<code>1234567</code>"); |
| 37 | expect(html).toContain(", deployed <time"); | |
| 38 | expect(html).not.toContain("Serving"); | |
| 37 | expect(html).toContain(" · deployed <time"); | |
| 39 | 38 | }); |
| 40 | 39 | |
| 41 | 40 | test("an app never released says so", async () => { |
| 42 | 41 | const { html } = await page("none", "production"); |
| 43 | expect(html).toContain("not released yet"); | |
| 42 | expect(html).toContain("Not deployed yet"); | |
| 44 | 43 | }); |
| 45 | 44 | |
| 46 | 45 | test("a guest, whose page names no repository, sees no sha and no history", async () => { |
| 47 | 46 | const guest = (where: { app: string; env: string; pull?: number }, serving = readServing(db, "r1", where.env)) => |
| 48 | 47 | doorPage({ where, forgeUrl: "https://forge.test", serving }, false).text(); |
| 49 | 48 | const prod = await guest({ app: "notes", env: "production" }); |
| 50 | expect(prod).toContain("Serving since <time"); | |
| 49 | expect(prod).toContain("Deployed <time"); | |
| 51 | 50 | expect(prod).not.toMatch(/<code>|\/commit\/|Before it/); |
| 52 | 51 | for (const c of "abcde") expect(prod).not.toContain(c.repeat(7)); |
| 53 | 52 | const prev = await guest({ app: "notes", env: "pull-7", pull: 7 }); |
| 54 | expect(prev).toContain("Preview of #7, deployed <time"); | |
| 53 | expect(prev).toContain("Deployed <time"); | |
| 55 | 54 | expect(prev).not.toMatch(/<code>|1234567/); |
| 56 | 55 | }); |
| 57 | 56 | |
| @@ -84,5 +83,5 @@ test("a preview with no deploy says so", async () => { | ||
| 84 | 83 | { where: { app: "notes", env: "pull-99", repo: "me/notes", pull: 99 }, forgeUrl: "https://forge.test", serving: s }, |
| 85 | 84 | false, |
| 86 | 85 | ).text(); |
| 87 | expect(html).toContain("Preview of #99, not deployed yet"); | |
| 86 | expect(html).toContain("Not deployed yet"); | |
| 88 | 87 | }); |
test/toolbar-version.test.ts added +43
| @@ -0,0 +1,43 @@ | ||
| 1 | /** The /__forge/ door names the live version and when it was deployed (#14520). */ | |
| 2 | import { Database } from "bun:sqlite"; | |
| 3 | import { expect, test } from "bun:test"; | |
| 4 | import { ago, doorPage } from "../src/apps/door.ts"; | |
| 5 | import { readServing } from "../src/apps/serving.ts"; | |
| 6 | ||
| 7 | const db = new Database(":memory:"); | |
| 8 | db.run(`CREATE TABLE run (id INTEGER PRIMARY KEY, repo_id TEXT, kind TEXT, env TEXT, commit_oid TEXT, serving_at TEXT)`); | |
| 9 | const put = (repo: string, env: string, sha: string, at: string) => | |
| 10 | db.run(`INSERT INTO run (repo_id, kind, env, commit_oid, serving_at) VALUES (?,'deploy',?,?,?)`, [repo, env, sha, at]); | |
| 11 | const page = (repo: string, env: string) => | |
| 12 | doorPage( | |
| 13 | { | |
| 14 | where: { app: "n", env, repo: "me/n", ...(env === "production" ? {} : { pull: 7 }) }, | |
| 15 | forgeUrl: "https://forge.test", | |
| 16 | serving: readServing(db, repo, env), | |
| 17 | }, | |
| 18 | false, | |
| 19 | ).text(); | |
| 20 | ||
| 21 | test("production and a preview each show their own commit, with a time element and title", async () => { | |
| 22 | const at = new Date(Date.now() - 3 * 3600_000).toISOString(); | |
| 23 | put("r", "production", "a".repeat(40), at); | |
| 24 | put("r", "pull-7", "b".repeat(40), at); | |
| 25 | const prod = await page("r", "production"); | |
| 26 | expect(prod).toContain("Version <a"); | |
| 27 | expect(prod).toContain("<code>aaaaaaa</code></a> · deployed <time datetime=\"" + at + "\" title=\"" + new Date(at).toUTCString() + "\">3 h ago</time>"); | |
| 28 | const prev = await page("r", "pull-7"); | |
| 29 | expect(prev).toContain("<code>bbbbbbb</code>"); | |
| 30 | expect(prev).not.toContain("aaaaaaa"); | |
| 31 | }); | |
| 32 | ||
| 33 | test("a never-deployed app shows 'Not deployed yet'", async () => { | |
| 34 | expect(await page("none", "production")).toContain("Not deployed yet"); | |
| 35 | expect(await page("none", "pull-7")).toContain("Not deployed yet"); | |
| 36 | }); | |
| 37 | ||
| 38 | test("relative time words", () => { | |
| 39 | const now = Date.parse("2026-11-20T12:00:00Z"); | |
| 40 | expect(ago("2026-11-20T11:59:50Z", now)).toBe("just now"); | |
| 41 | expect(ago("2026-11-20T11:30:00Z", now)).toBe("30 min ago"); | |
| 42 | expect(ago("2026-11-18T12:00:00Z", now)).toBe("2 d ago"); | |
| 43 | }); |
new above
offline
A preview with no deploy now reads "Not deployed yet" without the pull number. The heading line above still names the pull, so this is fine. Please confirm it on the redeployed preview.