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

A tell longer than the limit is refused at the boundary with the limit named #15116

Merged opened this

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

Merged

scout/forge:scout/15109-a-tell-longer-than-the-limit-is-refused → main 11 commits fork 7 threads · 7 unresolved

  • Merged. scout/15109-a-tell-longer-than-the-limit-is-refused was merged into main as c407bfb.

Review

Sign in to review this change.
20 files changed +178 −71
src/actions/first_ask.ts +3 −4
@@ -21,11 +21,10 @@ import { newAppFromSentence, NEW_APP_ERRORS } from "./apps.ts";
2121 import { getRepoById } from "../core/repos.ts";
2222 import { seatFirstAskCrew } from "../spawn/starter_crew.ts";
2323 import { FORGE_REPO_WORDS, NOT_TOLD_WORDS, SAY_SOMETHING_WORDS } from "./tell_words.ts";
24 import { FROM_WORDS, TOO_LONG_WORDS, tell, type TellError, type Told } from "./tell.ts";
25 import { parseFrom } from "./tell_from.ts";
24 import { FROM_WORDS, tell, type TellError, type Told } from "./tell.ts";
25 import { overTellLimit, parseFrom, tellTooLongWords } from "./tell_from.ts";
2626 import { deriveAppName } from "../web/pages/apps-name.ts";
2727 import { requireVerified } from "./verify.ts";
28 import { MAX_BODY } from "../core/issues.ts";
2928 import { recordRefusal } from "../core/first_ask_refusals.ts";
outdated

Second import from ./tell_from.ts: parseFrom is already imported from it a line above. Merge them into one import.

3029 import { DIRECTION_NOTE } from "../crew/direct.ts";
3130
@@ -67,7 +66,7 @@ export async function firstAsk(
6766 // Everything the tell could refuse is asked before the app exists, so a
6867 // refused ask leaves nothing behind and a retry makes no second app. The
6968 // new app's owner is the actor, who may direct the crew on it.
70 if (text.length > MAX_BODY) return refuse(TOO_LONG_WORDS);
69 if (overTellLimit(text)) return refuse(tellTooLongWords(text));
7170 if (actor === undefined || actor.kind === "org") return refuse(DIRECTION_NOTE);
7271 if (!requireVerified(app, actor).ok) return refuse("Verify your email first.");
7372 if (from !== null && typeof parseFrom(from) !== "string") return refuse(FROM_WORDS);
src/actions/tell.ts +6 −7
@@ -8,7 +8,7 @@
88
99 import type { App } from "../app.ts";
1010 import { listCrewRoles } from "../core/agents.ts";
11 import { MAX_BODY, type Issue, type TitleError } from "../core/issues.ts";
11 import { type Issue, type TitleError } from "../core/issues.ts";
1212 import type { Repo } from "../core/repos.ts";
1313 import { listRuns } from "../core/runs.ts";
1414 import type { User } from "../core/users.ts";
@@ -17,7 +17,7 @@ import { routeIssue, type Routed } from "../crew/route.ts";
1717 import { err, ok, type Result } from "../kernel/result.ts";
1818 import { requireParticipant } from "./access.ts";
1919 import { assignIssue, openIssue, type MirrorError } from "./issues.ts";
20 import { parseFrom, TELL_LIMIT_WORDS } from "./tell_from.ts";
20 import { overTellLimit, parseFrom } from "./tell_from.ts";
2121 import { requireVerified } from "./verify.ts";
2222 import { VERIFY_FIRST } from "./verify_words.ts";
2323
@@ -98,8 +98,10 @@ export async function tell(
9898 if (!requireVerified(app, participant.value).ok) return err("unverified");
9999 const text = said.trim();
100100 if (text === "") return err("empty");
101 // One long line becomes only a title, so the body cap never sees it.
102 if (text.length > MAX_BODY) return err("body_too_long");
101 // One long line becomes only a title, so the body cap never sees it. The
102 // tell limit (4,000) is under the body cap, so this narrows `tell()` for
outdated

text.length > MAX_BODY (65,536) can never be true once overTellLimit (4,000) is false, so this is dead code. Keep only overTellLimit(text), and drop the MAX_BODY import if nothing else uses it. Also say in the comment that this now narrows tell() for every caller.

103 // every caller.
outdated

Non-blocking: this comment line passes 100 columns; wrap it.

104 if (overTellLimit(text)) return err("body_too_long");
103105 if (from !== null && !(fromApp && APP_ADDRESS.test(from))) {
104106 const path = parseFrom(from);
105107 if (typeof path !== "string") return err("bad_from");
@@ -162,9 +164,6 @@ export async function tell(
162164 /** What every door says when a tell is refused for an unverified address. */
163165 export const UNVERIFIED_WORDS = VERIFY_FIRST;
164166
165 /** What both doors say when `tell` refuses a text over `TELL_TEXT_MAX`. */
166 export const TOO_LONG_WORDS = TELL_LIMIT_WORDS;
167
168167 /** What happened, in the sentence both doors say. */
169168 export function toldWords(told: Told): string {
170169 if (told.routed === undefined)
src/actions/tell_answer.ts +11 −13
@@ -3,7 +3,8 @@
33 * (shared by the terminal screen and the ssh `tell` command).
44 */
55
6 import { toldWords, TOO_LONG_WORDS, UNVERIFIED_WORDS, type Told, type TellError } from "./tell.ts";
6 import { toldWords, UNVERIFIED_WORDS, type Told, type TellError } from "./tell.ts";
7 import { tellTooLongWords } from "./tell_from.ts";
78 import { NOT_TOLD_WORDS, SAY_SOMETHING_WORDS } from "./tell_words.ts";
89 import { DIRECTION_NOTE } from "../crew/direct.ts";
910 import type { Result } from "../kernel/result.ts";
@@ -11,19 +12,16 @@ import type { Result } from "../kernel/result.ts";
1112 const SENTENCE_UNVERIFIED = `${UNVERIFIED_WORDS[0]!.toUpperCase()}${UNVERIFIED_WORDS.slice(1)}.`;
1213
1314 /** The words for a refused tell: one sentence at the feed composer, the terminal and the MCP. */
14 export function refusalWords(error: TellError): string {
15 return error === "forbidden"
16 ? DIRECTION_NOTE
17 : error === "unverified"
18 ? SENTENCE_UNVERIFIED
19 : error === "body_too_long"
20 ? TOO_LONG_WORDS
21 : error === "empty"
22 ? SAY_SOMETHING_WORDS
23 : NOT_TOLD_WORDS;
15 export function refusalWords(error: TellError, said: string): string {
16 if (error === "forbidden") return DIRECTION_NOTE;
17 if (error === "unverified") return SENTENCE_UNVERIFIED;
18 if (error === "body_too_long") return tellTooLongWords(said);
19 if (error === "empty") return SAY_SOMETHING_WORDS;
20 return NOT_TOLD_WORDS;
2421 }
outdated

The nested ternary is getting hard to read, and the optional said lets a caller drop the length without noticing; share_tell and tell_here already do. Make said required for the too-long case, or pass it from every caller. Use an if chain or a small lookup instead of the ternary.

2522
26 export function tellAnswer(told: Result<Told, TellError>): { text: string; tone: "success" | "danger" } {
23 /** `said` (the words as sent) is required: a too-long refusal names their length. */
24 export function tellAnswer(told: Result<Told, TellError>, said: string): { text: string; tone: "success" | "danger" } {
2725 if (told.ok) return { tone: told.value.routed === undefined || told.value.assigned ? "success" : "danger", text: toldWords(told.value) };
28 return { tone: "danger", text: refusalWords(told.error) };
26 return { tone: "danger", text: refusalWords(told.error, said) };
2927 }
src/actions/tell_from.ts +4
@@ -14,6 +14,10 @@ export const TELL_LIMIT_WORDS = "One thought, at most 4,000 characters.";
1414 /** What a refused tell is told to do about it. */
1515 export const TELL_LIMIT_HINT = "Shorten it to 4,000 characters or fewer, or send the rest as a second tell.";
1616
17 /** The refusal for words over the limit: the limit and how long these were. */
18 export const tellTooLongWords = (text: string): string =>
19 `${TELL_LIMIT_WORDS} These are ${text.length.toLocaleString("en-US")}.`;
20
1721 /** Whether these words are over the limit (UTF-16 characters, as `maxlength` counts). */
1822 export const overTellLimit = (text: string): boolean => text.length > TELL_TEXT_MAX;
1923
src/http/feed.ts +2 −2
@@ -13,7 +13,7 @@ import {
1313 UNVERIFIED_WORDS,
1414 VARIANTS_MAX,
1515 } from "../actions/tell.ts";
16 import { overTellLimit, parseFrom, TELL_LIMIT_HINT, TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../actions/tell_from.ts";
16 import { overTellLimit, parseFrom, TELL_LIMIT_HINT, tellTooLongWords, TELL_TEXT_MAX } from "../actions/tell_from.ts";
1717 import { DIRECTION_NOTE } from "../crew/direct.ts";
1818 import { readInteraction } from "../feed/interact.ts";
1919 import { LEDGER_PAGE, likeLedger, parseLedgerBefore, setLike } from "../feed/likes.ts";
@@ -313,7 +313,7 @@ export function feedRoutes(router: Router<Handler>): void {
313313 const viewer = ctx.auth.user!;
314314 const input = await body(ctx.request);
315315 const text = str(input.text).trim();
316 if (overTellLimit(text)) return apiError("invalid_text", 422, TELL_LIMIT_WORDS, TELL_LIMIT_HINT);
316 if (overTellLimit(text)) return apiError("invalid_text", 422, tellTooLongWords(text), TELL_LIMIT_HINT);
317317 if (text === "") return apiError("invalid_text", 422, `text is 1 to ${TELL_TEXT_MAX.toLocaleString("en-US")} characters`);
318318 const variants = parseVariants(input.variants);
319319 if (variants === undefined)
src/http/mcp/tools/tell.ts +4 −4
@@ -2,7 +2,7 @@ import { contextNote, parseContext } from "../../../actions/tell_context.ts";
22 import { asksMakeANewApp, firstAsk } from "../../../actions/first_ask.ts";
33 import { crewCanRun } from "../../../web/studio/crew_key.ts";
44 import { keepThought } from "../../../actions/thought.ts";
5 import { overTellLimit, parseFrom, TELL_LIMIT_HINT, TELL_LIMIT_WORDS } from "../../../actions/tell_from.ts";
5 import { overTellLimit, parseFrom, TELL_LIMIT_HINT, tellTooLongWords } from "../../../actions/tell_from.ts";
66 import { FROM_WORDS, tell, toldWords } from "../../../actions/tell.ts";
77 import { refusalWords } from "../../../actions/tell_answer.ts";
88 import { mayReadRuns } from "../../../actions/runs.ts";
@@ -65,8 +65,8 @@ export const tool: Tool = {
6565 "text is a string of at most 20,000 characters",
6666 );
6767 }
68 if (overTellLimit(str(args["text"]).trim()))
69 return bad("invalid", `${TELL_LIMIT_WORDS} ${TELL_LIMIT_HINT}`);
68 const said = str(args["text"]).trim();
69 if (overTellLimit(said)) return bad("invalid", `${tellTooLongWords(said)} ${TELL_LIMIT_HINT}`);
7070 const repo = repoArg(ctx, user, args);
7171 if (isAnswer(repo)) return repo;
7272 if (args["issue"] !== undefined) {
@@ -93,7 +93,7 @@ export const tool: Tool = {
9393 1,
9494 from,
9595 );
96 if (!told.ok) return bad(told.error, refusalWords(told.error));
96 if (!told.ok) return bad(told.error, refusalWords(told.error, said));
outdated

Non-blocking: reuse said here instead of trimming args["text"] a second time.

9797 return good({
9898 says: toldWords(told.value),
9999 issue: told.value.issue.number,
src/tui/screens/answers.ts +1 −1
@@ -80,7 +80,7 @@ export function answersScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
8080 onSubmit: (said) => {
8181 if (said === "") return SAY_SOMETHING_WORDS;
8282 return (async () => {
83 const answer = tellAnswer(await tell(f.app, f.user, repo, said, 1, from));
83 const answer = tellAnswer(await tell(f.app, f.user, repo, said, 1, from), said.trim());
8484 ctx.toast(answer.text, answer.tone);
8585 read();
8686 ctx.invalidate();
src/tui/screens/share_tell.ts +1 −1
@@ -112,5 +112,5 @@ export async function fileShare(
112112 const [owner = "", name = "", ...extra] = target.split("/");
113113 const repo = extra.length === 0 ? listReposWritableTo(f.db, user, { limit: 200, withoutArchived: true }).find((r) => r.ownerName === owner && r.name === name) : undefined;
114114 if (repo === undefined) return { tone: "danger", text: "That app is not one you can tell." };
115 return tellAnswer(await tell(f.app, user, repo, draft));
115 return tellAnswer(await tell(f.app, user, repo, draft), draft.trim());
116116 }
src/tui/screens/tell.ts +3 −3
@@ -38,7 +38,7 @@ export function tellCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R
3838 onSubmit: (said) => {
3939 if (said === "") return SAY_SOMETHING_WORDS;
4040 return (async () => {
41 const answer = tellAnswer(await tell(f.app, f.user, repo, said));
41 const answer = tellAnswer(await tell(f.app, f.user, repo, said), said.trim());
4242 ctx.toast(answer.text, answer.tone);
4343 })();
4444 },
@@ -114,7 +114,7 @@ export async function tellFromPage(
114114 repo,
115115 `${said}${contextNote(where, { preview: true, app: named ? app : repo.name })}`,
116116 );
117 const answer = tellAnswer(told);
117 const answer = tellAnswer(told, said.trim());
118118 const left = dropped || (app !== undefined && !named);
119119 ctx.toast(left && told.ok ? `${answer.text} ${WITHOUT_WHERE_WORDS}` : answer.text, answer.tone);
120120 }
@@ -131,7 +131,7 @@ export function askForSomething(f: Session, ctx: Ctx, parent: () => Screen, repo
131131 if (said === "") return SAY_SOMETHING_WORDS;
132132 return (async () => {
133133 const told = await tell(f.app, f.user, repo, said, 1, "/");
134 const answer = told.ok ? { text: SENT_WORDS, tone: "success" as const } : tellAnswer(told);
134 const answer = told.ok ? { text: SENT_WORDS, tone: "success" as const } : tellAnswer(told, said.trim());
135135 ctx.toast(answer.text, answer.tone);
136136 })();
137137 },
src/tui/screens/tell_here.ts +1 −1
@@ -52,7 +52,7 @@ export function herePath(h: Here): string {
5252 /** One tell from `h`: the answer, then the receipt, in one confirm line. */
5353 export async function tellHereNow(f: Pick<Session, "app" | "user">, ctx: Pick<Ctx, "toast">, h: Here, said: string, send: Sender = sendTell): Promise<void> {
5454 const told = await send(f.app, f.user, h.repo, said, 1, herePath(h));
55 const answer = tellAnswer(told);
55 const answer = tellAnswer(told, said.trim());
5656 // The receipt leads: a long answer is cut to the toast's width, the number must not be.
5757 const lead = told.ok ? `Told from ${hereWords(h)} — receipt: issue #${told.value.issue.number}. ` : "";
5858 ctx.toast(`${lead}${answer.text}`, answer.tone);
src/tui/ssh-tell.ts +3 −3
@@ -90,7 +90,7 @@ async function told(
9090 if (repo === undefined) return refuse(session, NO_CREW_WORDS);
9191 const sentence = named?.words ?? said;
9292 const result = await tell(app, user, repo, sentence, 1, from, from !== null);
93 const answer = tellAnswer(result);
93 const answer = tellAnswer(result, sentence.trim());
9494 if (!result.ok) return refuse(session, answer.text);
9595 const base = app.config.url ?? `http://localhost:${app.config.port ?? 3000}`;
9696 // A first word shaped like owner/name that named nothing readable went in
@@ -133,10 +133,10 @@ async function firstTold(app: App, session: SshSession, user: User, said: string
133133 const first = await firstAsk(app, user, said, crewCanRun(app));
134134 if (!first.ok) return refuse(session, first.error.words);
135135 const { repo, told, autonomyFailed } = first.value;
136 if (!told.ok) return refuse(session, tellAnswer(told).text);
136 if (!told.ok) return refuse(session, tellAnswer(told, said.trim()).text);
137137 const base = app.config.url ?? `http://localhost:${app.config.port ?? 3000}`;
138138 session.write(
139 `${tellAnswer(told).text}${CRLF}${autonomyFailed ? `${AUTONOMY_FAILED_WORDS}${CRLF}` : ""}${base}/${repo.ownerName}/${repo.name}/issues/${told.value.issue.number}${CRLF}`,
139 `${tellAnswer(told, said.trim()).text}${CRLF}${autonomyFailed ? `${AUTONOMY_FAILED_WORDS}${CRLF}` : ""}${base}/${repo.ownerName}/${repo.name}/issues/${told.value.issue.number}${CRLF}`,
140140 );
141141 session.exit(0);
142142 }
src/web/studio/actions.ts +6 −11
@@ -14,8 +14,8 @@ import { mayView } from "../../core/sealed.ts";
1414 import { shipsPastReviews } from "./land_as_is.ts";
1515 import { holdPull, releasePull } from "../../actions/holds.ts";
1616 import { addComment } from "../../actions/issues.ts";
17 import { overTellLimit, parseFrom } from "../../actions/tell_from.ts";
18 import { SENT_WORDS, tell, toldWords, TOO_LONG_WORDS } from "../../actions/tell.ts";
17 import { overTellLimit, parseFrom, tellTooLongWords } from "../../actions/tell_from.ts";
18 import { SENT_WORDS, tell, toldWords } from "../../actions/tell.ts";
1919 import { TAKEN_BACK_WORDS, TOO_LATE_WORDS, tellUndoable, undoTell } from "../../actions/tell_undo.ts";
2020 import { contextNote, whereTold } from "../../actions/tell_context.ts";
2121 import { refusalWords } from "../../actions/tell_answer.ts";
@@ -78,7 +78,7 @@ async function tellFrom(
7878 tone: "danger",
7979 message: SAY_SOMETHING_WORDS,
8080 });
81 if (overTellLimit(text)) return flashOrJson(ctx, back, { tone: "danger", message: TOO_LONG_WORDS });
81 if (overTellLimit(text)) return flashOrJson(ctx, back, { tone: "danger", message: tellTooLongWords(text) });
8282 return toldAnswer(ctx, repo, form, back, from, await tell(ctx.app, ctx.auth.user, repo, text, 1, from), onTold);
8383 }
8484
@@ -95,15 +95,10 @@ function toldAnswer(
9595 subject = "",
9696 ): Promise<Response> | Response {
9797 const named = (message: string): string => prefixed(message, subject);
98 if (!told.ok && told.error === "body_too_long")
99 return flashOrJson(ctx, back, {
100 tone: "danger",
101 message: TOO_LONG_WORDS,
102 });
10398 if (!told.ok)
10499 return flashOrJson(ctx, back, {
105100 tone: "danger",
106 message: refusalWords(told.error),
101 message: refusalWords(told.error, field(form, "text").trim()),
107102 });
108103 onTold();
109104 const { routed } = told.value;
@@ -183,12 +178,12 @@ async function tellFromPage(ctx: Ctx, repo: Repo, form: Form): Promise<Response>
183178 const back = `${repoBase(repo)}/tell?${keep}`;
184179 const text = field(form, "text").trim();
185180 if (text === "") return flashTo(ctx, back, { tone: "danger", message: SAY_SOMETHING_WORDS });
186 if (overTellLimit(text)) return flashTo(ctx, back, { tone: "danger", message: TOO_LONG_WORDS });
181 if (overTellLimit(text)) return flashOrJson(ctx, back, { tone: "danger", message: tellTooLongWords(text) });
187182 const told = await tell(ctx.app, ctx.auth.user, repo, `${text}${contextNote(where, { preview: true, app: repo.name })}`);
188183 if (!told.ok)
189184 return flashTo(ctx, back, {
190185 tone: "danger",
191 message: refusalWords(told.error),
186 message: refusalWords(told.error, text),
192187 });
193188 const issue = `${repoBase(repo)}/issues/${told.value.issue.number}`;
194189 return page({
test/app-answers.test.ts +2 −2
@@ -9,7 +9,7 @@ import { mkdtemp, rm } from "node:fs/promises";
99 import { tmpdir } from "node:os";
1010 import { join } from "node:path";
1111 import { enableApp } from "../src/actions/apps.ts";
12 import { TOO_LONG_WORDS } from "../src/actions/tell.ts";
12 import { TELL_LIMIT_WORDS } from "../src/actions/tell_from.ts";
1313 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1414 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1515 import { createApp, type App } from "../src/app.ts";
@@ -156,7 +156,7 @@ describe("the crew's answer under the tell box", () => {
156156 const long = await tell(alice, "x".repeat(70_000));
157157 const flash = long.headers.getSetCookie().map((c) => c.split(";")[0]).join("; ");
158158 const shown = await (await fetch(new URL(long.headers.get("location")!, servers.url), { headers: { cookie: `${alice}; ${flash}` } })).text();
159 expect(shown).toContain(TOO_LONG_WORDS);
159 expect(shown).toContain(`${TELL_LIMIT_WORDS} These are 70,000.`);
160160 expect(listIssues(app.db, repo.id, { state: "all", limit: 50 }).length).toBe(before);
161161 });
162162
test/first-ask-refusals.test.ts +2 −2
@@ -16,7 +16,7 @@ import { NEW_APP_ERRORS } from "../src/actions/apps.ts";
1616 import { deriveAppName } from "../src/web/pages/apps-name.ts";
1717 import { listReposOwnedBy } from "../src/core/repos.ts";
1818 import { createUser, type User } from "../src/core/users.ts";
19 import { TOO_LONG_WORDS } from "../src/actions/tell.ts";
19 import { TELL_LIMIT_WORDS } from "../src/actions/tell_from.ts";
2020 import { quietLogs } from "./helpers/globals.ts";
2121
2222 quietLogs();
@@ -54,7 +54,7 @@ test("too long, nobody signed in and a bad from each leave one row", async () =>
5454 const long = "x".repeat(MAX_BODY + 1);
5555 const a = await firstAsk(app, maria, long, false);
5656 if (a.ok) throw new Error("kept");
57 expect(a.error.words).toBe(TOO_LONG_WORDS);
57 expect(a.error.words).toBe(`${TELL_LIMIT_WORDS} These are 65,537.`);
5858 await firstAsk(app, undefined, "a menu page", false);
5959 await firstAsk(app, maria, "a menu page", false, "not-a-from-value-\u0000");
6060 const rows = listRefusals(app.db, 10, Date.now());
test/mcp-tell.test.ts +11 −9
@@ -2,6 +2,7 @@
22 * `tell` refuses in the feed composer's words: one function (`refusalWords`)
33 * speaks for the page, the terminal and the MCP.
44 */
5 import { tellTooLongWords } from "../src/actions/tell_from.ts";
56 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
67 import { mkdtemp, rm } from "node:fs/promises";
78 import { tmpdir } from "node:os";
@@ -79,9 +80,10 @@ describe("MCP tell refusals", () => {
7980 });
8081
8182 test("an over-long tell is refused in the words the terminal and the page say", async () => {
82 const r = await call({ repo: "alice/notes", text: "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000) });
83 const body = "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000);
84 const r = await call({ repo: "alice/notes", text: body });
8385 expect(r.error).toBe(true);
84 expect(r.text).toContain(tellAnswer({ ok: false, error: "body_too_long" }).text);
86 expect(r.text).toContain(tellAnswer({ ok: false, error: "body_too_long" }, body).text);
8587 });
8688
8789 /** The feed composer's own action (the studio's POST /:owner/:name/tell), asked for JSON. */
@@ -99,8 +101,8 @@ describe("MCP tell refusals", () => {
99101 test("the composer and the MCP refuse the same input in the same words", async () => {
100102 const long = "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000);
101103 for (const [text, said] of [
102 [" ", refusalWords("empty")],
103 [long, refusalWords("body_too_long")],
104 [" ", refusalWords("empty", "")],
105 [long, tellTooLongWords(long)],
104106 ] as const) {
105107 const web = await composer(text);
106108 expect(web).toBe(said);
@@ -109,7 +111,7 @@ describe("MCP tell refusals", () => {
109111 app.db.query("UPDATE email_check SET verified_at = NULL").run();
110112 try {
111113 const web = await composer("hello");
112 expect(web).toBe(refusalWords("unverified"));
114 expect(web).toBe(refusalWords("unverified", ""));
113115 const mcp = await call({ repo: "alice/notes", text: "hello" });
114116 expect(mcp.error).toBe(true);
115117 expect(mcp.text).toContain(web);
@@ -119,9 +121,9 @@ describe("MCP tell refusals", () => {
119121 });
120122
121123 test("every refusal the composer words is worded by the shared function", () => {
122 expect(refusalWords("empty")).toBe(SAY_SOMETHING_WORDS);
123 expect(refusalWords("unverified")).toBe("Verify your email first."); // the one place the sentence is spelled out
124 expect(refusalWords("body_too_long")).toBe("One thought, at most 4,000 characters.");
125 expect(refusalWords("not_found")).toBe("That could not be told.");
124 expect(refusalWords("empty", "")).toBe(SAY_SOMETHING_WORDS);
125 expect(refusalWords("unverified", "")).toBe("Verify your email first."); // the one place the sentence is spelled out
126 expect(refusalWords("body_too_long", "x")).toBe("One thought, at most 4,000 characters. These are 1.");
127 expect(refusalWords("not_found", "x")).toBe("That could not be told.");
126128 });
127129 });
test/ssh-tell.test.ts +3 −3
@@ -10,7 +10,7 @@ import { createApp, type App } from "../src/app.ts";
1010 import { createRepo } from "../src/actions/repos.ts";
1111 import { SAY_SOMETHING_WORDS } from "../src/actions/tell_words.ts";
1212 import { MAX_BODY } from "../src/core/issues.ts";
13 import { TOO_LONG_WORDS } from "../src/actions/tell.ts";
13 import { TELL_LIMIT_WORDS } from "../src/actions/tell_from.ts";
1414 import { refusalWords } from "../src/actions/tell_answer.ts";
1515 import { addKey, fingerprint, parseAuthorizedKey } from "../src/core/keys.ts";
1616 import { getRepo } from "../src/core/repos.ts";
@@ -138,13 +138,13 @@ describe("ssh forge tell", () => {
138138 const bare = await exec(KEY_A, "tell");
139139 expect(bare.err).toContain(SAY_SOMETHING_WORDS);
140140 const long = await exec(KEY_A, `tell ${"x".repeat(MAX_BODY + 1)}`);
141 expect([long.code, long.err]).toEqual([1, `forge: ${TOO_LONG_WORDS}\r\n`]);
141 expect([long.code, long.err]).toEqual([1, `forge: ${TELL_LIMIT_WORDS} These are 65,537.\r\n`]);
142142 for (const bad of ["tell a\x1b[2Jb", "tell a\nb", "tell a\x00b"]) {
143143 const r = await exec(KEY_A, bad);
144144 expect([r.code, r.err]).toEqual([1, `forge: ${CONTROL_WORDS}\r\n`]);
145145 }
146146 const unverified = await exec(KEY_B, "tell hello");
147 expect([unverified.code, unverified.err]).toEqual([1, `forge: ${refusalWords("unverified")}\r\n`]);
147 expect([unverified.code, unverified.err]).toEqual([1, `forge: ${refusalWords("unverified", "")}\r\n`]);
148148 expect(issues().length).toBe(1);
149149 });
150150
test/tell-limit-doors.test.ts +41
@@ -109,3 +109,44 @@ test("every tell box says the limit in one line", async () => {
109109 if (page.includes('name="text"')) expect(page).toContain(TELL_LIMIT_WORDS);
110110 }
111111 });
112
113 // Each door names the limit and the text's own length, so dropping the length from any door fails.
114 const LONG = 4321;
115 const named = (said: string) => {
116 expect(said).toContain("4,000");
117 expect(said).toContain("4,321");
118 };
119
120 test("the feed API's refusal names the limit and the length, and files nothing", async () => {
121 const before = issues();
122 const over = await api("x".repeat(LONG));
123 expect(over.status).toBe(422);
124 named(((await over.json()) as { message: string }).message);
125 expect(issues()).toBe(before);
126 });
127
128 for (const [door, extra] of [["the tell box", {}], ["the page's toolbar", { page: "http://forge.test/x" }]] as const) {
129 test(`${door}: a form post is sent back with a flash naming the limit and the length, and files nothing`, async () => {
130 const before = issues();
131 const over = await web("/alice/notes/tell", { text: "w".repeat(LONG), ...extra });
132 expect(over.status).toBe(303);
133 const flash = decodeURIComponent(over.headers.get("set-cookie") ?? "");
134 named(flash);
135 expect(issues()).toBe(before);
136 });
137
138 test(`${door}: a JSON post is a 422 naming the limit and the length, and files nothing`, async () => {
139 const before = issues();
140 const over = await fetch(`${servers.url}/alice/notes/tell`, {
141 method: "POST",
142 headers: { cookie, origin: servers.url, accept: "application/json" },
143 body: new URLSearchParams({ text: "v".repeat(LONG), ...extra }),
144 redirect: "manual",
145 });
146 expect(over.status).toBe(422);
147 const body = (await over.json()) as { ok: boolean; error: string };
148 expect(body.ok).toBe(false);
149 named(body.error);
150 expect(issues()).toBe(before);
151 });
152 }
test/tell-limit-length.test.ts added +68
@@ -0,0 +1,68 @@
1 /**
2 * An over-long tell is refused naming the limit and its own length, stores nothing, at the
3 * first ask, the tell action, and the MCP tool.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import type { Ctx } from "../src/http/context.ts";
10 import { createApp, type App } from "../src/app.ts";
11 import { createRepo } from "../src/actions/repos.ts";
12 import { firstAsk } from "../src/actions/first_ask.ts";
13 import { tell } from "../src/actions/tell.ts";
14 import { tellAnswer } from "../src/actions/tell_answer.ts";
15 import { err } from "../src/kernel/result.ts";
16 import { tool } from "../src/http/mcp/tools/tell.ts";
17 import { seedAdmin } from "./helpers/admin.ts";
18 import { quietLogs } from "./helpers/globals.ts";
19
20 quietLogs();
21
22 let dataDir: string;
23 let app: App;
24
25 beforeAll(async () => {
26 dataDir = await mkdtemp(join(tmpdir(), "forge-tell-length-"));
27 app = createApp({ dataDir, port: 0 });
28 });
29 afterAll(async () => {
30 app.close();
31 await rm(dataDir, { recursive: true, force: true });
32 });
33
34 const count = (table: string) => app.db.query<{ n: number }, []>(`SELECT count(*) AS n FROM ${table}`).get()!.n;
35
36 test("the first ask and the MCP tool name the limit and the length, and store nothing", async () => {
37 const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-tell-passphrase" });
38 if (!a.ok) throw new Error("signup failed");
39 const made = await createRepo(app, a.value, { name: "notes", visibility: "public" });
40 if (!made.ok) throw new Error("repo failed");
41 const long = "x".repeat(4321);
42 const repos = count("repo");
43 const first = await firstAsk(app, a.value, long, false);
44 expect(first.ok).toBe(false);
45 if (!first.ok) {
46 expect(first.error.words).toContain("4,000");
47 expect(first.error.words).toContain("4,321");
48 }
49 expect(count("repo")).toBe(repos);
50 const issues = count("issue");
51 const direct = await tell(app, a.value, made.value, long);
52 expect(direct.ok).toBe(false);
53 const url = new URL("http://localhost/mcp");
54 const ctx: Ctx = { app, request: new Request(url.href), url, params: {}, auth: { user: a.value, scope: "admin", via: "token" }, theme: undefined };
55 const over = await tool.run(ctx, a.value, { repo: "alice/notes", text: long });
56 expect(over.ok).toBe(false);
57 if (!over.ok) {
58 expect(over.message).toContain("4,000");
59 expect(over.message).toContain("4,321");
60 }
61 expect(count("issue")).toBe(issues);
62 });
outdated

Imports sit in the middle of the file, after the tests. Move them to the top with the others. This test file also has no case for the page, the feed API or the 422 status, so box 3 (both doors) is not met.

63
64 test("the terminal's refusal names the limit and the length", () => {
65 const said = "x".repeat(4001);
66 expect(tellAnswer(err("body_too_long"), said).text).toContain("4,000");
67 expect(tellAnswer(err("body_too_long"), said).text).toContain("4,001");
68 });
test/tui-answers-tell.test.ts +1 −1
@@ -118,7 +118,7 @@ describe("t on the answers screen", () => {
118118 app.db.query("UPDATE email_check SET verified_at = NULL").run();
119119 try {
120120 const seen = await drive(alice, ["t", ..."Unseen.", "\r"]);
121 expect(seen.text).toContain(refusalWords("unverified"));
121 expect(seen.text).toContain(refusalWords("unverified", ""));
122122 } finally {
123123 proveAll(app);
124124 }
test/tui-tell.test.ts +5 −4
@@ -12,7 +12,8 @@ import { createApp, type App } from "../src/app.ts";
1212 import { listIssues, MAX_BODY } from "../src/core/issues.ts";
1313 import { createUser, type User } from "../src/core/users.ts";
1414 import { refusalWords, tellAnswer } from "../src/actions/tell_answer.ts";
15 import { tell, toldWords, TOO_LONG_WORDS, type Told } from "../src/actions/tell.ts";
15 import { tell, toldWords, type Told } from "../src/actions/tell.ts";
16 import { TELL_LIMIT_WORDS } from "../src/actions/tell_from.ts";
1617 import { createForgeApp } from "../src/tui/forge.ts";
1718 import { repoScreen } from "../src/tui/screens/repo.ts";
1819 import { local } from "../src/tui/screens/where.ts";
@@ -139,7 +140,7 @@ describe("tell the crew in the terminal", () => {
139140 assigned: false,
140141 routed: { builder: { user: { username: "mason" } }, size: "small", kind: "fix", by: "rule", ms: 1 },
141142 } as unknown as Told;
142 const answer = tellAnswer({ ok: true, value });
143 const answer = tellAnswer({ ok: true, value }, "");
143144 expect(answer.text).toBe(toldWords(value));
144145 expect(answer.text).toContain("Opened as issue #7, but mason could not take it.");
145146 expect(answer.text).not.toContain("is on it");
@@ -147,10 +148,10 @@ describe("tell the crew in the terminal", () => {
147148 });
148149
149150 test("an unverified address gets the shared words", () => {
150 expect(tellAnswer({ ok: false, error: "unverified" }).text).toBe(refusalWords("unverified"));
151 expect(tellAnswer({ ok: false, error: "unverified" }, "").text).toBe(refusalWords("unverified", ""));
151152 });
152153
153154 test("an over-long line gets the page's words", async () => {
154 expect(tellAnswer(await tell(app, alice, repo, "x".repeat(MAX_BODY + 1))).text).toBe(TOO_LONG_WORDS);
155 expect(tellAnswer(await tell(app, alice, repo, "x".repeat(MAX_BODY + 1)), "x".repeat(MAX_BODY + 1)).text).toBe(`${TELL_LIMIT_WORDS} These are 65,537.`);
155156 });
156157 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs