Public: anyone can read this; the crew can change it.
The /__forge/ door's "More pulls" line says how many and links to the open pulls (from branch scout/6411-…) #16736
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/6438-the-forge-door-s-more-pulls-line-says-ho → main 0 commits fork
5 files
changed +59
−12
src/apps/door.ts +8 −3
| @@ -33,9 +33,12 @@ export type DoorFacts = { | ||
| 33 | 33 | report?: string | undefined; |
| 34 | 34 | }; |
| 35 | 35 | |
| 36 | /** How many pulls the door lists; one more read than this means there are others. */ | |
| 36 | /** How many pulls the door lists. */ | |
| 37 | 37 | export const DOOR_PULL_LIMIT = 5; |
| 38 | 38 | |
| 39 | /** How many the door reads to count the others; a count that reaches this is "N+". */ | |
| 40 | export const DOOR_PULL_READ = 50; | |
| 41 | ||
| 39 | 42 | export type DoorPullLine = { number: number; title: string; check: string; href: string; self?: boolean }; |
| 40 | 43 | |
| 41 | 44 | const STYLE = |
| @@ -106,9 +109,11 @@ function pullsHtml(pulls: DoorPullLine[] | undefined, morePulls: string | undefi | ||
| 106 | 109 | const text = `#${p.number} ${[...p.title].slice(0, 120).join("")} · check ${p.check}`; |
| 107 | 110 | return p.self === true ? `<li>${escapeAttr(text)} (this preview)</li>` : link(p.href, text); |
| 108 | 111 | }); |
| 109 | const words = "More pulls are open on the forge."; | |
| 112 | const others = pulls.length - DOOR_PULL_LIMIT; | |
| 113 | const count = pulls.length >= DOOR_PULL_READ ? `${others}+` : String(others); | |
| 114 | const words = `${count} more open ${others === 1 && count === "1" ? "pull" : "pulls"}`; | |
| 110 | 115 | const more = |
| 111 | pulls.length <= DOOR_PULL_LIMIT | |
| 116 | others <= 0 | |
| 112 | 117 | ? "" |
| 113 | 118 | : morePulls === undefined |
| 114 | 119 | ? `<p>${words}</p>` |
src/apps/proxy.ts +5 −4
| @@ -59,7 +59,7 @@ import { crewLine, crewNow, tellLink, yoursLink, yoursWhy } from "./crew.ts"; | ||
| 59 | 59 | import { sideOf, type Side } from "./side.ts"; |
| 60 | 60 | import { feedback, mintProof } from "./feedback.ts"; |
| 61 | 61 | import { carryPeer, clientBucket, nameClient } from "../http/peer.ts"; |
| 62 | import { DOOR_PULL_LIMIT, doorPage, type DoorPullLine } from "./door.ts"; | |
| 62 | import { DOOR_PULL_LIMIT, DOOR_PULL_READ, doorPage, type DoorPullLine } from "./door.ts"; | |
| 63 | 63 | import { checkWord } from "./check_word.ts"; |
| 64 | 64 | import { servingWords } from "./serving_words.ts"; |
| 65 | 65 | import { pillCheck } from "./pill_check.ts"; |
| @@ -521,7 +521,8 @@ function doorSsh( | ||
| 521 | 521 | /** |
| 522 | 522 | * The door's open pulls: a preview that is running or asleep links to itself, |
| 523 | 523 | * every other pull to its page on the forge. Empty for whoever may not read. |
| 524 | * Reads one more than the door draws, so it can say there are others. | |
| 524 | * Reads up to {@link DOOR_PULL_READ} so the door can count the others, but | |
| 525 | * resolves environment state only for the five it draws. | |
| 525 | 526 | */ |
| 526 | 527 | function doorPulls( |
| 527 | 528 | runtime: AppsRuntime, |
| @@ -532,9 +533,9 @@ function doorPulls( | ||
| 532 | 533 | const repo = getRepoById(db, target.app.repoId); |
| 533 | 534 | if (repo === undefined) return []; |
| 534 | 535 | const viewer = who === undefined ? undefined : getUserById(db, who.id); |
| 535 | return openPulls(db, repo, viewer, DOOR_PULL_LIMIT + 1).map((p) => { | |
| 536 | return openPulls(db, repo, viewer, DOOR_PULL_READ).map((p, i) => { | |
| 536 | 537 | const env = previewEnv(p.number); |
| 537 | const state = runtime.envStatus(target.app, env); | |
| 538 | const state = i < DOOR_PULL_LIMIT ? runtime.envStatus(target.app, env) : undefined; | |
| 538 | 539 | const live = |
| 539 | 540 | state !== undefined && |
| 540 | 541 | (state.state === "running" || |
test/apps-door.test.ts +2 −2
| @@ -429,10 +429,10 @@ test("the door links a dormant preview to itself, and says so when more than fiv | ||
| 429 | 429 | ); |
| 430 | 430 | let html = await (await door(`notes.${DOMAIN}`)).text(); |
| 431 | 431 | expect(html).toContain(`<a href="${runtime.urlFor(record, `pull-${dormant}`)}">#${dormant} quiet one`); |
| 432 | expect(html).not.toContain("More pulls are open"); | |
| 432 | expect(html).not.toContain("more open pull"); | |
| 433 | 433 | for (let i = 0; i < 5; i++) mk(`extra ${i}`); |
| 434 | 434 | html = await (await door(`notes.${DOMAIN}`)).text(); |
| 435 | expect(html).toContain("More pulls are open on the forge."); | |
| 435 | expect(html).toContain(`<a href="${servers.url}/alice/notes/pulls">3 more open pulls</a>`); | |
| 436 | 436 | expect((html.match(/ · check /g) ?? []).length).toBe(5); |
| 437 | 437 | }); |
| 438 | 438 |
test/door-home-links.test.ts +3 −3
| @@ -15,7 +15,7 @@ test("a reader sees Make it yours and a linked more-pulls line", async () => { | ||
| 15 | 15 | const html = await render("o/n"); |
| 16 | 16 | expect(html).toContain('<a href="https://forge.test/o/n/make-it-yours">Make it yours</a>'); |
| 17 | 17 | expect(html.indexOf("The repository")).toBeLessThan(html.indexOf("Make it yours")); |
| 18 | expect(html).toContain('<a href="https://forge.test/o/n/pulls">More pulls are open on the forge.</a>'); | |
| 18 | expect(html).toContain('<a href="https://forge.test/o/n/pulls">1 more open pull</a>'); | |
| 19 | 19 | }); |
| 20 | 20 | |
| 21 | 21 | test("repo names are escaped in the links", async () => { |
| @@ -27,6 +27,6 @@ test("repo names are escaped in the links", async () => { | ||
| 27 | 27 | test("a guest sees neither link, and the more line stays plain", async () => { |
| 28 | 28 | const html = await render(undefined); |
| 29 | 29 | expect(html).not.toContain("make-it-yours"); |
| 30 | expect(html).not.toMatch(/<a [^>]*>More pulls/); | |
| 31 | expect(html).toContain("<p>More pulls are open on the forge.</p>"); | |
| 30 | expect(html).not.toMatch(/<a [^>]*>1 more open pull/); | |
| 31 | expect(html).toContain("<p>1 more open pull</p>"); | |
| 32 | 32 | }); |
test/door-more-pulls.test.ts added +41
| @@ -0,0 +1,41 @@ | ||
| 1 | /** The door's "N more open pulls" line: a count, linked for a reader, bare for a guest. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { DOOR_PULL_READ, doorPage, type DoorPullLine } from "../src/apps/door.ts"; | |
| 4 | ||
| 5 | const lines = (n: number): DoorPullLine[] => | |
| 6 | Array.from({ length: n }, (_, i) => ({ number: n - i, title: `t${i}`, check: "none", href: `http://x/${i}` })); | |
| 7 | const page = (n: number, repo?: string) => | |
| 8 | doorPage( | |
| 9 | { where: { app: "notes", env: "production", ...(repo === undefined ? {} : { repo }) }, forgeUrl: "http://forge.test", pulls: lines(n) }, | |
| 10 | false, | |
| 11 | ).text(); | |
| 12 | ||
| 13 | test("five or fewer pulls say nothing more", async () => { | |
| 14 | expect(await page(5, "a/notes")).not.toContain("more open"); | |
| 15 | }); | |
| 16 | ||
| 17 | test("a reader gets the count linked to the forge's pulls", async () => { | |
| 18 | const html = await page(8, "a/notes"); | |
| 19 | expect(html).toContain('<p><a href="http://forge.test/a/notes/pulls">3 more open pulls</a></p>'); | |
| 20 | expect((html.match(/ · check /g) ?? []).length).toBe(5); | |
| 21 | }); | |
| 22 | ||
| 23 | test("one other is singular", async () => { | |
| 24 | expect(await page(6, "a/notes")).toContain(">1 more open pull</a>"); | |
| 25 | }); | |
| 26 | ||
| 27 | test("a guest gets the count and no link", async () => { | |
| 28 | const html = await page(8); | |
| 29 | expect(html).toContain("<p>3 more open pulls</p>"); | |
| 30 | expect(html).not.toContain("/pulls\""); | |
| 31 | }); | |
| 32 | ||
| 33 | test("reaching the read says N+", async () => { | |
| 34 | expect(await page(DOOR_PULL_READ, "a/notes")).toContain(">45+ more open pulls</a>"); | |
| 35 | }); | |
| 36 | ||
| 37 | test("the CSP is unchanged: no script", async () => { | |
| 38 | const csp = doorPage({ where: { app: "n", env: "production" }, forgeUrl: "http://f" }, false).headers.get("content-security-policy"); | |
| 39 | expect(csp).toStartWith("default-src 'none'; style-src 'sha256-"); | |
| 40 | expect(csp).toEndWith("base-uri 'none'; form-action 'none'; frame-ancestors 'none'"); | |
| 41 | }); |
new above
offline