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

A tell sent from a preview or an app's toolbar carries the page address and the pull it previews into the issue it opens #15671

Merged opened this

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

Merged

mason/forge:mason/15638-a-tell-sent-from-a-preview-or-an-app-s-t → main 0 commits fork 2 threads · 2 unresolved

  • Merged. mason/15638-a-tell-sent-from-a-preview-or-an-app-s-t was merged into main as 3d1b3c1.

Review

Sign in to review this change.
10 files changed +54 −32
docs/features/tell-context-app.md +1 −1
@@ -9,5 +9,5 @@ A tell can say where it was told from. `context.page` is the address (the url) a
99 - MCP: `tell` takes `context: { page?, app?, pull?, run?, commit?, said? }`. A malformed `app` (not a slug) refuses the whole call.
1010 - Terminal: `:` then "Tell the crew from a page" asks for the page, the pull, the app (empty to skip), then the line. The app is checked by the same `parseContext`.
1111 - A door that knows the app itself (the web toolbar passes the repository's name) wins over `context.app`.
12 - With a pull and a page the body says one `from preview of #N` line in place of the page, pull and app lines.
12 - With a pull and a page the body says one `From: <app> /x (preview of #N)` line, last in the block, in place of the page, pull and app lines.
1313 - Code: `src/actions/tell_context.ts`, `src/tui/screens/tell.ts`; tests in `test/tell-context.test.ts`, `test/mcp-tell.test.ts`, `test/tui-tell.test.ts`.
docs/features/toolbar-tell.md +2 −2
@@ -5,8 +5,8 @@ row: A tell from a preview's toolbar carries its pull
55 # A tell from a preview's toolbar carries its pull
66
77 A tell sent from the forge toolbar of an app or a preview arrives with where it was said.
8 On a preview the issue's "Where this was told from" block opens with one line,
9 `from preview of #N, page /x`, in place of the plain page and pull lines.
8 On a preview the issue's "Where this was told from" block ends with one line,
9 `From: <app> /x (preview of #N)`, in place of the plain page and pull lines.
1010
1111 - **Which doors say it.** The toolbar's tell form (`tellFromPage`, `src/web/studio/actions.ts`)
1212 and the terminal's "Tell the crew from a page" (`src/tui/screens/tell.ts`), both of which ask for
src/actions/tell_context.ts +7 −7
@@ -147,17 +147,16 @@ export function parseContext(v: unknown): TellContext | undefined | null {
147147 /**
148148 * The block appended to a tell; empty when there is nothing to say. `preview`
149149 * is said only by a door that asked for a preview's pull (the forge toolbar,
150 * the terminal's "from a page"); then one line, "from preview of #N, page
151 * /x", takes the place of the page and pull lines. Any other door (MCP, API)
152 * keeps the plain page and pull, so no door claims a preview it did not see.
150 * the terminal's "from a page"); then one closing line, "From: <app> /x
151 * (preview of #N)", takes the place of the page and pull lines. Any other
outdated

This comment line runs past the wrap width; rewrap it with the gate.

152 * door (MCP, API) keeps the plain page and pull, so no door claims a
153 * preview it did not see.
153154 */
154155 export function contextNote(c: TellContext | undefined, opts: { preview?: boolean; app?: string } = {}): string {
155156 if (c === undefined) return "";
156157 const app = opts.app ?? c.app;
157158 const preview = opts.preview === true ? previewLine(c.pull, c.page, app) : "";
158159 const lines = [
159 preview !== "" ? `- ${preview}` : "",
160 preview === "" ? fromLine(c.page, opts.app) : "",
161160 preview !== "" || c.page === undefined ? "" : `- page: ${c.page}`,
162161 preview !== "" || c.pull === undefined ? "" : `- pull: #${c.pull}`,
163162 preview !== "" || app === undefined || !APP_SLUG.test(app)
@@ -168,12 +167,13 @@ export function contextNote(c: TellContext | undefined, opts: { preview?: boolea
168167 c.said === undefined || c.said === ""
169168 ? ""
170169 : `- their words: ${c.said.replace(/\s*\n\s*/g, " ")}`,
170 preview === "" ? fromLine(c.page, opts.app) : preview,
171171 ].filter((l) => l !== "");
172172 return lines.length === 0 ? "" : `\n\n---\nWhere this was told from:\n${lines.join("\n")}`;
173173 }
174174
175175 /**
176 * "- from <app> <path>": the app and the path of the page a tell was said on; empty unless both
176 * "From: <app> <path>": the app and the path of the page a tell was said on; empty unless both
177177 * check.
178178 */
179179 function fromLine(page: string | undefined, app: string | undefined): string {
@@ -184,5 +184,5 @@ function fromLine(page: string | undefined, app: string | undefined): string {
184184 /[\\\s\x00-\x1f\x7f<>()\[\]`"'*_~|!#&]/g,
185185 (ch) => `%${ch.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`,
186186 );
187 return parseFrom(path) === path ? `- from ${app} ${path}` : "";
187 return parseFrom(path) === path ? `From: ${app} ${path}` : "";
188188 }
src/actions/tell_from.ts +3 −3
@@ -48,7 +48,7 @@ export const APP_SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
4848
4949 /**
5050 * The plain line a tell from a preview's toolbar opens its issue with:
51 * "from preview of #N, page /x". The path is only the path of the page the
51 * "From: <app> /x (preview of #N)". The path is only the path of the page the
5252 * person was on (never its host, query or fragment), with every character
5353 * `parseFrom` refuses percent-encoded, so it cannot become markup. It is
5454 * context for a reader, never authority: nothing is granted by it.
@@ -67,6 +67,6 @@ export function previewLine(
6767 (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`,
6868 );
6969 if (parseFrom(path) !== path) return "";
70 const named = app !== undefined && APP_SLUG.test(app) ? `, app ${app}` : "";
71 return `from preview of #${pull}, page ${path}${named}`;
70 const named = app !== undefined && APP_SLUG.test(app) ? `${app} ` : "";
71 return `From: ${named}${path} (preview of #${pull})`;
7272 }
test/apps-toolbar-context.test.ts +28 −6
@@ -1,11 +1,11 @@
11 import { describe, expect, test } from "bun:test";
2 import { contextNote } from "../src/actions/tell_context.ts";
2 import { contextNote, parseContext } from "../src/actions/tell_context.ts";
33 import { previewLine } from "../src/actions/tell_from.ts";
44
55 describe("a tell's context line names the app", () => {
66 test("a preview line carries app, path and pull", () => {
77 expect(previewLine(3, "https://n.apps.test/b?q=1", "notes")).toBe(
8 "from preview of #3, page /b, app notes",
8 "From: notes /b (preview of #3)",
99 );
1010 });
1111 test("production keeps its page and names the app on its own line", () => {
@@ -20,15 +20,37 @@ describe("a tell's context line names the app", () => {
2020 );
2121 expect(n).not.toContain("app a");
2222 expect(n).not.toContain("app:");
23 expect(n.split("\n").find((l) => l.startsWith("- from"))!).not.toMatch(/[()\[\]*<>]/);
23 expect(n.split("\n").find((l) => l.startsWith("From:"))!.replace(" (preview of #3)", "")).not.toMatch(/[()\[\]*<>]/);
2424 });
2525 test("production's page says 'from <app> <path>', without query or host", () => {
2626 const n = contextNote({ page: "https://n.apps.test/a/b?x=1" }, { preview: true, app: "notes" });
27 expect(n).toContain("- from notes /a/b\n");
27 expect(n).toContain("From: notes /a/b");
2828 });
2929 test("a hostile path or app is encoded or dropped from the from line", () => {
3030 const bad = contextNote({ page: "https://n.apps.test/x)[e](http://e.test)*<b>" }, { preview: true, app: "notes" });
31 expect(bad.split("\n").find((l) => l.startsWith("- from "))!).not.toMatch(/[()\[\]*<>]/);
32 expect(contextNote({ page: "https://n.apps.test/a" }, { preview: true, app: "a](x)" })).not.toContain("- from ");
31 expect(bad.split("\n").find((l) => l.startsWith("From: "))!.replace(" (preview of #3)", "")).not.toMatch(/[()\[\]*<>]/);
32 expect(contextNote({ page: "https://n.apps.test/a" }, { preview: true, app: "a](x)" })).not.toContain("From: ");
outdated

not.toContain("- from ") is vacuous now. Assert not.toContain("From: ") for the bad app slug.

33 });
34 test("a production tell with a hostile or off-origin page says no From line", () => {
35 for (const page of ["javascript:alert(1)", "//evil.test/x", "/relative", "ftp://e.test/x"]) {
36 expect(parseContext({ page })).toBeNull();
37 }
38 const hostile = parseContext({ page: "https://n.apps.test/x\\y" }) ?? undefined;
39 const n = contextNote(hostile, { preview: true, app: "notes" });
40 expect(n).not.toContain("From: notes /x\\");
41 expect(n).not.toMatch(/\\\\/);
42 });
43 test("the From line is the last line when run, commit and their words exist", () => {
44 const c = { page: "https://n.apps.test/a", pull: 3, run: "r1", commit: "abc1234", said: "make it bigger" };
45 for (const body of [
46 contextNote(c, { preview: true, app: "notes" }),
47 contextNote({ page: c.page, run: c.run, commit: c.commit, said: c.said }, { preview: true, app: "notes" }),
48 ]) {
49 const lines = body.split("\n");
50 expect(lines.at(-1)!.startsWith("From: notes /a")).toBe(true);
51 expect(body).toContain("- run: r1");
52 expect(body).toContain("- commit: abc1234");
53 expect(body).toContain("- their words: make it bigger");
54 }
3355 });
3456 });
test/apps-toolbar-tell.test.ts +5 −5
@@ -170,7 +170,7 @@ describe("tell the crew from the pill", () => {
170170 });
171171 expect(res.status).toBe(200);
172172 const issue = listIssues(app.db, repoId, {}).find((i) => i.title === "Bigger button")!;
173 expect(issue.body).toContain("- from preview of #3, page /b, app notes");
173 expect(issue.body).toContain("From: notes /b (preview of #3)");
174174 expect(issue.body).not.toContain("- page:");
175175 expect(issue.body).not.toContain("- pull:");
176176 });
@@ -183,7 +183,7 @@ describe("tell the crew from the pill", () => {
183183 });
184184 expect(res.status).toBe(200);
185185 const issue = listIssues(app.db, repoId, {}).find((i) => i.title === "Hostile path")!;
186 const line = issue.body.split("\n").find((l) => l.startsWith("- from preview"))!;
186 const line = issue.body.split("\n").find((l) => l.startsWith("From:"))!.replace(" (preview of #3)", "");
187187 expect(line).not.toMatch(/[()\[\]*<>]/);
188188 });
189189
@@ -195,16 +195,16 @@ describe("tell the crew from the pill", () => {
195195 expect(flash).toContain("It was sent without where it was told from.");
196196 expect((await post({ text: "Dropped pull", page: "https://notes.apps.test/k", pull: "3; drop" })).status).toBe(200);
197197 const b = listIssues(app.db, repoId, {}).find((i) => i.title === "Dropped pull")!;
198 expect(b.body).toContain("- from notes /k");
198 expect(b.body).toContain("From: notes /k");
199199 expect(b.body).toBe(
200 "---\nWhere this was told from:\n- from notes /k\n- page: https://notes.apps.test/k\n- app: notes",
200 "---\nWhere this was told from:\n- page: https://notes.apps.test/k\n- app: notes\nFrom: notes /k",
201201 );
202202 });
203203
204204 test("a tell from production stores 'from <app> <path>'", async () => {
205205 await post({ text: "Carried", page: "https://notes.apps.test/deep/page?q=1" });
206206 const i = listIssues(app.db, repoId, {}).find((x) => x.title === "Carried")!;
207 expect(i.body).toContain("- from notes /deep/page\n");
207 expect(i.body).toContain("From: notes /deep/page");
208208 });
209209
210210 test("a refused tell sends the person back with their words, the page and the pull kept", async () => {
test/tell-context.test.ts +2 −2
@@ -16,11 +16,11 @@ test("a page without a fragment is kept as it was", () => {
1616 test("only a door that asked for a preview's pull says 'from preview'", () => {
1717 const where = parseContext({ page: "https://n.apps.test/a?x=1", pull: 7 }) ?? undefined;
1818 const plain = contextNote(where);
19 expect(plain).not.toContain("from preview");
19 expect(plain).not.toContain("(preview of");
2020 expect(plain).toContain("- page: https://n.apps.test/a?x=1");
2121 expect(plain).toContain("- pull: #7");
2222 const said = contextNote(where, { preview: true });
23 expect(said).toContain("- from preview of #7, page /a");
23 expect(said).toContain("From: /a (preview of #7)");
2424 expect(said).not.toContain("- page:");
2525 expect(said).not.toContain("- pull:");
2626 // A preview with no pull is no preview.
test/tell_from.test.ts +3 −3
@@ -180,7 +180,7 @@ describe("tell from a page, through the box", () => {
180180
181181 describe("previewLine", () => {
182182 test("says the pull and the path, nothing else", () => {
183 expect(previewLine(7, "https://n-pull-7.apps.test/a/b?token=x#h")).toBe("from preview of #7, page /a/b");
183 expect(previewLine(7, "https://n-pull-7.apps.test/a/b?token=x#h")).toBe("From: /a/b (preview of #7)");
184184 });
185185 test("no pull or no page is no line", () => {
186186 expect(previewLine(undefined, "https://a.test/")).toBe("");
@@ -189,8 +189,8 @@ describe("previewLine", () => {
189189 });
190190 test("a hostile path cannot carry markup", () => {
191191 const l = previewLine(3, "https://a.test/x)[y](http://e.test)*_`<i>");
192 expect(l).not.toMatch(/[()\[\]*`<>]/);
193 expect(l.startsWith("from preview of #3, page /x%29")).toBe(true);
192 expect(l.replace(" (preview of #3)", "")).not.toMatch(/[()\[\]*`<>]/);
193 expect(l.startsWith("From: /x%29")).toBe(true);
194194 });
195195 test("a hostile from value is refused", () => {
196196 expect(parseFrom("//evil.test")).toBeUndefined();
test/toolbar-actions.test.ts +1 −1
@@ -282,7 +282,7 @@ describe("toolbar actions", () => {
282282 pull: String(pullNumber),
283283 });
284284 const two = listIssues(app.db, repoId, {}).find((i) => i.title === "Page tell preview")!;
285 expect(two.body).toContain(`- from preview of #${pullNumber}, page /b`);
285 expect(two.body).toContain(`From: notes /b (preview of #${pullNumber})`);
286286 expect(two.body).not.toContain("- pull:");
287287 });
288288
test/tui-tell.test.ts +2 −2
@@ -94,7 +94,7 @@ describe("tell the crew in the terminal", () => {
9494 const text = await palette(alice, keys);
9595 expect(text).toContain("Nobody is on the crew to take it yet");
9696 const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "move the button")!;
97 expect(issue.body).toContain("- from preview of #7, page /a");
97 expect(issue.body).toContain("From: lobby /a (preview of #7)");
9898 expect(await palette(bob, [":", "from a page"])).not.toContain("Tell the crew from a page");
9999 });
100100
@@ -123,7 +123,7 @@ describe("tell the crew in the terminal", () => {
123123 expect(text).toContain("It was sent without");
124124 const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "bad pull tell")!;
125125 expect(issue.body).toBe(
126 "---\nWhere this was told from:\n- from lobby /k\n- page: https://notes.apps.test/k\n- app: lobby",
126 "---\nWhere this was told from:\n- page: https://notes.apps.test/k\n- app: lobby\nFrom: lobby /k",
127127 );
128128 });
129129

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs