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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/6438-the-forge-door-s-more-pulls-line-says-ho → main 0 commits fork

  • Merged. scout/6438-the-forge-door-s-more-pulls-line-says-ho was merged into main as af22bcd.

Review

Sign in to review this change.
5 files changed +59 −12
src/apps/door.ts +8 −3
@@ -33,9 +33,12 @@ export type DoorFacts = {
3333 report?: string | undefined;
3434 };
3535
36 /** How many pulls the door lists; one more read than this means there are others. */
36 /** How many pulls the door lists. */
3737 export const DOOR_PULL_LIMIT = 5;
3838
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
3942 export type DoorPullLine = { number: number; title: string; check: string; href: string; self?: boolean };
4043
4144 const STYLE =
@@ -106,9 +109,11 @@ function pullsHtml(pulls: DoorPullLine[] | undefined, morePulls: string | undefi
106109 const text = `#${p.number} ${[...p.title].slice(0, 120).join("")} · check ${p.check}`;
107110 return p.self === true ? `<li>${escapeAttr(text)} (this preview)</li>` : link(p.href, text);
108111 });
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"}`;
110115 const more =
111 pulls.length <= DOOR_PULL_LIMIT
116 others <= 0
112117 ? ""
113118 : morePulls === undefined
114119 ? `<p>${words}</p>`
src/apps/proxy.ts +5 −4
@@ -59,7 +59,7 @@ import { crewLine, crewNow, tellLink, yoursLink, yoursWhy } from "./crew.ts";
5959 import { sideOf, type Side } from "./side.ts";
6060 import { feedback, mintProof } from "./feedback.ts";
6161 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";
6363 import { checkWord } from "./check_word.ts";
6464 import { servingWords } from "./serving_words.ts";
6565 import { pillCheck } from "./pill_check.ts";
@@ -521,7 +521,8 @@ function doorSsh(
521521 /**
522522 * The door's open pulls: a preview that is running or asleep links to itself,
523523 * 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.
525526 */
526527 function doorPulls(
527528 runtime: AppsRuntime,
@@ -532,9 +533,9 @@ function doorPulls(
532533 const repo = getRepoById(db, target.app.repoId);
533534 if (repo === undefined) return [];
534535 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) => {
536537 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;
538539 const live =
539540 state !== undefined &&
540541 (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
429429 );
430430 let html = await (await door(`notes.${DOMAIN}`)).text();
431431 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");
433433 for (let i = 0; i < 5; i++) mk(`extra ${i}`);
434434 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>`);
436436 expect((html.match(/ · check /g) ?? []).length).toBe(5);
437437 });
438438
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs