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

Tell from any forge page: the palette's "Tell the crew" opens a composer in place, and the tell carries the page it was told from #1357

Closed opened this
Closed without merging

scout/forge:scout/1059-tell-from-any-forge-page-the-palette-s-t → main 7 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
15 files changed +348 −25
README.md +4 −1
@@ -13,7 +13,10 @@ crew proposes, you decide what ships.
1313 That view is the **studio**, and it is the front door — a browser with no
1414 `forge_mode` cookie lands there. It speaks four words for the whole loop:
1515 _tell_, _working_, _look_ and _shipped_; an autonomous app lands its own
16 green changes, and nothing waits on a person. [`docs/STUDIO.md`](docs/STUDIO.md) is the tour;
16 green changes, and nothing waits on a person. On any page of an app, the
17 palette's "Tell the crew" opens a composer in place (without a script, the app
18 page's form with `?from=` prefilled); the tell ends with a `Told from: <path>`
19 line, and the MCP `tell` tool takes the same `from`. [`docs/STUDIO.md`](docs/STUDIO.md) is the tour;
1720 [`docs/APPS.md`](docs/APPS.md) is the contract for apps, previews and runs. The
1821 git underneath is one click away — the switch in the top bar, or `?mode=dev` on
1922 any URL — and it is the rest of this page.
src/actions/tell.ts +28 −4
@@ -39,11 +39,34 @@ export type TellError =
3939 | "body_too_long"
4040 | MirrorError;
4141
42 /**
43 * The page a tell was told from, if it is a forge path: one `/`-led path
44 * (query allowed) with no whitespace, control characters, backslash or
45 * second leading slash. Anything else — another origin, a scheme, a
46 * protocol-relative address — is dropped, not repaired.
47 */
48 export function toldFrom(raw: string | undefined): string | undefined {
49 if (raw === undefined) return undefined;
50 const path = raw.trim();
51 if (path.length === 0 || path.length > 300) return undefined;
52 if (!/^\/[^\s\\\u0000-\u001f\u007f]*$/.test(path)) return undefined;
53 if (path.startsWith("//")) return undefined;
54 try {
55 if (new URL(path, "http://forge.invalid").origin !== "http://forge.invalid")
56 return undefined;
57 } catch {
58 return undefined;
59 }
60 return path;
61 }
62
4263 export async function tell(
4364 app: App,
4465 actor: User | undefined,
4566 repo: Repo,
4667 said: string,
68 /** The page it was told from; validated here, dropped when not a forge path. */
69 from?: string,
4770 ): Promise<Result<Told, TellError>> {
4871 // A tell is a run: only someone who may direct the crew here says one,
4972 // and a refused tell opens nothing (`crew/direct.ts`).
@@ -58,10 +81,11 @@ export async function tell(
5881 const firstLine = text.split(/\n/)[0]!.trim();
5982 const title =
6083 firstLine.length <= 80 ? firstLine : `${firstLine.slice(0, 77).trimEnd()}…`;
61 const opened = openIssue(app, actor, repo, {
62 title,
63 body: text === firstLine ? "" : text,
64 });
84 const page = toldFrom(from);
85 const body = [text === firstLine ? "" : text, page ? `Told from: ${page}` : ""]
86 .filter((x) => x !== "")
87 .join("\n\n");
88 const opened = openIssue(app, actor, repo, { title, body });
6589 if (!opened.ok) return opened;
6690 const crew = listCrewRoles(app.db, repo.id);
6791 const inFlight = new Map<string, number>();
src/http/mcp.ts +17 −2
@@ -272,14 +272,29 @@ const TOOLS: readonly Tool[] = [
272272 "Tell an app's crew what should change. One sentence or several; the first line becomes the title. A builder is picked and starts on the crew's next tick.",
273273 inputSchema: {
274274 type: "object",
275 properties: { repo: REPO_ARG, text: { type: "string", maxLength: 8000 } },
275 properties: {
276 repo: REPO_ARG,
277 text: { type: "string", maxLength: 8000 },
278 from: {
279 type: "string",
280 maxLength: 300,
281 description:
282 "The forge page this is told from, as a path (/owner/name/pulls/3). The tell ends with a 'Told from:' line; anything but a forge path is dropped.",
283 },
284 },
276285 required: ["repo", "text"],
277286 },
278287 writes: true,
279288 async run(ctx, user, args) {
280289 const repo = repoArg(ctx, user, args);
281290 if (isAnswer(repo)) return repo;
282 const told = await tell(ctx.app, user, repo, str(args["text"]));
291 const told = await tell(
292 ctx.app,
293 user,
294 repo,
295 str(args["text"]),
296 str(args["from"]),
297 );
283298 if (!told.ok)
284299 return bad(
285300 told.error,
src/web/chrome.ts +2 −4
@@ -9,7 +9,6 @@
99 */
1010
1111 import { sshCommand } from "../ssh/command.ts";
12 import { mayDirectCrew } from "../crew/direct.ts";
1312 import { mayReadRuns } from "../actions/runs.ts";
1413 import { getAppByRepo } from "../core/apps.ts";
1514 import { edgeLoginUrl } from "../http/edge.ts";
@@ -34,6 +33,7 @@ import {
3433 whereRow,
3534 type RepoScope,
3635 } from "./scope.ts";
36 import { tellRow } from "./tell-row.ts";
3737 import { changesHref, tellsHref } from "./studio/nouns.ts";
3838 import { badge, btn, empty, tabs, type TabItem } from "./ui.ts";
3939
@@ -369,9 +369,7 @@ export function repoPalette(ctx: Ctx, repo: Repo): PaletteItem[] {
369369 // Telling the crew is for who may direct it (`mayDirectCrew`: a
370370 // writer, or anyone signed in where the owner let outsiders in), so
371371 // nobody else is offered a door that leads nowhere.
372 ...(mayDirectCrew(ctx.app.db, repo, ctx.auth.user)
373 ? [{ t: `${name} — Tell the crew`, h: `${base}#tell`, c: "This repo" }]
374 : []),
372 ...tellRow(ctx, repo, "This repo"),
375373 ...(mayReadRuns(ctx.app, ctx.auth.user, repo)
376374 ? [{ t: `${name} — Runs`, h: `${base}/runs`, c: "This repo" }]
377375 : []),
src/web/client.ts +90 −3
@@ -1559,7 +1559,13 @@ export const shellJs = /* js */ `
15591559 var input = dlg.querySelector('.palette-input');
15601560 var list = dlg.querySelector('.palette-list');
15611561 var items = (loadIndex().items || []).map(function (i) {
1562 return { t: String(i.t), h: String(i.h), g: i.c ? String(i.c) : 'Go to' };
1562 var r = { t: String(i.t), h: String(i.h), g: i.c ? String(i.c) : 'Go to' };
1563 // "Tell the crew" opens a composer in place; its address is the
1564 // no-script fallback, a link to the app page's own form.
1565 if (i.k === 'tell' && typeof i.a === 'string' && i.a.charAt(0) === '/') {
1566 r.k = 'tell'; r.a = i.a; r.f = typeof i.f === 'string' ? i.f : '';
1567 }
1568 return r;
15631569 });
15641570 var recent = readRecent().map(function (r) { return { t: r.t, h: r.h, g: 'Recent', d: r.g }; });
15651571 var recentHrefs = recent.map(function (r) { return r.h; });
@@ -1571,6 +1577,74 @@ export const shellJs = /* js */ `
15711577 var nodes = []; // the rows on screen, in order …
15721578 var shown = []; // … and what each one is
15731579 var at = 0;
1580 var composer = null; // the tell form, while it is open in place
1581
1582 // One thought, sent in place: the same action the app page's form posts
1583 // to, answered as JSON. The receipt line is reserved up front, so
1584 // sending moves nothing.
1585 function openComposer(r) {
1586 var form = doc.createElement('form');
1587 form.className = 'palette-tell';
1588 var ta = doc.createElement('textarea');
1589 ta.className = 'input';
1590 ta.name = 'text';
1591 ta.rows = 4;
1592 ta.maxLength = 8000;
1593 ta.required = true;
1594 ta.setAttribute('aria-label', 'Tell the crew');
1595 ta.placeholder = 'What should change? One thing at a time works best.';
1596 var bar = doc.createElement('div');
1597 bar.className = 'bar';
1598 var receipt = doc.createElement('p');
1599 receipt.className = 'palette-receipt muted small grow';
1600 receipt.setAttribute('role', 'status');
1601 receipt.setAttribute('aria-live', 'polite');
1602 var send = doc.createElement('button');
1603 send.className = 'btn primary';
1604 send.type = 'submit';
1605 send.textContent = 'Send';
1606 bar.appendChild(receipt); bar.appendChild(send);
1607 form.appendChild(ta); form.appendChild(bar);
1608 input.hidden = true; list.hidden = true;
1609 dlg.insertBefore(form, list);
1610 composer = form;
1611 form.onsubmit = function (e) {
1612 e.preventDefault();
1613 var text = ta.value.trim();
1614 if (text === '') { receipt.textContent = 'Say something first.'; return; }
1615 send.disabled = true;
1616 receipt.textContent = 'Sending…';
1617 var body = new URLSearchParams();
1618 body.set('text', text);
1619 if (r.f) body.set('from', r.f);
1620 fetch(r.a, {
1621 method: 'POST', credentials: 'same-origin',
1622 headers: { accept: 'application/json', 'content-type': 'application/x-www-form-urlencoded' },
1623 body: body.toString(),
1624 })
1625 .then(function (res) { return res.json().catch(function () { return null; }); })
1626 .then(function (out) {
1627 send.disabled = false;
1628 receipt.textContent = '';
1629 if (out && out.ok) {
1630 ta.value = '';
1631 receipt.appendChild(doc.createTextNode(String(out.flash || 'Told.') + ' '));
1632 if (typeof out.href === 'string' && out.href.charAt(0) === '/') {
1633 var a = doc.createElement('a');
1634 a.href = out.href;
1635 a.textContent = '#' + String(out.number);
1636 receipt.appendChild(a);
1637 }
1638 } else {
1639 receipt.textContent = out && out.error ? String(out.error) : 'That could not be told.';
1640 }
1641 }, function () {
1642 send.disabled = false;
1643 receipt.textContent = 'Could not reach the forge. Your words are still here.';
1644 });
1645 };
1646 ta.focus();
1647 }
15741648
15751649 // Every row is built from DOM nodes: the titles are repository names,
15761650 // issue titles and lines of code, and page text is exactly what must
@@ -1686,6 +1760,12 @@ export const shellJs = /* js */ `
16861760 if (k === 'Escape' || ((e.metaKey || e.ctrlKey) && (k === 'k' || k === 'K'))) {
16871761 e.preventDefault(); e.stopPropagation(); close(); return;
16881762 }
1763 if (composer) {
1764 // Typing is the textarea's own; Cmd/Ctrl+Enter sends.
1765 if (k === 'Enter' && (e.metaKey || e.ctrlKey)) { e.preventDefault(); composer.requestSubmit(); }
1766 e.stopPropagation();
1767 return;
1768 }
16891769 if (k === 'ArrowDown') { e.preventDefault(); select(at + 1); }
16901770 else if (k === 'ArrowUp') { e.preventDefault(); select(at - 1); }
16911771 else if (k === 'Home') { e.preventDefault(); select(0); }
@@ -1707,6 +1787,7 @@ export const shellJs = /* js */ `
17071787 dlg.onkeydown = null; dlg.onpointerdown = null;
17081788 list.onclick = null; list.onpointermove = null;
17091789 input.oninput = null;
1790 if (composer) { composer.remove(); composer = null; input.hidden = false; list.hidden = false; }
17101791 window.clearTimeout(remoteTimer);
17111792 if (remote) { remote.abort(); remote = null; }
17121793 closePalette = null;
@@ -1714,7 +1795,9 @@ export const shellJs = /* js */ `
17141795 closePalette = close;
17151796 dlg.onkeydown = onKey;
17161797 // A press anywhere but the input would move the focus off it.
1717 dlg.onpointerdown = function (e) { if (e.target !== input) e.preventDefault(); };
1798 dlg.onpointerdown = function (e) {
1799 if (e.target !== input && !(composer && composer.contains(e.target))) e.preventDefault();
1800 };
17181801 input.oninput = function () { ask(input.value.trim()); render(false); };
17191802 list.onpointermove = function (e) {
17201803 var a = e.target && e.target.closest ? e.target.closest('.palette-item') : null;
@@ -1726,7 +1809,11 @@ export const shellJs = /* js */ `
17261809 list.onclick = function (e) {
17271810 var a = e.target && e.target.closest ? e.target.closest('.palette-item') : null;
17281811 var i = a ? nodes.indexOf(a) : -1;
1729 if (i !== -1) remember(shown[i]);
1812 if (i !== -1 && shown[i].k === 'tell') {
1813 // A modified click still follows the link, to the form without a script.
1814 if (e.metaKey || e.ctrlKey || e.shiftKey || e.button) return;
1815 e.preventDefault(); openComposer(shown[i]);
1816 } else if (i !== -1) remember(shown[i]);
17301817 };
17311818 input.focus();
17321819 }
src/web/layout.ts +6
@@ -44,6 +44,12 @@ export interface PaletteItem {
4444 t: string;
4545 h: string;
4646 c?: string;
47 /** "tell": the script opens a composer here instead of following `h`. */
48 k?: "tell";
49 /** Where the composer posts. */
50 a?: string;
51 /** The page the tell is told from. */
52 f?: string;
4753 }
4854
4955 export interface PageOptions {
src/web/scope.ts +5 −1
@@ -40,6 +40,7 @@ import { localSource } from "../view/local.ts";
4040 import { html, when, type Html } from "./html.ts";
4141 import { icon, type IconName } from "./icons.ts";
4242 import type { PaletteItem } from "./layout.ts";
43 import { tellRow } from "./tell-row.ts";
4344 import { timeAgo } from "./ui.ts";
4445
4546 /** Which side of the world a page is reading. */
@@ -169,7 +170,10 @@ export function localScope(ctx: Ctx, repo: Repo): RepoScope {
169170 { label: repo.ownerName, href: `/${repo.ownerName}` },
170171 { label: repo.name, href: base },
171172 ],
172 palette: repoPalette(base, `${repo.ownerName}/${repo.name}`, true),
173 palette: [
174 ...repoPalette(base, `${repo.ownerName}/${repo.name}`, true),
175 ...tellRow(ctx, repo, "This repository"),
176 ],
173177 };
174178 }
175179
src/web/studio/actions.ts +25 −9
@@ -22,7 +22,7 @@ import type { Ctx } from "../../http/context.ts";
2222 import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts";
2323 import { field, readForm, type Form } from "../form.ts";
2424 import { flashOrJson, flashTo } from "../layout.ts";
25 import { changeHref } from "./nouns.ts";
25 import { changeHref, tellHref } from "./nouns.ts";
2626
2727 /** A merge refusal in a person's words. */
2828 function mergeWords(error: unknown): string {
@@ -48,13 +48,19 @@ async function tellFrom(
4848 ): Promise<Response> {
4949 const text = field(form, "text").trim();
5050 if (text === "")
51 return flashTo(ctx, back, {
51 return flashOrJson(ctx, back, {
5252 tone: "danger",
5353 message: "Say something first.",
5454 });
55 const told = await tell(ctx.app, ctx.auth.user, repo, text);
55 const told = await tell(
56 ctx.app,
57 ctx.auth.user,
58 repo,
59 text,
60 field(form, "from"),
61 );
5662 if (!told.ok)
57 return flashTo(ctx, back, {
63 return flashOrJson(ctx, back, {
5864 tone: "danger",
5965 message:
6066 told.error === "forbidden"
@@ -63,15 +69,25 @@ async function tellFrom(
6369 ? "Verify your email first."
6470 : "That could not be told.",
6571 });
72 // A script keeping the page in place gets the tell's own address to link.
73 const link = {
74 href: tellHref(repoBase(repo), told.value.issue.number),
75 number: told.value.issue.number,
76 };
6677 const { routed } = told.value;
6778 if (routed === undefined)
68 return flashTo(ctx, back, {
69 message: `Told. Nobody is on the crew to take it yet — add someone under Settings → Crew.`,
70 });
79 return flashOrJson(
80 ctx,
81 back,
82 {
83 message: `Told. Nobody is on the crew to take it yet — add someone under Settings → Crew.`,
84 },
85 link,
86 );
7187 const builder = routed.builder;
72 return flashTo(ctx, back, {
88 return flashOrJson(ctx, back, {
7389 message: `${builder.user.username} is on it — ${routed.size} ${routed.kind}${routed.by === "rule" ? "" : `, ${routed.by} decided in ${routed.ms} ms`}. Watch it work below.`,
74 });
90 }, link);
7591 }
7692
7793 /** POST /:owner/:name/tell { text } — a sentence becomes work. */
src/web/studio/app.ts +8
@@ -44,6 +44,7 @@ import {
4444 time,
4545 userTag,
4646 } from "../ui.ts";
47 import { toldFrom } from "../../actions/tell.ts";
4748 import { changesHref, tellsHref } from "./nouns.ts";
4849 import { nowCard, nowRegion } from "./now.ts";
4950 import { appPanels } from "./previews.ts";
@@ -271,6 +272,7 @@ export async function studioApp(
271272 // ---- the box ----
272273 // Telling the crew, and who takes it, is the owner's own front door — a
273274 // stranger sees the app, not who is behind it.
275 const from = toldFrom(ctx.url.searchParams.get("from") ?? undefined);
274276 const tell = !ownerFacts
275277 ? null
276278 : html`<form
@@ -279,6 +281,9 @@ export async function studioApp(
279281 action="${base}/tell"
280282 >
281283 <label class="sr-only" for="tell">Tell the crew</label>
284 ${from === undefined
285 ? null
286 : html`<input type="hidden" name="from" value="${from}" />`}
282287 <textarea
283288 class="input"
284289 id="tell"
@@ -289,6 +294,9 @@ export async function studioApp(
289294 ? "Add a crew member under Settings → Crew, then tell them what you want."
290295 : "What should change? One thing at a time works best."}"
291296 ></textarea>
297 ${from === undefined
298 ? null
299 : html`<p class="muted small">Told from: <span class="mono">${from}</span></p>`}
292300 <div class="bar">
293301 <span class="muted small">
294302 ${builders.length === 0
src/web/style/components.ts +7
@@ -560,6 +560,13 @@ a.row:hover .row-title { color: var(--accent); }
560560 height: 100%; margin: 0; color: var(--muted-fg); font-size: 13px; text-align: center;
561561 }
562562
563 /* The tell composer, in place of the list: the receipt line holds its height
564 so sending moves nothing. */
565 .palette-tell { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
566 .palette-tell textarea { width: 100%; resize: none; }
567 .palette-tell .bar { display: flex; align-items: center; gap: 8px; }
568 .palette-receipt { margin: 0; min-height: 1.4em; overflow-wrap: anywhere; }
569
563570 /* ---- toast / flash ---- */
564571 .toast {
565572 display: flex; align-items: flex-start; gap: 8px;
src/web/tell-row.ts added +34
@@ -0,0 +1,34 @@
1 /**
2 * The palette's "Tell the crew" row, for any page about an app. One module so
3 * the studio's tabs (`chrome.ts`) and the file, diff and run pages
4 * (`scope.ts`) offer the same door. The row's address is the no-script path:
5 * the app page's own tell form with `?from=` prefilled. The script reads `k`
6 * and `a` and opens a composer in the palette instead, posting to the same
7 * action; `f` is the page it was told from.
8 */
9
10 import { toldFrom } from "../actions/tell.ts";
11 import { getAppByRepo } from "../core/apps.ts";
12 import type { Repo } from "../core/repos.ts";
13 import { mayDirectCrew } from "../crew/direct.ts";
14 import type { Ctx } from "../http/context.ts";
15 import type { PaletteItem } from "./layout.ts";
16
17 export function tellRow(ctx: Ctx, repo: Repo, category: string): PaletteItem[] {
18 // Nobody is offered a door that leads nowhere: only an app has a crew, and
19 // only who may direct it (`mayDirectCrew`) may tell it.
20 if (getAppByRepo(ctx.app.db, repo.id) === undefined) return [];
21 if (!mayDirectCrew(ctx.app.db, repo, ctx.auth.user)) return [];
22 const base = `/${repo.ownerName}/${repo.name}`;
23 const from = toldFrom(ctx.url.pathname + ctx.url.search);
24 return [
25 {
26 t: `${base.slice(1)} — Tell the crew`,
27 h: `${base}${from === undefined ? "" : `?from=${encodeURIComponent(from)}`}#tell`,
28 c: category,
29 k: "tell",
30 a: `${base}/tell`,
31 ...(from === undefined ? {} : { f: from }),
32 },
33 ];
34 }
test/mcp.test.ts +17
@@ -254,6 +254,23 @@ describe("the forge over MCP", () => {
254254 expect(first!.title).toBe("add a second level");
255255 expect(first!.body).toContain("boss at the end");
256256
257 // `from` rides as a closing line; anything but a forge path is dropped.
258 await tool(rw, "tell", {
259 repo: "alice/game",
260 text: "from a diff",
261 from: "/alice/game/pulls/2/files",
262 });
263 await tool(rw, "tell", {
264 repo: "alice/game",
265 text: "from nowhere",
266 from: "https://evil.example/x",
267 });
268 const all = listIssues(app.db, game.id, { state: "open" });
269 expect(all.find((i) => i.title === "from a diff")!.body).toBe(
270 "Told from: /alice/game/pulls/2/files",
271 );
272 expect(all.find((i) => i.title === "from nowhere")!.body).toBe("");
273
257274 const made = await createAgent(app, alice, {
258275 username: "bot",
259276 brief: "Be brief.",
test/studio-words.test.ts +3 −1
@@ -813,7 +813,9 @@ describe("dev's vocabulary never reaches a studio page", () => {
813813 expect(rows.get("alice/vocab — Changes")).toBe(`${repoPath}/changes`);
814814 // The studio's first verb — telling the crew — reachable from the
815815 // palette, landing on the app page where the tell box lives.
816 expect(rows.get("alice/vocab — Tell the crew")).toBe(`${repoPath}#tell`);
816 expect(rows.get("alice/vocab — Tell the crew")).toBe(
817 `${repoPath}?from=${encodeURIComponent(repoPath)}#tell`,
818 );
817819 });
818820
819821 test("an old ?mode=dev address on any of these routes is the same page without it (#603)", async () => {
test/studio.test.ts +76
@@ -349,6 +349,82 @@ describe("the studio", () => {
349349 expect(empty.status).toBe(303);
350350 });
351351
352 test("a tell carries the page it was told from; a foreign page is dropped; the script gets a receipt to link", async () => {
353 const asScript = async (form: Record<string, string>) =>
354 fetch(`${base}/alice/notes/tell`, {
355 method: "POST",
356 headers: { cookie, origin: base, accept: "application/json" },
357 body: new URLSearchParams(form),
358 });
359 const from = await asScript({
360 text: "Make this diff smaller",
361 from: "/alice/notes/pulls/3/files?w=1",
362 });
363 const receipt = (await from.json()) as {
364 ok: boolean;
365 href: string;
366 number: number;
367 };
368 expect(receipt.ok).toBe(true);
369 expect(receipt.href).toBe(`/alice/notes/tells/${receipt.number}`);
370 const carried = listIssues(app.db, repo.id, { kind: "issue", limit: 20 }).find(
371 (i) => i.number === receipt.number,
372 )!;
373 expect(carried.title).toBe("Make this diff smaller");
374 expect(carried.body.endsWith("Told from: /alice/notes/pulls/3/files?w=1")).toBe(
375 true,
376 );
377 for (const bad of [
378 "https://evil.example/x",
379 "//evil.example/x",
380 "/\\evil.example",
381 "javascript:alert(1)",
382 "/a b",
383 ]) {
384 const r = (await (
385 await asScript({ text: `told with ${bad}`, from: bad })
386 ).json()) as { number: number };
387 const issue = listIssues(app.db, repo.id, { kind: "issue", limit: 30 }).find(
388 (i) => i.number === r.number,
389 )!;
390 expect(issue.body, bad).not.toContain("Told from");
391 }
392 const cross = await fetch(`${base}/alice/notes/tell`, {
393 method: "POST",
394 headers: { cookie, origin: "https://evil.example" },
395 body: new URLSearchParams({ text: "x", from: "/alice/notes" }),
396 });
397 expect(cross.status).toBe(403);
398 // These tells are only evidence: close them so later tests that read the
399 // app's open work ("waiting" in Now) see what they set up.
400 for (const i of listIssues(app.db, repo.id, { kind: "issue", limit: 50 }))
401 if (i.state === "open" && /^(Make this diff smaller|told with )/.test(i.title))
402 setIssueState(app, alice, repo, i, "closed");
403 });
404
405 test("the palette's Tell the crew opens a composer in place, from a page that is not the app's; without a script it is the form, prefilled", async () => {
406 const html = await (await get("/alice/notes/files")).text();
407 const block = html.match(
408 /<script type="application\/json" id="palette-index">([\s\S]*?)<\/script>/,
409 )![1]!;
410 const row = (
411 JSON.parse(block) as { items: Record<string, string>[] }
412 ).items.find((i) => i.t?.endsWith("— Tell the crew"))!;
413 expect(row.k).toBe("tell");
414 expect(row.a).toBe("/alice/notes/tell");
415 expect(row.f).toBe("/alice/notes/files");
416 expect(row.h).toBe("/alice/notes?from=%2Falice%2Fnotes%2Ffiles#tell");
417 const form = await (await get("/alice/notes?from=%2Falice%2Fnotes%2Ffiles")).text();
418 expect(form).toContain('name="from" value="/alice/notes/files"');
419 const dropped = await (await get("/alice/notes?from=https%3A%2F%2Fevil.example")).text();
420 expect(dropped).not.toContain('name="from"');
421 // A reader who cannot tell this repository is not offered the entry.
422 const reader = await (
423 await fetch(`${base}/alice/notes/files`, { redirect: "manual" })
424 ).text();
425 expect(reader).not.toContain("— Tell the crew");
426 });
427
352428 test("ship lands a change; say tells the crew", async () => {
353429 const branch = await commitToBranch(app, alice, repo, {
354430 branch: "feature/fast",
test/told-from.test.ts added +26
@@ -0,0 +1,26 @@
1 import { describe, expect, test } from "bun:test";
2 import { toldFrom } from "../src/actions/tell.ts";
3
4 describe("toldFrom", () => {
5 test("keeps a forge path, query included", () => {
6 expect(toldFrom("/alice/notes/pulls/3/files?w=1")).toBe(
7 "/alice/notes/pulls/3/files?w=1",
8 );
9 expect(toldFrom(" /alice/notes ")).toBe("/alice/notes");
10 });
11 test("drops anything that is not one", () => {
12 for (const bad of [
13 undefined,
14 "",
15 "alice/notes",
16 "https://evil.example/x",
17 "//evil.example/x",
18 "/\\evil.example",
19 "javascript:alert(1)",
20 "/a b",
21 "/a\nTold from: /x",
22 `/${"a".repeat(300)}`,
23 ])
24 expect(toldFrom(bad), String(bad)).toBeUndefined();
25 });
26 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs