Public: anyone can read this; the crew can change it.

/talk?about= names its subject: one line above the composer, only for what the viewer can read #10497

Parked opened this
Closed without merging

mason/forge:mason/10494-talk-about-names-its-subject-one-line-ab → main 4 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +85 −3
scripts/unreached-allow.json −1
@@ -15,7 +15,6 @@
1515 "src/flow/review_rounds.ts",
1616 "src/flow/shared_red.ts",
1717 "src/flow/stale_fold.ts",
18 "src/kernel/why_now.ts",
1918 "src/spawn/pod.ts",
2019 "src/tui/gallery.ts",
2120 "src/tui/ui/qr.ts",
src/web/pages/talk.ts +33
@@ -38,6 +38,9 @@ import {
3838 type Turn,
3939 } from "../../core/conversations.ts";
4040 import { contextOf, contextText, dollars, turnCosts, type Context } from "../../core/conversation_cost.ts";
41 import { getIssue } from "../../core/issues.ts";
42 import { canRead, getRepo } from "../../core/repos.ts";
43 import { mayViewId } from "../../core/sealed.ts";
4144 import { WORDS_MAX } from "../../core/fence.ts";
4245 import { thinkingOf, worksOf, type Work } from "../../core/talk_work.ts";
4346 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
@@ -70,6 +73,35 @@ const HERE = "/talk";
7073 const FIND_CHARS = 100;
7174 const CONVERSATION_ID = /^[0-9a-z]{1,40}$/;
7275
76 /** What `?about=` names: a repository, and an issue or pull of it when `number` is there. */
77 export interface About {
78 readonly owner: string;
79 readonly repo: string;
80 readonly number?: number;
81 }
82 const ABOUT = /^([A-Za-z0-9][A-Za-z0-9_.-]{0,63})\/([A-Za-z0-9][A-Za-z0-9_.-]{0,63})(?:#([1-9][0-9]{0,8}))?$/;
83
84 /** `owner/repo` or `owner/repo#N` read from the query; null for anything else. Pure: it looks nothing up. */
85 export function parseAbout(text: string | null): About | null {
86 const m = text === null || text.length > 140 ? null : ABOUT.exec(text);
87 if (m === null) return null;
88 return m[3] === undefined ? { owner: m[1]!, repo: m[2]! } : { owner: m[1]!, repo: m[2]!, number: Number(m[3]) };
89 }
90
91 /** The one line naming what the talk is about, or nothing when it is unnamed, unknown or not the viewer's to read: the three look alike. */
92 function aboutLine(ctx: Ctx): Html | null {
93 const about = parseAbout(ctx.url.searchParams.get("about"));
94 if (about === null) return null;
95 const { db } = ctx.app;
96 const repo = getRepo(db, about.owner, about.repo);
97 if (repo === undefined || !canRead(db, repo, ctx.auth.user)) return null;
98 const name = `${about.owner}/${about.repo}`;
99 if (about.number === undefined) return html`<p class="talk-about small muted" data-about>About ${name}</p>`;
100 const issue = getIssue(db, repo.id, about.number);
101 if (issue === undefined || !mayViewId(db, repo, issue.id, ctx.auth.user)) return null;
102 return html`<p class="talk-about small muted" data-about>About ${name}#${about.number}: ${issue.title}</p>`;
103 }
104
73105 /** What a conversation is called in a list: its title, else the day it began. */
74106 const nameOf = (c: Conversation): string => (c.title === "" ? `Chat of ${c.createdAt.slice(0, 10)}` : c.title);
75107 /** Where a conversation lives. */
@@ -316,6 +348,7 @@ function talkPage(ctx: Ctx, conversation: Conversation, before0: string | undefi
316348 </ol>
317349 <div id="end"></div>
318350 </div>
351 ${aboutLine(ctx)}
319352 <form class="talk-compose" id="compose" method="post" action="${editing === undefined ? here : `${here}/again/edit`}" ${editing === undefined ? null : html`data-edit`}>
320353 ${conversation.archivedAt === null ? null : html`<p class="small muted" data-archived-note>Archived: sending here keeps it archived; Restore puts it back in the list.</p>`}
321354 <p class="talk-status small muted" role="status" aria-live="polite">${running ? "The forge is answering…" : ""}</p>
test/child-quota.test.ts +1 −1
@@ -101,7 +101,7 @@ describe("child quota", () => {
101101
102102 test("room for small but not large is refused only for large", async () => {
103103 clear();
104 process.env["FORGE_CHILD_MEMORY_MIB"] = "2000";
104 process.env["FORGE_CHILD_MEMORY_MIB"] = "5000";
105105 expect(quotaRefusal(dir, "small")).toBeUndefined();
106106 expect(quotaRefusal(dir, "large")).toContain("memory limit");
107107 });
test/talk-page.test.ts +51 −1
@@ -12,7 +12,8 @@ import { join } from "node:path";
1212 import { createApp, type App } from "../src/app.ts";
1313 import { createRepo } from "../src/actions/repos.ts";
1414 import { sayNo } from "../src/actions/conversation_confirms.ts";
15 import { clock, STREAMS_MAX } from "../src/web/pages/talk.ts";
15 import { openIssue } from "../src/actions/issues.ts";
16 import { clock, parseAbout, STREAMS_MAX } from "../src/web/pages/talk.ts";
1617 import { appendTurn, listTurns, openConversation } from "../src/core/conversations.ts";
1718 import { hold, waitingFor } from "../src/core/fence.ts";
1819 import { getRepoById } from "../src/core/repos.ts";
@@ -662,3 +663,52 @@ describe("cost and context (#8822)", () => {
662663 expect(calm).not.toContain("A new conversation answers faster");
663664 });
664665 });
666
667 describe("?about= names the subject", () => {
668 const subject = (page: string) => /<p class="talk-about[^>]*>[^<]*<\/p>/.exec(page)?.[0];
669 test("parseAbout reads owner/repo and owner/repo#N, and nothing else", () => {
670 expect(parseAbout("a/b")).toEqual({ owner: "a", repo: "b" });
671 expect(parseAbout("a/b#12")).toEqual({ owner: "a", repo: "b", number: 12 });
672 for (const bad of ["../x", "a/b#x", "a/b#0", "a/b/c", "", "x".repeat(300), "a/b#1 "]) expect(parseAbout(bad)).toBeNull();
673 expect(parseAbout(null)).toBeNull();
674 });
675
676 test("a readable issue shows its title, escaped; a repository shows its name", async () => {
677 const made = await createRepo(app, alice, { name: "about-pub", visibility: "public" });
678 if (!made.ok) throw new Error(String(made.error));
679 const issue = openIssue(app, alice, made.value, { title: "Fix <b>this</b>", body: "x" });
680 if (!issue.ok) throw new Error(String(issue.error));
681 const page = await (await get(`/talk?about=${encodeURIComponent(`alice/about-pub#${issue.value.number}`)}`, bob)).text();
682 expect(subject(page)).toContain(`About alice/about-pub#${issue.value.number}: Fix &lt;b&gt;this&lt;/b&gt;`);
683 expect(page).not.toContain("Fix <b>this</b>");
684 expect(subject(await (await get("/talk?about=alice/about-pub", bob)).text())).toContain("About alice/about-pub<");
685 });
686
687 test("a private repository names nothing for another person, and looks like one that does not exist", async () => {
688 const made = await createRepo(app, alice, { name: "about-priv", visibility: "private" });
689 if (!made.ok) throw new Error(String(made.error));
690 const issue = openIssue(app, alice, made.value, { title: "Secret title", body: "x" });
691 if (!issue.ok) throw new Error(String(issue.error));
692 const q = (v: string) => get(`/talk?about=${encodeURIComponent(v)}`, bob).then((r) => r.text());
693 const hidden = await q(`alice/about-priv#${issue.value.number}`);
694 expect(hidden).not.toContain("Secret title");
695 expect(subject(hidden)).toBeUndefined();
696 expect(hidden).toBe(await q("alice/no-such-repo#1"));
697 expect(await q("alice/about-priv")).toBe(await q("alice/no-such-repo"));
698 // Signed out the page sends to sign-in, which only echoes the asked URL: no repository is looked up.
699 const out = await get("/talk?about=alice/about-priv");
700 expect(out.status).toBe(303);
701 expect(out.headers.get("location")).toBe("/signin?next=%2Ftalk%3Fabout%3Dalice%2Fabout-priv");
702 expect(await out.text()).not.toContain("Secret title");
703 expect(await (await get(`/talk?about=${encodeURIComponent(`alice/about-priv#${issue.value.number}`)}`, alice)).text()).toContain("Secret title");
704 });
705
706 test("a malformed value is ignored: the page equals plain /talk", async () => {
707 const plain = await (await get("/talk", bob)).text();
708 for (const bad of ["../x", "a/b#x", "x".repeat(300)]) {
709 const res = await get(`/talk?about=${encodeURIComponent(bad)}`, bob);
710 expect(res.status).toBe(200);
711 expect(await res.text()).toBe(plain);
712 }
713 });
714 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs